Conversation
Basic support for Dataview is added by this commit. This is achieved by using three functions, napi_create_dataview(), napi_is_dataview() and napi_get_dataview_info(); Fixes: nodejs#13926
|
It seems there are two similar |
addaleax
left a comment
There was a problem hiding this comment.
Looks good to me! I only have a few comments left.
doc/api/n-api.md
Outdated
|
|
||
| #### *napi_create_dataview* | ||
| <!-- YAML | ||
| added: v8.0.0 |
| <!-- YAML | ||
| added: v8.0.0 | ||
| --> | ||
| ```C |
There was a problem hiding this comment.
Can you leave a newline before this?
doc/api/n-api.md
Outdated
| size_t length, | ||
| napi_value arraybuffer, | ||
| size_t byte_offset, | ||
| napi_value* result) |
There was a problem hiding this comment.
Can you align the arguments vertically (i.e. size_t length directly below napi_env env etc.?)
doc/api/n-api.md
Outdated
| - `[in] length`: Number of elements in the DataView. | ||
| - `[in] arraybuffer`: ArrayBuffer underlying the DataView. | ||
| - `[in] byte_offset`: The byte offset within the ArrayBuffer from which to | ||
| start projecting the DataVIew. |
There was a problem hiding this comment.
typo: DataView (also, I’d indent this line to be on the same indentation as `[in] …)
| added: v8.0.0 | ||
| --> | ||
| ```C | ||
| napi_status napi_get_dataview_info(napi_env env, |
doc/api/n-api.md
Outdated
| - `[out] length`: Number of elements in the DataView. | ||
| - `[out] data`: The data buffer underlying the DataView. | ||
| - `[out] byte_offset`: The byte offset within the data buffer from which | ||
| to start projecting the DataView. |
There was a problem hiding this comment.
Is documentation for arraybuffer missing?
doc/api/n-api.md
Outdated
| This API returns various properties of a DataView. | ||
|
|
||
| *Warning*: Use caution while using this API since the underlying data buffer | ||
| is managed by the VM |
There was a problem hiding this comment.
I don’t really know what this is saying? If you do use the napi_value* arraybuffer parameter, this should be okay, right?
| <!-- YAML | ||
| added: v8.0.0 | ||
| --> | ||
| ```C |
doc/api/n-api.md
Outdated
|
|
||
| Returns `napi_ok` if the API succeeded. | ||
|
|
||
| This API checks if the Object passsed in is a dataview. |
src/node_api.cc
Outdated
| size_t length, | ||
| napi_value arraybuffer, | ||
| size_t byte_offset, | ||
| napi_value* result) { |
There was a problem hiding this comment.
Can you align the parameters here as well?
doc/api/n-api.md
Outdated
|
|
||
|
|
||
| JavaScript DataView Objects are described in | ||
| [Section 24.3](https://tc39.github.io/ecma262/#sec-dataview-objects) |
There was a problem hiding this comment.
Can you move the link to the bottom of the file.
There was a problem hiding this comment.
I see that every napi_create_x function refers to the ECMA standards within it's section through out the document. Shouldn't we stick to this format ?
There was a problem hiding this comment.
There was a problem hiding this comment.
This should now just be [Section 24.3][]. Search the file for Section 12.5.5 for an example.
doc/api/n-api.md
Outdated
|
|
||
| ### *napi_is_dataview* | ||
| <!-- YAML | ||
| added: v8.0.0 |
There was a problem hiding this comment.
REPLACEME here too please.
src/node_api.h
Outdated
| size_t* byte_offset); | ||
|
|
||
| NAPI_EXTERN napi_status napi_create_dataview(napi_env env, | ||
| size_t length, |
There was a problem hiding this comment.
Can you line up the args please.
|
|
||
| //create dataview | ||
| const buffer3 = new ArrayBuffer(128); | ||
| console.log(buffer3 instanceof ArrayBuffer); |
There was a problem hiding this comment.
Can you remove the console.log() calls.
| const test_dataview = require(`./build/${common.buildType}/test_dataview`); | ||
|
|
||
| //create dataview | ||
| const buffer3 = new ArrayBuffer(128); |
There was a problem hiding this comment.
Why is this named buffer3?
doc/api/n-api.md
Outdated
|
|
||
|
|
||
| JavaScript DataView Objects are described in | ||
| [Section 24.3](https://tc39.github.io/ecma262/#sec-dataview-objects) |
There was a problem hiding this comment.
This should now just be [Section 24.3][]. Search the file for Section 12.5.5 for an example.
doc/api/n-api.md
Outdated
| [Working with JavaScript Properties]: #n_api_working_with_javascript_properties | ||
| [Working with JavaScript Values]: #n_api_working_with_javascript_values | ||
| [Working with JavaScript Values - Abstract Operations]: #n_api_working_with_javascript_values_abstract_operations | ||
| [Section 24.3]: https://tc39.github.io/ecma262/#sec-dataview-objects |
There was a problem hiding this comment.
Can you move this up a few lines to keep the links sorted. This should come after the Section 12.5.5 link.
doc/api/n-api.md
Outdated
|
|
||
| ```C | ||
| napi_status napi_create_dataview(napi_env env, | ||
| size_t length, |
There was a problem hiding this comment.
length should be byte_length for clarity.
| Dataview objects provide an array-like view over an underlying data buffer, | ||
| but one which allows items of different size and type in the ArrayBuffer. | ||
|
|
||
|
|
There was a problem hiding this comment.
napi_create_typedarray() has
It's required that (length * size_of_element) + byte_offset should be <= the size in bytes of the array passed in. If not, a RangeError exception is raised.
There should one here as well, with "(length * size_of_element)" replaced with byte_length.
doc/api/n-api.md
Outdated
| ```C | ||
| napi_status napi_get_dataview_info(napi_env env, | ||
| napi_value dataview, | ||
| size_t* bytelength, |
There was a problem hiding this comment.
byte_length for consistency with other functions.
|
|
||
| NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); | ||
| NAPI_ASSERT(env, valuetype == napi_object, | ||
| "Wrong type of argments. Expects a dataview as the first argument."); |
There was a problem hiding this comment.
Align the arguments please, like so:
NAPI_ASSERT(env, valuetype == napi_object,
"Wrong type of argument. 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 arugments. Expects a dataview as first argument."); |
| size_t length = 0; | ||
| napi_value buffer; | ||
| NAPI_CALL(env, napi_get_dataview_info( | ||
| env, input_dataview, &length, NULL, &buffer, &byte_offset)); |
There was a problem hiding this comment.
NAPI_CALL(env,
napi_get_dataview_info(env, input_dataview, &byte_length, NULL,
&buffer, &byte_offset));| }; | ||
|
|
||
| NAPI_CALL_RETURN_VOID(env, napi_define_properties( | ||
| env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); |
There was a problem hiding this comment.
Not sure how do I format this 😁
There was a problem hiding this comment.
Just add two more spaces, so that env, … is indented four columns more than the beginning of the statement :)
doc/api/n-api.md
Outdated
| Dataview objects provide an array-like view over an underlying data buffer, | ||
| but one which allows items of different size and type in the ArrayBuffer. | ||
|
|
||
| It's required that (byte_length * size_of_element) + byte_offset |
There was a problem hiding this comment.
size_of_element is always 1 for DataView. Delete the * size_of_element part plesse
| NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); | ||
| NAPI_ASSERT(env, valuetype == napi_object, | ||
| "Wrong type of argments. Expects a dataview as the first" | ||
| "argument."); |
There was a problem hiding this comment.
Reminder to whoever lands this: extra space in front.
|
LGTM. Thanks @shivanth! |
|
CI: https://ci.nodejs.org/job/node-test-commit/11385/ This should be ready now, if CI comes back good and this isn’t landed tomorrow, please bump this thread. :) |
|
|
||
| NAPI_CALL(env, napi_typeof(env, input_dataview, &valuetype)); | ||
| NAPI_ASSERT(env, valuetype == napi_object, | ||
| "Wrong type of argments. Expects a dataview as the first" |
There was a problem hiding this comment.
Spelling: argments, and an additional space between dataview and as.
As dataview refers to a type here, I think DataView would be better.
There was a problem hiding this comment.
Also, there is no space between first and argument..
|
|
||
| Returns `napi_ok` if the API succeeded. | ||
|
|
||
| This API checks if the Object passsed in is a DataView. |
| Returns `napi_ok` if the API succeeded. | ||
|
|
||
| This API creates a JavaScript DataView object over an existing ArrayBuffer. | ||
| Dataview objects provide an array-like view over an underlying data buffer, |
| Dataview objects provide an array-like view over an underlying data buffer, | ||
| but one which allows items of different size and type in the ArrayBuffer. | ||
|
|
||
| It's required that byte_length + byte_offset |
There was a problem hiding this comment.
Maybe put byte_length + byte_offset in backticks? Also, I think we prefer formal language (It is) over shortness.
| but one which allows items of different size and type in the ArrayBuffer. | ||
|
|
||
| It's required that byte_length + byte_offset | ||
| should be <= the size in bytes of the array passed in. If not, a RangeError |
There was a problem hiding this comment.
"It is required that ... should be" does not make sense in my head (I am not a native English speaker though).
|
|
||
| v8::Local<v8::DataView> array = value.As<v8::DataView>(); | ||
|
|
||
|
|
There was a problem hiding this comment.
Nit: I would try to avoid multiple consecutive empty lines within functions. It usually does not improve readability.
| bool is_dataview; | ||
| NAPI_CALL(env, napi_is_dataview(env, input_dataview, &is_dataview)); | ||
| NAPI_ASSERT(env,is_dataview, | ||
| "Wrong type of arugments. Expects a dataview as first argument."); |
There was a problem hiding this comment.
Spelling: arugments.
As dataview refers to a type here, I think DataView would be better.
There was a problem hiding this comment.
Also, this could just be the same message as above.
| }; | ||
|
|
||
| NAPI_CALL_RETURN_VOID(env,napi_define_properties( | ||
| env, exports,sizeof(descriptors) / sizeof(*descriptors), descriptors)); |
| DECLARE_NAPI_PROPERTY("CreateDataView", CreateDataView) | ||
| }; | ||
|
|
||
| NAPI_CALL_RETURN_VOID(env,napi_define_properties( |
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]>
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]>
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: nodejs#14382 Fixes: nodejs#13926 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
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(). Backport-PR-URL: #19447 PR-URL: #14382 Fixes: #13926 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
n-api
n-api: Add support for DataView …Basic support for Dataview is added by this commit. This is achieved by using three functions,
napi_create_dataview(),napi_is_dataview()andnapi_get_dataview_info().Fixes: #13926
(edited by @vsemozhetbyt: fix formatting