-
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: implement worker.moveMessagePortToContext() #26497
Conversation
b58679b
to
1153455
Compare
/cc @nodejs/workers |
@chjj I’m not a 100 % sure but this might also make it easier to implement something closer to a “real” WebWorker-style Environment in Node.js, because you can control the global object and still have |
e8b1b4a
to
bd0ef7a
Compare
Rebased, new CI: https://ci.nodejs.org/job/node-test-pull-request/21369/ |
/cc @nodejs/workers |
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 code generally LGTM but I have some questions
FIXED_ONE_BYTE_STRING(isolate, "node:per_context_binding_exports")); | ||
|
||
Local<Value> existing_value; | ||
if (!global->GetPrivate(context, key).ToLocal(&existing_value)) |
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 we use context->GetExtrasBindingObject()
to store these somehow instead of using v8 privates (which are...an experimental feature. Use at your own risk.
)? V8 already puts isTraceCategoryEnabled
and trace
in there.
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.
We’ve been using V8 privates extensively for a while, I don’t think they’re going away (and if they did we’d have bigger problems, e.g. N-API relies on them as well).
But yes, if you prefer, we could use the extras binding object for that … I feel like that’s mostly intended for actual v8-extras, but in theory nothing stops us, and I don’t mind making the switch if you prefer.
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.
@addaleax I don't have very strong opinions about the choices here...although I wonder what does this look like in the heap snapshot? Do they show up?
BTW, we probably need to do something similar for the Environment persistent handles (save them temporarily to the global proxy) when we implement snapshots...
76070c3
to
8937fd6
Compare
Rebased again, CI: https://ci.nodejs.org/job/node-test-pull-request/21464/ |
CI is green. I’ll land this tomorrow if there are no objections, but I’d appreciate another review from @nodejs/workers. |
@addaleax, yeah, that's a possibility. Someone could replicate the web worker scope exactly with |
Create an `lib/internal/per_context/` directory that can host multiple files which we execute for each context. PR-URL: nodejs#26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This allows using `DOMException` from Node.js code for any `vm.Context`. PR-URL: nodejs#26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This enables using `MessagePort`s in different `vm.Context`s, aiding with the isolation that the `vm` module seeks to provide. Refs: ayojs/ayo#111 PR-URL: nodejs#26497 Reviewed-By: James M Snell <jasnell@gmail.com>
8937fd6
to
23bf4ce
Compare
Sigh… Needed to update this because of |
Landed in 0752a18...fe8972a |
Create an `lib/internal/per_context/` directory that can host multiple files which we execute for each context. PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This allows using `DOMException` from Node.js code for any `vm.Context`. PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This enables using `MessagePort`s in different `vm.Context`s, aiding with the isolation that the `vm` module seeks to provide. Refs: ayojs/ayo#111 PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
Create an `lib/internal/per_context/` directory that can host multiple files which we execute for each context. PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This allows using `DOMException` from Node.js code for any `vm.Context`. PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This enables using `MessagePort`s in different `vm.Context`s, aiding with the isolation that the `vm` module seeks to provide. Refs: ayojs/ayo#111 PR-URL: #26497 Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes: * crypto * Allow deriving public from private keys (Tobias Nießen) [#26278](#26278). * events * Added a `once` function to use `EventEmitter` with promises (Matteo Collina) [#26078](#26078). * tty * Added a `hasColors` method to `WriteStream` (Ruben Bridgewater) [#26247](#26247). * Added NO_COLOR and FORCE_COLOR support (Ruben Bridgewater) [#26485](#26485). * v8 * Added `v8.getHeapSnapshot` and `v8.writeHeapSnapshot` to generate snapshots in the format used by tools such as Chrome DevTools (James M Snell) [#26501](#26501). * worker * Added `worker.moveMessagePortToContext`. This enables using MessagePorts in different vm.Contexts, aiding with the isolation that the vm module seeks to provide (Anna Henningsen) [#26497](#26497). * C++ API * `AddPromiseHook` is now deprecated. This API was added to fill an use case that is served by `async_hooks`, since that has `Promise` support (Anna Henningsen) [#26529](#26529). * Added a `Stop` API to shut down Node.js while it is running (Gireesh Punathil) [#21283](#21283). * meta * [Gireesh Punathil](https://github.com/gireeshpunathil) is now a member of the Technical Steering Committee [#26657](#26657). * Added [Yongsheng Zhang](https://github.com/ZYSzys) to collaborators [#26730](#26730). PR-URL: #26949
Notable changes: * crypto * Allow deriving public from private keys (Tobias Nießen) [#26278](#26278). * events * Added a `once` function to use `EventEmitter` with promises (Matteo Collina) [#26078](#26078). * tty * Added a `hasColors` method to `WriteStream` (Ruben Bridgewater) [#26247](#26247). * Added NO_COLOR and FORCE_COLOR support (Ruben Bridgewater) [#26485](#26485). * v8 * Added `v8.getHeapSnapshot` and `v8.writeHeapSnapshot` to generate snapshots in the format used by tools such as Chrome DevTools (James M Snell) [#26501](#26501). * worker * Added `worker.moveMessagePortToContext`. This enables using MessagePorts in different vm.Contexts, aiding with the isolation that the vm module seeks to provide (Anna Henningsen) [#26497](#26497). * C++ API * `AddPromiseHook` is now deprecated. This API was added to fill an use case that is served by `async_hooks`, since that has `Promise` support (Anna Henningsen) [#26529](#26529). * Added a `Stop` API to shut down Node.js while it is running (Gireesh Punathil) [#21283](#21283). * meta * [Gireesh Punathil](https://github.com/gireeshpunathil) is now a member of the Technical Steering Committee [#26657](#26657). * Added [Yongsheng Zhang](https://github.com/ZYSzys) to collaborators [#26730](#26730). PR-URL: #26949
Notable changes: * crypto * Allow deriving public from private keys (Tobias Nießen) [#26278](#26278). * events * Added a `once` function to use `EventEmitter` with promises (Matteo Collina) [#26078](#26078). * tty * Added a `hasColors` method to `WriteStream` (Ruben Bridgewater) [#26247](#26247). * Added NO_COLOR and FORCE_COLOR support (Ruben Bridgewater) [#26485](#26485). * v8 * Added `v8.getHeapSnapshot` and `v8.writeHeapSnapshot` to generate snapshots in the format used by tools such as Chrome DevTools (James M Snell) [#26501](#26501). * worker * Added `worker.moveMessagePortToContext`. This enables using MessagePorts in different vm.Contexts, aiding with the isolation that the vm module seeks to provide (Anna Henningsen) [#26497](#26497). * C++ API * `AddPromiseHook` is now deprecated. This API was added to fill an use case that is served by `async_hooks`, since that has `Promise` support (Anna Henningsen) [#26529](#26529). * Added a `Stop` API to shut down Node.js while it is running (Gireesh Punathil) [#21283](#21283). * meta * [Gireesh Punathil](https://github.com/gireeshpunathil) is now a member of the Technical Steering Committee [#26657](#26657). * Added [Yongsheng Zhang](https://github.com/ZYSzys) to collaborators [#26730](#26730). PR-URL: #26949
src,lib: allow running multiple per-context files
Create an
lib/internal/per_context/
directory that canhost multiple files which we execute for each context.
src,lib: make DOMException available in all Contexts
This allows using
DOMException
from Node.js code for anyvm.Context
.worker: implement worker.moveMessagePortToContext()
This enables using
MessagePort
s in differentvm.Context
s,aiding with the isolation that the
vm
module seeks to provide.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes