{
  "type": "module",
  "source": "doc/api/vm.md",
  "modules": [
    {
      "textRaw": "VM (Executing JavaScript)",
      "name": "vm",
      "introduced_in": "v0.10.0",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>The <code>vm</code> module enables compiling and running code within V8 Virtual\nMachine contexts. <strong>The <code>vm</code> module is not a security mechanism. Do\nnot 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=\"#vm_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('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>",
      "modules": [
        {
          "textRaw": "Class: `vm.Script`",
          "name": "class:_`vm.script`",
          "meta": {
            "added": [
              "v0.3.1"
            ],
            "changes": []
          },
          "desc": "<p>Instances of the <code>vm.Script</code> class contain precompiled scripts that can be\nexecuted in specific contexts.</p>",
          "modules": [
            {
              "textRaw": "Constructor: `new vm.Script(code[, options])`",
              "name": "constructor:_`new_vm.script(code[,_options])`",
              "meta": {
                "added": [
                  "v0.3.1"
                ],
                "changes": [
                  {
                    "version": "v5.7.0",
                    "pr-url": "https://github.com/nodejs/node/pull/4777",
                    "description": "The `cachedData` and `produceCachedData` options are supported now."
                  },
                  {
                    "version": "v10.6.0",
                    "pr-url": "https://github.com/nodejs/node/pull/20300",
                    "description": "The `produceCachedData` is deprecated in favour of `script.createCachedData()`"
                  }
                ]
              },
              "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The JavaScript code to compile.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></p>\n<ul>\n<li><code>filename</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Specifies the filename used in stack traces produced\nby this script. <strong>Default:</strong> <code>'evalmachine.&#x3C;anonymous>'</code>.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the column number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>cachedData</code> <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\">&lt;TypedArray&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\">&lt;DataView&gt;</a> Provides an optional <code>Buffer</code> or\n<code>TypedArray</code>, or <code>DataView</code> with V8's code cache data for the supplied\nsource. When supplied, the <code>cachedDataRejected</code> value will be set to\neither <code>true</code> or <code>false</code> depending on acceptance of the data by V8.</li>\n<li><code>produceCachedData</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code> and no <code>cachedData</code> is present, V8\nwill attempt to produce code cache data for <code>code</code>. Upon success, a\n<code>Buffer</code> with V8's code cache data will be produced and stored in the\n<code>cachedData</code> property of the returned <code>vm.Script</code> instance.\nThe <code>cachedDataProduced</code> value will be set to either <code>true</code> or <code>false</code>\ndepending on whether code cache data is produced successfully.\nThis option is <strong>deprecated</strong> in favor of <code>script.createCachedData()</code>.\n<strong>Default:</strong> <code>false</code>.</li>\n<li>\n<p><code>importModuleDynamically</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this module\nwhen <code>import()</code> is called. If this option is not specified, calls to\n<code>import()</code> will reject with <a href=\"errors.html#ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING\"><code>ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</code></a>.\nThis option is part of the experimental API for the <code>--experimental-modules</code>\nflag, and should not be considered stable.</p>\n<ul>\n<li><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> specifier passed to <code>import()</code></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a></li>\n<li>Returns: <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\" class=\"type\">&lt;Module Namespace Object&gt;</a> | <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> Returning a <code>vm.Module</code> is\nrecommended in order to take advantage of error tracking, and to avoid\nissues with namespaces that contain <code>then</code> function exports.</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "Constructor: `new vm.Script(code[, options])`"
            },
            {
              "textRaw": "`script.createCachedData()`",
              "name": "`script.createcacheddata()`",
              "meta": {
                "added": [
                  "v10.6.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li>Returns: <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a></li>\n</ul>\n<p>Creates a code cache that can be used with the Script constructor's\n<code>cachedData</code> option. Returns a Buffer. This method may be called at any\ntime and any number of times.</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 cacheWithoutX = script.createCachedData();\n\nscript.runInThisContext();\n\nconst cacheWithX = script.createCachedData();\n</code></pre>",
              "type": "module",
              "displayName": "`script.createCachedData()`"
            },
            {
              "textRaw": "`script.runInContext(contextifiedObject[, options])`",
              "name": "`script.runincontext(contextifiedobject[,_options])`",
              "meta": {
                "added": [
                  "v0.3.1"
                ],
                "changes": [
                  {
                    "version": "v6.3.0",
                    "pr-url": "https://github.com/nodejs/node/pull/6635",
                    "description": "The `breakOnSigint` option is supported now."
                  }
                ]
              },
              "desc": "<ul>\n<li><code>contextifiedObject</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> A <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object as returned by the\n<code>vm.createContext()</code> method.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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 util = require('util');\nconst vm = require('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 &#x3C; 10; ++i) {\n  script.runInContext(context);\n}\n\nconsole.log(util.inspect(context));\n\n// { 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>",
              "type": "module",
              "displayName": "`script.runInContext(contextifiedObject[, options])`"
            },
            {
              "textRaw": "`script.runInNewContext([contextObject[, options]])`",
              "name": "`script.runinnewcontext([contextobject[,_options]])`",
              "meta": {
                "added": [
                  "v0.3.1"
                ],
                "changes": [
                  {
                    "version": "v10.0.0",
                    "pr-url": "https://github.com/nodejs/node/pull/19016",
                    "description": "The `contextCodeGeneration` option is supported now."
                  },
                  {
                    "version": "v6.3.0",
                    "pr-url": "https://github.com/nodejs/node/pull/6635",
                    "description": "The `breakOnSigint` option is supported now."
                  }
                ]
              },
              "desc": "<ul>\n<li><code>contextObject</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> An object that will be <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a>. If\n<code>undefined</code>, a new object will be created.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n<li><code>contextName</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Human-readable name of the newly created context.\n<strong>Default:</strong> <code>'VM Context i'</code>, where <code>i</code> is an ascending numerical index of\nthe created context.</li>\n<li><code>contextOrigin</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Origin\">Origin</a> corresponding to the newly\ncreated context for display purposes. The origin should be formatted like a\nURL, but with only the scheme, host, and port (if necessary), like the\nvalue of the <a href=\"url.html#url_url_origin\"><code>url.origin</code></a> property of a <a href=\"url.html#url_class_url\"><code>URL</code></a> object. Most notably,\nthis string should omit the trailing slash, as that denotes a path.\n<strong>Default:</strong> <code>''</code>.</li>\n<li>\n<p><code>contextCodeGeneration</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>strings</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any calls to <code>eval</code> or function\nconstructors (<code>Function</code>, <code>GeneratorFunction</code>, etc) will throw an\n<code>EvalError</code>. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>wasm</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any attempt to compile a WebAssembly\nmodule will throw a <code>WebAssembly.CompileError</code>. <strong>Default:</strong> <code>true</code>.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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 util = require('util');\nconst vm = require('vm');\n\nconst script = new vm.Script('globalVar = \"set\"');\n\nconst contexts = [{}, {}, {}];\ncontexts.forEach((context) => {\n  script.runInNewContext(context);\n});\n\nconsole.log(util.inspect(contexts));\n\n// [{ globalVar: 'set' }, { globalVar: 'set' }, { globalVar: 'set' }]\n</code></pre>",
              "type": "module",
              "displayName": "`script.runInNewContext([contextObject[, options]])`"
            },
            {
              "textRaw": "`script.runInThisContext([options])`",
              "name": "`script.runinthiscontext([options])`",
              "meta": {
                "added": [
                  "v0.3.1"
                ],
                "changes": [
                  {
                    "version": "v6.3.0",
                    "pr-url": "https://github.com/nodejs/node/pull/6635",
                    "description": "The `breakOnSigint` option is supported now."
                  }
                ]
              },
              "desc": "<ul>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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('vm');\n\nglobal.globalVar = 0;\n\nconst script = new vm.Script('globalVar += 1', { filename: 'myfile.vm' });\n\nfor (let i = 0; i &#x3C; 1000; ++i) {\n  script.runInThisContext();\n}\n\nconsole.log(globalVar);\n\n// 1000\n</code></pre>",
              "type": "module",
              "displayName": "`script.runInThisContext([options])`"
            }
          ],
          "type": "module",
          "displayName": "Class: `vm.Script`"
        },
        {
          "textRaw": "Class: `vm.Module`",
          "name": "class:_`vm.module`",
          "meta": {
            "added": [
              "v12.16.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<p><em>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</em></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. With the help\nof async functions, however, manipulating <code>vm.Module</code> objects is fairly\nstraightforward.</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#esm_ecmascript_modules\">ECMAScript Module\nloader</a>. There is also currently no way to interact with the Loader, though\nsupport is planned.</p>\n<pre><code class=\"language-js\">const vm = require('vm');\n\nconst contextifiedObject = vm.createContext({ secret: 42 });\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  `, { 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 with a single\n  // property \"result\" that contains the result of the very last statement\n  // executed in the Module. In the case of `bar`, it is `s;`, which refers to\n  // the default export of the `foo` module, the `secret` we set in the\n  // beginning to 42.\n\n  const { result } = await bar.evaluate();\n\n  console.log(result);\n  // Prints 42.\n})();\n</code></pre>",
          "modules": [
            {
              "textRaw": "`module.dependencySpecifiers`",
              "name": "`module.dependencyspecifiers`",
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a></li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "`module.dependencySpecifiers`"
            },
            {
              "textRaw": "`module.error`",
              "name": "`module.error`",
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a></li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "`module.error`"
            },
            {
              "textRaw": "`module.evaluate([options])`",
              "name": "`module.evaluate([options])`",
              "desc": "<ul>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to evaluate\nbefore terminating execution. If execution is interrupted, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the event that have\nbeen attached via <code>process.on('SIGINT')</code> will be disabled during script\nexecution, but will continue to work after that. If execution is\ninterrupted, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</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\">&lt;Promise&gt;</a></li>\n</ul>\n<p>Evaluate the module.</p>\n<p>This must be called after the module has been linked; otherwise it will\nthrow an error. It could be called also when the module has already been\nevaluated, in which case it will do one of the following two things:</p>\n<ul>\n<li>return <code>undefined</code> if the initial evaluation ended in success (<code>module.status</code>\nis <code>'evaluated'</code>)</li>\n<li>rethrow the same exception the initial evaluation threw if the initial\nevaluation ended in an error (<code>module.status</code> is <code>'errored'</code>)</li>\n</ul>\n<p>This method cannot be called while the module is being evaluated\n(<code>module.status</code> is <code>'evaluating'</code>) to prevent infinite recursion.</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>",
              "type": "module",
              "displayName": "`module.evaluate([options])`"
            },
            {
              "textRaw": "`module.link(linker)`",
              "name": "`module.link(linker)`",
              "desc": "<ul>\n<li>\n<p><code>linker</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a></p>\n<ul>\n<li>\n<p><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The specifier of the requested module:</p>\n<!-- eslint-skip -->\n<pre><code class=\"language-js\">import foo from 'foo';\n//              ^^^^^ the module specifier\n</code></pre>\n</li>\n<li>\n<p><code>referencingModule</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> The <code>Module</code> object <code>link()</code> is called on.</p>\n</li>\n<li>\n<p>Returns: <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\" class=\"type\">&lt;Promise&gt;</a></p>\n</li>\n</ul>\n</li>\n<li>\n<p>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise\" class=\"type\">&lt;Promise&gt;</a></p>\n</li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "`module.link(linker)`"
            },
            {
              "textRaw": "`module.namespace`",
              "name": "`module.namespace`",
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "`module.namespace`"
            },
            {
              "textRaw": "`module.status`",
              "name": "`module.status`",
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "`module.status`"
            },
            {
              "textRaw": "`module.identifier`",
              "name": "`module.identifier`",
              "desc": "<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></li>\n</ul>\n<p>The identifier of the current module, as set in the constructor.</p>",
              "type": "module",
              "displayName": "`module.identifier`"
            }
          ],
          "type": "module",
          "displayName": "Class: `vm.Module`"
        },
        {
          "textRaw": "Class: `vm.SourceTextModule`",
          "name": "class:_`vm.sourcetextmodule`",
          "meta": {
            "added": [
              "v9.6.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<p><em>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</em></p>\n<ul>\n<li>Extends: <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</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>",
          "modules": [
            {
              "textRaw": "Constructor: `new vm.SourceTextModule(code[, options])`",
              "name": "constructor:_`new_vm.sourcetextmodule(code[,_options])`",
              "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> JavaScript Module code to parse</li>\n<li>\n<p><code>options</code></p>\n<ul>\n<li><code>identifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> String used in stack traces.\n<strong>Default:</strong> <code>'vm:module(i)'</code> where <code>i</code> is a context-specific ascending\nindex.</li>\n<li><code>context</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> The <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object as returned by the\n<code>vm.createContext()</code> method, to compile and evaluate this <code>Module</code> in.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this <code>Module</code>. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the column number offset that is\ndisplayed in stack traces produced by this <code>Module</code>. <strong>Default:</strong> <code>0</code>.</li>\n<li>\n<p><code>initializeImportMeta</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this <code>Module</code>\nto initialize the <code>import.meta</code>.</p>\n<ul>\n<li><code>meta</code> <a href=\"esm.html#esm_import_meta\" class=\"type\">&lt;import.meta&gt;</a></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_sourcetextmodule\" class=\"type\">&lt;vm.SourceTextModule&gt;</a></li>\n</ul>\n</li>\n<li>\n<p><code>importModuleDynamically</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this module\nwhen <code>import()</code> is called. If this option is not specified, calls to\n<code>import()</code> will reject with <a href=\"errors.html#ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING\"><code>ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</code></a>.</p>\n<ul>\n<li><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> specifier passed to <code>import()</code></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a></li>\n<li>Returns: <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\" class=\"type\">&lt;Module Namespace Object&gt;</a> | <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> Returning a <code>vm.Module</code> is\nrecommended in order to take advantage of error tracking, and to avoid\nissues with namespaces that contain <code>then</code> function exports.</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<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-js\">const vm = require('vm');\n\nconst contextifiedObject = vm.createContext({ secret: 42 });\n\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\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>",
              "type": "module",
              "displayName": "Constructor: `new vm.SourceTextModule(code[, options])`"
            }
          ],
          "type": "module",
          "displayName": "Class: `vm.SourceTextModule`"
        },
        {
          "textRaw": "Class: `vm.SyntheticModule`",
          "name": "class:_`vm.syntheticmodule`",
          "meta": {
            "added": [
              "v12.16.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": "Experimental",
          "desc": "<p><em>This feature is only available with the <code>--experimental-vm-modules</code> command\nflag enabled.</em></p>\n<ul>\n<li>Extends: <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</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('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>",
          "modules": [
            {
              "textRaw": "Constructor: `new vm.SyntheticModule(exportNames, evaluateCallback[, options])`",
              "name": "constructor:_`new_vm.syntheticmodule(exportnames,_evaluatecallback[,_options])`",
              "meta": {
                "added": [
                  "v12.16.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li><code>exportNames</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a> Array of names that will be exported from the module.</li>\n<li><code>evaluateCallback</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called when the module is evaluated.</li>\n<li>\n<p><code>options</code></p>\n<ul>\n<li><code>identifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> String used in stack traces.\n<strong>Default:</strong> <code>'vm:module(i)'</code> where <code>i</code> is a context-specific ascending\nindex.</li>\n<li><code>context</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> The <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object as returned by the\n<code>vm.createContext()</code> method, to compile and evaluate this <code>Module</code> in.</li>\n</ul>\n</li>\n</ul>\n<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>",
              "type": "module",
              "displayName": "Constructor: `new vm.SyntheticModule(exportNames, evaluateCallback[, options])`"
            },
            {
              "textRaw": "`syntheticModule.setExport(name, value)`",
              "name": "`syntheticmodule.setexport(name,_value)`",
              "meta": {
                "added": [
                  "v12.16.0"
                ],
                "changes": []
              },
              "desc": "<ul>\n<li><code>name</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Name of the export to set.</li>\n<li><code>value</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> The value to set the export to.</li>\n</ul>\n<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-js\">const vm = require('vm');\n\n(async () => {\n  const m = new vm.SyntheticModule(['x'], () => {\n    m.setExport('x', 1);\n  });\n\n  await m.link(() => {});\n  await m.evaluate();\n\n  assert.strictEqual(m.namespace.x, 1);\n})();\n</code></pre>",
              "type": "module",
              "displayName": "`syntheticModule.setExport(name, value)`"
            }
          ],
          "type": "module",
          "displayName": "Class: `vm.SyntheticModule`"
        },
        {
          "textRaw": "`vm.compileFunction(code[, params[, options]])`",
          "name": "`vm.compilefunction(code[,_params[,_options]])`",
          "meta": {
            "added": [
              "v10.10.0"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The body of the function to compile.</li>\n<li><code>params</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string[]&gt;</a> An array of strings containing all parameters for the\nfunction.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>filename</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Specifies the filename used in stack traces produced\nby this script. <strong>Default:</strong> <code>''</code>.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the column number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>cachedData</code> <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\">&lt;TypedArray&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\">&lt;DataView&gt;</a> Provides an optional <code>Buffer</code> or\n<code>TypedArray</code>, or <code>DataView</code> with V8's code cache data for the supplied\nsource.</li>\n<li><code>produceCachedData</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> Specifies whether to produce new cache data.\n<strong>Default:</strong> <code>false</code>.</li>\n<li><code>parsingContext</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> The <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object in which the said\nfunction should be compiled in.</li>\n<li><code>contextExtensions</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object[]&gt;</a> An array containing a collection of context\nextensions (objects wrapping the current scope) to be applied while\ncompiling. <strong>Default:</strong> <code>[]</code>.</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a></li>\n</ul>\n<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>",
          "type": "module",
          "displayName": "`vm.compileFunction(code[, params[, options]])`"
        },
        {
          "textRaw": "`vm.createContext([contextObject[, options]])`",
          "name": "`vm.createcontext([contextobject[,_options]])`",
          "meta": {
            "added": [
              "v0.3.1"
            ],
            "changes": [
              {
                "version": "v10.0.0",
                "pr-url": "https://github.com/nodejs/node/pull/19398",
                "description": "The first argument can no longer be a function."
              },
              {
                "version": "v10.0.0",
                "pr-url": "https://github.com/nodejs/node/pull/19016",
                "description": "The `codeGeneration` option is supported now."
              }
            ]
          },
          "desc": "<ul>\n<li><code>contextObject</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>name</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Human-readable name of the newly created context.\n<strong>Default:</strong> <code>'VM Context i'</code>, where <code>i</code> is an ascending numerical index of\nthe created context.</li>\n<li><code>origin</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Origin\">Origin</a> corresponding to the newly created\ncontext for display purposes. The origin should be formatted like a URL,\nbut with only the scheme, host, and port (if necessary), like the value of\nthe <a href=\"url.html#url_url_origin\"><code>url.origin</code></a> property of a <a href=\"url.html#url_class_url\"><code>URL</code></a> object. Most notably, this\nstring should omit the trailing slash, as that denotes a path.\n<strong>Default:</strong> <code>''</code>.</li>\n<li>\n<p><code>codeGeneration</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>strings</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any calls to <code>eval</code> or function\nconstructors (<code>Function</code>, <code>GeneratorFunction</code>, etc) will throw an\n<code>EvalError</code>. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>wasm</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any attempt to compile a WebAssembly\nmodule will throw a <code>WebAssembly.CompileError</code>. <strong>Default:</strong> <code>true</code>.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> contextified object.</li>\n</ul>\n<p>If given a <code>contextObject</code>, the <code>vm.createContext()</code> method will <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">prepare\nthat object</a> so that it can be used in calls to\n<a href=\"#vm_vm_runincontext_code_contextifiedobject_options\"><code>vm.runInContext()</code></a> or <a href=\"#vm_script_runincontext_contextifiedobject_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 util = require('util');\nconst vm = require('vm');\n\nglobal.globalVar = 3;\n\nconst context = { globalVar: 1 };\nvm.createContext(context);\n\nvm.runInContext('globalVar *= 2;', context);\n\nconsole.log(util.inspect(context)); // { globalVar: 2 }\n\nconsole.log(util.inspect(globalVar)); // 3\n</code></pre>\n<p>If <code>contextObject</code> is omitted (or passed explicitly as <code>undefined</code>), a new,\nempty <a href=\"#vm_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>&#x3C;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>",
          "type": "module",
          "displayName": "`vm.createContext([contextObject[, options]])`"
        },
        {
          "textRaw": "`vm.isContext(object)`",
          "name": "`vm.iscontext(object)`",
          "meta": {
            "added": [
              "v0.11.7"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li><code>object</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a></li>\n</ul>\n<p>Returns <code>true</code> if the given <code>oject</code> object has been <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> using\n<a href=\"#vm_vm_createcontext_contextobject_options\"><code>vm.createContext()</code></a>.</p>",
          "type": "module",
          "displayName": "`vm.isContext(object)`"
        },
        {
          "textRaw": "`vm.runInContext(code, contextifiedObject[, options])`",
          "name": "`vm.runincontext(code,_contextifiedobject[,_options])`",
          "meta": {
            "added": [
              "v0.3.1"
            ],
            "changes": [
              {
                "version": "v6.3.0",
                "pr-url": "https://github.com/nodejs/node/pull/6635",
                "description": "The `breakOnSigint` option is supported now."
              }
            ]
          },
          "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The JavaScript code to compile and run.</li>\n<li><code>contextifiedObject</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> The <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object that will be used\nas the <code>global</code> when the <code>code</code> is compiled and run.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></p>\n<ul>\n<li><code>filename</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Specifies the filename used in stack traces produced\nby this script. <strong>Default:</strong> <code>'evalmachine.&#x3C;anonymous>'</code>.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the column number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n<li><code>cachedData</code> <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\">&lt;TypedArray&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\">&lt;DataView&gt;</a> Provides an optional <code>Buffer</code> or\n<code>TypedArray</code>, or <code>DataView</code> with V8's code cache data for the supplied\nsource. When supplied, the <code>cachedDataRejected</code> value will be set to\neither <code>true</code> or <code>false</code> depending on acceptance of the data by V8.</li>\n<li><code>produceCachedData</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code> and no <code>cachedData</code> is present, V8\nwill attempt to produce code cache data for <code>code</code>. Upon success, a\n<code>Buffer</code> with V8's code cache data will be produced and stored in the\n<code>cachedData</code> property of the returned <code>vm.Script</code> instance.\nThe <code>cachedDataProduced</code> value will be set to either <code>true</code> or <code>false</code>\ndepending on whether code cache data is produced successfully.\nThis option is <strong>deprecated</strong> in favor of <code>script.createCachedData()</code>.\n<strong>Default:</strong> <code>false</code>.</li>\n<li>\n<p><code>importModuleDynamically</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this module\nwhen <code>import()</code> is called. If this option is not specified, calls to\n<code>import()</code> will reject with <a href=\"errors.html#ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING\"><code>ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</code></a>.\nThis option is part of the experimental API for the <code>--experimental-modules</code>\nflag, and should not be considered stable.</p>\n<ul>\n<li><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> specifier passed to <code>import()</code></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a></li>\n<li>Returns: <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\" class=\"type\">&lt;Module Namespace Object&gt;</a> | <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> Returning a <code>vm.Module</code> is\nrecommended in order to take advantage of error tracking, and to avoid\nissues with namespaces that contain <code>then</code> function exports.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> using the <a href=\"#vm_vm_createcontext_contextobject_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=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a> object:</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst vm = require('vm');\n\nconst contextObject = { globalVar: 1 };\nvm.createContext(contextObject);\n\nfor (let i = 0; i &#x3C; 10; ++i) {\n  vm.runInContext('globalVar *= 2;', contextObject);\n}\nconsole.log(util.inspect(contextObject));\n\n// { globalVar: 1024 }\n</code></pre>",
          "type": "module",
          "displayName": "`vm.runInContext(code, contextifiedObject[, options])`"
        },
        {
          "textRaw": "`vm.runInNewContext(code[, contextObject[, options]])`",
          "name": "`vm.runinnewcontext(code[,_contextobject[,_options]])`",
          "meta": {
            "added": [
              "v0.3.1"
            ],
            "changes": [
              {
                "version": "v10.0.0",
                "pr-url": "https://github.com/nodejs/node/pull/19016",
                "description": "The `contextCodeGeneration` option is supported now."
              },
              {
                "version": "v6.3.0",
                "pr-url": "https://github.com/nodejs/node/pull/6635",
                "description": "The `breakOnSigint` option is supported now."
              }
            ]
          },
          "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The JavaScript code to compile and run.</li>\n<li><code>contextObject</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> An object that will be <a href=\"#vm_what_does_it_mean_to_contextify_an_object\">contextified</a>. If\n<code>undefined</code>, a new object will be created.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></p>\n<ul>\n<li><code>filename</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Specifies the filename used in stack traces produced\nby this script. <strong>Default:</strong> <code>'evalmachine.&#x3C;anonymous>'</code>.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the column number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n<li><code>contextName</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Human-readable name of the newly created context.\n<strong>Default:</strong> <code>'VM Context i'</code>, where <code>i</code> is an ascending numerical index of\nthe created context.</li>\n<li><code>contextOrigin</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> <a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Origin\">Origin</a> corresponding to the newly\ncreated context for display purposes. The origin should be formatted like a\nURL, but with only the scheme, host, and port (if necessary), like the\nvalue of the <a href=\"url.html#url_url_origin\"><code>url.origin</code></a> property of a <a href=\"url.html#url_class_url\"><code>URL</code></a> object. Most notably,\nthis string should omit the trailing slash, as that denotes a path.\n<strong>Default:</strong> <code>''</code>.</li>\n<li>\n<p><code>contextCodeGeneration</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a></p>\n<ul>\n<li><code>strings</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any calls to <code>eval</code> or function\nconstructors (<code>Function</code>, <code>GeneratorFunction</code>, etc) will throw an\n<code>EvalError</code>. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>wasm</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If set to false any attempt to compile a WebAssembly\nmodule will throw a <code>WebAssembly.CompileError</code>. <strong>Default:</strong> <code>true</code>.</li>\n</ul>\n</li>\n<li><code>cachedData</code> <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\">&lt;TypedArray&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\">&lt;DataView&gt;</a> Provides an optional <code>Buffer</code> or\n<code>TypedArray</code>, or <code>DataView</code> with V8's code cache data for the supplied\nsource. When supplied, the <code>cachedDataRejected</code> value will be set to\neither <code>true</code> or <code>false</code> depending on acceptance of the data by V8.</li>\n<li><code>produceCachedData</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code> and no <code>cachedData</code> is present, V8\nwill attempt to produce code cache data for <code>code</code>. Upon success, a\n<code>Buffer</code> with V8's code cache data will be produced and stored in the\n<code>cachedData</code> property of the returned <code>vm.Script</code> instance.\nThe <code>cachedDataProduced</code> value will be set to either <code>true</code> or <code>false</code>\ndepending on whether code cache data is produced successfully.\nThis option is <strong>deprecated</strong> in favor of <code>script.createCachedData()</code>.\n<strong>Default:</strong> <code>false</code>.</li>\n<li>\n<p><code>importModuleDynamically</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this module\nwhen <code>import()</code> is called. If this option is not specified, calls to\n<code>import()</code> will reject with <a href=\"errors.html#ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING\"><code>ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</code></a>.\nThis option is part of the experimental API for the <code>--experimental-modules</code>\nflag, and should not be considered stable.</p>\n<ul>\n<li><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> specifier passed to <code>import()</code></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a></li>\n<li>Returns: <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\" class=\"type\">&lt;Module Namespace Object&gt;</a> | <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> Returning a <code>vm.Module</code> is\nrecommended in order to take advantage of error tracking, and to avoid\nissues with namespaces that contain <code>then</code> function exports.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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 util = require('util');\nconst vm = require('vm');\n\nconst contextObject = {\n  animal: 'cat',\n  count: 2\n};\n\nvm.runInNewContext('count += 1; name = \"kitty\"', contextObject);\nconsole.log(util.inspect(contextObject));\n\n// { animal: 'cat', count: 3, name: 'kitty' }\n</code></pre>",
          "type": "module",
          "displayName": "`vm.runInNewContext(code[, contextObject[, options]])`"
        },
        {
          "textRaw": "`vm.runInThisContext(code[, options])`",
          "name": "`vm.runinthiscontext(code[,_options])`",
          "meta": {
            "added": [
              "v0.3.1"
            ],
            "changes": [
              {
                "version": "v6.3.0",
                "pr-url": "https://github.com/nodejs/node/pull/6635",
                "description": "The `breakOnSigint` option is supported now."
              }
            ]
          },
          "desc": "<ul>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> The JavaScript code to compile and run.</li>\n<li>\n<p><code>options</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object\" class=\"type\">&lt;Object&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a></p>\n<ul>\n<li><code>filename</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> Specifies the filename used in stack traces produced\nby this script. <strong>Default:</strong> <code>'evalmachine.&#x3C;anonymous>'</code>.</li>\n<li><code>lineOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the line number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>columnOffset</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;number&gt;</a> Specifies the column number offset that is displayed\nin stack traces produced by this script. <strong>Default:</strong> <code>0</code>.</li>\n<li><code>displayErrors</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code>, if an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> occurs\nwhile compiling the <code>code</code>, the line of code causing the error is attached\nto the stack trace. <strong>Default:</strong> <code>true</code>.</li>\n<li><code>timeout</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type\" class=\"type\">&lt;integer&gt;</a> Specifies the number of milliseconds to execute <code>code</code>\nbefore terminating execution. If execution is terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a>\nwill be thrown. This value must be a strictly positive integer.</li>\n<li><code>breakOnSigint</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> If <code>true</code>, the execution will be terminated when\n<code>SIGINT</code> (Ctrl+C) is received. Existing handlers for the\nevent that have been attached via <code>process.on('SIGINT')</code> will be disabled\nduring script execution, but will continue to work after that. If execution\nis terminated, an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> will be thrown. <strong>Default:</strong> <code>false</code>.</li>\n<li><code>cachedData</code> <a href=\"buffer.html#buffer_class_buffer\" class=\"type\">&lt;Buffer&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray\" class=\"type\">&lt;TypedArray&gt;</a> | <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView\" class=\"type\">&lt;DataView&gt;</a> Provides an optional <code>Buffer</code> or\n<code>TypedArray</code>, or <code>DataView</code> with V8's code cache data for the supplied\nsource. When supplied, the <code>cachedDataRejected</code> value will be set to\neither <code>true</code> or <code>false</code> depending on acceptance of the data by V8.</li>\n<li><code>produceCachedData</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\">&lt;boolean&gt;</a> When <code>true</code> and no <code>cachedData</code> is present, V8\nwill attempt to produce code cache data for <code>code</code>. Upon success, a\n<code>Buffer</code> with V8's code cache data will be produced and stored in the\n<code>cachedData</code> property of the returned <code>vm.Script</code> instance.\nThe <code>cachedDataProduced</code> value will be set to either <code>true</code> or <code>false</code>\ndepending on whether code cache data is produced successfully.\nThis option is <strong>deprecated</strong> in favor of <code>script.createCachedData()</code>.\n<strong>Default:</strong> <code>false</code>.</li>\n<li>\n<p><code>importModuleDynamically</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function\" class=\"type\">&lt;Function&gt;</a> Called during evaluation of this module\nwhen <code>import()</code> is called. If this option is not specified, calls to\n<code>import()</code> will reject with <a href=\"errors.html#ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING\"><code>ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING</code></a>.\nThis option is part of the experimental API for the <code>--experimental-modules</code>\nflag, and should not be considered stable.</p>\n<ul>\n<li><code>specifier</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\">&lt;string&gt;</a> specifier passed to <code>import()</code></li>\n<li><code>module</code> <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a></li>\n<li>Returns: <a href=\"https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects\" class=\"type\">&lt;Module Namespace Object&gt;</a> | <a href=\"vm.html#vm_class_vm_module\" class=\"type\">&lt;vm.Module&gt;</a> Returning a <code>vm.Module</code> is\nrecommended in order to take advantage of error tracking, and to avoid\nissues with namespaces that contain <code>then</code> function exports.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>Returns: <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\">&lt;any&gt;</a> the result of the very last statement executed in the script.</li>\n</ul>\n<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('vm');\nlet localVar = 'initial value';\n\nconst vmResult = vm.runInThisContext('localVar = \"vm\";');\nconsole.log('vmResult:', vmResult);\nconsole.log('localVar:', localVar);\n\nconst evalResult = eval('localVar = \"eval\";');\nconsole.log('evalResult:', evalResult);\nconsole.log('localVar:', localVar);\n\n// vmResult: 'vm', localVar: 'initial value'\n// 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=\"#vm_script_runinthiscontext_options\"><code>script.runInThisContext()</code></a> or\n<a href=\"#vm_vm_runinthiscontext_code_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>http</code> module the code passed to\nthe context must either call <code>require('http')</code> on its own, or have a reference\nto the <code>http</code> module passed to it. For instance:</p>\n<pre><code class=\"language-js\">'use strict';\nconst vm = require('vm');\n\nconst code = `\n((require) => {\n  const http = require('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>",
          "type": "module",
          "displayName": "`vm.runInThisContext(code[, options])`"
        },
        {
          "textRaw": "What does it mean to \"contextify\" an object?",
          "name": "what_does_it_mean_to_\"contextify\"_an_object?",
          "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>vm</code> module's methods with an isolated global environment\nwithin which it can operate. The process of creating the V8 Context and\nassociating it with the <code>contextObject</code> is what this document refers to as\n\"contextifying\" the object.</p>",
          "type": "module",
          "displayName": "What does it mean to \"contextify\" an object?"
        },
        {
          "textRaw": "Timeout limitations when using `process.nextTick()`, Promises, and `queueMicrotask()`",
          "name": "timeout_limitations_when_using_`process.nexttick()`,_promises,_and_`queuemicrotask()`",
          "desc": "<p>Because of the internal mechanics of how the <code>process.nextTick()</code> queue and\nthe microtask queue that underlies Promises are implemented within V8 and\nNode.js, it is possible for code running within a context to \"escape\" the\n<code>timeout</code> set using <code>vm.runInContext()</code>, <code>vm.runInNewContext()</code>, and\n<code>vm.runInThisContext()</code>.</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('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 }\n);\n</code></pre>\n<p>This issue also occurs when the <code>loop()</code> call is scheduled using\nthe <code>process.nextTick()</code> and <code>queueMicrotask()</code> functions.</p>\n<p>This issue occurs because all contexts share the same microtask and nextTick\nqueues.</p>",
          "type": "module",
          "displayName": "Timeout limitations when using `process.nextTick()`, Promises, and `queueMicrotask()`"
        }
      ],
      "type": "module",
      "displayName": "vm"
    }
  ]
}