/** * The `vm` module enables compiling and running code within V8 Virtual * Machine contexts. * * **The `vm` module is not a security** * **mechanism. Do not use it to run untrusted code.** * * JavaScript code can be compiled and run immediately or * compiled, saved, and run later. * * A common use case is to run the code in a different V8 Context. This means * invoked code has a different global object than the invoking code. * * One can provide the context by `contextifying` an * object. The invoked code treats any property in the context like a * global variable. Any changes to global variables caused by the invoked * code are reflected in the context object. * * ```js * import vm from 'node:vm'; * * const x = 1; * * const context = { x: 2 }; * vm.createContext(context); // Contextify the object. * * const code = 'x += 40; var y = 17;'; * // `x` and `y` are global variables in the context. * // Initially, x has the value 2 because that is the value of context.x. * vm.runInContext(code, context); * * console.log(context.x); // 42 * console.log(context.y); // 17 * * console.log(x); // 1; y is not defined. * ``` * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/vm.js) */ declare module "vm" { import { ImportAttributes } from "node:module"; interface Context extends NodeJS.Dict {} interface BaseOptions { /** * Specifies the filename used in stack traces produced by this script. * Default: `''`. */ filename?: string | undefined; /** * Specifies the line number offset that is displayed in stack traces produced by this script. * Default: `0`. */ lineOffset?: number | undefined; /** * Specifies the column number offset that is displayed in stack traces produced by this script. * @default 0 */ columnOffset?: number | undefined; } type DynamicModuleLoader = ( specifier: string, referrer: T, importAttributes: ImportAttributes, ) => Module | Promise; interface ScriptOptions extends BaseOptions { /** * Provides an optional data with V8's code cache data for the supplied source. */ cachedData?: Buffer | NodeJS.ArrayBufferView | undefined; /** @deprecated in favor of `script.createCachedData()` */ produceCachedData?: boolean | undefined; /** * 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`. */ importModuleDynamically?: DynamicModuleLoader