-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Evaluate node core modules within a vm.Context
#31852
Comments
I think we could expose this somewhat painlessly, whether we want to or not being a separate question. |
Ah, that's promising! What would be the reasons to not add this (beyond a larger api surface)? |
I’ve talked about this recently with other people, partially in the context of #28823. This is definitely doable, but it’s also going to be a lot of work. |
Thanks for that link, that's also something that would be great for us! We currently inject them manually, but they pose the same issues ( |
If cross-context support is not necessary, this can be done with an explicit option to include these globals during context creation, which tells Node.js to run the corresponding setups and create a different set of builtins for the context (from the top of my head, it should also be possible to make the option switch on/off Node.js-specific non browser globals). I believe it would be more difficult, or at least require more serialization/deserialization overhead, if we want the builtins from different contexts to interoperate with each other, however.
The source code is actually available through one of the |
You're referring to the node globals part (#28823) right? I'm not 100% sure what you mean with cross-context. I'm reasonably sure we wouldn't want any cross context stuff, as long as we could still override them from the outside. For example we can install fake timers and interact with them from the outside. But we wouldn't want 2 context's messing with each other, beyond the place creating a context being able to access it. Is that considered cross-context and would make it harder? |
@SimenB By cross-context operations I mean for example, passing a sandbox into the |
Ah okay, thanks for elaborating! The use case in the OP should be perfectly fine with that limitation, then. As for globals in user code, that limitation would present issues for us I think. For example our However, the code snippet I linked to would not be affected as in that case we just want what's inside the context to look like what's outside - we don't actually need to know what they are or access them. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Seeing as it was seen as (possibly) painless back in #31852 (comment), I'd still love to see this land! This would solve a long-standing issue in Jest which is the cause of unnecessary friction and causes people to think Jest is not fitting for testing plain Node apps (including messaging from projects in the nodejs organization on GH, which is... unfortunate) |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
By the way with the recent progress on ShadowRealms integration we should be closer to getting separate set of builtins implemented in vm contexts now. ShadowRealm mandates that each shadow realm has a completely isolated set of builtins, in the case of Node.js, that includes both JS builtins like |
Thanks for the update @joyeecheung! I'm very excited to hear about progress on this. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
No bot - this might still be possible down the line when shadowrealms is further along |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
😢 |
Yeah... I suppose the question is: is someone volunteering to do the work? It's definitely possible to implement this feature request but it's also definitely a lot of work. I'd like to see it happen but If no one is stepping up, then we might as well close this instead of letting it languish and pollute everyone's inbox every 6 months. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Also interested in these changes. I came here from the issue with testing transformers.js with jest. |
Is your feature request related to a problem? Please describe.
One of Jest's longest-standing issue are about globals in tests being different from Node's, see jestjs/jest#2549.
Short example illustrating the problem:
Run this example, and the
instanceof
test will fail. RemoveparsingContext
option, and it will pass.Describe the solution you'd like
Jest implements its own
require
etc, which works great most of the time, but in the case of node core modules, it fallbacks to requiring the module outside of the context. AFAIK the JS source of the node core modules are embedded in the binary of Node, so we cannot read them and pass them thoughcompileFunction
,SourceTextModule
or some such ourselves so the globals would be the same.It would be great if Node provided some API allowing the JS of core modules to be evaluated within a
vm.Context
.(I had originally given up on this, but seeing as #30709 solves the super old #855 I thought maybe we might be lucky enough that this is possible as well? 😀)
Describe alternatives you've considered
We have tried to mess around with setting
Symbol.hasInstance
and just injecting globals from the outside (although that breaks the encapsulation we're aiming for by using separateContext
s in the first place) without luck. It's also a moving target as we'd have to add that property to all globals.FWIW the Jest issue has a $500 bounty which I'd be happy to give to someone solving this in core, or the JS Foundation if that's more correct.
The text was updated successfully, but these errors were encountered: