Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JsGetDataViewInfo support #3462

Merged
merged 2 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is very similar API JsGetDataViewStorage. Can we reuse this? What is the use-case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought the same thing at first, but that method is purely interested in the raw storage. This method returns the parameters which were passed to the create method and I couldn't see a good way to get them (other than using script). Since TypedArray and DataView are both views over an ArrayBuffer, I think it makes sense for them to have similar interaction models.

_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