v8.h | v8.h | |||
---|---|---|---|---|
skipping to change at line 126 | skipping to change at line 126 | |||
class Symbol; | class Symbol; | |||
class SymbolObject; | class SymbolObject; | |||
class Private; | class Private; | |||
class Uint32; | class Uint32; | |||
class Utils; | class Utils; | |||
class Value; | class Value; | |||
template <class T> class Handle; | template <class T> class Handle; | |||
template <class T> class Local; | template <class T> class Local; | |||
template <class T> class Eternal; | template <class T> class Eternal; | |||
template<class T> class NonCopyablePersistentTraits; | template<class T> class NonCopyablePersistentTraits; | |||
template<class T> class PersistentBase; | ||||
template<class T, | template<class T, | |||
class M = NonCopyablePersistentTraits<T> > class Persistent; | class M = NonCopyablePersistentTraits<T> > class Persistent; | |||
template<class T> class UniquePersistent; | ||||
template<class T, class P> class WeakCallbackObject; | template<class T, class P> class WeakCallbackObject; | |||
class FunctionTemplate; | class FunctionTemplate; | |||
class ObjectTemplate; | class ObjectTemplate; | |||
class Data; | class Data; | |||
template<typename T> class PropertyCallbackInfo; | template<typename T> class PropertyCallbackInfo; | |||
class StackTrace; | class StackTrace; | |||
class StackFrame; | class StackFrame; | |||
class Isolate; | class Isolate; | |||
class DeclaredAccessorDescriptor; | class DeclaredAccessorDescriptor; | |||
class ObjectOperationDescriptor; | class ObjectOperationDescriptor; | |||
skipping to change at line 258 | skipping to change at line 260 | |||
V8_INLINE T* operator*() const { return val_; } | V8_INLINE T* operator*() const { return val_; } | |||
/** | /** | |||
* Checks whether two handles are the same. | * Checks whether two handles are the same. | |||
* Returns true if both are empty, or if the objects | * Returns true if both are empty, or if the objects | |||
* to which they refer are identical. | * to which they refer are identical. | |||
* The handles' references are not checked. | * The handles' references are not checked. | |||
*/ | */ | |||
template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { | template <class S> V8_INLINE bool operator==(const Handle<S>& that) const { | |||
internal::Object** a = reinterpret_cast<internal::Object**>(**this); | internal::Object** a = reinterpret_cast<internal::Object**>(this->val_) | |||
internal::Object** b = reinterpret_cast<internal::Object**>(*that); | ; | |||
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); | ||||
if (a == 0) return b == 0; | if (a == 0) return b == 0; | |||
if (b == 0) return false; | if (b == 0) return false; | |||
return *a == *b; | return *a == *b; | |||
} | } | |||
template <class S> V8_INLINE bool operator==( | template <class S> V8_INLINE bool operator==( | |||
const Persistent<S>& that) const { | const PersistentBase<S>& that) const { | |||
internal::Object** a = reinterpret_cast<internal::Object**>(**this); | internal::Object** a = reinterpret_cast<internal::Object**>(this->val_) | |||
internal::Object** b = reinterpret_cast<internal::Object**>(*that); | ; | |||
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); | ||||
if (a == 0) return b == 0; | if (a == 0) return b == 0; | |||
if (b == 0) return false; | if (b == 0) return false; | |||
return *a == *b; | return *a == *b; | |||
} | } | |||
/** | /** | |||
* Checks whether two handles are different. | * Checks whether two handles are different. | |||
* Returns true if only one of the handles is empty, or if | * Returns true if only one of the handles is empty, or if | |||
* the objects to which they refer are different. | * the objects to which they refer are different. | |||
* The handles' references are not checked. | * The handles' references are not checked. | |||
skipping to change at line 305 | skipping to change at line 307 | |||
return Handle<T>(T::Cast(*that)); | return Handle<T>(T::Cast(*that)); | |||
} | } | |||
template <class S> V8_INLINE Handle<S> As() { | template <class S> V8_INLINE Handle<S> As() { | |||
return Handle<S>::Cast(*this); | return Handle<S>::Cast(*this); | |||
} | } | |||
V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) { | V8_INLINE static Handle<T> New(Isolate* isolate, Handle<T> that) { | |||
return New(isolate, that.val_); | return New(isolate, that.val_); | |||
} | } | |||
V8_INLINE static Handle<T> New(Isolate* isolate, const Persistent<T>& tha | V8_INLINE static Handle<T> New(Isolate* isolate, | |||
t) { | const PersistentBase<T>& that) { | |||
return New(isolate, that.val_); | return New(isolate, that.val_); | |||
} | } | |||
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |||
private: | private: | |||
#endif | #endif | |||
/** | /** | |||
* Creates a new handle for the specified value. | * Creates a new handle for the specified value. | |||
*/ | */ | |||
V8_INLINE explicit Handle(T* val) : val_(val) {} | V8_INLINE explicit Handle(T* val) : val_(val) {} | |||
private: | private: | |||
friend class Utils; | friend class Utils; | |||
template<class F, class M> friend class Persistent; | template<class F, class M> friend class Persistent; | |||
template<class F> friend class PersistentBase; | ||||
template<class F> friend class Handle; | ||||
template<class F> friend class Local; | template<class F> friend class Local; | |||
template<class F> friend class FunctionCallbackInfo; | template<class F> friend class FunctionCallbackInfo; | |||
template<class F> friend class PropertyCallbackInfo; | template<class F> friend class PropertyCallbackInfo; | |||
template<class F> friend class internal::CustomArguments; | template<class F> friend class internal::CustomArguments; | |||
friend Handle<Primitive> Undefined(Isolate* isolate); | friend Handle<Primitive> Undefined(Isolate* isolate); | |||
friend Handle<Primitive> Null(Isolate* isolate); | friend Handle<Primitive> Null(Isolate* isolate); | |||
friend Handle<Boolean> True(Isolate* isolate); | friend Handle<Boolean> True(Isolate* isolate); | |||
friend Handle<Boolean> False(Isolate* isolate); | friend Handle<Boolean> False(Isolate* isolate); | |||
friend class Context; | friend class Context; | |||
friend class HandleScope; | friend class HandleScope; | |||
skipping to change at line 382 | skipping to change at line 387 | |||
template <class S> V8_INLINE Local<S> As() { | template <class S> V8_INLINE Local<S> As() { | |||
return Local<S>::Cast(*this); | return Local<S>::Cast(*this); | |||
} | } | |||
/** | /** | |||
* Create a local handle for the content of another handle. | * Create a local handle for the content of another handle. | |||
* The referee is kept alive by the local handle even when | * The referee is kept alive by the local handle even when | |||
* the original handle is destroyed/disposed. | * the original handle is destroyed/disposed. | |||
*/ | */ | |||
V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); | V8_INLINE static Local<T> New(Isolate* isolate, Handle<T> that); | |||
template<class M> | ||||
V8_INLINE static Local<T> New(Isolate* isolate, | V8_INLINE static Local<T> New(Isolate* isolate, | |||
const Persistent<T, M>& that); | const PersistentBase<T>& that); | |||
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |||
private: | private: | |||
#endif | #endif | |||
template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } | template <class S> V8_INLINE Local(S* that) : Handle<T>(that) { } | |||
private: | private: | |||
friend class Utils; | friend class Utils; | |||
template<class F> friend class Eternal; | template<class F> friend class Eternal; | |||
template<class F> friend class PersistentBase; | ||||
template<class F, class M> friend class Persistent; | template<class F, class M> friend class Persistent; | |||
template<class F> friend class Handle; | template<class F> friend class Handle; | |||
template<class F> friend class Local; | ||||
template<class F> friend class FunctionCallbackInfo; | template<class F> friend class FunctionCallbackInfo; | |||
template<class F> friend class PropertyCallbackInfo; | template<class F> friend class PropertyCallbackInfo; | |||
friend class String; | friend class String; | |||
friend class Object; | friend class Object; | |||
friend class Context; | friend class Context; | |||
template<class F> friend class internal::CustomArguments; | template<class F> friend class internal::CustomArguments; | |||
friend class HandleScope; | friend class HandleScope; | |||
friend class EscapableHandleScope; | friend class EscapableHandleScope; | |||
V8_INLINE static Local<T> New(Isolate* isolate, T* that); | V8_INLINE static Local<T> New(Isolate* isolate, T* that); | |||
skipping to change at line 457 | skipping to change at line 463 | |||
typename P, | typename P, | |||
typename M = NonCopyablePersistentTraits<T> > | typename M = NonCopyablePersistentTraits<T> > | |||
class WeakReferenceCallbacks { | class WeakReferenceCallbacks { | |||
public: | public: | |||
typedef void (*Revivable)(Isolate* isolate, | typedef void (*Revivable)(Isolate* isolate, | |||
Persistent<T, M>* object, | Persistent<T, M>* object, | |||
P* parameter); | P* parameter); | |||
}; | }; | |||
/** | /** | |||
* 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. | ||||
* | ||||
*/ | ||||
template <class T> class PersistentBase { | ||||
public: | ||||
/** | ||||
* If non-empty, destroy the underlying storage cell | ||||
* IsEmpty() will return true after this call. | ||||
*/ | ||||
V8_INLINE void Reset(); | ||||
/** | ||||
* If non-empty, destroy the underlying storage cell | ||||
* and create a new one with the contents of other if other is non empty | ||||
*/ | ||||
template <class S> | ||||
V8_INLINE 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 | ||||
*/ | ||||
template <class S> | ||||
V8_INLINE void Reset(Isolate* isolate, const PersistentBase<S>& other); | ||||
V8_INLINE bool IsEmpty() const { return val_ == 0; } | ||||
template <class S> | ||||
V8_INLINE bool operator==(const PersistentBase<S>& that) const { | ||||
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_) | ||||
; | ||||
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); | ||||
if (a == 0) return b == 0; | ||||
if (b == 0) return false; | ||||
return *a == *b; | ||||
} | ||||
template <class S> V8_INLINE bool operator==(const Handle<S>& that) const | ||||
{ | ||||
internal::Object** a = reinterpret_cast<internal::Object**>(this->val_) | ||||
; | ||||
internal::Object** b = reinterpret_cast<internal::Object**>(that.val_); | ||||
if (a == 0) return b == 0; | ||||
if (b == 0) return false; | ||||
return *a == *b; | ||||
} | ||||
template <class S> | ||||
V8_INLINE bool operator!=(const PersistentBase<S>& that) const { | ||||
return !operator==(that); | ||||
} | ||||
template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const | ||||
{ | ||||
return !operator==(that); | ||||
} | ||||
template<typename P> | ||||
V8_INLINE void SetWeak( | ||||
P* parameter, | ||||
typename WeakCallbackData<T, P>::Callback callback); | ||||
template<typename S, typename P> | ||||
V8_INLINE void SetWeak( | ||||
P* parameter, | ||||
typename WeakCallbackData<S, P>::Callback callback); | ||||
V8_INLINE void ClearWeak(); | ||||
/** | ||||
* Marks the reference to this object independent. Garbage collector is f | ||||
ree | ||||
* to ignore any object groups containing this object. Weak callback for | ||||
an | ||||
* independent handle should not assume that it will be preceded by a glo | ||||
bal | ||||
* GC prologue callback or followed by a global GC epilogue callback. | ||||
*/ | ||||
V8_INLINE void MarkIndependent(); | ||||
/** | ||||
* Marks the reference to this object partially dependent. Partially depe | ||||
ndent | ||||
* 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 o | ||||
f all | ||||
* external dependencies. This mark is automatically cleared after each | ||||
* garbage collection. | ||||
*/ | ||||
V8_INLINE void MarkPartiallyDependent(); | ||||
V8_INLINE bool IsIndependent() const; | ||||
/** Checks if the handle holds the only reference to an object. */ | ||||
V8_INLINE bool IsNearDeath() const; | ||||
/** Returns true if the handle's reference is weak. */ | ||||
V8_INLINE bool IsWeak() const; | ||||
/** | ||||
* Assigns a wrapper class ID to the handle. See RetainedObjectInfo inter | ||||
face | ||||
* description in v8-profiler.h for details. | ||||
*/ | ||||
V8_INLINE void SetWrapperClassId(uint16_t class_id); | ||||
/** | ||||
* Returns the class ID previously assigned to this handle or 0 if no cla | ||||
ss ID | ||||
* was previously assigned. | ||||
*/ | ||||
V8_INLINE uint16_t WrapperClassId() const; | ||||
private: | ||||
friend class Isolate; | ||||
friend class Utils; | ||||
template<class F> friend class Handle; | ||||
template<class F> friend class Local; | ||||
template<class F1, class F2> friend class Persistent; | ||||
template<class F> friend class UniquePersistent; | ||||
template<class F> friend class PersistentBase; | ||||
template<class F> friend class ReturnValue; | ||||
explicit V8_INLINE PersistentBase(T* val) : val_(val) {} | ||||
PersistentBase(PersistentBase& other); // NOLINT | ||||
void operator=(PersistentBase&); | ||||
V8_INLINE static T* New(Isolate* isolate, T* that); | ||||
T* val_; | ||||
}; | ||||
/** | ||||
* Default traits for Persistent. This class does not allow | * Default traits for Persistent. This class does not allow | |||
* use of the copy constructor or assignment operator. | * use of the copy constructor or assignment operator. | |||
* At present kResetInDestructor is not set, but that will change in a futu re | * At present kResetInDestructor is not set, but that will change in a futu re | |||
* version. | * version. | |||
*/ | */ | |||
template<class T> | template<class T> | |||
class NonCopyablePersistentTraits { | class NonCopyablePersistentTraits { | |||
public: | public: | |||
typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersist ent; | typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersist ent; | |||
static const bool kResetInDestructor = false; | static const bool kResetInDestructor = false; | |||
skipping to change at line 494 | skipping to change at line 630 | |||
typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; | typedef Persistent<T, CopyablePersistentTraits<T> > CopyablePersistent; | |||
static const bool kResetInDestructor = true; | static const bool kResetInDestructor = true; | |||
template<class S, class M> | template<class S, class M> | |||
static V8_INLINE void Copy(const Persistent<S, M>& source, | static V8_INLINE void Copy(const Persistent<S, M>& source, | |||
CopyablePersistent* dest) { | CopyablePersistent* dest) { | |||
// do nothing, just allow copy | // do nothing, just allow copy | |||
} | } | |||
}; | }; | |||
/** | /** | |||
* An object reference that is independent of any handle scope. Where | * A PersistentBase which allows copy and assignment. | |||
* a Local handle only lives as long as the HandleScope in which it was | ||||
* allocated, a Persistent 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 Persistent::Reset and | ||||
* existing handles can be disposed using Persistent::Reset. | ||||
* | * | |||
* Copy, assignment and destructor bevavior is controlled by the traits | * Copy, assignment and destructor bevavior is controlled by the traits | |||
* class M. | * class M. | |||
* | ||||
* Note: Persistent class hierarchy is subject to future changes. | ||||
*/ | */ | |||
template <class T, class M> class Persistent { | template <class T, class M> class Persistent : public PersistentBase<T> { | |||
public: | public: | |||
/** | /** | |||
* A Persistent with no storage cell. | * A Persistent with no storage cell. | |||
*/ | */ | |||
V8_INLINE Persistent() : val_(0) { } | V8_INLINE Persistent() : PersistentBase<T>(0) { } | |||
/** | /** | |||
* Construct a Persistent from a Handle. | * Construct a Persistent from a Handle. | |||
* When the Handle is non-empty, a new storage cell is created | * When the Handle is non-empty, a new storage cell is created | |||
* pointing to the same object, and no flags are set. | * pointing to the same object, and no flags are set. | |||
*/ | */ | |||
template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) | template <class S> V8_INLINE Persistent(Isolate* isolate, Handle<S> that) | |||
: val_(New(isolate, *that)) { | : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
} | } | |||
/** | /** | |||
* Construct a Persistent from a Persistent. | * Construct a Persistent from a Persistent. | |||
* When the Persistent is non-empty, a new storage cell is created | * When the Persistent is non-empty, a new storage cell is created | |||
* pointing to the same object, and no flags are set. | * pointing to the same object, and no flags are set. | |||
*/ | */ | |||
template <class S, class M2> | template <class S, class M2> | |||
V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) | V8_INLINE Persistent(Isolate* isolate, const Persistent<S, M2>& that) | |||
: val_(New(isolate, *that)) { | : PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
} | } | |||
/** | /** | |||
* The copy constructors and assignment operator create a Persistent | * The copy constructors and assignment operator create a Persistent | |||
* exactly as the Persistent constructor, but the Copy function from the | * exactly as the Persistent constructor, but the Copy function from the | |||
* traits class is called, allowing the setting of flags based on the | * traits class is called, allowing the setting of flags based on the | |||
* copied Persistent. | * copied Persistent. | |||
*/ | */ | |||
V8_INLINE Persistent(const Persistent& that) : val_(0) { | V8_INLINE Persistent(const Persistent& that) : PersistentBase<T>(0) { | |||
Copy(that); | Copy(that); | |||
} | } | |||
template <class S, class M2> | template <class S, class M2> | |||
V8_INLINE Persistent(const Persistent<S, M2>& that) : val_(0) { | V8_INLINE Persistent(const Persistent<S, M2>& that) : PersistentBase<T>(0 ) { | |||
Copy(that); | Copy(that); | |||
} | } | |||
V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT | V8_INLINE Persistent& operator=(const Persistent& that) { // NOLINT | |||
Copy(that); | Copy(that); | |||
return *this; | return *this; | |||
} | } | |||
template <class S, class M2> | template <class S, class M2> | |||
V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLIN T | V8_INLINE Persistent& operator=(const Persistent<S, M2>& that) { // NOLIN T | |||
Copy(that); | Copy(that); | |||
return *this; | return *this; | |||
} | } | |||
/** | /** | |||
* The destructor will dispose the Persistent based on the | * The destructor will dispose the Persistent based on the | |||
* kResetInDestructor flags in the traits class. Since not calling dispo se | * kResetInDestructor flags in the traits class. Since not calling dispo se | |||
* can result in a memory leak, it is recommended to always set this flag . | * can result in a memory leak, it is recommended to always set this flag . | |||
*/ | */ | |||
V8_INLINE ~Persistent() { | V8_INLINE ~Persistent() { | |||
if (M::kResetInDestructor) Reset(); | if (M::kResetInDestructor) this->Reset(); | |||
} | } | |||
/** | ||||
* If non-empty, destroy the underlying storage cell | ||||
* IsEmpty() will return true after this call. | ||||
*/ | ||||
V8_INLINE void Reset(); | ||||
/** | ||||
* If non-empty, destroy the underlying storage cell | ||||
* and create a new one with the contents of other if other is non empty | ||||
*/ | ||||
template <class S> | ||||
V8_INLINE 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 | ||||
*/ | ||||
template <class S, class M2> | ||||
V8_INLINE void Reset(Isolate* isolate, const Persistent<S, M2>& other); | ||||
V8_DEPRECATED("Use Reset instead", | V8_DEPRECATED("Use Reset instead", | |||
V8_INLINE void Dispose()) { Reset(); } | V8_INLINE void Dispose()) { this->Reset(); } | |||
V8_INLINE bool IsEmpty() const { return val_ == 0; } | ||||
// TODO(dcarney): this is pretty useless, fix or remove | // TODO(dcarney): this is pretty useless, fix or remove | |||
template <class S> | template <class S> | |||
V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT | V8_INLINE static Persistent<T>& Cast(Persistent<S>& that) { // NOLINT | |||
#ifdef V8_ENABLE_CHECKS | #ifdef V8_ENABLE_CHECKS | |||
// If we're going to perform the type check then we have to check | // If we're going to perform the type check then we have to check | |||
// that the handle isn't empty before doing the checked cast. | // that the handle isn't empty before doing the checked cast. | |||
if (!that.IsEmpty()) T::Cast(*that); | if (!that.IsEmpty()) T::Cast(*that); | |||
#endif | #endif | |||
return reinterpret_cast<Persistent<T>&>(that); | return reinterpret_cast<Persistent<T>&>(that); | |||
} | } | |||
// TODO(dcarney): this is pretty useless, fix or remove | // TODO(dcarney): this is pretty useless, fix or remove | |||
template <class S> V8_INLINE Persistent<S>& As() { // NOLINT | template <class S> V8_INLINE Persistent<S>& As() { // NOLINT | |||
return Persistent<S>::Cast(*this); | return Persistent<S>::Cast(*this); | |||
} | } | |||
template <class S, class M2> | ||||
V8_INLINE bool operator==(const Persistent<S, M2>& that) const { | ||||
internal::Object** a = reinterpret_cast<internal::Object**>(**this); | ||||
internal::Object** b = reinterpret_cast<internal::Object**>(*that); | ||||
if (a == 0) return b == 0; | ||||
if (b == 0) return false; | ||||
return *a == *b; | ||||
} | ||||
template <class S> V8_INLINE bool operator==(const Handle<S>& that) const | ||||
{ | ||||
internal::Object** a = reinterpret_cast<internal::Object**>(**this); | ||||
internal::Object** b = reinterpret_cast<internal::Object**>(*that); | ||||
if (a == 0) return b == 0; | ||||
if (b == 0) return false; | ||||
return *a == *b; | ||||
} | ||||
template <class S, class M2> | ||||
V8_INLINE bool operator!=(const Persistent<S, M2>& that) const { | ||||
return !operator==(that); | ||||
} | ||||
template <class S> V8_INLINE bool operator!=(const Handle<S>& that) const | ||||
{ | ||||
return !operator==(that); | ||||
} | ||||
template<typename P> | ||||
V8_INLINE void SetWeak( | ||||
P* parameter, | ||||
typename WeakCallbackData<T, P>::Callback callback); | ||||
template<typename S, typename P> | ||||
V8_INLINE void SetWeak( | ||||
P* parameter, | ||||
typename WeakCallbackData<S, P>::Callback callback); | ||||
template<typename S, typename P> | template<typename S, typename P> | |||
V8_DEPRECATED( | V8_DEPRECATED( | |||
"Use SetWeak instead", | "Use SetWeak instead", | |||
V8_INLINE void MakeWeak( | V8_INLINE void MakeWeak( | |||
P* parameter, | P* parameter, | |||
typename WeakReferenceCallbacks<S, P>::Revivable callback)); | typename WeakReferenceCallbacks<S, P>::Revivable callback)); | |||
template<typename P> | template<typename P> | |||
V8_DEPRECATED( | V8_DEPRECATED( | |||
"Use SetWeak instead", | "Use SetWeak instead", | |||
V8_INLINE void MakeWeak( | V8_INLINE void MakeWeak( | |||
P* parameter, | P* parameter, | |||
typename WeakReferenceCallbacks<T, P>::Revivable callback)); | typename WeakReferenceCallbacks<T, P>::Revivable callback)); | |||
V8_INLINE void ClearWeak(); | ||||
/** | ||||
* Marks the reference to this object independent. Garbage collector is f | ||||
ree | ||||
* to ignore any object groups containing this object. Weak callback for | ||||
an | ||||
* independent handle should not assume that it will be preceded by a glo | ||||
bal | ||||
* GC prologue callback or followed by a global GC epilogue callback. | ||||
*/ | ||||
V8_INLINE void MarkIndependent(); | ||||
/** | ||||
* Marks the reference to this object partially dependent. Partially depe | ||||
ndent | ||||
* 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 o | ||||
f all | ||||
* external dependencies. This mark is automatically cleared after each | ||||
* garbage collection. | ||||
*/ | ||||
V8_INLINE void MarkPartiallyDependent(); | ||||
V8_INLINE bool IsIndependent() const; | ||||
/** Checks if the handle holds the only reference to an object. */ | ||||
V8_INLINE bool IsNearDeath() const; | ||||
/** Returns true if the handle's reference is weak. */ | ||||
V8_INLINE bool IsWeak() const; | ||||
/** | ||||
* Assigns a wrapper class ID to the handle. See RetainedObjectInfo inter | ||||
face | ||||
* description in v8-profiler.h for details. | ||||
*/ | ||||
V8_INLINE void SetWrapperClassId(uint16_t class_id); | ||||
/** | ||||
* Returns the class ID previously assigned to this handle or 0 if no cla | ||||
ss ID | ||||
* was previously assigned. | ||||
*/ | ||||
V8_INLINE uint16_t WrapperClassId() const; | ||||
V8_DEPRECATED("This will be removed", | V8_DEPRECATED("This will be removed", | |||
V8_INLINE T* ClearAndLeak()); | V8_INLINE T* ClearAndLeak()); | |||
V8_DEPRECATED("This will be removed", | V8_DEPRECATED("This will be removed", | |||
V8_INLINE void Clear()) { val_ = 0; } | V8_INLINE void Clear()) { this->val_ = 0; } | |||
// TODO(dcarney): remove | // TODO(dcarney): remove | |||
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR | |||
private: | private: | |||
#endif | #endif | |||
template <class S> V8_INLINE Persistent(S* that) : val_(that) { } | template <class S> V8_INLINE Persistent(S* that) : PersistentBase<T>(that ) { } | |||
V8_INLINE T* operator*() const { return val_; } | V8_INLINE T* operator*() const { return this->val_; } | |||
private: | private: | |||
friend class Isolate; | friend class Isolate; | |||
friend class Utils; | friend class Utils; | |||
template<class F> friend class Handle; | template<class F> friend class Handle; | |||
template<class F> friend class Local; | template<class F> friend class Local; | |||
template<class F1, class F2> friend class Persistent; | template<class F1, class F2> friend class Persistent; | |||
template<class F> friend class ReturnValue; | template<class F> friend class ReturnValue; | |||
V8_INLINE static T* New(Isolate* isolate, T* that); | ||||
template<class S, class M2> | template<class S, class M2> | |||
V8_INLINE void Copy(const Persistent<S, M2>& that); | V8_INLINE void Copy(const Persistent<S, M2>& that); | |||
}; | ||||
T* val_; | /** | |||
* A PersistentBase which has move semantics. | ||||
* | ||||
* Note: Persistent class hierarchy is subject to future changes. | ||||
*/ | ||||
template<class T> | ||||
class UniquePersistent : public PersistentBase<T> { | ||||
struct RValue { | ||||
V8_INLINE explicit RValue(UniquePersistent* object) : object(object) {} | ||||
UniquePersistent* object; | ||||
}; | ||||
public: | ||||
/** | ||||
* A UniquePersistent with no storage cell. | ||||
*/ | ||||
V8_INLINE UniquePersistent() : PersistentBase<T>(0) { } | ||||
/** | ||||
* Construct a UniquePersistent from a Handle. | ||||
* When the Handle is non-empty, a new storage cell is created | ||||
* pointing to the same object, and no flags are set. | ||||
*/ | ||||
template <class S> | ||||
V8_INLINE UniquePersistent(Isolate* isolate, Handle<S> that) | ||||
: PersistentBase<T>(PersistentBase<T>::New(isolate, *that)) { | ||||
TYPE_CHECK(T, S); | ||||
} | ||||
/** | ||||
* Construct a UniquePersistent from a PersistentBase. | ||||
* When the Persistent is non-empty, a new storage cell is created | ||||
* pointing to the same object, and no flags are set. | ||||
*/ | ||||
template <class S> | ||||
V8_INLINE UniquePersistent(Isolate* isolate, const PersistentBase<S>& tha | ||||
t) | ||||
: PersistentBase<T>(PersistentBase<T>::New(isolate, that.val_)) { | ||||
TYPE_CHECK(T, S); | ||||
} | ||||
/** | ||||
* Move constructor. | ||||
*/ | ||||
V8_INLINE UniquePersistent(RValue rvalue) | ||||
: PersistentBase<T>(rvalue.object->val_) { | ||||
rvalue.object->val_ = 0; | ||||
} | ||||
V8_INLINE ~UniquePersistent() { this->Reset(); } | ||||
/** | ||||
* Move via assignment. | ||||
*/ | ||||
template<class S> | ||||
V8_INLINE UniquePersistent& operator=(UniquePersistent<S> rhs) { | ||||
TYPE_CHECK(T, S); | ||||
this->val_ = rhs.val_; | ||||
rhs.val_ = 0; | ||||
return *this; | ||||
} | ||||
/** | ||||
* Cast operator for moves. | ||||
*/ | ||||
V8_INLINE operator RValue() { return RValue(this); } | ||||
/** | ||||
* Pass allows returning uniques from functions, etc. | ||||
*/ | ||||
V8_INLINE UniquePersistent Pass() { return UniquePersistent(RValue(this)) | ||||
; } | ||||
private: | ||||
UniquePersistent(UniquePersistent&); | ||||
void operator=(UniquePersistent&); | ||||
}; | }; | |||
/** | /** | |||
* A stack-allocated class that governs a number of local handles. | * A stack-allocated class that governs a number of local handles. | |||
* After a handle scope has been created, all local handles will be | * After a handle scope has been created, all local handles will be | |||
* allocated within that handle scope until either the handle scope is | * allocated within that handle scope until either the handle scope is | |||
* deleted or another handle scope is created. If there is already a | * deleted or another handle scope is created. If there is already a | |||
* handle scope and a new one is created, all allocations will take | * handle scope and a new one is created, all allocations will take | |||
* place in the new handle scope until it is deleted. After that, | * place in the new handle scope until it is deleted. After that, | |||
* new handles will again be allocated in the original handle scope. | * new handles will again be allocated in the original handle scope. | |||
skipping to change at line 4779 | skipping to change at line 4878 | |||
RevivableCallback weak_reference_callback); | RevivableCallback weak_reference_callback); | |||
static void ClearWeak(internal::Object** global_handle); | static void ClearWeak(internal::Object** global_handle); | |||
static void Eternalize(Isolate* isolate, | static void Eternalize(Isolate* isolate, | |||
Value* handle, | Value* handle, | |||
int* index); | int* index); | |||
static Local<Value> GetEternal(Isolate* isolate, int index); | static Local<Value> GetEternal(Isolate* isolate, int index); | |||
template <class T> friend class Handle; | template <class T> friend class Handle; | |||
template <class T> friend class Local; | template <class T> friend class Local; | |||
template <class T> friend class Eternal; | template <class T> friend class Eternal; | |||
template <class T> friend class PersistentBase; | ||||
template <class T, class M> friend class Persistent; | template <class T, class M> friend class Persistent; | |||
friend class Context; | friend class Context; | |||
}; | }; | |||
/** | /** | |||
* An external exception handler. | * An external exception handler. | |||
*/ | */ | |||
class V8_EXPORT TryCatch { | class V8_EXPORT TryCatch { | |||
public: | public: | |||
/** | /** | |||
skipping to change at line 5558 | skipping to change at line 5658 | |||
template <class T> | template <class T> | |||
Local<T>::Local() : Handle<T>() { } | Local<T>::Local() : Handle<T>() { } | |||
template <class T> | template <class T> | |||
Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { | |||
return New(isolate, that.val_); | return New(isolate, that.val_); | |||
} | } | |||
template <class T> | template <class T> | |||
template <class M> | Local<T> Local<T>::New(Isolate* isolate, const PersistentBase<T>& that) { | |||
Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { | ||||
return New(isolate, that.val_); | return New(isolate, that.val_); | |||
} | } | |||
template <class T> | template <class T> | |||
Handle<T> Handle<T>::New(Isolate* isolate, T* that) { | Handle<T> Handle<T>::New(Isolate* isolate, T* that) { | |||
if (that == NULL) return Handle<T>(); | if (that == NULL) return Handle<T>(); | |||
T* that_ptr = that; | T* that_ptr = that; | |||
internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | internal::Object** p = reinterpret_cast<internal::Object**>(that_ptr); | |||
return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( | |||
reinterpret_cast<internal::Isolate*>(isolate), *p))); | reinterpret_cast<internal::Isolate*>(isolate), *p))); | |||
skipping to change at line 5593 | skipping to change at line 5692 | |||
void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { | void Eternal<T>::Set(Isolate* isolate, Local<S> handle) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_) ; | V8::Eternalize(isolate, reinterpret_cast<Value*>(*handle), &this->index_) ; | |||
} | } | |||
template<class T> | template<class T> | |||
Local<T> Eternal<T>::Get(Isolate* isolate) { | Local<T> Eternal<T>::Get(Isolate* isolate) { | |||
return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); | return Local<T>(reinterpret_cast<T*>(*V8::GetEternal(isolate, index_))); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
T* Persistent<T, M>::New(Isolate* isolate, T* that) { | T* PersistentBase<T>::New(Isolate* isolate, T* that) { | |||
if (that == NULL) return NULL; | if (that == NULL) return NULL; | |||
internal::Object** p = reinterpret_cast<internal::Object**>(that); | internal::Object** p = reinterpret_cast<internal::Object**>(that); | |||
return reinterpret_cast<T*>( | return reinterpret_cast<T*>( | |||
V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), | |||
p)); | p)); | |||
} | } | |||
template <class T, class M> | template <class T, class M> | |||
template <class S, class M2> | template <class S, class M2> | |||
void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { | void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
Reset(); | this->Reset(); | |||
if (that.IsEmpty()) return; | if (that.IsEmpty()) return; | |||
internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); | internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); | |||
this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); | this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); | |||
M::Copy(that, this); | M::Copy(that, this); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
bool Persistent<T, M>::IsIndependent() const { | bool PersistentBase<T>::IsIndependent() const { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
I::kNodeIsIndependentShift); | I::kNodeIsIndependentShift); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
bool Persistent<T, M>::IsNearDeath() const { | bool PersistentBase<T>::IsNearDeath() const { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
uint8_t node_state = | uint8_t node_state = | |||
I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); | I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)); | |||
return node_state == I::kNodeStateIsNearDeathValue || | return node_state == I::kNodeStateIsNearDeathValue || | |||
node_state == I::kNodeStateIsPendingValue; | node_state == I::kNodeStateIsPendingValue; | |||
} | } | |||
template <class T, class M> | template <class T> | |||
bool Persistent<T, M>::IsWeak() const { | bool PersistentBase<T>::IsWeak() const { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return false; | if (this->IsEmpty()) return false; | |||
return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == | |||
I::kNodeStateIsWeakValue; | I::kNodeStateIsWeakValue; | |||
} | } | |||
template <class T, class M> | template <class T> | |||
void Persistent<T, M>::Reset() { | void PersistentBase<T>::Reset() { | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); | V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); | |||
val_ = 0; | val_ = 0; | |||
} | } | |||
template <class T, class M> | template <class T> | |||
template <class S> | template <class S> | |||
void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { | void PersistentBase<T>::Reset(Isolate* isolate, const Handle<S>& other) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
Reset(); | Reset(); | |||
if (other.IsEmpty()) return; | if (other.IsEmpty()) return; | |||
this->val_ = New(isolate, other.val_); | this->val_ = New(isolate, other.val_); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
template <class S, class M2> | template <class S> | |||
void Persistent<T, M>::Reset(Isolate* isolate, | void PersistentBase<T>::Reset(Isolate* isolate, | |||
const Persistent<S, M2>& other) { | const PersistentBase<S>& other) { | |||
TYPE_CHECK(T, S); | TYPE_CHECK(T, S); | |||
Reset(); | Reset(); | |||
if (other.IsEmpty()) return; | if (other.IsEmpty()) return; | |||
this->val_ = New(isolate, other.val_); | this->val_ = New(isolate, other.val_); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
template <typename S, typename P> | template <typename S, typename P> | |||
void Persistent<T, M>::SetWeak( | void PersistentBase<T>::SetWeak( | |||
P* parameter, | P* parameter, | |||
typename WeakCallbackData<S, P>::Callback callback) { | typename WeakCallbackData<S, P>::Callback callback) { | |||
TYPE_CHECK(S, T); | TYPE_CHECK(S, T); | |||
typedef typename WeakCallbackData<Value, void>::Callback Callback; | typedef typename WeakCallbackData<Value, void>::Callback Callback; | |||
V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), | |||
parameter, | parameter, | |||
reinterpret_cast<Callback>(callback), | reinterpret_cast<Callback>(callback), | |||
NULL); | NULL); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
template <typename P> | template <typename P> | |||
void Persistent<T, M>::SetWeak( | void PersistentBase<T>::SetWeak( | |||
P* parameter, | P* parameter, | |||
typename WeakCallbackData<T, P>::Callback callback) { | typename WeakCallbackData<T, P>::Callback callback) { | |||
SetWeak<T, P>(parameter, callback); | SetWeak<T, P>(parameter, callback); | |||
} | } | |||
template <class T, class M> | template <class T, class M> | |||
template <typename S, typename P> | template <typename S, typename P> | |||
void Persistent<T, M>::MakeWeak( | void Persistent<T, M>::MakeWeak( | |||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<S, P>::Revivable callback) { | typename WeakReferenceCallbacks<S, P>::Revivable callback) { | |||
skipping to change at line 5707 | skipping to change at line 5806 | |||
} | } | |||
template <class T, class M> | template <class T, class M> | |||
template <typename P> | template <typename P> | |||
void Persistent<T, M>::MakeWeak( | void Persistent<T, M>::MakeWeak( | |||
P* parameters, | P* parameters, | |||
typename WeakReferenceCallbacks<T, P>::Revivable callback) { | typename WeakReferenceCallbacks<T, P>::Revivable callback) { | |||
MakeWeak<T, P>(parameters, callback); | MakeWeak<T, P>(parameters, callback); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
void Persistent<T, M>::ClearWeak() { | void PersistentBase<T>::ClearWeak() { | |||
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
void Persistent<T, M>::MarkIndependent() { | void PersistentBase<T>::MarkIndependent() { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
true, | true, | |||
I::kNodeIsIndependentShift); | I::kNodeIsIndependentShift); | |||
} | } | |||
template <class T, class M> | template <class T> | |||
void Persistent<T, M>::MarkPartiallyDependent() { | void PersistentBase<T>::MarkPartiallyDependent() { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), | |||
true, | true, | |||
I::kNodeIsPartiallyDependentShift); | I::kNodeIsPartiallyDependentShift); | |||
} | } | |||
template <class T, class M> | template <class T, class M> | |||
T* Persistent<T, M>::ClearAndLeak() { | T* Persistent<T, M>::ClearAndLeak() { | |||
T* old; | T* old; | |||
old = val_; | old = this->val_; | |||
val_ = NULL; | this->val_ = NULL; | |||
return old; | return old; | |||
} | } | |||
template <class T, class M> | template <class T> | |||
void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { | void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return; | if (this->IsEmpty()) return; | |||
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | |||
*reinterpret_cast<uint16_t*>(addr) = class_id; | *reinterpret_cast<uint16_t*>(addr) = class_id; | |||
} | } | |||
template <class T, class M> | template <class T> | |||
uint16_t Persistent<T, M>::WrapperClassId() const { | uint16_t PersistentBase<T>::WrapperClassId() const { | |||
typedef internal::Internals I; | typedef internal::Internals I; | |||
if (this->IsEmpty()) return 0; | if (this->IsEmpty()) return 0; | |||
internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_) ; | |||
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + I::kNodeClassIdOffset; | |||
return *reinterpret_cast<uint16_t*>(addr); | return *reinterpret_cast<uint16_t*>(addr); | |||
} | } | |||
template<typename T> | template<typename T> | |||
ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | ReturnValue<T>::ReturnValue(internal::Object** slot) : value_(slot) {} | |||
End of changes. 51 change blocks. | ||||
173 lines changed or deleted | 277 lines changed or added | |||