Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: include/v8.h

Issue 17443004: new persistent semantics (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 9ddde5294b168900f3c8fbf318673b978e04a4a9..f2727d3a868384b593b6388109f8c8afcf3d2398 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -142,7 +142,10 @@ class Utils;
class Value;
template <class T> class Handle;
template <class T> class Local;
-template <class T> class Persistent;
+template<class T, class P> class NonCopyablePersistentModifier;
+template<class T,
+ class M = NonCopyablePersistentModifier<T, void> > class Persistent;
+template<class T, class P> class WeakCallbackObject;
class FunctionTemplate;
class ObjectTemplate;
class Data;
@@ -192,27 +195,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) \
@@ -253,13 +235,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
@@ -308,7 +283,6 @@ template <class T> class Handle {
return *a == *b;
}
-#ifndef V8_USE_UNSAFE_HANDLES
template <class S> V8_INLINE(
bool operator==(const Persistent<S>& that) const) {
internal::Object** a = reinterpret_cast<internal::Object**>(**this);
@@ -317,7 +291,6 @@ template <class T> class Handle {
if (b == 0) return false;
return *a == *b;
}
-#endif
/**
* Checks whether two handles are different.
@@ -342,15 +315,22 @@ 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_);
}
+ // TODO(dcarney): better name
+ // TODO(dcarney): implement
+ // This is a useful helper function for managing resources tied to
+ // a handle dynamically
+ template<class P>
+ void WeakBind(Isolate* isolate,
+ P* parameter,
+ void (*WeakBindFunction)(Isolate* isolate, P* parameter));
+
#ifndef V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR
private:
@@ -359,11 +339,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;
@@ -377,9 +356,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,10 +384,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
@@ -419,12 +392,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);
@@ -437,20 +408,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;
@@ -465,117 +435,150 @@ 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
+
+// TODO(dcarney): better name
+template<class P>
+class PersistentData {
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; }
+ // TODO(dcarney): fill out implementation
+ V8_INLINE(bool IsWeak());
+ V8_INLINE(bool IsIndependent());
+ V8_INLINE(P* GetParameter());
+ private:
+ uint8_t flags_;
+ 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))
- : val_(New(isolate, *that)) { }
- template <class S> V8_INLINE(Persistent(Isolate* isolate,
- Persistent<S>& that)) // NOLINT
- : val_(New(isolate, *that)) { }
+template<typename T,
+ typename P,
+ typename M = NonCopyablePersistentModifier<T, void> >
+class WeakReferenceCallbacks {
+ public:
+ typedef void (*Revivable)(Isolate* isolate,
+ Persistent<T, M>* object,
+ P* parameter);
+ // TODO(dcarney): better name
+ typedef void NewCallbackName(const WeakCallbackObject<T, P> &);
+};
-#else
- /**
- * Creates an empty persistent handle that doesn't point to any
- * storage cell.
- */
- V8_INLINE(Persistent()) : Handle<T>() { }
- /**
- * 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);
+// TODO(dcarney): better name
+template<class T, class P>
+class WeakCallbackObject {
+ public:
+ // TODO(dcarney): getters, make members private, etc
+ Isolate* isolate_;
+ // 'handle' for the persistent cell
+ // stack allocated
+ // not handle scoped
+ Handle<T> handle_;
+ const PersistentData<P>& data_;
+};
+
+
+// TODO(dcarney): better name
+// this class should make persistent mimic current behaviour
+template<class T, class P>
+class NonCopyablePersistentModifier {
+ typedef Persistent<T, NonCopyablePersistentModifier<T, P> > MyPersistent;
+ // TODO(dcarney): come up with a good compile error here.
+ template<class O>
+ V8_INLINE(static void Uncompilable()) {
+ TYPE_CHECK(O, Primitive);
+ }
+
+ public:
+ typedef P WeakParameter;
+ // This will be called on copy and assign
+ // in the case the handle is non-empty
+ V8_INLINE(static void Initialize(const PersistentData<P>& data,
+ MyPersistent* persistent)) {
+ Uncompilable<Object>();
+ }
+ // This will be called on move constructors
+ // in the case the handle is non-empty
+ V8_INLINE(static void Move(P** parameter)) {
+ Uncompilable<Object>();
}
+ // TODO(dcarney): have a static WeakDispose that gc can check against
+ // This will be called in the first sweep to determine if
+ // the persistent can be disposed early
+ static MyPersistent* WeakDispose(P* parameter) {
+ return NULL;
+ }
+ // TODO(dcarney): remove this
+ V8_INLINE(static bool AutoDispose()) { return false; }
+};
- template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { }
- /**
- * 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.
- */
+// TODO(dcarney): new comments
+// M is 'Modifier' - the templated class that
+// can deal with copying and moving the weak parameter
+template <class T, class M> class Persistent {
+ public:
+ typedef typename M::WeakParameter WeakParameter;
+ // normal constructors
+ V8_INLINE(Persistent()) : val_(0) { }
template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S> that))
- : Handle<T>(New(isolate, that)) { }
+ : val_(New(isolate, *that)) { }
+ template <class S, class M2>
+ V8_INLINE(Persistent(Isolate* isolate,
+ const Persistent<S, M2>& that))
+ : val_(New(that)) { }
+ // destructor
+ V8_INLINE(~Persistent()) {
+ // TODO(dcarney): Remove this check. Always dispose.
+ if (M::AutoDispose()) Reset();
+ }
+ // copy and assign operators
+ // Duplicate the storage cell and reinitialize
+ V8_INLINE(Persistent(const Persistent& that)) : val_(0) {
+ Copy(that);
+ }
+ V8_INLINE(Persistent& operator=(const Persistent& that)) { // NOLINT
+ Copy(that);
+ return *this;
+ }
+ // TODO(dcarney): move into private section at bottom
+ private:
+ template<class S, class M2>
+ V8_INLINE(void Copy(const Persistent<S, M2>& that)) {
+ // TODO(dcarney): New and Copy can be one function
+ this->val_ = New(that);
+ if (this->val_ == NULL) return;
+ const PersistentData<typename M2::WeakParameter>& data = that.GetData();
+ M::template Initialize<typename M2::WeakParameter>(data, this);
+ }
+ template<class S, class M2>
+ V8_INLINE(static T* New(const Persistent<S, M2>& that));
+ // TODO(dcarney): implement
+ // maybe this can return a reference into
+ // part of GlobalHandle::Node
+ // it needs to be inlined, and preferably pretty fast
+ const PersistentData<WeakParameter>& GetData();
+
+ public:
/**
- * "Casts" a plain handle which is known to be a persistent handle
- * to a persistent handle.
+ * Disposes the current contents of the handle and replaces it.
*/
- template <class S> explicit V8_INLINE(Persistent(Handle<S> that))
- : Handle<T>(*that) { }
-
-#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));
+ V8_INLINE(void Reset()) {
+ Dispose();
}
+ V8_INLINE(void Reset(Isolate* isolate, const Handle<T>& other));
+ template <class M2>
+ V8_INLINE(void Reset(Isolate* isolate, const Persistent<T, M2>& other));
+ // TODO(dcarney): deprecate
+ V8_INLINE(void Dispose());
+ // TODO(dcarney): deprecate
+ V8_INLINE(void Dispose(Isolate* isolate)) { Dispose(); }
- template <class S> V8_INLINE(Persistent<S> As()) {
- return Persistent<S>::Cast(*this);
- }
+ V8_INLINE(bool IsEmpty() const) { return val_ == 0; }
-#else
+ // TODO(dcarney): this is pretty useless, fix or remove
template <class S>
- V8_INLINE(static Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT
+ static V8_INLINE(Persistent<T>& Cast(Persistent<S>& that)) { // NOLINT
#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.
@@ -584,20 +587,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;
@@ -605,53 +601,53 @@ template <class T> class Persistent // NOLINT
return *a == *b;
}
- 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** b = reinterpret_cast<internal::Object**>(*that);
if (a == 0) return b == 0;
if (b == 0) return false;
return *a == *b;
}
-#endif
- V8_INLINE(void Dispose());
+ // New weak callbacks
+ // must be able to static_cast P into P2
+ // TODO(dcarney): implement
+ template<typename P2>
+ V8_INLINE(void MakeWeak(
+ P2* parameters,
+ typename WeakReferenceCallbacks<T, P2>::NewCallbackName callback));
- /**
- * 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(); }
+ // Use a weak callback defined in M
+ V8_INLINE(void MakeWeak(WeakParameter* parameters)) {
+ MakeWeak<WeakParameter>(parameters, M::WeakCallback);
+ }
- /**
- * 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>
+ // must be able to static_cast P into P2
+ // TODO(dcarney): deprecate
+ template<typename S, typename P2>
V8_INLINE(void MakeWeak(
- P* parameters,
- typename WeakReferenceCallbacks<S, P>::Revivable callback));
+ P2* parameters,
+ typename WeakReferenceCallbacks<S, P2>::Revivable callback));
- template<typename P>
+ // must be able to static_cast P into P2
+ // TODO(dcarney): deprecate
+ template<typename P2>
V8_INLINE(void MakeWeak(
- P* parameters,
- typename WeakReferenceCallbacks<T, P>::Revivable callback));
+ P2* parameters,
+ typename WeakReferenceCallbacks<T, P2>::Revivable callback));
- template<typename S, typename P>
+ template<typename S, typename P2>
V8_DEPRECATED(void MakeWeak(
Isolate* isolate,
- P* parameters,
- typename WeakReferenceCallbacks<S, P>::Revivable callback));
+ P2* parameters,
+ typename WeakReferenceCallbacks<S, P2>::Revivable callback));
- template<typename P>
+ template<typename P2>
V8_DEPRECATED(void MakeWeak(
Isolate* isolate,
- P* parameters,
- typename WeakReferenceCallbacks<T, P>::Revivable callback));
+ P2* parameters,
+ typename WeakReferenceCallbacks<T, P2>::Revivable callback));
V8_INLINE(void ClearWeak());
@@ -725,68 +721,36 @@ 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));
-#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
@@ -4630,7 +4594,7 @@ class V8EXPORT 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;
};
@@ -4968,11 +4932,7 @@ class V8EXPORT 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(); }
@@ -5458,9 +5418,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_);
}
@@ -5472,7 +5432,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>
@@ -5485,27 +5444,8 @@ Local<T> Local<T>::New(Isolate* isolate, T* that) {
}
-#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*>(
@@ -5514,8 +5454,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>
+T* Persistent<T, M>::New(const Persistent<S, M2>& that) {
+ if (*that == NULL) return NULL;
+ // TODO(dcarney): implement this correctly,
+ // isolate is available in GlobalHandles::Node, get it from there
+ // This should not be like current new but should copy everything
+ // over
+ return New(Isolate::GetCurrent(), *that);
+}
+
+
+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_),
@@ -5523,8 +5475,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;
return I::GetNodeState(reinterpret_cast<internal::Object**>(this->val_)) ==
@@ -5532,8 +5484,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_)) ==
@@ -5541,19 +5493,17 @@ bool Persistent<T>::IsWeak() const {
}
-template <class T>
-void Persistent<T>::Dispose() {
+template <class T, class M>
+void Persistent<T, M>::Dispose() {
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 <typename S, typename P>
-void Persistent<T>::MakeWeak(
+void Persistent<T, M>::MakeWeak(
P* parameters,
typename WeakReferenceCallbacks<S, P>::Revivable callback) {
TYPE_CHECK(S, T);
@@ -5564,18 +5514,18 @@ void Persistent<T>::MakeWeak(
}
-template <class T>
+template <class T, class M>
template <typename P>
-void Persistent<T>::MakeWeak(
+void Persistent<T, M>::MakeWeak(
P* parameters,
typename WeakReferenceCallbacks<T, P>::Revivable callback) {
MakeWeak<T, P>(parameters, callback);
}
-template <class T>
+template <class T, class M>
template <typename S, typename P>
-void Persistent<T>::MakeWeak(
+void Persistent<T, M>::MakeWeak(
Isolate* isolate,
P* parameters,
typename WeakReferenceCallbacks<S, P>::Revivable callback) {
@@ -5583,9 +5533,9 @@ void Persistent<T>::MakeWeak(
}
-template <class T>
+template <class T, class M>
template<typename P>
-void Persistent<T>::MakeWeak(
+void Persistent<T, M>::MakeWeak(
Isolate* isolate,
P* parameters,
typename WeakReferenceCallbacks<T, P>::Revivable callback) {
@@ -5593,14 +5543,14 @@ void Persistent<T>::MakeWeak(
}
-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_),
@@ -5609,8 +5559,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_),
@@ -5619,12 +5569,9 @@ 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
+template <class T, class M>
+void Persistent<T, M>::Reset(Isolate* isolate, const Handle<T>& other) {
+ Dispose();
if (other.IsEmpty()) {
this->val_ = NULL;
return;
@@ -5632,13 +5579,13 @@ void Persistent<T>::Reset(Isolate* isolate, const Handle<T>& other) {
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) {
+template <class T, class M>
+template <class M2>
+void Persistent<T, M>::Reset(Isolate* isolate,
+ const Persistent<T, M2>& other) {
Dispose(isolate);
if (other.IsEmpty()) {
this->val_ = NULL;
@@ -5648,25 +5595,19 @@ void Persistent<T>::Reset(Isolate* isolate, const Persistent<T>& other) {
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_);
@@ -5675,8 +5616,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_);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698