v8
3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
Data Structures | |
class | AllowJavascriptExecutionScope |
class | DisallowJavascriptExecutionScope |
class | Scope |
Public Types | |
enum | GarbageCollectionType { kFullGarbageCollection, kMinorGarbageCollection } |
typedef void(* | GCPrologueCallback )(Isolate *isolate, GCType type, GCCallbackFlags flags) |
typedef void(* | GCEpilogueCallback )(Isolate *isolate, GCType type, GCCallbackFlags flags) |
Static Public Member Functions | |
static Isolate * | New () |
static Isolate * | GetCurrent () |
static V8_INLINE uint32_t | GetNumberOfDataSlots () |
Friends | |
template<class K , class V , class Traits > | |
class | PersistentValueMap |
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. When V8 is initialized a default isolate is implicitly created and entered. The embedder can create additional 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 void(* GCEpilogueCallback)(Isolate *isolate, GCType type, GCCallbackFlags flags) |
typedef void(* GCPrologueCallback)(Isolate *isolate, GCType type, GCCallbackFlags flags) |
void AddGCEpilogueCallback | ( | GCEpilogueCallback | callback, |
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.
Definition at line 6440 of file api.cc.
References Heap::AddGCEpilogueCallback(), and Isolate::heap().
Referenced by TEST().
void AddGCPrologueCallback | ( | GCPrologueCallback | callback, |
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.
Definition at line 6427 of file api.cc.
References Heap::AddGCPrologueCallback(), and Isolate::heap().
Referenced by TEST().
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 6332 of file api.cc.
References Heap::AdjustAmountOfExternalAllocatedMemory().
Referenced by Shell::ReadBuffer(), and THREADED_TEST().
void ClearInterrupt | ( | ) |
Clear interrupt request created by |RequestInterrupt|. Can be called from another thread without acquiring a |Locker|.
Definition at line 6560 of file api.cc.
Referenced by RequestInterruptTestBase::RunTest().
void Dispose | ( | ) |
Disposes the isolate. The isolate must not be entered by any thread to be disposable.
Definition at line 6592 of file api.cc.
References Utils::ApiCheck(), Isolate::IsInUse(), and Isolate::TearDown().
Referenced by main(), KangarooThread::Run(), IsolateNonlockingThread::Run(), IsolateGenesisThread::Run(), InitDefaultIsolateThread::Run(), SetFunctionEntryHookTest::RunTest(), CcTest::TearDown(), TEST(), and UNINITIALIZED_TEST().
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.
Definition at line 6603 of file api.cc.
Referenced by main(), CcTest::Run(), LockerUnlockerThread::Run(), LockTwiceAndUnlockThread::Run(), InitDefaultIsolateThread::Run(), Isolate::Scope::Scope(), TEST(), and UNINITIALIZED_TEST().
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().
Definition at line 6609 of file api.cc.
Referenced by main(), CcTest::Run(), LockerUnlockerThread::Run(), LockTwiceAndUnlockThread::Run(), InitDefaultIsolateThread::Run(), TEST(), and UNINITIALIZED_TEST().
v8::Local< v8::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.
Definition at line 6369 of file api.cc.
References Isolate::GetCallingNativeContext(), Handle< T >::is_null(), and Utils::ToLocal().
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.
Definition at line 6346 of file api.cc.
Referenced by RunWithProfiler(), and TEST().
|
static |
Returns the entered isolate for the current thread or NULL in case there is no current isolate.
Definition at line 6580 of file api.cc.
Referenced by main(), Shell::Main(), ReadLineEditor::Prompt(), ReadLine(), RunMain(), and TEST().
v8::Local< v8::Context > GetCurrentContext | ( | ) |
Returns the context that is on the top of the stack.
Definition at line 6359 of file api.cc.
References Isolate::context(), Context::global_object(), NULL, and Utils::ToLocal().
Referenced by CcTest::global(), RunCppCycle(), and RunMain().
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 6583 of file v8.h.
References I.
Referenced by PerIsolateData::Get(), and UNINITIALIZED_TEST().
v8::Local< v8::Context > GetEnteredContext | ( | ) |
Returns the last entered context.
Definition at line 6377 of file api.cc.
References Isolate::handle_scope_implementer(), Handle< T >::is_null(), HandleScopeImplementer::LastEnteredContext(), and Utils::ToLocal().
Referenced by Shell::RealmCurrent(), and PerIsolateData::RealmScope::RealmScope().
HeapProfiler * GetHeapProfiler | ( | ) |
Returns heap profiler for this isolate. Will return NULL until the isolate is initialized.
Definition at line 6339 of file api.cc.
Referenced by HasWeakGlobalHandle(), and TEST().
void GetHeapStatistics | ( | HeapStatistics * | heap_statistics | ) |
Get statistics about the heap memory usage.
Definition at line 6656 of file api.cc.
References Heap::CommittedMemory(), Heap::CommittedMemoryExecutable(), Heap::CommittedPhysicalMemory(), Isolate::heap(), Isolate::IsInitialized(), Heap::MaxReserved(), and Heap::SizeOfObjects().
Referenced by THREADED_TEST().
|
static |
Returns the maximum number of available embedder data slots. Valid slots are in the range of 0 - GetNumberOfDataSlots() - 1.
Definition at line 6589 of file v8.h.
References I.
Referenced by UNINITIALIZED_TEST().
bool InContext | ( | ) |
Returns true if this isolate has a current context.
Definition at line 6353 of file api.cc.
References Isolate::context(), and NULL.
Referenced by Shell::ReportException(), and THREADED_TEST().
|
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.
Definition at line 6586 of file api.cc.
Referenced by main(), CcTest::Run(), IsolateNonlockingThread::Run(), IsolateGenesisThread::Run(), InitDefaultIsolateThread::Run(), SetFunctionEntryHookTest::RunTest(), TEST(), and UNINITIALIZED_TEST().
void RemoveGCEpilogueCallback | ( | GCEpilogueCallback | callback | ) |
This function removes callback which was installed by AddGCEpilogueCallback function.
Definition at line 6447 of file api.cc.
References Isolate::heap(), and Heap::RemoveGCEpilogueCallback().
Referenced by TEST().
void RemoveGCPrologueCallback | ( | GCPrologueCallback | callback | ) |
This function removes callback which was installed by AddGCPrologueCallback function.
Definition at line 6434 of file api.cc.
References Isolate::heap(), and Heap::RemoveGCPrologueCallback().
Referenced by TEST().
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 IdleNotification() or LowMemoryNotification() instead to influence the garbage collection schedule.
Definition at line 6565 of file api.cc.
References ASSERT_EQ, CHECK, Heap::CollectAllGarbage(), Heap::CollectGarbage(), Heap::kAbortIncrementalMarkingMask, v8::kGCCallbackFlagForced, and v8::internal::NEW_SPACE.
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. At any given moment V8 can remember only a single callback for the very last interrupt request. Can be called from another thread without acquiring a |Locker|. Registered |callback| must not reenter interrupted Isolate.
Definition at line 6554 of file api.cc.
Referenced by RequestInterruptTestBase::InterruptThread::Run().
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 6577 of file v8.h.
References I.
Referenced by PerIsolateData::PerIsolateData(), UNINITIALIZED_TEST(), and PerIsolateData::~PerIsolateData().
void SetEventLogger | ( | LogEventCallback | that | ) |
void SetObjectGroupId | ( | const Persistent< T > & | object, |
UniqueId | id | ||
) |
Allows the host application to group objects together. If one object in the group is alive, all objects in the group are alive. After each garbage collection, object groups are removed. It is intended to be used in the before-garbage-collection callback function, for instance to simulate DOM tree connections among JS wrapper objects. Object groups for all dependent handles need to be provided for kGCTypeMarkSweepCompact collections, for all other garbage collection types it is sufficient to provide object groups for partially dependent handles only.
Definition at line 6596 of file v8.h.
References T, and TYPE_CHECK.
Referenced by TEST(), and THREADED_TEST().
void SetReference | ( | const Persistent< T > & | parent, |
const Persistent< S > & | child | ||
) |
Allows the host application to declare implicit references from an object to another object. If the parent object is alive, the child object is alive too. After each garbage collection, all implicit references are removed. It is intended to be used in the before-garbage-collection callback function.
Definition at line 6613 of file v8.h.
References S, T, and TYPE_CHECK.
Referenced by PersistentValueMap< K, V, Traits >::SetReference(), and THREADED_TEST().
void SetReferenceFromGroup | ( | UniqueId | id, |
const Persistent< T > & | child | ||
) |
Allows the host application to declare implicit references from an object group to an object. If the objects of the object group are alive, the child object is alive too. After each garbage collection, all implicit references are removed. It is intended to be used in the before-garbage-collection callback function.
Definition at line 6604 of file v8.h.
References T, and TYPE_CHECK.
Referenced by THREADED_TEST().
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.
Definition at line 6386 of file api.cc.
References ENTER_V8, Isolate::heap(), Handle< T >::IsEmpty(), Utils::OpenHandle(), Isolate::ScheduleThrow(), and v8::Undefined().
Referenced by FailedAccessCheckThrows(), and ExecArgs::Init().
|
friend |