-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic support for Dataview is added in this commit. This is achieved by using three functions, napi_create_dataview(), napi_is_dataview() and napi_get_dataview_info(). PR-URL: #14382 Fixes: #13926 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
- Loading branch information
Showing
6 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "test_dataview", | ||
"sources": [ "test_dataview.c" ] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
|
||
// Testing api calls for arrays | ||
const test_dataview = require(`./build/${common.buildType}/test_dataview`); | ||
|
||
//create dataview | ||
const buffer = new ArrayBuffer(128); | ||
const template = Reflect.construct(DataView, [buffer]); | ||
|
||
const theDataview = test_dataview.CreateDataView(template); | ||
assert.ok(theDataview instanceof DataView, | ||
'The new variable should be of type Dataview'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <node_api.h> | ||
#include <string.h> | ||
#include "../common.h" | ||
|
||
napi_value CreateDataView(napi_env env, napi_callback_info info) { | ||
size_t argc = 1; | ||
napi_value args [1]; | ||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
||
NAPI_ASSERT(env, argc == 1, "Wrong number of arguments"); | ||
|
||
napi_valuetype valuetype; | ||
napi_value input_dataview = args[0]; | ||
|
||
NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); | ||
NAPI_ASSERT(env, valuetype == napi_object, | ||
"Wrong type of arguments. Expects a DataView as the first " | ||
"argument."); | ||
|
||
bool is_dataview; | ||
NAPI_CALL(env, napi_is_dataview(env, input_dataview, &is_dataview)); | ||
NAPI_ASSERT(env, is_dataview, | ||
"Wrong type of arguments. Expects a DataView as the first " | ||
"argument."); | ||
size_t byte_offset = 0; | ||
size_t length = 0; | ||
napi_value buffer; | ||
NAPI_CALL(env, | ||
napi_get_dataview_info(env, input_dataview, &length, NULL, | ||
&buffer, &byte_offset)); | ||
|
||
napi_value output_dataview; | ||
NAPI_CALL(env, | ||
napi_create_dataview(env, length, buffer, | ||
byte_offset, &output_dataview)); | ||
|
||
return output_dataview; | ||
} | ||
|
||
void Init(napi_env env, napi_value exports, napi_value module, void* priv) { | ||
napi_property_descriptor descriptors[] = { | ||
DECLARE_NAPI_PROPERTY("CreateDataView", CreateDataView) | ||
}; | ||
|
||
NAPI_CALL_RETURN_VOID(env, napi_define_properties( | ||
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); | ||
} | ||
|
||
NAPI_MODULE(addon, Init) |