V8 Project
v8::PersistentBase< T > Class Template Reference

An object reference that is independent of any handle scope. More...

#include <v8.h>

+ Inheritance diagram for v8::PersistentBase< T >:
+ Collaboration diagram for v8::PersistentBase< T >:

Public Member Functions

void Reset ()
 If non-empty, destroy the underlying storage cell IsEmpty() will return true after this call. More...
 
template<class S >
void Reset (Isolate *isolate, const Handle< S > &other)
 If non-empty, destroy the underlying storage cell and create a new one with the contents of other if other is non empty. More...
 
template<class S >
void Reset (Isolate *isolate, const PersistentBase< S > &other)
 If non-empty, destroy the underlying storage cell and create a new one with the contents of other if other is non empty. More...
 
bool IsEmpty () const
 
template<class S >
bool operator== (const PersistentBase< S > &that) const
 
template<class S >
bool operator== (const Handle< S > &that) const
 
template<class S >
bool operator!= (const PersistentBase< S > &that) const
 
template<class S >
bool operator!= (const Handle< S > &that) const
 
template<typename P >
void SetWeak (P *parameter, typename WeakCallbackData< T, P >::Callback callback)
 Install a finalization callback on this object. More...
 
template<typename S , typename P >
void SetWeak (P *parameter, typename WeakCallbackData< S, P >::Callback callback)
 
template<typename P >
PClearWeak ()
 
void ClearWeak ()
 
void MarkIndependent ()
 Marks the reference to this object independent. More...
 
void MarkPartiallyDependent ()
 Marks the reference to this object partially dependent. More...
 
bool IsIndependent () const
 
bool IsNearDeath () const
 Checks if the handle holds the only reference to an object. More...
 
bool IsWeak () const
 Returns true if the handle's reference is weak. More...
 
void SetWrapperClassId (uint16_t class_id)
 Assigns a wrapper class ID to the handle. More...
 
uint16_t WrapperClassId () const
 Returns the class ID previously assigned to this handle or 0 if no class ID was previously assigned. More...
 

Private Member Functions

 PersistentBase (T *val)
 
 PersistentBase (PersistentBase &other)
 
void operator= (PersistentBase &)
 

Static Private Member Functions

static TNew (Isolate *isolate, T *that)
 

Private Attributes

Tval_
 

Friends

class Isolate
 
class Utils
 
template<class F >
class Handle
 
template<class F >
class Local
 
template<class F1 , class F2 >
class Persistent
 
template<class F >
class UniquePersistent
 
template<class F >
class PersistentBase
 
template<class F >
class ReturnValue
 
template<class F1 , class F2 , class F3 >
class PersistentValueMap
 
template<class F1 , class F2 >
class PersistentValueVector
 
class Object
 

Detailed Description

template<class T>
class v8::PersistentBase< T >

An object reference that is independent of any handle scope.

Where a Local handle only lives as long as the HandleScope in which it was allocated, a PersistentBase handle remains valid until it is explicitly disposed.

A persistent handle contains a reference to a storage cell within the v8 engine which holds an object value and which is updated by the garbage collector whenever the object is moved. A new storage cell can be created using the constructor or PersistentBase::Reset and existing handles can be disposed using PersistentBase::Reset.

Definition at line 448 of file v8.h.

Constructor & Destructor Documentation

◆ PersistentBase() [1/2]

template<class T >
v8::PersistentBase< T >::PersistentBase ( T val)
inlineexplicitprivate

Definition at line 571 of file v8.h.

571 : val_(val) {}

◆ PersistentBase() [2/2]

template<class T >
v8::PersistentBase< T >::PersistentBase ( PersistentBase< T > &  other)
private

Member Function Documentation

◆ ClearWeak() [1/2]

template<class T >
template<typename P >
P * v8::PersistentBase< T >::ClearWeak
inline

Definition at line 6134 of file v8.h.

6134  {
6135  return reinterpret_cast<P*>(
6136  V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)));
6137 }
static void * ClearWeak(internal::Object **global_handle)
Definition: api.cc:520
kSerializedDataOffset Object
Definition: objects-inl.h:5322
#define P(name, number_of_args, result_size)
Definition: runtime.cc:53

