Skip to content

Commit 6ec963b

Browse files
committed
[1.7>master] [MERGE #3462 @kfarnung] Add JsGetDataViewInfo support
Merge pull request #3462 from kfarnung:dataview Match the existing JsGetTypedArrayInfo signature in order to support making similar queries for DataViews.
2 parents f33039c + d43c23a commit 6ec963b

File tree

8 files changed

+89
-2
lines changed

8 files changed

+89
-2
lines changed

lib/Jsrt/ChakraCore.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,5 +733,22 @@ JsCopyStringOneByte(
733733
_Out_opt_ char* buffer,
734734
_Out_opt_ size_t* written);
735735

736+
/// <summary>
737+
/// Obtains frequently used properties of a data view.
738+
/// </summary>
739+
/// <param name="dataView">The data view instance.</param>
740+
/// <param name="arrayBuffer">The ArrayBuffer backstore of the view.</param>
741+
/// <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param>
742+
/// <param name="byteLength">The number of bytes in the array.</param>
743+
/// <returns>
744+
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
745+
/// </returns>
746+
CHAKRA_API
747+
JsGetDataViewInfo(
748+
_In_ JsValueRef dataView,
749+
_Out_opt_ JsValueRef *arrayBuffer,
750+
_Out_opt_ unsigned int *byteOffset,
751+
_Out_opt_ unsigned int *byteLength);
752+
736753
#endif // _CHAKRACOREBUILD
737754
#endif // _CHAKRACORE_H_

lib/Jsrt/Jsrt.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4781,4 +4781,44 @@ CHAKRA_API JsCopyStringOneByte(
47814781
});
47824782
}
47834783

4784+
CHAKRA_API JsGetDataViewInfo(
4785+
_In_ JsValueRef dataView,
4786+
_Out_opt_ JsValueRef *arrayBuffer,
4787+
_Out_opt_ unsigned int *byteOffset,
4788+
_Out_opt_ unsigned int *byteLength)
4789+
{
4790+
VALIDATE_JSREF(dataView);
4791+
4792+
BEGIN_JSRT_NO_EXCEPTION
4793+
{
4794+
if (!Js::DataView::Is(dataView))
4795+
{
4796+
RETURN_NO_EXCEPTION(JsErrorInvalidArgument);
4797+
}
4798+
4799+
Js::DataView* dv = Js::DataView::FromVar(dataView);
4800+
if (arrayBuffer != nullptr) {
4801+
*arrayBuffer = dv->GetArrayBuffer();
4802+
}
4803+
4804+
if (byteOffset != nullptr) {
4805+
*byteOffset = dv->GetByteOffset();
4806+
}
4807+
4808+
if (byteLength != nullptr) {
4809+
*byteLength = dv->GetLength();
4810+
}
4811+
}
4812+
4813+
#if ENABLE_TTD
4814+
Js::ScriptContext* scriptContext = Js::RecyclableObject::FromVar(dataView)->GetScriptContext();
4815+
if(PERFORM_JSRT_TTD_RECORD_ACTION_CHECK(scriptContext) && arrayBuffer != nullptr)
4816+
{
4817+
scriptContext->GetThreadContext()->TTDLog->RecordJsRTGetDataViewInfo(dataView, *arrayBuffer);
4818+
}
4819+
#endif
4820+
4821+
END_JSRT_NO_EXCEPTION
4822+
}
4823+
47844824
#endif // _CHAKRACOREBUILD

lib/Jsrt/JsrtCommonExports.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@
121121
JsGetAndClearExceptionWithMetadata
122122
JsHasOwnProperty
123123
JsCopyStringOneByte
124+
JsGetDataViewInfo
124125
#endif

lib/Runtime/Debug/TTActionEvents.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "RuntimeDebugPch.h"
66

77
#include "Library/JavascriptExceptionMetadata.h"
8+
#include "Common/ByteSwap.h"
9+
#include "Library/DataView.h"
810

911
#if ENABLE_TTD
1012

@@ -719,6 +721,20 @@ namespace TTD
719721
JsRTActionHandleResultForReplay<JsRTSingleVarArgumentAction, EventKind::GetTypedArrayInfoActionTag>(executeContext, evt, res);
720722
}
721723

