Default CustomEvent detail to null when omitted - #689
olavoasantos wants to merge 1 commit into
Conversation
ef61cb9 to
294986c
Compare
294986c to
5f0b228
Compare
henrytao-me
left a comment
There was a problem hiding this comment.
LGTM for the scoped default-detail fix, reviewed at 5f0b2281bddfc7ac37c64503f40f38f4f9b98243 against actual #688 base 3c57e5b6202f0779eb7ee99ad3298f6d17032c51.
The constructor and legacy initCustomEvent() now use the DOM null default for omitted/undefined detail while preserving explicit falsy values and payload identity. I found no introduced blocker.
Validation:
- 108 polyfill tests and 56 focused core tests pass.
- The eight added constructor cases produce 3 failures / 5 passes on the base, matching the intended default changes.
- All 43 isolated native/base/head comparisons match the head, including legacy defaults, payload identity, detail getters, original getter errors, and listener delivery.
- Locked Prettier passes; reported current-head CI is green.
Non-blocking test suggestion: add initCustomEvent() cases for resetting a populated event with omitted/undefined detail and preserving falsy/object values. This method changed too, while the new repository tests exercise only the constructor; the separate native probe verified both paths.
This approval is scoped code-review sign-off, not a full locked build or live Shell/admin tophat. Restack/recheck as the parent lands; integrated stack and live-validation gates remain separate.
Problem
CustomEvent.detailwas assigned directly from the optional initialization dictionary. Constructing aCustomEventwithout adetailproperty therefore exposedundefined, whereas the event’s default detail value isnull.Impact
Minor. Consumers that distinguish an omitted payload from an explicitly supplied value can observe the wrong public event contract. In the worker polyfill, that makes
CustomEventbehave differently from the DOM API it models.Reproduction
Before this change, both expressions evaluated to
undefined. They now evaluate tonull. The regression test also shows that explicitly suppliednull,0,false,'', and object values are preserved; an explicitlyundefineddetailis normalized tonullby this implementation.Change
Normalize the constructor’s
detailvalue tonullwhen it is nullish. The same normalization is applied by the legacyinitCustomEvent()path so both ways of creating a custom event expose the same default.Tests
Adds focused constructor coverage for an omitted initialization dictionary, a dictionary without
detail, explicitundefined, and explicitly supplied falsy and object values.Stack
fix-node-containsValidation
Fresh GitHub CI on restacked head
5f0b228passes: