Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index f70f45769bb5ca58ff6d178b7129f92448301e8c..7c666ff356a0f88c3b5c27d26c3298618a0532ec 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -516,6 +516,18 @@ template <class T> class PersistentBase { |
P* parameter, |
typename WeakCallbackData<S, P>::Callback callback); |
+ // Phantom persistents work like weak persistents, except that the pointer to |
+ // the object being collected is not available in the finalization callback. |
+ // This enables the garbage collector to collect the object and any objects |
+ // it references transitively in one GC cycle. |
+ template <typename P> |
+ V8_INLINE void SetPhantom(P* parameter, |
+ typename WeakCallbackData<T, P>::Callback callback); |
+ |
+ template <typename S, typename P> |
+ V8_INLINE void SetPhantom(P* parameter, |
+ typename WeakCallbackData<S, P>::Callback callback); |
+ |
template<typename P> |
V8_INLINE P* ClearWeak(); |
@@ -5330,14 +5342,15 @@ class V8_EXPORT V8 { |
private: |
V8(); |
+ enum WeakHandleType { PhantomHandle, NonphantomHandle }; |
+ |
static internal::Object** GlobalizeReference(internal::Isolate* isolate, |
internal::Object** handle); |
static internal::Object** CopyPersistent(internal::Object** handle); |
static void DisposeGlobal(internal::Object** global_handle); |
typedef WeakCallbackData<Value, void>::Callback WeakCallback; |
- static void MakeWeak(internal::Object** global_handle, |
- void* data, |
- WeakCallback weak_callback); |
+ static void MakeWeak(internal::Object** global_handle, void* data, |
+ WeakCallback weak_callback, WeakHandleType phantom); |
static void* ClearWeak(internal::Object** global_handle); |
static void Eternalize(Isolate* isolate, |
Value* handle, |
@@ -6200,9 +6213,8 @@ void PersistentBase<T>::SetWeak( |
typename WeakCallbackData<S, P>::Callback callback) { |
TYPE_CHECK(S, T); |
typedef typename WeakCallbackData<Value, void>::Callback Callback; |
- V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), |
- parameter, |
- reinterpret_cast<Callback>(callback)); |
+ V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, |
+ reinterpret_cast<Callback>(callback), V8::NonphantomHandle); |
} |
@@ -6216,7 +6228,26 @@ void PersistentBase<T>::SetWeak( |
template <class T> |
-template<typename P> |
+template <typename S, typename P> |
+void PersistentBase<T>::SetPhantom( |
+ P* parameter, typename WeakCallbackData<S, P>::Callback callback) { |
+ TYPE_CHECK(S, T); |
+ typedef typename WeakCallbackData<Value, void>::Callback Callback; |
+ V8::MakeWeak(reinterpret_cast<internal::Object**>(this->val_), parameter, |
+ reinterpret_cast<Callback>(callback), V8::PhantomHandle); |
+} |
+ |
+ |
+template <class T> |
+template <typename P> |
+void PersistentBase<T>::SetPhantom( |
+ P* parameter, typename WeakCallbackData<T, P>::Callback callback) { |
+ SetPhantom<T, P>(parameter, callback); |
+} |
+ |
+ |
+template <class T> |
+template <typename P> |
P* PersistentBase<T>::ClearWeak() { |
return reinterpret_cast<P*>( |
V8::ClearWeak(reinterpret_cast<internal::Object**>(this->val_))); |