Skip to content

Commit 052e095

Browse files
joyeecheungrichardlau
authored andcommittedMar 15, 2024
vm: use internal versions of compileFunction and Script
Instead of using the public versions of the vm APIs internally, use the internal versions so that we can skip unnecessary argument validation. The public versions would need special care to the generation of host-defined options to hit the isolate compilation cache when imporModuleDynamically isn't used, while internally it's almost always used, so this allows us to handle the host-defined options separately. PR-URL: #50137 Backport-PR-URL: #51004 Refs: #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>
1 parent 9f7899e commit 052e095

File tree

7 files changed

+245
-173
lines changed

7 files changed

+245
-173
lines changed
 

‎lib/internal/modules/cjs/loader.js

+40-32
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const {
5353
SafeMap,
5454
SafeWeakMap,
5555
String,
56+
Symbol,
5657
StringPrototypeCharAt,
5758
StringPrototypeCharCodeAt,
5859
StringPrototypeEndsWith,
@@ -85,7 +86,12 @@ const {
8586
setOwnProperty,
8687
getLazy,
8788
} = require('internal/util');
88-
const { internalCompileFunction } = require('internal/vm');
89+
const {
90+
internalCompileFunction,
91+
makeContextifyScript,
92+
runScriptInThisContext,
93+
} = require('internal/vm');
94+
8995
const assert = require('internal/assert');
9096
const fs = require('fs');
9197
const path = require('path');
@@ -1236,7 +1242,6 @@ Module.prototype.require = function(id) {
12361242
let resolvedArgv;
12371243
let hasPausedEntry = false;
12381244
/** @type {import('vm').Script} */
1239-
let Script;
12401245

12411246
/**
12421247
* Wraps the given content in a script and runs it in a new context.
@@ -1245,46 +1250,49 @@ let Script;
12451250
* @param {Module} cjsModuleInstance The CommonJS loader instance
12461251
*/
12471252
function wrapSafe(filename, content, cjsModuleInstance) {
1253+
const hostDefinedOptionId = Symbol(`cjs:${filename}`);
1254+
async function importModuleDynamically(specifier, _, importAttributes) {
1255+
const cascadedLoader = getCascadedLoader();
1256+
return cascadedLoader.import(specifier, normalizeReferrerURL(filename),
1257+
importAttributes);
1258+
}
12481259
if (patched) {
1249-
const wrapper = Module.wrap(content);
1250-
if (Script === undefined) {
1251-
({ Script } = require('vm'));
1252-
}
1253-
const script = new Script(wrapper, {
1254-
filename,
1255-
lineOffset: 0,
1256-
importModuleDynamically: async (specifier, _, importAttributes) => {
1257-
const cascadedLoader = getCascadedLoader();
1258-
return cascadedLoader.import(specifier, normalizeReferrerURL(filename),
1259-
importAttributes);
1260-
},
1261-
});
1260+
const wrapped = Module.wrap(content);
1261+
const script = makeContextifyScript(
1262+
wrapped, // code
1263+
filename, // filename
1264+
0, // lineOffset
1265+
0, // columnOffset
1266+
undefined, // cachedData
1267+
false, // produceCachedData
1268+
undefined, // parsingContext
1269+
hostDefinedOptionId, // hostDefinedOptionId
1270+
importModuleDynamically, // importModuleDynamically
1271+
);
12621272

12631273
// Cache the source map for the module if present.
12641274
if (script.sourceMapURL) {
12651275
maybeCacheSourceMap(filename, content, this, false, undefined, script.sourceMapURL);
12661276
}
12671277

1268-
return script.runInThisContext({
1269-
displayErrors: true,
1270-
});
1278+
return runScriptInThisContext(script, true, false);
12711279
}
12721280

1281+
const params = [ 'exports', 'require', 'module', '__filename', '__dirname' ];
12731282
try {
1274-
const result = internalCompileFunction(content, [
1275-
'exports',
1276-
'require',
1277-
'module',
1278-
'__filename',
1279-
'__dirname',
1280-
], {
1281-
filename,
1282-
importModuleDynamically(specifier, _, importAttributes) {
1283-
const cascadedLoader = getCascadedLoader();
1284-
return cascadedLoader.import(specifier, normalizeReferrerURL(filename),
1285-
importAttributes);
1286-
},
1287-
});
1283+
const result = internalCompileFunction(
1284+
content, // code,
1285+
filename, // filename
1286+
0, // lineOffset
1287+
0, // columnOffset,
1288+
undefined, // cachedData
1289+
false, // produceCachedData
1290+
undefined, // parsingContext
1291+
undefined, // contextExtensions
1292+
params, // params
1293+
hostDefinedOptionId, // hostDefinedOptionId
1294+
importModuleDynamically, // importModuleDynamically
1295+
);
12881296

12891297
// Cache the source map for the module if present.
12901298
if (result.sourceMapURL) {

‎lib/internal/process/execution.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
Symbol,
45
RegExpPrototypeExec,
56
globalThis,
67
} = primordials;
@@ -24,7 +25,9 @@ const {
2425
emitAfter,
2526
popAsyncContext,
2627
} = require('internal/async_hooks');
27-
28+
const {
29+
makeContextifyScript, runScriptInThisContext,
30+
} = require('internal/vm');
2831
// shouldAbortOnUncaughtToggle is a typed array for faster
2932
// communication with JS.
3033
const { shouldAbortOnUncaughtToggle } = internalBinding('util');
@@ -52,8 +55,7 @@ function evalModule(source, print) {
5255

5356
function evalScript(name, body, breakFirstLine, print, shouldLoadESM = false) {
5457
const CJSModule = require('internal/modules/cjs/loader').Module;
55-
const { kVmBreakFirstLineSymbol } = require('internal/util');
56-
const { pathToFileURL } = require('url');
58+
const { pathToFileURL } = require('internal/url');
5759

5860
const cwd = tryGetCwd();
5961
const origModule = globalThis.module; // Set e.g. when called from the REPL.
@@ -78,16 +80,25 @@ function evalScript(name, body, breakFirstLine, print, shouldLoadESM = false) {
7880
`;
7981
globalThis.__filename = name;
8082
RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs.
81-
const result = module._compile(script, `${name}-wrapper`)(() =>
82-
require('vm').runInThisContext(body, {
83-
filename: name,
84-
displayErrors: true,
85-
[kVmBreakFirstLineSymbol]: !!breakFirstLine,
86-
importModuleDynamically(specifier, _, importAttributes) {
87-
const loader = asyncESM.esmLoader;
88-
return loader.import(specifier, baseUrl, importAttributes);
89-
},
90-
}));
83+
const result = module._compile(script, `${name}-wrapper`)(() => {
84+
const hostDefinedOptionId = Symbol(name);
85+
async function importModuleDynamically(specifier, _, importAttributes) {
86+
const loader = asyncESM.esmLoader;
87+
return loader.import(specifier, baseUrl, importAttributes);
88+
}
89+
const script = makeContextifyScript(
90+
body, // code
91+
name, // filename,
92+
0, // lineOffset
93+
0, // columnOffset,
94+
undefined, // cachedData
95+
false, // produceCachedData
96+
undefined, // parsingContext
97+
hostDefinedOptionId, // hostDefinedOptionId
98+
importModuleDynamically, // importModuleDynamically
99+
);
100+
return runScriptInThisContext(script, true, !!breakFirstLine);
101+
});
91102
if (print) {
92103
const { log } = require('internal/console/global');
93104
log(result);

‎lib/internal/vm.js

+69-61
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
'use strict';
22

33
const {
4-
ArrayPrototypeForEach,
4+
ReflectApply,
55
Symbol,
66
} = primordials;
77

88
const {
9+
ContextifyScript,
910
compileFunction,
1011
isContext: _isContext,
1112
} = internalBinding('contextify');
13+
const {
14+
runInContext,
15+
} = ContextifyScript.prototype;
1216
const {
1317
default_host_defined_options,
1418
} = internalBinding('symbols');
1519
const {
16-
validateArray,
17-
validateBoolean,
18-
validateBuffer,
1920
validateFunction,
2021
validateObject,
21-
validateString,
22-
validateStringArray,
23-
validateInt32,
2422
} = require('internal/validators');
25-
const {
26-
ERR_INVALID_ARG_TYPE,
27-
} = require('internal/errors').codes;
2823

2924
function isContext(object) {
3025
validateObject(object, 'object', { __proto__: null, allowArray: true });
@@ -48,49 +43,20 @@ function getHostDefinedOptionId(importModuleDynamically, filename) {
4843
return Symbol(filename);
4944
}
5045

51-
function internalCompileFunction(code, params, options) {
52-
validateString(code, 'code');
53-
if (params !== undefined) {
54-
validateStringArray(params, 'params');
55-
}
56-
const {
57-
filename = '',
58-
columnOffset = 0,
59-
lineOffset = 0,
60-
cachedData = undefined,
61-
produceCachedData = false,
62-
parsingContext = undefined,
63-
contextExtensions = [],
64-
importModuleDynamically,
65-
} = options;
66-
67-
validateString(filename, 'options.filename');
68-
validateInt32(columnOffset, 'options.columnOffset');
69-
validateInt32(lineOffset, 'options.lineOffset');
70-
if (cachedData !== undefined)
71-
validateBuffer(cachedData, 'options.cachedData');
72-
validateBoolean(produceCachedData, 'options.produceCachedData');
73-
if (parsingContext !== undefined) {
74-
if (
75-
typeof parsingContext !== 'object' ||
76-
parsingContext === null ||
77-
!isContext(parsingContext)
78-
) {
79-
throw new ERR_INVALID_ARG_TYPE(
80-
'options.parsingContext',
81-
'Context',
82-
parsingContext,
83-
);
84-
}
85-
}
86-
validateArray(contextExtensions, 'options.contextExtensions');
87-
ArrayPrototypeForEach(contextExtensions, (extension, i) => {
88-
const name = `options.contextExtensions[${i}]`;
89-
validateObject(extension, name, { __proto__: null, nullable: true });
46+
function registerImportModuleDynamically(referrer, importModuleDynamically) {
47+
const { importModuleDynamicallyWrap } = require('internal/vm/module');
48+
const { registerModule } = require('internal/modules/esm/utils');
49+
registerModule(referrer, {
50+
__proto__: null,
51+
importModuleDynamically:
52+
importModuleDynamicallyWrap(importModuleDynamically),
9053
});
54+
}
9155

92-
const hostDefinedOptionId =
93-
getHostDefinedOptionId(importModuleDynamically, filename);
56+
function internalCompileFunction(
57+
code, filename, lineOffset, columnOffset,
58+
cachedData, produceCachedData, parsingContext, contextExtensions,
59+
params, hostDefinedOptionId, importModuleDynamically) {
9460
const result = compileFunction(
9561
code,
9662
filename,
@@ -117,23 +83,65 @@ function internalCompileFunction(code, params, options) {
11783
}
11884

11985
if (importModuleDynamically !== undefined) {
120-
validateFunction(importModuleDynamically,
121-
'options.importModuleDynamically');
122-
const { importModuleDynamicallyWrap } = require('internal/vm/module');
123-
const wrapped = importModuleDynamicallyWrap(importModuleDynamically);
124-
const func = result.function;
125-
const { registerModule } = require('internal/modules/esm/utils');
126-
registerModule(func, {
127-
__proto__: null,
128-
importModuleDynamically: wrapped,
129-
});
86+
registerImportModuleDynamically(result.function, importModuleDynamically);
13087
}
13188

13289
return result;
13390
}
13491

92+
function makeContextifyScript(code,
93+
filename,
94+
lineOffset,
95+
columnOffset,
96+
cachedData,
97+
produceCachedData,
98+
parsingContext,
99+
hostDefinedOptionId,
100+
importModuleDynamically) {
101+
let script;
102+
// Calling `ReThrow()` on a native TryCatch does not generate a new
103+
// abort-on-uncaught-exception check. A dummy try/catch in JS land
104+
// protects against that.
105+
try { // eslint-disable-line no-useless-catch
106+
script = new ContextifyScript(code,
107+
filename,
108+
lineOffset,
109+
columnOffset,
110+
cachedData,
111+
produceCachedData,
112+
parsingContext,
113+
hostDefinedOptionId);
114+
} catch (e) {
115+
throw e; /* node-do-not-add-exception-line */
116+
}
117+
118+
if (importModuleDynamically !== undefined) {
119+
registerImportModuleDynamically(script, importModuleDynamically);
120+
}
121+
return script;
122+
}
123+
124+
// Internal version of vm.Script.prototype.runInThisContext() which skips
125+
// argument validation.
126+
function runScriptInThisContext(script, displayErrors, breakOnFirstLine) {
127+
return ReflectApply(
128+
runInContext,
129+
script,
130+
[
131+
null, // sandbox - use current context
132+
-1, // timeout
133+
displayErrors, // displayErrors
134+
false, // breakOnSigint
135+
breakOnFirstLine, // breakOnFirstLine
136+
],
137+
);
138+
}
139+
135140
module.exports = {
136141
getHostDefinedOptionId,
137142
internalCompileFunction,
138143
isContext,
144+
makeContextifyScript,
145+
registerImportModuleDynamically,
146+
runScriptInThisContext,
139147
};

‎lib/repl.js

+45-40
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ const {
118118
} = require('internal/util');
119119
const { inspect } = require('internal/util/inspect');
120120
const vm = require('vm');
121+
122+
const { runInThisContext, runInContext } = vm.Script.prototype;
123+
121124
const path = require('path');
122125
const fs = require('fs');
123126
const { Interface } = require('readline');
@@ -186,7 +189,9 @@ const {
186189
extensionFormatMap,
187190
legacyExtensionFormatMap,
188191
} = require('internal/modules/esm/formats');
189-
192+
const {
193+
makeContextifyScript,
194+
} = require('internal/vm');
190195
let nextREPLResourceNumber = 1;
191196
// This prevents v8 code cache from getting confused and using a different
192197
// cache from a resource of the same name
@@ -430,8 +435,6 @@ function REPLServer(prompt,
430435
}
431436

432437
function defaultEval(code, context, file, cb) {
433-
const asyncESM = require('internal/process/esm_loader');
434-
435438
let result, script, wrappedErr;
436439
let err = null;
437440
let wrappedCmd = false;
@@ -449,6 +452,21 @@ function REPLServer(prompt,
449452
wrappedCmd = true;
450453
}
451454

455+
const hostDefinedOptionId = Symbol(`eval:${file}`);
456+
let parentURL;
457+
try {
458+
const { pathToFileURL } = require('internal/url');
459+
// Adding `/repl` prevents dynamic imports from loading relative
460+
// to the parent of `process.cwd()`.
461+
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
462+
} catch {
463+
// Continue regardless of error.
464+
}
465+
async function importModuleDynamically(specifier, _, importAttributes) {
466+
const asyncESM = require('internal/process/esm_loader');
467+
return asyncESM.esmLoader.import(specifier, parentURL,
468+
importAttributes);
469+
}
452470
// `experimentalREPLAwait` is set to true by default.
453471
// Shall be false in case `--no-experimental-repl-await` flag is used.
454472
if (experimentalREPLAwait && StringPrototypeIncludes(code, 'await')) {
@@ -466,28 +484,21 @@ function REPLServer(prompt,
466484
} catch (e) {
467485
let recoverableError = false;
468486
if (e.name === 'SyntaxError') {
469-
let parentURL;
470-
try {
471-
const { pathToFileURL } = require('url');
472-
// Adding `/repl` prevents dynamic imports from loading relative
473-
// to the parent of `process.cwd()`.
474-
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
475-
} catch {
476-
// Continue regardless of error.
477-
}
478-
479487
// Remove all "await"s and attempt running the script
480488
// in order to detect if error is truly non recoverable
481489
const fallbackCode = SideEffectFreeRegExpPrototypeSymbolReplace(/\bawait\b/g, code, '');
482490
try {
483-
vm.createScript(fallbackCode, {
484-
filename: file,
485-
displayErrors: true,
486-
importModuleDynamically: (specifier, _, importAttributes) => {
487-
return asyncESM.esmLoader.import(specifier, parentURL,
488-
importAttributes);
489-
},
490-
});
491+
makeContextifyScript(
492+
fallbackCode, // code
493+
file, // filename,
494+
0, // lineOffset
495+
0, // columnOffset,
496+
undefined, // cachedData
497+
false, // produceCachedData
498+
undefined, // parsingContext
499+
hostDefinedOptionId, // hostDefinedOptionId
500+
importModuleDynamically, // importModuleDynamically
501+
);
491502
} catch (fallbackError) {
492503
if (isRecoverableError(fallbackError, fallbackCode)) {
493504
recoverableError = true;
@@ -507,15 +518,6 @@ function REPLServer(prompt,
507518
return cb(null);
508519

509520
if (err === null) {
510-
let parentURL;
511-
try {
512-
const { pathToFileURL } = require('url');
513-
// Adding `/repl` prevents dynamic imports from loading relative
514-
// to the parent of `process.cwd()`.
515-
parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href;
516-
} catch {
517-
// Continue regardless of error.
518-
}
519521
while (true) {
520522
try {
521523
if (self.replMode === module.exports.REPL_MODE_STRICT &&
@@ -524,14 +526,17 @@ function REPLServer(prompt,
524526
// value for statements and declarations that don't return a value.
525527
code = `'use strict'; void 0;\n${code}`;
526528
}
527-
script = vm.createScript(code, {
528-
filename: file,
529-
displayErrors: true,
530-
importModuleDynamically: (specifier, _, importAttributes) => {
531-
return asyncESM.esmLoader.import(specifier, parentURL,
532-
importAttributes);
533-
},
534-
});
529+
script = makeContextifyScript(
530+
code, // code
531+
file, // filename,
532+
0, // lineOffset
533+
0, // columnOffset,
534+
undefined, // cachedData
535+
false, // produceCachedData
536+
undefined, // parsingContext
537+
hostDefinedOptionId, // hostDefinedOptionId
538+
importModuleDynamically, // importModuleDynamically
539+
);
535540
} catch (e) {
536541
debug('parse error %j', code, e);
537542
if (wrappedCmd) {
@@ -591,9 +596,9 @@ function REPLServer(prompt,
591596
};
592597

593598
if (self.useGlobal) {
594-
result = script.runInThisContext(scriptOptions);
599+
result = ReflectApply(runInThisContext, script, [scriptOptions]);
595600
} else {
596-
result = script.runInContext(context, scriptOptions);
601+
result = ReflectApply(runInContext, script, [context, scriptOptions]);
597602
}
598603
} finally {
599604
if (self.breakEvalOnSigint) {

‎lib/vm.js

+53-9
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ const {
4040
ERR_INVALID_ARG_TYPE,
4141
} = require('internal/errors').codes;
4242
const {
43+
validateArray,
4344
validateBoolean,
4445
validateBuffer,
4546
validateInt32,
46-
validateObject,
4747
validateOneOf,
48+
validateObject,
4849
validateString,
50+
validateStringArray,
4951
validateUint32,
5052
} = require('internal/validators');
5153
const {
@@ -57,6 +59,7 @@ const {
5759
getHostDefinedOptionId,
5860
internalCompileFunction,
5961
isContext,
62+
registerImportModuleDynamically,
6063
} = require('internal/vm');
6164
const kParsingContext = Symbol('script parsing context');
6265

@@ -106,13 +109,7 @@ class Script extends ContextifyScript {
106109
}
107110

108111
if (importModuleDynamically !== undefined) {
109-
const { importModuleDynamicallyWrap } = require('internal/vm/module');
110-
const { registerModule } = require('internal/modules/esm/utils');
111-
registerModule(this, {
112-
__proto__: null,
113-
importModuleDynamically:
114-
importModuleDynamicallyWrap(importModuleDynamically),
115-
});
112+
registerImportModuleDynamically(this, importModuleDynamically);
116113
}
117114
}
118115

@@ -301,7 +298,54 @@ function runInThisContext(code, options) {
301298
}
302299

303300
function compileFunction(code, params, options = kEmptyObject) {
304-
return internalCompileFunction(code, params, options).function;
301+
validateString(code, 'code');
302+
if (params !== undefined) {
303+
validateStringArray(params, 'params');
304+
}
305+
const {
306+
filename = '',
307+
columnOffset = 0,
308+
lineOffset = 0,
309+
cachedData = undefined,
310+
produceCachedData = false,
311+
parsingContext = undefined,
312+
contextExtensions = [],
313+
importModuleDynamically,
314+
} = options;
315+
316+
validateString(filename, 'options.filename');
317+
validateInt32(columnOffset, 'options.columnOffset');
318+
validateInt32(lineOffset, 'options.lineOffset');
319+
if (cachedData !== undefined)
320+
validateBuffer(cachedData, 'options.cachedData');
321+
validateBoolean(produceCachedData, 'options.produceCachedData');
322+
if (parsingContext !== undefined) {
323+
if (
324+
typeof parsingContext !== 'object' ||
325+
parsingContext === null ||
326+
!isContext(parsingContext)
327+
) {
328+
throw new ERR_INVALID_ARG_TYPE(
329+
'options.parsingContext',
330+
'Context',
331+
parsingContext,
332+
);
333+
}
334+
}
335+
validateArray(contextExtensions, 'options.contextExtensions');
336+
ArrayPrototypeForEach(contextExtensions, (extension, i) => {
337+
const name = `options.contextExtensions[${i}]`;
338+
validateObject(extension, name, { __proto__: null, nullable: true });
339+
});
340+
341+
const hostDefinedOptionId =
342+
getHostDefinedOptionId(importModuleDynamically, filename);
343+
344+
return internalCompileFunction(
345+
code, filename, lineOffset, columnOffset,
346+
cachedData, produceCachedData, parsingContext, contextExtensions,
347+
params, hostDefinedOptionId, importModuleDynamically,
348+
).function;
305349
}
306350

307351
const measureMemoryModes = {

‎test/message/eval_messages.out

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
[eval]:1
33
with(this){__filename}
44
^^^^
5+
56
SyntaxError: Strict mode code may not include a with statement
6-
at new Script (node:vm:*:*)
7-
at createScript (node:vm:*:*)
8-
at Object.runInThisContext (node:vm:*:*)
7+
at makeContextifyScript (node:internal/vm:*:*)
98
at node:internal/process/execution:*:*
109
at [eval]-wrapper:*:*
1110
at runScript (node:internal/process/execution:*:*)
@@ -21,8 +20,7 @@ throw new Error("hello")
2120

2221
Error: hello
2322
at [eval]:1:7
24-
at Script.runInThisContext (node:vm:*:*)
25-
at Object.runInThisContext (node:vm:*:*)
23+
at runScriptInThisContext (node:internal/vm:*:*)
2624
at node:internal/process/execution:*:*
2725
at [eval]-wrapper:*:*
2826
at runScript (node:internal/process/execution:*:*)
@@ -37,8 +35,7 @@ throw new Error("hello")
3735

3836
Error: hello
3937
at [eval]:1:7
40-
at Script.runInThisContext (node:vm:*:*)
41-
at Object.runInThisContext (node:vm:*:*)
38+
at runScriptInThisContext (node:internal/vm:*:*)
4239
at node:internal/process/execution:*:*
4340
at [eval]-wrapper:*:*
4441
at runScript (node:internal/process/execution:*:*)
@@ -53,8 +50,7 @@ var x = 100; y = x;
5350

5451
ReferenceError: y is not defined
5552
at [eval]:1:16
56-
at Script.runInThisContext (node:vm:*:*)
57-
at Object.runInThisContext (node:vm:*:*)
53+
at runScriptInThisContext (node:internal/vm:*:*)
5854
at node:internal/process/execution:*:*
5955
at [eval]-wrapper:*:*
6056
at runScript (node:internal/process/execution:*:*)

‎test/message/stdin_messages.out

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ with(this){__filename}
44
^^^^
55

66
SyntaxError: Strict mode code may not include a with statement
7-
at new Script (node:vm:*)
8-
at createScript (node:vm:*)
9-
at Object.runInThisContext (node:vm:*)
7+
at makeContextifyScript (node:internal/vm:*:*)
108
at node:internal/process/execution:*:*
119
at [stdin]-wrapper:*:*
1210
at runScript (node:internal/process/execution:*:*)
1311
at evalScript (node:internal/process/execution:*:*)
1412
at node:internal/main/eval_stdin:*:*
1513
at Socket.<anonymous> (node:internal/process/execution:*:*)
1614
at Socket.emit (node:events:*:*)
15+
at endReadableNT (node:internal/streams/readable:*:*)
16+
at process.processTicksAndRejections (node:internal/process/task_queues:*:*)
1717

1818
Node.js *
1919
42
@@ -24,15 +24,15 @@ throw new Error("hello")
2424

2525
Error: hello
2626
at [stdin]:1:7
27-
at Script.runInThisContext (node:vm:*)
28-
at Object.runInThisContext (node:vm:*)
27+
at runScriptInThisContext (node:internal/vm:*:*)
2928
at node:internal/process/execution:*:*
3029
at [stdin]-wrapper:*:*
3130
at runScript (node:internal/process/execution:*:*)
3231
at evalScript (node:internal/process/execution:*:*)
3332
at node:internal/main/eval_stdin:*:*
3433
at Socket.<anonymous> (node:internal/process/execution:*:*)
3534
at Socket.emit (node:events:*:*)
35+
at endReadableNT (node:internal/streams/readable:*:*)
3636

3737
Node.js *
3838
[stdin]:1
@@ -41,15 +41,15 @@ throw new Error("hello")
4141

4242
Error: hello
4343
at [stdin]:1:*
44-
at Script.runInThisContext (node:vm:*)
45-
at Object.runInThisContext (node:vm:*)
44+
at runScriptInThisContext (node:internal/vm:*:*)
4645
at node:internal/process/execution:*:*
4746
at [stdin]-wrapper:*:*
4847
at runScript (node:internal/process/execution:*:*)
4948
at evalScript (node:internal/process/execution:*:*)
5049
at node:internal/main/eval_stdin:*:*
5150
at Socket.<anonymous> (node:internal/process/execution:*:*)
5251
at Socket.emit (node:events:*:*)
52+
at endReadableNT (node:internal/streams/readable:*:*)
5353

5454
Node.js *
5555
100
@@ -59,15 +59,15 @@ let x = 100; y = x;
5959

6060
ReferenceError: y is not defined
6161
at [stdin]:1:16
62-
at Script.runInThisContext (node:vm:*)
63-
at Object.runInThisContext (node:vm:*)
62+
at runScriptInThisContext (node:internal/vm:*:*)
6463
at node:internal/process/execution:*:*
6564
at [stdin]-wrapper:*:*
6665
at runScript (node:internal/process/execution:*:*)
6766
at evalScript (node:internal/process/execution:*:*)
6867
at node:internal/main/eval_stdin:*:*
6968
at Socket.<anonymous> (node:internal/process/execution:*:*)
7069
at Socket.emit (node:events:*:*)
70+
at endReadableNT (node:internal/streams/readable:*:*)
7171

7272
Node.js *
7373

0 commit comments

Comments
 (0)
Please sign in to comment.