References v8::V8::ClearWeak(), and P.

+ Here is the call graph for this function:

◆ ClearWeak() [2/2]

template<class T >
void v8::PersistentBase< T >::ClearWeak ( )
inline

Definition at line 518 of file v8.h.

518 { ClearWeak<void>(); }

◆ IsEmpty()

template<class T >
bool v8::PersistentBase< T >::IsEmpty ( ) const
inline

Definition at line 469 of file v8.h.

469 { return val_ == 0; }

References v8::PersistentBase< T >::val_.

Referenced by v8::Persistent< T, M >::Cast(), v8::Persistent< T, M >::Copy(), main(), and v8::PersistentBase< T >::Reset().

+ Here is the caller graph for this function:

◆ IsIndependent()

template<class T >
bool v8::PersistentBase< T >::IsIndependent
inline

Definition at line 6053 of file v8.h.

6053  {
6054  typedef internal::Internals I;
6055  if (this->IsEmpty()) return false;
6056  return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6057  I::kNodeIsIndependentShift);
6058 }
bool IsEmpty() const
Definition: v8.h:469
#define I(name, number_of_args, result_size)
Definition: runtime.cc:9248

References I.

◆ IsNearDeath()

template<class T >
bool v8::PersistentBase< T >::IsNearDeath
inline

Checks if the handle holds the only reference to an object.

Definition at line 6062 of file v8.h.

6062  {
6063  typedef internal::Internals I;
6064  if (this->IsEmpty()) return false;
6065  uint8_t node_state =
6066  I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_));
6067  return node_state == I::kNodeStateIsNearDeathValue ||
6068  node_state == I::kNodeStateIsPendingValue;
6069 }

References I.

◆ IsWeak()

template<class T >
bool v8::PersistentBase< T >::IsWeak
inline

Returns true if the handle's reference is weak.


Definition at line 6073 of file v8.h.

6073  {
6074  typedef internal::Internals I;
6075  if (this->IsEmpty()) return false;
6076  return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
6077  I::kNodeStateIsWeakValue;
6078 }

References I.

Referenced by v8::PersistentValueMap< K, V, Traits >::Release().

+ Here is the caller graph for this function:

◆ MarkIndependent()

template<class T >
void v8::PersistentBase< T >::MarkIndependent
inline

Marks the reference to this object independent.

Garbage collector is free to ignore any object groups containing this object. Weak callback for an independent handle should not assume that it will be preceded by a global GC prologue callback or followed by a global GC epilogue callback.

Definition at line 6141 of file v8.h.

6141  {
6142  typedef internal::Internals I;
6143  if (this->IsEmpty()) return;
6144  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6145  true,
6146  I::kNodeIsIndependentShift);
6147 }

References I.

◆ MarkPartiallyDependent()

template<class T >
void v8::PersistentBase< T >::MarkPartiallyDependent
inline

Marks the reference to this object partially dependent.

Partially dependent handles only depend on other partially dependent handles and these dependencies are provided through object groups. It provides a way to build smaller object groups for young objects that represent only a subset of all external dependencies. This mark is automatically cleared after each garbage collection.

Definition at line 6151 of file v8.h.

6151  {
6152  typedef internal::Internals I;
6153  if (this->IsEmpty()) return;
6154  I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_),
6155  true,
6156  I::kNodeIsPartiallyDependentShift);
6157 }

References I.

◆ New()

template<class T >
T * v8::PersistentBase< T >::New ( Isolate isolate,
T that 
)
inlinestaticprivate

Definition at line 6031 of file v8.h.

6031  {
6032  if (that == NULL) return NULL;
6033  internal::Object** p = reinterpret_cast<internal::Object**>(that);
6034  return reinterpret_cast<T*>(
6035  V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate),
6036  p));
6037 }
static internal::Object ** GlobalizeReference(internal::Isolate *isolate, internal::Object **handle)
Definition: api.cc:494
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define T(name, string, precedence)
Definition: token.cc:25

References v8::V8::GlobalizeReference(), NULL, and T.

