[whatwg] <video> ... <script> race condition

Simon Pieters simonp at opera.com
Mon May 16 00:20:31 PDT 2011


On Sun, 15 May 2011 19:11:09 +0200, Glenn Maynard <glenn at zewt.org> wrote:

> On Sat, May 14, 2011 at 11:49 AM, Eric Carlson  
> <eric.carlson at apple.com>wrote:
>
>>  It seems to me that the right way to "fix" the problem is let people  
>> know
>> it is sloppy code, not to figure out a way to work around it.
>>
>
> The basic problem is that it isn't sloppy code: it's correct for almost  
> all
> events.  It's just wrong for events that are fired as part of loading,  
> which
> is what makes it so easy to get wrong.  It also means that these events
> don't work well with deferred scripts.
>
> For the simple cases I'd probably do:
>
> video.addEventListener("canplay", func, false);
> if(video.readyState >= HAVE_FUTURE_DATA)
>     func.apply(video); // missed the first one

The state can have changed before the event has actually fired, since  
state changes are sync but the events are queued. So if the script happens  
to run in between then func is run twice. See  
http://www.w3.org/Bugs/Public/show_bug.cgi?id=12267

-- 
Simon Pieters
Opera Software



More information about the whatwg mailing list