724+
void GetDataViewInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext)
725+
{
726+
const JsRTSingleVarArgumentAction* action = GetInlineEventDataAs<JsRTSingleVarArgumentAction, EventKind::GetDataViewInfoActionTag>(evt);
727+
Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action));
728+
729+
Js::DataView* dataView = Js::DataView::FromVar(var);
730+
Js::Var res = dataView->GetArrayBuffer();
731+
732+
//Need additional notify since JsRTActionHandleResultForReplay may allocate but GetDataViewInfo does not enter runtime
733+
//Failure will kick all the way out to replay loop -- which is what we want
734+
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(ExceptionType_OutOfMemory);
735+
JsRTActionHandleResultForReplay<JsRTSingleVarArgumentAction, EventKind::GetDataViewInfoActionTag>(executeContext, evt, res);
736+
}
737+
722738
//////////////////
723739

724740
void JsRTRawBufferCopyAction_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext)

lib/Runtime/Debug/TTActionEvents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ namespace TTD
509509
void SetIndexAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);
510510

511511
void GetTypedArrayInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);
512+
void GetDataViewInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);
512513

513514
//////////////////
514515

lib/Runtime/Debug/TTEventLog.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ namespace TTD
562562
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(SetIndexActionTag, ContextAPIWrapper, JsRTTrippleVarArgumentAction, SetIndexAction_Execute);
563563

564564
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(GetTypedArrayInfoActionTag, None, JsRTSingleVarArgumentAction, GetTypedArrayInfoAction_Execute);
565+
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(GetDataViewInfoActionTag, None, JsRTSingleVarArgumentAction, GetDataViewInfoAction_Execute);
565566

566567
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(RawBufferCopySync, ContextAPIWrapper, JsRTRawBufferCopyAction, NSLogEvents::RawBufferCopySync_Execute, nullptr, NSLogEvents::JsRTRawBufferCopyAction_Emit, NSLogEvents::JsRTRawBufferCopyAction_Parse);
567568
TTD_CREATE_EVENTLIST_VTABLE_ENTRY(RawBufferModifySync, ContextAPIWrapper, JsRTRawBufferModifyAction, NSLogEvents::RawBufferModifySync_Execute, NSLogEvents::JsRTRawBufferModifyAction_UnloadEventMemory<NSLogEvents::EventKind::RawBufferModifySync>, NSLogEvents::JsRTRawBufferModifyAction_Emit<NSLogEvents::EventKind::RawBufferModifySync>, NSLogEvents::JsRTRawBufferModifyAction_Parse<NSLogEvents::EventKind::RawBufferModifySync>);
@@ -2339,7 +2340,16 @@ namespace TTD
23392340
NSLogEvents::JsRTSingleVarArgumentAction* giAction = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::JsRTSingleVarArgumentAction, NSLogEvents::EventKind::GetTypedArrayInfoActionTag>();
23402341
NSLogEvents::SetVarItem_0(giAction, TTD_CONVERT_JSVAR_TO_TTDVAR(var));
23412342

2342-
//entry/exit status should be set to clead by initialization so don't need to do anything
2343+
// entry/exit status should be set to clear by initialization so don't need to do anything
2344+
giAction->Result = TTD_CONVERT_JSVAR_TO_TTDVAR(result);
2345+
}
2346+
2347+
void EventLog::RecordJsRTGetDataViewInfo(Js::Var var, Js::Var result)
2348+
{
2349+
NSLogEvents::JsRTSingleVarArgumentAction* giAction = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::JsRTSingleVarArgumentAction, NSLogEvents::EventKind::GetDataViewInfoActionTag>();
2350+
NSLogEvents::SetVarItem_0(giAction, TTD_CONVERT_JSVAR_TO_TTDVAR(var));
2351+
2352+
// entry/exit status should be set to clear by initialization so don't need to do anything
23432353
giAction->Result = TTD_CONVERT_JSVAR_TO_TTDVAR(result);
23442354
}
23452355

lib/Runtime/Debug/TTEventLog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ namespace TTD
581581

582582
//Record a get info from a typed array
583583
void RecordJsRTGetTypedArrayInfo(Js::Var var, Js::Var result);
584+
void RecordJsRTGetDataViewInfo(Js::Var var, Js::Var result);
584585

585586
//Record various raw byte* from ArrayBuffer manipulations
586587
void RecordJsRTRawBufferCopySync(TTDJsRTActionResultAutoRecorder& actionPopper, Js::Var dst, uint32 dstIndex, Js::Var src, uint32 srcIndex, uint32 length);

lib/Runtime/Debug/TTEvents.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ namespace TTD
168168
ConstructCallActionTag,
169169
CodeParseActionTag,
170170
CallExistingFunctionActionTag,
171-
171+
172172
HasOwnPropertyActionTag,
173+
GetDataViewInfoActionTag,
173174

174175
Count
175176
};

0 commit comments

Comments
 (0)