Repository navigation
modules: implement deferred import for dynamic modules - #66727
MayaLekova wants to merge 1 commit into
Conversation
|
Review requested:
|
f8ef554 to
503ed1f
Compare
|
I tried fixing the @joyeecheung just FYI, I'll keep trying to fix it. |
| "});" | ||
| "await m.link(() => 0);" | ||
| "await m.evaluate();" | ||
| "await m.evaluate(-1, false, 3);" |
There was a problem hiding this comment.
This is the public API for the vm API, which is not used by the built-in loader at all, and it's not the same as the module wrap's evaluate, which is internal and used by both. There's no need to touch this.
There was a problem hiding this comment.
Gotcha, I don't know why exactly it hits the changed version of ModuleWrap::Evaluate. Without it, the same test crashes, but with different error:
[ RUN ] EnvironmentTest.EnvironmentWithESMLoader
(node:156113) ExperimentalWarning: VM Modules is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
# Node.js[156113]: static void node::loader::ModuleWrap::Evaluate(const v8::FunctionCallbackInfo<v8::Value>&) at ../../src/module_wrap.cc:789
# Assertion failed: (args.Length()) == (3)
----- Native stack trace -----
1: 0x5eb63c38fce4 [out/Release/cctest]
2: 0x5eb63c3909f9 node::Assert(node::AssertionInfo const&) [out/Release/cctest]
3: 0x5eb63c30ddd4 node::loader::ModuleWrap::Evaluate(v8::FunctionCallbackInfo<v8::Value> const&) [out/Release/cctest]
4: 0x785c5e58ffe9
----- JavaScript stack trace -----
1: evaluate (node:internal/vm/module:233:26)
2: /home/maya/Work/node/out/Release/cctest:1:328
3: processTicksAndRejections (node:internal/process/task_queues:104:5)
Aborted (core dumped)
There was a problem hiding this comment.
That is the public API wrapper, I think you need to pass in kEvaluationPhase in
node/lib/internal/vm/module.js
Line 233 in 46dc5d7
There was a problem hiding this comment.
Thanks, this was unintended to change the API.
|
Can you drop the amaro update commit? I don't think that's supposed to be in this PR? |
503ed1f to
930f23f
Compare
Yep, done. |
|
Hi @joyeecheung , could you please take a look again? This is the first version, with the cctest failure before my change to the test. |
930f23f to
cb19e4a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66727 +/- ##
==========================================
+ Coverage 90.50% 90.72% +0.21%
==========================================
Files 797 798 +1
Lines 277652 280058 +2406
Branches 53345 53874 +529
==========================================
+ Hits 251282 254071 +2789
+ Misses 16758 16281 -477
- Partials 9612 9706 +94
🚀 New features to boost your workflow:
|
1ecb21a to
236b046
Compare
|
Hi @joyeecheung, the PR seems in a good shape already. Could you please take a look? Also @guybedford, could you take a look as well? Just saw you were landing other module-related changes. This is wiring the Thank you both! |
|
Would it be a good idea add tests where the imported module on |
Thanks for the point! The synthetic modules code path is tested by this one: CommonJS and builtin modules seem to follow different paths:
|
236b046 to
709ca34
Compare
There's |
709ca34 to
21c9e24
Compare
|
@joyeecheung I've updated the implementation and made the JS tests more robust. Still there's this cctest failing, which shouldn't have its execution path affected: |
There was a problem hiding this comment.
Was this not true before? I think we should assert that it was empty before accessing the namespace too.
There was a problem hiding this comment.
It used to be true, as the module-with-module-tree.mjs was adding one entry to the eval_list (its imported eagerly and its dependency, which modifies the eval_list is also imported eagerly). I changed the latter, so now the dependency is deferred, too. Thus moved the assertion to where it makes sense, after the module-deferred-eval module evaluation is triggered, after accessing deferred.foo.
Also, adding the check you suggested, thanks!
This PR adds support for deferring the import of modules in additional cases, such as importing a dynamic module. It also adds a test for this case. Refs: https://github.com/tc39/proposal-defer-import-eval Signed-off-by: Maya Lekova <maya@igalia.com>
21c9e24 to
c24c6b2
Compare
modules: implement deferred import for dynamic modules
This PR adds support for deferring the import of modules in additional
cases, such as importing a dynamic module. It also adds a test for
this case.
Refs: https://github.com/tc39/proposal-defer-import-eval
Signed-off-by: Maya Lekova maya@igalia.com