-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add a js class for Serializer/Dserializer #13541
Conversation
Calling Serializer/Deserlizer without new crashes node. Adding a js class which just inherits cpp bindings. Fixes: nodejs#13326
Can you add some regression tests? There were some gotchas around I expect it throws an 'illegal invocation' exception but it would be good to verify that. |
It does, we already extend it :) |
I mean when you extend the class that this PR introduces. |
@bnoordhuis, the classes this PR introduces are already extended further down the file by |
Okay. Regression tests for the other issues would still be good though. |
Calling Serializer/Deserlizer without new crashes node. Adding a js class which just inherits cpp bindings. Fixes: nodejs#13326
@bnoordhuis : Added regression tests. |
test/parallel/test-v8-serdes.js
Outdated
@@ -131,3 +131,19 @@ const objects = [ | |||
|
|||
assert.deepStrictEqual(v8.deserialize(buf), expectedResult); | |||
} | |||
|
|||
{ | |||
try { |
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.
Can you use assert.throws()
for these.
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.
@cjihrig : Made suggested changes.
Calling Serializer/Deserlizer without new crashes node. Adding a js class which just inherits cpp bindings. Added refression tests. Fixes: nodejs#13326
test/parallel/test-v8-serdes.js
Outdated
v8.Serializer(); | ||
}, | ||
Error, | ||
"Class constructor Serializer cannot be invoked without 'new'" |
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.
Can you do something more like this:
assert.throws(
() => { v8.Serializer(); },
/^Error: Class constructor Serializer cannot be invoked without 'new'$/
);
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.
@cjihrig : Done
88817fa
to
b72ec9c
Compare
There are typos in the commit message(s): s/Dserializer/Deserializer/ |
b72ec9c
to
cfb934e
Compare
@mscdex : Thanks, fixed |
Can somebody fire a CI job for this. |
s/refression/regression/ in commit message(s) too. |
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: nodejs#13326
cfb934e
to
9643c6c
Compare
@mscdex : Fixed on top review. |
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.
Still LGTM
lib/v8.js
Outdated
const { copy } = process.binding('buffer'); | ||
const { objectToString } = require('internal/util'); | ||
const { FastBuffer } = require('internal/buffer'); | ||
|
||
class Serializer extends serdesBindings.Serializer {} | ||
|
||
class Deserializer extends serdesBindings.Deserializer {} |
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.
I'd prefer something like:
const { Serializer: _Serializer, Deserializer: _Deserializer } = process.binding('serdes');
// ...
class Serializer extends _Serializer { }
class Deserializer extends _Deserializer { }
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.
Will resend.
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.
@jasnell : Made changes and added a note.
() => { v8.Deserializer(); }, | ||
/^TypeError: Class constructor Deserializer cannot be invoked without 'new'$/ | ||
); | ||
} |
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.
Should likely also add a note to the documentation clarifying the requirement
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: nodejs#13326
47cccbe
to
955a1bb
Compare
lib/v8.js
Outdated
@@ -15,11 +15,21 @@ | |||
'use strict'; | |||
|
|||
const { Buffer } = require('buffer'); | |||
const { Serializer, Deserializer } = process.binding('serdes'); | |||
const { | |||
Serializer: _Serializer, |
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.
Can you indent two spaces only?
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.
Done. BTW jslint didn't catch that error. May be we should add a rule?
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: nodejs#13326
Another CI run: https://ci.nodejs.org/job/node-test-pull-request/8588/ |
Tests pass on my mac osx sierra laptop. Above failures looks related to CI, can somebody start another run?. |
Yea, CI is a bit problematic right now, I’m not sure another run would solve much. This code isn’t platform-specific, though, so I think this is okay. |
@addaleax : Thanks, anything else for landing this?. |
@zimbabao Our rules say that we’ll need to wait until tomorrow to land this, but nothing from your side I think. :) |
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.
LGTM % docs
arm: #13603 |
Landed in 12fd63d, thanks for the PR! |
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: #13326 PR-URL: #13541 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Calling Serializer/Deserializer without new crashes node. Adding a js class which just inherits cpp bindings. Added regression tests. Fixes: #13326 PR-URL: #13541 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Calling Serializer/Deserlizer without new crashes node.
Adding a js class which just inherits cpp bindings.
Fixes: #13326
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes (test failing on master too)Affected core subsystem(s)