11cb0ef41Sopenharmony_ci{ 21cb0ef41Sopenharmony_ci "type": "module", 31cb0ef41Sopenharmony_ci "source": "doc/api/vm.md", 41cb0ef41Sopenharmony_ci "modules": [ 51cb0ef41Sopenharmony_ci { 61cb0ef41Sopenharmony_ci "textRaw": "VM (executing JavaScript)", 71cb0ef41Sopenharmony_ci "name": "vm", 81cb0ef41Sopenharmony_ci "introduced_in": "v0.10.0", 91cb0ef41Sopenharmony_ci "stability": 2, 101cb0ef41Sopenharmony_ci "stabilityText": "Stable", 111cb0ef41Sopenharmony_ci "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v18.20.1/lib/vm.js\">lib/vm.js</a></p>\n<p>The <code>node:vm</code> module enables compiling and running code within V8 Virtual\nMachine contexts.</p>\n<p><strong class=\"critical\">The <code>node:vm</code> module is not a security\nmechanism. Do not use it to run untrusted code.</strong></p>\n<p>JavaScript code can be compiled and run immediately or\ncompiled, saved, and run later.</p>\n<p>A common use case is to run the code in a different V8 Context. This means\ninvoked code has a different global object than the invoking code.</p>\n<p>One can provide the context by <a href=\"#what-does-it-mean-to-contextify-an-object\"><em>contextifying</em></a> an\nobject. The invoked code treats any property in the context like a\nglobal variable. Any changes to global variables caused by the invoked\ncode are reflected in the context object.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst x = 1;\n\nconst context = { x: 2 };\nvm.createContext(context); // Contextify the object.\n\nconst code = 'x += 40; var y = 17;';\n// `x` and `y` are global variables in the context.\n// Initially, x has the value 2 because that is the value of context.x.\nvm.runInContext(code, context);\n\nconsole.log(context.x); // 42\nconsole.log(context.y); // 17\n\nconsole.log(x); // 1; y is not defined.\n</code></pre>", 121cb0ef41Sopenharmony_ci "classes": [ 131cb0ef41Sopenharmony_ci { 141cb0ef41Sopenharmony_ci "textRaw": "Class: `vm.Script`", 151cb0ef41Sopenharmony_ci "type": "class", 161cb0ef41Sopenharmony_ci "name": "vm.Script", 171cb0ef41Sopenharmony_ci "meta": { 181cb0ef41Sopenharmony_ci "added": [ 191cb0ef41Sopenharmony_ci "v0.3.1" 201cb0ef41Sopenharmony_ci ], 211cb0ef41Sopenharmony_ci "changes": [] 221cb0ef41Sopenharmony_ci }, 231cb0ef41Sopenharmony_ci "desc": "<p>Instances of the <code>vm.Script</code> class contain precompiled scripts that can be\nexecuted in specific contexts.</p>", 241cb0ef41Sopenharmony_ci "properties": [ 251cb0ef41Sopenharmony_ci { 261cb0ef41Sopenharmony_ci "textRaw": "`cachedDataRejected` {boolean|undefined}", 271cb0ef41Sopenharmony_ci "type": "boolean|undefined", 281cb0ef41Sopenharmony_ci "name": "cachedDataRejected", 291cb0ef41Sopenharmony_ci "meta": { 301cb0ef41Sopenharmony_ci "added": [ 311cb0ef41Sopenharmony_ci "v5.7.0" 321cb0ef41Sopenharmony_ci ], 331cb0ef41Sopenharmony_ci "changes": [] 341cb0ef41Sopenharmony_ci }, 351cb0ef41Sopenharmony_ci "desc": "<p>When <code>cachedData</code> is supplied to create the <code>vm.Script</code>, this value will be set\nto either <code>true</code> or <code>false</code> depending on acceptance of the data by V8.\nOtherwise the value is <code>undefined</code>.</p>" 361cb0ef41Sopenharmony_ci }, 371cb0ef41Sopenharmony_ci { 381cb0ef41Sopenharmony_ci "textRaw": "`sourceMapURL` {string|undefined}", 391cb0ef41Sopenharmony_ci "type": "string|undefined", 401cb0ef41Sopenharmony_ci "name": "sourceMapURL", 411cb0ef41Sopenharmony_ci "meta": { 421cb0ef41Sopenharmony_ci "added": [ 431cb0ef41Sopenharmony_ci "v18.13.0" 441cb0ef41Sopenharmony_ci ], 451cb0ef41Sopenharmony_ci "changes": [] 461cb0ef41Sopenharmony_ci }, 471cb0ef41Sopenharmony_ci "desc": "<p>When the script is compiled from a source that contains a source map magic\ncomment, this property will be set to the URL of the source map.</p>\n<pre><code class=\"language-mjs\">import vm from 'node:vm';\n\nconst script = new vm.Script(`\nfunction myFunc() {}\n//# sourceMappingURL=sourcemap.json\n`);\n\nconsole.log(script.sourceMapURL);\n// Prints: sourcemap.json\n</code></pre>\n<pre><code class=\"language-cjs\">const vm = require('node:vm');\n\nconst script = new vm.Script(`\nfunction myFunc() {}\n//# sourceMappingURL=sourcemap.json\n`);\n\nconsole.log(script.sourceMapURL);\n// Prints: sourcemap.json\n</code></pre>" 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci ], 501cb0ef41Sopenharmony_ci "methods": [ 511cb0ef41Sopenharmony_ci { 521cb0ef41Sopenharmony_ci "textRaw": "`script.createCachedData()`", 531cb0ef41Sopenharmony_ci "type": "method", 541cb0ef41Sopenharmony_ci "name": "createCachedData", 551cb0ef41Sopenharmony_ci "meta": { 561cb0ef41Sopenharmony_ci "added": [ 571cb0ef41Sopenharmony_ci "v10.6.0" 581cb0ef41Sopenharmony_ci ], 591cb0ef41Sopenharmony_ci "changes": [] 601cb0ef41Sopenharmony_ci }, 611cb0ef41Sopenharmony_ci "signatures": [ 621cb0ef41Sopenharmony_ci { 631cb0ef41Sopenharmony_ci "return": { 641cb0ef41Sopenharmony_ci "textRaw": "Returns: {Buffer}", 651cb0ef41Sopenharmony_ci "name": "return", 661cb0ef41Sopenharmony_ci "type": "Buffer" 671cb0ef41Sopenharmony_ci }, 681cb0ef41Sopenharmony_ci "params": [] 691cb0ef41Sopenharmony_ci } 701cb0ef41Sopenharmony_ci ], 711cb0ef41Sopenharmony_ci "desc": "<p>Creates a code cache that can be used with the <code>Script</code> constructor's\n<code>cachedData</code> option. Returns a <code>Buffer</code>. This method may be called at any\ntime and any number of times.</p>\n<p>The code cache of the <code>Script</code> doesn't contain any JavaScript observable\nstates. The code cache is safe to be saved along side the script source and\nused to construct new <code>Script</code> instances multiple times.</p>\n<p>Functions in the <code>Script</code> source can be marked as lazily compiled and they are\nnot compiled at construction of the <code>Script</code>. These functions are going to be\ncompiled when they are invoked the first time. The code cache serializes the\nmetadata that V8 currently knows about the <code>Script</code> that it can use to speed up\nfuture compilations.</p>\n<pre><code class=\"language-js\">const script = new vm.Script(`\nfunction add(a, b) {\n return a + b;\n}\n\nconst x = add(1, 2);\n`);\n\nconst cacheWithoutAdd = script.createCachedData();\n// In `cacheWithoutAdd` the function `add()` is marked for full compilation\n// upon invocation.\n\nscript.runInThisContext();\n\nconst cacheWithAdd = script.createCachedData();\n// `cacheWithAdd` contains fully compiled function `add()`.\n</code></pre>" 721cb0ef41Sopenharmony_ci }, 731cb0ef41Sopenharmony_ci { 741cb0ef41Sopenharmony_ci "textRaw": "`script.runInContext(contextifiedObject[, options])`", 751cb0ef41Sopenharmony_ci "type": "method", 761cb0ef41Sopenharmony_ci "name": "runInContext", 771cb0ef41Sopenharmony_ci "meta": { 781cb0ef41Sopenharmony_ci "added": [ 791cb0ef41Sopenharmony_ci "v0.3.1" 801cb0ef41Sopenharmony_ci ], 811cb0ef41Sopenharmony_ci "changes": [ 821cb0ef41Sopenharmony_ci { 831cb0ef41Sopenharmony_ci "version": "v6.3.0", 841cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 851cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 861cb0ef41Sopenharmony_ci } 871cb0ef41Sopenharmony_ci ] 881cb0ef41Sopenharmony_ci }, 891cb0ef41Sopenharmony_ci "signatures": [ 901cb0ef41Sopenharmony_ci { 911cb0ef41Sopenharmony_ci "return": { 921cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 931cb0ef41Sopenharmony_ci "name": "return", 941cb0ef41Sopenharmony_ci "type": "any", 951cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 961cb0ef41Sopenharmony_ci }, 971cb0ef41Sopenharmony_ci "params": [ 981cb0ef41Sopenharmony_ci { 991cb0ef41Sopenharmony_ci "textRaw": "`contextifiedObject` {Object} A [contextified][] object as returned by the `vm.createContext()` method.", 1001cb0ef41Sopenharmony_ci "name": "contextifiedObject", 1011cb0ef41Sopenharmony_ci "type": "Object", 1021cb0ef41Sopenharmony_ci "desc": "A [contextified][] object as returned by the `vm.createContext()` method." 1031cb0ef41Sopenharmony_ci }, 1041cb0ef41Sopenharmony_ci { 1051cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 1061cb0ef41Sopenharmony_ci "name": "options", 1071cb0ef41Sopenharmony_ci "type": "Object", 1081cb0ef41Sopenharmony_ci "options": [ 1091cb0ef41Sopenharmony_ci { 1101cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 1111cb0ef41Sopenharmony_ci "name": "displayErrors", 1121cb0ef41Sopenharmony_ci "type": "boolean", 1131cb0ef41Sopenharmony_ci "default": "`true`", 1141cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 1151cb0ef41Sopenharmony_ci }, 1161cb0ef41Sopenharmony_ci { 1171cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 1181cb0ef41Sopenharmony_ci "name": "timeout", 1191cb0ef41Sopenharmony_ci "type": "integer", 1201cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 1211cb0ef41Sopenharmony_ci }, 1221cb0ef41Sopenharmony_ci { 1231cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 1241cb0ef41Sopenharmony_ci "name": "breakOnSigint", 1251cb0ef41Sopenharmony_ci "type": "boolean", 1261cb0ef41Sopenharmony_ci "default": "`false`", 1271cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 1281cb0ef41Sopenharmony_ci } 1291cb0ef41Sopenharmony_ci ] 1301cb0ef41Sopenharmony_ci } 1311cb0ef41Sopenharmony_ci ] 1321cb0ef41Sopenharmony_ci } 1331cb0ef41Sopenharmony_ci ], 1341cb0ef41Sopenharmony_ci "desc": "<p>Runs the compiled code contained by the <code>vm.Script</code> object within the given\n<code>contextifiedObject</code> and returns the result. Running code does not have access\nto local scope.</p>\n<p>The following example compiles code that increments a global variable, sets\nthe value of another global variable, then execute the code multiple times.\nThe globals are contained in the <code>context</code> object.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst context = {\n animal: 'cat',\n count: 2,\n};\n\nconst script = new vm.Script('count += 1; name = \"kitty\";');\n\nvm.createContext(context);\nfor (let i = 0; i < 10; ++i) {\n script.runInContext(context);\n}\n\nconsole.log(context);\n// Prints: { animal: 'cat', count: 12, name: 'kitty' }\n</code></pre>\n<p>Using the <code>timeout</code> or <code>breakOnSigint</code> options will result in new event loops\nand corresponding threads being started, which have a non-zero performance\noverhead.</p>" 1351cb0ef41Sopenharmony_ci }, 1361cb0ef41Sopenharmony_ci { 1371cb0ef41Sopenharmony_ci "textRaw": "`script.runInNewContext([contextObject[, options]])`", 1381cb0ef41Sopenharmony_ci "type": "method", 1391cb0ef41Sopenharmony_ci "name": "runInNewContext", 1401cb0ef41Sopenharmony_ci "meta": { 1411cb0ef41Sopenharmony_ci "added": [ 1421cb0ef41Sopenharmony_ci "v0.3.1" 1431cb0ef41Sopenharmony_ci ], 1441cb0ef41Sopenharmony_ci "changes": [ 1451cb0ef41Sopenharmony_ci { 1461cb0ef41Sopenharmony_ci "version": "v14.6.0", 1471cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/34023", 1481cb0ef41Sopenharmony_ci "description": "The `microtaskMode` option is supported now." 1491cb0ef41Sopenharmony_ci }, 1501cb0ef41Sopenharmony_ci { 1511cb0ef41Sopenharmony_ci "version": "v10.0.0", 1521cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/19016", 1531cb0ef41Sopenharmony_ci "description": "The `contextCodeGeneration` option is supported now." 1541cb0ef41Sopenharmony_ci }, 1551cb0ef41Sopenharmony_ci { 1561cb0ef41Sopenharmony_ci "version": "v6.3.0", 1571cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 1581cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 1591cb0ef41Sopenharmony_ci } 1601cb0ef41Sopenharmony_ci ] 1611cb0ef41Sopenharmony_ci }, 1621cb0ef41Sopenharmony_ci "signatures": [ 1631cb0ef41Sopenharmony_ci { 1641cb0ef41Sopenharmony_ci "return": { 1651cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 1661cb0ef41Sopenharmony_ci "name": "return", 1671cb0ef41Sopenharmony_ci "type": "any", 1681cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 1691cb0ef41Sopenharmony_ci }, 1701cb0ef41Sopenharmony_ci "params": [ 1711cb0ef41Sopenharmony_ci { 1721cb0ef41Sopenharmony_ci "textRaw": "`contextObject` {Object} An object that will be [contextified][]. If `undefined`, a new object will be created.", 1731cb0ef41Sopenharmony_ci "name": "contextObject", 1741cb0ef41Sopenharmony_ci "type": "Object", 1751cb0ef41Sopenharmony_ci "desc": "An object that will be [contextified][]. If `undefined`, a new object will be created." 1761cb0ef41Sopenharmony_ci }, 1771cb0ef41Sopenharmony_ci { 1781cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 1791cb0ef41Sopenharmony_ci "name": "options", 1801cb0ef41Sopenharmony_ci "type": "Object", 1811cb0ef41Sopenharmony_ci "options": [ 1821cb0ef41Sopenharmony_ci { 1831cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 1841cb0ef41Sopenharmony_ci "name": "displayErrors", 1851cb0ef41Sopenharmony_ci "type": "boolean", 1861cb0ef41Sopenharmony_ci "default": "`true`", 1871cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 1881cb0ef41Sopenharmony_ci }, 1891cb0ef41Sopenharmony_ci { 1901cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 1911cb0ef41Sopenharmony_ci "name": "timeout", 1921cb0ef41Sopenharmony_ci "type": "integer", 1931cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 1941cb0ef41Sopenharmony_ci }, 1951cb0ef41Sopenharmony_ci { 1961cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 1971cb0ef41Sopenharmony_ci "name": "breakOnSigint", 1981cb0ef41Sopenharmony_ci "type": "boolean", 1991cb0ef41Sopenharmony_ci "default": "`false`", 2001cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 2011cb0ef41Sopenharmony_ci }, 2021cb0ef41Sopenharmony_ci { 2031cb0ef41Sopenharmony_ci "textRaw": "`contextName` {string} Human-readable name of the newly created context. **Default:** `'VM Context i'`, where `i` is an ascending numerical index of the created context.", 2041cb0ef41Sopenharmony_ci "name": "contextName", 2051cb0ef41Sopenharmony_ci "type": "string", 2061cb0ef41Sopenharmony_ci "default": "`'VM Context i'`, where `i` is an ascending numerical index of the created context", 2071cb0ef41Sopenharmony_ci "desc": "Human-readable name of the newly created context." 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci { 2101cb0ef41Sopenharmony_ci "textRaw": "`contextOrigin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. **Default:** `''`.", 2111cb0ef41Sopenharmony_ci "name": "contextOrigin", 2121cb0ef41Sopenharmony_ci "type": "string", 2131cb0ef41Sopenharmony_ci "default": "`''`", 2141cb0ef41Sopenharmony_ci "desc": "[Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path." 2151cb0ef41Sopenharmony_ci }, 2161cb0ef41Sopenharmony_ci { 2171cb0ef41Sopenharmony_ci "textRaw": "`contextCodeGeneration` {Object}", 2181cb0ef41Sopenharmony_ci "name": "contextCodeGeneration", 2191cb0ef41Sopenharmony_ci "type": "Object", 2201cb0ef41Sopenharmony_ci "options": [ 2211cb0ef41Sopenharmony_ci { 2221cb0ef41Sopenharmony_ci "textRaw": "`strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. **Default:** `true`.", 2231cb0ef41Sopenharmony_ci "name": "strings", 2241cb0ef41Sopenharmony_ci "type": "boolean", 2251cb0ef41Sopenharmony_ci "default": "`true`", 2261cb0ef41Sopenharmony_ci "desc": "If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`." 2271cb0ef41Sopenharmony_ci }, 2281cb0ef41Sopenharmony_ci { 2291cb0ef41Sopenharmony_ci "textRaw": "`wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. **Default:** `true`.", 2301cb0ef41Sopenharmony_ci "name": "wasm", 2311cb0ef41Sopenharmony_ci "type": "boolean", 2321cb0ef41Sopenharmony_ci "default": "`true`", 2331cb0ef41Sopenharmony_ci "desc": "If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`." 2341cb0ef41Sopenharmony_ci } 2351cb0ef41Sopenharmony_ci ] 2361cb0ef41Sopenharmony_ci }, 2371cb0ef41Sopenharmony_ci { 2381cb0ef41Sopenharmony_ci "textRaw": "`microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case.", 2391cb0ef41Sopenharmony_ci "name": "microtaskMode", 2401cb0ef41Sopenharmony_ci "type": "string", 2411cb0ef41Sopenharmony_ci "desc": "If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case." 2421cb0ef41Sopenharmony_ci } 2431cb0ef41Sopenharmony_ci ] 2441cb0ef41Sopenharmony_ci } 2451cb0ef41Sopenharmony_ci ] 2461cb0ef41Sopenharmony_ci } 2471cb0ef41Sopenharmony_ci ], 2481cb0ef41Sopenharmony_ci "desc": "<p>First contextifies the given <code>contextObject</code>, runs the compiled code contained\nby the <code>vm.Script</code> object within the created context, and returns the result.\nRunning code does not have access to local scope.</p>\n<p>The following example compiles code that sets a global variable, then executes\nthe code multiple times in different contexts. The globals are set on and\ncontained within each individual <code>context</code>.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst script = new vm.Script('globalVar = \"set\"');\n\nconst contexts = [{}, {}, {}];\ncontexts.forEach((context) => {\n script.runInNewContext(context);\n});\n\nconsole.log(contexts);\n// Prints: [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]\n</code></pre>" 2491cb0ef41Sopenharmony_ci }, 2501cb0ef41Sopenharmony_ci { 2511cb0ef41Sopenharmony_ci "textRaw": "`script.runInThisContext([options])`", 2521cb0ef41Sopenharmony_ci "type": "method", 2531cb0ef41Sopenharmony_ci "name": "runInThisContext", 2541cb0ef41Sopenharmony_ci "meta": { 2551cb0ef41Sopenharmony_ci "added": [ 2561cb0ef41Sopenharmony_ci "v0.3.1" 2571cb0ef41Sopenharmony_ci ], 2581cb0ef41Sopenharmony_ci "changes": [ 2591cb0ef41Sopenharmony_ci { 2601cb0ef41Sopenharmony_ci "version": "v6.3.0", 2611cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 2621cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 2631cb0ef41Sopenharmony_ci } 2641cb0ef41Sopenharmony_ci ] 2651cb0ef41Sopenharmony_ci }, 2661cb0ef41Sopenharmony_ci "signatures": [ 2671cb0ef41Sopenharmony_ci { 2681cb0ef41Sopenharmony_ci "return": { 2691cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 2701cb0ef41Sopenharmony_ci "name": "return", 2711cb0ef41Sopenharmony_ci "type": "any", 2721cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 2731cb0ef41Sopenharmony_ci }, 2741cb0ef41Sopenharmony_ci "params": [ 2751cb0ef41Sopenharmony_ci { 2761cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 2771cb0ef41Sopenharmony_ci "name": "options", 2781cb0ef41Sopenharmony_ci "type": "Object", 2791cb0ef41Sopenharmony_ci "options": [ 2801cb0ef41Sopenharmony_ci { 2811cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 2821cb0ef41Sopenharmony_ci "name": "displayErrors", 2831cb0ef41Sopenharmony_ci "type": "boolean", 2841cb0ef41Sopenharmony_ci "default": "`true`", 2851cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 2861cb0ef41Sopenharmony_ci }, 2871cb0ef41Sopenharmony_ci { 2881cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 2891cb0ef41Sopenharmony_ci "name": "timeout", 2901cb0ef41Sopenharmony_ci "type": "integer", 2911cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 2921cb0ef41Sopenharmony_ci }, 2931cb0ef41Sopenharmony_ci { 2941cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 2951cb0ef41Sopenharmony_ci "name": "breakOnSigint", 2961cb0ef41Sopenharmony_ci "type": "boolean", 2971cb0ef41Sopenharmony_ci "default": "`false`", 2981cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 2991cb0ef41Sopenharmony_ci } 3001cb0ef41Sopenharmony_ci ] 3011cb0ef41Sopenharmony_ci } 3021cb0ef41Sopenharmony_ci ] 3031cb0ef41Sopenharmony_ci } 3041cb0ef41Sopenharmony_ci ], 3051cb0ef41Sopenharmony_ci "desc": "<p>Runs the compiled code contained by the <code>vm.Script</code> within the context of the\ncurrent <code>global</code> object. Running code does not have access to local scope, but\n<em>does</em> have access to the current <code>global</code> object.</p>\n<p>The following example compiles code that increments a <code>global</code> variable then\nexecutes that code multiple times:</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nglobal.globalVar = 0;\n\nconst script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });\n\nfor (let i = 0; i < 1000; ++i) {\n script.runInThisContext();\n}\n\nconsole.log(globalVar);\n\n// 1000\n</code></pre>" 3061cb0ef41Sopenharmony_ci } 3071cb0ef41Sopenharmony_ci ], 3081cb0ef41Sopenharmony_ci "signatures": [ 3091cb0ef41Sopenharmony_ci { 3101cb0ef41Sopenharmony_ci "params": [ 3111cb0ef41Sopenharmony_ci { 3121cb0ef41Sopenharmony_ci "textRaw": "`code` {string} The JavaScript code to compile.", 3131cb0ef41Sopenharmony_ci "name": "code", 3141cb0ef41Sopenharmony_ci "type": "string", 3151cb0ef41Sopenharmony_ci "desc": "The JavaScript code to compile." 3161cb0ef41Sopenharmony_ci }, 3171cb0ef41Sopenharmony_ci { 3181cb0ef41Sopenharmony_ci "textRaw": "`options` {Object|string}", 3191cb0ef41Sopenharmony_ci "name": "options", 3201cb0ef41Sopenharmony_ci "type": "Object|string", 3211cb0ef41Sopenharmony_ci "options": [ 3221cb0ef41Sopenharmony_ci { 3231cb0ef41Sopenharmony_ci "textRaw": "`filename` {string} Specifies the filename used in stack traces produced by this script. **Default:** `'evalmachine.<anonymous>'`.", 3241cb0ef41Sopenharmony_ci "name": "filename", 3251cb0ef41Sopenharmony_ci "type": "string", 3261cb0ef41Sopenharmony_ci "default": "`'evalmachine.<anonymous>'`", 3271cb0ef41Sopenharmony_ci "desc": "Specifies the filename used in stack traces produced by this script." 3281cb0ef41Sopenharmony_ci }, 3291cb0ef41Sopenharmony_ci { 3301cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 3311cb0ef41Sopenharmony_ci "name": "lineOffset", 3321cb0ef41Sopenharmony_ci "type": "number", 3331cb0ef41Sopenharmony_ci "default": "`0`", 3341cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this script." 3351cb0ef41Sopenharmony_ci }, 3361cb0ef41Sopenharmony_ci { 3371cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 3381cb0ef41Sopenharmony_ci "name": "columnOffset", 3391cb0ef41Sopenharmony_ci "type": "number", 3401cb0ef41Sopenharmony_ci "default": "`0`", 3411cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this script." 3421cb0ef41Sopenharmony_ci }, 3431cb0ef41Sopenharmony_ci { 3441cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. When supplied, the `cachedDataRejected` value will be set to either `true` or `false` depending on acceptance of the data by V8.", 3451cb0ef41Sopenharmony_ci "name": "cachedData", 3461cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 3471cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. When supplied, the `cachedDataRejected` value will be set to either `true` or `false` depending on acceptance of the data by V8." 3481cb0ef41Sopenharmony_ci }, 3491cb0ef41Sopenharmony_ci { 3501cb0ef41Sopenharmony_ci "textRaw": "`produceCachedData` {boolean} When `true` and no `cachedData` is present, V8 will attempt to produce code cache data for `code`. Upon success, a `Buffer` with V8's code cache data will be produced and stored in the `cachedData` property of the returned `vm.Script` instance. The `cachedDataProduced` value will be set to either `true` or `false` depending on whether code cache data is produced successfully. This option is **deprecated** in favor of `script.createCachedData()`. **Default:** `false`.", 3511cb0ef41Sopenharmony_ci "name": "produceCachedData", 3521cb0ef41Sopenharmony_ci "type": "boolean", 3531cb0ef41Sopenharmony_ci "default": "`false`", 3541cb0ef41Sopenharmony_ci "desc": "When `true` and no `cachedData` is present, V8 will attempt to produce code cache data for `code`. Upon success, a `Buffer` with V8's code cache data will be produced and stored in the `cachedData` property of the returned `vm.Script` instance. The `cachedDataProduced` value will be set to either `true` or `false` depending on whether code cache data is produced successfully. This option is **deprecated** in favor of `script.createCachedData()`." 3551cb0ef41Sopenharmony_ci }, 3561cb0ef41Sopenharmony_ci { 3571cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 3581cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 3591cb0ef41Sopenharmony_ci "type": "Function", 3601cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 3611cb0ef41Sopenharmony_ci "options": [ 3621cb0ef41Sopenharmony_ci { 3631cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 3641cb0ef41Sopenharmony_ci "name": "specifier", 3651cb0ef41Sopenharmony_ci "type": "string", 3661cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 3671cb0ef41Sopenharmony_ci }, 3681cb0ef41Sopenharmony_ci { 3691cb0ef41Sopenharmony_ci "textRaw": "`script` {vm.Script}", 3701cb0ef41Sopenharmony_ci "name": "script", 3711cb0ef41Sopenharmony_ci "type": "vm.Script" 3721cb0ef41Sopenharmony_ci }, 3731cb0ef41Sopenharmony_ci { 3741cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 3751cb0ef41Sopenharmony_ci "name": "importAttributes", 3761cb0ef41Sopenharmony_ci "type": "Object", 3771cb0ef41Sopenharmony_ci "desc": "The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 3781cb0ef41Sopenharmony_ci }, 3791cb0ef41Sopenharmony_ci { 3801cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 3811cb0ef41Sopenharmony_ci "name": "return", 3821cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 3831cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 3841cb0ef41Sopenharmony_ci } 3851cb0ef41Sopenharmony_ci ] 3861cb0ef41Sopenharmony_ci } 3871cb0ef41Sopenharmony_ci ] 3881cb0ef41Sopenharmony_ci } 3891cb0ef41Sopenharmony_ci ], 3901cb0ef41Sopenharmony_ci "desc": "<p>If <code>options</code> is a string, then it specifies the filename.</p>\n<p>Creating a new <code>vm.Script</code> object compiles <code>code</code> but does not run it. The\ncompiled <code>vm.Script</code> can be run later multiple times. The <code>code</code> is not bound to\nany global object; rather, it is bound before each run, just for that run.</p>" 3911cb0ef41Sopenharmony_ci } 3921cb0ef41Sopenharmony_ci ] 3931cb0ef41Sopenharmony_ci }, 3941cb0ef41Sopenharmony_ci { 3951cb0ef41Sopenharmony_ci "textRaw": "Class: `vm.Module`", 3961cb0ef41Sopenharmony_ci "type": "class", 3971cb0ef41Sopenharmony_ci "name": "vm.Module", 3981cb0ef41Sopenharmony_ci "meta": { 3991cb0ef41Sopenharmony_ci "added": [ 4001cb0ef41Sopenharmony_ci "v13.0.0", 4011cb0ef41Sopenharmony_ci "v12.16.0" 4021cb0ef41Sopenharmony_ci ], 4031cb0ef41Sopenharmony_ci "changes": [] 4041cb0ef41Sopenharmony_ci }, 4051cb0ef41Sopenharmony_ci "stability": 1, 4061cb0ef41Sopenharmony_ci "stabilityText": "Experimental", 4071cb0ef41Sopenharmony_ci "desc": "<p>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</p>\n<p>The <code>vm.Module</code> class provides a low-level interface for using\nECMAScript modules in VM contexts. It is the counterpart of the <code>vm.Script</code>\nclass that closely mirrors <a href=\"https://www.ecma-international.org/ecma-262/#sec-abstract-module-records\">Module Record</a>s as defined in the ECMAScript\nspecification.</p>\n<p>Unlike <code>vm.Script</code> however, every <code>vm.Module</code> object is bound to a context from\nits creation. Operations on <code>vm.Module</code> objects are intrinsically asynchronous,\nin contrast with the synchronous nature of <code>vm.Script</code> objects. The use of\n'async' functions can help with manipulating <code>vm.Module</code> objects.</p>\n<p>Using a <code>vm.Module</code> object requires three distinct steps: creation/parsing,\nlinking, and evaluation. These three steps are illustrated in the following\nexample.</p>\n<p>This implementation lies at a lower level than the <a href=\"esm.html#modules-ecmascript-modules\">ECMAScript Module\nloader</a>. There is also no way to interact with the Loader yet, though\nsupport is planned.</p>\n<pre><code class=\"language-mjs\">import vm from 'node:vm';\n\nconst contextifiedObject = vm.createContext({\n secret: 42,\n print: console.log,\n});\n\n// Step 1\n//\n// Create a Module by constructing a new `vm.SourceTextModule` object. This\n// parses the provided source text, throwing a `SyntaxError` if anything goes\n// wrong. By default, a Module is created in the top context. But here, we\n// specify `contextifiedObject` as the context this Module belongs to.\n//\n// Here, we attempt to obtain the default export from the module \"foo\", and\n// put it into local binding \"secret\".\n\nconst bar = new vm.SourceTextModule(`\n import s from 'foo';\n s;\n print(s);\n`, { context: contextifiedObject });\n\n// Step 2\n//\n// \"Link\" the imported dependencies of this Module to it.\n//\n// The provided linking callback (the \"linker\") accepts two arguments: the\n// parent module (`bar` in this case) and the string that is the specifier of\n// the imported module. The callback is expected to return a Module that\n// corresponds to the provided specifier, with certain requirements documented\n// in `module.link()`.\n//\n// If linking has not started for the returned Module, the same linker\n// callback will be called on the returned Module.\n//\n// Even top-level Modules without dependencies must be explicitly linked. The\n// callback provided would never be called, however.\n//\n// The link() method returns a Promise that will be resolved when all the\n// Promises returned by the linker resolve.\n//\n// Note: This is a contrived example in that the linker function creates a new\n// \"foo\" module every time it is called. In a full-fledged module system, a\n// cache would probably be used to avoid duplicated modules.\n\nasync function linker(specifier, referencingModule) {\n if (specifier === 'foo') {\n return new vm.SourceTextModule(`\n // The \"secret\" variable refers to the global variable we added to\n // \"contextifiedObject\" when creating the context.\n export default secret;\n `, { context: referencingModule.context });\n\n // Using `contextifiedObject` instead of `referencingModule.context`\n // here would work as well.\n }\n throw new Error(`Unable to resolve dependency: ${specifier}`);\n}\nawait bar.link(linker);\n\n// Step 3\n//\n// Evaluate the Module. The evaluate() method returns a promise which will\n// resolve after the module has finished evaluating.\n\n// Prints 42.\nawait bar.evaluate();\n</code></pre>\n<pre><code class=\"language-cjs\">const vm = require('node:vm');\n\nconst contextifiedObject = vm.createContext({\n secret: 42,\n print: console.log,\n});\n\n(async () => {\n // Step 1\n //\n // Create a Module by constructing a new `vm.SourceTextModule` object. This\n // parses the provided source text, throwing a `SyntaxError` if anything goes\n // wrong. By default, a Module is created in the top context. But here, we\n // specify `contextifiedObject` as the context this Module belongs to.\n //\n // Here, we attempt to obtain the default export from the module \"foo\", and\n // put it into local binding \"secret\".\n\n const bar = new vm.SourceTextModule(`\n import s from 'foo';\n s;\n print(s);\n `, { context: contextifiedObject });\n\n // Step 2\n //\n // \"Link\" the imported dependencies of this Module to it.\n //\n // The provided linking callback (the \"linker\") accepts two arguments: the\n // parent module (`bar` in this case) and the string that is the specifier of\n // the imported module. The callback is expected to return a Module that\n // corresponds to the provided specifier, with certain requirements documented\n // in `module.link()`.\n //\n // If linking has not started for the returned Module, the same linker\n // callback will be called on the returned Module.\n //\n // Even top-level Modules without dependencies must be explicitly linked. The\n // callback provided would never be called, however.\n //\n // The link() method returns a Promise that will be resolved when all the\n // Promises returned by the linker resolve.\n //\n // Note: This is a contrived example in that the linker function creates a new\n // \"foo\" module every time it is called. In a full-fledged module system, a\n // cache would probably be used to avoid duplicated modules.\n\n async function linker(specifier, referencingModule) {\n if (specifier === 'foo') {\n return new vm.SourceTextModule(`\n // The \"secret\" variable refers to the global variable we added to\n // \"contextifiedObject\" when creating the context.\n export default secret;\n `, { context: referencingModule.context });\n\n // Using `contextifiedObject` instead of `referencingModule.context`\n // here would work as well.\n }\n throw new Error(`Unable to resolve dependency: ${specifier}`);\n }\n await bar.link(linker);\n\n // Step 3\n //\n // Evaluate the Module. The evaluate() method returns a promise which will\n // resolve after the module has finished evaluating.\n\n // Prints 42.\n await bar.evaluate();\n})();\n</code></pre>", 4081cb0ef41Sopenharmony_ci "properties": [ 4091cb0ef41Sopenharmony_ci { 4101cb0ef41Sopenharmony_ci "textRaw": "`dependencySpecifiers` {string\\[]}", 4111cb0ef41Sopenharmony_ci "type": "string\\[]", 4121cb0ef41Sopenharmony_ci "name": "dependencySpecifiers", 4131cb0ef41Sopenharmony_ci "desc": "<p>The specifiers of all dependencies of this module. The returned array is frozen\nto disallow any changes to it.</p>\n<p>Corresponds to the <code>[[RequestedModules]]</code> field of <a href=\"https://tc39.es/ecma262/#sec-cyclic-module-records\">Cyclic Module Record</a>s in\nthe ECMAScript specification.</p>" 4141cb0ef41Sopenharmony_ci }, 4151cb0ef41Sopenharmony_ci { 4161cb0ef41Sopenharmony_ci "textRaw": "`error` {any}", 4171cb0ef41Sopenharmony_ci "type": "any", 4181cb0ef41Sopenharmony_ci "name": "error", 4191cb0ef41Sopenharmony_ci "desc": "<p>If the <code>module.status</code> is <code>'errored'</code>, this property contains the exception\nthrown by the module during evaluation. If the status is anything else,\naccessing this property will result in a thrown exception.</p>\n<p>The value <code>undefined</code> cannot be used for cases where there is not a thrown\nexception due to possible ambiguity with <code>throw undefined;</code>.</p>\n<p>Corresponds to the <code>[[EvaluationError]]</code> field of <a href=\"https://tc39.es/ecma262/#sec-cyclic-module-records\">Cyclic Module Record</a>s\nin the ECMAScript specification.</p>" 4201cb0ef41Sopenharmony_ci }, 4211cb0ef41Sopenharmony_ci { 4221cb0ef41Sopenharmony_ci "textRaw": "`identifier` {string}", 4231cb0ef41Sopenharmony_ci "type": "string", 4241cb0ef41Sopenharmony_ci "name": "identifier", 4251cb0ef41Sopenharmony_ci "desc": "<p>The identifier of the current module, as set in the constructor.</p>" 4261cb0ef41Sopenharmony_ci }, 4271cb0ef41Sopenharmony_ci { 4281cb0ef41Sopenharmony_ci "textRaw": "`namespace` {Object}", 4291cb0ef41Sopenharmony_ci "type": "Object", 4301cb0ef41Sopenharmony_ci "name": "namespace", 4311cb0ef41Sopenharmony_ci "desc": "<p>The namespace object of the module. This is only available after linking\n(<code>module.link()</code>) has completed.</p>\n<p>Corresponds to the <a href=\"https://tc39.es/ecma262/#sec-getmodulenamespace\">GetModuleNamespace</a> abstract operation in the ECMAScript\nspecification.</p>" 4321cb0ef41Sopenharmony_ci }, 4331cb0ef41Sopenharmony_ci { 4341cb0ef41Sopenharmony_ci "textRaw": "`status` {string}", 4351cb0ef41Sopenharmony_ci "type": "string", 4361cb0ef41Sopenharmony_ci "name": "status", 4371cb0ef41Sopenharmony_ci "desc": "<p>The current status of the module. Will be one of:</p>\n<ul>\n<li>\n<p><code>'unlinked'</code>: <code>module.link()</code> has not yet been called.</p>\n</li>\n<li>\n<p><code>'linking'</code>: <code>module.link()</code> has been called, but not all Promises returned\nby the linker function have been resolved yet.</p>\n</li>\n<li>\n<p><code>'linked'</code>: The module has been linked successfully, and all of its\ndependencies are linked, but <code>module.evaluate()</code> has not yet been called.</p>\n</li>\n<li>\n<p><code>'evaluating'</code>: The module is being evaluated through a <code>module.evaluate()</code> on\nitself or a parent module.</p>\n</li>\n<li>\n<p><code>'evaluated'</code>: The module has been successfully evaluated.</p>\n</li>\n<li>\n<p><code>'errored'</code>: The module has been evaluated, but an exception was thrown.</p>\n</li>\n</ul>\n<p>Other than <code>'errored'</code>, this status string corresponds to the specification's\n<a href=\"https://tc39.es/ecma262/#sec-cyclic-module-records\">Cyclic Module Record</a>'s <code>[[Status]]</code> field. <code>'errored'</code> corresponds to\n<code>'evaluated'</code> in the specification, but with <code>[[EvaluationError]]</code> set to a\nvalue that is not <code>undefined</code>.</p>" 4381cb0ef41Sopenharmony_ci } 4391cb0ef41Sopenharmony_ci ], 4401cb0ef41Sopenharmony_ci "methods": [ 4411cb0ef41Sopenharmony_ci { 4421cb0ef41Sopenharmony_ci "textRaw": "`module.evaluate([options])`", 4431cb0ef41Sopenharmony_ci "type": "method", 4441cb0ef41Sopenharmony_ci "name": "evaluate", 4451cb0ef41Sopenharmony_ci "signatures": [ 4461cb0ef41Sopenharmony_ci { 4471cb0ef41Sopenharmony_ci "return": { 4481cb0ef41Sopenharmony_ci "textRaw": "Returns: {Promise} Fulfills with `undefined` upon success.", 4491cb0ef41Sopenharmony_ci "name": "return", 4501cb0ef41Sopenharmony_ci "type": "Promise", 4511cb0ef41Sopenharmony_ci "desc": "Fulfills with `undefined` upon success." 4521cb0ef41Sopenharmony_ci }, 4531cb0ef41Sopenharmony_ci "params": [ 4541cb0ef41Sopenharmony_ci { 4551cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 4561cb0ef41Sopenharmony_ci "name": "options", 4571cb0ef41Sopenharmony_ci "type": "Object", 4581cb0ef41Sopenharmony_ci "options": [ 4591cb0ef41Sopenharmony_ci { 4601cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to evaluate before terminating execution. If execution is interrupted, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 4611cb0ef41Sopenharmony_ci "name": "timeout", 4621cb0ef41Sopenharmony_ci "type": "integer", 4631cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to evaluate before terminating execution. If execution is interrupted, an [`Error`][] will be thrown. This value must be a strictly positive integer." 4641cb0ef41Sopenharmony_ci }, 4651cb0ef41Sopenharmony_ci { 4661cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 4671cb0ef41Sopenharmony_ci "name": "breakOnSigint", 4681cb0ef41Sopenharmony_ci "type": "boolean", 4691cb0ef41Sopenharmony_ci "default": "`false`", 4701cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 4711cb0ef41Sopenharmony_ci } 4721cb0ef41Sopenharmony_ci ] 4731cb0ef41Sopenharmony_ci } 4741cb0ef41Sopenharmony_ci ] 4751cb0ef41Sopenharmony_ci } 4761cb0ef41Sopenharmony_ci ], 4771cb0ef41Sopenharmony_ci "desc": "<p>Evaluate the module.</p>\n<p>This must be called after the module has been linked; otherwise it will reject.\nIt could be called also when the module has already been evaluated, in which\ncase it will either do nothing if the initial evaluation ended in success\n(<code>module.status</code> is <code>'evaluated'</code>) or it will re-throw the exception that the\ninitial evaluation resulted in (<code>module.status</code> is <code>'errored'</code>).</p>\n<p>This method cannot be called while the module is being evaluated\n(<code>module.status</code> is <code>'evaluating'</code>).</p>\n<p>Corresponds to the <a href=\"https://tc39.es/ecma262/#sec-moduleevaluation\">Evaluate() concrete method</a> field of <a href=\"https://tc39.es/ecma262/#sec-cyclic-module-records\">Cyclic Module\nRecord</a>s in the ECMAScript specification.</p>" 4781cb0ef41Sopenharmony_ci }, 4791cb0ef41Sopenharmony_ci { 4801cb0ef41Sopenharmony_ci "textRaw": "`module.link(linker)`", 4811cb0ef41Sopenharmony_ci "type": "method", 4821cb0ef41Sopenharmony_ci "name": "link", 4831cb0ef41Sopenharmony_ci "meta": { 4841cb0ef41Sopenharmony_ci "changes": [ 4851cb0ef41Sopenharmony_ci { 4861cb0ef41Sopenharmony_ci "version": "v18.19.0", 4871cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/50141", 4881cb0ef41Sopenharmony_ci "description": "The option `extra.assert` is renamed to `extra.attributes`. The former name is still provided for backward compatibility." 4891cb0ef41Sopenharmony_ci } 4901cb0ef41Sopenharmony_ci ] 4911cb0ef41Sopenharmony_ci }, 4921cb0ef41Sopenharmony_ci "signatures": [ 4931cb0ef41Sopenharmony_ci { 4941cb0ef41Sopenharmony_ci "return": { 4951cb0ef41Sopenharmony_ci "textRaw": "Returns: {Promise}", 4961cb0ef41Sopenharmony_ci "name": "return", 4971cb0ef41Sopenharmony_ci "type": "Promise" 4981cb0ef41Sopenharmony_ci }, 4991cb0ef41Sopenharmony_ci "params": [ 5001cb0ef41Sopenharmony_ci { 5011cb0ef41Sopenharmony_ci "textRaw": "`linker` {Function}", 5021cb0ef41Sopenharmony_ci "name": "linker", 5031cb0ef41Sopenharmony_ci "type": "Function", 5041cb0ef41Sopenharmony_ci "options": [ 5051cb0ef41Sopenharmony_ci { 5061cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} The specifier of the requested module:```mjs import foo from 'foo'; // ^^^^^ the module specifier ```", 5071cb0ef41Sopenharmony_ci "name": "specifier", 5081cb0ef41Sopenharmony_ci "type": "string", 5091cb0ef41Sopenharmony_ci "desc": "The specifier of the requested module:```mjs import foo from 'foo'; // ^^^^^ the module specifier ```" 5101cb0ef41Sopenharmony_ci }, 5111cb0ef41Sopenharmony_ci { 5121cb0ef41Sopenharmony_ci "textRaw": "`referencingModule` {vm.Module} The `Module` object `link()` is called on.", 5131cb0ef41Sopenharmony_ci "name": "referencingModule", 5141cb0ef41Sopenharmony_ci "type": "vm.Module", 5151cb0ef41Sopenharmony_ci "desc": "The `Module` object `link()` is called on." 5161cb0ef41Sopenharmony_ci }, 5171cb0ef41Sopenharmony_ci { 5181cb0ef41Sopenharmony_ci "textRaw": "`extra` {Object}", 5191cb0ef41Sopenharmony_ci "name": "extra", 5201cb0ef41Sopenharmony_ci "type": "Object", 5211cb0ef41Sopenharmony_ci "options": [ 5221cb0ef41Sopenharmony_ci { 5231cb0ef41Sopenharmony_ci "textRaw": "`attributes` {Object} The data from the attribute:```mjs import foo from 'foo' with { name: 'value' }; // ^^^^^^^^^^^^^^^^^ the attribute ```Per ECMA-262, hosts are expected to trigger an error if an unsupported attribute is present.", 5241cb0ef41Sopenharmony_ci "name": "attributes", 5251cb0ef41Sopenharmony_ci "type": "Object", 5261cb0ef41Sopenharmony_ci "desc": "The data from the attribute:```mjs import foo from 'foo' with { name: 'value' }; // ^^^^^^^^^^^^^^^^^ the attribute ```Per ECMA-262, hosts are expected to trigger an error if an unsupported attribute is present." 5271cb0ef41Sopenharmony_ci }, 5281cb0ef41Sopenharmony_ci { 5291cb0ef41Sopenharmony_ci "textRaw": "`assert` {Object} Alias for `extra.attributes`.", 5301cb0ef41Sopenharmony_ci "name": "assert", 5311cb0ef41Sopenharmony_ci "type": "Object", 5321cb0ef41Sopenharmony_ci "desc": "Alias for `extra.attributes`." 5331cb0ef41Sopenharmony_ci } 5341cb0ef41Sopenharmony_ci ] 5351cb0ef41Sopenharmony_ci }, 5361cb0ef41Sopenharmony_ci { 5371cb0ef41Sopenharmony_ci "textRaw": "Returns: {vm.Module|Promise}", 5381cb0ef41Sopenharmony_ci "name": "return", 5391cb0ef41Sopenharmony_ci "type": "vm.Module|Promise" 5401cb0ef41Sopenharmony_ci } 5411cb0ef41Sopenharmony_ci ] 5421cb0ef41Sopenharmony_ci } 5431cb0ef41Sopenharmony_ci ] 5441cb0ef41Sopenharmony_ci } 5451cb0ef41Sopenharmony_ci ], 5461cb0ef41Sopenharmony_ci "desc": "<p>Link module dependencies. This method must be called before evaluation, and\ncan only be called once per module.</p>\n<p>The function is expected to return a <code>Module</code> object or a <code>Promise</code> that\neventually resolves to a <code>Module</code> object. The returned <code>Module</code> must satisfy the\nfollowing two invariants:</p>\n<ul>\n<li>It must belong to the same context as the parent <code>Module</code>.</li>\n<li>Its <code>status</code> must not be <code>'errored'</code>.</li>\n</ul>\n<p>If the returned <code>Module</code>'s <code>status</code> is <code>'unlinked'</code>, this method will be\nrecursively called on the returned <code>Module</code> with the same provided <code>linker</code>\nfunction.</p>\n<p><code>link()</code> returns a <code>Promise</code> that will either get resolved when all linking\ninstances resolve to a valid <code>Module</code>, or rejected if the linker function either\nthrows an exception or returns an invalid <code>Module</code>.</p>\n<p>The linker function roughly corresponds to the implementation-defined\n<a href=\"https://tc39.es/ecma262/#sec-hostresolveimportedmodule\">HostResolveImportedModule</a> abstract operation in the ECMAScript\nspecification, with a few key differences:</p>\n<ul>\n<li>The linker function is allowed to be asynchronous while\n<a href=\"https://tc39.es/ecma262/#sec-hostresolveimportedmodule\">HostResolveImportedModule</a> is synchronous.</li>\n</ul>\n<p>The actual <a href=\"https://tc39.es/ecma262/#sec-hostresolveimportedmodule\">HostResolveImportedModule</a> implementation used during module\nlinking is one that returns the modules linked during linking. Since at\nthat point all modules would have been fully linked already, the\n<a href=\"https://tc39.es/ecma262/#sec-hostresolveimportedmodule\">HostResolveImportedModule</a> implementation is fully synchronous per\nspecification.</p>\n<p>Corresponds to the <a href=\"https://tc39.es/ecma262/#sec-moduledeclarationlinking\">Link() concrete method</a> field of <a href=\"https://tc39.es/ecma262/#sec-cyclic-module-records\">Cyclic Module\nRecord</a>s in the ECMAScript specification.</p>" 5471cb0ef41Sopenharmony_ci } 5481cb0ef41Sopenharmony_ci ] 5491cb0ef41Sopenharmony_ci }, 5501cb0ef41Sopenharmony_ci { 5511cb0ef41Sopenharmony_ci "textRaw": "Class: `vm.SourceTextModule`", 5521cb0ef41Sopenharmony_ci "type": "class", 5531cb0ef41Sopenharmony_ci "name": "vm.SourceTextModule", 5541cb0ef41Sopenharmony_ci "meta": { 5551cb0ef41Sopenharmony_ci "added": [ 5561cb0ef41Sopenharmony_ci "v9.6.0" 5571cb0ef41Sopenharmony_ci ], 5581cb0ef41Sopenharmony_ci "changes": [] 5591cb0ef41Sopenharmony_ci }, 5601cb0ef41Sopenharmony_ci "stability": 1, 5611cb0ef41Sopenharmony_ci "stabilityText": "Experimental", 5621cb0ef41Sopenharmony_ci "desc": "<p>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</p>\n<ul>\n<li>Extends: <a href=\"vm.html#class-vmmodule\" class=\"type\"><vm.Module></a></li>\n</ul>\n<p>The <code>vm.SourceTextModule</code> class provides the <a href=\"https://tc39.es/ecma262/#sec-source-text-module-records\">Source Text Module Record</a> as\ndefined in the ECMAScript specification.</p>", 5631cb0ef41Sopenharmony_ci "methods": [ 5641cb0ef41Sopenharmony_ci { 5651cb0ef41Sopenharmony_ci "textRaw": "`sourceTextModule.createCachedData()`", 5661cb0ef41Sopenharmony_ci "type": "method", 5671cb0ef41Sopenharmony_ci "name": "createCachedData", 5681cb0ef41Sopenharmony_ci "meta": { 5691cb0ef41Sopenharmony_ci "added": [ 5701cb0ef41Sopenharmony_ci "v13.7.0", 5711cb0ef41Sopenharmony_ci "v12.17.0" 5721cb0ef41Sopenharmony_ci ], 5731cb0ef41Sopenharmony_ci "changes": [] 5741cb0ef41Sopenharmony_ci }, 5751cb0ef41Sopenharmony_ci "signatures": [ 5761cb0ef41Sopenharmony_ci { 5771cb0ef41Sopenharmony_ci "return": { 5781cb0ef41Sopenharmony_ci "textRaw": "Returns: {Buffer}", 5791cb0ef41Sopenharmony_ci "name": "return", 5801cb0ef41Sopenharmony_ci "type": "Buffer" 5811cb0ef41Sopenharmony_ci }, 5821cb0ef41Sopenharmony_ci "params": [] 5831cb0ef41Sopenharmony_ci } 5841cb0ef41Sopenharmony_ci ], 5851cb0ef41Sopenharmony_ci "desc": "<p>Creates a code cache that can be used with the <code>SourceTextModule</code> constructor's\n<code>cachedData</code> option. Returns a <code>Buffer</code>. This method may be called any number\nof times before the module has been evaluated.</p>\n<p>The code cache of the <code>SourceTextModule</code> doesn't contain any JavaScript\nobservable states. The code cache is safe to be saved along side the script\nsource and used to construct new <code>SourceTextModule</code> instances multiple times.</p>\n<p>Functions in the <code>SourceTextModule</code> source can be marked as lazily compiled\nand they are not compiled at construction of the <code>SourceTextModule</code>. These\nfunctions are going to be compiled when they are invoked the first time. The\ncode cache serializes the metadata that V8 currently knows about the\n<code>SourceTextModule</code> that it can use to speed up future compilations.</p>\n<pre><code class=\"language-js\">// Create an initial module\nconst module = new vm.SourceTextModule('const a = 1;');\n\n// Create cached data from this module\nconst cachedData = module.createCachedData();\n\n// Create a new module using the cached data. The code must be the same.\nconst module2 = new vm.SourceTextModule('const a = 1;', { cachedData });\n</code></pre>" 5861cb0ef41Sopenharmony_ci } 5871cb0ef41Sopenharmony_ci ], 5881cb0ef41Sopenharmony_ci "signatures": [ 5891cb0ef41Sopenharmony_ci { 5901cb0ef41Sopenharmony_ci "params": [ 5911cb0ef41Sopenharmony_ci { 5921cb0ef41Sopenharmony_ci "textRaw": "`code` {string} JavaScript Module code to parse", 5931cb0ef41Sopenharmony_ci "name": "code", 5941cb0ef41Sopenharmony_ci "type": "string", 5951cb0ef41Sopenharmony_ci "desc": "JavaScript Module code to parse" 5961cb0ef41Sopenharmony_ci }, 5971cb0ef41Sopenharmony_ci { 5981cb0ef41Sopenharmony_ci "textRaw": "`options`", 5991cb0ef41Sopenharmony_ci "name": "options", 6001cb0ef41Sopenharmony_ci "options": [ 6011cb0ef41Sopenharmony_ci { 6021cb0ef41Sopenharmony_ci "textRaw": "`identifier` {string} String used in stack traces. **Default:** `'vm:module(i)'` where `i` is a context-specific ascending index.", 6031cb0ef41Sopenharmony_ci "name": "identifier", 6041cb0ef41Sopenharmony_ci "type": "string", 6051cb0ef41Sopenharmony_ci "default": "`'vm:module(i)'` where `i` is a context-specific ascending index", 6061cb0ef41Sopenharmony_ci "desc": "String used in stack traces." 6071cb0ef41Sopenharmony_ci }, 6081cb0ef41Sopenharmony_ci { 6091cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. The `code` must be the same as the module from which this `cachedData` was created.", 6101cb0ef41Sopenharmony_ci "name": "cachedData", 6111cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 6121cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. The `code` must be the same as the module from which this `cachedData` was created." 6131cb0ef41Sopenharmony_ci }, 6141cb0ef41Sopenharmony_ci { 6151cb0ef41Sopenharmony_ci "textRaw": "`context` {Object} The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in. If no context is specified, the module is evaluated in the current execution context.", 6161cb0ef41Sopenharmony_ci "name": "context", 6171cb0ef41Sopenharmony_ci "type": "Object", 6181cb0ef41Sopenharmony_ci "desc": "The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in. If no context is specified, the module is evaluated in the current execution context." 6191cb0ef41Sopenharmony_ci }, 6201cb0ef41Sopenharmony_ci { 6211cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {integer} Specifies the line number offset that is displayed in stack traces produced by this `Module`. **Default:** `0`.", 6221cb0ef41Sopenharmony_ci "name": "lineOffset", 6231cb0ef41Sopenharmony_ci "type": "integer", 6241cb0ef41Sopenharmony_ci "default": "`0`", 6251cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this `Module`." 6261cb0ef41Sopenharmony_ci }, 6271cb0ef41Sopenharmony_ci { 6281cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {integer} Specifies the first-line column number offset that is displayed in stack traces produced by this `Module`. **Default:** `0`.", 6291cb0ef41Sopenharmony_ci "name": "columnOffset", 6301cb0ef41Sopenharmony_ci "type": "integer", 6311cb0ef41Sopenharmony_ci "default": "`0`", 6321cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this `Module`." 6331cb0ef41Sopenharmony_ci }, 6341cb0ef41Sopenharmony_ci { 6351cb0ef41Sopenharmony_ci "textRaw": "`initializeImportMeta` {Function} Called during evaluation of this `Module` to initialize the `import.meta`.", 6361cb0ef41Sopenharmony_ci "name": "initializeImportMeta", 6371cb0ef41Sopenharmony_ci "type": "Function", 6381cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this `Module` to initialize the `import.meta`.", 6391cb0ef41Sopenharmony_ci "options": [ 6401cb0ef41Sopenharmony_ci { 6411cb0ef41Sopenharmony_ci "textRaw": "`meta` {import.meta}", 6421cb0ef41Sopenharmony_ci "name": "meta", 6431cb0ef41Sopenharmony_ci "type": "import.meta" 6441cb0ef41Sopenharmony_ci }, 6451cb0ef41Sopenharmony_ci { 6461cb0ef41Sopenharmony_ci "textRaw": "`module` {vm.SourceTextModule}", 6471cb0ef41Sopenharmony_ci "name": "module", 6481cb0ef41Sopenharmony_ci "type": "vm.SourceTextModule" 6491cb0ef41Sopenharmony_ci } 6501cb0ef41Sopenharmony_ci ] 6511cb0ef41Sopenharmony_ci }, 6521cb0ef41Sopenharmony_ci { 6531cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 6541cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 6551cb0ef41Sopenharmony_ci "type": "Function", 6561cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 6571cb0ef41Sopenharmony_ci "options": [ 6581cb0ef41Sopenharmony_ci { 6591cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 6601cb0ef41Sopenharmony_ci "name": "specifier", 6611cb0ef41Sopenharmony_ci "type": "string", 6621cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 6631cb0ef41Sopenharmony_ci }, 6641cb0ef41Sopenharmony_ci { 6651cb0ef41Sopenharmony_ci "textRaw": "`module` {vm.Module}", 6661cb0ef41Sopenharmony_ci "name": "module", 6671cb0ef41Sopenharmony_ci "type": "vm.Module" 6681cb0ef41Sopenharmony_ci }, 6691cb0ef41Sopenharmony_ci { 6701cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"assert\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 6711cb0ef41Sopenharmony_ci "name": "importAttributes", 6721cb0ef41Sopenharmony_ci "type": "Object", 6731cb0ef41Sopenharmony_ci "desc": "The `\"assert\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 6741cb0ef41Sopenharmony_ci }, 6751cb0ef41Sopenharmony_ci { 6761cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 6771cb0ef41Sopenharmony_ci "name": "return", 6781cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 6791cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 6801cb0ef41Sopenharmony_ci } 6811cb0ef41Sopenharmony_ci ] 6821cb0ef41Sopenharmony_ci } 6831cb0ef41Sopenharmony_ci ] 6841cb0ef41Sopenharmony_ci } 6851cb0ef41Sopenharmony_ci ], 6861cb0ef41Sopenharmony_ci "desc": "<p>Creates a new <code>SourceTextModule</code> instance.</p>\n<p>Properties assigned to the <code>import.meta</code> object that are objects may\nallow the module to access information outside the specified <code>context</code>. Use\n<code>vm.runInContext()</code> to create objects in a specific context.</p>\n<pre><code class=\"language-mjs\">import vm from 'node:vm';\n\nconst contextifiedObject = vm.createContext({ secret: 42 });\n\nconst module = new vm.SourceTextModule(\n 'Object.getPrototypeOf(import.meta.prop).secret = secret;',\n {\n initializeImportMeta(meta) {\n // Note: this object is created in the top context. As such,\n // Object.getPrototypeOf(import.meta.prop) points to the\n // Object.prototype in the top context rather than that in\n // the contextified object.\n meta.prop = {};\n },\n });\n// Since module has no dependencies, the linker function will never be called.\nawait module.link(() => {});\nawait module.evaluate();\n\n// Now, Object.prototype.secret will be equal to 42.\n//\n// To fix this problem, replace\n// meta.prop = {};\n// above with\n// meta.prop = vm.runInContext('{}', contextifiedObject);\n</code></pre>\n<pre><code class=\"language-cjs\">const vm = require('node:vm');\nconst contextifiedObject = vm.createContext({ secret: 42 });\n(async () => {\n const module = new vm.SourceTextModule(\n 'Object.getPrototypeOf(import.meta.prop).secret = secret;',\n {\n initializeImportMeta(meta) {\n // Note: this object is created in the top context. As such,\n // Object.getPrototypeOf(import.meta.prop) points to the\n // Object.prototype in the top context rather than that in\n // the contextified object.\n meta.prop = {};\n },\n });\n // Since module has no dependencies, the linker function will never be called.\n await module.link(() => {});\n await module.evaluate();\n // Now, Object.prototype.secret will be equal to 42.\n //\n // To fix this problem, replace\n // meta.prop = {};\n // above with\n // meta.prop = vm.runInContext('{}', contextifiedObject);\n})();\n</code></pre>" 6871cb0ef41Sopenharmony_ci } 6881cb0ef41Sopenharmony_ci ] 6891cb0ef41Sopenharmony_ci }, 6901cb0ef41Sopenharmony_ci { 6911cb0ef41Sopenharmony_ci "textRaw": "Class: `vm.SyntheticModule`", 6921cb0ef41Sopenharmony_ci "type": "class", 6931cb0ef41Sopenharmony_ci "name": "vm.SyntheticModule", 6941cb0ef41Sopenharmony_ci "meta": { 6951cb0ef41Sopenharmony_ci "added": [ 6961cb0ef41Sopenharmony_ci "v13.0.0", 6971cb0ef41Sopenharmony_ci "v12.16.0" 6981cb0ef41Sopenharmony_ci ], 6991cb0ef41Sopenharmony_ci "changes": [] 7001cb0ef41Sopenharmony_ci }, 7011cb0ef41Sopenharmony_ci "stability": 1, 7021cb0ef41Sopenharmony_ci "stabilityText": "Experimental", 7031cb0ef41Sopenharmony_ci "desc": "<p>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</p>\n<ul>\n<li>Extends: <a href=\"vm.html#class-vmmodule\" class=\"type\"><vm.Module></a></li>\n</ul>\n<p>The <code>vm.SyntheticModule</code> class provides the <a href=\"https://heycam.github.io/webidl/#synthetic-module-records\">Synthetic Module Record</a> as\ndefined in the WebIDL specification. The purpose of synthetic modules is to\nprovide a generic interface for exposing non-JavaScript sources to ECMAScript\nmodule graphs.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst source = '{ \"a\": 1 }';\nconst module = new vm.SyntheticModule(['default'], function() {\n const obj = JSON.parse(source);\n this.setExport('default', obj);\n});\n\n// Use `module` in linking...\n</code></pre>", 7041cb0ef41Sopenharmony_ci "methods": [ 7051cb0ef41Sopenharmony_ci { 7061cb0ef41Sopenharmony_ci "textRaw": "`syntheticModule.setExport(name, value)`", 7071cb0ef41Sopenharmony_ci "type": "method", 7081cb0ef41Sopenharmony_ci "name": "setExport", 7091cb0ef41Sopenharmony_ci "meta": { 7101cb0ef41Sopenharmony_ci "added": [ 7111cb0ef41Sopenharmony_ci "v13.0.0", 7121cb0ef41Sopenharmony_ci "v12.16.0" 7131cb0ef41Sopenharmony_ci ], 7141cb0ef41Sopenharmony_ci "changes": [] 7151cb0ef41Sopenharmony_ci }, 7161cb0ef41Sopenharmony_ci "signatures": [ 7171cb0ef41Sopenharmony_ci { 7181cb0ef41Sopenharmony_ci "params": [ 7191cb0ef41Sopenharmony_ci { 7201cb0ef41Sopenharmony_ci "textRaw": "`name` {string} Name of the export to set.", 7211cb0ef41Sopenharmony_ci "name": "name", 7221cb0ef41Sopenharmony_ci "type": "string", 7231cb0ef41Sopenharmony_ci "desc": "Name of the export to set." 7241cb0ef41Sopenharmony_ci }, 7251cb0ef41Sopenharmony_ci { 7261cb0ef41Sopenharmony_ci "textRaw": "`value` {any} The value to set the export to.", 7271cb0ef41Sopenharmony_ci "name": "value", 7281cb0ef41Sopenharmony_ci "type": "any", 7291cb0ef41Sopenharmony_ci "desc": "The value to set the export to." 7301cb0ef41Sopenharmony_ci } 7311cb0ef41Sopenharmony_ci ] 7321cb0ef41Sopenharmony_ci } 7331cb0ef41Sopenharmony_ci ], 7341cb0ef41Sopenharmony_ci "desc": "<p>This method is used after the module is linked to set the values of exports. If\nit is called before the module is linked, an <a href=\"errors.html#err_vm_module_status\"><code>ERR_VM_MODULE_STATUS</code></a> error\nwill be thrown.</p>\n<pre><code class=\"language-mjs\">import vm from 'node:vm';\n\nconst m = new vm.SyntheticModule(['x'], () => {\n m.setExport('x', 1);\n});\n\nawait m.link(() => {});\nawait m.evaluate();\n\nassert.strictEqual(m.namespace.x, 1);\n</code></pre>\n<pre><code class=\"language-cjs\">const vm = require('node:vm');\n(async () => {\n const m = new vm.SyntheticModule(['x'], () => {\n m.setExport('x', 1);\n });\n await m.link(() => {});\n await m.evaluate();\n assert.strictEqual(m.namespace.x, 1);\n})();\n</code></pre>" 7351cb0ef41Sopenharmony_ci } 7361cb0ef41Sopenharmony_ci ], 7371cb0ef41Sopenharmony_ci "signatures": [ 7381cb0ef41Sopenharmony_ci { 7391cb0ef41Sopenharmony_ci "params": [ 7401cb0ef41Sopenharmony_ci { 7411cb0ef41Sopenharmony_ci "textRaw": "`exportNames` {string\\[]} Array of names that will be exported from the module.", 7421cb0ef41Sopenharmony_ci "name": "exportNames", 7431cb0ef41Sopenharmony_ci "type": "string\\[]", 7441cb0ef41Sopenharmony_ci "desc": "Array of names that will be exported from the module." 7451cb0ef41Sopenharmony_ci }, 7461cb0ef41Sopenharmony_ci { 7471cb0ef41Sopenharmony_ci "textRaw": "`evaluateCallback` {Function} Called when the module is evaluated.", 7481cb0ef41Sopenharmony_ci "name": "evaluateCallback", 7491cb0ef41Sopenharmony_ci "type": "Function", 7501cb0ef41Sopenharmony_ci "desc": "Called when the module is evaluated." 7511cb0ef41Sopenharmony_ci }, 7521cb0ef41Sopenharmony_ci { 7531cb0ef41Sopenharmony_ci "textRaw": "`options`", 7541cb0ef41Sopenharmony_ci "name": "options", 7551cb0ef41Sopenharmony_ci "options": [ 7561cb0ef41Sopenharmony_ci { 7571cb0ef41Sopenharmony_ci "textRaw": "`identifier` {string} String used in stack traces. **Default:** `'vm:module(i)'` where `i` is a context-specific ascending index.", 7581cb0ef41Sopenharmony_ci "name": "identifier", 7591cb0ef41Sopenharmony_ci "type": "string", 7601cb0ef41Sopenharmony_ci "default": "`'vm:module(i)'` where `i` is a context-specific ascending index", 7611cb0ef41Sopenharmony_ci "desc": "String used in stack traces." 7621cb0ef41Sopenharmony_ci }, 7631cb0ef41Sopenharmony_ci { 7641cb0ef41Sopenharmony_ci "textRaw": "`context` {Object} The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in.", 7651cb0ef41Sopenharmony_ci "name": "context", 7661cb0ef41Sopenharmony_ci "type": "Object", 7671cb0ef41Sopenharmony_ci "desc": "The [contextified][] object as returned by the `vm.createContext()` method, to compile and evaluate this `Module` in." 7681cb0ef41Sopenharmony_ci } 7691cb0ef41Sopenharmony_ci ] 7701cb0ef41Sopenharmony_ci } 7711cb0ef41Sopenharmony_ci ], 7721cb0ef41Sopenharmony_ci "desc": "<p>Creates a new <code>SyntheticModule</code> instance.</p>\n<p>Objects assigned to the exports of this instance may allow importers of\nthe module to access information outside the specified <code>context</code>. Use\n<code>vm.runInContext()</code> to create objects in a specific context.</p>" 7731cb0ef41Sopenharmony_ci } 7741cb0ef41Sopenharmony_ci ] 7751cb0ef41Sopenharmony_ci } 7761cb0ef41Sopenharmony_ci ], 7771cb0ef41Sopenharmony_ci "methods": [ 7781cb0ef41Sopenharmony_ci { 7791cb0ef41Sopenharmony_ci "textRaw": "`vm.compileFunction(code[, params[, options]])`", 7801cb0ef41Sopenharmony_ci "type": "method", 7811cb0ef41Sopenharmony_ci "name": "compileFunction", 7821cb0ef41Sopenharmony_ci "meta": { 7831cb0ef41Sopenharmony_ci "added": [ 7841cb0ef41Sopenharmony_ci "v10.10.0" 7851cb0ef41Sopenharmony_ci ], 7861cb0ef41Sopenharmony_ci "changes": [ 7871cb0ef41Sopenharmony_ci { 7881cb0ef41Sopenharmony_ci "version": [ 7891cb0ef41Sopenharmony_ci "v18.15.0" 7901cb0ef41Sopenharmony_ci ], 7911cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/46320", 7921cb0ef41Sopenharmony_ci "description": "The return value now includes `cachedDataRejected` with the same semantics as the `vm.Script` version if the `cachedData` option was passed." 7931cb0ef41Sopenharmony_ci }, 7941cb0ef41Sopenharmony_ci { 7951cb0ef41Sopenharmony_ci "version": [ 7961cb0ef41Sopenharmony_ci "v17.0.0", 7971cb0ef41Sopenharmony_ci "v16.12.0" 7981cb0ef41Sopenharmony_ci ], 7991cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/40249", 8001cb0ef41Sopenharmony_ci "description": "Added support for import attributes to the `importModuleDynamically` parameter." 8011cb0ef41Sopenharmony_ci }, 8021cb0ef41Sopenharmony_ci { 8031cb0ef41Sopenharmony_ci "version": "v15.9.0", 8041cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/35431", 8051cb0ef41Sopenharmony_ci "description": "Added `importModuleDynamically` option again." 8061cb0ef41Sopenharmony_ci }, 8071cb0ef41Sopenharmony_ci { 8081cb0ef41Sopenharmony_ci "version": "v14.3.0", 8091cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/33364", 8101cb0ef41Sopenharmony_ci "description": "Removal of `importModuleDynamically` due to compatibility issues." 8111cb0ef41Sopenharmony_ci }, 8121cb0ef41Sopenharmony_ci { 8131cb0ef41Sopenharmony_ci "version": [ 8141cb0ef41Sopenharmony_ci "v14.1.0", 8151cb0ef41Sopenharmony_ci "v13.14.0" 8161cb0ef41Sopenharmony_ci ], 8171cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/32985", 8181cb0ef41Sopenharmony_ci "description": "The `importModuleDynamically` option is now supported." 8191cb0ef41Sopenharmony_ci } 8201cb0ef41Sopenharmony_ci ] 8211cb0ef41Sopenharmony_ci }, 8221cb0ef41Sopenharmony_ci "signatures": [ 8231cb0ef41Sopenharmony_ci { 8241cb0ef41Sopenharmony_ci "return": { 8251cb0ef41Sopenharmony_ci "textRaw": "Returns: {Function}", 8261cb0ef41Sopenharmony_ci "name": "return", 8271cb0ef41Sopenharmony_ci "type": "Function" 8281cb0ef41Sopenharmony_ci }, 8291cb0ef41Sopenharmony_ci "params": [ 8301cb0ef41Sopenharmony_ci { 8311cb0ef41Sopenharmony_ci "textRaw": "`code` {string} The body of the function to compile.", 8321cb0ef41Sopenharmony_ci "name": "code", 8331cb0ef41Sopenharmony_ci "type": "string", 8341cb0ef41Sopenharmony_ci "desc": "The body of the function to compile." 8351cb0ef41Sopenharmony_ci }, 8361cb0ef41Sopenharmony_ci { 8371cb0ef41Sopenharmony_ci "textRaw": "`params` {string\\[]} An array of strings containing all parameters for the function.", 8381cb0ef41Sopenharmony_ci "name": "params", 8391cb0ef41Sopenharmony_ci "type": "string\\[]", 8401cb0ef41Sopenharmony_ci "desc": "An array of strings containing all parameters for the function." 8411cb0ef41Sopenharmony_ci }, 8421cb0ef41Sopenharmony_ci { 8431cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 8441cb0ef41Sopenharmony_ci "name": "options", 8451cb0ef41Sopenharmony_ci "type": "Object", 8461cb0ef41Sopenharmony_ci "options": [ 8471cb0ef41Sopenharmony_ci { 8481cb0ef41Sopenharmony_ci "textRaw": "`filename` {string} Specifies the filename used in stack traces produced by this script. **Default:** `''`.", 8491cb0ef41Sopenharmony_ci "name": "filename", 8501cb0ef41Sopenharmony_ci "type": "string", 8511cb0ef41Sopenharmony_ci "default": "`''`", 8521cb0ef41Sopenharmony_ci "desc": "Specifies the filename used in stack traces produced by this script." 8531cb0ef41Sopenharmony_ci }, 8541cb0ef41Sopenharmony_ci { 8551cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 8561cb0ef41Sopenharmony_ci "name": "lineOffset", 8571cb0ef41Sopenharmony_ci "type": "number", 8581cb0ef41Sopenharmony_ci "default": "`0`", 8591cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this script." 8601cb0ef41Sopenharmony_ci }, 8611cb0ef41Sopenharmony_ci { 8621cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 8631cb0ef41Sopenharmony_ci "name": "columnOffset", 8641cb0ef41Sopenharmony_ci "type": "number", 8651cb0ef41Sopenharmony_ci "default": "`0`", 8661cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this script." 8671cb0ef41Sopenharmony_ci }, 8681cb0ef41Sopenharmony_ci { 8691cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. This must be produced by a prior call to [`vm.compileFunction()`][] with the same `code` and `params`.", 8701cb0ef41Sopenharmony_ci "name": "cachedData", 8711cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 8721cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source. This must be produced by a prior call to [`vm.compileFunction()`][] with the same `code` and `params`." 8731cb0ef41Sopenharmony_ci }, 8741cb0ef41Sopenharmony_ci { 8751cb0ef41Sopenharmony_ci "textRaw": "`produceCachedData` {boolean} Specifies whether to produce new cache data. **Default:** `false`.", 8761cb0ef41Sopenharmony_ci "name": "produceCachedData", 8771cb0ef41Sopenharmony_ci "type": "boolean", 8781cb0ef41Sopenharmony_ci "default": "`false`", 8791cb0ef41Sopenharmony_ci "desc": "Specifies whether to produce new cache data." 8801cb0ef41Sopenharmony_ci }, 8811cb0ef41Sopenharmony_ci { 8821cb0ef41Sopenharmony_ci "textRaw": "`parsingContext` {Object} The [contextified][] object in which the said function should be compiled in.", 8831cb0ef41Sopenharmony_ci "name": "parsingContext", 8841cb0ef41Sopenharmony_ci "type": "Object", 8851cb0ef41Sopenharmony_ci "desc": "The [contextified][] object in which the said function should be compiled in." 8861cb0ef41Sopenharmony_ci }, 8871cb0ef41Sopenharmony_ci { 8881cb0ef41Sopenharmony_ci "textRaw": "`contextExtensions` {Object\\[]} An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling. **Default:** `[]`.", 8891cb0ef41Sopenharmony_ci "name": "contextExtensions", 8901cb0ef41Sopenharmony_ci "type": "Object\\[]", 8911cb0ef41Sopenharmony_ci "default": "`[]`", 8921cb0ef41Sopenharmony_ci "desc": "An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling." 8931cb0ef41Sopenharmony_ci }, 8941cb0ef41Sopenharmony_ci { 8951cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API, and should not be considered stable. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 8961cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 8971cb0ef41Sopenharmony_ci "type": "Function", 8981cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API, and should not be considered stable. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 8991cb0ef41Sopenharmony_ci "options": [ 9001cb0ef41Sopenharmony_ci { 9011cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 9021cb0ef41Sopenharmony_ci "name": "specifier", 9031cb0ef41Sopenharmony_ci "type": "string", 9041cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 9051cb0ef41Sopenharmony_ci }, 9061cb0ef41Sopenharmony_ci { 9071cb0ef41Sopenharmony_ci "textRaw": "`function` {Function}", 9081cb0ef41Sopenharmony_ci "name": "function", 9091cb0ef41Sopenharmony_ci "type": "Function" 9101cb0ef41Sopenharmony_ci }, 9111cb0ef41Sopenharmony_ci { 9121cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 9131cb0ef41Sopenharmony_ci "name": "importAttributes", 9141cb0ef41Sopenharmony_ci "type": "Object", 9151cb0ef41Sopenharmony_ci "desc": "The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 9161cb0ef41Sopenharmony_ci }, 9171cb0ef41Sopenharmony_ci { 9181cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 9191cb0ef41Sopenharmony_ci "name": "return", 9201cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 9211cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 9221cb0ef41Sopenharmony_ci } 9231cb0ef41Sopenharmony_ci ] 9241cb0ef41Sopenharmony_ci } 9251cb0ef41Sopenharmony_ci ] 9261cb0ef41Sopenharmony_ci } 9271cb0ef41Sopenharmony_ci ] 9281cb0ef41Sopenharmony_ci } 9291cb0ef41Sopenharmony_ci ], 9301cb0ef41Sopenharmony_ci "desc": "<p>Compiles the given code into the provided context (if no context is\nsupplied, the current context is used), and returns it wrapped inside a\nfunction with the given <code>params</code>.</p>" 9311cb0ef41Sopenharmony_ci }, 9321cb0ef41Sopenharmony_ci { 9331cb0ef41Sopenharmony_ci "textRaw": "`vm.createContext([contextObject[, options]])`", 9341cb0ef41Sopenharmony_ci "type": "method", 9351cb0ef41Sopenharmony_ci "name": "createContext", 9361cb0ef41Sopenharmony_ci "meta": { 9371cb0ef41Sopenharmony_ci "added": [ 9381cb0ef41Sopenharmony_ci "v0.3.1" 9391cb0ef41Sopenharmony_ci ], 9401cb0ef41Sopenharmony_ci "changes": [ 9411cb0ef41Sopenharmony_ci { 9421cb0ef41Sopenharmony_ci "version": "v14.6.0", 9431cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/34023", 9441cb0ef41Sopenharmony_ci "description": "The `microtaskMode` option is supported now." 9451cb0ef41Sopenharmony_ci }, 9461cb0ef41Sopenharmony_ci { 9471cb0ef41Sopenharmony_ci "version": "v10.0.0", 9481cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/19398", 9491cb0ef41Sopenharmony_ci "description": "The first argument can no longer be a function." 9501cb0ef41Sopenharmony_ci }, 9511cb0ef41Sopenharmony_ci { 9521cb0ef41Sopenharmony_ci "version": "v10.0.0", 9531cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/19016", 9541cb0ef41Sopenharmony_ci "description": "The `codeGeneration` option is supported now." 9551cb0ef41Sopenharmony_ci } 9561cb0ef41Sopenharmony_ci ] 9571cb0ef41Sopenharmony_ci }, 9581cb0ef41Sopenharmony_ci "signatures": [ 9591cb0ef41Sopenharmony_ci { 9601cb0ef41Sopenharmony_ci "return": { 9611cb0ef41Sopenharmony_ci "textRaw": "Returns: {Object} contextified object.", 9621cb0ef41Sopenharmony_ci "name": "return", 9631cb0ef41Sopenharmony_ci "type": "Object", 9641cb0ef41Sopenharmony_ci "desc": "contextified object." 9651cb0ef41Sopenharmony_ci }, 9661cb0ef41Sopenharmony_ci "params": [ 9671cb0ef41Sopenharmony_ci { 9681cb0ef41Sopenharmony_ci "textRaw": "`contextObject` {Object}", 9691cb0ef41Sopenharmony_ci "name": "contextObject", 9701cb0ef41Sopenharmony_ci "type": "Object" 9711cb0ef41Sopenharmony_ci }, 9721cb0ef41Sopenharmony_ci { 9731cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 9741cb0ef41Sopenharmony_ci "name": "options", 9751cb0ef41Sopenharmony_ci "type": "Object", 9761cb0ef41Sopenharmony_ci "options": [ 9771cb0ef41Sopenharmony_ci { 9781cb0ef41Sopenharmony_ci "textRaw": "`name` {string} Human-readable name of the newly created context. **Default:** `'VM Context i'`, where `i` is an ascending numerical index of the created context.", 9791cb0ef41Sopenharmony_ci "name": "name", 9801cb0ef41Sopenharmony_ci "type": "string", 9811cb0ef41Sopenharmony_ci "default": "`'VM Context i'`, where `i` is an ascending numerical index of the created context", 9821cb0ef41Sopenharmony_ci "desc": "Human-readable name of the newly created context." 9831cb0ef41Sopenharmony_ci }, 9841cb0ef41Sopenharmony_ci { 9851cb0ef41Sopenharmony_ci "textRaw": "`origin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. **Default:** `''`.", 9861cb0ef41Sopenharmony_ci "name": "origin", 9871cb0ef41Sopenharmony_ci "type": "string", 9881cb0ef41Sopenharmony_ci "default": "`''`", 9891cb0ef41Sopenharmony_ci "desc": "[Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path." 9901cb0ef41Sopenharmony_ci }, 9911cb0ef41Sopenharmony_ci { 9921cb0ef41Sopenharmony_ci "textRaw": "`codeGeneration` {Object}", 9931cb0ef41Sopenharmony_ci "name": "codeGeneration", 9941cb0ef41Sopenharmony_ci "type": "Object", 9951cb0ef41Sopenharmony_ci "options": [ 9961cb0ef41Sopenharmony_ci { 9971cb0ef41Sopenharmony_ci "textRaw": "`strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. **Default:** `true`.", 9981cb0ef41Sopenharmony_ci "name": "strings", 9991cb0ef41Sopenharmony_ci "type": "boolean", 10001cb0ef41Sopenharmony_ci "default": "`true`", 10011cb0ef41Sopenharmony_ci "desc": "If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`." 10021cb0ef41Sopenharmony_ci }, 10031cb0ef41Sopenharmony_ci { 10041cb0ef41Sopenharmony_ci "textRaw": "`wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. **Default:** `true`.", 10051cb0ef41Sopenharmony_ci "name": "wasm", 10061cb0ef41Sopenharmony_ci "type": "boolean", 10071cb0ef41Sopenharmony_ci "default": "`true`", 10081cb0ef41Sopenharmony_ci "desc": "If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`." 10091cb0ef41Sopenharmony_ci } 10101cb0ef41Sopenharmony_ci ] 10111cb0ef41Sopenharmony_ci }, 10121cb0ef41Sopenharmony_ci { 10131cb0ef41Sopenharmony_ci "textRaw": "`microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after a script has run through [`script.runInContext()`][]. They are included in the `timeout` and `breakOnSigint` scopes in that case.", 10141cb0ef41Sopenharmony_ci "name": "microtaskMode", 10151cb0ef41Sopenharmony_ci "type": "string", 10161cb0ef41Sopenharmony_ci "desc": "If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after a script has run through [`script.runInContext()`][]. They are included in the `timeout` and `breakOnSigint` scopes in that case." 10171cb0ef41Sopenharmony_ci } 10181cb0ef41Sopenharmony_ci ] 10191cb0ef41Sopenharmony_ci } 10201cb0ef41Sopenharmony_ci ] 10211cb0ef41Sopenharmony_ci } 10221cb0ef41Sopenharmony_ci ], 10231cb0ef41Sopenharmony_ci "desc": "<p>If given a <code>contextObject</code>, the <code>vm.createContext()</code> method will <a href=\"#what-does-it-mean-to-contextify-an-object\">prepare\nthat object</a> so that it can be used in calls to\n<a href=\"#vmrunincontextcode-contextifiedobject-options\"><code>vm.runInContext()</code></a> or <a href=\"#scriptrunincontextcontextifiedobject-options\"><code>script.runInContext()</code></a>. Inside such scripts,\nthe <code>contextObject</code> will be the global object, retaining all of its existing\nproperties but also having the built-in objects and functions any standard\n<a href=\"https://es5.github.io/#x15.1\">global object</a> has. Outside of scripts run by the vm module, global variables\nwill remain unchanged.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nglobal.globalVar = 3;\n\nconst context = { globalVar: 1 };\nvm.createContext(context);\n\nvm.runInContext('globalVar *= 2;', context);\n\nconsole.log(context);\n// Prints: { globalVar: 2 }\n\nconsole.log(global.globalVar);\n// Prints: 3\n</code></pre>\n<p>If <code>contextObject</code> is omitted (or passed explicitly as <code>undefined</code>), a new,\nempty <a href=\"#what-does-it-mean-to-contextify-an-object\">contextified</a> object will be returned.</p>\n<p>The <code>vm.createContext()</code> method is primarily useful for creating a single\ncontext that can be used to run multiple scripts. For instance, if emulating a\nweb browser, the method can be used to create a single context representing a\nwindow's global object, then run all <code><script></code> tags together within that\ncontext.</p>\n<p>The provided <code>name</code> and <code>origin</code> of the context are made visible through the\nInspector API.</p>" 10241cb0ef41Sopenharmony_ci }, 10251cb0ef41Sopenharmony_ci { 10261cb0ef41Sopenharmony_ci "textRaw": "`vm.isContext(object)`", 10271cb0ef41Sopenharmony_ci "type": "method", 10281cb0ef41Sopenharmony_ci "name": "isContext", 10291cb0ef41Sopenharmony_ci "meta": { 10301cb0ef41Sopenharmony_ci "added": [ 10311cb0ef41Sopenharmony_ci "v0.11.7" 10321cb0ef41Sopenharmony_ci ], 10331cb0ef41Sopenharmony_ci "changes": [] 10341cb0ef41Sopenharmony_ci }, 10351cb0ef41Sopenharmony_ci "signatures": [ 10361cb0ef41Sopenharmony_ci { 10371cb0ef41Sopenharmony_ci "return": { 10381cb0ef41Sopenharmony_ci "textRaw": "Returns: {boolean}", 10391cb0ef41Sopenharmony_ci "name": "return", 10401cb0ef41Sopenharmony_ci "type": "boolean" 10411cb0ef41Sopenharmony_ci }, 10421cb0ef41Sopenharmony_ci "params": [ 10431cb0ef41Sopenharmony_ci { 10441cb0ef41Sopenharmony_ci "textRaw": "`object` {Object}", 10451cb0ef41Sopenharmony_ci "name": "object", 10461cb0ef41Sopenharmony_ci "type": "Object" 10471cb0ef41Sopenharmony_ci } 10481cb0ef41Sopenharmony_ci ] 10491cb0ef41Sopenharmony_ci } 10501cb0ef41Sopenharmony_ci ], 10511cb0ef41Sopenharmony_ci "desc": "<p>Returns <code>true</code> if the given <code>object</code> object has been <a href=\"#what-does-it-mean-to-contextify-an-object\">contextified</a> using\n<a href=\"#vmcreatecontextcontextobject-options\"><code>vm.createContext()</code></a>.</p>" 10521cb0ef41Sopenharmony_ci }, 10531cb0ef41Sopenharmony_ci { 10541cb0ef41Sopenharmony_ci "textRaw": "`vm.measureMemory([options])`", 10551cb0ef41Sopenharmony_ci "type": "method", 10561cb0ef41Sopenharmony_ci "name": "measureMemory", 10571cb0ef41Sopenharmony_ci "meta": { 10581cb0ef41Sopenharmony_ci "added": [ 10591cb0ef41Sopenharmony_ci "v13.10.0" 10601cb0ef41Sopenharmony_ci ], 10611cb0ef41Sopenharmony_ci "changes": [] 10621cb0ef41Sopenharmony_ci }, 10631cb0ef41Sopenharmony_ci "stability": 1, 10641cb0ef41Sopenharmony_ci "stabilityText": "Experimental", 10651cb0ef41Sopenharmony_ci "signatures": [ 10661cb0ef41Sopenharmony_ci { 10671cb0ef41Sopenharmony_ci "params": [] 10681cb0ef41Sopenharmony_ci } 10691cb0ef41Sopenharmony_ci ], 10701cb0ef41Sopenharmony_ci "desc": "<p>Measure the memory known to V8 and used by all contexts known to the\ncurrent V8 isolate, or the main context.</p>\n<ul>\n<li><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\"><Object></a> Optional.\n<ul>\n<li><code>mode</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> Either <code>'summary'</code> or <code>'detailed'</code>. In summary mode,\nonly the memory measured for the main context will be returned. In\ndetailed mode, the memory measured for all contexts known to the\ncurrent V8 isolate will be returned.\n<strong>Default:</strong> <code>'summary'</code></li>\n<li><code>execution</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> Either <code>'default'</code> or <code>'eager'</code>. With default\nexecution, the promise will not resolve until after the next scheduled\ngarbage collection starts, which may take a while (or never if the program\nexits before the next GC). With eager execution, the GC will be started\nright away to measure the memory.\n<strong>Default:</strong> <code>'default'</code></li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\" class=\"type\"><Promise></a> If the memory is successfully measured, the promise will\nresolve with an object containing information about the memory usage.\nOtherwise it will be rejected with an <code>ERR_CONTEXT_NOT_INITIALIZED</code> error.</li>\n</ul>\n<p>The format of the object that the returned Promise may resolve with is\nspecific to the V8 engine and may change from one version of V8 to the next.</p>\n<p>The returned result is different from the statistics returned by\n<code>v8.getHeapSpaceStatistics()</code> in that <code>vm.measureMemory()</code> measure the\nmemory reachable by each V8 specific contexts in the current instance of\nthe V8 engine, while the result of <code>v8.getHeapSpaceStatistics()</code> measure\nthe memory occupied by each heap space in the current V8 instance.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n// Measure the memory used by the main context.\nvm.measureMemory({ mode: 'summary' })\n // This is the same as vm.measureMemory()\n .then((result) => {\n // The current format is:\n // {\n // total: {\n // jsMemoryEstimate: 2418479, jsMemoryRange: [ 2418479, 2745799 ]\n // }\n // }\n console.log(result);\n });\n\nconst context = vm.createContext({ a: 1 });\nvm.measureMemory({ mode: 'detailed', execution: 'eager' })\n .then((result) => {\n // Reference the context here so that it won't be GC'ed\n // until the measurement is complete.\n console.log(context.a);\n // {\n // total: {\n // jsMemoryEstimate: 2574732,\n // jsMemoryRange: [ 2574732, 2904372 ]\n // },\n // current: {\n // jsMemoryEstimate: 2438996,\n // jsMemoryRange: [ 2438996, 2768636 ]\n // },\n // other: [\n // {\n // jsMemoryEstimate: 135736,\n // jsMemoryRange: [ 135736, 465376 ]\n // }\n // ]\n // }\n console.log(result);\n });\n</code></pre>" 10711cb0ef41Sopenharmony_ci }, 10721cb0ef41Sopenharmony_ci { 10731cb0ef41Sopenharmony_ci "textRaw": "`vm.runInContext(code, contextifiedObject[, options])`", 10741cb0ef41Sopenharmony_ci "type": "method", 10751cb0ef41Sopenharmony_ci "name": "runInContext", 10761cb0ef41Sopenharmony_ci "meta": { 10771cb0ef41Sopenharmony_ci "added": [ 10781cb0ef41Sopenharmony_ci "v0.3.1" 10791cb0ef41Sopenharmony_ci ], 10801cb0ef41Sopenharmony_ci "changes": [ 10811cb0ef41Sopenharmony_ci { 10821cb0ef41Sopenharmony_ci "version": [ 10831cb0ef41Sopenharmony_ci "v17.0.0", 10841cb0ef41Sopenharmony_ci "v16.12.0" 10851cb0ef41Sopenharmony_ci ], 10861cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/40249", 10871cb0ef41Sopenharmony_ci "description": "Added support for import attributes to the `importModuleDynamically` parameter." 10881cb0ef41Sopenharmony_ci }, 10891cb0ef41Sopenharmony_ci { 10901cb0ef41Sopenharmony_ci "version": "v6.3.0", 10911cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 10921cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 10931cb0ef41Sopenharmony_ci } 10941cb0ef41Sopenharmony_ci ] 10951cb0ef41Sopenharmony_ci }, 10961cb0ef41Sopenharmony_ci "signatures": [ 10971cb0ef41Sopenharmony_ci { 10981cb0ef41Sopenharmony_ci "return": { 10991cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 11001cb0ef41Sopenharmony_ci "name": "return", 11011cb0ef41Sopenharmony_ci "type": "any", 11021cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 11031cb0ef41Sopenharmony_ci }, 11041cb0ef41Sopenharmony_ci "params": [ 11051cb0ef41Sopenharmony_ci { 11061cb0ef41Sopenharmony_ci "textRaw": "`code` {string} The JavaScript code to compile and run.", 11071cb0ef41Sopenharmony_ci "name": "code", 11081cb0ef41Sopenharmony_ci "type": "string", 11091cb0ef41Sopenharmony_ci "desc": "The JavaScript code to compile and run." 11101cb0ef41Sopenharmony_ci }, 11111cb0ef41Sopenharmony_ci { 11121cb0ef41Sopenharmony_ci "textRaw": "`contextifiedObject` {Object} The [contextified][] object that will be used as the `global` when the `code` is compiled and run.", 11131cb0ef41Sopenharmony_ci "name": "contextifiedObject", 11141cb0ef41Sopenharmony_ci "type": "Object", 11151cb0ef41Sopenharmony_ci "desc": "The [contextified][] object that will be used as the `global` when the `code` is compiled and run." 11161cb0ef41Sopenharmony_ci }, 11171cb0ef41Sopenharmony_ci { 11181cb0ef41Sopenharmony_ci "textRaw": "`options` {Object|string}", 11191cb0ef41Sopenharmony_ci "name": "options", 11201cb0ef41Sopenharmony_ci "type": "Object|string", 11211cb0ef41Sopenharmony_ci "options": [ 11221cb0ef41Sopenharmony_ci { 11231cb0ef41Sopenharmony_ci "textRaw": "`filename` {string} Specifies the filename used in stack traces produced by this script. **Default:** `'evalmachine.<anonymous>'`.", 11241cb0ef41Sopenharmony_ci "name": "filename", 11251cb0ef41Sopenharmony_ci "type": "string", 11261cb0ef41Sopenharmony_ci "default": "`'evalmachine.<anonymous>'`", 11271cb0ef41Sopenharmony_ci "desc": "Specifies the filename used in stack traces produced by this script." 11281cb0ef41Sopenharmony_ci }, 11291cb0ef41Sopenharmony_ci { 11301cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 11311cb0ef41Sopenharmony_ci "name": "lineOffset", 11321cb0ef41Sopenharmony_ci "type": "number", 11331cb0ef41Sopenharmony_ci "default": "`0`", 11341cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this script." 11351cb0ef41Sopenharmony_ci }, 11361cb0ef41Sopenharmony_ci { 11371cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 11381cb0ef41Sopenharmony_ci "name": "columnOffset", 11391cb0ef41Sopenharmony_ci "type": "number", 11401cb0ef41Sopenharmony_ci "default": "`0`", 11411cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this script." 11421cb0ef41Sopenharmony_ci }, 11431cb0ef41Sopenharmony_ci { 11441cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 11451cb0ef41Sopenharmony_ci "name": "displayErrors", 11461cb0ef41Sopenharmony_ci "type": "boolean", 11471cb0ef41Sopenharmony_ci "default": "`true`", 11481cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 11491cb0ef41Sopenharmony_ci }, 11501cb0ef41Sopenharmony_ci { 11511cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 11521cb0ef41Sopenharmony_ci "name": "timeout", 11531cb0ef41Sopenharmony_ci "type": "integer", 11541cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 11551cb0ef41Sopenharmony_ci }, 11561cb0ef41Sopenharmony_ci { 11571cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 11581cb0ef41Sopenharmony_ci "name": "breakOnSigint", 11591cb0ef41Sopenharmony_ci "type": "boolean", 11601cb0ef41Sopenharmony_ci "default": "`false`", 11611cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 11621cb0ef41Sopenharmony_ci }, 11631cb0ef41Sopenharmony_ci { 11641cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source.", 11651cb0ef41Sopenharmony_ci "name": "cachedData", 11661cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 11671cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source." 11681cb0ef41Sopenharmony_ci }, 11691cb0ef41Sopenharmony_ci { 11701cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 11711cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 11721cb0ef41Sopenharmony_ci "type": "Function", 11731cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 11741cb0ef41Sopenharmony_ci "options": [ 11751cb0ef41Sopenharmony_ci { 11761cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 11771cb0ef41Sopenharmony_ci "name": "specifier", 11781cb0ef41Sopenharmony_ci "type": "string", 11791cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 11801cb0ef41Sopenharmony_ci }, 11811cb0ef41Sopenharmony_ci { 11821cb0ef41Sopenharmony_ci "textRaw": "`script` {vm.Script}", 11831cb0ef41Sopenharmony_ci "name": "script", 11841cb0ef41Sopenharmony_ci "type": "vm.Script" 11851cb0ef41Sopenharmony_ci }, 11861cb0ef41Sopenharmony_ci { 11871cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 11881cb0ef41Sopenharmony_ci "name": "importAttributes", 11891cb0ef41Sopenharmony_ci "type": "Object", 11901cb0ef41Sopenharmony_ci "desc": "The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 11911cb0ef41Sopenharmony_ci }, 11921cb0ef41Sopenharmony_ci { 11931cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 11941cb0ef41Sopenharmony_ci "name": "return", 11951cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 11961cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 11971cb0ef41Sopenharmony_ci } 11981cb0ef41Sopenharmony_ci ] 11991cb0ef41Sopenharmony_ci } 12001cb0ef41Sopenharmony_ci ] 12011cb0ef41Sopenharmony_ci } 12021cb0ef41Sopenharmony_ci ] 12031cb0ef41Sopenharmony_ci } 12041cb0ef41Sopenharmony_ci ], 12051cb0ef41Sopenharmony_ci "desc": "<p>The <code>vm.runInContext()</code> method compiles <code>code</code>, runs it within the context of\nthe <code>contextifiedObject</code>, then returns the result. Running code does not have\naccess to the local scope. The <code>contextifiedObject</code> object <em>must</em> have been\npreviously <a href=\"#what-does-it-mean-to-contextify-an-object\">contextified</a> using the <a href=\"#vmcreatecontextcontextobject-options\"><code>vm.createContext()</code></a> method.</p>\n<p>If <code>options</code> is a string, then it specifies the filename.</p>\n<p>The following example compiles and executes different scripts using a single\n<a href=\"#what-does-it-mean-to-contextify-an-object\">contextified</a> object:</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst contextObject = { globalVar: 1 };\nvm.createContext(contextObject);\n\nfor (let i = 0; i < 10; ++i) {\n vm.runInContext('globalVar *= 2;', contextObject);\n}\nconsole.log(contextObject);\n// Prints: { globalVar: 1024 }\n</code></pre>" 12061cb0ef41Sopenharmony_ci }, 12071cb0ef41Sopenharmony_ci { 12081cb0ef41Sopenharmony_ci "textRaw": "`vm.runInNewContext(code[, contextObject[, options]])`", 12091cb0ef41Sopenharmony_ci "type": "method", 12101cb0ef41Sopenharmony_ci "name": "runInNewContext", 12111cb0ef41Sopenharmony_ci "meta": { 12121cb0ef41Sopenharmony_ci "added": [ 12131cb0ef41Sopenharmony_ci "v0.3.1" 12141cb0ef41Sopenharmony_ci ], 12151cb0ef41Sopenharmony_ci "changes": [ 12161cb0ef41Sopenharmony_ci { 12171cb0ef41Sopenharmony_ci "version": [ 12181cb0ef41Sopenharmony_ci "v17.0.0", 12191cb0ef41Sopenharmony_ci "v16.12.0" 12201cb0ef41Sopenharmony_ci ], 12211cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/40249", 12221cb0ef41Sopenharmony_ci "description": "Added support for import attributes to the `importModuleDynamically` parameter." 12231cb0ef41Sopenharmony_ci }, 12241cb0ef41Sopenharmony_ci { 12251cb0ef41Sopenharmony_ci "version": "v14.6.0", 12261cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/34023", 12271cb0ef41Sopenharmony_ci "description": "The `microtaskMode` option is supported now." 12281cb0ef41Sopenharmony_ci }, 12291cb0ef41Sopenharmony_ci { 12301cb0ef41Sopenharmony_ci "version": "v10.0.0", 12311cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/19016", 12321cb0ef41Sopenharmony_ci "description": "The `contextCodeGeneration` option is supported now." 12331cb0ef41Sopenharmony_ci }, 12341cb0ef41Sopenharmony_ci { 12351cb0ef41Sopenharmony_ci "version": "v6.3.0", 12361cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 12371cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 12381cb0ef41Sopenharmony_ci } 12391cb0ef41Sopenharmony_ci ] 12401cb0ef41Sopenharmony_ci }, 12411cb0ef41Sopenharmony_ci "signatures": [ 12421cb0ef41Sopenharmony_ci { 12431cb0ef41Sopenharmony_ci "return": { 12441cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 12451cb0ef41Sopenharmony_ci "name": "return", 12461cb0ef41Sopenharmony_ci "type": "any", 12471cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 12481cb0ef41Sopenharmony_ci }, 12491cb0ef41Sopenharmony_ci "params": [ 12501cb0ef41Sopenharmony_ci { 12511cb0ef41Sopenharmony_ci "textRaw": "`code` {string} The JavaScript code to compile and run.", 12521cb0ef41Sopenharmony_ci "name": "code", 12531cb0ef41Sopenharmony_ci "type": "string", 12541cb0ef41Sopenharmony_ci "desc": "The JavaScript code to compile and run." 12551cb0ef41Sopenharmony_ci }, 12561cb0ef41Sopenharmony_ci { 12571cb0ef41Sopenharmony_ci "textRaw": "`contextObject` {Object} An object that will be [contextified][]. If `undefined`, a new object will be created.", 12581cb0ef41Sopenharmony_ci "name": "contextObject", 12591cb0ef41Sopenharmony_ci "type": "Object", 12601cb0ef41Sopenharmony_ci "desc": "An object that will be [contextified][]. If `undefined`, a new object will be created." 12611cb0ef41Sopenharmony_ci }, 12621cb0ef41Sopenharmony_ci { 12631cb0ef41Sopenharmony_ci "textRaw": "`options` {Object|string}", 12641cb0ef41Sopenharmony_ci "name": "options", 12651cb0ef41Sopenharmony_ci "type": "Object|string", 12661cb0ef41Sopenharmony_ci "options": [ 12671cb0ef41Sopenharmony_ci { 12681cb0ef41Sopenharmony_ci "textRaw": "`filename` {string} Specifies the filename used in stack traces produced by this script. **Default:** `'evalmachine.<anonymous>'`.", 12691cb0ef41Sopenharmony_ci "name": "filename", 12701cb0ef41Sopenharmony_ci "type": "string", 12711cb0ef41Sopenharmony_ci "default": "`'evalmachine.<anonymous>'`", 12721cb0ef41Sopenharmony_ci "desc": "Specifies the filename used in stack traces produced by this script." 12731cb0ef41Sopenharmony_ci }, 12741cb0ef41Sopenharmony_ci { 12751cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 12761cb0ef41Sopenharmony_ci "name": "lineOffset", 12771cb0ef41Sopenharmony_ci "type": "number", 12781cb0ef41Sopenharmony_ci "default": "`0`", 12791cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this script." 12801cb0ef41Sopenharmony_ci }, 12811cb0ef41Sopenharmony_ci { 12821cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 12831cb0ef41Sopenharmony_ci "name": "columnOffset", 12841cb0ef41Sopenharmony_ci "type": "number", 12851cb0ef41Sopenharmony_ci "default": "`0`", 12861cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this script." 12871cb0ef41Sopenharmony_ci }, 12881cb0ef41Sopenharmony_ci { 12891cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 12901cb0ef41Sopenharmony_ci "name": "displayErrors", 12911cb0ef41Sopenharmony_ci "type": "boolean", 12921cb0ef41Sopenharmony_ci "default": "`true`", 12931cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 12941cb0ef41Sopenharmony_ci }, 12951cb0ef41Sopenharmony_ci { 12961cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 12971cb0ef41Sopenharmony_ci "name": "timeout", 12981cb0ef41Sopenharmony_ci "type": "integer", 12991cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 13001cb0ef41Sopenharmony_ci }, 13011cb0ef41Sopenharmony_ci { 13021cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 13031cb0ef41Sopenharmony_ci "name": "breakOnSigint", 13041cb0ef41Sopenharmony_ci "type": "boolean", 13051cb0ef41Sopenharmony_ci "default": "`false`", 13061cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 13071cb0ef41Sopenharmony_ci }, 13081cb0ef41Sopenharmony_ci { 13091cb0ef41Sopenharmony_ci "textRaw": "`contextName` {string} Human-readable name of the newly created context. **Default:** `'VM Context i'`, where `i` is an ascending numerical index of the created context.", 13101cb0ef41Sopenharmony_ci "name": "contextName", 13111cb0ef41Sopenharmony_ci "type": "string", 13121cb0ef41Sopenharmony_ci "default": "`'VM Context i'`, where `i` is an ascending numerical index of the created context", 13131cb0ef41Sopenharmony_ci "desc": "Human-readable name of the newly created context." 13141cb0ef41Sopenharmony_ci }, 13151cb0ef41Sopenharmony_ci { 13161cb0ef41Sopenharmony_ci "textRaw": "`contextOrigin` {string} [Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path. **Default:** `''`.", 13171cb0ef41Sopenharmony_ci "name": "contextOrigin", 13181cb0ef41Sopenharmony_ci "type": "string", 13191cb0ef41Sopenharmony_ci "default": "`''`", 13201cb0ef41Sopenharmony_ci "desc": "[Origin][origin] corresponding to the newly created context for display purposes. The origin should be formatted like a URL, but with only the scheme, host, and port (if necessary), like the value of the [`url.origin`][] property of a [`URL`][] object. Most notably, this string should omit the trailing slash, as that denotes a path." 13211cb0ef41Sopenharmony_ci }, 13221cb0ef41Sopenharmony_ci { 13231cb0ef41Sopenharmony_ci "textRaw": "`contextCodeGeneration` {Object}", 13241cb0ef41Sopenharmony_ci "name": "contextCodeGeneration", 13251cb0ef41Sopenharmony_ci "type": "Object", 13261cb0ef41Sopenharmony_ci "options": [ 13271cb0ef41Sopenharmony_ci { 13281cb0ef41Sopenharmony_ci "textRaw": "`strings` {boolean} If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`. **Default:** `true`.", 13291cb0ef41Sopenharmony_ci "name": "strings", 13301cb0ef41Sopenharmony_ci "type": "boolean", 13311cb0ef41Sopenharmony_ci "default": "`true`", 13321cb0ef41Sopenharmony_ci "desc": "If set to false any calls to `eval` or function constructors (`Function`, `GeneratorFunction`, etc) will throw an `EvalError`." 13331cb0ef41Sopenharmony_ci }, 13341cb0ef41Sopenharmony_ci { 13351cb0ef41Sopenharmony_ci "textRaw": "`wasm` {boolean} If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`. **Default:** `true`.", 13361cb0ef41Sopenharmony_ci "name": "wasm", 13371cb0ef41Sopenharmony_ci "type": "boolean", 13381cb0ef41Sopenharmony_ci "default": "`true`", 13391cb0ef41Sopenharmony_ci "desc": "If set to false any attempt to compile a WebAssembly module will throw a `WebAssembly.CompileError`." 13401cb0ef41Sopenharmony_ci } 13411cb0ef41Sopenharmony_ci ] 13421cb0ef41Sopenharmony_ci }, 13431cb0ef41Sopenharmony_ci { 13441cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source.", 13451cb0ef41Sopenharmony_ci "name": "cachedData", 13461cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 13471cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source." 13481cb0ef41Sopenharmony_ci }, 13491cb0ef41Sopenharmony_ci { 13501cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 13511cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 13521cb0ef41Sopenharmony_ci "type": "Function", 13531cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 13541cb0ef41Sopenharmony_ci "options": [ 13551cb0ef41Sopenharmony_ci { 13561cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 13571cb0ef41Sopenharmony_ci "name": "specifier", 13581cb0ef41Sopenharmony_ci "type": "string", 13591cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 13601cb0ef41Sopenharmony_ci }, 13611cb0ef41Sopenharmony_ci { 13621cb0ef41Sopenharmony_ci "textRaw": "`script` {vm.Script}", 13631cb0ef41Sopenharmony_ci "name": "script", 13641cb0ef41Sopenharmony_ci "type": "vm.Script" 13651cb0ef41Sopenharmony_ci }, 13661cb0ef41Sopenharmony_ci { 13671cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 13681cb0ef41Sopenharmony_ci "name": "importAttributes", 13691cb0ef41Sopenharmony_ci "type": "Object", 13701cb0ef41Sopenharmony_ci "desc": "The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 13711cb0ef41Sopenharmony_ci }, 13721cb0ef41Sopenharmony_ci { 13731cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 13741cb0ef41Sopenharmony_ci "name": "return", 13751cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 13761cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 13771cb0ef41Sopenharmony_ci } 13781cb0ef41Sopenharmony_ci ] 13791cb0ef41Sopenharmony_ci }, 13801cb0ef41Sopenharmony_ci { 13811cb0ef41Sopenharmony_ci "textRaw": "`microtaskMode` {string} If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case.", 13821cb0ef41Sopenharmony_ci "name": "microtaskMode", 13831cb0ef41Sopenharmony_ci "type": "string", 13841cb0ef41Sopenharmony_ci "desc": "If set to `afterEvaluate`, microtasks (tasks scheduled through `Promise`s and `async function`s) will be run immediately after the script has run. They are included in the `timeout` and `breakOnSigint` scopes in that case." 13851cb0ef41Sopenharmony_ci } 13861cb0ef41Sopenharmony_ci ] 13871cb0ef41Sopenharmony_ci } 13881cb0ef41Sopenharmony_ci ] 13891cb0ef41Sopenharmony_ci } 13901cb0ef41Sopenharmony_ci ], 13911cb0ef41Sopenharmony_ci "desc": "<p>The <code>vm.runInNewContext()</code> first contextifies the given <code>contextObject</code> (or\ncreates a new <code>contextObject</code> if passed as <code>undefined</code>), compiles the <code>code</code>,\nruns it within the created context, then returns the result. Running code\ndoes not have access to the local scope.</p>\n<p>If <code>options</code> is a string, then it specifies the filename.</p>\n<p>The following example compiles and executes code that increments a global\nvariable and sets a new one. These globals are contained in the <code>contextObject</code>.</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nconst contextObject = {\n animal: 'cat',\n count: 2,\n};\n\nvm.runInNewContext('count += 1; name = \"kitty\"', contextObject);\nconsole.log(contextObject);\n// Prints: { animal: 'cat', count: 3, name: 'kitty' }\n</code></pre>" 13921cb0ef41Sopenharmony_ci }, 13931cb0ef41Sopenharmony_ci { 13941cb0ef41Sopenharmony_ci "textRaw": "`vm.runInThisContext(code[, options])`", 13951cb0ef41Sopenharmony_ci "type": "method", 13961cb0ef41Sopenharmony_ci "name": "runInThisContext", 13971cb0ef41Sopenharmony_ci "meta": { 13981cb0ef41Sopenharmony_ci "added": [ 13991cb0ef41Sopenharmony_ci "v0.3.1" 14001cb0ef41Sopenharmony_ci ], 14011cb0ef41Sopenharmony_ci "changes": [ 14021cb0ef41Sopenharmony_ci { 14031cb0ef41Sopenharmony_ci "version": [ 14041cb0ef41Sopenharmony_ci "v17.0.0", 14051cb0ef41Sopenharmony_ci "v16.12.0" 14061cb0ef41Sopenharmony_ci ], 14071cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/40249", 14081cb0ef41Sopenharmony_ci "description": "Added support for import attributes to the `importModuleDynamically` parameter." 14091cb0ef41Sopenharmony_ci }, 14101cb0ef41Sopenharmony_ci { 14111cb0ef41Sopenharmony_ci "version": "v6.3.0", 14121cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6635", 14131cb0ef41Sopenharmony_ci "description": "The `breakOnSigint` option is supported now." 14141cb0ef41Sopenharmony_ci } 14151cb0ef41Sopenharmony_ci ] 14161cb0ef41Sopenharmony_ci }, 14171cb0ef41Sopenharmony_ci "signatures": [ 14181cb0ef41Sopenharmony_ci { 14191cb0ef41Sopenharmony_ci "return": { 14201cb0ef41Sopenharmony_ci "textRaw": "Returns: {any} the result of the very last statement executed in the script.", 14211cb0ef41Sopenharmony_ci "name": "return", 14221cb0ef41Sopenharmony_ci "type": "any", 14231cb0ef41Sopenharmony_ci "desc": "the result of the very last statement executed in the script." 14241cb0ef41Sopenharmony_ci }, 14251cb0ef41Sopenharmony_ci "params": [ 14261cb0ef41Sopenharmony_ci { 14271cb0ef41Sopenharmony_ci "textRaw": "`code` {string} The JavaScript code to compile and run.", 14281cb0ef41Sopenharmony_ci "name": "code", 14291cb0ef41Sopenharmony_ci "type": "string", 14301cb0ef41Sopenharmony_ci "desc": "The JavaScript code to compile and run." 14311cb0ef41Sopenharmony_ci }, 14321cb0ef41Sopenharmony_ci { 14331cb0ef41Sopenharmony_ci "textRaw": "`options` {Object|string}", 14341cb0ef41Sopenharmony_ci "name": "options", 14351cb0ef41Sopenharmony_ci "type": "Object|string", 14361cb0ef41Sopenharmony_ci "options": [ 14371cb0ef41Sopenharmony_ci { 14381cb0ef41Sopenharmony_ci "textRaw": "`filename` {string} Specifies the filename used in stack traces produced by this script. **Default:** `'evalmachine.<anonymous>'`.", 14391cb0ef41Sopenharmony_ci "name": "filename", 14401cb0ef41Sopenharmony_ci "type": "string", 14411cb0ef41Sopenharmony_ci "default": "`'evalmachine.<anonymous>'`", 14421cb0ef41Sopenharmony_ci "desc": "Specifies the filename used in stack traces produced by this script." 14431cb0ef41Sopenharmony_ci }, 14441cb0ef41Sopenharmony_ci { 14451cb0ef41Sopenharmony_ci "textRaw": "`lineOffset` {number} Specifies the line number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 14461cb0ef41Sopenharmony_ci "name": "lineOffset", 14471cb0ef41Sopenharmony_ci "type": "number", 14481cb0ef41Sopenharmony_ci "default": "`0`", 14491cb0ef41Sopenharmony_ci "desc": "Specifies the line number offset that is displayed in stack traces produced by this script." 14501cb0ef41Sopenharmony_ci }, 14511cb0ef41Sopenharmony_ci { 14521cb0ef41Sopenharmony_ci "textRaw": "`columnOffset` {number} Specifies the first-line column number offset that is displayed in stack traces produced by this script. **Default:** `0`.", 14531cb0ef41Sopenharmony_ci "name": "columnOffset", 14541cb0ef41Sopenharmony_ci "type": "number", 14551cb0ef41Sopenharmony_ci "default": "`0`", 14561cb0ef41Sopenharmony_ci "desc": "Specifies the first-line column number offset that is displayed in stack traces produced by this script." 14571cb0ef41Sopenharmony_ci }, 14581cb0ef41Sopenharmony_ci { 14591cb0ef41Sopenharmony_ci "textRaw": "`displayErrors` {boolean} When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace. **Default:** `true`.", 14601cb0ef41Sopenharmony_ci "name": "displayErrors", 14611cb0ef41Sopenharmony_ci "type": "boolean", 14621cb0ef41Sopenharmony_ci "default": "`true`", 14631cb0ef41Sopenharmony_ci "desc": "When `true`, if an [`Error`][] occurs while compiling the `code`, the line of code causing the error is attached to the stack trace." 14641cb0ef41Sopenharmony_ci }, 14651cb0ef41Sopenharmony_ci { 14661cb0ef41Sopenharmony_ci "textRaw": "`timeout` {integer} Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer.", 14671cb0ef41Sopenharmony_ci "name": "timeout", 14681cb0ef41Sopenharmony_ci "type": "integer", 14691cb0ef41Sopenharmony_ci "desc": "Specifies the number of milliseconds to execute `code` before terminating execution. If execution is terminated, an [`Error`][] will be thrown. This value must be a strictly positive integer." 14701cb0ef41Sopenharmony_ci }, 14711cb0ef41Sopenharmony_ci { 14721cb0ef41Sopenharmony_ci "textRaw": "`breakOnSigint` {boolean} If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that. **Default:** `false`.", 14731cb0ef41Sopenharmony_ci "name": "breakOnSigint", 14741cb0ef41Sopenharmony_ci "type": "boolean", 14751cb0ef41Sopenharmony_ci "default": "`false`", 14761cb0ef41Sopenharmony_ci "desc": "If `true`, receiving `SIGINT` (<kbd>Ctrl</kbd>+<kbd>C</kbd>) will terminate execution and throw an [`Error`][]. Existing handlers for the event that have been attached via `process.on('SIGINT')` are disabled during script execution, but continue to work after that." 14771cb0ef41Sopenharmony_ci }, 14781cb0ef41Sopenharmony_ci { 14791cb0ef41Sopenharmony_ci "textRaw": "`cachedData` {Buffer|TypedArray|DataView} Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source.", 14801cb0ef41Sopenharmony_ci "name": "cachedData", 14811cb0ef41Sopenharmony_ci "type": "Buffer|TypedArray|DataView", 14821cb0ef41Sopenharmony_ci "desc": "Provides an optional `Buffer` or `TypedArray`, or `DataView` with V8's code cache data for the supplied source." 14831cb0ef41Sopenharmony_ci }, 14841cb0ef41Sopenharmony_ci { 14851cb0ef41Sopenharmony_ci "textRaw": "`importModuleDynamically` {Function} Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 14861cb0ef41Sopenharmony_ci "name": "importModuleDynamically", 14871cb0ef41Sopenharmony_ci "type": "Function", 14881cb0ef41Sopenharmony_ci "desc": "Called during evaluation of this module when `import()` is called. If this option is not specified, calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING`][]. This option is part of the experimental modules API. We do not recommend using it in a production environment. If `--experimental-vm-modules` isn't set, this callback will be ignored and calls to `import()` will reject with [`ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG`][].", 14891cb0ef41Sopenharmony_ci "options": [ 14901cb0ef41Sopenharmony_ci { 14911cb0ef41Sopenharmony_ci "textRaw": "`specifier` {string} specifier passed to `import()`", 14921cb0ef41Sopenharmony_ci "name": "specifier", 14931cb0ef41Sopenharmony_ci "type": "string", 14941cb0ef41Sopenharmony_ci "desc": "specifier passed to `import()`" 14951cb0ef41Sopenharmony_ci }, 14961cb0ef41Sopenharmony_ci { 14971cb0ef41Sopenharmony_ci "textRaw": "`script` {vm.Script}", 14981cb0ef41Sopenharmony_ci "name": "script", 14991cb0ef41Sopenharmony_ci "type": "vm.Script" 15001cb0ef41Sopenharmony_ci }, 15011cb0ef41Sopenharmony_ci { 15021cb0ef41Sopenharmony_ci "textRaw": "`importAttributes` {Object} The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided.", 15031cb0ef41Sopenharmony_ci "name": "importAttributes", 15041cb0ef41Sopenharmony_ci "type": "Object", 15051cb0ef41Sopenharmony_ci "desc": "The `\"with\"` value passed to the [`optionsExpression`][] optional parameter, or an empty object if no value was provided." 15061cb0ef41Sopenharmony_ci }, 15071cb0ef41Sopenharmony_ci { 15081cb0ef41Sopenharmony_ci "textRaw": "Returns: {Module Namespace Object|vm.Module} Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports.", 15091cb0ef41Sopenharmony_ci "name": "return", 15101cb0ef41Sopenharmony_ci "type": "Module Namespace Object|vm.Module", 15111cb0ef41Sopenharmony_ci "desc": "Returning a `vm.Module` is recommended in order to take advantage of error tracking, and to avoid issues with namespaces that contain `then` function exports." 15121cb0ef41Sopenharmony_ci } 15131cb0ef41Sopenharmony_ci ] 15141cb0ef41Sopenharmony_ci } 15151cb0ef41Sopenharmony_ci ] 15161cb0ef41Sopenharmony_ci } 15171cb0ef41Sopenharmony_ci ] 15181cb0ef41Sopenharmony_ci } 15191cb0ef41Sopenharmony_ci ], 15201cb0ef41Sopenharmony_ci "desc": "<p><code>vm.runInThisContext()</code> compiles <code>code</code>, runs it within the context of the\ncurrent <code>global</code> and returns the result. Running code does not have access to\nlocal scope, but does have access to the current <code>global</code> object.</p>\n<p>If <code>options</code> is a string, then it specifies the filename.</p>\n<p>The following example illustrates using both <code>vm.runInThisContext()</code> and\nthe JavaScript <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval\"><code>eval()</code></a> function to run the same code:</p>\n<!-- eslint-disable prefer-const -->\n<pre><code class=\"language-js\">const vm = require('node:vm');\nlet localVar = 'initial value';\n\nconst vmResult = vm.runInThisContext('localVar = \"vm\";');\nconsole.log(`vmResult: '${vmResult}', localVar: '${localVar}'`);\n// Prints: vmResult: 'vm', localVar: 'initial value'\n\nconst evalResult = eval('localVar = \"eval\";');\nconsole.log(`evalResult: '${evalResult}', localVar: '${localVar}'`);\n// Prints: evalResult: 'eval', localVar: 'eval'\n</code></pre>\n<p>Because <code>vm.runInThisContext()</code> does not have access to the local scope,\n<code>localVar</code> is unchanged. In contrast, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval\"><code>eval()</code></a> <em>does</em> have access to the\nlocal scope, so the value <code>localVar</code> is changed. In this way\n<code>vm.runInThisContext()</code> is much like an <a href=\"https://es5.github.io/#x10.4.2\">indirect <code>eval()</code> call</a>, e.g.\n<code>(0,eval)('code')</code>.</p>\n<h2>Example: Running an HTTP server within a VM</h2>\n<p>When using either <a href=\"#scriptruninthiscontextoptions\"><code>script.runInThisContext()</code></a> or\n<a href=\"#vmruninthiscontextcode-options\"><code>vm.runInThisContext()</code></a>, the code is executed within the current V8 global\ncontext. The code passed to this VM context will have its own isolated scope.</p>\n<p>In order to run a simple web server using the <code>node:http</code> module the code passed\nto the context must either call <code>require('node:http')</code> on its own, or have a\nreference to the <code>node:http</code> module passed to it. For instance:</p>\n<pre><code class=\"language-js\">'use strict';\nconst vm = require('node:vm');\n\nconst code = `\n((require) => {\n const http = require('node:http');\n\n http.createServer((request, response) => {\n response.writeHead(200, { 'Content-Type': 'text/plain' });\n response.end('Hello World\\\\n');\n }).listen(8124);\n\n console.log('Server running at http://127.0.0.1:8124/');\n})`;\n\nvm.runInThisContext(code)(require);\n</code></pre>\n<p>The <code>require()</code> in the above case shares the state with the context it is\npassed from. This may introduce risks when untrusted code is executed, e.g.\naltering objects in the context in unwanted ways.</p>" 15211cb0ef41Sopenharmony_ci } 15221cb0ef41Sopenharmony_ci ], 15231cb0ef41Sopenharmony_ci "modules": [ 15241cb0ef41Sopenharmony_ci { 15251cb0ef41Sopenharmony_ci "textRaw": "What does it mean to \"contextify\" an object?", 15261cb0ef41Sopenharmony_ci "name": "what_does_it_mean_to_\"contextify\"_an_object?", 15271cb0ef41Sopenharmony_ci "desc": "<p>All JavaScript executed within Node.js runs within the scope of a \"context\".\nAccording to the <a href=\"https://v8.dev/docs/embed#contexts\">V8 Embedder's Guide</a>:</p>\n<blockquote>\n<p>In V8, a context is an execution environment that allows separate, unrelated,\nJavaScript applications to run in a single instance of V8. You must explicitly\nspecify the context in which you want any JavaScript code to be run.</p>\n</blockquote>\n<p>When the method <code>vm.createContext()</code> is called, the <code>contextObject</code> argument\n(or a newly-created object if <code>contextObject</code> is <code>undefined</code>) is associated\ninternally with a new instance of a V8 Context. This V8 Context provides the\n<code>code</code> run using the <code>node:vm</code> module's methods with an isolated global\nenvironment within which it can operate. The process of creating the V8 Context\nand associating it with the <code>contextObject</code> is what this document refers to as\n\"contextifying\" the object.</p>", 15281cb0ef41Sopenharmony_ci "type": "module", 15291cb0ef41Sopenharmony_ci "displayName": "What does it mean to \"contextify\" an object?" 15301cb0ef41Sopenharmony_ci }, 15311cb0ef41Sopenharmony_ci { 15321cb0ef41Sopenharmony_ci "textRaw": "Timeout interactions with asynchronous tasks and Promises", 15331cb0ef41Sopenharmony_ci "name": "timeout_interactions_with_asynchronous_tasks_and_promises", 15341cb0ef41Sopenharmony_ci "desc": "<p><code>Promise</code>s and <code>async function</code>s can schedule tasks run by the JavaScript\nengine asynchronously. By default, these tasks are run after all JavaScript\nfunctions on the current stack are done executing.\nThis allows escaping the functionality of the <code>timeout</code> and\n<code>breakOnSigint</code> options.</p>\n<p>For example, the following code executed by <code>vm.runInNewContext()</code> with a\ntimeout of 5 milliseconds schedules an infinite loop to run after a promise\nresolves. The scheduled loop is never interrupted by the timeout:</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nfunction loop() {\n console.log('entering loop');\n while (1) console.log(Date.now());\n}\n\nvm.runInNewContext(\n 'Promise.resolve().then(() => loop());',\n { loop, console },\n { timeout: 5 },\n);\n// This is printed *before* 'entering loop' (!)\nconsole.log('done executing');\n</code></pre>\n<p>This can be addressed by passing <code>microtaskMode: 'afterEvaluate'</code> to the code\nthat creates the <code>Context</code>:</p>\n<pre><code class=\"language-js\">const vm = require('node:vm');\n\nfunction loop() {\n while (1) console.log(Date.now());\n}\n\nvm.runInNewContext(\n 'Promise.resolve().then(() => loop());',\n { loop, console },\n { timeout: 5, microtaskMode: 'afterEvaluate' },\n);\n</code></pre>\n<p>In this case, the microtask scheduled through <code>promise.then()</code> will be run\nbefore returning from <code>vm.runInNewContext()</code>, and will be interrupted\nby the <code>timeout</code> functionality. This applies only to code running in a\n<code>vm.Context</code>, so e.g. <a href=\"#vmruninthiscontextcode-options\"><code>vm.runInThisContext()</code></a> does not take this option.</p>\n<p>Promise callbacks are entered into the microtask queue of the context in which\nthey were created. For example, if <code>() => loop()</code> is replaced with just <code>loop</code>\nin the above example, then <code>loop</code> will be pushed into the global microtask\nqueue, because it is a function from the outer (main) context, and thus will\nalso be able to escape the timeout.</p>\n<p>If asynchronous scheduling functions such as <code>process.nextTick()</code>,\n<code>queueMicrotask()</code>, <code>setTimeout()</code>, <code>setImmediate()</code>, etc. are made available\ninside a <code>vm.Context</code>, functions passed to them will be added to global queues,\nwhich are shared by all contexts. Therefore, callbacks passed to those functions\nare not controllable through the timeout either.</p>", 15351cb0ef41Sopenharmony_ci "type": "module", 15361cb0ef41Sopenharmony_ci "displayName": "Timeout interactions with asynchronous tasks and Promises" 15371cb0ef41Sopenharmony_ci } 15381cb0ef41Sopenharmony_ci ], 15391cb0ef41Sopenharmony_ci "type": "module", 15401cb0ef41Sopenharmony_ci "displayName": "vm" 15411cb0ef41Sopenharmony_ci } 15421cb0ef41Sopenharmony_ci ] 15431cb0ef41Sopenharmony_ci}