mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
vm: add importModuleDynamically option to compileFunction
Fixes: https://github.com/nodejs/node/issues/31860 PR-URL: https://github.com/nodejs/node/pull/32985 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
5 files changed
+63
-30
No files matched your search
@@ -8,7 +8,8 @@ const {
|
||||
Module,
|
||||
SourceTextModule,
|
||||
SyntheticModule,
|
||||
createContext
|
||||
createContext,
|
||||
compileFunction,
|
||||
} = require('vm');
|
||||
const util = require('util');
|
||||
|
||||
@@ -147,3 +148,19 @@ const util = require('util');
|
||||
name: 'TypeError'
|
||||
});
|
||||
}
|
||||
|
||||
// Test compileFunction importModuleDynamically
|
||||
{
|
||||
const module = new SyntheticModule([], () => {});
|
||||
module.link(() => {});
|
||||
const f = compileFunction('return import("x")', [], {
|
||||
importModuleDynamically(specifier, referrer) {
|
||||
assert.strictEqual(specifier, 'x');
|
||||
assert.strictEqual(referrer, f);
|
||||
return module;
|
||||
},
|
||||
});
|
||||
f().then((ns) => {
|
||||
assert.strictEqual(ns, module.namespace);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user