<?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>142954</bug_id>
          
          <creation_ts>2015-03-22 18:40:37 -0700</creation_ts>
          <short_desc>img load event forgets img target when passed through Promise</short_desc>
          <delta_ts>2024-05-21 09:30:29 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ben">bbirch</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>karlcow</cc>
    
    <cc>rniwa</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1079191</commentid>
    <comment_count>0</comment_count>
    <who name="Ben">bbirch</who>
    <bug_when>2015-03-22 18:40:37 -0700</bug_when>
    <thetext>Wrapping image loading in a Promise does not work as expected.

After the image load event fires event.target contains a IMG element
When the promise is resolved event.target is null

It can be worked around by resolving the promise with event.target rather than event

Here is a demonstration 

http://jsfiddle.net/8ys0dn4x/1/

Fails in Safari and webkit nightly 
In Firefox the code works as expected
In Chrome there is also a bug, however it is slightly different in that the last promise to resolve in a group still remembers the target, but others are null

Here is a variation on the demonstration

http://jsfiddle.net/d13sf3f2/5/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1079211</commentid>
    <comment_count>1</comment_count>
    <who name="Ben">bbirch</who>
    <bug_when>2015-03-22 19:41:54 -0700</bug_when>
    <thetext>Minimal test case

(new Promise( function( resolve ) {
    var i = document.createElement(&quot;IMG&quot;);
    i.onload = function( event ) {
        console.log(&quot;onload&quot;, event.target ); // -&gt; &lt;img ...&gt;
        resolve(event);
    };
    i.src = &quot;http://i.imgur.com/waV028T.jpg&quot;;
})).then( function( resolved_event ) {
    console.log( resolved_event.target ); // -&gt; null
});</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1503296</commentid>
    <comment_count>2</comment_count>
    <who name="Lucas Forschler">lforschler</who>
    <bug_when>2019-02-06 09:19:02 -0800</bug_when>
    <thetext>Mass move bugs into the DOM component.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2036748</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-05-21 09:30:29 -0700</bug_when>
    <thetext>It seems to work for me and matching with Chrome Canary 127.

Test case from Comment 0 shows two console message across all browsers (Safari 17.5 , Chrome Canary 127 and Firefox Nightly 128).</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>