-
Notifications
You must be signed in to change notification settings - Fork 97
worker: implement MessagePort
and MessageChannel
#98
Conversation
src/env.h
Outdated
@@ -92,6 +92,7 @@ class ModuleWrap; | |||
V(decorated_private_symbol, "node:decorated") \ | |||
V(npn_buffer_private_symbol, "node:npnBuffer") \ | |||
V(processed_private_symbol, "node:processed") \ | |||
V(sab_lifetimepartner_symbol, "node:sharedArrayBufferLiftimePartner") \ |
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.
typo? node:sharedArrayBufferLiftimePartner -> node:sharedArrayBufferLifetimePartner
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.
a) yes, thank you and b) it wasn’t even meant to be in this commit 😄 I’ve fixed it in #58, though
d27a8dc
to
dd54fc7
Compare
References: |
I assume "along the lines" is mostly referring to the differences in event listener interfaces ( |
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.
More review coming.
lib/internal/worker.js
Outdated
} | ||
|
||
Object.defineProperty(MessagePort.prototype, 'onmessage', { | ||
enumerable: false, |
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.
Make it enumerable for consistency.
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.
Hm – the idea here was consistency with ES6 class methods, but I guess you’re right, this should match the native ones
src/env.h
Outdated
@@ -317,6 +322,7 @@ class ModuleWrap; | |||
V(promise_wrap_template, v8::ObjectTemplate) \ | |||
V(push_values_to_array_function, v8::Function) \ | |||
V(randombytes_constructor_template, v8::ObjectTemplate) \ | |||
V(sab_lifetimepartner_constructor_template, v8::FunctionTemplate) \ |
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 this be in this commit?
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.
nope :)
using v8::ValueSerializer; | ||
|
||
namespace node { | ||
namespace worker { |
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.
Make it namespace messaging
for consistency with the file name?
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.
well … it’s still conceptually part of the worker
code, isn’t it?
There's that, and also some additional APIs like |
src/node_messaging.cc
Outdated
// Factor generating the MessagePort JS constructor into its own piece | ||
// of code, because it is needed early on in the child environment setup. | ||
Local<FunctionTemplate> templ; | ||
templ = env->message_port_constructor_template(); |
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.
Merge these two lines?
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 :)
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.
Other than one question, it all LGTM.
this.ref(); | ||
this.start(); | ||
} | ||
}); |
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.
Changing onmessage
will stop the message
and flaggedMessage
events from being emitted. Is that intended behaviour?
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, I would say so. This is only there to match the Web spec more closely, but in that case you don’t want the EventEmitter interface anyways I guess.
@TimothyGu For context - I was trying to figure out how hard it would be to write portable code against this, so I wasn't worried too much about additional properties and more about meaningful API overlap. I assume the absence of |
@jkrems Hm, yes. We could add missing methods to the |
I'm somewhat partial towards "make it a clean superset of the existing/spec browser API" but I'm not sure how realistic that is (and how much value it would provide in practice). Adding |
@jkrems Do you want to try & take a stab at this yourself? The trickiest thing I guess would be the interaction of all 3 event emitter systems ( |
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s.
de35803
to
c1d07d1
Compare
c1d07d1
to
582b756
Compare
The missing bits could probably also just be added later. |
Landed in f65bb3d |
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. PR-URL: #98 Reviewed-By: Stephen Belanger <[email protected]>
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98 PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98 PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Implement `MessagePort` and `MessageChannel` along the lines of the DOM classes of the same names. `MessagePort`s initially support transferring only `ArrayBuffer`s. Thanks to Stephen Belanger for reviewing this change in its original form, to Benjamin Gruenbaum for reviewing the added tests in their original form, and to Olivia Hugger for reviewing the documentation in its original form. Refs: ayojs/ayo#98 PR-URL: #20876 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
Implement
MessagePort
andMessageChannel
along the lines ofthe DOM classes of the same names.
MessagePort
s initiallysupport transferring only
ArrayBuffer
s.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
worker