Bug 175802
| Summary: | RTCPeerConnection addEventListener handler context changed (a new this?) | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Jia Li <jiali.passion> |
| Component: | UI Events | Assignee: | 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
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 | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Mark Roberts
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
<rdar://problem/34035850>