vm.compileFunction(code[, params[, options]])
code<string> 要编译的函数体。params<string[]> 包含函数所有参数的字符串数组。options<Object>filename<string> 指定此脚本生成的堆栈跟踪中使用的文件名。 默认值:''。lineOffset<number> 指定在此脚本生成的堆栈跟踪中显示的行号偏移量。 默认值:0。columnOffset<number> 指定在此脚本生成的堆栈跟踪中显示的第一行列号偏移量。 默认值:0。cachedData<Buffer> | <TypedArray> | <DataView> 为所提供的源提供可选的Buffer或TypedArray或DataView,其中包含 V8 的代码缓存数据。produceCachedData<boolean> 指定是否产生新的缓存数据。 默认值:false。parsingContext<Object> 应在其中编译所述函数的上下文隔离化的对象。contextExtensions<Object[]> 包含要在编译时应用的上下文扩展集合(包含当前作用域的对象)的数组。 默认值:[]。importModuleDynamically<Function> 在调用import()时在评估此模块期间调用。 如果未指定此选项,则调用import()将使用ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING拒绝。 此选项是实验模块 API 的一部分,不应被视为稳定的。specifier<string> 传给import()的说明符function<Function>importAssertions<Object> 传给optionsExpression可选参数的"assert"值,如果没有提供值,则为空对象。- 返回: <Module Namespace Object> | <vm.Module> 建议返回
vm.Module以利用错误跟踪,并避免包含then函数导出的命名空间出现问题。
- 返回: <Function>
将给定的代码编译到提供的上下文中(如果没有提供上下文,则使用当前上下文),并返回它包装在具有给定 params 的函数中。
code<string> The body of the function to compile.params<string[]> An array of strings containing all parameters for the function.options<Object>filename<string> Specifies the filename used in stack traces produced by this script. Default:''.lineOffset<number> Specifies the line number offset that is displayed in stack traces produced by this script. Default: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> Provides an optionalBufferorTypedArray, orDataViewwith V8's code cache data for the supplied source.produceCachedData<boolean> Specifies whether to produce new cache data. Default:false.parsingContext<Object> The contextified object in which the said function should be compiled in.contextExtensions<Object[]> An array containing a collection of context extensions (objects wrapping the current scope) to be applied while compiling. Default:[].importModuleDynamically<Function> Called during evaluation of this module whenimport()is called. If this option is not specified, calls toimport()will reject withERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING. This option is part of the experimental modules API, and should not be considered stable.specifier<string> specifier passed toimport()function<Function>importAssertions<Object> The"assert"value passed to theoptionsExpressionoptional parameter, or an empty object if no value was provided.- Returns: <Module Namespace Object> | <vm.Module> Returning a
vm.Moduleis recommended in order to take advantage of error tracking, and to avoid issues with namespaces that containthenfunction exports.
- Returns: <Function>
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.