Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Mar 7, 2019

src,lib: allow running multiple per-context files

Create an lib/internal/per_context/ directory that can
host 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 any
vm.Context.

worker: implement worker.moveMessagePortToContext()

This enables using MessagePorts in different vm.Contexts,
aiding with the isolation that the vm module seeks to provide.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@addaleax addaleax added vm Issues and PRs related to the vm subsystem. semver-minor PRs that contain new features and should be released in the next minor version. worker Issues and PRs related to Worker support. labels Mar 7, 2019
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Mar 7, 2019
@addaleax addaleax force-pushed the worker-messageport-move branch 4 times, most recently from b58679b to 1153455 Compare March 7, 2019 15:47
@addaleax
Copy link
Member Author

addaleax commented Mar 7, 2019

/cc @nodejs/workers

CI: https://ci.nodejs.org/job/node-test-pull-request/21303/

@addaleax
Copy link
Member Author

addaleax commented Mar 7, 2019

@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 MessagePorts in it?

@BridgeAR
Copy link
Member

BridgeAR commented Mar 8, 2019

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 8, 2019
@addaleax
Copy link
Member Author

addaleax commented Mar 9, 2019

@addaleax
Copy link
Member Author

addaleax commented Mar 9, 2019

/cc @nodejs/workers

Copy link
Member

@joyeecheung joyeecheung left a 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

src/api/environment.cc Show resolved Hide resolved
src/api/environment.cc Show resolved Hide resolved
FIXED_ONE_BYTE_STRING(isolate, "node:per_context_binding_exports"));

Local<Value> existing_value;
if (!global->GetPrivate(context, key).ToLocal(&existing_value))
Copy link
Member

@joyeecheung joyeecheung Mar 9, 2019

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.

Copy link
Member Author

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.

Copy link
Member

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...

@addaleax addaleax force-pushed the worker-messageport-move branch 3 times, most recently from 76070c3 to 8937fd6 Compare March 12, 2019 15:49
@addaleax
Copy link
Member Author

@addaleax
Copy link
Member Author

CI is green.

I’ll land this tomorrow if there are no objections, but I’d appreciate another review from @nodejs/workers.

@chjj
Copy link
Contributor

chjj commented Mar 13, 2019

@addaleax, yeah, that's a possibility. Someone could replicate the web worker scope exactly with vm I suppose. It's not something I'm personally interested in though since I think I'm more focused on making the browser behave like node.js instead of the other way around (though, my approach seems to be less popular these days).

chjj added a commit to chjj/bthreads that referenced this pull request Mar 14, 2019
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>
@addaleax
Copy link
Member Author

Sigh… Needed to update this because of test/parallel/test-bootstrap-modules.js.

CI: https://ci.nodejs.org/job/node-test-pull-request/21564/

@addaleax
Copy link
Member Author

Landed in 0752a18...fe8972a

@addaleax addaleax closed this Mar 15, 2019
@addaleax addaleax deleted the worker-messageport-move branch March 15, 2019 15:57
addaleax added a commit that referenced this pull request Mar 15, 2019
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>
addaleax added a commit that referenced this pull request Mar 15, 2019
This allows using `DOMException` from Node.js code for any
`vm.Context`.

PR-URL: #26497
Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax added a commit that referenced this pull request Mar 15, 2019
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>
targos pushed a commit that referenced this pull request Mar 27, 2019
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>
targos pushed a commit that referenced this pull request Mar 27, 2019
This allows using `DOMException` from Node.js code for any
`vm.Context`.

PR-URL: #26497
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Mar 27, 2019
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>
targos added a commit that referenced this pull request Mar 28, 2019
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
targos added a commit that referenced this pull request Mar 28, 2019
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
BethGriggs pushed a commit that referenced this pull request Apr 5, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. lib / src Issues and PRs related to general changes in the lib or src directory. semver-minor PRs that contain new features and should be released in the next minor version. vm Issues and PRs related to the vm subsystem. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants