Implement IsIndependent(Isolate*)
authormstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 5 Nov 2012 12:35:51 +0000 (12:35 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 5 Nov 2012 12:35:51 +0000 (12:35 +0000)
BUG=
TEST=cctest/test-api/IndependentWeakHandle

Review URL: https://codereview.chromium.org/11368053
Patch from Kentaro Hara <haraken@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12852 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc
test/cctest/test-api.cc

index 811f8ffd26128c85ba0b537792eae0cbc0c98315..db0240d70a205e9623014963223ad559d4325804 100644 (file)
@@ -392,6 +392,7 @@ template <class T> class Persistent : public Handle<T> {
    * cell remain and IsEmpty will still return false.
    */
   inline void Dispose();
+  inline void Dispose(Isolate* isolate);
 
   /**
    * Make the reference to this object weak.  When only weak handles
@@ -3511,6 +3512,8 @@ class V8EXPORT V8 {
 
   static internal::Object** GlobalizeReference(internal::Object** handle);
   static void DisposeGlobal(internal::Object** global_handle);
+  static void DisposeGlobal(internal::Isolate* isolate,
+                            internal::Object** global_handle);
   static void MakeWeak(internal::Object** global_handle,
                        void* data,
                        WeakReferenceCallback);
@@ -4279,6 +4282,14 @@ void Persistent<T>::Dispose() {
 }
 
 
+template <class T>
+void Persistent<T>::Dispose(Isolate* isolate) {
+  if (this->IsEmpty()) return;
+  V8::DisposeGlobal(reinterpret_cast<internal::Isolate*>(isolate),
+                    reinterpret_cast<internal::Object**>(**this));
+}
+
+
 template <class T>
 Persistent<T>::Persistent() : Handle<T>() { }
 
index 1c15134f42934a54089562d6c10d784f6892080a..8b60c49c8c39637f2f1a2b23c567daf83d96862e 100644 (file)
@@ -682,6 +682,14 @@ void V8::DisposeGlobal(i::Object** obj) {
   isolate->global_handles()->Destroy(obj);
 }
 
+
+void V8::DisposeGlobal(i::Isolate* isolate, i::Object** obj) {
+  ASSERT(isolate == i::Isolate::Current());
+  LOG_API(isolate, "DisposeGlobal");
+  if (!isolate->IsInitialized()) return;
+  isolate->global_handles()->Destroy(obj);
+}
+
 // --- H a n d l e s ---
 
 
index 84c0612eb665bd53869d193c560f20e2febdf758..e42c1eded2050fd6b197fa9ff53602a39a8d2074 100644 (file)
@@ -2345,6 +2345,14 @@ THREADED_TEST(GlobalHandle) {
   }
   CHECK_EQ(global->Length(), 3);
   global.Dispose();
+
+  {
+    v8::HandleScope scope;
+    Local<String> str = v8_str("str");
+    global = v8::Persistent<String>::New(str);
+  }
+  CHECK_EQ(global->Length(), 3);
+  global.Dispose(v8::Isolate::GetCurrent());
 }