<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>175802</bug_id>
          
          <creation_ts>2017-08-21 17:48:46 -0700</creation_ts>
          <short_desc>RTCPeerConnection addEventListener handler context changed (a new this?)</short_desc>
          <delta_ts>2017-11-09 01:31:16 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>UI Events</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>macOS 10.12.4</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jia Li">jiali.passion</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>eric.carlson</cc>
    
    <cc>marcel</cc>
    
    <cc>mroberts</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1340878</commentid>
    <comment_count>0</comment_count>
    <who name="Jia Li">jiali.passion</who>
    <bug_when>2017-08-21 17:48:46 -0700</bug_when>
    <thetext>The reproduce code is below.

&lt;html&gt;
  &lt;head&gt;
    &lt;script&gt;
      window.onload = function () {
          console.log(&apos;Create RTCPeerConnection&apos;)
          const pc = new RTCPeerConnection()

          console.log(&apos;Add &quot;track&quot; event listener&apos;)
          pc.addEventListener(&apos;track&apos;, function(_event) {
            console.log(&apos;this === pc&apos;, this === pc);
            console.log(&apos;track event&apos;, _event);
          });

          console.log(&apos;Dispatch &quot;track&quot; event&apos;)
          pc.dispatchEvent(new Event(&apos;track&apos;))
      }
    &lt;/script&gt;
  &lt;/head&gt;
&lt;/html&gt;

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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1340919</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Roberts">mroberts</who>
    <bug_when>2017-08-21 19:11:23 -0700</bug_when>
    <thetext>I can confirm this happens for apparently any event dispatched to RTCPeerConnection (all WebRTC-related events and even arbitrary events like &quot;foo&quot;).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1341556</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-08-23 09:12:07 -0700</bug_when>
    <thetext>&lt;rdar://problem/34035850&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>