When focus and blur are dispatched, a global capturing event listener sees the event and manually dispatches it through the tree to listeners added with wrapped addEventListener calls. The manual dispatching patches currentTarget to return retargeted values (along with eventPhase, since we are simulating the bubbling phase via a capturing listener). When all addEventListener calls are wrapped this works fine.
However, because the capturing listener does not stop propagation, the event will also natively fire to any native listeners added with an unwrapped addEventListener call (note that Polymer does not wrapaddEventListener for listeners added via templates when in noPatch mode, as a performance optimization/correctness tradeoff). Because the manual dispatching code leaves the patched currentTarget accessor installed, it can cause the subsequent native listeners to see the same event, but with patched accessors that return invalid values (like null), rather than just the unpatched values.
This change restores the original accessors for those fields when the manual dispatching is complete, so that native listeners see native fields on the event.
This seems good to me. I think since we're having trouble with the test infra right now, an internal run on a CL that imports this branch would be a good substitute.
When
focus
andblur
are dispatched, a global capturing event listener sees the event and manually dispatches it through the tree to listeners added with wrappedaddEventListener
calls. The manual dispatching patchescurrentTarget
to return retargeted values (along witheventPhase
, since we are simulating the bubbling phase via a capturing listener). When alladdEventListener
calls are wrapped this works fine.However, because the capturing listener does not stop propagation, the event will also natively fire to any native listeners added with an unwrapped
addEventListener
call (note that Polymer does not wrapaddEventListener
for listeners added via templates when innoPatch
mode, as a performance optimization/correctness tradeoff). Because the manual dispatching code leaves the patchedcurrentTarget
accessor installed, it can cause the subsequent native listeners to see the same event, but with patched accessors that return invalid values (likenull
), rather than just the unpatched values.This change restores the original accessors for those fields when the manual dispatching is complete, so that native listeners see native fields on the event.
Fixes https://github.com/webcomponents/polyfills/issues/503.