Skip to Content
V8-wasm
API Reference

V8 Isolates, Contexts & Platform

V8 initialization, Isolate, Context, MicrotaskQueue, Platform, TaskRunner, StartupData, SnapshotCreator, and SharedHandle types

Generated TypeScript bindings for V8 process initialization, Isolate, Context, MicrotaskQueue, platform task runners, startup snapshots, and reference-counted SharedHandle wrappers.

Contains 44 classes and 191 bound methods. Inherited WasmHandle base methods (ptr, isNull(), as()) are documented on Core Runtime & Realms.

Allocator

class Allocator extends WasmHandle

An allocator interface for managing memory explicitly.

Implementations of this interface must be thread-safe as V8 will invoke these methods concurrently from multiple threads.

Upstream C++: v8::Allocator (v8-platform.h)

Methods

  • allocate(size: number): number

    Allocates zero-initialized memory.

    • size: The number of bytes to allocate. Returns: Pointer to the allocated memory or null on failure.

    Upstream C++: v8::Allocator::Allocate

  • allocateUninitialized(size: number): number

    Allocates uninitialized memory.

    • size: The number of bytes to allocate. Returns: Pointer to the allocated memory or null on failure.

    Upstream C++: v8::Allocator::AllocateUninitialized

  • allocateUninitializedOrCrash(size: number): number

    Allocates uninitialized memory.

    • size: The number of bytes to allocate. Returns: Pointer to the allocated memory. Crashes on failure (e.g. OOM). This is intended for critical allocations where failure means the process cannot continue.

    Upstream C++: v8::Allocator::AllocateUninitializedOrCrash

  • free(ptr_: number): void

    Frees memory that was acquired with one of the allocation methods.

    • ptr: Pointer to the memory to free. If ptr is null, no operation is performed.

    Upstream C++: v8::Allocator::Free

api_internalIndirectHandleBase

class api_internalIndirectHandleBase extends WasmHandle

A base class for abstract handles containing indirect pointers. These are useful regardless of whether direct local support is enabled.

Upstream C++: v8::api_internal::IndirectHandleBase (v8-handle-base.h)

Methods

  • clear(): void

    Sets the handle to be empty. IsEmpty() will then return true.

    Upstream C++: v8::api_internal::IndirectHandleBase::Clear

  • isEmpty(): boolean

    Returns true if the handle is empty.

    Upstream C++: v8::api_internal::IndirectHandleBase::IsEmpty

ArrayBufferAllocatorShared

class ArrayBufferAllocatorShared extends SharedHandle

Reference-counted std.shared_ptr<ArrayBuffer.Allocator> wrapper for custom V8 ArrayBuffer allocators. Call dispose() or use using when done.

BackingStoreShared

class BackingStoreShared extends SharedHandle

Reference-counted std.shared_ptr<BackingStore> wrapper for V8 ArrayBuffer / SharedArrayBuffer backing stores. Call dispose() or use using when done.

Context

class Context extends Data

A sandboxed execution context with its own set of built-in objects and functions.

Upstream C++: v8::Context (v8-context.h)

Static Methods

  • static fromPtr(ptr: number): Context

    Wraps a raw V8-wasm handle pointer as a Context.

  • static newRemoteContext(isolate: Isolate, global_template: ObjectTemplate, global_object: MaybeLocal<Value>): MaybeLocal<V8Object>

    Returns an global object that isn't backed by an actual context.

    The global template needs to have access checks with handlers installed. If an existing global object is passed in, the global object is detached from its context.

    Note that this is different from a detached context where all accesses to the global proxy will fail. Instead, the access check handlers are invoked.

    It is also not possible to detach an object returned by this method. Instead, the access check handlers need to return nothing to achieve the same effect.

    It is possible, however, to create a new context from the global object returned by this method.

    Upstream C++: v8::Context::NewRemoteContext

Methods

  • allowCodeGenerationFromStrings(allow: boolean): void

    Control whether code generation from strings is allowed. Calling this method with false will disable 'eval' and the 'Function' constructor for code running in this context. If 'eval' or the 'Function' constructor are used an exception will be thrown.

    If code generation from strings is not allowed the V8.ModifyCodeGenerationFromStringsCallback callback will be invoked if set before blocking the call to 'eval' or the 'Function' constructor. If that callback returns true, the call will be allowed, otherwise an exception will be thrown. If no callback is set an exception will be thrown.

    Upstream C++: v8::Context::AllowCodeGenerationFromStrings

  • deepFreeze(delegate?: ContextDeepFreezeDelegate): boolean

    Attempts to recursively freeze all objects reachable from this context. Some objects (generators, iterators, non-const closures) can not be frozen and will cause this method to throw an error. An optional delegate can be provided to help freeze embedder-specific objects.

    Freezing occurs in two steps:

    1. "Marking" where we iterate through all objects reachable by this context, accumulating a list of objects that need to be frozen and looking for objects that can't be frozen. This step is separated because it is more efficient when we can assume there is no garbage collection.
    2. "Freezing" where we go through the list of objects and freezing them. This effectively requires copying them so it may trigger garbage collection.

    Upstream C++: v8::Context::DeepFreeze

  • detachGlobal(): void

    Detaches the global object from its context before the global object can be reused to create a new context.

    Upstream C++: v8::Context::DetachGlobal

  • enter(): void

    Enter this context. After entering a context, all code compiled and run is compiled and run in this context. If another context is already entered, this old context is saved so it can be restored when the new context is exited.

    Upstream C++: v8::Context::Enter

  • exit(): void

    Exit this context. Exiting the current context restores the context that was in place when entering the current context.

    Upstream C++: v8::Context::Exit

  • getAlignedPointerFromEmbedderData(isolate: Isolate, index: number, tag: number): number

    Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have been set by a previous call to SetAlignedPointerInEmbedderData with the same index. Note that index 0 currently has a special meaning for Chrome's debugger.

    Upstream C++: v8::Context::GetAlignedPointerFromEmbedderData

  • getAlignedPointerFromEmbedderData2(index: number, tag: number): number

    Gets a 2-byte-aligned native pointer from the embedder data with the given index, which must have been set by a previous call to SetAlignedPointerInEmbedderData with the same index. Note that index 0 currently has a special meaning for Chrome's debugger.

    Upstream C++: v8::Context::GetAlignedPointerFromEmbedderData

  • getEmbedderData(index: number): Value

    Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedderData with the same index.

    Upstream C++: v8::Context::GetEmbedderData

  • getEmbedderDataV2(index: number): Data

    Gets the embedder data with the given index, which must have been set by a previous call to SetEmbedderData with the same index.

    Upstream C++: v8::Context::GetEmbedderDataV2

  • getExtrasBindingObject(): V8Object

    Gets the binding object used by V8 extras. Extra natives get a reference to this object and can use it to "export" functionality by adding properties. Extra natives can also "import" functionality by accessing properties added by the embedder using the V8 API.

    Upstream C++: v8::Context::GetExtrasBindingObject

  • getMicrotaskQueue(): MicrotaskQueue | null

    Returns the microtask queue associated with a current context.

    Upstream C++: v8::Context::GetMicrotaskQueue

  • getNumberOfEmbedderDataFields(): number

    Return the number of fields allocated for embedder data.

    Upstream C++: v8::Context::GetNumberOfEmbedderDataFields

  • getSecurityToken(): Value

    Returns the security token of this context.

    Upstream C++: v8::Context::GetSecurityToken

  • global(): V8Object

    Returns the global proxy object.

    Global proxy object is a thin wrapper whose prototype points to actual context's global object with the properties like Object, etc. This is done that way for security reasons (for more details see https://wiki.mozilla.org/Gecko:SplitWindow).

    Please note that changes to global proxy object prototype most probably would break VM---v8 expects only global object as a prototype of global proxy object.

    Upstream C++: v8::Context::Global

  • hasTemplateLiteralObject(object: Value): boolean

    Binds upstream V8 C++ v8::Context::HasTemplateLiteralObject.

  • isCodeGenerationFromStringsAllowed(): boolean

    Returns true if code generation from strings is allowed for the context. For more details see AllowCodeGenerationFromStrings(bool) documentation.

    Upstream C++: v8::Context::IsCodeGenerationFromStringsAllowed

  • setAlignedPointerInEmbedderData(index: number, value: number, tag: number): void

    Binds upstream V8 C++ v8::Context::SetAlignedPointerInEmbedderData.

  • setEmbedderData(index: number, value: Value): void

    Sets the embedder data with the given index, growing the data as needed. Note that index 0 currently has a special meaning for Chrome's debugger.

    Upstream C++: v8::Context::SetEmbedderData

  • setEmbedderDataV2(index: number, value: Data): void

    Sets the embedder data with the given index, growing the data as needed. Note that index 0 currently has a special meaning for Chrome's debugger.

    Upstream C++: v8::Context::SetEmbedderDataV2

  • setErrorMessageForCodeGenerationFromStrings(message: V8String): void

    Sets the error description for the exception that is thrown when code generation from strings is not allowed and 'eval' or the 'Function' constructor are called.

    Upstream C++: v8::Context::SetErrorMessageForCodeGenerationFromStrings

  • setErrorMessageForWasmCodeGeneration(message: V8String): void

    Sets the error description for the exception that is thrown when wasm code generation is not allowed.

    Upstream C++: v8::Context::SetErrorMessageForWasmCodeGeneration

  • setMicrotaskQueue(queue: MicrotaskQueue): void

    Sets the microtask queue associated with the current context.

    Upstream C++: v8::Context::SetMicrotaskQueue

  • setPromiseHooks(init_hook: V8Function, before_hook: V8Function, after_hook: V8Function, resolve_hook: V8Function): void

    Set or clear hooks to be invoked for promise lifecycle operations. To clear a hook, set it to an empty Function. Each function will receive the observed promise as the first argument. If a chaining operation is used on a promise, the init will additionally receive the parent promise as the second argument.

    Upstream C++: v8::Context::SetPromiseHooks

  • setSecurityToken(token: Value): void

    Sets the security token for the context. To access an object in another context, the security tokens must match.

    Upstream C++: v8::Context::SetSecurityToken

  • useDefaultSecurityToken(): void

    Restores the security token to the default value.

    Upstream C++: v8::Context::UseDefaultSecurityToken

