Bug 1342012 - Associate event handler with active script when they are compiled r=smaug
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 03 Jan 2019 10:06:01 +0000
changeset 509513 83937d7bd335502994bddba98238fb8f0c713067
parent 509512 85c9dc639077c81e38bedf9fd01fea9bd99084df
child 509514 5ad9c5b505d3e84d4db7e242d53b881b967a2ffc
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1342012
milestone66.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 1342012 - Associate event handler with active script when they are compiled r=smaug
dom/events/EventListenerManager.cpp
dom/script/LoadedScript.cpp
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html.ini
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html.ini
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html.ini
testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html.ini
--- a/dom/events/EventListenerManager.cpp
+++ b/dom/events/EventListenerManager.cpp
@@ -17,17 +17,19 @@
 #include "mozilla/JSEventHandler.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/Event.h"
 #include "mozilla/dom/EventTargetBinding.h"
+#include "mozilla/dom/LoadedScript.h"
 #include "mozilla/dom/PopupBlocker.h"
+#include "mozilla/dom/ScriptLoader.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/dom/TouchEvent.h"
 #include "mozilla/TimelineConsumers.h"
 #include "mozilla/EventTimelineMarker.h"
 #include "mozilla/TimeStamp.h"
 
 #include "EventListenerService.h"
 #include "nsCOMArray.h"
@@ -985,16 +987,25 @@ nsresult EventListenerManager::CompileEv
 
   JS::Rooted<JSObject*> handler(cx);
   result = nsJSUtils::CompileFunction(jsapi, scopeChain, options,
                                       nsAtomCString(typeAtom), argCount,
                                       argNames, *body, handler.address());
   NS_ENSURE_SUCCESS(result, result);
   NS_ENSURE_TRUE(handler, NS_ERROR_FAILURE);
 
+  JS::Rooted<JSFunction*> func(cx, JS_GetObjectFunction(handler));
+  MOZ_ASSERT(func);
+  JS::Rooted<JSScript*> jsScript(cx, JS_GetFunctionScript(cx, func));
+  MOZ_ASSERT(jsScript);
+  RefPtr<LoadedScript> loaderScript = ScriptLoader::GetActiveScript(cx);
+  if (loaderScript) {
+    loaderScript->AssociateWithScript(jsScript);
+  }
+
   MOZ_ASSERT(js::IsObjectInContextCompartment(handler, cx));
   JS::Rooted<JSObject*> handlerGlobal(cx, JS::CurrentGlobalOrNull(cx));
 
   if (jsEventHandler->EventName() == nsGkAtoms::onerror && win) {
     RefPtr<OnErrorEventHandlerNonNull> handlerCallback =
         new OnErrorEventHandlerNonNull(static_cast<JSContext*>(nullptr),
                                        handler, handlerGlobal,
                                        /* aIncumbentGlobal = */ nullptr);
--- a/dom/script/LoadedScript.cpp
+++ b/dom/script/LoadedScript.cpp
@@ -64,17 +64,17 @@ void HostFinalizeTopLevelScript(JSFreeOp
   // pointed to by a dying JSScript. The reference count was
   // originally incremented by AssociateWithScript() above.
 
   auto script = static_cast<LoadedScript*>(aPrivate.toPrivate());
 
 #ifdef DEBUG
   if (script->IsModuleScript()) {
     JSObject* module = script->AsModuleScript()->mModuleRecord.unbarrieredGet();
-    MOZ_ASSERT(JS::GetModulePrivate(module) == aPrivate);
+    MOZ_ASSERT_IF(module, JS::GetModulePrivate(module) == aPrivate);
   }
 #endif
 
   script->Release();
 }
 
 //////////////////////////////////////////////////////////////
 // ClassicScript
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-classic.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[string-compilation-base-url-external-classic.html]
-  [reflected-inline-event-handlers should successfully import]
-    expected: FAIL
-
-  [inline-event-handlers-UA-code should successfully import]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-base-url-external-module.html.ini
+++ /dev/null
@@ -1,7 +0,0 @@
-[string-compilation-base-url-external-module.html]
-  [reflected-inline-event-handlers should successfully import]
-    expected: FAIL
-
-  [inline-event-handlers-UA-code should successfully import]
-    expected: FAIL
-
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html.ini
+++ b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-classic.html.ini
@@ -1,10 +1,4 @@
 [string-compilation-nonce-classic.html]
   [setTimeout must inherit the nonce from the triggering script, thus execute]
     expected: FAIL
 
-  [reflected inline event handlers must inherit the nonce from the triggering script, thus execute]
-    expected: FAIL
-
-  [inline event handlers triggered via UA code must inherit the nonce from the triggering script, thus execute]
-    expected: FAIL
-
--- a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html.ini
+++ b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/dynamic-import/string-compilation-nonce-module.html.ini
@@ -1,10 +1,3 @@
 [string-compilation-nonce-module.html]
   [setTimeout must inherit the nonce from the triggering script, thus execute]
     expected: FAIL
-
-  [reflected inline event handlers must inherit the nonce from the triggering script, thus execute]
-    expected: FAIL
-
-  [inline event handlers triggered via UA code must inherit the nonce from the triggering script, thus execute]
-    expected: FAIL
-