-
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
worker: add typechecking for postMessage transfer list #28033
worker: add typechecking for postMessage transfer list #28033
Conversation
If the transfer list argument is present, it should be an array. This commit adds typechecking to that effect. This aligns behaviour with browsers.
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 if CI is green
src/node_messaging.cc
Outdated
if (!args[1]->IsNullOrUndefined() && !args[1]->IsObject()) { | ||
// Browsers also do not throw on `null` or objects, although it really | ||
// should be an array or undefined, thus the mismatch between the checks | ||
// above and the actual error message. |
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 reason for this is due to the fact that browsers have an overload that accepts an option bag in addition to just a transfer list. See https://html.spec.whatwg.org/multipage/web-messaging.html#messageport. How browsers resolve the overloading is roughly something like this
- If second arg is undefined or null then ignore.
- If second arg is not an object (i.e., also not a function), then throw.
- Try to get the Symbol.iterator property of the second arg.
- If that throws, then rethrow the exception.
- If that returns anything other than undefined or function, also throw an exception.
- If it returns a function, then treat this as an iterable and use the equivalent of Array.from to convert it to a list.
- Otherwise (it returns undefined), then treat the second arg as an option bag. Try to get the transferList property and then convert it to a list through something like Array.from if present.
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.
@TimothyGu I’m adding a TODO comment in this PR and merge this with the current state, if that’s okay with you
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.
Yeah sure. You might encounter it as we try to pass more WPTs, so hope it'd be helpful.
Landed in 269c1d6 |
If the transfer list argument is present, it should be an array. This commit adds typechecking to that effect. This aligns behaviour with browsers. PR-URL: #28033 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
If the transfer list argument is present, it should be an array. This commit adds typechecking to that effect. This aligns behaviour with browsers. PR-URL: #28033 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Allow generic iterables as transfer list arguments, as well as an options object with a `transfer` option, for web compatibility. Refs: nodejs#28033 (comment)
Allow generic iterables as transfer list arguments, as well as an options object with a `transfer` option, for web compatibility. PR-URL: #29319 Refs: #28033 (comment) Reviewed-By: James M Snell <[email protected]>
Allow generic iterables as transfer list arguments, as well as an options object with a `transfer` option, for web compatibility. PR-URL: #29319 Refs: #28033 (comment) Reviewed-By: James M Snell <[email protected]>
If the transfer list argument is present, it should be an array.
This commit adds typechecking to that effect. This aligns behaviour
with browsers.
I’m also more than happy to label this semver-major.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes