Bug 1497707, part 4 - Only support loading JS files in the component manager r=froydnj
☠☠ backed out by c73a5da46b9f ☠ ☠
authorAndrew McCreight <continuation@gmail.com>
Wed, 17 Oct 2018 20:45:43 +0000
changeset 500281 11c813f192e21cec64b252515c6b89d37b255300
parent 500280 32595f9e73d376499b5d1d26b1954a37a9c7e600
child 500282 bb1b80139e377d9f5202e9fa1b94d39985381caf
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1497707
milestone64.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 1497707, part 4 - Only support loading JS files in the component manager r=froydnj JS is the only file extension actually supported, and there are a few layers of cruft that can be eliminated if we specialize it. This eliminates one XPCOM registration of the JS component loader. Depends on D8170 Differential Revision: https://phabricator.services.mozilla.com/D8171
js/xpconnect/src/XPCModule.h
layout/build/nsLayoutModule.cpp
xpcom/components/moz.build
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
--- a/js/xpconnect/src/XPCModule.h
+++ b/js/xpconnect/src/XPCModule.h
@@ -34,13 +34,10 @@ NS_DEFINE_NAMED_CID(MOZ_JSSUBSCRIPTLOADE
   { &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 },
 
-#define XPCONNECT_CATEGORIES \
-  { "module-loader", "js", MOZJSCOMPONENTLOADER_CONTRACTID },
-
 nsresult xpcModuleCtor();
 void xpcModuleDtor();
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -663,17 +663,16 @@ static const mozilla::Module::ContractID
   { PRESENTATION_DEVICE_MANAGER_CONTRACTID, &kPRESENTATION_DEVICE_MANAGER_CID },
   { PRESENTATION_TCP_SESSION_TRANSPORT_CONTRACTID, &kPRESENTATION_TCP_SESSION_TRANSPORT_CID },
   { "@mozilla.org/text-input-processor;1", &kTEXT_INPUT_PROCESSOR_CID },
   { NS_SCRIPTERROR_CONTRACTID, &kNS_SCRIPTERROR_CID },
   { nullptr }
 };
 
 static const mozilla::Module::CategoryEntry kLayoutCategories[] = {
-  XPCONNECT_CATEGORIES
   { "content-policy", NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID, NS_DATADOCUMENTCONTENTPOLICY_CONTRACTID },
   { "content-policy", NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID, NS_NODATAPROTOCOLCONTENTPOLICY_CONTRACTID },
   { "content-policy", "CSPService", CSPSERVICE_CONTRACTID },
   { "content-policy", NS_MIXEDCONTENTBLOCKER_CONTRACTID, NS_MIXEDCONTENTBLOCKER_CONTRACTID },
   { "net-channel-event-sinks", "CSPService", CSPSERVICE_CONTRACTID },
   { "net-channel-event-sinks", NS_MIXEDCONTENTBLOCKER_CONTRACTID, NS_MIXEDCONTENTBLOCKER_CONTRACTID },
   { "app-startup", "Script Security Manager", "service," NS_SCRIPTSECURITYMANAGER_CONTRACTID },
   { "app-startup", "Push Notifier", "service," PUSHNOTIFIER_CONTRACTID },
--- a/xpcom/components/moz.build
+++ b/xpcom/components/moz.build
@@ -42,13 +42,14 @@ UNIFIED_SOURCES += [
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '!..',
     '../base',
     '../build',
     '../ds',
     '/chrome',
+    '/js/xpconnect/loader',
     '/modules/libjar',
 ]
 
 if 'gtk' in CONFIG['MOZ_WIDGET_TOOLKIT']:
     CXXFLAGS += CONFIG['TK_CFLAGS']
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -33,16 +33,17 @@
 #include "nsThreadUtils.h"
 #include "prthread.h"
 #include "private/pprthred.h"
 #include "nsTArray.h"
 #include "prio.h"
 #include "ManifestParser.h"
 #include "nsNetUtil.h"
 #include "mozilla/Services.h"
+#include "mozJSComponentLoader.h"
 
 #include "mozilla/GenericFactory.h"
 #include "nsSupportsPrimitives.h"
 #include "nsArray.h"
 #include "nsIMutableArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsStringEnumerator.h"
 #include "mozilla/FileUtils.h"
@@ -769,40 +770,31 @@ nsComponentManagerImpl::RereadChromeMani
 
   nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
   if (obs) {
     obs->NotifyObservers(nullptr, "chrome-manifests-loaded", nullptr);
   }
 }
 
 bool
