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

vm: update source, related basic & cached data tests for ArrayBuffer #22921

Closed
wants to merge 10 commits into from
Closed

vm: update source, related basic & cached data tests for ArrayBuffer #22921

wants to merge 10 commits into from

Conversation

BeniCheni
Copy link
Contributor

Refs: #1826

Referring to the comment in "mentor-available" #1826, this PR tries out the vm item from the checklist of the comment:

  • accept ArrayBufferView type(s) in place of Uint8Array in the source

  • related test code in test-vm-basic.js & test-vm-cached-data.js.

(P.S.: if any potential test case(s) or vm doc update is missed, please advise. Thanks!)

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

targos
targos previously requested changes Sep 18, 2018
Copy link
Member

@targos targos left a comment

Choose a reason for hiding this comment

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

The native code must be changed to handle the new allowed types.

@targos
Copy link
Member

targos commented Sep 18, 2018

Example showing that the C++ part is not ready for it:

'use strict';

const vm = require('vm');

let script = new vm.Script('var x = 0;', { produceCachedData: true });
const cachedData = script.cachedData;

new vm.Script('var x = 0;', { cachedData: new Uint16Array(cachedData.buffer) } );
$ ./node test.js
./node[10954]: ../src/node_contextify.cc:685:static void node::contextify::ContextifyScript::New(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `args[4]->IsUint8Array()' failed.
 1: 0x8dbd90 node::Abort() [./node]
 2: 0x8dbe65  [./node]
 3: 0x910fea node::contextify::ContextifyScript::New(v8::FunctionCallbackInfo<v8::Value> const&) [./node]
 4: 0xb6e1f1  [./node]
 5: 0xb6e7bf  [./node]
 6: 0x1c3b281cfc3d 
[1]    10954 abort (core dumped)  ./node test.js

@BeniCheni
Copy link
Contributor Author

BeniCheni commented Sep 26, 2018

Thank you, @ targos / ping reviewer(s).

Learned about the “vm” module & dug deeper in the node_contextify.cc code, based on the stack-trace error from your helpful test case, and able to use ArrayBufferView/IsArrayBufferView in places of Uint8Array/IsUint8Array. Please review at your convenience,

Tested w. the following test snippet:

‘use strict';

const vm = require('vm');

let script = new vm.Script('var x = 0;', { produceCachedData: true });
const cachedData = script.cachedData;

new vm.Script('var x = 0;', { cachedData: new Uint16Array(cachedData.buffer) } )

@BeniCheni
Copy link
Contributor Author

BeniCheni commented Oct 1, 2018

Ping/Dear reviewers,

Friendly reminder that - Made updates according per previous review comments, & was able to passed the suggested “vm” test w. cached data. Please review again at convenience.

Copy link
Member

@lundibundi lundibundi left a comment

Choose a reason for hiding this comment

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

I think change to the doc is missing here https://github.com/nodejs/node/blob/master/doc/api/vm.md#new-vmscriptcode-options and here https://github.com/nodejs/node/blob/master/doc/api/vm.md#vmcompilefunctioncode-params-options.

Also, I don't see any tests for TypedArray or DataView as cachedData, is there any?

@BeniCheni
Copy link
Contributor Author

BeniCheni commented Oct 3, 2018

@lundibundi,

I think change to the doc is missing here https://github.com/nodejs/node/blob/master/doc/api/vm.md#new-vmscriptcode-options and here https://github.com/nodejs/node/blob/master/doc/api/vm.md#vmcompilefunctioncode-params-options.

Updated the "cachedData" description for new-vmscriptcode-options & vmcompilefunctioncode-params-options docs. Thank you!

Also, I don't see any tests for TypedArray or DataView as cachedData, is there any?

The updated test in test/parallel/test-vm-cached-data.js for ERR_INVALID_ARG_TYPE should cover cachedData with the validation of TypedArray & DataView type error.

Please guide me other test(s) that'd add test for TypedArray or DataView as cachedData?

{
  code: 'ERR_INVALID_ARG_TYPE',
  type: TypeError,
-message: /must be one of type Buffer or Uint8Array/
+message: /must be one of type Buffer, TypedArray, or DataView/
}

@lundibundi
Copy link
Member

Thanks for the swift changes =). It seems there is no reasonable way to test for cachedData besides simple arg checks, so it should be fine.

Though, I cannot understand how can we actually get the cachedData in anything besides Buffer. IIRC https://nodejs.org/api/vm.html#vm_script_createcacheddata is the only way to get cachedData therefore is there any sense of having cachedData available as TypedArray or DataView?

Also, this line https://github.com/nodejs/node/pull/22921/files#diff-0cf206672499c2f86db4ffb0cc5b668bR683 and this https://github.com/nodejs/node/pull/22921/files#diff-0cf206672499c2f86db4ffb0cc5b668bR1019 extracts data as uint8_t will this still be correct if we pass i.e. Int32Array (it should work but would that be correct)?

@BeniCheni
Copy link
Contributor Author

@lundibundi and/or other dear reviewers,

Per these two topics, I'd need some guideline to know how to update the PR to move forward. Would you mind advising?

...sense of having cachedData available as TypedArray or DataView"

...extracts data as uint8_t will this still be correct if we pass i.e. Int32Array (it should work but would that be correct)?

@BeniCheni
Copy link
Contributor Author

Ping / dear reviewers,

Would you mind guiding this PR for next step based on the questions in last comment? (Hoping the PR would not become stale; thank you!)

@lundibundi
Copy link
Member

lundibundi commented Oct 6, 2018

ping @addaleax @jasnell @targos as the ones who reviewed this could you provide some input on #22921 (comment)?

Just to be clear: I'm not blocking this, my concern is - maybe it's worth changing something here for it to become a bit more relevant.

CI: https://ci.nodejs.org/job/node-test-pull-request/17668/

@TimothyGu
Copy link
Member

I don’t quite see any tests for the newly supported types. You could use the common.getArrayBufferViews() function to make sure all TypedArray and DataView types are actually supported. Check out https://github.com/nodejs/node/blob/master/test/parallel/test-fs-write-file-typedarrays.js for an example

@BeniCheni
Copy link
Contributor Author

BeniCheni commented Oct 21, 2018

Ping / dear reviewers,

Per the suggestion in last comment, I've rebased & updated the tests in "test-vm-cached-data.js" to use common.getArrayBufferViews() function, to ensure all TypedArray and DataView types are actually supported. Please review again at convenience.

(P.S.: sorry about the delayed update. Was in Node+JS Interactive (glad to meet some of you in person), & a busy week at work after the conf. Looking forward to your review again to pick back up this PR, to work towards landing/closure. 🙏 )

for (const parsedData of common.getArrayBufferViews(data)) {
// It should consume code cache
const script = new vm.Script(source, {
cachedData: parsedData
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I'd prefer to just rename parsedData -> cachedData and the this line will become just

Suggested change
cachedData: parsedData
cachedData

@lundibundi
Copy link
Member

lundibundi commented Oct 23, 2018

CI: https://ci.nodejs.org/job/node-test-pull-request/18070/

Also, ping @targos, I believe your concerns were addressed.

@targos targos dismissed their stale review October 23, 2018 13:05

native layer was updated and tests added

@BeniCheni
Copy link
Contributor Author

@lundibundi, updated to use cachedData, since the term is indeed more contextually aligned than parsedData. Please review again at convenience. Thank you!

(P.S: also thank you @targos for reviewing the "native layer" part!)

@BeniCheni
Copy link
Contributor Author

BeniCheni commented Oct 30, 2018

@lundibundi & reviewers,

Friendly reminder that Updated to use cachedData variable name per nit in last comment.

Would you mind reviewing to see if the PR is okay for “author ready” label, since all previous feedback & advice have been addressed? Thank you!

@refack
Copy link
Contributor

refack commented Oct 30, 2018

@refack refack added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 30, 2018
In vm module, accept ArrayBuffer in place of Uint8Array in the source
code & related test code in "test-vm-basic.js" & "test-vm-cached-data.js", per
the "vm" item in the checklist of the comment in #1826.

Refs: #1826 (comment)
Use ArrayBufferView/IsArrayBufferView in places of Uint8Array/IsUint8Array,
in the node_contextify.cc source code.

Refs: #22921 (comment)
Update the "cachedData" description with support of TypedArray
or DataView support in “new vm.Script” & “vm.compileFunction”.
@refack
Copy link
Contributor

refack commented Nov 1, 2018

@Trott
Copy link
Member

Trott commented Nov 2, 2018

@refack
Copy link
Contributor

refack commented Nov 2, 2018

Landed in 65fe999 🎉

@refack refack closed this Nov 2, 2018
@refack refack added doc Issues and PRs related to the documentations. test Issues and PRs related to the tests. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Nov 2, 2018
refack pushed a commit that referenced this pull request Nov 2, 2018
PR-URL: #22921
Refs: #1826
Refs: #22921 (comment)
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
targos pushed a commit that referenced this pull request Nov 2, 2018
PR-URL: #22921
Refs: #1826
Refs: #22921 (comment)
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@BeniCheni BeniCheni deleted the vm-array-buffer-view branch November 2, 2018 22:33
@refack refack removed their assignment Nov 6, 2018
@MylesBorins MylesBorins added semver-minor PRs that contain new features and should be released in the next minor version. dont-land-on-v8.x labels Nov 27, 2018
BethGriggs pushed a commit that referenced this pull request Apr 8, 2019
PR-URL: #22921
Refs: #1826
Refs: #22921 (comment)
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
@BethGriggs BethGriggs mentioned this pull request May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. semver-minor PRs that contain new features and should be released in the next minor version. test Issues and PRs related to the tests. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.