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

Committed: https://code.google.com/p/v8/source/detail?r=12852

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@12854 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

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

index db0240d..7d9cccc 100644 (file)
@@ -416,6 +416,7 @@ template <class T> class Persistent : public Handle<T> {
 
   /** Returns true if this handle was previously marked as independent. */
   inline bool IsIndependent() const;
+  inline bool IsIndependent(Isolate* isolate) const;
 
   /** Checks if the handle holds the only reference to an object. */
   inline bool IsNearDeath() const;
@@ -3520,6 +3521,8 @@ class V8EXPORT V8 {
   static void ClearWeak(internal::Object** global_handle);
   static void MarkIndependent(internal::Object** global_handle);
   static bool IsGlobalIndependent(internal::Object** global_handle);
+  static bool IsGlobalIndependent(internal::Isolate* isolate,
+                                  internal::Object** global_handle);
   static bool IsGlobalNearDeath(internal::Object** global_handle);
   static bool IsGlobalWeak(internal::Object** global_handle);
   static void SetWrapperClassId(internal::Object** global_handle,
@@ -4262,6 +4265,14 @@ bool Persistent<T>::IsIndependent() const {
 
 
 template <class T>
+bool Persistent<T>::IsIndependent(Isolate* isolate) const {
+  if (this->IsEmpty()) return false;
+  return V8::IsGlobalIndependent(reinterpret_cast<internal::Isolate*>(isolate),
+                                 reinterpret_cast<internal::Object**>(**this));
+}
+
+
+template <class T>
 bool Persistent<T>::IsNearDeath() const {
   if (this->IsEmpty()) return false;
   return V8::IsGlobalNearDeath(reinterpret_cast<internal::Object**>(**this));
index 8b60c49..145608b 100644 (file)
@@ -659,6 +659,14 @@ bool V8::IsGlobalIndependent(i::Object** obj) {
 }
 
 
+bool V8::IsGlobalIndependent(i::Isolate* isolate, i::Object** obj) {
+  ASSERT(isolate == i::Isolate::Current());
+  LOG_API(isolate, "IsGlobalIndependent");
+  if (!isolate->IsInitialized()) return false;
+  return i::GlobalHandles::IsIndependent(obj);
+}
+
+
 bool V8::IsGlobalNearDeath(i::Object** obj) {
   i::Isolate* isolate = i::Isolate::Current();
   LOG_API(isolate, "IsGlobalNearDeath");
index e42c1ed..a4dcc54 100644 (file)
@@ -5419,11 +5419,14 @@ THREADED_TEST(IndependentWeakHandle) {
     object_a = v8::Persistent<v8::Object>::New(v8::Object::New());
   }
 
+  v8::Isolate* isolate = v8::Isolate::GetCurrent();
   bool object_a_disposed = false;
   object_a.MakeWeak(&object_a_disposed, &DisposeAndSetFlag);
   CHECK(!object_a.IsIndependent());
+  CHECK(!object_a.IsIndependent(isolate));
   object_a.MarkIndependent();
   CHECK(object_a.IsIndependent());
+  CHECK(object_a.IsIndependent(isolate));
   HEAP->PerformScavenge();
   CHECK(object_a_disposed);
 }