mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 17:57:53 +00:00

At the last TC39 meeting, a new type of Module Records backed by JavaScript source called Dynamic Module Records was discussed, and it is now at Stage 1. Regardless of whether that proposal makes it all the way into the spec, SourceTextModule is indeed a more descriptive and accurate name for what this class represents. PR-URL: https://github.com/nodejs/node/pull/22007 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
49 lines
992 B
JavaScript
49 lines
992 B
JavaScript
'use strict';
|
|
|
|
// Flags: --experimental-vm-modules
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { SourceTextModule } = require('vm');
|
|
|
|
const finished = common.mustCall();
|
|
|
|
(async function main() {
|
|
{
|
|
const m = new SourceTextModule('1');
|
|
await m.link(common.mustNotCall());
|
|
m.instantiate();
|
|
assert.strictEqual((await m.evaluate()).result, 1);
|
|
assert.strictEqual((await m.evaluate()).result, undefined);
|
|
assert.strictEqual((await m.evaluate()).result, undefined);
|
|
}
|
|
|
|
{
|
|
const m = new SourceTextModule('throw new Error()');
|
|
await m.link(common.mustNotCall());
|
|
m.instantiate();
|
|
|
|
let threw = false;
|
|
try {
|
|
await m.evaluate();
|
|
} catch (err) {
|
|
assert(err instanceof Error);
|
|
threw = true;
|
|
}
|
|
assert(threw);
|
|
|
|
threw = false;
|
|
try {
|
|
await m.evaluate();
|
|
} catch (err) {
|
|
assert(err instanceof Error);
|
|
threw = true;
|
|
}
|
|
assert(threw);
|
|
}
|
|
|
|
finished();
|
|
})();
|