mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c2d79208d6
Users cannot access any API that can be used to return a module or module namespace in this callback without --experimental-vm-modules anyway, so this would eventually lead to a rejection. This patch rejects in this case with our own error message and use a constant host-defined option for the rejection, so that scripts with the same source can still be compiled using the compilation cache if no `import()` is actually called in the script. PR-URL: https://github.com/nodejs/node/pull/50137 Refs: https://github.com/nodejs/node/issues/35375 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
29 lines
809 B
JavaScript
29 lines
809 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { Script, compileFunction } = require('vm');
|
|
const assert = require('assert');
|
|
|
|
assert(
|
|
!process.execArgv.includes('--experimental-vm-modules'),
|
|
'This test must be run without --experimental-vm-modules');
|
|
|
|
assert.rejects(async () => {
|
|
const script = new Script('import("fs")', {
|
|
importModuleDynamically: common.mustNotCall(),
|
|
});
|
|
const imported = script.runInThisContext();
|
|
await imported;
|
|
}, {
|
|
code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG'
|
|
}).then(common.mustCall());
|
|
|
|
assert.rejects(async () => {
|
|
const imported = compileFunction('return import("fs")', [], {
|
|
importModuleDynamically: common.mustNotCall(),
|
|
})();
|
|
await imported;
|
|
}, {
|
|
code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG'
|
|
}).then(common.mustCall());
|