Bug 1056418 - Fix testGCFinalizeCallback to not to clobber its global r=terrence
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 21 Aug 2014 16:56:56 +0100
changeset 200849 359dfa6e087802ff51480cb806c6b81039cab9e4
parent 200848 d870412529127feda45d2b2f64cbde970713ae10
child 200850 36ffb9b24c56e71062bd621036c75a5c4911d576
push id48013
push userjcoppeard@mozilla.com
push dateThu, 21 Aug 2014 15:57:15 +0000
treeherdermozilla-inbound@359dfa6e0878 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs1056418
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1056418 - Fix testGCFinalizeCallback to not to clobber its global r=terrence
js/src/jsapi-tests/testGCFinalizeCallback.cpp
--- a/js/src/jsapi-tests/testGCFinalizeCallback.cpp
+++ b/js/src/jsapi-tests/testGCFinalizeCallback.cpp
@@ -7,17 +7,16 @@
 static const unsigned BufferSize = 20;
 static unsigned FinalizeCalls = 0;
 static JSFinalizeStatus StatusBuffer[BufferSize];
 static bool IsCompartmentGCBuffer[BufferSize];
 
 BEGIN_TEST(testGCFinalizeCallback)
 {
     JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_INCREMENTAL);
-    JS_AddFinalizeCallback(rt, FinalizeCallback, nullptr);
 
     /* Full GC, non-incremental. */
     FinalizeCalls = 0;
     JS_GC(rt);
     CHECK(rt->gc.isFullGc());
     CHECK(checkSingleGroup());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(false));
@@ -27,19 +26,19 @@ BEGIN_TEST(testGCFinalizeCallback)
     JS::PrepareForFullGC(rt);
     JS::IncrementalGC(rt, JS::gcreason::API, 1000000);
     CHECK(rt->gc.state() == js::gc::NO_INCREMENTAL);
     CHECK(rt->gc.isFullGc());
     CHECK(checkMultipleGroups());
     CHECK(checkFinalizeStatus());
     CHECK(checkFinalizeIsCompartmentGC(false));
 
-    JS::RootedObject global1(cx, createGlobal());
-    JS::RootedObject global2(cx, createGlobal());
-    JS::RootedObject global3(cx, createGlobal());
+    JS::RootedObject global1(cx, createTestGlobal());
+    JS::RootedObject global2(cx, createTestGlobal());
+    JS::RootedObject global3(cx, createTestGlobal());
     CHECK(global1);
     CHECK(global2);
     CHECK(global3);
 
     /* Compartment GC, non-incremental, single compartment. */
     FinalizeCalls = 0;
     JS::PrepareZoneForGC(global1->zone());
     JS::GCForReason(rt, JS::gcreason::API);
@@ -87,17 +86,17 @@ BEGIN_TEST(testGCFinalizeCallback)
 
     FinalizeCalls = 0;
     JS_SetGCZeal(cx, 9, 1000000);
     JS::PrepareForFullGC(rt);
     rt->gc.gcDebugSlice(true, 1);
     CHECK(rt->gc.state() == js::gc::MARK);
     CHECK(rt->gc.isFullGc());
 
-    JS::RootedObject global4(cx, createGlobal());
+    JS::RootedObject global4(cx, createTestGlobal());
     rt->gc.gcDebugSlice(true, 1);
     CHECK(rt->gc.state() == js::gc::NO_INCREMENTAL);
     CHECK(!rt->gc.isFullGc());
     CHECK(checkMultipleGroups());
     CHECK(checkFinalizeStatus());
 
     for (unsigned i = 0; i < FinalizeCalls - 1; ++i)
         CHECK(!IsCompartmentGCBuffer[i]);
@@ -111,18 +110,39 @@ BEGIN_TEST(testGCFinalizeCallback)
      * Make some use of the globals here to ensure the compiler doesn't optimize
      * them away in release builds, causing the compartments to be collected and
      * the test to fail.
      */
     CHECK(JS_IsGlobalObject(global1));
     CHECK(JS_IsGlobalObject(global2));
     CHECK(JS_IsGlobalObject(global3));
 
+    return true;
+}
+
+JSObject *createTestGlobal()
+{
+    JS::CompartmentOptions options;
+    options.setVersion(JSVERSION_LATEST);
+    return JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::FireOnNewGlobalHook, options);
+}
+
+virtual bool init() MOZ_OVERRIDE
+{
+    if (!JSAPITest::init())
+        return false;
+
+    JS_AddFinalizeCallback(rt, FinalizeCallback, nullptr);
+    return true;
+}
+
+virtual void uninit() MOZ_OVERRIDE
+{
     JS_RemoveFinalizeCallback(rt, FinalizeCallback);
-    return true;
+    JSAPITest::uninit();
 }
 
 bool checkSingleGroup()
 {
     CHECK(FinalizeCalls < BufferSize);
     CHECK(FinalizeCalls == 3);
     return true;
 }