Package-level declarations

Types

Link copied to clipboard
sealed external interface BaseOptions
Link copied to clipboard
sealed external interface CompileFunctionOptions : BaseOptions
Link copied to clipboard
sealed external interface CompileFunctionResult : JsContextFunction<Void?, Nothing, Any?>
Link copied to clipboard
sealed external interface Context : Record<String, Any?>
Link copied to clipboard
sealed external interface CreateContextOptions
Link copied to clipboard
sealed external interface CreateContextOptionsCodeGeneration
Link copied to clipboard
sealed external interface MeasureMemoryMode
Link copied to clipboard
sealed external interface MeasureMemoryOptions
Link copied to clipboard
sealed external interface MeasureMemoryOptionsExecution
Link copied to clipboard
sealed external interface MemoryMeasurement
Link copied to clipboard
sealed external interface MemoryMeasurementTotal
Link copied to clipboard
open external class Module

This feature is only available with the --experimental-vm-modules command flag enabled.

Link copied to clipboard
sealed external interface ModuleEvaluateOptions
Link copied to clipboard
typealias ModuleLinker = (specifier: String, referencingModule: Module, extra: ModuleLinkerExtra) -> PromiseResult<Module>
Link copied to clipboard
sealed external interface ModuleLinkerExtra
Link copied to clipboard
sealed external interface ModuleStatus
Link copied to clipboard
sealed external interface RunningCodeOptions : RunningScriptOptions
Link copied to clipboard
Link copied to clipboard
sealed external interface RunningScriptOptions : BaseOptions
Link copied to clipboard
external class Script

Instances of the vm.Script class contain precompiled scripts that can be executed in specific contexts.

Link copied to clipboard
sealed external interface ScriptOptions : BaseOptions
Link copied to clipboard
external class SourceTextModule : Module

This feature is only available with the --experimental-vm-modules command flag enabled.

Link copied to clipboard
sealed external interface SourceTextModuleOptions
Link copied to clipboard
external class SyntheticModule : Module

This feature is only available with the --experimental-vm-modules command flag enabled.

Link copied to clipboard
sealed external interface SyntheticModuleOptions

Functions

Link copied to clipboard
external fun compileFunction(code: String, params: ReadonlyArray<String> = definedExternally, options: CompileFunctionOptions = definedExternally): CompileFunctionResult

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.

Link copied to clipboard
external fun createContext(sandbox: Context = definedExternally, options: CreateContextOptions = definedExternally): Context

If given a contextObject, the vm.createContext() method will prepare that object and return a reference to it so that it can be used in {@link runInContext} or script.runInContext(). Inside such scripts, the contextObject will be the global object, retaining all of its existing properties but also having the built-in objects and functions any standard global object has. Outside of scripts run by the vm module, global variables will remain unchanged.

Link copied to clipboard
external fun isContext(sandbox: Context): Boolean

Returns true if the given object object has been contextified using {@link createContext}.

Link copied to clipboard
suspend fun measureMemory(options: MeasureMemoryOptions = undefined.unsafeCast<Nothing>()): MemoryMeasurement
Link copied to clipboard
external fun measureMemoryAsync(options: MeasureMemoryOptions = definedExternally): Promise<MemoryMeasurement>

Measure the memory known to V8 and used by all contexts known to the current V8 isolate, or the main context.

Link copied to clipboard
external fun runInContext(code: String, contextifiedObject: Context): Any?
external fun runInContext(code: String, contextifiedObject: Context, options: String = definedExternally): Any?
external fun runInContext(code: String, contextifiedObject: Context, options: RunningCodeOptions = definedExternally): Any?

The vm.runInContext() method compiles code, runs it within the context of the contextifiedObject, then returns the result. Running code does not have access to the local scope. The contextifiedObject object must have been previously contextified using the {@link createContext} method.

Link copied to clipboard
external fun runInNewContext(code: String, contextObject: Context = definedExternally, options: String = definedExternally): Any?
external fun runInNewContext(code: String, contextObject: Context = definedExternally, options: RunningCodeInNewContextOptions = definedExternally): Any?

The vm.runInNewContext() first contextifies the given contextObject (or creates a new contextObject if passed as undefined), compiles the code, runs it within the created context, then returns the result. Running code does not have access to the local scope.

Link copied to clipboard
external fun runInThisContext(code: String): Any?
external fun runInThisContext(code: String, options: String = definedExternally): Any?
external fun runInThisContext(code: String, options: RunningCodeOptions = definedExternally): Any?

vm.runInThisContext() compiles code, runs it within the context of the current global and returns the result. Running code does not have access to local scope, but does have access to the current global object.