webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.13k stars 165 forks source link

Fix failing tests: patch `XMLHttpRequest` if no `EventTarget`; dispatch a 'proxy' if `currentTarget` is an own value property descriptor #519

Closed bicknellr closed 1 year ago

bicknellr commented 1 year ago

In at least Chrome 41, events' currentTarget is an own property with a broken descriptor. Setting a new descriptor on one of these events makes it impossible to restore the default behavior of currentTarget for that event, making it useless to any later listeners. Shady DOM occasionally has to manually dispatch an event, which involves temporarily setting a new currentTarget descriptor to allow Shady DOM to update this property. With this PR, if the currentTarget property of events is broken as it is in Chrome 41, Shady DOM will create a new object with the event as its prototype, modify that new object's currentTarget descriptor, and pass that new object to listeners during the manual dispatch.

EventTarget doesn't exist in some older browsers, so objects that would normally have EventTarget.prototype in their prototype chain in modern browsers instead have separate copies of those properties on other prototypes. XMLHttpRequest is one of these objects with EventTarget-like properties, but these properties were unpatched until this PR.