mirror of
https://github.com/nodejs/node.git
synced 2025-05-20 21:13:12 +00:00

Adds vm.Module, which wraps around ModuleWrap to provide an interface for developers to work with modules in a more reflective manner. Co-authored-by: Timothy Gu <timothygu99@gmail.com> PR-URL: https://github.com/nodejs/node/pull/17560 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
28 lines
688 B
JavaScript
28 lines
688 B
JavaScript
'use strict';
|
|
|
|
// Flags: --experimental-vm-modules --experimental-modules --harmony-dynamic-import
|
|
|
|
const common = require('../common');
|
|
common.crashOnUnhandledRejection();
|
|
|
|
const assert = require('assert');
|
|
const { Module, createContext } = require('vm');
|
|
|
|
const finished = common.mustCall();
|
|
|
|
(async function() {
|
|
const m = new Module('import("foo")', { context: createContext() });
|
|
await m.link(common.mustNotCall());
|
|
m.instantiate();
|
|
const { result } = await m.evaluate();
|
|
let threw = false;
|
|
try {
|
|
await result;
|
|
} catch (err) {
|
|
threw = true;
|
|
assert.strictEqual(err.message, 'import() called outside of main context');
|
|
}
|
|
assert(threw);
|
|
finished();
|
|
}());
|