runInContext(code: string, context: Record<string | number | symbol, unknown>, opts?: { filename?: string offset?: number }): unknown
Run code inside context, a context previously created with createContext(), and return the result.
Parameters
Parameter
Type
Default
Description
code
string
—
The JavaScript source to run.
context
Record<string | number | symbol, unknown>
—
A context previously created with createContext().
opts?
{ filename?: string offset?: number }
—
Options. filename is the script name used in stack traces (default '<anonymous>'); offset shifts the reported line numbers (default 0, also accepted as lineOffset for Node.js compatibility).
runInNewContext(code: string, opts?: { filename?: string offset?: number }): unknown
Create a new context and run code inside it in one step, equivalent to calling createContext() followed by runInContext().
Parameters
Parameter
Type
Default
Description
code
string
—
The JavaScript source to run.
opts?
{ filename?: string offset?: number }
—
Options. filename is the script name used in stack traces (default '<anonymous>'); offset shifts the reported line numbers (default 0, also accepted as lineOffset for Node.js compatibility).