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


版本历史
版本变更
v21.7.0, v20.12.0

Added support for vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER.

v19.6.0, v18.15.0

The return value now includes cachedDataRejected with the same semantics as the vm.Script version if the cachedData option was passed.

v17.0.0, v16.12.0

Added support for import attributes to the importModuleDynamically parameter.

v15.9.0

Added importModuleDynamically option again.

v14.3.0

Removal of importModuleDynamically due to compatibility issues.

v14.1.0, v13.14.0

The importModuleDynamically option is now supported.

v10.10.0

新增于: v10.10.0

  • code <string> 要编译的函数体。
  • params <string[]> 包含函数所有参数的字符串数组。
  • options <Object>
    • filename <string> 指定此脚本生成的堆栈跟踪中使用的文件名。默认值: ''
    • lineOffset <number> 指定此脚本生成的堆栈跟踪中显示的行号偏移。默认值:0
    • columnOffset <number> 指定此脚本生成的堆栈跟踪中显示的第一行列号偏移。默认值:0
    • cachedData <Buffer> | <TypedArray> | <DataView> 为所提供的源代码提供可选的 BufferTypedArray,或包含 V8 代码缓存数据的 DataView。这必须由之前使用相同 codeparams 调用 vm.compileFunction() 生成。
    • produceCachedData <boolean> 指定是否生成新的缓存数据。 默认值: false
    • parsingContext <Object> 应在其中编译上述函数的 情境化 对象。
    • contextExtensions <Object[]> 一个包含上下文扩展集合的数组(封装当前作用域的对象),将在编译时应用。默认值: []
    • importModuleDynamically <Function> | <vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER> 用于指定在调用 import() 时评估此函数期间模块应如何加载。此选项是实验性模块 API 的一部分。我们不建议在生产环境中使用它。有关详细信息,请参阅 在编译 API 中支持动态 import()
  • 返回:<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 によって変換されたページ (->オリジナル) /