Skip to content

Commit

Permalink
[MERGE #3462 @kfarnung] Add JsGetDataViewInfo support
Browse files Browse the repository at this point in the history
Merge pull request #3462 from kfarnung:dataview

Match the existing JsGetTypedArrayInfo signature in order to support making similar queries for DataViews.
  • Loading branch information
kfarnung committed Jul 31, 2017
2 parents 0eabffe + 3e20cf2 commit d43c23a
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/Jsrt/ChakraCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,5 +733,22 @@ JsCopyStringOneByte(
_Out_opt_ char* buffer,
_Out_opt_ size_t* written);

/// <summary>
/// Obtains frequently used properties of a data view.
/// </summary>
/// <param name="dataView">The data view instance.</param>
/// <param name="arrayBuffer">The ArrayBuffer backstore of the view.</param>
/// <param name="byteOffset">The offset in bytes from the start of arrayBuffer referenced by the array.</param>
/// <param name="byteLength">The number of bytes in the array.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsGetDataViewInfo(
_In_ JsValueRef dataView,
_Out_opt_ JsValueRef *arrayBuffer,
_Out_opt_ unsigned int *byteOffset,
_Out_opt_ unsigned int *byteLength);

#endif // _CHAKRACOREBUILD
#endif // _CHAKRACORE_H_
40 changes: 40 additions & 0 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4781,4 +4781,44 @@ CHAKRA_API JsCopyStringOneByte(
});
}

CHAKRA_API JsGetDataViewInfo(
_In_ JsValueRef dataView,
_Out_opt_ JsValueRef *arrayBuffer,
_Out_opt_ unsigned int *byteOffset,
_Out_opt_ unsigned int *byteLength)
{
VALIDATE_JSREF(dataView);

BEGIN_JSRT_NO_EXCEPTION
{
if (!Js::DataView::Is(dataView))
{
RETURN_NO_EXCEPTION(JsErrorInvalidArgument);
}

Js::DataView* dv = Js::DataView::FromVar(dataView);
if (arrayBuffer != nullptr) {
*arrayBuffer = dv->GetArrayBuffer();
}

if (byteOffset != nullptr) {
*byteOffset = dv->GetByteOffset();
}

if (byteLength != nullptr) {
*byteLength = dv->GetLength();
}
}

#if ENABLE_TTD
Js::ScriptContext* scriptContext = Js::RecyclableObject::FromVar(dataView)->GetScriptContext();
if(PERFORM_JSRT_TTD_RECORD_ACTION_CHECK(scriptContext) && arrayBuffer != nullptr)
{
scriptContext->GetThreadContext()->TTDLog->RecordJsRTGetDataViewInfo(dataView, *arrayBuffer);
}
#endif

END_JSRT_NO_EXCEPTION
}

#endif // _CHAKRACOREBUILD
1 change: 1 addition & 0 deletions lib/Jsrt/JsrtCommonExports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@
JsGetAndClearExceptionWithMetadata
JsHasOwnProperty
JsCopyStringOneByte
JsGetDataViewInfo
#endif
16 changes: 16 additions & 0 deletions lib/Runtime/Debug/TTActionEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "RuntimeDebugPch.h"

#include "Library/JavascriptExceptionMetadata.h"
#include "Common/ByteSwap.h"
#include "Library/DataView.h"

#if ENABLE_TTD

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

void GetDataViewInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext)
{
const JsRTSingleVarArgumentAction* action = GetInlineEventDataAs<JsRTSingleVarArgumentAction, EventKind::GetDataViewInfoActionTag>(evt);
Js::Var var = InflateVarInReplay(executeContext, GetVarItem_0(action));

Js::DataView* dataView = Js::DataView::FromVar(var);
Js::Var res = dataView->GetArrayBuffer();

//Need additional notify since JsRTActionHandleResultForReplay may allocate but GetDataViewInfo does not enter runtime
//Failure will kick all the way out to replay loop -- which is what we want
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(ExceptionType_OutOfMemory);
JsRTActionHandleResultForReplay<JsRTSingleVarArgumentAction, EventKind::GetDataViewInfoActionTag>(executeContext, evt, res);
}

//////////////////

void JsRTRawBufferCopyAction_Emit(const EventLogEntry* evt, FileWriter* writer, ThreadContext* threadContext)
Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Debug/TTActionEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ namespace TTD
void SetIndexAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);

void GetTypedArrayInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);
void GetDataViewInfoAction_Execute(const EventLogEntry* evt, ThreadContextTTD* executeContext);

//////////////////

Expand Down
12 changes: 11 additions & 1 deletion lib/Runtime/Debug/TTEventLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ namespace TTD
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(SetIndexActionTag, ContextAPIWrapper, JsRTTrippleVarArgumentAction, SetIndexAction_Execute);

TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(GetTypedArrayInfoActionTag, None, JsRTSingleVarArgumentAction, GetTypedArrayInfoAction_Execute);
TTD_CREATE_EVENTLIST_VTABLE_ENTRY_COMMON(GetDataViewInfoActionTag, None, JsRTSingleVarArgumentAction, GetDataViewInfoAction_Execute);

TTD_CREATE_EVENTLIST_VTABLE_ENTRY(RawBufferCopySync, ContextAPIWrapper, JsRTRawBufferCopyAction, NSLogEvents::RawBufferCopySync_Execute, nullptr, NSLogEvents::JsRTRawBufferCopyAction_Emit, NSLogEvents::JsRTRawBufferCopyAction_Parse);
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>);
Expand Down Expand Up @@ -2339,7 +2340,16 @@ namespace TTD
NSLogEvents::JsRTSingleVarArgumentAction* giAction = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::JsRTSingleVarArgumentAction, NSLogEvents::EventKind::GetTypedArrayInfoActionTag>();
NSLogEvents::SetVarItem_0(giAction, TTD_CONVERT_JSVAR_TO_TTDVAR(var));

//entry/exit status should be set to clead by initialization so don't need to do anything
// entry/exit status should be set to clear by initialization so don't need to do anything
giAction->Result = TTD_CONVERT_JSVAR_TO_TTDVAR(result);
}

void EventLog::RecordJsRTGetDataViewInfo(Js::Var var, Js::Var result)
{
NSLogEvents::JsRTSingleVarArgumentAction* giAction = this->RecordGetInitializedEvent_DataOnly<NSLogEvents::JsRTSingleVarArgumentAction, NSLogEvents::EventKind::GetDataViewInfoActionTag>();
NSLogEvents::SetVarItem_0(giAction, TTD_CONVERT_JSVAR_TO_TTDVAR(var));

// entry/exit status should be set to clear by initialization so don't need to do anything
giAction->Result = TTD_CONVERT_JSVAR_TO_TTDVAR(result);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Debug/TTEventLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ namespace TTD

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

//Record various raw byte* from ArrayBuffer manipulations
void RecordJsRTRawBufferCopySync(TTDJsRTActionResultAutoRecorder& actionPopper, Js::Var dst, uint32 dstIndex, Js::Var src, uint32 srcIndex, uint32 length);
Expand Down
3 changes: 2 additions & 1 deletion lib/Runtime/Debug/TTEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ namespace TTD
ConstructCallActionTag,
CodeParseActionTag,
CallExistingFunctionActionTag,

HasOwnPropertyActionTag,
GetDataViewInfoActionTag,

Count
};
Expand Down

0 comments on commit d43c23a

Please sign in to comment.