Bug 1506324 - Use DefaultGlobalClassOps in existing code. r=jorendorff
☠☠ backed out by 1eeecfde9fe1 ☠ ☠
authorPhilip Chimento <philip.chimento@gmail.com>
Mon, 19 Nov 2018 09:05:07 -0500
changeset 503544 f00f5277735f4f5a4784659716f7ceede6a339b6
parent 503543 adec7f223b0292b8dc446ab6d4fe0883dfbdcaf9
child 503545 412920e602faa64d31b4a07a8d9d068413f04bc0
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1506324
milestone65.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 1506324 - Use DefaultGlobalClassOps in existing code. r=jorendorff Summary: Depends on D11570 Reviewers: tcampbell, jorendorff Reviewed By: tcampbell, jorendorff Subscribers: jandem Bug #: 1506324 Differential Revision: https://phabricator.services.mozilla.com/D11571
devtools/shared/heapsnapshot/tests/gtest/DevTools.h
js/src/fuzz-tests/tests.cpp
js/src/gdb/gdb-tests.cpp
js/src/jsapi-tests/testChromeBuffer.cpp
js/src/jsapi-tests/testDebugger.cpp
js/src/jsapi-tests/testMutedErrors.cpp
js/src/jsapi-tests/testSetProperty.cpp
js/src/jsapi-tests/tests.cpp
js/src/jsapi-tests/tests.h
js/src/vm/HelperThreads.cpp
netwerk/base/ProxyAutoConfig.cpp
xpcom/tests/gtest/TestGCPostBarriers.cpp
--- a/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
+++ b/devtools/shared/heapsnapshot/tests/gtest/DevTools.h
@@ -64,47 +64,29 @@ 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);
   }
 
   static const JSClass* getGlobalClass() {
-    static const JSClassOps globalClassOps = {
-      nullptr, nullptr, nullptr, nullptr,
-      nullptr, nullptr, nullptr, nullptr,
-      nullptr, nullptr,
-      JS_GlobalObjectTraceHook
-    };
     static const JSClass globalClass = {
       "global", JSCLASS_GLOBAL_FLAGS,
-      &globalClassOps
+      &JS::DefaultGlobalClassOps
     };
     return &globalClass;
   }
 
   JSObject* createGlobal()
   {
     /* Create the global object. */
-    JS::RootedObject newGlobal(cx);
     JS::RealmOptions options;
-    newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
-                                   JS::FireOnNewGlobalHook, options);
-    if (!newGlobal)
-      return nullptr;
-
-    JSAutoRealm ar(cx, newGlobal);
-
-    /* Populate the global object with the standard globals, like Object and
-       Array. */
-    if (!JS::InitRealmStandardClasses(cx))
-      return nullptr;
-
-    return newGlobal;
+    return JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
+                              JS::FireOnNewGlobalHook, options);
   }
 
   virtual void TearDown() {
     _initialized = false;
 
     if (global) {
       JS::LeaveRealm(cx, nullptr);
       global = nullptr;
--- a/js/src/fuzz-tests/tests.cpp
+++ b/js/src/fuzz-tests/tests.cpp
@@ -20,54 +20,34 @@
 using namespace mozilla;
 
 JS::PersistentRootedObject gGlobal;
 JSContext* gCx = nullptr;
 
 static const JSClass*
 getGlobalClass()
 {
-    static const JSClassOps cOps = {
-        nullptr, nullptr, nullptr, nullptr,
-        nullptr, nullptr, nullptr, nullptr,
-        nullptr, nullptr,
-        JS_GlobalObjectTraceHook
-    };
     static const JSClass c = {
         "global", JSCLASS_GLOBAL_FLAGS,
-        &cOps
+        &JS::DefaultGlobalClassOps
     };
     return &c;
 }
 
 static JSObject*
 jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals)
 {
     /* Create the global object. */
-    JS::RootedObject newGlobal(cx);
     JS::RealmOptions options;
     options.creationOptions().setStreamsEnabled(true);
 #ifdef ENABLE_BIGINT
     options.creationOptions().setBigIntEnabled(true);
 #endif
-    newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
-                                   options);
-    if (!newGlobal) {
-        return nullptr;
-    }
-
-    JSAutoRealm ar(cx, newGlobal);
-
-    // Populate the global object with the standard globals like Object and
-    // Array.
-    if (!JS::InitRealmStandardClasses(cx)) {
-        return nullptr;
-    }
-
-    return newGlobal;
+    return JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
+                              options);
 }
 
 static bool
 jsfuzz_init(JSContext** cx, JS::PersistentRootedObject* global)
 {
     *cx = JS_NewContext(8L * 1024 * 1024);
     if (!*cx) {
         return false;
--- a/js/src/gdb/gdb-tests.cpp
+++ b/js/src/gdb/gdb-tests.cpp
@@ -8,27 +8,20 @@
 
 #include "gdb-tests.h"
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "js/Initialization.h"
 
 using namespace JS;
 
-static const JSClassOps global_classOps = {
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr,
-    JS_GlobalObjectTraceHook
-};
-
 /* The class of the global object. */
 static const JSClass global_class = {
     "global", JSCLASS_GLOBAL_FLAGS,
-    &global_classOps
+    &DefaultGlobalClassOps
 };
 
 static volatile int dontOptimizeMeAway = 0;
 
 void
 usePointer(const void* ptr) {
     dontOptimizeMeAway++;
 }
@@ -85,20 +78,16 @@ main(int argc, const char** argv)
     JS::SetWarningReporter(cx, reportWarning);
 
     /* Create the global object. */
     JS::RealmOptions options;
     RootedObject global(cx, checkPtr(JS_NewGlobalObject(cx, &global_class,
                         nullptr, JS::FireOnNewGlobalHook, options)));
     JSAutoRealm ar(cx, global);
 
-    /* Populate the global object with the standard globals,
-       like Object and Array. */
-    checkBool(JS::InitRealmStandardClasses(cx));
-
     argv++;
     while (*argv) {
         const char* name = *argv++;
         GDBFragment* fragment;
         for (fragment = GDBFragment::allFragments; fragment; fragment = fragment->next) {
             if (strcmp(fragment->name(), name) == 0) {
                 fragment->run(cx, argv);
                 break;
--- a/js/src/jsapi-tests/testChromeBuffer.cpp
+++ b/js/src/jsapi-tests/testChromeBuffer.cpp
@@ -4,34 +4,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "js/CompilationAndEvaluation.h"
 #include "jsapi-tests/tests.h"
 
 static TestJSPrincipals system_principals(1);
 
-static const JSClassOps global_classOps = {
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    nullptr,
-    JS_GlobalObjectTraceHook
-};
-
 static const JSClass global_class = {
     "global",
     JSCLASS_IS_GLOBAL | JSCLASS_GLOBAL_FLAGS,
-    &global_classOps
+    &JS::DefaultGlobalClassOps
 };
 
 static JS::PersistentRootedObject trusted_glob;
 static JS::PersistentRootedObject trusted_fun;
 
 static bool
 CallTrusted(JSContext* cx, unsigned argc, JS::Value* vp)
 {
--- a/js/src/jsapi-tests/testDebugger.cpp
+++ b/js/src/jsapi-tests/testDebugger.cpp
@@ -13,20 +13,16 @@ using namespace js;
 BEGIN_TEST(testDebugger_newScriptHook)
 {
     // Test that top-level indirect eval fires the newScript hook.
     CHECK(JS_DefineDebuggerObject(cx, global));
     JS::RealmOptions options;
     JS::RootedObject g(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
                                               JS::FireOnNewGlobalHook, options));
     CHECK(g);
-    {
-        JSAutoRealm ar(cx, g);
-        CHECK(JS::InitRealmStandardClasses(cx));
-    }
 
     JS::RootedObject gWrapper(cx, g);
     CHECK(JS_WrapObject(cx, &gWrapper));
     JS::RootedValue v(cx, JS::ObjectValue(*gWrapper));
     CHECK(JS_SetProperty(cx, global, "g", v));
 
     EXEC("var dbg = Debugger(g);\n"
          "var hits = 0;\n"
--- a/js/src/jsapi-tests/testMutedErrors.cpp
+++ b/js/src/jsapi-tests/testMutedErrors.cpp
@@ -45,18 +45,16 @@ eval(const char* asciiChars, bool mutedE
     }
     chars[len] = 0;
 
     JS::RealmOptions globalOptions;
     JS::RootedObject global(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
 						   JS::FireOnNewGlobalHook, globalOptions));
     CHECK(global);
     JSAutoRealm ar(cx, global);
-    CHECK(JS::InitRealmStandardClasses(cx));
-
 
     JS::CompileOptions options(cx);
     options.setMutedErrors(mutedErrors)
            .setFileAndLine("", 0);
 
     JS::SourceText<char16_t> srcBuf;
     CHECK(srcBuf.init(cx, chars.get(), len, JS::SourceOwnership::Borrowed));
 
--- a/js/src/jsapi-tests/testSetProperty.cpp
+++ b/js/src/jsapi-tests/testSetProperty.cpp
@@ -4,25 +4,51 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "jsapi-tests/tests.h"
 
 BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
 {
-    // This is a JSAPI test because jsapi-test globals do not have a resolve
-    // hook and therefore can use the property cache in some cases where the
-    // shell can't.
+    // This is a JSAPI test because jsapi-test globals can be set up to not have
+    // a resolve hook and therefore can use the property cache in some cases
+    // where the shell can't.
     MOZ_RELEASE_ASSERT(!JS_GetClass(global)->getResolve());
 
+    CHECK(JS::InitRealmStandardClasses(cx));
+
     CHECK(JS_DefineProperty(cx, global, "HOTLOOP", 8, 0));
     EXEC("var n = 0;\n"
          "var global = this;\n"
          "function f() { n++; }\n"
          "Object.defineProperty(Object.prototype, 'x', {set: f});\n"
          "for (var i = 0; i < HOTLOOP; i++)\n"
          "    global.x = i;\n");
     EXEC("if (n != HOTLOOP)\n"
          "    throw 'FAIL';\n");
     return true;
 }
+
+const JSClass* getGlobalClass(void) override {
+    static const JSClassOps noResolveGlobalClassOps = {
+        nullptr, // add
+        nullptr, // delete
+        nullptr, // enumerate
+        nullptr, // newEnumerate
+        nullptr, // resolve
+        nullptr, // mayResolve
+        nullptr, // finalize
+        nullptr, // call
+        nullptr, // hasInstance
+        nullptr, // construct
+        JS_GlobalObjectTraceHook
+    };
+
+    static const JSClass noResolveGlobalClass = {
+        "testSetProperty_InheritedGlobalSetter_noResolveGlobalClass",
+        JSCLASS_GLOBAL_FLAGS,
+        &noResolveGlobalClassOps
+    };
+
+    return &noResolveGlobalClass;
+}
 END_TEST(testSetProperty_InheritedGlobalSetter)
--- a/js/src/jsapi-tests/tests.cpp
+++ b/js/src/jsapi-tests/tests.cpp
@@ -90,24 +90,16 @@ JSObject* JSAPITest::createGlobal(JSPrin
     options.creationOptions().setBigIntEnabled(true);
 #endif
     newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
                                    options);
     if (!newGlobal) {
         return nullptr;
     }
 
-    JSAutoRealm ar(cx, newGlobal);
-
-    // Populate the global object with the standard globals like Object and
-    // Array.
-    if (!JS::InitRealmStandardClasses(cx)) {
-        return nullptr;
-    }
-
     global = newGlobal;
     return newGlobal;
 }
 
 int main(int argc, char* argv[])
 {
     int total = 0;
     int failures = 0;
--- a/js/src/jsapi-tests/tests.h
+++ b/js/src/jsapi-tests/tests.h
@@ -256,25 +256,19 @@ class JSAPITest
         }
         msgs += message;
         return false;
     }
 
     JSAPITestString messages() const { return msgs; }
 
     static const JSClass * basicGlobalClass() {
-        static const JSClassOps cOps = {
-            nullptr, nullptr, nullptr, nullptr,
-            nullptr, nullptr, nullptr, nullptr,
-            nullptr, nullptr,
-            JS_GlobalObjectTraceHook
-        };
         static const JSClass c = {
             "global", JSCLASS_GLOBAL_FLAGS,
-            &cOps
+            &JS::DefaultGlobalClassOps
         };
         return &c;
     }
 
   protected:
     static bool
     print(JSContext* cx, unsigned argc, JS::Value* vp)
     {
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -424,26 +424,19 @@ js::HasOffThreadIonCompile(Realm* realm)
         }
         builder = builder->getNext();
     }
 
     return false;
 }
 #endif
 
-static const JSClassOps parseTaskGlobalClassOps = {
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr,
-    JS_GlobalObjectTraceHook
-};
-
 static const JSClass parseTaskGlobalClass = {
     "internal-parse-task-global", JSCLASS_GLOBAL_FLAGS,
-    &parseTaskGlobalClassOps
+    &JS::DefaultGlobalClassOps
 };
 
 ParseTask::ParseTask(ParseTaskKind kind, JSContext* cx,
                      JS::OffThreadCompileCallback callback, void* callbackData)
   : kind(kind),
     options(cx),
     parseGlobal(nullptr),
     callback(callback), callbackData(callbackData),
--- a/netwerk/base/ProxyAutoConfig.cpp
+++ b/netwerk/base/ProxyAutoConfig.cpp
@@ -675,40 +675,30 @@ private:
     if (!mGlobal) {
       JS_ClearPendingException(mContext);
       return NS_ERROR_OUT_OF_MEMORY;
     }
     JS::Rooted<JSObject*> global(mContext, mGlobal);
 
     JSAutoRealm ar(mContext, global);
     AutoPACErrorReporter aper(mContext);
-    if (!JS::InitRealmStandardClasses(mContext)) {
-      return NS_ERROR_FAILURE;
-    }
     if (!JS_DefineFunctions(mContext, global, PACGlobalFunctions)) {
       return NS_ERROR_FAILURE;
     }
 
     JS_FireOnNewGlobalObject(mContext, global);
 
     return NS_OK;
   }
 };
 