ContextBackupIncumbentScope

class ContextBackupIncumbentScope extends WasmHandle

Stack-allocated class to support the backup incumbent settings object stack. https://html.spec.whatwg.org/multipage/webappapis.html#backup-incumbent-settings-object-stack

Upstream C++: v8::Context::BackupIncumbentScope (v8-context.h)

ContextDeepFreezeDelegate

class ContextDeepFreezeDelegate extends WasmHandle

Delegate to help with Deep freezing embedder-specific objects (such as JSApiObjects) that can not be frozen natively.

Upstream C++: v8::Context::DeepFreezeDelegate (v8-context.h)

ConvertableToTraceFormat

class ConvertableToTraceFormat extends WasmHandle

The interface represents complex arguments to trace events.

Upstream C++: v8::ConvertableToTraceFormat (v8-platform.h)

DeserializeAPIWrapperCallback

class DeserializeAPIWrapperCallback extends WasmHandle

Upstream V8 C++ struct v8::DeserializeAPIWrapperCallback (v8-snapshot.h).

DeserializeContextDataCallback

class DeserializeContextDataCallback extends WasmHandle

Similar to DeserializeInternalFieldsCallback, but works with the embedder data in a Context.

Upstream C++: v8::DeserializeContextDataCallback (v8-snapshot.h)

DeserializeInternalFieldsCallback

class DeserializeInternalFieldsCallback extends WasmHandle

Callback and supporting data used to implement embedder logic to deserialize internal fields of Objects.

Upstream C++: v8::DeserializeInternalFieldsCallback (v8-snapshot.h)

EmbedderRootsHandler

class EmbedderRootsHandler extends WasmHandle

Handler for embedder roots on non-unified heap garbage collections.

Upstream C++: v8::EmbedderRootsHandler (v8-embedder-heap.h)

EmbedderStateScope

class EmbedderStateScope extends WasmHandle

A stack-allocated class that manages an embedder state on the isolate. After an EmbedderState scope has been created, a new embedder state will be pushed on the isolate stack.

Upstream C++: v8::EmbedderStateScope (v8-embedder-state-scope.h)

EscapableHandleScopeBase

class EscapableHandleScopeBase extends WasmHandle

A HandleScope which first allocates a handle in the current scope which will be later filled with the escape value.

Upstream C++: v8::EscapableHandleScopeBase (v8-local-handle.h)

ExtensionConfiguration

class ExtensionConfiguration extends WasmHandle

A container for extension names.

Upstream C++: v8::ExtensionConfiguration (v8-context.h)

HighAllocationThroughputObserver

class HighAllocationThroughputObserver extends WasmHandle

Observer used by V8 to notify the embedder about entering/leaving sections with high throughput of malloc/free operations.

Upstream C++: v8::HighAllocationThroughputObserver (v8-platform.h)

Methods

  • enterSection(): void

    Binds upstream V8 C++ v8::HighAllocationThroughputObserver::EnterSection.

  • leaveSection(): void

    Binds upstream V8 C++ v8::HighAllocationThroughputObserver::LeaveSection.

IdleTask

class IdleTask extends WasmHandle

An IdleTask represents a unit of work to be performed in idle time. The Run method is invoked with an argument that specifies the deadline in seconds returned by MonotonicallyIncreasingTime(). The idle task is expected to complete by this deadline.

Upstream C++: v8::IdleTask (v8-platform.h)

Methods

  • run(deadline_in_seconds: number): void

    Binds upstream V8 C++ v8::IdleTask::Run.

Isolate

class Isolate extends WasmHandle

Isolate represents an isolated instance of the V8 engine. V8 isolates have completely separate states. Objects from one isolate must not be used in other isolates. The embedder can create multiple isolates and use them in parallel in multiple threads. An isolate can be entered by at most one thread at any given time. The Locker/Unlocker API must be used to synchronize.

Upstream C++: v8::Isolate (v8-isolate.h)

Static Methods

  • static allocate(): Isolate | null

    Allocates a new isolate but does not initialize it. Does not change the currently entered isolate.

    Only Isolate.GetData() and Isolate.SetData(), which access the embedder-controlled parts of the isolate, as well as Isolate.GetGroup(), are allowed to be called on the uninitialized isolate. To initialize the isolate, call Isolate.Initialize() or initialize a SnapshotCreator.

    When an isolate is no longer used its resources should be freed by calling Dispose(). Using the delete operator is not allowed.

    V8.Initialize() must have run prior to this.

    Upstream C++: v8::Isolate::Allocate

  • static allocate2(group: IsolateGroup): Isolate | null

    Allocates a new isolate but does not initialize it. Does not change the currently entered isolate.

    Only Isolate.GetData() and Isolate.SetData(), which access the embedder-controlled parts of the isolate, as well as Isolate.GetGroup(), are allowed to be called on the uninitialized isolate. To initialize the isolate, call Isolate.Initialize() or initialize a SnapshotCreator.

    When an isolate is no longer used its resources should be freed by calling Dispose(). Using the delete operator is not allowed.

    V8.Initialize() must have run prior to this.

    Upstream C++: v8::Isolate::Allocate

  • static free(isolate: Isolate): void

    Frees the memory allocated for the isolate. Can only be called after the Isolate has already been deinitialized with Isolate.Deinitialize(). After the isolate is freed, the next call to Isolate.New() or Isolate.Allocate() might return the same address that just get freed.

    Upstream C++: v8::Isolate::Free

  • static getCurrent(): Isolate | null

    Returns the entered isolate for the current thread or null in case there is no current isolate.

    This method must not be invoked before V8.Initialize() was invoked.

    Upstream C++: v8::Isolate::GetCurrent

  • static getNumberOfDataSlots(): number

    Returns the maximum number of available embedder data slots. Valid slots are in the range of 0 - GetNumberOfDataSlots() - 1.

    Upstream C++: v8::Isolate::GetNumberOfDataSlots

  • static initialize(isolate: Isolate, params: IsolateCreateParams): void

    Initialize an Isolate previously allocated by Isolate.Allocate().

    Upstream C++: v8::Isolate::Initialize

  • static new(params: IsolateCreateParams): Isolate | null

    Creates a new isolate. Does not change the currently entered isolate.

    When an isolate is no longer used its resources should be freed by calling Dispose(). Using the delete operator is not allowed.

    V8.Initialize() must have run prior to this.

    Upstream C++: v8::Isolate::New

  • static new2(group: IsolateGroup, params: IsolateCreateParams): Isolate | null

    Creates a new isolate. Does not change the currently entered isolate.

    When an isolate is no longer used its resources should be freed by calling Dispose(). Using the delete operator is not allowed.

    V8.Initialize() must have run prior to this.

    Upstream C++: v8::Isolate::New

  • static tryGetCurrent(): Isolate | null

    Returns the entered isolate for the current thread or null in case there is no current isolate.

    No checks are performed by this method.

    Upstream C++: v8::Isolate::TryGetCurrent

