blob: bcd91daebd0ff67c7c870e5498c6190c33a49c74 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
'use strict';
// Flags: --experimental-vm-modules --expose-internals
//
const common = require('../common');
const assert = require('assert');
const { types } = require('util');
const { SourceTextModule, wrapMap } = require('internal/vm/source_text_module');
const { importModuleDynamicallyCallback } =
require('internal/process/esm_loader');
async function getNamespace() {
const m = new SourceTextModule('');
await m.link(() => 0);
m.instantiate();
await m.evaluate();
return m.namespace;
}
(async () => {
const namespace = await getNamespace();
const m = new SourceTextModule('export const A = "A";', {
importModuleDynamically: common.mustCall((specifier, wrap) => {
return namespace;
})
});
await m.link(() => 0);
m.instantiate();
await m.evaluate();
const ns = await importModuleDynamicallyCallback(wrapMap.get(m));
assert.ok(types.isModuleNamespaceObject(ns));
})().then(common.mustCall());
|