Bug 1278223 part 1 - Stop using multiple contexts per runtime in gtests. r=fitzgen
authorJan de Mooij <jdemooij@mozilla.com>
Mon, 06 Jun 2016 19:45:06 +0200
changeset 325796 8456f48c6118754b49b22f5607f62185d1a97556
parent 325795 f99522f6c95162da9c76ae1d773a90dcebbeacf8
child 325797 1258a697a4bb282fe810fb3756ca9a2102e8a8f3
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfitzgen
bugs1278223
milestone49.0a1
Bug 1278223 part 1 - Stop using multiple contexts per runtime in gtests. r=fitzgen
devtools/shared/heapsnapshot/tests/gtest/DevTools.h
xpcom/glue/tests/gtest/TestGCPostBarriers.cpp
--- a/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
+++ b/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
@@ -43,19 +43,19 @@ struct DevTools : public ::testing::Test
 
   virtual void SetUp() {
     MOZ_ASSERT(!_initialized);
 
     rt = getRuntime();
     if (!rt)
       return;
 
-    cx = createContext();
-    if (!cx)
-      return;
+    MOZ_RELEASE_ASSERT(!cx);
+    MOZ_RELEASE_ASSERT(JS_ContextIterator(rt, &cx));
+
     JS_BeginRequest(cx);
 
     global.init(rt, createGlobal());
     if (!global)
       return;
     JS_EnterCompartment(cx, global);
 
     compartment = js::GetContextCompartment(cx);
@@ -88,20 +88,16 @@ struct DevTools : public ::testing::Test
 
   static void reportError(JSContext* cx, const char* message, JSErrorReport* report) {
     fprintf(stderr, "%s:%u:%s\n",
             report->filename ? report->filename : "<no filename>",
             (unsigned int) report->lineno,
             message);
   }
 
-  JSContext* createContext() {
-    return JS_NewContext(rt, 8192);
-  }
-
   static const JSClass* getGlobalClass() {
     static const JSClassOps globalClassOps = {
       nullptr, nullptr, nullptr, nullptr,
       nullptr, nullptr, nullptr, nullptr,
       nullptr, nullptr, nullptr,
       JS_GlobalObjectTraceHook
     };
     static const JSClass globalClass = {
@@ -134,21 +130,18 @@ struct DevTools : public ::testing::Test
 
   virtual void TearDown() {
     _initialized = false;
 
     if (global) {
       JS_LeaveCompartment(cx, nullptr);
       global = nullptr;
     }
-    if (cx) {
+    if (cx)
       JS_EndRequest(cx);
-      JS_DestroyContext(cx);
-      cx = nullptr;
-    }
   }
 };
 
 
 // Helper to define a test and ensure that the fixture is initialized properly.
 #define DEF_TEST(name, body)                    \
   TEST_F(DevTools, name) {                      \
     ASSERT_TRUE(_initialized);                  \
--- a/xpcom/glue/tests/gtest/TestGCPostBarriers.cpp
+++ b/xpcom/glue/tests/gtest/TestGCPostBarriers.cpp
@@ -127,17 +127,17 @@ CreateGlobalAndRunTest(JSRuntime* rt, JS
 }
 
 TEST(GCPostBarriers, nsTArray) {
   CycleCollectedJSRuntime* ccrt = CycleCollectedJSRuntime::Get();
   ASSERT_TRUE(ccrt != nullptr);
   JSRuntime* rt = ccrt->Runtime();
   ASSERT_TRUE(rt != nullptr);
 
-  JSContext *cx = JS_NewContext(rt, 8192);
-  ASSERT_TRUE(cx != nullptr);
+  JSContext* cx = nullptr;
+  MOZ_RELEASE_ASSERT(JS_ContextIterator(rt, &cx));
+
   JS_BeginRequest(cx);
 
   CreateGlobalAndRunTest(rt, cx);
 
   JS_EndRequest(cx);
-  JS_DestroyContext(cx);
 }