Bug 175802

Summary: RTCPeerConnection addEventListener handler context changed (a new this?)
Product: WebKit Reporter: Jia Li <jiali.passion>
Component: UI EventsAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: cdumez, eric.carlson, marcel, mroberts, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Mac   
OS: macOS 10.12.4   

Jia Li
Reported 2017-08-21 17:48:46 PDT
The reproduce code is below. <html> <head> <script> window.onload = function () { console.log('Create RTCPeerConnection') const pc = new RTCPeerConnection() console.log('Add "track" event listener') pc.addEventListener('track', function(_event) { console.log('this === pc', this === pc); console.log('track event', _event); }); console.log('Dispatch "track" event') pc.dispatchEvent(new Event('track')) } </script> </head> </html> the output will be ------------------------ this === pc, false in the eventhandler of `track`, the context `this` is different with `pc`. In Firefox and Chrome, this is the same with pc.
Attachments
Mark Roberts
Comment 1 2017-08-21 19:11:23 PDT
I can confirm this happens for apparently any event dispatched to RTCPeerConnection (all WebRTC-related events and even arbitrary events like "foo").
Radar WebKit Bug Importer
Comment 2 2017-08-23 09:12:07 PDT
Note You need to log in before you can comment on or make changes to this bug.