Bug 142954 - img load event forgets img target when passed through Promise
Summary: img load event forgets img target when passed through Promise
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Depends on:
Reported: 2015-03-22 18:40 PDT by Ben
Modified: 2019-02-06 09:19 PST (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Ben 2015-03-22 18:40:37 PDT
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 


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

Comment 1 Ben 2015-03-22 19:41:54 PDT
Minimal test case

(new Promise( function( resolve ) {
    var i = document.createElement("IMG");
    i.onload = function( event ) {
        console.log("onload", event.target ); // -> <img ...>
    i.src = "http://i.imgur.com/waV028T.jpg";
})).then( function( resolved_event ) {
    console.log( resolved_event.target ); // -> null
Comment 2 Lucas Forschler 2019-02-06 09:19:02 PST
Mass move bugs into the DOM component.