Methods

  • adjustAmountOfExternalAllocatedMemory(change_in_bytes: bigint): bigint

    Adjusts the amount of registered external memory.

    • change_in_bytes: the change in externally allocated memory that is kept alive by JavaScript objects. Returns: the adjusted value.

    Upstream C++: v8::Isolate::AdjustAmountOfExternalAllocatedMemory

  • automaticallyRestoreInitialHeapLimit(threshold_percent: number): void

    If the heap limit was changed by the NearHeapLimitCallback, then the initial heap limit will be restored once the heap size falls below the given threshold percentage of the initial heap limit. The threshold percentage is a number in (0.0, 1.0) range.

    Upstream C++: v8::Isolate::AutomaticallyRestoreInitialHeapLimit

  • cancelTerminateExecution(): void

    Resume execution capability in the given isolate, whose execution was previously forcefully terminated using TerminateExecution().

    When execution is forcefully terminated using TerminateExecution(), the isolate can not resume execution until all JavaScript frames have propagated the uncatchable exception which is generated. This method allows the program embedding the engine to handle the termination event and resume execution capability, even if JavaScript frames remain on the stack.

    This method can be used by any thread even if that thread has not acquired the V8 lock with a Locker object.

    Upstream C++: v8::Isolate::CancelTerminateExecution

  • clearCachesForTesting(): void

    Drop non-essential caches. Should only be called from testing code. The method can potentially block for a long time and does not necessarily trigger GC.

    Upstream C++: v8::Isolate::ClearCachesForTesting

  • clearKeptObjects(): void

    Clears the set of objects held strongly by the heap. This set of objects are originally built when a WeakRef is created or successfully dereferenced.

    This is invoked automatically after microtasks are run. See MicrotasksPolicy for when microtasks are run.

    This needs to be manually invoked only if the embedder is manually running microtasks via a custom MicrotaskQueue class's PerformCheckpoint. In that case, it is the embedder's responsibility to make this call at a time which does not interrupt synchronous ECMAScript code execution.

    Upstream C++: v8::Isolate::ClearKeptObjects

  • contextDisposedNotification(dependant_context: boolean): number

    Optional notification that a context has been disposed. V8 uses these notifications to guide the GC heuristic and cancel FinalizationRegistry cleanup tasks. Returns the number of context disposals - including this one

    • since the last time V8 had a chance to clean up.

    The optional parameter dependant_context specifies whether the disposed context was depending on state from other contexts or not.

    Upstream C++: v8::Isolate::ContextDisposedNotification

  • contextDisposedNotification2(dependants: ContextDependants): void

    Optional notification that a context has been disposed. V8 uses these notifications to guide heuristics on e.g. GC or compilers.

    • dependants: A signal on whether this context possibly had any dependants.

    Upstream C++: v8::Isolate::ContextDisposedNotification

  • dateTimeConfigurationChangeNotification(time_zone_detection: IsolateTimeZoneDetection): void

    Notification that the embedder has changed the time zone, daylight savings time or other date / time configuration parameters. V8 keeps a cache of various values used for date / time computation. This notification will reset those cached values for the current context so that date / time configuration changes would be reflected.

    This API should not be called more than needed as it will negatively impact the performance of date operations.

    Upstream C++: v8::Isolate::DateTimeConfigurationChangeNotification

  • deinitialize(): void

    Deinitializes the isolate, but does not free the address. The isolate must not be entered by any thread to be deinitializable. Embedders must call Isolate.Free() to free the isolate afterwards.

    Upstream C++: v8::Isolate::Deinitialize

  • discardThreadSpecificMetadata(): void

    Discards all V8 thread-specific data for the Isolate. Should be used if a thread is terminating and it has used an Isolate that will outlive the thread -- all thread-specific data for an Isolate is discarded when an Isolate is disposed so this call is pointless if an Isolate is about to be Disposed.

    Upstream C++: v8::Isolate::DiscardThreadSpecificMetadata

  • dispose(): void

    Deinitializes and frees the isolate. The isolate must not be entered by any thread to be disposable.

    Upstream C++: v8::Isolate::Dispose

  • dumpAndResetStats(): void

    Dumps activated low-level V8 internal stats. This can be used instead of performing a full isolate disposal.

    Upstream C++: v8::Isolate::DumpAndResetStats

  • enqueueMicrotask(microtask: V8Function): void

    Enqueues the callback to the default MicrotaskQueue

    Upstream C++: v8::Isolate::EnqueueMicrotask

  • enter(): void

    Sets this isolate as the entered one for the current thread. Saves the previously entered one (if any), so that it can be restored when exiting. Re-entering an isolate is allowed.

    Upstream C++: v8::Isolate::Enter

  • exit(): void

    Exits this isolate by restoring the previously entered one in the current thread. The isolate may still stay the same, if it was entered more than once.

    Requires: this == Isolate.GetCurrent().

    Upstream C++: v8::Isolate::Exit

  • freeze(is_frozen: boolean): void

    Optional notification to tell V8 whether the embedder is currently frozen. V8 uses these notifications to guide heuristics. This is an unfinished experimental feature. Semantics and implementation may change frequently.

    Upstream C++: v8::Isolate::Freeze

  • getArrayBufferAllocator(): ArrayBufferAllocator | null

    Returns the ArrayBuffer.Allocator used in this isolate.

    Upstream C++: v8::Isolate::GetArrayBufferAllocator

  • getContinuationPreservedEmbedderData(): Data

    Returns the value set by SetContinuationPreservedEmbedderData() or restored during microtask execution for the currently running continuation, if any. Returns undefiend if no continuation preserved embedder data was set.

    Upstream C++: v8::Isolate::GetContinuationPreservedEmbedderData

  • getContinuationPreservedEmbedderDataV2(): Data

    Returns the value set by SetContinuationPreservedEmbedderDataV2() or restored during microtask execution for the currently running continuation, if any. Returns undefiend if no continuation preserved embedder data was set.

    Upstream C++: v8::Isolate::GetContinuationPreservedEmbedderDataV2

  • getCurrentContext(): Context

    Returns the context of the currently running JavaScript, or the context on the top of the stack if no JavaScript is running.

    Upstream C++: v8::Isolate::GetCurrentContext

  • getCurrentHostDefinedOptions(): MaybeLocal<Data>

    Returns the host defined options set for currently running script or module, if available.

    Upstream C++: v8::Isolate::GetCurrentHostDefinedOptions

  • getData(slot: number): number

    Retrieve embedder-specific data from the isolate. Returns null if SetData has never been called for the given slot.

    Upstream C++: v8::Isolate::GetData

  • getEnteredOrMicrotaskContext(): Context

    Returns either the last context entered through V8's C++ API, or the context of the currently running microtask while processing microtasks. If a context is entered while executing a microtask, that context is returned.

    Upstream C++: v8::Isolate::GetEnteredOrMicrotaskContext

  • getHashSeed(): bigint

    Returns the hash seed for that isolate, for testing purposes.

    Upstream C++: v8::Isolate::GetHashSeed

  • getHeapCodeAndMetadataStatistics(object_statistics: HeapCodeStatistics): boolean

    Get statistics about code and its metadata in the heap.

    • object_statistics: The HeapCodeStatistics object to fill in statistics of code, bytecode and their metadata. Returns: true on success.

    Upstream C++: v8::Isolate::GetHeapCodeAndMetadataStatistics

  • getHeapObjectStatisticsAtLastGC(object_statistics: HeapObjectStatistics, type_index: number): boolean

    Get statistics about objects in the heap.

    • object_statistics: The HeapObjectStatistics object to fill in statistics of objects of given type, which were live in the previous GC.
    • type_index: The index of the type of object to fill details about, which ranges from 0 to NumberOfTrackedHeapObjectTypes() - 1. Returns: true on success.

    Upstream C++: v8::Isolate::GetHeapObjectStatisticsAtLastGC

  • getHeapProfiler(): HeapProfiler | null

    Returns heap profiler for this isolate. Will return null until the isolate is initialized.

    Upstream C++: v8::Isolate::GetHeapProfiler

  • getHeapSpaceStatistics(space_statistics: HeapSpaceStatistics, index: number): boolean

    Get the memory usage of a space in the heap.

    • space_statistics: The HeapSpaceStatistics object to fill in statistics.
    • index: The index of the space to get statistics from, which ranges from 0 to NumberOfHeapSpaces() - 1. Returns: true on success.

    Upstream C++: v8::Isolate::GetHeapSpaceStatistics

  • getHeapStatistics(heap_statistics: HeapStatistics): void

    Get statistics about the heap memory usage.

    Upstream C++: v8::Isolate::GetHeapStatistics

  • getIncumbentContext(): Context

    Returns the Context that corresponds to the Incumbent realm in HTML spec. https://html.spec.whatwg.org/multipage/webappapis.html#incumbent

    Upstream C++: v8::Isolate::GetIncumbentContext

  • getMicrotasksPolicy(): MicrotasksPolicy

    Returns the policy controlling how Microtasks are invoked.

    Upstream C++: v8::Isolate::GetMicrotasksPolicy

  • getStackTraceLimit(): number

    Get the stackTraceLimit property of Error.

    Upstream C++: v8::Isolate::GetStackTraceLimit

  • hasPendingBackgroundTasks(): boolean

    Returns true if there is ongoing background work within V8 that will eventually post a foreground task, like asynchronous WebAssembly compilation.

    Upstream C++: v8::Isolate::HasPendingBackgroundTasks

  • hasPendingException(): boolean

    Returns true if an exception was thrown but not processed yet by an exception handler on JavaScript side or by TryCatch handler.

    This is an experimental feature and may still change significantly.

    Upstream C++: v8::Isolate::HasPendingException

  • inContext(): boolean

    Returns true if this isolate has a current context.

    Upstream C++: v8::Isolate::InContext

  • increaseHeapLimitForDebugging(): void

    Optional notification to tell V8 the current isolate is used for debugging and requires higher heap limit.

    Upstream C++: v8::Isolate::IncreaseHeapLimitForDebugging

  • installConditionalFeatures(context: Context): void

    This function can be called by the embedder to signal V8 that the dynamic enabling of features has finished. V8 can now set up dynamically added features.

    Upstream C++: v8::Isolate::InstallConditionalFeatures

  • isCurrent(): boolean

    Return true if this isolate is currently active.

    Upstream C++: v8::Isolate::IsCurrent

  • isDead(): boolean

    Check if V8 is dead and therefore unusable. This is the case after fatal errors such as out-of-memory situations.

    Upstream C++: v8::Isolate::IsDead

  • isExecutionTerminating(): boolean

    Is V8 terminating JavaScript execution.

    Returns true if JavaScript execution is currently terminating because of a call to TerminateExecution. In that case there are still JavaScript frames on the stack and the termination exception is still active.

    Upstream C++: v8::Isolate::IsExecutionTerminating

  • isHeapLimitIncreasedForDebugging(): boolean

    Returns true if the heap limit was increased for debugging and the original heap limit was not restored yet.

    Upstream C++: v8::Isolate::IsHeapLimitIncreasedForDebugging

  • isInUse(): boolean

    Check if this isolate is in use. True if at least one thread Enter'ed this isolate.

    Upstream C++: v8::Isolate::IsInUse

  • isolateInBackgroundNotification(): void

    Optional notification that the isolate switched to the background. V8 uses these notifications to guide heuristics.

    Upstream C++: v8::Isolate::IsolateInBackgroundNotification

  • isolateInForegroundNotification(): void

    Optional notification that the isolate switched to the foreground. V8 uses these notifications to guide heuristics.

    Upstream C++: v8::Isolate::IsolateInForegroundNotification

  • localeConfigurationChangeNotification(): void

    Notification that the embedder has changed the locale. V8 keeps a cache of various values used for locale computation. This notification will reset those cached values for the current context so that locale configuration changes would be reflected.

    This API should not be called more than needed as it will negatively impact the performance of locale operations.

    Upstream C++: v8::Isolate::LocaleConfigurationChangeNotification

  • lowMemoryNotification(): void

    Optional notification that the system is running low on memory. V8 uses these notifications to attempt to free memory.

    Upstream C++: v8::Isolate::LowMemoryNotification

  • memoryPressureNotification(level: MemoryPressureLevel): void

    Optional notification that the system is running low on memory. V8 uses these notifications to guide heuristics. It is allowed to call this function from another thread while the isolate is executing long running JavaScript code.

    Upstream C++: v8::Isolate::MemoryPressureNotification

  • numberOfHeapSpaces(): number

    Returns the number of spaces in the heap.

    Upstream C++: v8::Isolate::NumberOfHeapSpaces

  • numberOfTrackedHeapObjectTypes(): number

    Returns the number of types of objects tracked in the heap at GC.

    Upstream C++: v8::Isolate::NumberOfTrackedHeapObjectTypes

  • performMicrotaskCheckpoint(): void

    Runs the default MicrotaskQueue until it gets empty and perform other microtask checkpoint steps, such as calling ClearKeptObjects. Asserts that the MicrotasksPolicy is not kScoped. Any exceptions thrown by microtask callbacks are swallowed.

    Upstream C++: v8::Isolate::PerformMicrotaskCheckpoint

  • requestGarbageCollectionForTesting(type_: IsolateGarbageCollectionType): void

    Request garbage collection in this Isolate. It is only valid to call this function if --expose_gc was specified.

    This should only be used for testing purposes and not to enforce a garbage collection schedule. It has strong negative impact on the garbage collection performance. Use MemoryPressureNotification() instead to influence the garbage collection schedule.

    Upstream C++: v8::Isolate::RequestGarbageCollectionForTesting

  • restoreOriginalHeapLimit(): void

    Restores the original heap limit after IncreaseHeapLimitForDebugging().

    Upstream C++: v8::Isolate::RestoreOriginalHeapLimit

  • setAllowAtomicsWait(allow: boolean): void

    Set whether calling Atomics.wait (a function that may block) is allowed in this isolate. This can also be configured via CreateParams.allow_atomics_wait.

    Upstream C++: v8::Isolate::SetAllowAtomicsWait

  • setBatterySaverMode(battery_saver_mode_enabled: boolean): void

    Optional request from the embedder to tune v8 towards energy efficiency rather than speed if battery_saver_mode_enabled is true, because the embedder is in battery saver mode. If false, the correct tuning is left to v8 to decide.

    Upstream C++: v8::Isolate::SetBatterySaverMode

  • setCaptureStackTraceForUncaughtExceptions(capture: boolean, frame_limit: number, options: StackTraceStackTraceOptions): void

    Tells V8 to capture current stack trace when uncaught exception occurs and report it to the message listeners. The option is off by default.

    Upstream C++: v8::Isolate::SetCaptureStackTraceForUncaughtExceptions

  • setContinuationPreservedEmbedderData(data: Data): void

    Sets a value that will be stored on continuations and restored while the continuation runs. If data is empty, the continuation preserved embedder data is set to undefined.

    Upstream C++: v8::Isolate::SetContinuationPreservedEmbedderData

  • setContinuationPreservedEmbedderDataV2(data: Data): void

    Sets a value that will be stored on continuations and restored while the continuation runs. If data is empty, the continuation preserved embedder data is set to undefined.

    Upstream C++: v8::Isolate::SetContinuationPreservedEmbedderDataV2

  • setData(slot: number, data: number): void

    Associate embedder-specific data with the isolate. slot has to be between 0 and GetNumberOfDataSlots() - 1.

    Upstream C++: v8::Isolate::SetData

  • setEmbedderRootsHandler(handler: EmbedderRootsHandler): void

    Sets an embedder roots handle that V8 should consider when performing non-unified heap garbage collections. The intended use case is for setting a custom handler after invoking AttachCppHeap().

    V8 does not take ownership of the handler.

    Upstream C++: v8::Isolate::SetEmbedderRootsHandler

  • setIdle(is_idle: boolean): void

    Tells the VM whether the embedder is idle or not.

    Upstream C++: v8::Isolate::SetIdle

  • setIsInputHandling(is_input_handling: boolean): void

    Optional notification to tell V8 whether the embedder is currently handling user input. If the embedder uses this notification, it should call SetIsInputHandling(true) when input handling starts, and SetIsInputHandling(false) when it ends. Calling SetIsInputHandling(true) while handling input, or calling SetIsInputHandling(false) while not handling input, both have no effect. V8 uses these notifications to guide heuristics. This is an unfinished experimental feature. Semantics and implementation may change frequently.

    Upstream C++: v8::Isolate::SetIsInputHandling

  • setIsLoading(is_loading: boolean): void

    Optional notification to tell V8 whether the embedder is currently loading resources. If the embedder uses this notification, it should call SetIsLoading(true) when loading starts and SetIsLoading(false) when it ends. It's valid to call SetIsLoading(true) again while loading, which will update the timestamp when V8 considers the load started. Calling SetIsLoading(false) while not loading does nothing. V8 uses these notifications to guide heuristics. This is an unfinished experimental feature. Semantics and implementation may change frequently.

    Upstream C++: v8::Isolate::SetIsLoading

  • setMemorySaverMode(memory_saver_mode_enabled: boolean): void

    Optional request from the embedder to tune v8 towards memory efficiency rather than speed if memory_saver_mode_enabled is true, because the embedder is in memory saver mode. If false, the correct tuning is left to v8 to decide.

    Upstream C++: v8::Isolate::SetMemorySaverMode

  • setMicrotasksPolicy(policy: MicrotasksPolicy): void

    Controls how Microtasks are invoked. See MicrotasksPolicy for details.

    Upstream C++: v8::Isolate::SetMicrotasksPolicy

  • setPriority(priority: IsolatePriority): void

    Optional notification that the isolate changed priority. V8 uses the priority value to guide heuristics.

    Upstream C++: v8::Isolate::SetPriority

  • setStackLimit(stack_limit: number): void

    Modifies the stack limit for this Isolate.

    • stack_limit: An address beyond which the Vm's stack may not grow.

    Note: If you are using threads then you should hold the V8.Locker lock while setting the stack limit and you must set a non-default stack limit separately for each thread.

    Upstream C++: v8::Isolate::SetStackLimit

  • terminateExecution(): void

    Forcefully terminate the current thread of JavaScript execution in the given isolate.

    This method can be used by any thread even if that thread has not acquired the V8 lock with a Locker object.

    Upstream C++: v8::Isolate::TerminateExecution

  • throwError(message: V8String): Value

    Binds upstream V8 C++ v8::Isolate::ThrowError.

  • throwException(exception: Value): Value

    Schedules an exception to be thrown when returning to JavaScript. When an exception has been scheduled it is illegal to invoke any JavaScript operation; the caller must return immediately and only after the exception has been handled does it become legal to invoke JavaScript operations.

    Upstream C++: v8::Isolate::ThrowException

