Repository navigation
fix: report defaultView as event target for window-dispatched events - #363
Open
johnhldiver-beep wants to merge 1 commit into
Open
johnhldiver-beep wants to merge 1 commit into
johnhldiver-beep wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #298.
Dispatching directly on
windowreported the internal detachedDOMEventTargetase.targetinstead of thewindowproxy (dispatching ondocumentalready worked).Root cause: in
esm/interface/document.js,defaultViewis a Proxy overglobalThis. Itsgettrap interceptsaddEventListener/removeEventListener/dispatchEventand delegates to a detached internalEventTarget.EventTarget.dispatchEventbuilt the event path withthis(the internal target) as the reported target, so the window never appeared asevent.target.Fix (minimal, one concern): a new
DISPATCH_TARGETsymbol inesm/shared/symbols.js(mirrored incjs/).EventTarget.dispatchEventnow reportsthis[DISPATCH_TARGET] || thisas the target, anddocument.jssetset[DISPATCH_TARGET] = window.get(this)(the actual defaultView proxy) on the window's internal event target. Other nodes fall back tothis, so bubbling behavior is unchanged (a bubbled event from a descendant still reports the originating node — covered by the unchanged bubbling tests).Tests: new regression test in
test/interface/event-target.js(direct dispatch on bothdocumentandwindowassertsevent.target === view). The new test fails on base ("window is the event target", expected true / got false) and passes with the fix.node test/interface/event-target.jsand the fullnode test/index.jssuite both exit 0 with no failures. Honest limits: this suite prints no numeric assertion totals, so counts are reported as exit codes + failure-grep counts; eslint/tsc/rollup were not run (devDeps deliberately skipped for disk).Note: a 2025-02 "I'll take a look" comment never produced a PR in 20 months — stale claim, not a race. Adjacent open PR #355 (native functions read through window run with the global as receiver) touches the same
document.jsproxygetfor a different concern — disclose, do not merge into it.