W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2011

Re: Strict mode callbacks and setTimeout

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 06 Jul 2011 16:56:45 -0400
Message-ID: <4E14CC0D.8090204@mit.edu>
To: "Mark S. Miller" <erights@google.com>
CC: Allen Wirfs-Brock <allen@wirfs-brock.com>, Luke Hoban <lukeh@microsoft.com>, "es5-discuss@mozilla.org" <es5-discuss@mozilla.org>, public-script-coord@w3.org
On 7/6/11 4:42 PM, Mark S. Miller wrote:
> The normative text is the more useful interpretation, in that access to
> a frame's setTimeout function should provide the ability to schedule a
> call to happen later, but should not provide access to that frame's
> global object.

You can't do the former without having the latter.  In particular, 
invoking a frame's setTimeout function without the right |this| will throw.

Of course you could be handed a prebound function which will invoke with 
the right |this|....

> The alternative, of changing the HTML5 spec to pass some global object
> explicitly, would require yet more hard to explain and emulate magic,
> since, for legacy compat, a setTimeout from frame X calling a callback
> from frame Y would need to explicitly pass Y's global object.

This is true for non-strict-mode code already, right?  Or am I 
misunderstanding the problem?

The problem description strongly reminds me of 
https://bugzilla.mozilla.org/show_bug.cgi?id=634590 by the way.

> An emulated setTimeout written in JavaScript *could not* correctly emulate
> this behavior without introducing a generic way to get Y's global object
> from a frame Y closure.

Again, you need that anyway to be able to setTimeout non-strict-mode 
things, seems like.

> I think we should see this as yet more teething pains as browsers
> improve their ES5 implementations to be more conformant. In that
> context, given the HTML5 normative spec text above

It's not clear to me that the HTML5 spec normative text is necessarily 
correct.

What do browsers set |this| to in a function if you define it in one 
frame but then pass it to setTimeout in another frame and there's no 
strict mode involved?  What does the ES5 spec say about that case? 
(Probably nothing, since it assumes a unique global.)

> The HTML5 normative text is actually quite clear -- that undefined is
> provided as the thisArg.

It's clear, but it may still be wrong....

-Boris
Received on Wednesday, 6 July 2011 20:57:26 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:04 UTC