Skip to content

Preserve the realm of the promise returned by importModuleDynamically in vm:SourceTextModule #53575

@lachrist

Description

@lachrist

What is the problem this feature will solve?

Dynamic imports in modules created by the vm:SourceTextModule currently return a promise created by the intrinsic Promise of the main realm and not the realm of the module. This can be a problem in practice because realms are commonly used to achieve test case isolation at a cheap performance cost. And these test cases might somehow rely on the identity of the constructor of promises returned by dynamic imports -- eg: https://github.com/tc39/test262/blob/c47b716e8d6bea0c4510d449fd22b7ed5f8b0151/test/language/expressions/dynamic-import/returns-promise.js

What is the feature you are proposing to solve the problem?

The problem comes from importModuleDynamicallyWrap which returns an async function:

function importModuleDynamicallyWrap(importModuleDynamically) {

If we want preserve the promise constructor provided by the user-defined importModuleDynamically , it should use explicit then chaining. NB: I'm not sure there is no other async jump downstream that could cause the same issue.

What alternatives have you considered?

No response

Activity

added
feature requestIssues that request new features to be added to Node.js.
on Jun 25, 2024
added
vmIssues and PRs related to the vm subsystem.
on Jun 26, 2024
github-actions

github-actions commented on Dec 24, 2024

@github-actions
Contributor

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Mark issue so that it is never considered stale label or close this issue if it should be closed. If not, the issue will be automatically 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.

github-actions

github-actions commented on Jan 24, 2025

@github-actions
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.vmIssues and PRs related to the vm subsystem.

    Type

    No type

    Projects

    Status

    Awaiting Triage

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @lachrist@legendecas@avivkeller

      Issue actions

        Preserve the realm of the promise returned by importModuleDynamically in vm:SourceTextModule · Issue #53575 · nodejs/node