Bug 1398895: Part 2 - Ensure component loader initialization after user prefs load. r=mccr8 draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 11 Sep 2017 13:52:13 -0700
changeset 664472 1babbd71cf1d59aaedec6e3794729a1b60f90c23
parent 664471 6147fac9649f0aea390f74bc39d0f66942ace23f
child 731450 570e48f38e109695bfdb0139ac9f33f6e4cca506
push id79702
push usermaglione.k@gmail.com
push dateWed, 13 Sep 2017 23:57:00 +0000
reviewersmccr8
bugs1398895
milestone57.0a1
Bug 1398895: Part 2 - Ensure component loader initialization after user prefs load. r=mccr8 The script precompiler needs to begin its work very early in the startup process in order to be effective. At the moment, this means before user preferences are loaded. It also needs to be able to compile scripts into the shared JSM global when that's in use, in order to avoid unnecessary script clones. Since we can't know whether global sharing is enabled by that point, instead, we just always compile module scripts into the shared module global rather than the XPC compillation scope. This also changes the global sharing tests to make a failure to respect the user preference value a fatal error. MozReview-Commit-ID: G0NkSOl2vU9
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/loader/mozJSComponentLoader.h
js/xpconnect/tests/marionette/test_loader_global_sharing.py
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -561,18 +561,16 @@ mozJSComponentLoader::ReuseGlobal(bool a
 
     return true;
 }
 
 JSObject*
 mozJSComponentLoader::GetSharedGlobal(JSContext* aCx)
 {
     if (!mLoaderGlobal) {
-        MOZ_ASSERT(mShareLoaderGlobal);
-
         JS::RootedObject globalObj(aCx);
         CreateLoaderGlobal(aCx, NS_LITERAL_CSTRING("shared JSM global"),
                            nullptr, &globalObj);
 
         // If we fail to create a module global this early, we're not going to
         // get very far, so just bail out now.
         MOZ_RELEASE_ASSERT(globalObj);
         mLoaderGlobal = globalObj;
--- a/js/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/xpconnect/loader/mozJSComponentLoader.h
@@ -72,22 +72,17 @@ class mozJSComponentLoader final : publi
     virtual ~mozJSComponentLoader();
 
     friend class mozilla::ScriptPreloader;
 
     JSObject* CompilationScope(JSContext* aCx)
     {
         if (mLoaderGlobal)
             return mLoaderGlobal;
-        if ((mInitialized || NS_SUCCEEDED(ReallyInit())) &&
-            mShareLoaderGlobal)
-        {
-            return GetSharedGlobal(aCx);
-        }
-        return xpc::CompilationScope();
+        return GetSharedGlobal(aCx);
     }
 
  private:
     static mozJSComponentLoader* sSelf;
 
     nsresult ReallyInit();
     void UnloadModules();
 
--- a/js/xpconnect/tests/marionette/test_loader_global_sharing.py
+++ b/js/xpconnect/tests/marionette/test_loader_global_sharing.py
@@ -66,18 +66,16 @@ class TestLoaderGlobalSharing(Marionette
           Cu.import("resource://gre/modules/Services.jsm");
           window.env = Cc["@mozilla.org/process/environment;1"]
                     .getService(Ci.nsIEnvironment);
         ''')
 
     def setUp(self):
         super(TestLoaderGlobalSharing, self).setUp()
 
-        self.default_pref_value = self.marionette.get_pref(GLOBAL_SHARING_PREF)
-
         self.setUpSession()
 
     def tearDown(self):
         self.marionette.restart(clean=True)
 
         super(TestLoaderGlobalSharing, self).tearDown()
 
     def test_global_sharing_settings(self):
@@ -104,16 +102,12 @@ class TestLoaderGlobalSharing(Marionette
             # defined.
             expect_sharing = pref if var is None else var != '0'
 
             self.restart(prefs={GLOBAL_SHARING_PREF: pref},
                          env={GLOBAL_SHARING_VAR: var})
 
             have_sharing = self.get_global_sharing_enabled()
 
-            # FIXME: User preference values currently do not always take
-            # effect early enough to influence loader behavior.
-            msg = ('Global sharing state should match settings: %r != %r'
-                   % (have_sharing, expect_sharing))
-            if var is not None or pref == self.default_pref_value:
-                self.assertEqual(have_sharing, expect_sharing, msg)
-            elif have_sharing != expect_sharing:
-                print('TEST-EXPECTED-FAIL: ' + msg)
+            self.assertEqual(
+                have_sharing, expect_sharing,
+                'Global sharing state should match settings: %r != %r'
+                % (have_sharing, expect_sharing))