-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
v8 module: allow TypedArray and DataView #23953
Conversation
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.
Nits made me ask a question about timing.
test/parallel/test-v8-serdes.js
Outdated
const length = des.readUint32(); | ||
const buf = des.readRawBytes(length); | ||
|
||
let length = des.readUint32(); |
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.
Please const
test/parallel/test-v8-serdes.js
Outdated
assert.strictEqual(buf.toString(), 'hostObjectTag'); | ||
for (let i = 0; i < arrayBufferViewsLength; i += 1) { | ||
length = des.readUint32(); |
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.
Could these be const length2
and const buf2
please?
Recycling variables should be avoided.
test/parallel/test-v8-serdes.js
Outdated
// `v8.serializer.writeRawBytes()` should support both `TypedArray` | ||
// and `DataView`. | ||
const arrayBufferViews = common.getArrayBufferViews(buf); | ||
arrayBufferViewsLength = arrayBufferViews.length; |
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.
Could this be const arrayBufferViewsLength
instead.
.
.
.
Which made be think isn't there a race here?
Is the callbacks guaranteed to be in order?
At minimum this should be documented in a comment
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.
Is the callbacks guaranteed to be in order?
Yes. We have only one HostObject
so that the callback will be called only once.
I think v8.Serializer.writeRawBytes()
being expected to be called inside of the callback of _writeHostObject
makes the test a bit confusing. I'm going to refactor this.
@oyyd as alway thank you for the contribution. While reviewing the code and looking at cases of variable recycling I found that I don't understand the operation order guarantee. |
test/parallel/test-v8-serdes.js
Outdated
@@ -66,6 +66,7 @@ const deserializerTypeError = | |||
} | |||
|
|||
{ | |||
let arrayBufferViewsLength; |
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.
Maybe simplest solution is to add a sentinel:
let has_writeHostObjectCalled = false;
the in _writeHostObject
has_writeHostObjectCalled = true;
the first line of _readHostObject
assert.ok(has_writeHostObjectCalled);
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.
or dual use arrayBufferViewsLength
- initialise it to false
, and then assert
des._readHostObject = common.mustCall(() => {
assert.notStrictEqual(false, arrayBufferViewsLength);
...
@refack Thanks for your advice! Comments addressed. I have separated the test for |
Looks 💯. Thank you for following up! |
This commit allow passing `TypedArray` and `DataView` to: - v8.deserialize() - new v8.Deserializer() - v8.serializer.writeRawBytes() PR-URL: nodejs#23953 Refs: nodejs#1826 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Landed in 56881b0 🎉 |
This commit allow passing `TypedArray` and `DataView` to: - v8.deserialize() - new v8.Deserializer() - v8.serializer.writeRawBytes() PR-URL: #23953 Refs: #1826 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This commit allow passing `TypedArray` and `DataView` to: - v8.deserialize() - new v8.Deserializer() - v8.serializer.writeRawBytes() PR-URL: #23953 Refs: #1826 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This commit allow passing
TypedArray
andDataView
to:v8.deserialize()
new v8.Deserializer()
v8.serializer.writeRawBytes()
Refs: #1826
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes