summaryrefslogtreecommitdiff
path: root/dom/events
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-04-21 17:55:33 -0500
committerBrian Smith <brian@dbsoft.org>2023-04-27 13:35:01 -0500
commit30a6828f475a76f88c292b8b3fd0163839db5b29 (patch)
tree525045fbce02c54b3d0cf3efe9e4290b81cbc6b4 /dom/events
parent914299b8ba22bb40fc30f83fe5481ebf4598ab48 (diff)
downloaduxp-30a6828f475a76f88c292b8b3fd0163839db5b29.tar.gz
Issue #1691 - Part 9: Make import() work when the active script is in another document.
https://bugzilla.mozilla.org/show_bug.cgi?id=1342012 Associate event handler with active script when they are compiled. (cherry picked from commit 1a3cc5d6828a05a6309d959fad3c7e959ab9eb8d)
Diffstat (limited to 'dom/events')
-rw-r--r--dom/events/EventListenerManager.cpp11
1 files changed, 11 insertions, 0 deletions
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<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);
+ }
+
if (jsEventHandler->EventName() == nsGkAtoms::onerror && win) {
RefPtr<OnErrorEventHandlerNonNull> handlerCallback =
new OnErrorEventHandlerNonNull(nullptr, handler, /* aIncumbentGlobal = */ nullptr);