IsolateCreateParams

class IsolateCreateParams extends WasmHandle

Initial configuration parameters for a new Isolate.

Upstream C++: v8::Isolate::CreateParams (v8-isolate.h)

IsolateGroup

class IsolateGroup extends WasmHandle

The set of V8 isolates in a process is partitioned into groups. Each group has its own sandbox (if V8 was configured with support for the sandbox) and pointer-compression cage (if configured with pointer compression).

By default, all isolates are placed in the same group. This is the most efficient configuration in terms of speed and memory use. However, with pointer compression enabled, total heap usage of isolates in a group cannot exceed 4 GB, not counting array buffers and other off-heap storage. Using multiple isolate groups can allow embedders to allocate more than 4GB of objects with pointer compression enabled, if the embedder's use case can span multiple isolates.

Creating an isolate group reserves a range of virtual memory addresses. A group's memory mapping will be released when the last isolate in the group is disposed, and there are no more live IsolateGroup objects that refer to it.

Note that Isolate groups are reference counted, and the IsolateGroup type is a reference to one.

Note that it's not going to be possible to pass shared JS objects across IsolateGroup boundary.

Upstream C++: v8::IsolateGroup (v8-isolate.h)

Static Methods

  • static canCreateNewGroups(): boolean

    Return true if new isolate groups can be created at run-time, or false if all isolates must be in the same group.

    Upstream C++: v8::IsolateGroup::CanCreateNewGroups

