* 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
()
| 16 | */ |
| 17 | |
| 18 | async 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 | |
| 51 | async function testMissing() { |
| 52 | const ctx = createContext({}); |
no test coverage detected
searching dependent graphs…