Bug 1529203 - Clear the module map when changing a Document's global r=bzbarsky a=abillings
authorJon Coppeard <jcoppeard@mozilla.com>
Fri, 01 Mar 2019 16:53:47 +0000
changeset 516233 0f09554ca8cbab37de0187b6d67a25739a18ede4
parent 516232 a95052dd004316192c823033b4aad5e8dc6f2493
child 516234 4c7d56a0a897172ef44a9a63047ceba033ac49e1
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, abillings
bugs1529203
milestone66.0
Bug 1529203 - Clear the module map when changing a Document's global r=bzbarsky a=abillings Differential Revision: https://phabricator.services.mozilla.com/D21718
dom/html/nsHTMLDocument.cpp
dom/script/ScriptLoader.cpp
dom/script/ScriptLoader.h
xpcom/ds/nsBaseHashtable.h
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -1316,16 +1316,19 @@ already_AddRefed<Document> nsHTMLDocumen
     nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(shell));
     webnav->Stop(nsIWebNavigation::STOP_NETWORK);
 
     // The Stop call may have cancelled the onload blocker request or prevented
     // it from getting added, so we need to make sure it gets added to the
     // document again otherwise the document could have a non-zero onload block
     // count without the onload blocker request being in the loadgroup.
     EnsureOnloadBlocker();
+
+    // Throw away loaded modules created for the previous global.
+    ScriptLoader()->ClearModuleMap();
   }
 
   // The open occurred after the document finished loading.
   // So we reset the document and then reinitialize it.
   nsCOMPtr<nsIDocShell> curDocShell = GetDocShell();
   nsCOMPtr<nsIDocShellTreeItem> parent;
   if (curDocShell) {
     curDocShell->GetSameTypeParent(getter_AddRefs(parent));
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -395,16 +395,21 @@ ModuleScript* ScriptLoader::GetFetchedMo
   }
 
   bool found;
   ModuleScript* ms = mFetchedModules.GetWeak(aURL, &found);
   MOZ_ASSERT(found);
   return ms;
 }
 
+void ScriptLoader::ClearModuleMap() {
+  MOZ_ASSERT(mFetchingModules.IsEmpty());
+  mFetchedModules.Clear();
+}
+
 nsresult ScriptLoader::ProcessFetchedModuleSource(ModuleLoadRequest* aRequest) {
   MOZ_ASSERT(!aRequest->mModuleScript);
 
   nsresult rv = CreateModuleScript(aRequest);
   MOZ_ASSERT(NS_FAILED(rv) == !aRequest->mModuleScript);
 
   aRequest->ClearScriptSource();
 
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -336,16 +336,22 @@ class ScriptLoader final : public nsISup
   /*
    * Get the currently active script. This is used as the initiating script when
    * executing timeout handler scripts.
    */
   static LoadedScript* GetActiveScript(JSContext* aCx);
 
   Document* GetDocument() const { return mDocument; }
 
+  /*
+   * Clear the map of loaded modules. Called when a Document object is reused
+   * for a different global.
+   */
+  void ClearModuleMap();
+
  private:
   virtual ~ScriptLoader();
 
   void EnsureModuleHooksInitialized();
 
   ScriptLoadRequest* CreateLoadRequest(
       ScriptKind aKind, nsIURI* aURI, nsIScriptElement* aElement,
       nsIPrincipal* aTriggeringPrincipal, mozilla::CORSMode aCORSMode,
--- a/xpcom/ds/nsBaseHashtable.h
+++ b/xpcom/ds/nsBaseHashtable.h
@@ -53,16 +53,17 @@ class nsBaseHashtable
   typedef mozilla::fallible_t fallible_t;
 
  public:
   typedef typename KeyClass::KeyType KeyType;
   typedef nsBaseHashtableET<KeyClass, DataType> EntryType;
 
   using nsTHashtable<EntryType>::Contains;
   using nsTHashtable<EntryType>::GetGeneration;
+  using nsTHashtable<EntryType>::IsEmpty;
   using nsTHashtable<EntryType>::SizeOfExcludingThis;
   using nsTHashtable<EntryType>::SizeOfIncludingThis;
 
   nsBaseHashtable() {}
   explicit nsBaseHashtable(uint32_t aInitLength)
       : nsTHashtable<EntryType>(aInitLength) {}
 
   /**