+ Here is the call graph for this function:

◆ operator!=() [1/2]

template<class T >
template<class S >
bool v8::PersistentBase< T >::operator!= ( const Handle< S > &  that) const
inline

Definition at line 493 of file v8.h.

493  {
494  return !operator==(that);
495  }
bool operator==(const PersistentBase< S > &that) const
Definition: v8.h:472

References v8::PersistentBase< T >::operator==().

+ Here is the call graph for this function:

◆ operator!=() [2/2]

template<class T >
template<class S >
bool v8::PersistentBase< T >::operator!= ( const PersistentBase< S > &  that) const
inline

Definition at line 489 of file v8.h.

489  {
490  return !operator==(that);
491  }

References v8::PersistentBase< T >::operator==().

+ Here is the call graph for this function:

◆ operator=()

template<class T >
void v8::PersistentBase< T >::operator= ( PersistentBase< T > &  )
private

◆ operator==() [1/2]

template<class T >
template<class S >
bool v8::PersistentBase< T >::operator== ( const Handle< S > &  that) const
inline

Definition at line 480 of file v8.h.

480  {
481  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
482  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
483  if (a == 0) return b == 0;
484  if (b == 0) return false;
485  return *a == *b;
486  }

References v8::Handle< T >::val_, and v8::PersistentBase< T >::val_.

◆ operator==() [2/2]

template<class T >
template<class S >
bool v8::PersistentBase< T >::operator== ( const PersistentBase< S > &  that) const
inline

Definition at line 472 of file v8.h.

472  {
473  internal::Object** a = reinterpret_cast<internal::Object**>(this->val_);
474  internal::Object** b = reinterpret_cast<internal::Object**>(that.val_);
475  if (a == 0) return b == 0;
476  if (b == 0) return false;
477  return *a == *b;
478  }

References v8::PersistentBase< T >::val_.

Referenced by v8::PersistentBase< T >::operator!=().

+ Here is the caller graph for this function:

◆ Reset() [1/3]

template<class T >
void v8::PersistentBase< T >::Reset
inline

If non-empty, destroy the underlying storage cell IsEmpty() will return true after this call.

Definition at line 6082 of file v8.h.

6082  {
6083  if (this->IsEmpty()) return;
6084  V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_));
6085  val_ = 0;
6086 }
static void DisposeGlobal(internal::Object **global_handle)
Definition: api.cc:525

References v8::V8::DisposeGlobal().

Referenced by v8::ReadLineEditor::CompletionGenerator(), main(), v8::UniquePersistent< T >::operator=(), v8::Persistent< T, M >::~Persistent(), and v8::UniquePersistent< T >::~UniquePersistent().

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

◆ Reset() [2/3]

template<class T >
template<class S >
void v8::PersistentBase< T >::Reset ( Isolate isolate,
const Handle< S > &  other 
)
inline

If non-empty, destroy the underlying storage cell and create a new one with the contents of other if other is non empty.

Definition at line 6091 of file v8.h.

6091  {
6092  TYPE_CHECK(T, S);
6093  Reset();
6094  if (other.IsEmpty()) return;
6095  this->val_ = New(isolate, other.val_);
6096 }
void Reset()
If non-empty, destroy the underlying storage cell IsEmpty() will return true after this call.
Definition: v8.h:6082
static T * New(Isolate *isolate, T *that)
Definition: v8.h:6031
#define TYPE_CHECK(T, S)
Definition: v8.h:167
#define S(x)
Definition: version.cc:55

References v8::Handle< T >::IsEmpty(), S, T, TYPE_CHECK, and v8::Handle< T >::val_.

+ Here is the call graph for this function:

◆ Reset() [3/3]

template<class T >
template<class S >
void v8::PersistentBase< T >::Reset ( Isolate isolate,
const PersistentBase< S > &  other 
)
inline

If non-empty, destroy the underlying storage cell and create a new one with the contents of other if other is non empty.

Definition at line 6101 of file v8.h.

6102  {
6103  TYPE_CHECK(T, S);
6104  Reset();
6105  if (other.IsEmpty()) return;
6106  this->val_ = New(isolate, other.val_);
6107 }

