Bug 1365187 - Simplify module map interface r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 14 Dec 2017 15:13:57 -0600
changeset 448212 ebcc9ceb0842d5e925d693d0e48eeef80c0d0877
parent 448211 28f5404cc95e8e911bb21545b73638473b4aecd9
child 448213 9eca4461d0799a310d610dadf3e78cc1b5e35b3e
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1365187
milestone59.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 1365187 - Simplify module map interface r=smaug
dom/script/ScriptLoader.cpp
dom/script/ScriptLoader.h
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -328,39 +328,39 @@ ScriptLoader::ModuleScriptsEnabled()
     sCachedPref = true;
     Preferences::AddBoolVarCache(&sEnabledForContent, "dom.moduleScripts.enabled", false);
   }
 
   return nsContentUtils::IsChromeDoc(mDocument) || sEnabledForContent;
 }
 
 bool
-ScriptLoader::ModuleMapContainsModule(ModuleLoadRequest* aRequest) const
+ScriptLoader::ModuleMapContainsURL(nsIURI* aURL) const
 {
   // Returns whether we have fetched, or are currently fetching, a module script
-  // for the request's URL.
-  return mFetchingModules.Contains(aRequest->mURI) ||
-         mFetchedModules.Contains(aRequest->mURI);
+  // for a URL.
+  return mFetchingModules.Contains(aURL) ||
+         mFetchedModules.Contains(aURL);
 }
 
 bool
 ScriptLoader::IsFetchingModule(ModuleLoadRequest* aRequest) const
 {
   bool fetching = mFetchingModules.Contains(aRequest->mURI);
   MOZ_ASSERT_IF(fetching, !mFetchedModules.Contains(aRequest->mURI));
   return fetching;
 }
 
 void
 ScriptLoader::SetModuleFetchStarted(ModuleLoadRequest* aRequest)
 {
   // Update the module map to indicate that a module is currently being fetched.
 
   MOZ_ASSERT(aRequest->IsLoading());
-  MOZ_ASSERT(!ModuleMapContainsModule(aRequest));
+  MOZ_ASSERT(!ModuleMapContainsURL(aRequest->mURI));
   mFetchingModules.Put(aRequest->mURI, nullptr);
 }
 
 void
 ScriptLoader::SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,
                                                              nsresult aResult)
 {
   // Update module map with the result of fetching a single module script.
@@ -387,29 +387,29 @@ ScriptLoader::SetModuleFetchFinishedAndR
     } else {
       LOG(("ScriptLoadRequest (%p):   rejecting %p", aRequest, promise.get()));
       promise->Reject(aResult, __func__);
     }
   }
 }
 
 RefPtr<GenericPromise>
-ScriptLoader::WaitForModuleFetch(ModuleLoadRequest* aRequest)
+ScriptLoader::WaitForModuleFetch(nsIURI* aURL)
 {
-  MOZ_ASSERT(ModuleMapContainsModule(aRequest));
-
-  if (auto entry = mFetchingModules.Lookup(aRequest->mURI)) {
+  MOZ_ASSERT(ModuleMapContainsURL(aURL));
+
+  if (auto entry = mFetchingModules.Lookup(aURL)) {
     if (!entry.Data()) {
       entry.Data() = new GenericPromise::Private(__func__);
     }
     return entry.Data();
   }
 
   RefPtr<ModuleScript> ms;
-  MOZ_ALWAYS_TRUE(mFetchedModules.Get(aRequest->mURI, getter_AddRefs(ms)));
+  MOZ_ALWAYS_TRUE(mFetchedModules.Get(aURL, getter_AddRefs(ms)));
   if (!ms) {
     return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
   }
 
   return GenericPromise::CreateAndResolve(true, __func__);
 }
 
 ModuleScript*
@@ -983,19 +983,19 @@ ScriptLoader::StartLoad(ScriptLoadReques
     aRequest->mURI->GetAsciiSpec(url);
     LOG(("ScriptLoadRequest (%p): Start Load (url = %s)", aRequest, url.get()));
   }
 
   if (aRequest->IsModuleRequest()) {
     // Check whether the module has been fetched or is currently being fetched,
     // and if so wait for it.
     ModuleLoadRequest* request = aRequest->AsModuleRequest();
-    if (ModuleMapContainsModule(request)) {
+    if (ModuleMapContainsURL(request->mURI)) {
       LOG(("ScriptLoadRequest (%p): Waiting for module fetch", aRequest));
-      WaitForModuleFetch(request)
+      WaitForModuleFetch(request->mURI)
         ->Then(GetMainThreadSerialEventTarget(), __func__, request,
                &ModuleLoadRequest::ModuleLoaded,
                &ModuleLoadRequest::LoadFailed);
       return NS_OK;
     }
 
     // Otherwise put the URL in the module map and mark it as fetching.
     SetModuleFetchStarted(request);
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -466,18 +466,18 @@ private:
   bool ModuleScriptsEnabled();
 
   void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
   void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,
                                                       nsresult aResult);
 
   bool IsFetchingModule(ModuleLoadRequest* aRequest) const;
 
-  bool ModuleMapContainsModule(ModuleLoadRequest* aRequest) const;
-  RefPtr<mozilla::GenericPromise> WaitForModuleFetch(ModuleLoadRequest* aRequest);
+  bool ModuleMapContainsURL(nsIURI* aURL) const;
+  RefPtr<mozilla::GenericPromise> WaitForModuleFetch(nsIURI* aURL);
   ModuleScript* GetFetchedModule(nsIURI* aURL) const;
 
   friend bool
   HostResolveImportedModule(JSContext* aCx, unsigned argc, JS::Value* vp);
 
   // Returns wether we should save the bytecode of this script after the
   // execution of the script.
   static bool