haikuwebkit/LayoutTests/fast/events/window-event-onerror-recurs...

35 lines
1.0 KiB
HTML
Raw Permalink Normal View History

window.event may get set on wrong global when dispatching an event https://bugs.webkit.org/show_bug.cgi?id=218546 Reviewed by Sam Weinig. LayoutTests/imported/w3c: Rebaseline WPT test that is now passing. * web-platform-tests/dom/events/event-global-extra.window-expected.txt: Source/WebCore: As per the specification [1], while invoking an event listener, we should set the global's 'current event', stating that global is the 'listener callback’s associated Realm’s global object'. It also states we should do so only if global is a Window object. Previously, we were setting the 'current event' on the wrong global. We were using the global of the object the event listener was registered on. [1] https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke Tests: fast/events/window-event-onerror-recursive.html fast/events/window-event-onerror.html fast/events/window-event-recursive.html * bindings/js/JSDOMGlobalObject.cpp: * bindings/js/JSDOMGlobalObject.h: * bindings/js/JSDOMWindowBase.cpp: (WebCore::JSDOMWindowBase::setCurrentEvent): (WebCore::JSDOMWindowBase::currentEvent const): * bindings/js/JSDOMWindowBase.h: * bindings/js/JSErrorHandler.cpp: (WebCore::JSErrorHandler::handleEvent): * bindings/js/JSEventListener.cpp: (WebCore::JSEventListener::handleEvent): LayoutTests: Extend layout test coverage. * fast/events/window-event-onerror-expected.txt: Added. * fast/events/window-event-onerror-recursive-expected.txt: Added. * fast/events/window-event-onerror-recursive.html: Added. * fast/events/window-event-onerror.html: Added. * fast/events/window-event-recursive.html: Added. Canonical link: https://commits.webkit.org/231243@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269414 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-05 02:23:30 +00:00
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/js-test.js"></script>
<script>
description("Tests that window.event is set on the right global when an error event is fired.");
let dispatchedRecursiveEvent = false;
const otherWindow = document.body.appendChild(document.createElement("iframe")).contentWindow;
otherWindow.onerror = (e) => {
passedEvent = e;
shouldBeUndefined("otherWindow.event");
shouldBe("passedEvent", "window.event");
if (!dispatchedRecursiveEvent) {
dispatchedRecursiveEvent = true;
debug("Dispatching recursive error event");
otherWindow.dispatchEvent(new Event("error"));
passedEvent = e;
shouldBeUndefined("otherWindow.event");
shouldBe("passedEvent", "window.event");
}
}
shouldBeUndefined("otherWindow.event");
shouldBeUndefined("window.event");
debug("Dispatching error event");
otherWindow.dispatchEvent(new Event("error"));
shouldBeUndefined("otherWindow.event");
shouldBeUndefined("window.event");
</script>
</body>
</html>