Methods

  • sandboxContains(pointer: number): boolean

    Binds upstream V8 C++ v8::IsolateGroup::SandboxContains.

JobDelegate

class JobDelegate extends WasmHandle

Delegate that's passed to Job's worker task, providing an entry point to communicate with the scheduler.

Upstream C++: v8::JobDelegate (v8-platform.h)

Methods

  • getTaskId(): number

    Returns a task_id unique among threads currently running this job, such that GetTaskId() < worker count. To achieve this, the same task_id may be reused by a different thread after a worker_task returns.

    Upstream C++: v8::JobDelegate::GetTaskId

  • isJoiningThread(): boolean

    Returns true if the current task is called from the thread currently running JobHandle.Join().

    Upstream C++: v8::JobDelegate::IsJoiningThread

  • notifyConcurrencyIncrease(): void

    Notifies the scheduler that max concurrency was increased, and the number of worker should be adjusted accordingly. See Platform.PostJob() for more details.

    Upstream C++: v8::JobDelegate::NotifyConcurrencyIncrease

  • shouldYield(): boolean

    Returns true if this thread must return from the worker task on the current thread ASAP. Workers should periodically invoke ShouldYield (or YieldIfNeeded()) as often as is reasonable. After this method returned true, ShouldYield must not be called again.

    Upstream C++: v8::JobDelegate::ShouldYield

JobHandle

class JobHandle extends WasmHandle

Handle returned when posting a Job. Provides methods to control execution of the posted Job.

Upstream C++: v8::JobHandle (v8-platform.h)

Methods

  • cancel(): void

    Forces all existing workers to yield ASAP. Waits until they have all returned from the Job's callback before returning.

    Upstream C++: v8::JobHandle::Cancel

  • cancelAndDetach(): void

    Forces all existing workers to yield ASAP but doesn’t wait for them. Warning, this is dangerous if the Job's callback is bound to or has access to state which may be deleted after this call.

    Upstream C++: v8::JobHandle::CancelAndDetach

  • isActive(): boolean

    Returns true if there's any work pending or any worker running.

    Upstream C++: v8::JobHandle::IsActive

  • isValid(): boolean

    Returns true if associated with a Job and other methods may be called. Returns false after Join() or Cancel() was called. This may return true even if no workers are running and IsCompleted() returns true

    Upstream C++: v8::JobHandle::IsValid

  • join(): void

    Contributes to the job on this thread. Doesn't return until all tasks have completed and max concurrency becomes 0. When Join() is called and max concurrency reaches 0, it should not increase again. This also promotes this Job's priority to be at least as high as the calling thread's priority.

    Upstream C++: v8::JobHandle::Join

  • notifyConcurrencyIncrease(): void

    Notifies the scheduler that max concurrency was increased, and the number of worker should be adjusted accordingly. See Platform.PostJob() for more details.

    Upstream C++: v8::JobHandle::NotifyConcurrencyIncrease

  • updatePriority(new_priority: TaskPriority): void

    Update this Job's priority.

    Upstream C++: v8::JobHandle::UpdatePriority

  • updatePriorityEnabled(): boolean

    Returns true if job priority can be changed.

    Upstream C++: v8::JobHandle::UpdatePriorityEnabled

