Bug 1426189 - Make document.currentScript null in modules r=baku
authorJon Coppeard <jcoppeard@mozilla.com>
Mon, 08 Jan 2018 18:07:39 +0000
changeset 398261 eeeb7268e4921056013c8fe1f774f18b2db819f3
parent 398260 a7b9b4a615cc0887e62b0f9ad86e85a211f175fa
child 398262 05fed903f40f05fd923ba2137696ecc1fa0bafe6
child 398318 4e0e46d3ef07a672fbd2eff8093d42a0530bee95
push id33212
push userbtara@mozilla.com
push dateMon, 08 Jan 2018 22:06:17 +0000
treeherdermozilla-central@05fed903f40f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1426189
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 1426189 - Make document.currentScript null in modules r=baku
dom/script/ScriptLoader.cpp
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/currentScript-null.html.ini
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -472,19 +472,16 @@ ScriptLoader::CreateModuleScript(ModuleL
   nsAutoMicroTask mt;
   AutoEntryScript aes(globalObject, "CompileModule", true);
 
   bool oldProcessingScriptTag = context->GetProcessingScriptTag();
   context->SetProcessingScriptTag(true);
 
   nsresult rv;
   {
-    // Update our current script.
-    AutoCurrentScriptUpdater scriptUpdater(this, aRequest->mElement);
-
     JSContext* cx = aes.cx();
     JS::Rooted<JSObject*> module(cx);
 
     if (aRequest->mWasCompiledOMT) {
       module = JS::FinishOffThreadModule(cx, aRequest->mOffThreadToken);
       aRequest->mOffThreadToken = nullptr;
       rv = module ? NS_OK : NS_ERROR_FAILURE;
     } else {
@@ -2205,25 +2202,25 @@ ScriptLoader::EvaluateScript(ScriptLoadR
   AutoEntryScript aes(globalObject, "<script> element", true);
   JSContext* cx = aes.cx();
   JS::Rooted<JSObject*> global(cx, globalObject->GetGlobalJSObject());
 
   bool oldProcessingScriptTag = context->GetProcessingScriptTag();
   context->SetProcessingScriptTag(true);
   nsresult rv;
   {
-    // Update our current script.
-    AutoCurrentScriptUpdater scriptUpdater(this, aRequest->mElement);
-
     if (aRequest->IsModuleRequest()) {
       // When a module is already loaded, it is not feched a second time and the
       // mDataType of the request might remain set to DataType::Unknown.
       MOZ_ASSERT(!aRequest->IsBytecode());
       LOG(("ScriptLoadRequest (%p): Evaluate Module", aRequest));
 
+      // currentScript is set to null for modules.
+      AutoCurrentScriptUpdater scriptUpdater(this, nullptr);
+
       rv = EnsureModuleResolveHook(cx);
       NS_ENSURE_SUCCESS(rv, rv);
 
       ModuleLoadRequest* request = aRequest->AsModuleRequest();
       MOZ_ASSERT(request->mModuleScript);
       MOZ_ASSERT(!request->mOffThreadToken);
 
       ModuleScript* moduleScript = request->mModuleScript;
@@ -2241,16 +2238,19 @@ ScriptLoader::EvaluateScript(ScriptLoadR
       MOZ_ASSERT(NS_FAILED(rv) == aes.HasException());
       if (NS_FAILED(rv)) {
         LOG(("ScriptLoadRequest (%p):   evaluation failed", aRequest));
         rv = NS_OK; // An error is reported by AutoEntryScript.
       }
 
       aRequest->mCacheInfo = nullptr;
     } else {
+      // Update our current script.
+      AutoCurrentScriptUpdater scriptUpdater(this, aRequest->mElement);
+
       JS::CompileOptions options(cx);
       rv = FillCompileOptionsForRequest(aes, aRequest, global, &options);
 
       if (NS_SUCCEEDED(rv)) {
         if (aRequest->IsBytecode()) {
           TRACE_FOR_TEST(aRequest->mElement, "scriptloader_execute");
           nsJSUtils::ExecutionContext exec(cx, global);
           if (aRequest->mOffThreadToken) {
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/currentScript-null.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[currentScript-null.html]
-  type: testharness
-  [currentScript on script type=module should be all null]
-    expected: FAIL
-