-nsComponentManagerImpl::KnownModule::EnsureLoader()
-{
-  if (!mLoader) {
-    nsCString extension;
-    mFile.GetURIString(extension);
-    CutExtension(extension);
-    mLoader =
-      nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
-  }
-  return !!mLoader;
-}
-
-bool
 nsComponentManagerImpl::KnownModule::Load()
 {
   if (mFailed) {
     return false;
   }
   if (!mModule) {
-    if (!EnsureLoader()) {
+    nsCString extension;
+    mFile.GetURIString(extension);
+    CutExtension(extension);
+    if (!extension.Equals("js")) {
       return false;
     }
 
-    mModule = mLoader->LoadModule(mFile);
+    RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::GetOrCreate();
+    mModule = loader->LoadModule(mFile);
 
     if (!mModule) {
       mFailed = true;
       return false;
     }
   }
   if (!mLoaded) {
     if (mModule->loadProc) {
@@ -839,17 +831,16 @@ nsresult nsComponentManagerImpl::Shutdow
   MOZ_LOG(nsComponentManagerLog, LogLevel::Debug,
          ("nsComponentManager: Beginning Shutdown."));
 
   UnregisterWeakMemoryReporter(this);
 
   // Release all cached factories
   mContractIDs.Clear();
   mFactories.Clear(); // XXX release the objects, don't just clear
-  mLoaderMap.Clear();
   mKnownModules.Clear();
   mKnownStaticModules.Clear();
 
   delete sExtraStaticModules;
   delete sModuleLocations;
 
   mStatus = SHUTDOWN_COMPLETE;
 
@@ -1516,33 +1507,16 @@ nsComponentManagerImpl::GetServiceByCont
 
   nsISupports** sresult = reinterpret_cast<nsISupports**>(aResult);
   *sresult = entry->mServiceObject;
   (*sresult)->AddRef();
 
   return NS_OK;
 }
 
-already_AddRefed<mozilla::ModuleLoader>
-nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
-{
-  nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
-  if (!loader) {
-    loader = do_GetServiceFromCategory(NS_LITERAL_CSTRING("module-loader"),
-                                       aExt);
-    if (!loader) {
-      return nullptr;
-    }
-
-    mLoaderMap.Put(aExt, loader);
-  }
-
-  return loader.forget();
-}
-
 NS_IMETHODIMP
 nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
                                         const char* aName,
                                         const char* aContractID,
                                         nsIFactory* aFactory)
 {
   if (!aFactory) {
     // If a null factory is passed in, this call just wants to reset
@@ -1741,18 +1715,16 @@ nsComponentManagerImpl::CollectReports(n
 }
 
 size_t
 nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
   const
 {
   size_t n = aMallocSizeOf(this);
 
-  n += mLoaderMap.ShallowSizeOfExcludingThis(aMallocSizeOf);
-
   n += mFactories.ShallowSizeOfExcludingThis(aMallocSizeOf);
   for (auto iter = mFactories.ConstIter(); !iter.Done(); iter.Next()) {
     n += iter.Data()->SizeOfIncludingThis(aMallocSizeOf);
   }
 
   n += mContractIDs.ShallowSizeOfExcludingThis(aMallocSizeOf);
   for (auto iter = mContractIDs.ConstIter(); !iter.Done(); iter.Next()) {
     // We don't measure the nsFactoryEntry data because it's owned by
@@ -1769,17 +1741,16 @@ nsComponentManagerImpl::SizeOfIncludingT
   n += mKnownModules.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
   n += mArena.SizeOfExcludingThis(aMallocSizeOf);
 
   n += mPendingServices.ShallowSizeOfExcludingThis(aMallocSizeOf);
 
   // Measurement of the following members may be added later if DMD finds it is
   // worthwhile:
-  // - mLoaderMap's keys and values
   // - mMon
   // - sModuleLocations' entries
   // - mKnownStaticModules' entries?
   // - mKnownModules' keys and values?
 
   return n;
 }
 
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -137,19 +137,16 @@ public:
 
   static nsComponentManagerImpl* gComponentManager;
   nsresult Init();
 
   nsresult Shutdown(void);
 
   nsresult FreeServices();
 
-  already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
-  nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;
-
   already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
   already_AddRefed<nsIFactory> FindFactory(const char* aContractID,
                                            uint32_t aContractIDLen);
 
   already_AddRefed<nsIFactory> LoadFactory(nsFactoryEntry* aEntry);
 
   nsFactoryEntry* GetFactoryEntry(const char* aContractID,
                                   uint32_t aContractIDLen);
@@ -191,44 +188,41 @@ public:
       , mLoaded(false)
       , mFailed(false)
     {
     }
 
     explicit KnownModule(mozilla::FileLocation& aFile)
       : mModule(nullptr)
       , mFile(aFile)
-      , mLoader(nullptr)
       , mLoaded(false)
       , mFailed(false)
     {
     }
 
     ~KnownModule()
     {
       if (mLoaded && mModule->unloadProc) {
         mModule->unloadProc();
       }
     }
 
-    bool EnsureLoader();
     bool Load();
 
     const mozilla::Module* Module() const { return mModule; }
 
     /**
      * For error logging, get a description of this module, either the
      * file path, or <static module>.
      */
     nsCString Description() const;
 
   private:
     const mozilla::Module* mModule;
     mozilla::FileLocation mFile;
-    nsCOMPtr<mozilla::ModuleLoader> mLoader;
     bool mLoaded;
     bool mFailed;
   };
 
   // The KnownModule is kept alive by these members, it is
   // referenced by pointer from the factory entries.
   nsTArray<nsAutoPtr<KnownModule>> mKnownStaticModules;
   // The key is the URI string of the module