diff --git a/dom/events/EventListenerManager.cpp b/dom/events/EventListenerManager.cpp index af268f24bb..058e6916b5 100644 --- a/dom/events/EventListenerManager.cpp +++ b/dom/events/EventListenerManager.cpp @@ -22,6 +22,8 @@ #include "mozilla/dom/Element.h" #include "mozilla/dom/Event.h" #include "mozilla/dom/EventTargetBinding.h" +#include "mozilla/dom/ModuleScript.h" +#include "mozilla/dom/ScriptLoader.h" #include "mozilla/dom/TouchEvent.h" #include "mozilla/TimelineConsumers.h" #include "mozilla/EventTimelineMarker.h" @@ -1018,6 +1020,15 @@ EventListenerManager::CompileEventHandlerInternal(Listener* aListener, NS_ENSURE_SUCCESS(result, result); NS_ENSURE_TRUE(handler, NS_ERROR_FAILURE); + JS::Rooted func(cx, JS_GetObjectFunction(handler)); + MOZ_ASSERT(func); + JS::Rooted jsScript(cx, JS_GetFunctionScript(cx, func)); + MOZ_ASSERT(jsScript); + RefPtr loaderScript = ScriptLoader::GetActiveScript(cx); + if (loaderScript) { + loaderScript->AssociateWithScript(jsScript); + } + if (jsEventHandler->EventName() == nsGkAtoms::onerror && win) { RefPtr handlerCallback = new OnErrorEventHandlerNonNull(nullptr, handler, /* aIncumbentGlobal = */ nullptr); diff --git a/dom/script/ModuleScript.cpp b/dom/script/ModuleScript.cpp index e8f2802e14..8004ede3c6 100644 --- a/dom/script/ModuleScript.cpp +++ b/dom/script/ModuleScript.cpp @@ -72,7 +72,7 @@ void HostFinalizeTopLevelScript(JSFreeOp* aFop, const JS::Value& aPrivate) { #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 diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp index d4f76d18b8..ca650c80c8 100644 --- a/dom/script/ScriptLoader.cpp +++ b/dom/script/ScriptLoader.cpp @@ -2259,9 +2259,11 @@ ScriptLoader::EvaluateScript(ScriptLoadRequest* aRequest) return NS_ERROR_FAILURE; } - nsCOMPtr scriptContent(do_QueryInterface(aRequest->Element())); - MOZ_ASSERT_IF(!scriptContent, aRequest->AsModuleRequest()->IsDynamicImport()); - if (scriptContent) { + bool isDynamicImport = aRequest->IsModuleRequest() && + aRequest->AsModuleRequest()->IsDynamicImport(); + if (!isDynamicImport) { + nsCOMPtr scriptContent(do_QueryInterface(aRequest->Element())); + MOZ_ASSERT(scriptContent); nsIDocument* ownerDoc = scriptContent->OwnerDoc(); if (ownerDoc != mDocument) { // Willful violation of HTML5 as of 2010-12-01