Bug 1492584, part 3 - Remove JS component loader registration. r=kmag
authorAndrew McCreight <continuation@gmail.com>
Tue, 23 Oct 2018 23:20:38 +0000
changeset 491185 2c675ab661cad80e1cc5a791de042a3322110adc
parent 491184 2df4dcfce65f9a9a0e41d3f65390c614d147cc1b
child 491186 a1f419870e136b8838471fde0d1094f2942fa20a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerskmag
bugs1492584
milestone65.0a1
Bug 1492584, part 3 - Remove JS component loader registration. r=kmag After the previous patches, we no longer rely on the component manager to incidentally start up XPConnect when we load the JS loader service or to hold the JS component loader alive, so the do_GetService() call for the JS loader in XPCOMInit.cpp can be removed. After that is done, the JS loader is no longer used as an XPCOM component, so all of the boilerplate for that can be removed. Depends on D8757 Differential Revision: https://phabricator.services.mozilla.com/D8758
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/loader/mozJSComponentLoader.h
js/xpconnect/src/XPCJSRuntime.cpp
js/xpconnect/src/XPCModule.h
xpcom/build/XPCOMInit.cpp
xpcom/components/nsComponentManager.cpp
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -195,26 +195,16 @@ mozJSComponentLoader::mozJSComponentLoad
       mLocations(16),
       mInitialized(false),
       mShareLoaderGlobal(false),
       mLoaderGlobal(dom::RootingCx())
 {
     MOZ_ASSERT(!sSelf, "mozJSComponentLoader should be a singleton");
 }
 
-// static
-already_AddRefed<mozJSComponentLoader>
-mozJSComponentLoader::GetOrCreate()
-{
-    if (!sSelf) {
-        sSelf = new mozJSComponentLoader();
-    }
-    return do_AddRef(sSelf);
-}
-
 #define ENSURE_DEP(name) { nsresult rv = Ensure##name(); NS_ENSURE_SUCCESS(rv, rv); }
 #define ENSURE_DEPS(...) MOZ_FOR_EACH(ENSURE_DEP, (), (__VA_ARGS__));
 #define BEGIN_ENSURE(self, ...) { \
     if (m##self) \
         return NS_OK; \
     ENSURE_DEPS(__VA_ARGS__); \
 }
 
--- a/js/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/xpconnect/loader/mozJSComponentLoader.h
@@ -26,23 +26,16 @@
 class nsIFile;
 class ComponentLoaderInfo;
 
 namespace mozilla {
     class ScriptPreloader;
 } // namespace mozilla
 
 
