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

New Strategic Initiative on ShadowRealm #1221

Closed
legendecas opened this issue May 4, 2022 · 4 comments · Fixed by nodejs/node#43037
Closed

New Strategic Initiative on ShadowRealm #1221

legendecas opened this issue May 4, 2022 · 4 comments · Fixed by nodejs/node#43037

Comments

@legendecas
Copy link
Member

legendecas commented May 4, 2022

ShadowRealm is a stage 3 TC39 proposal. ShadowRealm provides a strong guarantee on isolating object graphs between different JavaScript executing contexts and introduces a new built-in to provide a distinct global environment. ShadowRealm also ensures the module graph it uses is isolated from its outer contexts.

It may sound similar to the Node.js vm module at the first look, but it actually opens up a different possibility for running code modules in one Isolate without interfering with each other. I've posted an issue to discuss the details about this: nodejs/node#42528.

The web is adopting ShadowRealm. They are working on exposing a curated useful web built-in APIs to the ShadowRealm, like EventTarget, Stream, etc. This is what Node.js vm module is missing all the time: people pass the outer builtin API objects into the VM and get confused by the obscure obj instanceof Object result, or have to find the alternatives in the wild and require them in the vm. Apart from the built-in APIs, there are also global events like uncaughtException and unhandledRejection, and async_hooks that need to be designed to fit in the model correctly.

To support exposing Node.js own built-in API in the ShadowRealm (or maybe in the vm too!), we need to disentangle the native modules from the main context and make it possible to evaluate those native modules in the ShadowRealm's context again. This could be a lot of work since people are not aware of if a native module written in Node.js can be evaluated multiple times in one single Environment. It will be a good effort to refactor the codebase to disentangle this. Also, we may need to be able to snapshot the startup state too to boost the performance of creating the new contexts for ShadowRealm.

This work is likely to be a long-term effort and lots of decisions to make. I believe establishing a strategic initiative will help share progress and increase TSC awareness/attention on the topic. I'd be happy to champion the initiative.

@mhdawson
Copy link
Member

mhdawson commented May 4, 2022

This sounds like a good idea to me +1. I assume you would volunteer to be the champion?

@legendecas
Copy link
Member Author

I assume you would volunteer to be the champion?

Yes, I'd be happy to champion the initiative.

@ljharb
Copy link
Member

ljharb commented May 4, 2022

I think it’d be very challenging to implement because node would need a full membrane implementation, not just ShadowRealm (since many core node module functions require object identities to be input and preserved in the output), but it’s definitely worth exploring.

@mhdawson
Copy link
Member

I believe this issue can now be closed as its been added as a strategic initiative and there is another issue which ongoing discussion can take place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants