vm.compileFunction(code[, params[, options]])


版本历史
版本变更
v18.15.0

如果传递了 cachedData 选项,返回值现在包括与 vm.Script 版本具有相同语义的 cachedDataRejected

v17.0.0, v16.12.0

添加了对 importModuleDynamically 参数导入属性的支持。

v15.9.0

再次添加 importModuleDynamically 选项。

v14.3.0

由于兼容性问题删除 importModuleDynamically

v14.1.0, v13.14.0

现在支持 importModuleDynamically 选项。

v10.10.0

新增于: v10.10.0

  • code <string> 要编译的函数体。

    \code <string> The body of the function to compile.

  • params <string[]> 包含函数所有参数的字符串数组。

    \params <string[]> An array of strings containing all parameters for the function.

  • options <Object>

    • filename <string> 指定此脚本生成的堆栈跟踪中使用的文件名。默认值:''

      \filename <string> Specifies the filename used in stack traces produced by this script. Default: ''.

    • lineOffset <number> 指定在此脚本生成的堆栈跟踪中显示的行号偏移量。默认值:0

      \lineOffset <number> Specifies the line number offset that is displayed in stack traces produced by this script. Default: 0.

    • columnOffset <number> 指定在此脚本生成的堆栈跟踪中显示的第一行列号偏移量。默认值:0

      \columnOffset <number> Specifies the first-line column number offset that is displayed in stack traces produced by this script. Default: 0.

    • cachedData <Buffer> | <TypedArray> | <DataView> 为所提供的源提供可选的 BufferTypedArrayDataView,其中包含 V8 的代码缓存数据。这必须通过使用相同的 codeparams 预先调用 vm.compileFunction() 来生成。

      \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.

    • produceCachedData <boolean> 指定是否产生新的缓存数据。默认值:false

      \produceCachedData <boolean> Specifies whether to produce new cache data. Default: false.

    • parsingContext <Object> 应在其中编译所述函数的 contextified 对象。

      \parsingContext <Object> The contextified object in which the said function should be compiled in.

    • contextExtensions <Object[]> 包含要在编译时应用的上下文扩展集合(包含当前作用域的对象)的数组。默认值:[]

      \contextExtensions <Object[]> An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling. Default: [].

    • importModuleDynamically <Function> 在调用 import() 时在评估此模块期间调用。如果未指定此选项,则调用 import() 将使用 ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING 拒绝。此选项是实验模块 API 的一部分,不应被视为稳定的。如果未设置 --experimental-vm-modules,则该回调将被忽略,对 import() 的调用将被拒绝并返回 ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG

      \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.

  • 返回:<Function>

    \Returns: <Function>

将给定的代码编译到提供的上下文中(如果没有提供上下文,则使用当前上下文),并返回它封装在具有给定 params 的函数中。

\Compiles the given code into the provided context (if no context is supplied, the current context is used), and returns it wrapped inside a function with the given params.

AltStyle によって変換されたページ (->オリジナル) /