Skip to content

fix: report defaultView as event target for window-dispatched events - #363

Open
johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/298-window-event-target
Open

johnhldiver-beep wants to merge 1 commit into
WebReflection:mainfrom
johnhldiver-beep:fix/298-window-event-target

Conversation

@johnhldiver-beep

Copy link
Copy Markdown

Fixes #298.

Dispatching directly on window reported the internal detached DOMEventTarget as e.target instead of the window proxy (dispatching on document already worked).

Root cause: in esm/interface/document.js, defaultView is a Proxy over globalThis. Its get trap intercepts addEventListener/removeEventListener/dispatchEvent and delegates to a detached internal EventTarget. EventTarget.dispatchEvent built the event path with this (the internal target) as the reported target, so the window never appeared as event.target.

Fix (minimal, one concern): a new DISPATCH_TARGET symbol in esm/shared/symbols.js (mirrored in cjs/). EventTarget.dispatchEvent now reports this[DISPATCH_TARGET] || this as the target, and document.js sets et[DISPATCH_TARGET] = window.get(this) (the actual defaultView proxy) on the window's internal event target. Other nodes fall back to this, 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 both document and window asserts event.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.js and the full node test/index.js suite 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.js proxy get for a different concern — disclose, do not merge into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event target not reflected correctly for defaultView

1 participant