V8 Project
v8::HandleScope Class Reference

A stack-allocated class that governs a number of local handles. More...

#include <v8.h>

+ Inheritance diagram for v8::HandleScope:
+ Collaboration diagram for v8::HandleScope:

Public Member Functions

 HandleScope (Isolate *isolate)
 
 ~HandleScope ()
 
IsolateGetIsolate () const
 

Static Public Member Functions

static int NumberOfHandles (Isolate *isolate)
 Counts the number of allocated handles. More...
 

Protected Member Functions

 HandleScope ()
 
void Initialize (Isolate *isolate)
 

Static Protected Member Functions

static internal::Object ** CreateHandle (internal::Isolate *isolate, internal::Object *value)
 

Private Member Functions

 HandleScope (const HandleScope &)
 
void operator= (const HandleScope &)
 
void * operator new (size_t size)
 
void operator delete (void *, size_t)
 

Static Private Member Functions

static internal::Object ** CreateHandle (internal::HeapObject *heap_object, internal::Object *value)
 

Private Attributes

internal::Isolateisolate_
 
internal::Object ** prev_next_
 
internal::Object ** prev_limit_
 

Friends

template<class F >
class Local
 
class Object
 
class Context
 

Detailed Description

A stack-allocated class that governs a number of local handles.

After a handle scope has been created, all local handles will be allocated within that handle scope until either the handle scope is deleted or another handle scope is created. If there is already a handle scope and a new one is created, all allocations will take place in the new handle scope until it is deleted. After that, new handles will again be allocated in the original handle scope.

After the handle scope of a local handle has been deleted the garbage collector will no longer track the object stored in the handle and may deallocate it. The behavior of accessing a handle for which the handle scope has been deleted is undefined.

Definition at line 802 of file v8.h.

Constructor & Destructor Documentation

◆ HandleScope() [1/3]

v8::HandleScope::HandleScope ( Isolate isolate)

Definition at line 546 of file api.cc.

546  {
547  Initialize(isolate);
548 }
void Initialize(Isolate *isolate)
Definition: api.cc:551

References Initialize().

+ Here is the call graph for this function:

◆ ~HandleScope()

v8::HandleScope::~HandleScope ( )

Definition at line 568 of file api.cc.

568  {
570 }
internal::Isolate * isolate_
Definition: v8.h:837
internal::Object ** prev_next_
Definition: v8.h:838
internal::Object ** prev_limit_
Definition: v8.h:839
static void CloseScope(Isolate *isolate, Object **prev_next, Object **prev_limit)
Definition: handles-inl.h:99

References v8::internal::HandleScope::CloseScope(), isolate_, prev_limit_, and prev_next_.

+ Here is the call graph for this function:

◆ HandleScope() [2/3]

v8::HandleScope::HandleScope ( )
inlineprotected

Definition at line 818 of file v8.h.

818 {}

◆ HandleScope() [3/3]

v8::HandleScope::HandleScope ( const HandleScope )
private

Member Function Documentation

◆ CreateHandle() [1/2]

i::Object ** v8::HandleScope::CreateHandle ( internal::HeapObject heap_object,
internal::Object value 
)
staticprivate

Definition at line 584 of file api.cc.

585  {
586  DCHECK(heap_object->IsHeapObject());
587  return i::HandleScope::CreateHandle(heap_object->GetIsolate(), value);
588 }
static T ** CreateHandle(Isolate *isolate, T *value)
Definition: handles-inl.h:138
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::HandleScope::CreateHandle(), DCHECK, and v8::internal::HeapObject::GetIsolate().

+ Here is the call graph for this function:

◆ CreateHandle() [2/2]

i::Object ** v8::HandleScope::CreateHandle ( internal::Isolate isolate,
internal::Object value 
)
staticprotected

Definition at line 579 of file api.cc.

579  {
580  return i::HandleScope::CreateHandle(isolate, value);
581 }

References v8::internal::HandleScope::CreateHandle().

Referenced by v8::EscapableHandleScope::EscapableHandleScope(), v8::Context::GetEmbedderData(), v8::Object::GetInternalField(), v8::Handle< T >::New(), and v8::Local< T >::New().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetIsolate()

Isolate* v8::HandleScope::GetIsolate ( ) const
inline

Definition at line 813 of file v8.h.

813  {
814  return reinterpret_cast<Isolate*>(isolate_);
815  }

Referenced by v8::EscapableHandleScope::Escape().

+ Here is the caller graph for this function:

◆ Initialize()

void v8::HandleScope::Initialize ( Isolate isolate)
protected

Definition at line 551 of file api.cc.

551  {
552  i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
553  // We do not want to check the correct usage of the Locker class all over the
554  // place, so we do it only here: Without a HandleScope, an embedder can do
555  // almost nothing, so it is enough to check in this central place.
557  internal_isolate->thread_manager()->IsLockedByCurrentThread(),
558  "HandleScope::HandleScope",
559  "Entering the V8 API without proper locking in place");
560  i::HandleScopeData* current = internal_isolate->handle_scope_data();
561  isolate_ = internal_isolate;
562  prev_next_ = current->next;
563  prev_limit_ = current->limit;
564  current->level++;
565 }
static bool IsActive()
Returns whether v8::Locker is being used by this V8 instance.
Definition: v8threads.cc:66
static bool ApiCheck(bool condition, const char *location, const char *message)
Definition: api.h:177
HandleScopeData * handle_scope_data()
Definition: isolate.h:899
ThreadManager * thread_manager()
Definition: isolate.h:921
internal::Object ** next
Definition: handles.h:285
internal::Object ** limit
Definition: handles.h:286

References v8::Utils::ApiCheck(), v8::internal::Isolate::handle_scope_data(), v8::Locker::IsActive(), v8::internal::ThreadManager::IsLockedByCurrentThread(), isolate_, v8::internal::HandleScopeData::level, v8::internal::HandleScopeData::limit, v8::internal::HandleScopeData::next, prev_limit_, prev_next_, and v8::internal::Isolate::thread_manager().

Referenced by v8::EscapableHandleScope::EscapableHandleScope(), and HandleScope().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NumberOfHandles()

int v8::HandleScope::NumberOfHandles ( Isolate isolate)
static

Counts the number of allocated handles.

Definition at line 573 of file api.cc.

573  {
575  reinterpret_cast<i::Isolate*>(isolate));
576 }
static int NumberOfHandles(Isolate *isolate)
Definition: handles.cc:13

References v8::internal::HandleScope::NumberOfHandles().

+ Here is the call graph for this function:

◆ operator delete()

void v8::HandleScope::operator delete ( void *  ,
size_t   
)
private

◆ operator new()

void* v8::HandleScope::operator new ( size_t  size)
private

◆ operator=()

void v8::HandleScope::operator= ( const HandleScope )
private

Friends And Related Function Documentation

◆ Context

friend class Context
friend

Definition at line 847 of file v8.h.

◆ Local

template<class F >
friend class Local
friend

Definition at line 842 of file v8.h.

◆ Object

friend class Object
friend

Definition at line 846 of file v8.h.

Member Data Documentation

◆ isolate_

internal::Isolate* v8::HandleScope::isolate_
private

Definition at line 837 of file v8.h.

Referenced by Initialize(), and ~HandleScope().

◆ prev_limit_

internal::Object** v8::HandleScope::prev_limit_
private

Definition at line 839 of file v8.h.

Referenced by Initialize(), and ~HandleScope().

◆ prev_next_

internal::Object** v8::HandleScope::prev_next_
private

Definition at line 838 of file v8.h.

Referenced by Initialize(), and ~HandleScope().


The documentation for this class was generated from the following files: