You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EventTarget is broken and not aligned with spec #6022
extra built-in wrappers around on* handling in EventTarget directly are not aligned with the spec and break usage of anything subclassing EventTarget, as adding on* handlers in subclasses causes double firing and out of order.
constEventsTest1_AC={asynctest(ctrl,env,ctx){console.log('# Should print: a c')constx=newEventTarget()x.addEventListener('hit',()=>console.log('a'))x.onhit=()=>console.log('[SHOULD NOT FIRE]')x.addEventListener('hit',()=>console.log('c'))x.dispatchEvent(newEvent('hit'))awaitnewPromise((accept)=>setTimeout(accept,100))},}constEventsTest2_ABC={asynctest(ctrl,env,ctx){console.log('# Should print: a b c')constx=newEventTarget()for(consttypeof['hit']){letcurrentObject.defineProperty(x,`on${type}`,{get: ()=>current,set(value){if(current)this.removeEventListener(type,current)current=valueif(current)this.addEventListener(type,current)},})}x.addEventListener('hit',()=>console.log('a'))x.onhit=()=>console.log('b')x.addEventListener('hit',()=>console.log('c'))x.dispatchEvent(newEvent('hit'))awaitnewPromise((accept)=>setTimeout(accept,100))},}if(globalThis.process?.versions?.node||globalThis.window){awaitEventsTest1_AC.test()console.log()awaitEventsTest2_ABC.test()}export{EventsTest1_AC,EventsTest2_ABC}
on workerd, prints:
# Should print: a c
[SHOULD NOT FIRE]
a
c
# Should print: a b c
b
a
b
c
on Node.js, Chrome, Safari, Firefox, Deno and Bun prints:
# Should print: a c
a
c
# Should print: a b c
a
b
c
Activity
fix: work-around for broken workerd EventTarget