References v8::PersistentBase< T >::IsEmpty(), S, T, TYPE_CHECK, and v8::PersistentBase< T >::val_.

+ Here is the call graph for this function:

◆ SetWeak() [1/2]

template<class T >
template<typename S , typename P >
void v8::PersistentBase< T >::SetWeak ( P parameter,
typename WeakCallbackData< S, P >::Callback  callback 
)
inline

Definition at line 6112 of file v8.h.

6114  {
6115  TYPE_CHECK(S, T);
6116  typedef typename WeakCallbackData<Value, void>::Callback Callback;
6117  V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_),
6118  parameter,
6119  reinterpret_cast<Callback>(callback));
6120 }
static void MakeWeak(internal::Object **global_handle, void *data, WeakCallback weak_callback)
Definition: api.cc:513
void(* Callback)(const WeakCallbackData< T, P > &data)
Definition: v8.h:419

References v8::V8::MakeWeak(), S, T, and TYPE_CHECK.

+ Here is the call graph for this function:

◆ SetWeak() [2/2]

template<class T >
template<typename P >
void v8::PersistentBase< T >::SetWeak ( P parameter,
typename WeakCallbackData< T, P >::Callback  callback 
)
inline

Install a finalization callback on this object.

NOTE: There is no guarantee as to when or even if the callback is invoked. The invocation is performed solely on a best effort basis. As always, GC-based finalization should not be relied upon for any critical form of resource management!

Definition at line 6125 of file v8.h.

6127  {
6128  SetWeak<T, P>(parameter, callback);
6129 }

◆ SetWrapperClassId()

template<class T >
void v8::PersistentBase< T >::SetWrapperClassId ( uint16_t  class_id)
inline

Assigns a wrapper class ID to the handle.

See RetainedObjectInfo interface description in v8-profiler.h for details.

Definition at line 6170 of file v8.h.

6170  {
6171  typedef internal::Internals I;
6172  if (this->IsEmpty()) return;
6173  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
6174  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
6175  *reinterpret_cast<uint16_t*>(addr) = class_id;
6176 }
unsigned short uint16_t
Definition: unicode.cc:23

References I.

◆ WrapperClassId()

template<class T >
uint16_t v8::PersistentBase< T >::WrapperClassId
inline

Returns the class ID previously assigned to this handle or 0 if no class ID was previously assigned.

Definition at line 6180 of file v8.h.

6180  {
6181  typedef internal::Internals I;
6182  if (this->IsEmpty()) return 0;
6183  internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_);
6184  uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset;
6185  return *reinterpret_cast<uint16_t*>(addr);
6186 }

References I.

Friends And Related Function Documentation

◆ Handle

template<class T >
template<class F >
friend class Handle
friend

Definition at line 561 of file v8.h.

◆ Isolate

template<class T >
friend class Isolate
friend

Definition at line 559 of file v8.h.

◆ Local

template<class T >
template<class F >
friend class Local
friend

Definition at line 562 of file v8.h.

◆ Object

template<class T >
friend class Object
friend

Definition at line 569 of file v8.h.

◆ Persistent

template<class T >
template<class F1 , class F2 >
friend class Persistent
friend

Definition at line 563 of file v8.h.

◆ PersistentBase

template<class T >
template<class F >
friend class PersistentBase
friend

Definition at line 565 of file v8.h.

◆ PersistentValueMap

template<class T >
template<class F1 , class F2 , class F3 >
friend class PersistentValueMap
friend

Definition at line 567 of file v8.h.

◆ PersistentValueVector

template<class T >
template<class F1 , class F2 >
friend class PersistentValueVector
friend

Definition at line 568 of file v8.h.

◆ ReturnValue

template<class T >
template<class F >
friend class ReturnValue
friend

Definition at line 566 of file v8.h.

◆ UniquePersistent

template<class T >
template<class F >
friend class UniquePersistent
friend

Definition at line 564 of file v8.h.

◆ Utils

template<class T >
friend class Utils
friend

Definition at line 560 of file v8.h.

Member Data Documentation

◆ val_


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