-/* 6bd13476-1dd2-11b2-bbef-f0ccb5fa64b6 (thanks, mozbot) */
-
-#define MOZJSCOMPONENTLOADER_CID                                              \
-  {0x6bd13476, 0x1dd2, 0x11b2,                                                \
-    { 0xbb, 0xef, 0xf0, 0xcc, 0xb5, 0xfa, 0x64, 0xb6 }}
-#define MOZJSCOMPONENTLOADER_CONTRACTID "@mozilla.org/moz/jsloader;1"
-
 #if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION) || defined(DEBUG)
 #define STARTUP_RECORDER_ENABLED
 #endif
 
 class mozJSComponentLoader final : public nsIObserver
 {
  public:
     NS_DECL_ISUPPORTS
@@ -58,18 +51,16 @@ class mozJSComponentLoader final : publi
     const mozilla::Module* LoadModule(mozilla::FileLocation& aFile);
 
     void FindTargetObject(JSContext* aCx,
                           JS::MutableHandleObject aTargetObject);
 
     static void InitStatics();
     static void Shutdown();
 
-    static already_AddRefed<mozJSComponentLoader> GetOrCreate();
-
     static mozJSComponentLoader* Get() {
         MOZ_ASSERT(sSelf, "Should have already created the component loader");
         return sSelf;
     }
 
     nsresult ImportInto(const nsACString& aResourceURI, JS::HandleValue aTargetObj,
                         JSContext* aCx, uint8_t aArgc, JS::MutableHandleValue aRetval);
 
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -3349,17 +3349,17 @@ XPCJSRuntime::DeleteSingletonScopes()
     mUnprivilegedJunkScope = nullptr;
     mLoaderGlobal = nullptr;
 }
 
 JSObject*
 XPCJSRuntime::LoaderGlobal()
 {
     if (!mLoaderGlobal) {
-        RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
+        RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::Get();
 
         dom::AutoJSAPI jsapi;
         jsapi.Init();
 
         mLoaderGlobal = loader->GetSharedGlobal(jsapi.cx());
         MOZ_RELEASE_ASSERT(!JS_IsExceptionPending(jsapi.cx()));
     }
     return mLoaderGlobal;
--- a/js/xpconnect/src/XPCModule.h
+++ b/js/xpconnect/src/XPCModule.h
@@ -1,43 +1,36 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=4 et sw=4 tw=99: */
 /* 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 "xpcprivate.h"
 #include "mozilla/ModuleUtils.h"
-#include "mozJSComponentLoader.h"
 #include "mozJSSubScriptLoader.h"
 
 /* Module implementation for the xpconnect library. */
 
 #define XPCVARIANT_CONTRACTID "@mozilla.org/xpcvariant;1"
 
 // {FE4F7592-C1FC-4662-AC83-538841318803}
 #define SCRIPTABLE_INTERFACES_CID                                             \
     {0xfe4f7592, 0xc1fc, 0x4662,                                              \
       { 0xac, 0x83, 0x53, 0x88, 0x41, 0x31, 0x88, 0x3 } }
 
 #define MOZJSSUBSCRIPTLOADER_CONTRACTID "@mozilla.org/moz/jssubscript-loader;1"
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSID)
-
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(mozJSComponentLoader,
-                                         mozJSComponentLoader::GetOrCreate);
 NS_GENERIC_FACTORY_CONSTRUCTOR(mozJSSubScriptLoader)
 
 NS_DEFINE_NAMED_CID(NS_JS_ID_CID);
-NS_DEFINE_NAMED_CID(MOZJSCOMPONENTLOADER_CID);
 NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADER_CID);
 
 #define XPCONNECT_CIDENTRIES                                                  \
   { &kNS_JS_ID_CID, false, nullptr,  nsJSIDConstructor },                     \
-  { &kMOZJSCOMPONENTLOADER_CID, false, nullptr, mozJSComponentLoaderConstructor },\
   { &kMOZ_JSSUBSCRIPTLOADER_CID, false, nullptr, mozJSSubScriptLoaderConstructor },
 
 #define XPCONNECT_CONTRACTS                                                   \
-  { MOZJSCOMPONENTLOADER_CONTRACTID, &kMOZJSCOMPONENTLOADER_CID },            \
   { MOZJSSUBSCRIPTLOADER_CONTRACTID, &kMOZ_JSSUBSCRIPTLOADER_CID },
 
 nsresult xpcModuleCtor();
 void xpcModuleDtor();
--- a/xpcom/build/XPCOMInit.cpp
+++ b/xpcom/build/XPCOMInit.cpp
@@ -697,22 +697,16 @@ NS_InitXPCOM2(nsIServiceManager** aResul
     NS_RELEASE(nsComponentManagerImpl::gComponentManager);
     return rv;
   }
 
   if (aResult) {
     NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
   }
 
-  // Ensure that XPConnect etc. is started up before we might call
-  // into JS. For instance, on Android nsIDirectoryServiceProvider is
-  // written in JS.
-  nsCOMPtr<nsISupports> componentLoader =
-    do_GetService("@mozilla.org/moz/jsloader;1");
-
   // After autoreg, but before we actually instantiate any components,
   // add any services listed in the "xpcom-directory-providers" category
   // to the directory service.
   nsDirectoryService::gService->RegisterCategoryProviders();
 
   // Init SharedThreadPool (which needs the service manager).
   SharedThreadPool::InitStatics();
 
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -788,17 +788,17 @@ nsComponentManagerImpl::KnownModule::Loa
   if (!mModule) {
     nsCString extension;
     mFile.GetURIString(extension);
     CutExtension(extension);
     if (!extension.Equals("js")) {
       return false;
     }
 
-    RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
+    RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::Get();
     mModule = loader->LoadModule(mFile);
 
     if (!mModule) {
       mFailed = true;
       return false;
     }
   }
   if (!mLoaded) {