JobTask

class JobTask extends WasmHandle

A JobTask represents work to run in parallel from Platform.PostJob().

Upstream C++: v8::JobTask (v8-platform.h)

Methods

  • getMaxConcurrency(worker_count: number): number

    Controls the maximum number of threads calling Run() concurrently, given the number of threads currently assigned to this job and executing Run(). Run() is only invoked if the number of threads previously running Run() was less than the value returned. In general, this should return the latest number of incomplete work items (smallest unit of work) left to process, including items that are currently in progress. worker_count is the number of threads currently assigned to this job which some callers may need to determine their return value. Since GetMaxConcurrency() is a leaf function, it must not call back any JobHandle methods.

    Upstream C++: v8::JobTask::GetMaxConcurrency

  • run(delegate: JobDelegate): void

    Binds upstream V8 C++ v8::JobTask::Run.

MicrotaskQueue

class MicrotaskQueue extends WasmHandle

Represents the microtask queue, where microtasks are stored and processed. https://html.spec.whatwg.org/multipage/webappapis.html#microtask-queue https://html.spec.whatwg.org/multipage/webappapis.html#enqueuejob(queuename,-job,-arguments) https://html.spec.whatwg.org/multipage/webappapis.html#perform-a-microtask-checkpoint

A MicrotaskQueue instance may be associated to multiple Contexts by passing it to Context.New(), and they can be detached by Context.DetachGlobal(). The embedder must keep the MicrotaskQueue instance alive until all associated Contexts are gone or detached.

Use the same instance of MicrotaskQueue for all Contexts that may access each other synchronously. E.g. for Web embedding, use the same instance for all origins that share the same URL scheme and eTLD+1.

Upstream C++: v8::MicrotaskQueue (v8-microtask-queue.h)

Static Methods

  • static new(isolate: Isolate, policy: MicrotasksPolicy): MicrotaskQueue | null

    Creates an empty MicrotaskQueue instance.

    Upstream C++: v8::MicrotaskQueue::New

Methods

  • enqueueMicrotask(isolate: Isolate, microtask: V8Function): void

    Enqueues the callback to the queue.

    Upstream C++: v8::MicrotaskQueue::EnqueueMicrotask

  • getMicrotasksScopeDepth(): number

    Returns the current depth of nested MicrotasksScope that has kRunMicrotasks.

    Upstream C++: v8::MicrotaskQueue::GetMicrotasksScopeDepth

  • isRunningMicrotasks(): boolean

    Returns true if a microtask is running on this MicrotaskQueue instance.

    Upstream C++: v8::MicrotaskQueue::IsRunningMicrotasks

  • performCheckpoint(isolate: Isolate): void

    Runs microtasks if no microtask is running on this MicrotaskQueue instance.

    Upstream C++: v8::MicrotaskQueue::PerformCheckpoint

PersistentHandleVisitor

class PersistentHandleVisitor extends WasmHandle

Interface for iterating through all the persistent handles in the heap.

Upstream C++: v8::PersistentHandleVisitor (v8-persistent-handle.h)

Platform

class Platform extends WasmHandle

V8 Platform abstraction layer.

The embedder has to provide an implementation of this interface before initializing the rest of V8.

Upstream C++: v8::Platform (v8-platform.h)

Methods

  • createBlockingScope(blocking_type: BlockingType): ScopedBlockingCall

    Instantiates a ScopedBlockingCall to annotate a scope that may/will block.

    Upstream C++: v8::Platform::CreateBlockingScope

  • createBoostablePriorityScope(): ScopedBoostablePriority

    Instantiates a ScopedBoostablePriority to boost a thread's priority.

    Upstream C++: v8::Platform::CreateBoostablePriorityScope

  • currentClockTimeMillis(): number

    This function is deprecated and will be deleted. Use either CurrentClockTimeMilliseconds() or CurrentClockTimeMillisecondsHighResolution().

    Upstream C++: v8::Platform::CurrentClockTimeMillis

  • currentClockTimeMilliseconds(): bigint

    Current wall-clock time in milliseconds since epoch. Use CurrentClockTimeMillisHighResolution() when higher precision is required.

    Upstream C++: v8::Platform::CurrentClockTimeMilliseconds

  • currentClockTimeMillisecondsHighResolution(): number

    Same as CurrentClockTimeMilliseconds(), but with more precision.

    Upstream C++: v8::Platform::CurrentClockTimeMillisecondsHighResolution

  • dumpWithoutCrashing(): void

    Tells the embedder to generate and upload a crashdump during an unexpected but non-critical scenario.

    Upstream C++: v8::Platform::DumpWithoutCrashing

  • getForegroundTaskRunner(isolate: Isolate): TaskRunnerShared

    Returns a TaskRunner which can be used to post a task on the foreground. The TaskRunner's NonNestableTasksEnabled() must be true. This function should only be called from a foreground thread.

    Upstream C++: v8::Platform::GetForegroundTaskRunner

  • getForegroundTaskRunner2(isolate: Isolate, priority: TaskPriority): TaskRunnerShared

    Returns a TaskRunner with a specific priority which can be used to post a task on the foreground thread. The TaskRunner's NonNestableTasksEnabled() must be true. This function should only be called from a foreground thread.

    Upstream C++: v8::Platform::GetForegroundTaskRunner

  • getHighAllocationThroughputObserver(): HighAllocationThroughputObserver | null

    Allows the embedder to observe sections with high throughput allocation operations.

    Upstream C++: v8::Platform::GetHighAllocationThroughputObserver

  • getTracingController(): TracingController | null

    Returns an instance of a TracingController. This must be non-null.

    Upstream C++: v8::Platform::GetTracingController

  • getZeroSegmentSize(): number

    Returns the size of the zero segment of the process. The segment starts at address 0x0 and extends up to the returned size. Permissions of the segment may only be read-only, or no access. The permissions must never change and the segment must never be reused.

    This API is experimental and may change significantly.

    Upstream C++: v8::Platform::GetZeroSegmentSize

  • idleTasksEnabled(isolate: Isolate): boolean

    Returns true if idle tasks are enabled for the given isolate.

    Upstream C++: v8::Platform::IdleTasksEnabled

  • monotonicallyIncreasingTime(): number

    Monotonically increasing time in seconds from an arbitrary fixed point in the past. This function is expected to return at least millisecond-precision values. For this reason, it is recommended that the fixed point be no further in the past than the epoch.

    Upstream C++: v8::Platform::MonotonicallyIncreasingTime

  • numberOfWorkerThreads(): number

    Gets the max number of worker threads that may be used to execute concurrent work scheduled for any single TaskPriority by Call(BlockingTask)OnWorkerThread() or PostJob(). This can be used to estimate the number of tasks a work package should be split into. A return value of 0 means that there are no worker threads available. Note that a value of 0 won't prohibit V8 from posting tasks using CallOnWorkerThread.

    Upstream C++: v8::Platform::NumberOfWorkerThreads

  • onCriticalMemoryPressure(): void

    Enables the embedder to respond in cases where V8 can't allocate large blocks of memory. V8 retries the failed allocation once after calling this method. On success, execution continues; otherwise V8 exits with a fatal error. Embedder overrides of this function must NOT call back into V8.

    Upstream C++: v8::Platform::OnCriticalMemoryPressure

ResourceConstraints

class ResourceConstraints extends WasmHandle

A set of constraints that specifies the limits of the runtime's memory use. You must set the heap size before initializing the VM - the size cannot be adjusted after the VM is initialized.

If you are using threads then you should hold the V8.Locker lock while setting the stack limit and you must set a non-default stack limit separately for each thread.

The arguments for set_max_semi_space_size, set_max_old_space_size, set_max_executable_size, set_code_range_size specify limits in MB.

The argument for set_max_semi_space_size_in_kb is in KB.

