MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

test/parallel/test-vm-module-referrer-realm.mjs:18–49  ·  view source on GitHub ↗

* This test verifies that dynamic import in an indirect eval without JS stacks. * In this case, the referrer for the dynamic import will be null and the * per-context importModuleDynamically callback will be invoked. * * Caveat: this test can be unstable if the loader internals are changed and p

()

Source from the content-addressed store, hash-verified

16 */
17
18async function test() {
19 const foo = new SourceTextModule('export const a = 1;');
20 await foo.link(common.mustNotCall());
21 await foo.evaluate();
22
23 const ctx = createContext({}, {
24 importModuleDynamically: common.mustCall((specifier, wrap) => {
25 assert.strictEqual(specifier, 'foo');
26 assert.strictEqual(wrap, ctx);
27 return foo;
28 }, 2),
29 });
30 {
31 const s = new Script('Promise.resolve("import(\'foo\')").then(eval)', {
32 importModuleDynamically: common.mustNotCall(),
33 });
34
35 const result = s.runInContext(ctx);
36 assert.strictEqual(await result, foo.namespace);
37 }
38
39 {
40 const m = new SourceTextModule('globalThis.fooResult = Promise.resolve("import(\'foo\')").then(eval)', {
41 context: ctx,
42 importModuleDynamically: common.mustNotCall(),
43 });
44 await m.link(common.mustNotCall());
45 await m.evaluate();
46 assert.strictEqual(await ctx.fooResult, foo.namespace);
47 delete ctx.fooResult;
48 }
49}
50
51async function testMissing() {
52 const ctx = createContext({});

Calls 4

runInContextMethod · 0.95
createContextFunction · 0.85
linkMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…