-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: port test_dataview to CTS #39
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
Open
bavulapati
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
bavulapati:feat/port-test-dataview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| add_node_api_cts_experimental_addon(test_dataview test_dataview.c) |
This file contains hidden or 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,48 @@ | ||
| "use strict"; | ||
|
|
||
| if (experimentalFeatures.sharedArrayBuffer) { | ||
| // Testing api calls for arrays | ||
| const test_dataview = loadAddon("test_dataview"); | ||
|
|
||
| // Test for creating dataview with ArrayBuffer | ||
| { | ||
| const buffer = new ArrayBuffer(128); | ||
| const template = Reflect.construct(DataView, [buffer]); | ||
|
|
||
| const theDataview = test_dataview.CreateDataViewFromJSDataView(template); | ||
| assert.ok( | ||
| theDataview instanceof DataView, | ||
| `Expect ${theDataview} to be a DataView`, | ||
| ); | ||
| } | ||
|
|
||
| // Test for creating dataview with SharedArrayBuffer | ||
| { | ||
| const buffer = new SharedArrayBuffer(128); | ||
| const template = new DataView(buffer); | ||
|
|
||
| const theDataview = test_dataview.CreateDataViewFromJSDataView(template); | ||
| assert.ok( | ||
| theDataview instanceof DataView, | ||
| `Expect ${theDataview} to be a DataView`, | ||
| ); | ||
|
|
||
| assert.strictEqual(template.buffer, theDataview.buffer); | ||
| } | ||
|
|
||
| // Test for creating dataview with ArrayBuffer and invalid range | ||
| { | ||
| const buffer = new ArrayBuffer(128); | ||
| assert.throws(() => { | ||
| test_dataview.CreateDataView(buffer, 10, 200); | ||
| }, RangeError); | ||
| } | ||
|
|
||
| // Test for creating dataview with SharedArrayBuffer and invalid range | ||
| { | ||
| const buffer = new SharedArrayBuffer(128); | ||
| assert.throws(() => { | ||
| test_dataview.CreateDataView(buffer, 10, 200); | ||
| }, RangeError); | ||
| } | ||
| } |
This file contains hidden or 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,111 @@ | ||
| #include <js_native_api.h> | ||
| #include <string.h> | ||
| #include "../common.h" | ||
| #include "../entry_point.h" | ||
|
|
||
| static napi_value CreateDataView(napi_env env, napi_callback_info info) { | ||
| size_t argc = 3; | ||
| napi_value args [3]; | ||
| NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
|
||
| NODE_API_ASSERT(env, argc == 3, "Wrong number of arguments"); | ||
|
|
||
| napi_valuetype valuetype0; | ||
| napi_value arraybuffer = args[0]; | ||
|
|
||
| NODE_API_CALL(env, napi_typeof(env, arraybuffer, &valuetype0)); | ||
| NODE_API_ASSERT(env, valuetype0 == napi_object, | ||
| "Wrong type of arguments. Expects a ArrayBuffer as the first " | ||
| "argument."); | ||
|
|
||
| bool is_arraybuffer; | ||
| NODE_API_CALL(env, napi_is_arraybuffer(env, arraybuffer, &is_arraybuffer)); | ||
|
|
||
| if (!is_arraybuffer) { | ||
| bool is_sharedarraybuffer; | ||
| NODE_API_CALL( | ||
| env, | ||
| node_api_is_sharedarraybuffer(env, arraybuffer, &is_sharedarraybuffer)); | ||
| NODE_API_ASSERT(env, | ||
| is_sharedarraybuffer, | ||
| "Wrong type of arguments. Expects a SharedArrayBuffer or " | ||
| "ArrayBuffer as the first " | ||
| "argument."); | ||
| } | ||
|
|
||
| napi_valuetype valuetype1; | ||
| NODE_API_CALL(env, napi_typeof(env, args[1], &valuetype1)); | ||
|
|
||
| NODE_API_ASSERT(env, valuetype1 == napi_number, | ||
| "Wrong type of arguments. Expects a number as second argument."); | ||
|
|
||
| size_t byte_offset = 0; | ||
| NODE_API_CALL(env, napi_get_value_uint32(env, args[1], (uint32_t*)(&byte_offset))); | ||
|
|
||
| napi_valuetype valuetype2; | ||
| NODE_API_CALL(env, napi_typeof(env, args[2], &valuetype2)); | ||
|
|
||
| NODE_API_ASSERT(env, valuetype2 == napi_number, | ||
| "Wrong type of arguments. Expects a number as third argument."); | ||
|
|
||
| size_t length = 0; | ||
| NODE_API_CALL(env, napi_get_value_uint32(env, args[2], (uint32_t*)(&length))); | ||
|
|
||
| napi_value output_dataview; | ||
| NODE_API_CALL(env, | ||
| napi_create_dataview(env, length, arraybuffer, | ||
| byte_offset, &output_dataview)); | ||
|
|
||
| return output_dataview; | ||
| } | ||
|
|
||
| static napi_value CreateDataViewFromJSDataView(napi_env env, napi_callback_info info) { | ||
| size_t argc = 1; | ||
| napi_value args [1]; | ||
| NODE_API_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); | ||
|
|
||
| NODE_API_ASSERT(env, argc == 1, "Wrong number of arguments"); | ||
|
|
||
| napi_valuetype valuetype; | ||
| napi_value input_dataview = args[0]; | ||
|
|
||
| NODE_API_CALL(env, napi_typeof(env, input_dataview, &valuetype)); | ||
| NODE_API_ASSERT(env, valuetype == napi_object, | ||
| "Wrong type of arguments. Expects a DataView as the first " | ||
| "argument."); | ||
|
|
||
| bool is_dataview; | ||
| NODE_API_CALL(env, napi_is_dataview(env, input_dataview, &is_dataview)); | ||
| NODE_API_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; | ||
| NODE_API_CALL(env, | ||
| napi_get_dataview_info(env, input_dataview, &length, NULL, | ||
| &buffer, &byte_offset)); | ||
|
|
||
| napi_value output_dataview; | ||
| NODE_API_CALL(env, | ||
| napi_create_dataview(env, length, buffer, | ||
| byte_offset, &output_dataview)); | ||
|
|
||
|
|
||
| return output_dataview; | ||
| } | ||
|
|
||
| EXTERN_C_START | ||
| napi_value Init(napi_env env, napi_value exports) { | ||
| napi_property_descriptor descriptors[] = { | ||
| DECLARE_NODE_API_PROPERTY("CreateDataView", CreateDataView), | ||
| DECLARE_NODE_API_PROPERTY("CreateDataViewFromJSDataView", | ||
| CreateDataViewFromJSDataView) | ||
| }; | ||
|
|
||
| NODE_API_CALL(env, napi_define_properties( | ||
| env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); | ||
|
|
||
| return exports; | ||
| } | ||
| EXTERN_C_END |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
PARSE_ARGVusage isn't picking the sources correctly. We can just do what we do in theadd_node_cts_addon.