Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
n-api: implement DataView APIs for ChakraCore
Browse files Browse the repository at this point in the history
Implemented the DataView APIs for ChakraCore using the existing JSRT
APIs as well as one new API, JsGetDataViewInfo. The test case has also
been removed from the flaky list.

PR-URL: #351
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
  • Loading branch information
kfarnung committed Aug 14, 2017
1 parent fef55b4 commit 39876b5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
73 changes: 73 additions & 0 deletions src/node_api_jsrt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,79 @@ napi_status napi_get_typedarray_info(napi_env env,
return napi_ok;
}

napi_status napi_create_dataview(napi_env env,
size_t byte_length,
napi_value arraybuffer,
size_t byte_offset,
napi_value* result) {
CHECK_ARG(result);

JsValueRef jsArrayBuffer = reinterpret_cast<JsValueRef>(arraybuffer);

CHECK_JSRT(JsCreateDataView(
jsArrayBuffer,
static_cast<unsigned int>(byte_offset),
static_cast<unsigned int>(byte_length),
reinterpret_cast<JsValueRef*>(result)));

return napi_ok;
}

napi_status napi_is_dataview(napi_env env, napi_value value, bool* result) {
CHECK_ARG(result);

JsValueRef jsValue = reinterpret_cast<JsValueRef>(value);
JsValueType valueType;
CHECK_JSRT(JsGetValueType(jsValue, &valueType));

*result = (valueType == JsDataView);
return napi_ok;
}

napi_status napi_get_dataview_info(napi_env env,
napi_value dataview,
size_t* byte_length,
void** data,
napi_value* arraybuffer,
size_t* byte_offset) {
JsValueRef jsArrayBuffer = JS_INVALID_REFERENCE;
unsigned int byteOffset = 0;
unsigned int byteLength = 0;
ChakraBytePtr bufferData = nullptr;
unsigned int bufferLength = 0;

JsValueRef jsDataView = reinterpret_cast<JsValueRef>(dataview);

CHECK_JSRT(JsGetDataViewInfo(
jsDataView,
&jsArrayBuffer,
&byteOffset,
&byteLength));

CHECK_JSRT(JsGetDataViewStorage(
jsDataView,
&bufferData,
&bufferLength));

if (byte_length != nullptr) {
*byte_length = static_cast<size_t>(byteLength);
}

if (data != nullptr) {
*data = static_cast<uint8_t*>(bufferData);
}

if (arraybuffer != nullptr) {
*arraybuffer = reinterpret_cast<napi_value>(jsArrayBuffer);
}

if (byte_offset != nullptr) {
*byte_offset = static_cast<size_t>(byteOffset);
}

return napi_ok;
}

napi_status napi_get_version(napi_env env, uint32_t* result) {
CHECK_ARG(result);
*result = NAPI_VERSION;
Expand Down
22 changes: 22 additions & 0 deletions test/addons-napi/addons-napi.status
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
prefix addons-napi

# To mark a test as flaky, list the test name in the appropriate section
# below, without ".js", followed by ": PASS,FLAKY". Example:
# sample-test : PASS,FLAKY

[true] # This section applies to all platforms

[$system==win32]

[$system==linux]

[$system==macos]

[$system==solaris]

[$system==freebsd]

[$system==aix]

[$jsEngine==chakracore]
test_env_sharing/test : PASS,FLAKY

0 comments on commit 39876b5

Please sign in to comment.