W3C home > Mailing lists > Public > whatwg@whatwg.org > March 2014

Re: [whatwg] Promise-vending loaded() & ready() methods on various elements

From: Jake Archibald <jaffathecake@gmail.com>
Date: Wed, 12 Mar 2014 14:27:30 +0000
Message-ID: <CAJ5xic83Cw7pn76dqtbTALzzLJKZhyssfgvSx-c3WvmzFhTWiQ@mail.gmail.com>
To: Domenic Denicola <domenic@domenicdenicola.com>
Cc: "whatwg@lists.whatwg.org" <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>
On 12 March 2014 14:17, Domenic Denicola <domenic@domenicdenicola.com>wrote:
>
> var img = document.createElement("img");
> var promise1 = img.loaded();
> img.src =" foo.png";
> var promise2 = img.loaded();
>
> // (1) will promise1 be immediately fulfilled, since img has "about:blank"
> or similar loaded already?
> // (2) or will promise1 and promise2 fulfill at the same time, since
> promise1 waits until a src appears?
> // (3) or will promise1 be rejected with AbortError, similar to Jake's
> previous case?
> // (4) or it could be rejected with an "InvalidStateError" saying you
> can't wait for the loading of a non-src'ed image.
>
> Here (1), (3), and (4) seem to encourage a consistent model of "always ask
> for loaded() promises after setting src, otherwise it won't work". It's (2)
> that's problematic as if that's the case then asking for loaded() promises
> before setting src sometimes works, but usually doesn't.
>

This is a very good point, and I'd say (4).

Lets say you didn't change the src:

(1) Means the promise would reject with an EncodingError as it isn't a
valid image format
(2) Would remain unresolved
(3) N/A
(4) Reject with InvalidStateError

The consistency makes me like (4) the most.
Received on Wednesday, 12 March 2014 14:27:59 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:17 UTC