Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index b81645081e577a21685f0f4d1f61ffb124e5c61f..3b953376be87a6ecacedef24f3a590edd5f7854c 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -145,7 +145,10 @@ class Utils; |
| class Value; |
| template <class T> class Handle; |
| template <class T> class Local; |
| -template <class T> class Persistent; |
| +template<class T> class NonCopyablePersistentTraits; |
| +template<class T, |
| + class M = NonCopyablePersistentTraits<T> > class Persistent; |
| +template<class T, class P> class WeakCallbackObject; |
| class FunctionTemplate; |
| class ObjectTemplate; |
| class Data; |
| @@ -168,6 +171,7 @@ class Object; |
| template<typename T> class CustomArguments; |
| class PropertyCallbackArguments; |
| class FunctionCallbackArguments; |
| +class GlobalHandles; |
| } |
| @@ -195,27 +199,6 @@ class UniqueId { |
| intptr_t data_; |
| }; |
| - |
| -// --- Weak Handles --- |
| - |
| - |
| -/** |
| - * A weak reference callback function. |
| - * |
| - * This callback should either explicitly invoke Dispose on |object| if |
| - * V8 wrapper is not needed anymore, or 'revive' it by invocation of MakeWeak. |
| - * |
| - * \param object the weak global object to be reclaimed by the garbage collector |
| - * \param parameter the value passed in when making the weak global object |
| - */ |
| -template<typename T, typename P> |
| -class WeakReferenceCallbacks { |
| - public: |
| - typedef void (*Revivable)(Isolate* isolate, |
| - Persistent<T>* object, |
| - P* parameter); |
| -}; |
| - |
| // --- Handles --- |
| #define TYPE_CHECK(T, S) \ |
| @@ -256,13 +239,6 @@ template <class T> class Handle { |
| */ |
| V8_INLINE(Handle()) : val_(0) {} |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - /** |
| - * Creates a new handle for the specified value. |
| - */ |
| - V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| -#endif |
| - |
| /** |
| * Creates a handle for the contents of the specified handle. This |
| * constructor allows you to pass handles as arguments by value and |
| @@ -311,7 +287,6 @@ template <class T> class Handle { |
| return *a == *b; |
| } |
| -#ifndef V8_USE_UNSAFE_HANDLES |
|
marja
2013/08/23 13:02:40
Would it be feasible to just do one round of V8_US
dcarney
2013/08/23 13:06:10
I announced in the mailing list that I'd do this.
marja
2013/08/26 07:08:14
Fair enough. In that case, would it be feasible to
|
| template <class S> V8_INLINE( |
| bool operator==(const Persistent<S>& that) const) { |
| internal::Object** a = reinterpret_cast<internal::Object**>(**this); |
| @@ -320,7 +295,6 @@ template <class T> class Handle { |
| if (b == 0) return false; |
| return *a == *b; |
| } |
| -#endif |
| /** |
| * Checks whether two handles are different. |
| @@ -352,11 +326,9 @@ template <class T> class Handle { |
| return Handle<S>::Cast(*this); |
| } |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| V8_INLINE(static Handle<T> New(Isolate* isolate, Handle<T> that)) { |
| return New(isolate, that.val_); |
| } |
| - // TODO(dcarney): remove before cutover |
| V8_INLINE(static Handle<T> New(Isolate* isolate, const Persistent<T>& that)) { |
| return New(isolate, that.val_); |
| } |
| @@ -369,11 +341,10 @@ template <class T> class Handle { |
| * Creates a new handle for the specified value. |
| */ |
| V8_INLINE(explicit Handle(T* val)) : val_(val) {} |
| -#endif |
| private: |
| friend class Utils; |
| - template<class F> friend class Persistent; |
| + template<class F, class M> friend class Persistent; |
| template<class F> friend class Local; |
| friend class Arguments; |
| template<class F> friend class FunctionCallbackInfo; |
| @@ -387,9 +358,7 @@ template <class T> class Handle { |
| friend class Context; |
| friend class HandleScope; |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| V8_INLINE(static Handle<T> New(Isolate* isolate, T* that)); |
| -#endif |
| T* val_; |
| }; |
| @@ -407,7 +376,6 @@ const int kUninitializedEternalIndex = -1; |
| * handle scope are destroyed when the handle scope is destroyed. Hence it |
| * is not necessary to explicitly deallocate local handles. |
| */ |
| -// TODO(dcarney): deprecate entire class |
| template <class T> class Local : public Handle<T> { |
| public: |
| V8_INLINE(Local()); |
| @@ -422,10 +390,6 @@ template <class T> class Local : public Handle<T> { |
| } |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| -#endif |
| - |
| template <class S> V8_INLINE(static Local<T> Cast(Local<S> that)) { |
| #ifdef V8_ENABLE_CHECKS |
| // If we're going to perform the type check then we have to check |
| @@ -434,12 +398,10 @@ template <class T> class Local : public Handle<T> { |
| #endif |
| return Local<T>(T::Cast(*that)); |
| } |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| template <class S> V8_INLINE(Local(Handle<S> that)) |
| : Handle<T>(reinterpret_cast<T*>(*that)) { |
| TYPE_CHECK(T, S); |
| } |
| -#endif |
| template <class S> V8_INLINE(Local<S> As()) { |
| return Local<S>::Cast(*this); |
| @@ -457,20 +419,19 @@ template <class T> class Local : public Handle<T> { |
| */ |
| V8_INLINE(static Local<T> New(Handle<T> that)); |
| V8_INLINE(static Local<T> New(Isolate* isolate, Handle<T> that)); |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| - // TODO(dcarney): remove before cutover |
| - V8_INLINE(static Local<T> New(Isolate* isolate, const Persistent<T>& that)); |
| + template<class M> |
| + V8_INLINE(static Local<T> New(Isolate* isolate, |
| + const Persistent<T, M>& that)); |
| #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| private: |
| #endif |
| template <class S> V8_INLINE(Local(S* that) : Handle<T>(that)) { } |
| -#endif |
| private: |
| friend class Utils; |
| - template<class F> friend class Persistent; |
| + template<class F, class M> friend class Persistent; |
| template<class F> friend class Handle; |
| friend class Arguments; |
| template<class F> friend class FunctionCallbackInfo; |
| @@ -485,115 +446,107 @@ template <class T> class Local : public Handle<T> { |
| V8_INLINE(static Local<T> New(Isolate* isolate, T* that)); |
| }; |
| -/** |
| - * 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 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 Persistent::New and existing handles can |
| - * be disposed using Persistent::Dispose. Since persistent handles |
| - * are passed by value you may have many persistent handle objects |
| - * that point to the same storage cell. For instance, if you pass a |
| - * persistent handle as an argument to a function you will not get two |
| - * different storage cells but rather two references to the same |
| - * storage cell. |
| - */ |
| -template <class T> class Persistent // NOLINT |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - : public Handle<T> { |
| -#else |
| - { // NOLINT |
| -#endif |
| - public: |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| - V8_INLINE(Persistent()) : val_(0) { } |
| - // TODO(dcarney): add this back before cutover. |
| -// V8_INLINE(~Persistent()) { |
| -// Dispose(); |
| -// } |
| - V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| - // TODO(dcarney): remove somehow before cutover |
| - // The handle should either be 0, or a pointer to a live cell. |
| - V8_INLINE(void Clear()) { val_ = 0; } |
| - /** |
| - * A constructor that creates a new global cell pointing to that. In contrast |
| - * to the copy constructor, this creates a new persistent handle which needs |
| - * to be separately disposed. |
| - */ |
| - template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| - : val_(New(isolate, *that)) { } |
| +// TODO(dcarney): comments |
| +template<class T, class P> |
| +class WeakCallbackData { |
| + public: |
| + typedef void (*Callback)(WeakCallbackData<T, P>* data); |
| - template <class S> V8_INLINE(Persistent(Isolate* isolate, |
| - const Persistent<S>& that)) // NOLINT |
| - : val_(New(isolate, *that)) { } |
| + V8_INLINE(Isolate* GetIsolate()) { return isolate_; } |
|
Sven Panne
2013/09/05 08:24:09
Constify all the getters! ;-)
|
| + V8_INLINE(Local<T> GetValue()) { return handle_; } |
| + V8_INLINE(P* GetParameter()) { return parameter_; } |
| -#else |
| - /** |
| - * Creates an empty persistent handle that doesn't point to any |
| - * storage cell. |
| - */ |
| - V8_INLINE(Persistent()) : Handle<T>() { } |
| + private: |
| + friend class internal::GlobalHandles; |
| + WeakCallbackData(Isolate* isolate, Local<T> handle, P* parameter) |
| + : isolate_(isolate), handle_(handle), parameter_(parameter) { } |
| + Isolate* isolate_; |
| + Local<T> handle_; |
| + P* parameter_; |
| +}; |
| - /** |
| - * Creates a persistent handle for the same storage cell as the |
| - * specified handle. This constructor allows you to pass persistent |
| - * handles as arguments by value and to assign between persistent |
| - * handles. However, attempting to assign between incompatible |
| - * persistent handles, for instance from a Persistent<String> to a |
| - * Persistent<Number> will cause a compile-time error. Assigning |
| - * between compatible persistent handles, for instance assigning a |
| - * Persistent<String> to a variable declared as Persistent<Value>, |
| - * is allowed as String is a subclass of Value. |
| - */ |
| - template <class S> V8_INLINE(Persistent(Persistent<S> that)) |
| - : Handle<T>(reinterpret_cast<T*>(*that)) { |
| - /** |
| - * This check fails when trying to convert between incompatible |
| - * handles. For example, converting from a Handle<String> to a |
| - * Handle<Number>. |
| - */ |
| - TYPE_CHECK(T, S); |
| - } |
| - template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { } |
| +// TODO(dcarney): Remove this class. |
| +template<typename T, |
| + typename P, |
| + typename M = NonCopyablePersistentTraits<T> > |
| +class WeakReferenceCallbacks { |
| + public: |
| + typedef void (*Revivable)(Isolate* isolate, |
| + Persistent<T, M>* object, |
| + P* parameter); |
| +}; |
| - /** |
| - * A constructor that creates a new global cell pointing to that. In contrast |
| - * to the copy constructor, this creates a new persistent handle which needs |
| - * to be separately disposed. |
| - */ |
| - template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| - : Handle<T>(New(isolate, that)) { } |
| - /** |
| - * "Casts" a plain handle which is known to be a persistent handle |
| - * to a persistent handle. |
| - */ |
| - template <class S> explicit V8_INLINE(Persistent(Handle<S> that)) |
| - : Handle<T>(*that) { } |
| +// TODO(dcarney): comments |
| +template<class T> |
| +class NonCopyablePersistentTraits { |
|
marja
2013/08/23 13:02:40
Neat :)
|
| + public: |
| + typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent; |
| + static const bool kDisposeInDestructor = false; |
| + template<class S, class M> |
| + V8_INLINE(static void Copy(const Persistent<S, M>& source, |
| + NonCopyablePersistent* dest)) { |
| + Uncompilable<Object>(); |
| + } |
| + // TODO(dcarney): come up with a good compile error here. |
| + template<class O> |
| + V8_INLINE(static void Uncompilable()) { |
| + TYPE_CHECK(O, Primitive); |
| + } |
| +}; |
| -#endif |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - template <class S> V8_INLINE(static Persistent<T> Cast(Persistent<S> that)) { |
| -#ifdef V8_ENABLE_CHECKS |
| - // 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. |
| - if (that.IsEmpty()) return Persistent<T>(); |
| -#endif |
| - return Persistent<T>(T::Cast(*that)); |
| +// TODO(dcarney): comments |
| +template <class T, class M> class Persistent { |
| + public: |
| + // normal constructors |
| + V8_INLINE(Persistent()) : val_(0) { } |
| + template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that)) |
| + : val_(New(isolate, *that)) { |
| + TYPE_CHECK(T, S); |
| } |
| - |
| - template <class S> V8_INLINE(Persistent<S> As()) { |
| - return Persistent<S>::Cast(*this); |
| + template <class S, class M2> |
| + V8_INLINE(Persistent(Isolate* isolate, const Persistent<S, M2>& that)) |
| + : val_(New(isolate, *that)) { |
| + TYPE_CHECK(T, S); |
| + } |
| + // copy constructor and assignment operators |
| + V8_INLINE(Persistent(const Persistent& that)) : val_(0) { |
| + Copy(that); |
| + } |
| + template <class S, class M2> |
| + V8_INLINE(Persistent(const Persistent<S, M2>& that)) : val_(0) { |
| + Copy(that); |
| + } |
| + V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| + Copy(that); |
| + return *this; |
| + } |
| + template <class S, class M2> |
| + V8_INLINE(Persistent& operator=(const Persistent<S, M2>& that)) { // NOLINT |
| + Copy(that); |
| + return *this; |
| + } |
| + // destructor |
| + V8_INLINE(~Persistent()) { |
| + if (M::kDisposeInDestructor) Reset(); |
| } |
| -#else |
| + V8_INLINE(void Reset()); |
| + template <class S> |
| + V8_INLINE(void Reset(Isolate* isolate, const Handle<S>& other)); |
| + template <class S, class M2> |
| + V8_INLINE(void Reset(Isolate* isolate, const Persistent<S, M2>& other)); |
| + // TODO(dcarney): deprecate |
| + V8_INLINE(void Dispose()) { Reset(); } |
| + // TODO(dcarney): deprecate |
| + V8_INLINE(void Dispose(Isolate* isolate)) { Reset(); } |
| + |
| + V8_INLINE(bool IsEmpty() const) { return val_ == 0; } |
| + |
| + // TODO(dcarney): this is pretty useless, fix or remove |
| template <class S> |
| V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT |
| #ifdef V8_ENABLE_CHECKS |
| @@ -604,20 +557,13 @@ template <class T> class Persistent // NOLINT |
| return reinterpret_cast<Persistent<T>&>(that); |
| } |
| + // TODO(dcarney): this is pretty useless, fix or remove |
| template <class S> V8_INLINE(Persistent<S>& As()) { // NOLINT |
| return Persistent<S>::Cast(*this); |
| } |
| -#endif |
| - |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - V8_DEPRECATED(static Persistent<T> New(Handle<T> that)); |
| - V8_INLINE(static Persistent<T> New(Isolate* isolate, Handle<T> that)); |
| - V8_INLINE(static Persistent<T> New(Isolate* isolate, Persistent<T> that)); |
| -#endif |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| - template <class S> V8_INLINE( |
| - bool operator==(const Persistent<S>& that) const) { |
| + 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; |
| @@ -633,53 +579,35 @@ template <class T> class Persistent // NOLINT |
| return *a == *b; |
| } |
| - template <class S> V8_INLINE( |
| - bool operator!=(const Persistent<S>& that) const) { |
| + 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); |
| } |
| -#endif |
| - |
| - V8_INLINE(void Dispose()); |
| - |
| - /** |
| - * Releases the storage cell referenced by this persistent handle. |
| - * Does not remove the reference to the cell from any handles. |
| - * This handle's reference, and any other references to the storage |
| - * cell remain and IsEmpty will still return false. |
| - */ |
| - // TODO(dcarney): deprecate |
| - V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); } |
| - /** |
| - * Make the reference to this object weak. When only weak handles |
| - * refer to the object, the garbage collector will perform a |
| - * callback to the given V8::NearDeathCallback function, passing |
| - * it the object reference and the given parameters. |
| - */ |
| - template<typename S, typename P> |
| + template<typename P> |
| V8_INLINE(void MakeWeak( |
| - P* parameters, |
| - typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| + P* parameter, |
| + typename WeakCallbackData<T, P>::Callback callback)); |
| - template<typename P> |
| + template<typename S, typename P> |
| V8_INLINE(void MakeWeak( |
| - P* parameters, |
| - typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| + P* parameter, |
| + typename WeakCallbackData<S, P>::Callback callback)); |
| + // TODO(dcarney): deprecate |
| template<typename S, typename P> |
| - V8_DEPRECATED(void MakeWeak( |
| - Isolate* isolate, |
| - P* parameters, |
| + V8_INLINE(void MakeWeak( |
| + P* parameter, |
| typename WeakReferenceCallbacks<S, P>::Revivable callback)); |
| + // TODO(dcarney): deprecate |
| template<typename P> |
| - V8_DEPRECATED(void MakeWeak( |
| - Isolate* isolate, |
| - P* parameters, |
| + V8_INLINE(void MakeWeak( |
| + P* parameter, |
| typename WeakReferenceCallbacks<T, P>::Revivable callback)); |
| V8_INLINE(void ClearWeak()); |
| @@ -754,68 +682,38 @@ template <class T> class Persistent // NOLINT |
| return WrapperClassId(); |
| } |
| - /** |
| - * Disposes the current contents of the handle and replaces it. |
| - */ |
| - V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other)); |
| - |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| - V8_INLINE(void Reset(Isolate* isolate, const Persistent<T>& other)); |
| -#endif |
| - |
| - /** |
| - * Returns the underlying raw pointer and clears the handle. The caller is |
| - * responsible of eventually destroying the underlying object (by creating a |
| - * Persistent handle which points to it and Disposing it). In the future, |
| - * destructing a Persistent will also Dispose it. With this function, the |
| - * embedder can let the Persistent go out of scope without it getting |
| - * disposed. |
| - */ |
| + // TODO(dcarney): remove |
| V8_INLINE(T* ClearAndLeak()); |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| - |
| - private: |
| - // TODO(dcarney): make unlinkable before cutover |
| - V8_INLINE(Persistent(const Persistent& that)) : val_(that.val_) {} |
| - // TODO(dcarney): make unlinkable before cutover |
| - V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT |
| - this->val_ = that.val_; |
| - return *this; |
| - } |
| + // TODO(dcarney) make private or remove |
| + // Only the garbage collector should do this, |
| + // and it can just change val_ directly |
| + // could temporarily just assert that the node is disposed |
| + V8_INLINE(void Clear()) { val_ = 0; } |
| - public: |
| + // TODO(dcarney): remove need for this in chrome |
| #ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| private: |
| #endif |
| - // TODO(dcarney): remove before cutover |
| template <class S> V8_INLINE(Persistent(S* that)) : val_(that) { } |
| - // TODO(dcarney): remove before cutover |
| V8_INLINE(T* operator*() const) { return val_; } |
| private: |
| - // TODO(dcarney): remove before cutover |
| - V8_INLINE(T* operator->() const) { return val_; } |
| - public: |
| -#endif |
| - |
| - private: |
| friend class Utils; |
| template<class F> friend class Handle; |
| template<class F> friend class Local; |
| - template<class F> friend class Persistent; |
| + template<class F1, class F2> friend class Persistent; |
| template<class F> friend class ReturnValue; |
| V8_INLINE(static T* New(Isolate* isolate, T* that)); |
| + template<class S, class M2> |
| + V8_INLINE(void Copy(const Persistent<S, M2>& that)); |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| T* val_; |
| -#endif |
| }; |
| - |
| /** |
| * A stack-allocated class that governs a number of local handles. |
| * After a handle scope has been created, all local handles will be |
| @@ -4807,10 +4705,13 @@ class V8_EXPORT V8 { |
| static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
| internal::Object** handle); |
| + static internal::Object** CopyPersistent(internal::Object** handle); |
|
marja
2013/08/23 13:02:40
This creates another legit Persistent for the same
|
| static void DisposeGlobal(internal::Object** global_handle); |
| typedef WeakReferenceCallbacks<Value, void>::Revivable RevivableCallback; |
| + typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
| static void MakeWeak(internal::Object** global_handle, |
| void* data, |
| + WeakCallback weak_callback, |
| RevivableCallback weak_reference_callback); |
| static void ClearWeak(internal::Object** global_handle); |
| static int Eternalize(internal::Isolate* isolate, |
| @@ -4819,7 +4720,7 @@ class V8_EXPORT V8 { |
| template <class T> friend class Handle; |
| template <class T> friend class Local; |
| - template <class T> friend class Persistent; |
| + template <class T, class M> friend class Persistent; |
| friend class Context; |
| }; |
| @@ -5160,11 +5061,7 @@ class V8_EXPORT Context { |
| } |
| // TODO(dcarney): deprecate |
| V8_INLINE(Scope(Isolate* isolate, Persistent<Context>& context)) // NOLINT |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| : context_(Handle<Context>::New(isolate, context)) { |
| -#else |
| - : context_(Local<Context>::New(isolate, context)) { |
| -#endif |
| context_->Enter(); |
| } |
| V8_INLINE(~Scope()) { context_->Exit(); } |
| @@ -5652,9 +5549,9 @@ Local<T> Local<T>::New(Isolate* isolate, Handle<T> that) { |
| return New(isolate, that.val_); |
| } |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| template <class T> |
| -Local<T> Local<T>::New(Isolate* isolate, const Persistent<T>& that) { |
| +template <class M> |
| +Local<T> Local<T>::New(Isolate* isolate, const Persistent<T, M>& that) { |
| return New(isolate, that.val_); |
| } |
| @@ -5666,7 +5563,6 @@ Handle<T> Handle<T>::New(Isolate* isolate, T* that) { |
| return Handle<T>(reinterpret_cast<T*>(HandleScope::CreateHandle( |
| reinterpret_cast<internal::Isolate*>(isolate), *p))); |
| } |
| -#endif |
| template <class T> |
| @@ -5694,27 +5590,8 @@ Local<T> Local<T>::GetEternal(Isolate* isolate, int index) { |
| } |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| -template <class T> |
| -Persistent<T> Persistent<T>::New(Handle<T> that) { |
| - return New(Isolate::GetCurrent(), that.val_); |
| -} |
| - |
| - |
| -template <class T> |
| -Persistent<T> Persistent<T>::New(Isolate* isolate, Handle<T> that) { |
| - return New(Isolate::GetCurrent(), that.val_); |
| -} |
| - |
| -template <class T> |
| -Persistent<T> Persistent<T>::New(Isolate* isolate, Persistent<T> that) { |
| - return New(Isolate::GetCurrent(), that.val_); |
| -} |
| -#endif |
| - |
| - |
| -template <class T> |
| -T* Persistent<T>::New(Isolate* isolate, T* that) { |
| +template <class T, class M> |
| +T* Persistent<T, M>::New(Isolate* isolate, T* that) { |
| if (that == NULL) return NULL; |
| internal::Object** p = reinterpret_cast<internal::Object**>(that); |
| return reinterpret_cast<T*>( |
| @@ -5723,8 +5600,20 @@ T* Persistent<T>::New(Isolate* isolate, T* that) { |
| } |
| -template <class T> |
| -bool Persistent<T>::IsIndependent() const { |
| +template <class T, class M> |
| +template <class S, class M2> |
| +void Persistent<T, M>::Copy(const Persistent<S, M2>& that) { |
| + TYPE_CHECK(T, S); |
| + Reset(); |
| + if (that.IsEmpty()) return; |
| + internal::Object** p = reinterpret_cast<internal::Object**>(that.val_); |
| + this->val_ = reinterpret_cast<T*>(V8::CopyPersistent(p)); |
| + M::Copy(that, this); |
| +} |
| + |
| + |
| +template <class T, class M> |
| +bool Persistent<T, M>::IsIndependent() const { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return false; |
| return I::GetNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| @@ -5732,8 +5621,8 @@ bool Persistent<T>::IsIndependent() const { |
| } |
| -template <class T> |
| -bool Persistent<T>::IsNearDeath() const { |
| +template <class T, class M> |
| +bool Persistent<T, M>::IsNearDeath() const { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return false; |
| uint8_t node_state = |
| @@ -5743,8 +5632,8 @@ bool Persistent<T>::IsNearDeath() const { |
| } |
| -template <class T> |
| -bool Persistent<T>::IsWeak() const { |
| +template <class T, class M> |
| +bool Persistent<T, M>::IsWeak() const { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return false; |
| return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) == |
| @@ -5752,66 +5641,89 @@ bool Persistent<T>::IsWeak() const { |
| } |
| -template <class T> |
| -void Persistent<T>::Dispose() { |
| +template <class T, class M> |
| +void Persistent<T, M>::Reset() { |
| if (this->IsEmpty()) return; |
| V8::DisposeGlobal(reinterpret_cast<internal::Object**>(this->val_)); |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| val_ = 0; |
| -#endif |
| } |
| -template <class T> |
| +template <class T, class M> |
| +template <class S> |
| +void Persistent<T, M>::Reset(Isolate* isolate, const Handle<S>& other) { |
| + TYPE_CHECK(T, S); |
| + Reset(); |
| + if (other.IsEmpty()) return; |
| + this->val_ = New(isolate, other.val_); |
| +} |
| + |
| + |
| +template <class T, class M> |
| +template <class S, class M2> |
| +void Persistent<T, M>::Reset(Isolate* isolate, |
| + const Persistent<S, M2>& other) { |
| + TYPE_CHECK(T, S); |
| + Reset(); |
| + if (other.IsEmpty()) return; |
| + this->val_ = New(isolate, other.val_); |
| +} |
| + |
| + |
| +template <class T, class M> |
| template <typename S, typename P> |
| -void Persistent<T>::MakeWeak( |
| - P* parameters, |
| - typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| +void Persistent<T, M>::MakeWeak( |
| + P* parameter, |
| + typename WeakCallbackData<S, P>::Callback callback) { |
| TYPE_CHECK(S, T); |
| - typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
| + typedef typename WeakCallbackData<Value, void>::Callback Callback; |
| V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
| - parameters, |
| - reinterpret_cast<Revivable>(callback)); |
| + parameter, |
| + reinterpret_cast<Callback>(callback), |
| + NULL); |
| } |
| -template <class T> |
| +template <class T, class M> |
| template <typename P> |
| -void Persistent<T>::MakeWeak( |
| - P* parameters, |
| - typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| - MakeWeak<T, P>(parameters, callback); |
| +void Persistent<T, M>::MakeWeak( |
| + P* parameter, |
| + typename WeakCallbackData<T, P>::Callback callback) { |
| + MakeWeak<T, P>(parameter, callback); |
| } |
| -template <class T> |
| +template <class T, class M> |
| template <typename S, typename P> |
| -void Persistent<T>::MakeWeak( |
| - Isolate* isolate, |
| +void Persistent<T, M>::MakeWeak( |
| P* parameters, |
| typename WeakReferenceCallbacks<S, P>::Revivable callback) { |
| - MakeWeak<S, P>(parameters, callback); |
| + TYPE_CHECK(S, T); |
| + typedef typename WeakReferenceCallbacks<Value, void>::Revivable Revivable; |
| + V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
| + parameters, |
| + NULL, |
| + reinterpret_cast<Revivable>(callback)); |
| } |
| -template <class T> |
| -template<typename P> |
| -void Persistent<T>::MakeWeak( |
| - Isolate* isolate, |
| +template <class T, class M> |
| +template <typename P> |
| +void Persistent<T, M>::MakeWeak( |
| P* parameters, |
| typename WeakReferenceCallbacks<T, P>::Revivable callback) { |
| - MakeWeak<P>(parameters, callback); |
| + MakeWeak<T, P>(parameters, callback); |
| } |
| -template <class T> |
| -void Persistent<T>::ClearWeak() { |
| +template <class T, class M> |
| +void Persistent<T, M>::ClearWeak() { |
| V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_)); |
| } |
| -template <class T> |
| -void Persistent<T>::MarkIndependent() { |
| +template <class T, class M> |
| +void Persistent<T, M>::MarkIndependent() { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return; |
| I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| @@ -5820,8 +5732,8 @@ void Persistent<T>::MarkIndependent() { |
| } |
| -template <class T> |
| -void Persistent<T>::MarkPartiallyDependent() { |
| +template <class T, class M> |
| +void Persistent<T, M>::MarkPartiallyDependent() { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return; |
| I::UpdateNodeFlag(reinterpret_cast<internal::Object**>(this->val_), |
| @@ -5830,54 +5742,17 @@ void Persistent<T>::MarkPartiallyDependent() { |
| } |
| -template <class T> |
| -void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) { |
| - Dispose(isolate); |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - *this = *New(isolate, other); |
| -#else |
| - if (other.IsEmpty()) { |
| - this->val_ = NULL; |
| - return; |
| - } |
| - internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| - this->val_ = reinterpret_cast<T*>( |
| - V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| -#endif |
| -} |
| - |
| - |
| -#ifndef V8_USE_UNSAFE_HANDLES |
| -template <class T> |
| -void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) { |
| - Dispose(isolate); |
| - if (other.IsEmpty()) { |
| - this->val_ = NULL; |
| - return; |
| - } |
| - internal::Object** p = reinterpret_cast<internal::Object**>(other.val_); |
| - this->val_ = reinterpret_cast<T*>( |
| - V8::GlobalizeReference(reinterpret_cast<internal::Isolate*>(isolate), p)); |
| -} |
| -#endif |
| - |
| - |
| -template <class T> |
| -T* Persistent<T>::ClearAndLeak() { |
| +template <class T, class M> |
| +T* Persistent<T, M>::ClearAndLeak() { |
| T* old; |
| -#ifdef V8_USE_UNSAFE_HANDLES |
| - old = **this; |
| - *this = Persistent<T>(); |
| -#else |
| old = val_; |
| val_ = NULL; |
| -#endif |
| return old; |
| } |
| -template <class T> |
| -void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
| +template <class T, class M> |
| +void Persistent<T, M>::SetWrapperClassId(uint16_t class_id) { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return; |
| internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |
| @@ -5886,8 +5761,8 @@ void Persistent<T>::SetWrapperClassId(uint16_t class_id) { |
| } |
| -template <class T> |
| -uint16_t Persistent<T>::WrapperClassId() const { |
| +template <class T, class M> |
| +uint16_t Persistent<T, M>::WrapperClassId() const { |
| typedef internal::Internals I; |
| if (this->IsEmpty()) return 0; |
| internal::Object** obj = reinterpret_cast<internal::Object**>(this->val_); |