Bug 1917654, pass some reasonable object as the owner to Event's constructor, r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D221640
This commit is contained in:
Olli Pettay 2024-09-10 19:36:35 +00:00
parent 4bd881078b
commit 5145c88e01
3 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,17 @@
<script id="worker" type="javascript/worker">
(() => {
const func_0 = (e) => {
e.returnValue = false
}
self.addEventListener("error", func_0, {"passive": true})
const ref = new WeakRef(self)
self.reportError(ref)
})()
</script>
<script>
window.addEventListener("DOMContentLoaded", () => {
const blob = new Blob([document.querySelector('#worker').textContent], { type: "text/javascript" })
const sw = new SharedWorker(window.URL.createObjectURL(blob))
sw.port.postMessage([], [])
})
</script>

View File

@ -17,3 +17,4 @@ load recursive-DOMNodeInserted.html
load recursive-onload.html
load 1397711.html
load 1856737.html
load 1917654.html

View File

@ -323,8 +323,8 @@ void WorkerErrorReport::ReportError(
MOZ_ASSERT(globalScope->GetWrapperPreserveColor() == global);
RefPtr<ErrorEvent> event =
ErrorEvent::Constructor(aTarget, u"error"_ns, init);
RefPtr<ErrorEvent> event = ErrorEvent::Constructor(
aTarget ? aTarget : globalScope, u"error"_ns, init);
event->SetTrusted(true);
if (NS_FAILED(EventDispatcher::DispatchDOMEvent(