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
--- 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))