"use strict" VS setTimeout

Andrea Giammarchi andrea.giammarchi at gmail.com
Sun Sep 7 10:57:22 PDT 2014


My same thoughts on "break the web" ... I think whoever put "use strict" in
there would eventually never expect the `this` to be the global context.

@Michał Wadas ... you haven't proved much in there ... you should look at
global methods more like this:

```js
// your global context to be executed
with({
  get window() {return this},
  setTimeout: function () { ... },
  alert: function () { ... },
  // all other window methods
}) {
  setTimeout('alert("hello world")');
}
```

The fact is a `window` method, whatever window it is and of course an
iframe will have its own, does not mean every method is automatically bound
+ even if that was the case, what you pass in there is a user defined
function, not a windows method.

I think this is an issue I am not sure how come it didn't bite already out
there ... but I also understand that putting together everyone to fix this
seems utopia so ... watch out your bounds or you might leak or change the
global context by accident where "use strict" will not save you.

Best Regards



On Sun, Sep 7, 2014 at 6:47 PM, Mark S. Miller <erights at google.com> wrote:

> On Sun, Sep 7, 2014 at 10:36 AM, Mathias Bynens <mathiasb at opera.com>
> wrote:
>
>> On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi
>> <andrea.giammarchi at gmail.com> wrote:
>> > This looks like a potential problem when possible passed methods are not
>> > bound + it looks inconsistent with *"use strict"* expectations.
>>
>
> Yes. This looks like a typical screwup. Thanks for pointing it out.
>
>
>
>
>> It’s not just `setTimeout` – other DOM timer methods have the same
>> behavior. The spec is here, FWIW:
>>
>> http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#dom-windowtimers-settimeout
>> Pretty sure this cannot be changed without breaking the Web.
>>
>
> Why? If "undefined" were passed instead, sloppy callback functions would
> still see the same behavior -- on entry they would coerce undefined to
> their global object. Do you think the web already depends on strict
> functions seeing the global object here, rather than undefined?
>
>
>
>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
>
> --
>     Cheers,
>     --MarkM
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140907/08373e44/attachment-0001.html>


More information about the es-discuss mailing list