Skip to content

vm: import call should return a promise in the current context #58309

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented May 13, 2025

A import call should returns a promise created in the context where
the import was called, not the context of importModuleDynamically
callback.

This is also a requirement in ECMA262 https://tc39.es/ecma262/#sec-evaluate-import-call
step 7 and 14:

13.3.10.2 EvaluateImportCall ( specifierExpression [ , optionsExpression ] )
  ...
  7. Let promiseCapability be ! NewPromiseCapability(%Promise%).
  ...
  14. Return promiseCapability.[[Promise]].

Fixes: #53575

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels May 13, 2025
@legendecas legendecas force-pushed the vm/import-promise branch 3 times, most recently from 5b59a37 to 819f136 Compare May 13, 2025 10:41
@legendecas legendecas added the vm Issues and PRs related to the vm subsystem. label May 13, 2025
@legendecas legendecas force-pushed the vm/import-promise branch 2 times, most recently from 41a1ebe to 2a09b6e Compare May 13, 2025 11:09
A `import` call should returns a promise created in the context where
the `import` was called, not the context of `importModuleDynamically`
callback.
@legendecas legendecas force-pushed the vm/import-promise branch from 2a09b6e to 1b6a655 Compare May 13, 2025 11:11
@legendecas
Copy link
Member Author

Added a test to cover import rejection as well.

Copy link

codecov bot commented May 13, 2025

Codecov Report

Attention: Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.22%. Comparing base (28cbc4c) to head (b464995).
Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
src/module_wrap.cc 45.45% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #58309   +/-   ##
=======================================
  Coverage   90.21%   90.22%           
=======================================
  Files         633      633           
  Lines      186836   186821   -15     
  Branches    36671    36668    -3     
=======================================
+ Hits       168562   168564    +2     
+ Misses      11070    11045   -25     
- Partials     7204     7212    +8     
Files with missing lines Coverage Δ
src/module_wrap.cc 72.12% <45.45%> (-0.26%) ⬇️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels May 14, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 15, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

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. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve the realm of the promise returned by importModuleDynamically in vm:SourceTextModule
4 participants