Bug 1330688 - Report a better error in the console when a module load fails r=baku r=flod
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 19 Dec 2017 15:29:38 +0000
changeset 448680 8e6356ea82b27a29aad6a0eea2bfa850dc4fd893
parent 448679 1e2457625325ac08b5820c186d82a8f1bdc7b20f
child 448681 fd6d8af1cda716d5dd7f876384d4af9898efe2f7
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)
reviewersbaku, flod
bugs1330688
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 1330688 - Report a better error in the console when a module load fails r=baku r=flod
dom/locales/en-US/chrome/dom/dom.properties
dom/script/ScriptLoader.cpp
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -334,16 +334,19 @@ SVGRefLoopWarning=The SVG <%S> with ID “%S” has a reference loop.
 # LOCALIZATION NOTE: The first %S is the tag name of the element in the chain where the chain was broken, the second %S is the element's ID.
 SVGRefChainLengthExceededWarning=An SVG <%S> reference chain which is too long was abandoned at the element with ID “%S”.
 # LOCALIZATION NOTE: Do not translate "<script>".
 ScriptSourceEmpty=‘%S’ attribute of <script> element is empty.
 # LOCALIZATION NOTE: Do not translate "<script>".
 ScriptSourceInvalidUri=‘%S’ attribute of <script> element is not a valid URI: “%S”
 # LOCALIZATION NOTE: Do not translate "<script>".
 ScriptSourceLoadFailed=Loading failed for the <script> with source “%S”.
+ModuleSourceLoadFailed=Loading failed for the module with source “%S”.
 # LOCALIZATION NOTE: Do not translate "<script>".
 ScriptSourceMalformed=<script> source URI is malformed: “%S”.
+ModuleSourceMalformed=Module source URI is malformed: “%S”.
 # LOCALIZATION NOTE: Do not translate "<script>".
 ScriptSourceNotAllowed=<script> source URI is not allowed in this document: “%S”.
+ModuleSourceNotAllowed=Module source URI is not allowed in this document: “%S”.
 # LOCALIZATION NOTE: %1$S is the invalid property value and %2$S is the property name.
 InvalidKeyframePropertyValue=Keyframe property value “%1$S” is invalid according to the syntax for “%2$S”.
 # LOCALIZATION NOTE: Do not translate "ReadableStream".
 ReadableStreamReadingFailed=Failed to read data from the ReadableStream: “%S”.
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -1418,23 +1418,28 @@ ScriptLoader::ProcessScriptElement(nsISc
       request->mTriggeringPrincipal = Move(principal);
       request->mIsInline = false;
       request->mReferrerPolicy = ourRefPolicy;
       // keep request->mScriptFromHead to false so we don't treat non preloaded
       // scripts as blockers for full page load. See bug 792438.
 
       rv = StartLoad(request);
       if (NS_FAILED(rv)) {
-        const char* message = "ScriptSourceLoadFailed";
-
+        const char* message;
+        bool isScript = scriptKind == ScriptKind::Classic;
         if (rv == NS_ERROR_MALFORMED_URI) {
-            message = "ScriptSourceMalformed";
+          message =
+            isScript ? "ScriptSourceMalformed" : "ModuleSourceMalformed";
         }
         else if (rv == NS_ERROR_DOM_BAD_URI) {
-            message = "ScriptSourceNotAllowed";
+          message =
+            isScript ? "ScriptSourceNotAllowed" : "ModuleSourceNotAllowed";
+        } else {
+          message =
+            isScript ? "ScriptSourceLoadFailed" : "ModuleSourceLoadFailed";
         }
 
         NS_ConvertUTF8toUTF16 url(scriptURI->GetSpecOrDefault());
         const char16_t* params[] = { url.get() };
 
         nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
             NS_LITERAL_CSTRING("Script Loader"), mDocument,
             nsContentUtils::eDOM_PROPERTIES, message,
@@ -2838,21 +2843,26 @@ ScriptLoader::OnStreamComplete(nsIIncrem
 
       uint32_t lineNo = aRequest->mElement->GetScriptLineNumber();
 
       nsAutoString url;
       if (aRequest->mURI) {
         AppendUTF8toUTF16(aRequest->mURI->GetSpecOrDefault(), url);
       }
 
+      const char* message = "ScriptSourceLoadFailed";
+      if (aRequest->IsModuleRequest()) {
+        message = "ModuleSourceLoadFailed";
+      }
+
       const char16_t* params[] = { url.get() };
 
       nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
         NS_LITERAL_CSTRING("Script Loader"), mDocument,
-        nsContentUtils::eDOM_PROPERTIES, "ScriptSourceLoadFailed",
+        nsContentUtils::eDOM_PROPERTIES, message,
         params, ArrayLength(params), nullptr,
         EmptyString(), lineNo);
     }
 
     /*
      * Handle script not loading error because source was a tracking URL.
      * We make a note of this script node by including it in a dedicated
      * array of blocked tracking nodes under its parent document.