-static const JSClassOps sJSContextWrapperGlobalClassOps = {
-  nullptr, nullptr, nullptr, nullptr,
-  nullptr, nullptr, nullptr, nullptr,
-  nullptr, nullptr,
-  JS_GlobalObjectTraceHook
-};
-
 const JSClass JSContextWrapper::sGlobalClass = {
   "PACResolutionThreadGlobal",
   JSCLASS_GLOBAL_FLAGS,
-  &sJSContextWrapperGlobalClassOps
+  &JS::DefaultGlobalClassOps
 };
 
 void
 ProxyAutoConfig::SetThreadLocalIndex(uint32_t index)
 {
   sRunningIndex = index;
 }
 
--- a/xpcom/tests/gtest/TestGCPostBarriers.cpp
+++ b/xpcom/tests/gtest/TestGCPostBarriers.cpp
@@ -79,25 +79,19 @@ RunTest(JSContext* cx, ArrayT* array)
   }
 
   JS_RemoveExtraGCRootsTracer(cx, TraceArray<ArrayT>, array);
 }
 
 static void
 CreateGlobalAndRunTest(JSContext* cx)
 {
-  static const JSClassOps GlobalClassOps = {
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr, nullptr, nullptr,
-    nullptr, nullptr, JS_GlobalObjectTraceHook
-  };
-
   static const JSClass GlobalClass = {
     "global", JSCLASS_GLOBAL_FLAGS,
-    &GlobalClassOps
+    &JS::DefaultGlobalClassOps
   };
 
   JS::RealmOptions options;
   JS::PersistentRootedObject global(cx);
   global = JS_NewGlobalObject(cx, &GlobalClass, nullptr, JS::FireOnNewGlobalHook, options);
   ASSERT_TRUE(global != nullptr);
 
   JS::Realm* oldRealm = JS::EnterRealm(cx, global);