Upstream C++: v8::ResourceConstraints (v8-isolate.h)

Methods

  • code_range_size_in_bytes(): number

    The amount of virtual memory reserved for generated code. This is relevant for 64-bit architectures that rely on code range for calls in code.

    When V8_COMPRESS_POINTERS_IN_SHARED_CAGE is defined, there is a shared process-wide code range that is lazily initialized. This value is used to configure that shared code range when the first Isolate is created. Subsequent Isolates ignore this value.

    Upstream C++: v8::ResourceConstraints::code_range_size_in_bytes

  • configureDefaults(physical_memory: bigint, virtual_memory_limit: bigint): void

    Configures the constraints with reasonable default values based on the capabilities of the current device the VM is running on.

    • physical_memory: The total amount of physical memory on the current device, in bytes.
    • virtual_memory_limit: The amount of virtual memory on the current device, in bytes, or zero, if there is no limit.

    Upstream C++: v8::ResourceConstraints::ConfigureDefaults

  • configureDefaultsFromHeapSize(initial_heap_size_in_bytes: number, maximum_heap_size_in_bytes: number): void

    Configures the constraints with reasonable default values based on the provided heap size limit. The heap size includes both the young and the old generation.

    • initial_heap_size_in_bytes: The initial heap size or zero. By default V8 starts with a small heap and dynamically grows it to match the set of live objects. This may lead to ineffective garbage collections at startup if the live set is large. Setting the initial heap size avoids such garbage collections. Note that this does not affect young generation garbage collections.

    • maximum_heap_size_in_bytes: The hard limit for the heap size. When the heap size approaches this limit, V8 will perform series of garbage collections and invoke the NearHeapLimitCallback. If the garbage collections do not help and the callback does not increase the limit, then V8 will crash with V8.FatalProcessOutOfMemory.

    Upstream C++: v8::ResourceConstraints::ConfigureDefaultsFromHeapSize

  • initial_old_generation_size_in_bytes(): number

    Binds upstream V8 C++ v8::ResourceConstraints::initial_old_generation_size_in_bytes.

  • initial_young_generation_size_in_bytes(): number

    Binds upstream V8 C++ v8::ResourceConstraints::initial_young_generation_size_in_bytes.

  • max_old_generation_size_in_bytes(): number

    The maximum size of the old generation. When the old generation approaches this limit, V8 will perform series of garbage collections and invoke the NearHeapLimitCallback. If the garbage collections do not help and the callback does not increase the limit, then V8 will crash with V8.FatalProcessOutOfMemory.

    Upstream C++: v8::ResourceConstraints::max_old_generation_size_in_bytes

  • max_young_generation_size_in_bytes(): number

    The maximum size of the young generation, which consists of two semi-spaces and a large object space. This affects frequency of Scavenge garbage collections and should be typically much smaller that the old generation.

    Upstream C++: v8::ResourceConstraints::max_young_generation_size_in_bytes

  • physical_memory_size_in_bytes(): bigint

    Binds upstream V8 C++ v8::ResourceConstraints::physical_memory_size_in_bytes.

  • set_code_range_size_in_bytes(limit: number): void

    Binds upstream V8 C++ v8::ResourceConstraints::set_code_range_size_in_bytes.

  • set_initial_old_generation_size_in_bytes(initial_size: number): void

    Binds upstream V8 C++ v8::ResourceConstraints::set_initial_old_generation_size_in_bytes.

  • set_initial_young_generation_size_in_bytes(initial_size: number): void

    Binds upstream V8 C++ v8::ResourceConstraints::set_initial_young_generation_size_in_bytes.

  • set_max_old_generation_size_in_bytes(limit: number): void

    Binds upstream V8 C++ v8::ResourceConstraints::set_max_old_generation_size_in_bytes.

  • set_max_young_generation_size_in_bytes(limit: number): void

    Binds upstream V8 C++ v8::ResourceConstraints::set_max_young_generation_size_in_bytes.

SampleInfo

class SampleInfo extends WasmHandle

The output structure filled up by GetStackSample API function.

Upstream C++: v8::SampleInfo (v8-unwinder.h)

SandboxHardwareSupport

class SandboxHardwareSupport extends WasmHandle

Hardware support for the V8 Sandbox.

This is an experimental feature that may change or be removed without further notice. Use at your own risk.

Upstream C++: v8::SandboxHardwareSupport (v8-sandbox.h)

Static Methods

  • static initializeBeforeThreadCreation(): void

    Initialize sandbox hardware support. This needs to be called before creating any thread that might access sandbox memory since it sets up hardware permissions to the memory that will be inherited on clone.

    Upstream C++: v8::SandboxHardwareSupport::InitializeBeforeThreadCreation

ScopedBlockingCall

class ScopedBlockingCall extends WasmHandle

This class is instantiated with CreateBlockingScope() in every scope where a blocking call is made and serves as a precise annotation of the scope that may/will block. May be implemented by an embedder to adjust the thread count. CPU usage should be minimal within that scope. ScopedBlockingCalls can be nested.

Upstream C++: v8::ScopedBlockingCall (v8-platform.h)

ScopedBoostablePriority

class ScopedBoostablePriority extends WasmHandle

Allows a thread to temporarily boost another thread's priority to match its own priority. The priority is reset when the object is destroyed, which must happens on the boosted thread.

Upstream C++: v8::ScopedBoostablePriority (v8-platform.h)

Methods

  • boostPriority(): boolean

    Boosts the priority of the thread where this ScopedBoostablePriority was created. Can be called from any thread, but requires proper external synchronization with the constructor, destructor and any other call to BoostPriority/Reset(). If called multiple times, only the first call takes effect.

    Upstream C++: v8::ScopedBoostablePriority::BoostPriority

  • reset(): void

    Resets the priority of the thread where this ScopedBoostablePriority was created to its original priority.

    Upstream C++: v8::ScopedBoostablePriority::Reset

SerializeAPIWrapperCallback

class SerializeAPIWrapperCallback extends WasmHandle

Similar to SerializeInternalFieldsCallback, but is used exclusively to serialize API wrappers. The pointers for API wrappers always point into the CppHeap.

Upstream C++: v8::SerializeAPIWrapperCallback (v8-snapshot.h)

SerializeContextDataCallback

class SerializeContextDataCallback extends WasmHandle

Similar to SerializeInternalFieldsCallback, but works with the embedder data in a Context.

Upstream C++: v8::SerializeContextDataCallback (v8-snapshot.h)

SerializeInternalFieldsCallback

class SerializeInternalFieldsCallback extends WasmHandle

Callback and supporting data used in SnapshotCreator to implement embedder logic to serialize internal fields of Objects. Internal fields that directly reference V8 objects are serialized without calling this callback. Internal fields that contain aligned pointers are serialized by this callback if it returns non-zero result. Otherwise it is serialized verbatim.

Upstream C++: v8::SerializeInternalFieldsCallback (v8-snapshot.h)

SharedMemoryHandle

class SharedMemoryHandle extends WasmHandle

Opaque type representing a handle to a shared memory region.

Upstream C++: v8::SharedMemoryHandle (v8-platform.h)

SnapshotCreator

class SnapshotCreator extends WasmHandle

Helper class to create a snapshot data blob.

The Isolate used by a SnapshotCreator is owned by it, and will be entered and exited by the constructor and destructor, respectively; The destructor will also destroy the Isolate. Experimental language features, including those available by default, are not available while creating a snapshot.

Upstream C++: v8::SnapshotCreator (v8-snapshot.h)

Methods

  • getIsolate(): Isolate | null

    Returns: the isolate prepared by the snapshot creator.

    Upstream C++: v8::SnapshotCreator::GetIsolate

StartupData

class StartupData extends WasmHandle

Upstream V8 C++ class v8::StartupData (v8-snapshot.h).

Methods

  • canBeRehashed(): boolean

    Whether the data created can be rehashed and and the hash seed can be recomputed when deserialized. Only valid for StartupData returned by SnapshotCreator.CreateBlob().

    Upstream C++: v8::StartupData::CanBeRehashed

  • isValid(): boolean

    Allows embedders to verify whether the data is valid for the current V8 instance.

    Upstream C++: v8::StartupData::IsValid

