v8
6.8.275 (node 10.15.3)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
Data Structures | |
class | AllowJavascriptExecutionScope |
struct | CreateParams |
class | DisallowJavascriptExecutionScope |
class | SafeForTerminationScope |
class | Scope |
class | SuppressMicrotaskExecutionScope |
Static Public Member Functions | |
static Isolate * | Allocate () |
static void | Initialize (Isolate *isolate, const CreateParams ¶ms) |
static Isolate * | New (const CreateParams ¶ms) |
static Isolate * | GetCurrent () |
static V8_INLINE uint32_t | GetNumberOfDataSlots () |
Friends | |
template<class K , class V , class Traits > | |
class | PersistentValueMapBase |
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.
typedef bool(* AbortOnUncaughtExceptionCallback) (Isolate *) |
Custom callback used by embedders to help V8 determine if it should abort when it throws and no internal handler is predicted to catch the exception. If –abort-on-uncaught-exception is used on the command line, then V8 will abort if either:
typedef void(* GCCallback) (Isolate *isolate, GCType type, GCCallbackFlags flags) |
typedef void(* GCCallbackWithData) (Isolate *isolate, GCType type, GCCallbackFlags flags, void *data) |
typedef size_t(* GetExternallyAllocatedMemoryInBytesCallback) () |
typedef void(* UseCounterCallback) (Isolate *isolate, UseCounterFeature feature) |
enum MessageErrorLevel |
enum UseCounterFeature |
Features reported via the SetUseCounterCallback callback. Do not change assigned numbers of existing items; add new features to the end of this list.
|
delete |
|
delete |
void AddBeforeCallEnteredCallback | ( | BeforeCallEnteredCallback | callback | ) |
Adds a callback to notify the host application right before a script is about to run. If a script re-enters the runtime during executing, the BeforeCallEnteredCallback is invoked for each re-entrance. Executing scripts inside the callback will re-trigger the callback.
void AddCallCompletedCallback | ( | CallCompletedCallback | callback | ) |
Adds a callback to notify the host application when a script finished running. If a script re-enters the runtime during executing, the CallCompletedCallback is only invoked when the outer-most script execution ends. Executing scripts inside the callback do not trigger further callbacks.
void AddGCEpilogueCallback | ( | GCCallback | callback, |
GCType | gc_type_filter = kGCTypeAll |
||
) |
void AddGCEpilogueCallback | ( | GCCallbackWithData | callback, |
void * | data = nullptr , |
||
GCType | gc_type_filter = kGCTypeAll |
||
) |
Enables the host application to receive a notification after a garbage collection. Allocations are allowed in the callback function, but the callback is not re-entrant: if the allocation inside it will trigger the garbage collection, the callback won't be called again. It is possible to specify the GCType filter for your callback. But it is not possible to register the same callback function two times with different GCType filters.
void AddGCPrologueCallback | ( | GCCallback | callback, |
GCType | gc_type_filter = kGCTypeAll |
||
) |
void AddGCPrologueCallback | ( | GCCallbackWithData | callback, |
void * | data = nullptr , |
||
GCType | gc_type_filter = kGCTypeAll |
||
) |
Enables the host application to receive a notification before a garbage collection. Allocations are allowed in the callback function, but the callback is not re-entrant: if the allocation inside it will trigger the garbage collection, the callback won't be called again. It is possible to specify the GCType filter for your callback. But it is not possible to register the same callback function two times with different GCType filters.
bool AddMessageListener | ( | MessageCallback | that, |
Local< Value > | data = Local< Value >() |
||
) |
Adds a message listener (errors only).
The same message listener can be added more than once and in that case it will be called more than once for each message.
If data is specified, it will be passed to the callback when it is called. Otherwise, the exception object will be passed to the callback instead.
bool AddMessageListenerWithErrorLevel | ( | MessageCallback | that, |
int | message_levels, | ||
Local< Value > | data = Local< Value >() |
||
) |
Adds a message listener.
The same message listener can be added more than once and in that case it will be called more than once for each message.
If data is specified, it will be passed to the callback when it is called. Otherwise, the exception object will be passed to the callback instead.
A listener can listen for particular error levels by providing a mask.
void AddMicrotasksCompletedCallback | ( | MicrotasksCompletedCallback | callback | ) |
Adds a callback to notify the host application after microtasks were run. The callback is triggered by explicit RunMicrotasks call or automatic microtasks execution (see SetAutorunMicrotasks).
Callback will trigger even if microtasks were attempted to run, but the microtasks queue was empty and no single microtask was actually executed.
Executing scriptsinside the callback will not re-trigger microtasks and the callback.
void AddNearHeapLimitCallback | ( | NearHeapLimitCallback | callback, |
void * | data | ||
) |
Add a callback to invoke in case the heap size is close to the heap limit. If multiple callbacks are added, only the most recently added callback is invoked.
int64_t AdjustAmountOfExternalAllocatedMemory | ( | int64_t | change_in_bytes | ) |
Adjusts the amount of registered external memory. Used to give V8 an indication of the amount of externally allocated memory that is kept alive by JavaScript objects. V8 uses this to decide when to perform global garbage collections. Registering externally allocated memory will trigger global garbage collections more often than it would otherwise in an attempt to garbage collect the JavaScript objects that keep the externally allocated memory alive.
change_in_bytes | the change in externally allocated memory that is kept alive by JavaScript objects. |
Definition at line 10439 of file v8.h.
References Internals::kExternalMemoryAtLastMarkCompactOffset, Internals::kExternalMemoryLimitOffset, and Internals::kExternalMemoryOffset.
|
static |
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, are allowed to be called on the uninitialized isolate. To initialize the isolate, call Isolate::Initialize().
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.
void CancelTerminateExecution | ( | ) |
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.
int ContextDisposedNotification | ( | bool | dependant_context = true | ) |
Optional notification that a context has been disposed. V8 uses these notifications to guide the GC heuristic. 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.
void DiscardThreadSpecificMetadata | ( | ) |
void Dispose | ( | ) |
Disposes the isolate. The isolate must not be entered by any thread to be disposable.
void DumpAndResetStats | ( | ) |
Dumps activated low-level V8 internal stats. This can be used instead of performing a full isolate disposal.
Enqueues the callback to the Microtask Work Queue
void EnqueueMicrotask | ( | MicrotaskCallback | callback, |
void * | data = nullptr |
||
) |
Enqueues the callback to the Microtask Work Queue
void Enter | ( | ) |
Methods below this point require holding a lock (using Locker) in a multi-threaded environment. 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.
Referenced by Isolate::Scope::Scope().
void Exit | ( | ) |
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().
Referenced by Isolate::Scope::~Scope().
void GetCodeRange | ( | void ** | start, |
size_t * | length_in_bytes | ||
) |
Returns a memory range that can potentially contain jitted code.
On Win64, embedders are advised to install function table callbacks for these ranges, as default SEH won't be able to unwind through jitted code.
The first page of the code range is reserved for the embedder and is committed, writable, and executable.
Might be empty on other platforms.
|
static |
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.
Referenced by Value::ToBoolean(), Value::ToInteger(), Value::ToObject(), and Value::ToString().
Returns the context of the currently running JavaScript, or the context on the top of the stack if no JavaScript is running.
Referenced by Value::ToBoolean(), Value::ToInteger(), Value::ToObject(), and Value::ToString().
void * GetData | ( | uint32_t | slot | ) |
Retrieve embedder-specific data from the isolate. Returns NULL if SetData has never been called for the given |slot|.
Definition at line 10421 of file v8.h.
References Internals::GetEmbedderData().
V8_INLINE MaybeLocal<T> GetDataFromSnapshotOnce | ( | size_t | index | ) |
Return data that was previously attached to the isolate snapshot via SnapshotCreator, and removes the reference to it. Repeated call with the same index returns an empty MaybeLocal.
MaybeLocal<T> GetDataFromSnapshotOnce | ( | size_t | index | ) |
Definition at line 10433 of file v8.h.
References Local< T >::Local.
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.
bool GetHeapCodeAndMetadataStatistics | ( | HeapCodeStatistics * | object_statistics | ) |
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. |
bool GetHeapObjectStatisticsAtLastGC | ( | HeapObjectStatistics * | object_statistics, |
size_t | type_index | ||
) |
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. |
HeapProfiler* GetHeapProfiler | ( | ) |
Returns heap profiler for this isolate. Will return NULL until the isolate is initialized.
bool GetHeapSpaceStatistics | ( | HeapSpaceStatistics * | space_statistics, |
size_t | index | ||
) |
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. |
void GetHeapStatistics | ( | HeapStatistics * | heap_statistics | ) |
Get statistics about the heap memory usage.
Returns the Context that corresponds to the Incumbent realm in HTML spec. https://html.spec.whatwg.org/multipage/webappapis.html#incumbent
MicrotasksPolicy GetMicrotasksPolicy | ( | ) | const |
Returns the policy controlling how Microtasks are invoked.
|
static |
Returns the maximum number of available embedder data slots. Valid slots are in the range of 0 - GetNumberOfDataSlots() - 1.
Definition at line 10427 of file v8.h.
References Internals::kNumIsolateDataSlots.
void GetStackSample | ( | const RegisterState & | state, |
void ** | frames, | ||
size_t | frames_limit, | ||
SampleInfo * | sample_info | ||
) |
Get a call stack sample from the isolate.
state | Execution state. |
frames | Caller allocated buffer to store stack frames. |
frames_limit | Maximum number of frames to capture. The buffer must be large enough to hold the number of frames. |
sample_info | The sample info is filled up by the function provides number of actual captured stack frames and the current VM state. |
bool IdleNotificationDeadline | ( | double | deadline_in_seconds | ) |
Optional notification that the embedder is idle. V8 uses the notification to perform garbage collection. This call can be used repeatedly if the embedder remains idle. Returns true if the embedder should stop calling IdleNotificationDeadline until real work has been done. This indicates that V8 has done as much cleanup as it will be able to do.
The deadline_in_seconds argument specifies the deadline V8 has to finish garbage collection work. deadline_in_seconds is compared with MonotonicallyIncreasingTime() and should be based on the same timebase as that function. There is no guarantee that the actual work will be done within the time limit.
bool InContext | ( | ) |
Returns true if this isolate has a current context.
void IncreaseHeapLimitForDebugging | ( | ) |
Optional notification to tell V8 the current isolate is used for debugging and requires higher heap limit.
|
static |
Initialize an Isolate previously allocated by Isolate::Allocate().
bool IsDead | ( | ) |
Check if V8 is dead and therefore unusable. This is the case after fatal errors such as out-of-memory situations.
bool IsExecutionTerminating | ( | ) |
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.
bool IsHeapLimitIncreasedForDebugging | ( | ) |
Returns true if the heap limit was increased for debugging and the original heap limit was not restored yet.
bool IsInUse | ( | ) |
Check if this isolate is in use. True if at least one thread Enter'ed this isolate.
void IsolateInBackgroundNotification | ( | ) |
Optional notification that the isolate switched to the background. V8 uses these notifications to guide heuristics.
void IsolateInForegroundNotification | ( | ) |
Optional notification that the isolate switched to the foreground. V8 uses these notifications to guide heuristics.
void LowMemoryNotification | ( | ) |
Optional notification that the system is running low on memory. V8 uses these notifications to attempt to free memory.
void MemoryPressureNotification | ( | MemoryPressureLevel | level | ) |
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.
|
static |
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.
size_t NumberOfHeapSpaces | ( | ) |
Returns the number of spaces in the heap.
size_t NumberOfPhantomHandleResetsSinceLastCall | ( | ) |
Returns the number of phantom handles without callbacks that were reset by the garbage collector since the last call to this function.
size_t NumberOfTrackedHeapObjectTypes | ( | ) |
Returns the number of types of objects tracked in the heap at GC.
|
delete |
|
delete |
|
delete |
|
delete |
void RemoveBeforeCallEnteredCallback | ( | BeforeCallEnteredCallback | callback | ) |
Removes callback that was installed by AddBeforeCallEnteredCallback.
void RemoveCallCompletedCallback | ( | CallCompletedCallback | callback | ) |
Removes callback that was installed by AddCallCompletedCallback.
void RemoveGCEpilogueCallback | ( | GCCallback | callback | ) |
void RemoveGCEpilogueCallback | ( | GCCallbackWithData | callback, |
void * | data = nullptr |
||
) |
This function removes callback which was installed by AddGCEpilogueCallback function.
void RemoveGCPrologueCallback | ( | GCCallback | callback | ) |
void RemoveGCPrologueCallback | ( | GCCallbackWithData | , |
void * | data = nullptr |
||
) |
This function removes callback which was installed by AddGCPrologueCallback function.
void RemoveMessageListeners | ( | MessageCallback | that | ) |
Remove all message listeners from the specified callback function.
void RemoveMicrotasksCompletedCallback | ( | MicrotasksCompletedCallback | callback | ) |
Removes callback that was installed by AddMicrotasksCompletedCallback.
void RemoveNearHeapLimitCallback | ( | NearHeapLimitCallback | callback, |
size_t | heap_limit | ||
) |
Remove the given callback and restore the heap limit to the given limit. If the given limit is zero, then it is ignored. If the current heap size is greater than the given limit, then the heap limit is restored to the minimal limit that is possible for the current heap size.
void RequestGarbageCollectionForTesting | ( | GarbageCollectionType | type | ) |
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 IdleNotificationDeadline() or LowMemoryNotification() instead to influence the garbage collection schedule.
void RequestInterrupt | ( | InterruptCallback | callback, |
void * | data | ||
) |
Request V8 to interrupt long running JavaScript code and invoke the given |callback| passing the given |data| to it. After |callback| returns control will be returned to the JavaScript code. There may be a number of interrupt requests in flight. Can be called from another thread without acquiring a |Locker|. Registered |callback| must not reenter interrupted Isolate.
void RestoreOriginalHeapLimit | ( | ) |
Restores the original heap limit after IncreaseHeapLimitForDebugging().
void RunMicrotasks | ( | ) |
Runs the Microtask Work Queue until empty Any exceptions thrown by microtask callbacks are swallowed.
void SetAbortOnUncaughtExceptionCallback | ( | AbortOnUncaughtExceptionCallback | callback | ) |
void SetAddHistogramSampleFunction | ( | AddHistogramSampleCallback | ) |
void SetAllowAtomicsWait | ( | bool | allow | ) |
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.
void SetAllowCodeGenerationFromStringsCallback | ( | AllowCodeGenerationFromStringsCallback | callback | ) |
Set the callback to invoke to check if code generation from strings should be allowed.
void SetAllowWasmCodeGenerationCallback | ( | AllowWasmCodeGenerationCallback | callback | ) |
Set the callback to invoke to check if wasm code generation should be allowed.
void SetCaptureStackTraceForUncaughtExceptions | ( | bool | capture, |
int | frame_limit = 10 , |
||
StackTrace::StackTraceOptions | options = StackTrace::kOverview |
||
) |
Tells V8 to capture current stack trace when uncaught exception occurs and report it to the message listeners. The option is off by default.
void SetCounterFunction | ( | CounterLookupCallback | ) |
Enables the host application to provide a mechanism for recording statistics counters.
void SetCreateHistogramFunction | ( | CreateHistogramCallback | ) |
Enables the host application to provide a mechanism for recording histograms. The CreateHistogram function returns a histogram which will later be passed to the AddHistogramSample function.
void SetData | ( | uint32_t | slot, |
void * | data | ||
) |
Associate embedder-specific data with the isolate. |slot| has to be between 0 and GetNumberOfDataSlots() - 1.
Definition at line 10415 of file v8.h.
References Internals::SetEmbedderData().
void SetEmbedderHeapTracer | ( | EmbedderHeapTracer * | tracer | ) |
Sets the embedder heap tracer for the isolate.
void SetEventLogger | ( | LogEventCallback | that | ) |
Set the callback to invoke for logging event.
void SetFailedAccessCheckCallbackFunction | ( | FailedAccessCheckCallback | ) |
Callback function for reporting failed access checks.
void SetFatalErrorHandler | ( | FatalErrorCallback | that | ) |
Set the callback to invoke in case of fatal errors.
void SetGetExternallyAllocatedMemoryInBytesCallback | ( | GetExternallyAllocatedMemoryInBytesCallback | callback | ) |
void SetHostImportModuleDynamicallyCallback | ( | HostImportModuleDynamicallyCallback | callback | ) |
This specifies the callback called by the upcoming dynamic import() language feature to load modules.
void SetHostInitializeImportMetaObjectCallback | ( | HostInitializeImportMetaObjectCallback | callback | ) |
This specifies the callback called by the upcoming importa.meta language feature to retrieve host-defined meta data for a module.
void SetIdle | ( | bool | is_idle | ) |
Tells the CPU profiler whether the embedder is idle.
void SetJitCodeEventHandler | ( | JitCodeEventOptions | options, |
JitCodeEventHandler | event_handler | ||
) |
Allows the host application to provide the address of a function that is notified each time code is added, moved or removed.
options | options for the JIT code event handler. |
event_handler | the JIT code event handler, which will be invoked each time code is added, moved or removed. |
event_handler
won't get notified of existent code. event_handler
may get notifications of code that overlaps earlier code notifications. This happens when code areas are reused, and the earlier overlapping code areas should therefore be discarded. event_handler
and the strings they point to are not guaranteed to live past each call. The event_handler
must copy strings and other parameters it needs to keep around. event_handler
function must ignore event codes it does not recognize to maintain future compatibility. void SetMicrotasksPolicy | ( | MicrotasksPolicy | policy | ) |
Controls how Microtasks are invoked. See MicrotasksPolicy for details.
void SetOOMErrorHandler | ( | OOMErrorCallback | that | ) |
Set the callback to invoke in case of OOM errors.
void SetPromiseHook | ( | PromiseHook | hook | ) |
Set the PromiseHook callback for various promise lifecycle events.
void SetPromiseRejectCallback | ( | PromiseRejectCallback | callback | ) |
Set callback to notify about promise reject with no handler, or revocation of such a previous notification once the handler is added.
void SetRAILMode | ( | RAILMode | rail_mode | ) |
void SetStackLimit | ( | uintptr_t | stack_limit | ) |
Modifies the stack limit for this Isolate.
stack_limit | An address beyond which the Vm's stack may not grow. |
void SetUseCounterCallback | ( | UseCounterCallback | callback | ) |
Sets a callback for counting the number of times a feature of V8 is used.
void SetWasmCompileStreamingCallback | ( | ApiImplementationCallback | callback | ) |
void SetWasmInstanceCallback | ( | ExtensionCallback | callback | ) |
void SetWasmModuleCallback | ( | ExtensionCallback | callback | ) |
Embedder over{ride|load} injection points for wasm APIs. The expectation is that the embedder sets them at most once.
void TerminateExecution | ( | ) |
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.
V8_DEPRECATED | ( | "Calling context concept is not compatible with tail | calls, |
and will be " "removed." | , | ||
Local< Context > | GetCallingContext() | ||
) |
Returns the context of the calling JavaScript code. That is the context of the top-most JavaScript frame. If there are no JavaScript frames an empty handle is returned.
V8_DEPRECATED | ( | "CpuProfiler should be created with CpuProfiler::New call." | , |
CpuProfiler * | GetCpuProfiler() | ||
) |
Returns CPU profiler for this isolate. Will return NULL unless the isolate is initialized. It is the embedder's responsibility to stop all CPU profiling activities if it has started any.
V8_DEPRECATED | ( | "Use callback with parameter" | , |
void | AddCallCompletedCallbackDeprecatedCallCompletedCallback callback | ||
) |
V8_DEPRECATED | ( | "Use callback with parameter" | , |
void | RemoveCallCompletedCallbackDeprecatedCallCompletedCallback callback | ||
) |
V8_DEPRECATED | ( | "Use GetMicrotasksPolicy" | , |
bool WillAutorunMicrotasks() const | |||
) |
V8_DEPRECATED | ( | "Use SetMicrotasksPolicy" | , |
void | SetAutorunMicrotasksbool autorun | ||
) |
void VisitExternalResources | ( | ExternalResourceVisitor * | visitor | ) |
Iterates through all external resources referenced from current isolate heap. GC is not invoked prior to iterating, therefore there is no guarantee that visited objects are still alive.
void VisitHandlesForPartialDependence | ( | PersistentHandleVisitor * | visitor | ) |
Iterates through all the persistent handles in the current isolate's heap that have class_ids and are candidates to be marked as partially dependent handles. This will visit handles to young objects created since the last garbage collection but is free to visit an arbitrary superset of these objects.
void VisitHandlesWithClassIds | ( | PersistentHandleVisitor * | visitor | ) |
Iterates through all the persistent handles in the current isolate's heap that have class_ids.
void VisitWeakHandles | ( | PersistentHandleVisitor * | visitor | ) |
Iterates through all the persistent handles in the current isolate's heap that have class_ids and are weak to be marked as inactive if there is no pending activity for the handle.
|
friend |