M
vm.compileFunction
History
Added in: v10.10.0
v10.10.0
Introduced in: v0.10.0
v0.10.0
Added support for
vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER.v21.7.0, v20.12.0
The return value now includes
cachedDataRejected with the same semantics as the vm.Script version if the cachedData option was passed.v19.6.0, v18.15.0
Added support for import attributes to the
importModuleDynamically parameter.v17.0.0, v16.12.0
Added
importModuleDynamically option again.v15.9.0
Removal of
importModuleDynamically due to compatibility issues.v14.3.0
The
importModuleDynamically option is now supported.v14.1.0, v13.14.0
vm.compileFunction(code, params?, options?): Function
Attributes
code:
stringThe body of the function to compile.
params:
string[]An array of strings containing all parameters for the
function.
options:
Objectfilename?:
stringSpecifies the filename used in stack traces produced
by this script. Default:
''.lineOffset?:
numberSpecifies the line number offset that is displayed
in stack traces produced by this script. Default:
0.columnOffset?:
numberSpecifies the first-line column number offset that
is displayed in stack traces produced by this script. Default:
0.cachedData:
Buffer | TypedArray | DataViewProvides 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?:
booleanSpecifies whether to produce new cache data.
Default:
false.parsingContext:
ObjectThe 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 | vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADERUsed to specify the how the modules should be loaded during the evaluation of
this function when
import() is called. This option is part of the
experimental modules API. We do not recommend using it in a production
environment. For detailed information, see
Support of dynamic import() in compilation APIs.Returns:
FunctionCompiles 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.