Bug 1292614 - Set introductionType correctly for imported modules r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 18 Aug 2016 10:26:16 +0100
changeset 309945 72f943bf11090f85584637aa202ecfb0a45f690d
parent 309944 775fa3ede1603f56bc128a21d0d1e733e70039cc
child 309946 7d3e8cea2291576c15ce3aca91b2161dfa8941d3
push id80720
push userjcoppeard@mozilla.com
push dateThu, 18 Aug 2016 09:43:57 +0000
treeherdermozilla-inbound@72f943bf1109 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1292614
milestone51.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 1292614 - Set introductionType correctly for imported modules r=smaug
dom/base/nsScriptLoader.cpp
dom/base/test/jsmodules/chrome.ini
dom/base/test/jsmodules/iframe_extractIntroType.html
dom/base/test/jsmodules/module_extractIntroType.js
dom/base/test/jsmodules/test_importIntroType.html
dom/base/test/jsmodules/test_topLevelIntroType.html
--- a/dom/base/nsScriptLoader.cpp
+++ b/dom/base/nsScriptLoader.cpp
@@ -1921,17 +1921,20 @@ nsScriptLoader::FillCompileOptionsForReq
                                              nsScriptLoadRequest *aRequest,
                                              JS::Handle<JSObject *> aScopeChain,
                                              JS::CompileOptions *aOptions)
 {
   // It's very important to use aRequest->mURI, not the final URI of the channel
   // aRequest ended up getting script data from, as the script filename.
   nsContentUtils::GetWrapperSafeScriptFilename(mDocument, aRequest->mURI, aRequest->mURL);
 
-  aOptions->setIntroductionType("scriptElement");
+  bool isScriptElement = !aRequest->IsModuleRequest() ||
+                         aRequest->AsModuleRequest()->IsTopLevel();
+  aOptions->setIntroductionType(isScriptElement ? "scriptElement"
+                                                : "importedModule");
   aOptions->setFileAndLine(aRequest->mURL.get(), aRequest->mLineNo);
   aOptions->setVersion(JSVersion(aRequest->mJSVersion));
   aOptions->setIsRunOnce(true);
   // We only need the setNoScriptRval bit when compiling off-thread here, since
   // otherwise nsJSUtils::EvaluateString will set it up for us.
   aOptions->setNoScriptRval(true);
   if (aRequest->mHasSourceMapURL) {
     aOptions->setSourceMapURL(aRequest->mSourceMapURL.get());
--- a/dom/base/test/jsmodules/chrome.ini
+++ b/dom/base/test/jsmodules/chrome.ini
@@ -13,16 +13,18 @@ support-files =
   module_cyclic2.js
   module_cyclic3.js
   module_multiImports.js
   module_multiLargeImports.js
   script_simple2.js
   module_large1.js
   module_large2.js
   module_large3.js
+  module_extractIntroType.js
+  iframe_extractIntroType.html
 
 [test_moduleScriptsRun.html]
 [test_moduleParsedAsModule.html]
 [test_scriptNotParsedAsModule.html]
 [test_typeAttrCaseInsensitive.html]
 [test_moduleNotFound.html]
 [test_importNotFound.html]
 [test_syntaxError.html]
@@ -37,8 +39,10 @@ support-files =
 [test_multiAsyncImports.html]
 [test_scriptModuleOrder.html]
 [test_toplevelModuleMemoization.html]
 [test_importedModuleMemoization.html]
 [test_multiTopLevelLargeImports.html]
 [test_multiModuleLargeImports.html]
 [test_asyncInlineModules.html]
 [test_scriptInsertedModule.html]
+[test_topLevelIntroType.html]
+[test_importIntroType.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/jsmodules/iframe_extractIntroType.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+  // Hook up the debugger statement to extract the calling script's
+  // introductionType and set it in a property on the parent global.
+  Components.utils.import("resource://gre/modules/jsdebugger.jsm");
+  addDebuggerToGlobal(this);
+  var dbg = new Debugger;
+  dbg.addDebuggee(parent);
+  dbg.onDebuggerStatement = function (frame) {
+    parent.introType = frame.script.source.introductionType;
+  }
+</script>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/jsmodules/module_extractIntroType.js
@@ -0,0 +1,5 @@
+// Extract the introductionType for this module in conjunction with
+// iframe_extractIntroType.html.
+extractIntroType = function() {
+    debugger;
+}
new file mode 100644
--- /dev/null
+++ b/dom/base/test/jsmodules/test_importIntroType.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test introduction type of an imported module</title>
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+  var introType;
+  var extractIntroType;
+
+  info('start');
+  SimpleTest.waitForExplicitFinish();
+
+  function testIntroductionType() {
+    extractIntroType();
+    ok(introType == "importedModule", 'Check introduction type');
+    SimpleTest.finish();
+  }
+</script>
+<iframe src="iframe_extractIntroType.html"></iframe>
+<script type="module">
+import "./module_extractIntroType.js";
+</script>
+<body onload='testIntroductionType()'></body>
new file mode 100644
--- /dev/null
+++ b/dom/base/test/jsmodules/test_topLevelIntroType.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Test introduction type of a top-level module</title>
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<script>
+  var introType;
+  var extractIntroType;
+
+  info('start');
+  SimpleTest.waitForExplicitFinish();
+
+  function testIntroductionType() {
+    extractIntroType();
+    ok(introType == "scriptElement", 'Check introduction type');
+    SimpleTest.finish();
+  }
+</script>
+<iframe src="iframe_extractIntroType.html"></iframe>
+<script type="module" src="module_extractIntroType.js">
+</script>
+<body onload='testIntroductionType()'></body>