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

Re: Strict mode callbacks and setTimeout

From: Cameron McCormack <cam@mcc.id.au>
Date: Thu, 7 Jul 2011 11:35:46 +1200
To: "Mark S. Miller" <erights@google.com>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, 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
Message-ID: <20110706233546.GB21787@wok.mcc.id.au>
Mark S. Miller:
> Then
>     (1,setTimeout)(function(){'use strict'; alert('foo'); }, 0)
> should throw a TypeError on all browsers. I think the bug is in this part of
> WebIDL, but this something we could argue about. There is definitely a bug
> somewhere.

I did some testing recently and found that all major browsers throw when
given a random this object:


but I didn’t test it with undefined as the this value.

Adding that to the test:


I find that setTimeout.call(undefined) works in Firefox/Chrome/Safari/
Opera but not in IE.  It looks like no implementation implements the ES5
requirement that

  (function() { return this }).call(undefined)

return undefined.  Did I test that correctly?  (Maybe IE is doing
something different for native Functions and setTimeout.)

> Proposal: I think WebIDL should distinguish between methods sensitive to
> their this-binding and functions which are not. I think setTimeout should be
> classified as a function not sensitive to its this-binding.

I doubt authors are doing setTimeout.call(undefined).  However, they
probably are doing bare setTimeout() calls in strict mode.

Cameron McCormack ≝ http://mcc.id.au/
Received on Wednesday, 6 July 2011 23:36:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:03 UTC