mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
vm: rename vm.Module to vm.SourceTextModule
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>
This commit is contained in:
parent
3b23b4d7c0
commit
2bdcdfc3cb
14 changed files with 86 additions and 81 deletions
|
@ -6,7 +6,7 @@ const common = require('../common');
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
const { Module, createContext } = require('vm');
|
||||
const { SourceTextModule, createContext } = require('vm');
|
||||
|
||||
async function expectsRejection(fn, settings) {
|
||||
const validateError = common.expectsError(settings);
|
||||
|
@ -29,14 +29,14 @@ async function expectsRejection(fn, settings) {
|
|||
}
|
||||
|
||||
async function createEmptyLinkedModule() {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
await m.link(common.mustNotCall());
|
||||
return m;
|
||||
}
|
||||
|
||||
async function checkArgType() {
|
||||
common.expectsError(() => {
|
||||
new Module();
|
||||
new SourceTextModule();
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError
|
||||
|
@ -46,7 +46,7 @@ async function checkArgType() {
|
|||
0, 1, null, true, 'str', () => {}, { url: 0 }, Symbol.iterator
|
||||
]) {
|
||||
common.expectsError(() => {
|
||||
new Module('', invalidOptions);
|
||||
new SourceTextModule('', invalidOptions);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
type: TypeError
|
||||
|
@ -57,7 +57,7 @@ async function checkArgType() {
|
|||
0, 1, undefined, null, true, 'str', {}, Symbol.iterator
|
||||
]) {
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
await m.link(invalidLinker);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
|
@ -69,7 +69,7 @@ async function checkArgType() {
|
|||
// Check methods/properties can only be used under a specific state.
|
||||
async function checkModuleState() {
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
await m.link(common.mustNotCall());
|
||||
assert.strictEqual(m.linkingStatus, 'linked');
|
||||
await m.link(common.mustNotCall());
|
||||
|
@ -78,7 +78,7 @@ async function checkModuleState() {
|
|||
});
|
||||
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
m.link(common.mustNotCall());
|
||||
assert.strictEqual(m.linkingStatus, 'linking');
|
||||
await m.link(common.mustNotCall());
|
||||
|
@ -87,14 +87,14 @@ async function checkModuleState() {
|
|||
});
|
||||
|
||||
common.expectsError(() => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
m.instantiate();
|
||||
}, {
|
||||
code: 'ERR_VM_MODULE_NOT_LINKED'
|
||||
});
|
||||
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('import "foo";');
|
||||
const m = new SourceTextModule('import "foo";');
|
||||
try {
|
||||
await m.link(common.mustCall(() => ({})));
|
||||
} catch (err) {
|
||||
|
@ -107,7 +107,7 @@ async function checkModuleState() {
|
|||
});
|
||||
|
||||
{
|
||||
const m = new Module('import "foo";');
|
||||
const m = new SourceTextModule('import "foo";');
|
||||
await m.link(common.mustCall(async (specifier, module) => {
|
||||
assert.strictEqual(module, m);
|
||||
assert.strictEqual(specifier, 'foo');
|
||||
|
@ -117,14 +117,14 @@ async function checkModuleState() {
|
|||
}, {
|
||||
code: 'ERR_VM_MODULE_NOT_LINKED'
|
||||
});
|
||||
return new Module('');
|
||||
return new SourceTextModule('');
|
||||
}));
|
||||
m.instantiate();
|
||||
await m.evaluate();
|
||||
}
|
||||
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
await m.evaluate();
|
||||
}, {
|
||||
code: 'ERR_VM_MODULE_STATUS',
|
||||
|
@ -140,7 +140,7 @@ async function checkModuleState() {
|
|||
});
|
||||
|
||||
common.expectsError(() => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
m.error;
|
||||
}, {
|
||||
code: 'ERR_VM_MODULE_STATUS',
|
||||
|
@ -158,7 +158,7 @@ async function checkModuleState() {
|
|||
});
|
||||
|
||||
common.expectsError(() => {
|
||||
const m = new Module('');
|
||||
const m = new SourceTextModule('');
|
||||
m.namespace;
|
||||
}, {
|
||||
code: 'ERR_VM_MODULE_STATUS',
|
||||
|
@ -177,7 +177,7 @@ async function checkModuleState() {
|
|||
// Check link() fails when the returned module is not valid.
|
||||
async function checkLinking() {
|
||||
await expectsRejection(async () => {
|
||||
const m = new Module('import "foo";');
|
||||
const m = new SourceTextModule('import "foo";');
|
||||
try {
|
||||
await m.link(common.mustCall(() => ({})));
|
||||
} catch (err) {
|
||||
|
@ -191,9 +191,9 @@ async function checkLinking() {
|
|||
|
||||
await expectsRejection(async () => {
|
||||
const c = createContext({ a: 1 });
|
||||
const foo = new Module('', { context: c });
|
||||
const foo = new SourceTextModule('', { context: c });
|
||||
await foo.link(common.mustNotCall());
|
||||
const bar = new Module('import "foo";');
|
||||
const bar = new SourceTextModule('import "foo";');
|
||||
try {
|
||||
await bar.link(common.mustCall(() => foo));
|
||||
} catch (err) {
|
||||
|
@ -206,7 +206,7 @@ async function checkLinking() {
|
|||
});
|
||||
|
||||
await expectsRejection(async () => {
|
||||
const erroredModule = new Module('import "foo";');
|
||||
const erroredModule = new SourceTextModule('import "foo";');
|
||||
try {
|
||||
await erroredModule.link(common.mustCall(() => ({})));
|
||||
} catch (err) {
|
||||
|
@ -215,7 +215,7 @@ async function checkLinking() {
|
|||
assert.strictEqual(erroredModule.linkingStatus, 'errored');
|
||||
}
|
||||
|
||||
const rootModule = new Module('import "errored";');
|
||||
const rootModule = new SourceTextModule('import "errored";');
|
||||
await rootModule.link(common.mustCall(() => erroredModule));
|
||||
}, {
|
||||
code: 'ERR_VM_MODULE_LINKING_ERRORED'
|
||||
|
@ -225,8 +225,8 @@ async function checkLinking() {
|
|||
// Check the JavaScript engine deals with exceptions correctly
|
||||
async function checkExecution() {
|
||||
await (async () => {
|
||||
const m = new Module('import { nonexistent } from "module";');
|
||||
await m.link(common.mustCall(() => new Module('')));
|
||||
const m = new SourceTextModule('import { nonexistent } from "module";');
|
||||
await m.link(common.mustCall(() => new SourceTextModule('')));
|
||||
|
||||
// There is no code for this exception since it is thrown by the JavaScript
|
||||
// engine.
|
||||
|
@ -236,7 +236,7 @@ async function checkExecution() {
|
|||
})();
|
||||
|
||||
await (async () => {
|
||||
const m = new Module('throw new Error();');
|
||||
const m = new SourceTextModule('throw new Error();');
|
||||
await m.link(common.mustNotCall());
|
||||
m.instantiate();
|
||||
const evaluatePromise = m.evaluate();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue