Reviewers: Michael Starzinger,

Description:
Add Isolate parameter to HandleScope::NumberOfHandles.

LOG=y
BUG=324225

Please review this at https://codereview.chromium.org/128233002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+22, -26 lines):
  M include/v8.h
  M src/api.cc
  M test/cctest/test-api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index b2cc9eb8392ca28207164f81e9ede44a344495dd..c56295ac78dd8a4c6561f97f12717e5972381520 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -823,7 +823,7 @@ class V8_EXPORT HandleScope {
   /**
    * Counts the number of allocated handles.
    */
-  static int NumberOfHandles();
+  static int NumberOfHandles(Isolate* isolate);

  private:
   /**
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index a8ab69f85dda4d493d179f5aac4a67f5341778ec..42965b61560389d5018ef90b6b4ce8c3fff4a0c1 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -662,12 +662,9 @@ HandleScope::~HandleScope() {
 }


-int HandleScope::NumberOfHandles() {
-  i::Isolate* isolate = i::Isolate::Current();
- if (!EnsureInitializedForIsolate(isolate, "HandleScope::NumberOfHandles")) {
-    return 0;
-  }
-  return i::HandleScope::NumberOfHandles(isolate);
+int HandleScope::NumberOfHandles(Isolate* isolate) {
+  return i::HandleScope::NumberOfHandles(
+      reinterpret_cast<i::Isolate*>(isolate));
 }


Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 9e759d2b03cf3e3f3606bde6978c3f41712ad4c1..3e3afeeb909a1bef8857704f525d0d04fa97407f 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -11022,45 +11022,44 @@ THREADED_TEST(CallableObject) {
 }


-static int CountHandles() {
-  return v8::HandleScope::NumberOfHandles();
-}
-
-
-static int Recurse(int depth, int iterations) {
-  v8::HandleScope scope(CcTest::isolate());
-  if (depth == 0) return CountHandles();
+static int Recurse(v8::Isolate* isolate, int depth, int iterations) {
+  v8::HandleScope scope(isolate);
+  if (depth == 0) return v8::HandleScope::NumberOfHandles(isolate);
   for (int i = 0; i < iterations; i++) {
-    Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42));
+    Local<v8::Number> n(v8::Integer::New(isolate, 42));
   }
-  return Recurse(depth - 1, iterations);
+  return Recurse(isolate, depth - 1, iterations);
 }


 THREADED_TEST(HandleIteration) {
   static const int kIterations = 500;
   static const int kNesting = 200;
-  CHECK_EQ(0, CountHandles());
+  LocalContext context;
+  v8::Isolate* isolate = context->GetIsolate();
+  v8::HandleScope scope0(isolate);
+  CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
   {
-    v8::HandleScope scope1(CcTest::isolate());
-    CHECK_EQ(0, CountHandles());
+    v8::HandleScope scope1(isolate);
+    CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
     for (int i = 0; i < kIterations; i++) {
       Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42));
-      CHECK_EQ(i + 1, CountHandles());
+      CHECK_EQ(i + 1, v8::HandleScope::NumberOfHandles(isolate));
     }

-    CHECK_EQ(kIterations, CountHandles());
+    CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate));
     {
       v8::HandleScope scope2(CcTest::isolate());
       for (int j = 0; j < kIterations; j++) {
         Local<v8::Number> n(v8::Integer::New(CcTest::isolate(), 42));
-        CHECK_EQ(j + 1 + kIterations, CountHandles());
+        CHECK_EQ(j + 1 + kIterations,
+                 v8::HandleScope::NumberOfHandles(isolate));
       }
     }
-    CHECK_EQ(kIterations, CountHandles());
+    CHECK_EQ(kIterations, v8::HandleScope::NumberOfHandles(isolate));
   }
-  CHECK_EQ(0, CountHandles());
-  CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
+  CHECK_EQ(0, v8::HandleScope::NumberOfHandles(isolate));
+ CHECK_EQ(kNesting * kIterations, Recurse(isolate, kNesting, kIterations));
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to