Re: Strict mode callbacks and setTimeout

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:

  http://people.mozilla.org/~cmccormack/tests/settimeout-this.html

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

Adding that to the test:

  http://people.mozilla.org/~cmccormack/tests/settimeout-this-2.html

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