Task

class Task extends WasmHandle

A Task represents a unit of work.

Upstream C++: v8::Task (v8-platform.h)

Methods

  • run(): void

    Binds upstream V8 C++ v8::Task::Run.

TaskRunner

class TaskRunner extends WasmHandle

A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to post tasks after the isolate gets destructed, but these tasks may not get executed anymore. All tasks posted to a given TaskRunner will be invoked in sequence. Tasks can be posted from any thread.

Upstream C++: v8::TaskRunner (v8-platform.h)

Methods

  • idleTasksEnabled(): boolean

    Returns true if idle tasks are enabled for this TaskRunner.

    Upstream C++: v8::TaskRunner::IdleTasksEnabled

  • nonNestableDelayedTasksEnabled(): boolean

    Returns true if non-nestable delayed tasks are enabled for this TaskRunner.

    Upstream C++: v8::TaskRunner::NonNestableDelayedTasksEnabled

  • nonNestableTasksEnabled(): boolean

    Returns true if non-nestable tasks are enabled for this TaskRunner.

    Upstream C++: v8::TaskRunner::NonNestableTasksEnabled

TaskRunnerShared

class TaskRunnerShared extends SharedHandle

Reference-counted std.shared_ptr<TaskRunner> wrapper for V8 platform task runners. Call dispose() or use using when done.

TracingController

class TracingController extends WasmHandle

V8 Tracing controller.

Can be implemented by an embedder to record trace events from V8.

Will become obsolete in Perfetto build (v8_use_perfetto = true).

Upstream C++: v8::TracingController (v8-platform.h)

Methods

  • addTraceStateObserver(arg0: TracingControllerTraceStateObserver): void

    Adds tracing state change observer. Does nothing in Perfetto SDK build (v8_use_perfetto = true).

    Upstream C++: v8::TracingController::AddTraceStateObserver

  • removeTraceStateObserver(arg0: TracingControllerTraceStateObserver): void

    Removes tracing state change observer. Does nothing in Perfetto SDK build (v8_use_perfetto = true).

    Upstream C++: v8::TracingController::RemoveTraceStateObserver

TracingControllerTraceStateObserver

class TracingControllerTraceStateObserver extends WasmHandle

Upstream V8 C++ class v8::TracingController::TraceStateObserver (v8-platform.h).

Methods

  • onTraceDisabled(): void

    Binds upstream V8 C++ v8::TracingController::TraceStateObserver::OnTraceDisabled.

  • onTraceEnabled(): void

    Binds upstream V8 C++ v8::TracingController::TraceStateObserver::OnTraceEnabled.

V8

class V8 extends WasmHandle

Container class for static utility functions.

Upstream C++: v8::V8 (v8-initialization.h)

Static Methods

  • static dispose(): boolean

    Releases any resources used by v8 and stops any utility threads that may be running. Note that disposing v8 is permanent, it cannot be reinitialized.

    It should generally not be necessary to dispose v8 before exiting a process, this should happen automatically. It is only necessary to use if the process needs the resources taken up by v8.

    Upstream C++: v8::V8::Dispose

  • static disposePlatform(): void

    Clears all references to the Platform. This should be invoked after V8 was disposed.

    Upstream C++: v8::V8::DisposePlatform

  • static enableWebAssemblyTrapHandler(use_v8_signal_handler: boolean): boolean

    Activate trap-based bounds checking for WebAssembly.

    • use_v8_signal_handler: Whether V8 should install its own signal handler or rely on the embedder's.

    Upstream C++: v8::V8::EnableWebAssemblyTrapHandler

  • static getSharedMemoryStatistics(statistics: SharedMemoryStatistics): void

    Get statistics about the shared memory usage.

    Upstream C++: v8::V8::GetSharedMemoryStatistics

  • static getVersion(): string | null

    Get the version string.

    Upstream C++: v8::V8::GetVersion

  • static getWasmMemoryReservationSizeInBytes(type_: V8WasmMemoryType, byte_capacity: number): number

    Returns the virtual address space reservation size (in bytes) needed for one WebAssembly memory instance of the given capacity.

    • type: Whether this is a memory32 or memory64 instance.
    • byte_capacity: The maximum size, in bytes, of the WebAssembly memory. Values exceeding the engine's maximum allocatable memory size for the given type (determined by max_mem32_pages or max_mem64_pages) are clamped.

    When trap-based bounds checking is enabled by EnableWebAssemblyTrapHandler(), the amount of virtual address space that V8 needs to reserve for each WebAssembly memory instance can be much bigger than the requested size. If the process does not have enough virtual memory available, WebAssembly memory allocation would fail. During the initialization of V8, embedders can use this method to estimate whether the process has enough virtual memory for their usage of WebAssembly, and decide whether to enable the trap handler via EnableWebAssemblyTrapHandler(), or to skip it and reduce the amount of virtual memory required to keep the application running.

    Upstream C++: v8::V8::GetWasmMemoryReservationSizeInBytes

  • static initialize(): boolean

    Initializes V8. This function needs to be called before the first Isolate is created. It always returns true.

    Upstream C++: v8::V8::Initialize

  • static initializeExternalStartupData(directory_path: string | null): void

    Initialize the external startup data. The embedder only needs to invoke this method when external startup data was enabled in a build.

    If V8 was compiled with the startup data in an external file, then V8 needs to be given those external files during startup. There are three ways to do this:

    • InitializeExternalStartupData(const char*) This will look in the given directory for the file "snapshot_blob.bin".
    • InitializeExternalStartupDataFromFile(const char*) As above, but will directly use the given file name.
    • Call SetSnapshotDataBlob. This will read the blobs from the given data structure and will not perform any file IO.

    Upstream C++: v8::V8::InitializeExternalStartupData

  • static initializeExternalStartupDataFromFile(snapshot_blob: string | null): void

    Binds upstream V8 C++ v8::V8::InitializeExternalStartupDataFromFile.

  • static initializeICU(icu_data_file?: string | null): boolean

    Initialize the ICU library bundled with V8. The embedder should only invoke this method when using the bundled ICU. Returns true on success.

    If V8 was compiled with the ICU data in an external file, the location of the data file has to be provided.

    Upstream C++: v8::V8::InitializeICU

  • static initializeICUDefaultLocation(exec_path: string | null, icu_data_file?: string | null): boolean

    Initialize the ICU library bundled with V8. The embedder should only invoke this method when using the bundled ICU. If V8 was compiled with the ICU data in an external file and when the default location of that file should be used, a path to the executable must be provided. Returns true on success.

    The default is a file called icudtl.dat side-by-side with the executable.

    Optionally, the location of the data file can be provided to override the default.

    Upstream C++: v8::V8::InitializeICUDefaultLocation

  • static initializePlatform(platform: Platform): void

    Sets the Platform to use. This should be invoked before V8 is initialized.

    Upstream C++: v8::V8::InitializePlatform

  • static setFlagsFromString(str: string | null): void

    Sets V8 flags from a string.

    Upstream C++: v8::V8::SetFlagsFromString

  • static setFlagsFromString2(str: string | null, length: number): void

    Sets V8 flags from a string.

    Upstream C++: v8::V8::SetFlagsFromString

  • static setSnapshotDataBlob(startup_blob: StartupData): void

    Hand startup data to V8, in case the embedder has chosen to build V8 with external startup data.

    Note:

    • By default the startup data is linked into the V8 library, in which case this function is not meaningful.
    • If this needs to be called, it needs to be called before V8 tries to make use of its built-ins.
    • To avoid unnecessary copies of data, V8 will point directly into the given data blob, so pretty please keep it around until V8 exit.
    • Compression of the startup blob might be useful, but needs to handled entirely on the embedders' side.
    • The call will abort if the data is invalid.

    Upstream C++: v8::V8::SetSnapshotDataBlob

WasmStreamingShared

class WasmStreamingShared extends SharedHandle

Reference-counted std.shared_ptr<WasmStreaming> wrapper for streaming WebAssembly compilation handles. Call dispose() or use using when done.

On this page