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

Symbol.dispose is undefined when calling vm.runInNewContext #50745

Closed
cesaryuan opened this issue Nov 15, 2023 · 7 comments
Closed

Symbol.dispose is undefined when calling vm.runInNewContext #50745

cesaryuan opened this issue Nov 15, 2023 · 7 comments
Labels
vm Issues and PRs related to the vm subsystem.

Comments

@cesaryuan
Copy link

Version

21.2.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

vm

What steps will reproduce the bug?

PS E:\code> node
Welcome to Node.js v21.2.0.       
Type ".help" for more information.
> const vm = require('node:vm')
undefined
> vm.runInNewContext("Symbol.dispose")
undefined
> vm.runInNewContext("Symbol")
[Function: Symbol]

How often does it reproduce? Is there a required condition?

Can be reproduced stably

What is the expected behavior? Why is that the expected behavior?

Symbol.dispose should not be undefined. Because it is avaliable in globally, so it should also be avaliable in vm.

What do you see instead?

vm.runInNewContext("Symbol.dispose") outputs undefined.

Additional information

No response

@kvakil kvakil added the vm Issues and PRs related to the vm subsystem. label Nov 16, 2023
@joyeecheung
Copy link
Member

These symbols are polyfilled by Node.js so they are currently only available in Node.js contexts. I guess we can also polyfill it in the vm context, though I am not too fond of the idea of polyfilling something that should be implemented by V8 in the first place..

@aduh95
Copy link
Contributor

aduh95 commented Nov 21, 2023

For reference, the V8 issue tracking this is https://bugs.chromium.org/p/v8/issues/detail?id=13559

@malthe
Copy link
Contributor

malthe commented Nov 21, 2023

This issue shows up also when running tests using jest – since tests run in a vm context.

Note that for example Symbol.asyncIterator is defined.

@MoLow
Copy link
Member

MoLow commented Nov 23, 2023

@malthe is the disposable resource a resource created by your code or internally by node?
if you can provide some reproduction, we might come up with a workaround

@malthe
Copy link
Contributor

malthe commented Nov 23, 2023

The disposable resource is created by my code – it's a database connection.

Now, in TypeScript 5.2, this actually works now because of polyfilling. However, in the VM context, this does not work because the symbols aren't defined.

@legendecas
Copy link
Member

legendecas commented Sep 2, 2024

Please use a proper polyfill library like babel-polyfills or core-js explicit resource-management to get full feature polyfill.

The Symbol.dipose was polyfilled in Node.js for experimental support in built-in classes. But this was released without hiding behind an experimental flag. The current implementation of explicit resource management proposal in Node.js is incomplete.

I don't think there is anything we can do like hiding the feature with experimental flag or emit a warning as it could break existing pioneers depend on this symbol (#54329). Please follow https://issues.chromium.org/issues/42203506 for future implementation status in V8.

@legendecas legendecas added the known limitation Issues that are identified as known limitations. label Sep 2, 2024
@legendecas
Copy link
Member

Fixed in 9d7cd9b with cli flag --js-explicit-resource-management.

@legendecas legendecas removed the known limitation Issues that are identified as known limitations. label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

7 participants