use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
I know this is probably W3C land but the following code shows the global object in every JS engine I could test: ```js (function () { 'use strict'; setTimeout(function () { 'use strict'; console.log(this); // [window/global Object] }, 0); }()); ``` This looks like a potential

Re: use strict VS setTimeout

2014-09-07 Thread Mathias Bynens
On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: This looks like a potential problem when possible passed methods are not bound + it looks inconsistent with *use strict* expectations. It’s not just `setTimeout` – other DOM timer methods have the same

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
Fair enough, I was looking for that part indeed but couldn't find anything explicitly related in here: http://www.w3.org/TR/2011/WD-html5-20110525/timers.html Thanks! On Sun, Sep 7, 2014 at 6:36 PM, Mathias Bynens mathi...@opera.com wrote: On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi

Re: use strict VS setTimeout

2014-09-07 Thread Mark S. Miller
On Sun, Sep 7, 2014 at 10:36 AM, Mathias Bynens mathi...@opera.com wrote: On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: This looks like a potential problem when possible passed methods are not bound + it looks inconsistent with *use strict*

Re: use strict VS setTimeout

2014-09-07 Thread Michał Wadas
` var temp = window; document.querySelector('iframe').contentWindow.setTimeout(function() { console.log(temp === window); // false }) ` setTimeout is a method of global object, not a standalone function. 2014-09-07 19:47 GMT+02:00 Mark S. Miller erig...@google.com: On Sun, Sep 7, 2014 at 10:36

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
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

Re: use strict VS setTimeout

2014-09-07 Thread Axel Rauschmayer
On Sep 7, 2014, at 19:47 , Mark S. Miller erig...@google.com wrote: On Sun, Sep 7, 2014 at 10:36 AM, Mathias Bynens mathi...@opera.com wrote: On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: This looks like a potential problem when possible passed methods

Re: use strict VS setTimeout

2014-09-07 Thread Mark Miller
On Sun, Sep 7, 2014 at 10:29 AM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: I know this is probably W3C land but the following code shows the global object in every JS engine I could test: ```js (function () { 'use strict'; setTimeout(function () { 'use strict';

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
Yes Axel, that's how it works, this will show undefined indeed all over ```js (function () { 'use strict'; function g() { console.log(this); } g(); // undefined setTimeout(function () { g(); // undefined }, 0); }()); ``` or testing other use strict restrictions: ```js

Re: use strict VS setTimeout

2014-09-07 Thread Mark Miller
On Sun, Sep 7, 2014 at 11:07 AM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: Yes Axel, that's how it works, this will show undefined indeed all over ```js (function () { 'use strict'; function g() { console.log(this); } g(); // undefined setTimeout(function () {

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
It feels to me also a vector that will happily pass all linters and code analyzers giving users a door to reach native context and start playing in there with everything else. I'm pretty sure you would agree on this too :) Please let us know if there's any follow up, it's probably easier/faster

RE: use strict VS setTimeout

2014-09-07 Thread Domenic Denicola
I don't understand why this is any more surprising than any other function that calls its callback with .call(something). It doesn't matter whether the callback is strict or not; .call(window), which is what the spec does, will override it. As far as I can see this issue has absolutely nothing

Re: use strict VS setTimeout

2014-09-07 Thread Alex Kocharin
 I would add that in node.js it returns neither undefined nor window, but a timer object, which you can clear up with `clearInterval(this)` inside the callback.  07.09.2014, 21:30, "Andrea Giammarchi" andrea.giammar...@gmail.com:I know this is probably W3C land but the following code shows the

Re: use strict VS setTimeout

2014-09-07 Thread Garrett Smith
On 9/7/14, Domenic Denicola dome...@domenicdenicola.com wrote: I don't understand why this is any more surprising than any other function that calls its callback with .call(something). It doesn't matter whether the callback is strict or not; .call(window), which is what the spec does, will

Re: use strict VS setTimeout

2014-09-07 Thread Mark Miller
On Sun, Sep 7, 2014 at 11:27 AM, Domenic Denicola dome...@domenicdenicola.com wrote: I don't understand why this is any more surprising than any other function that calls its callback with .call(something). The issue is what the something should be, and which choices for something are

Re: use strict VS setTimeout

2014-09-07 Thread Mark Miller
On Sun, Sep 7, 2014 at 11:44 AM, Garrett Smith dhtmlkitc...@gmail.com wrote: On 9/7/14, Domenic Denicola dome...@domenicdenicola.com wrote: I don't understand why this is any more surprising than any other function that calls its callback with .call(something). It doesn't matter whether

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
You wrote itself the surprise, nobody wrote `.call(window)` or `.bind(window)` so you receive implicitly a global context in a place you were not expecting it. Think about object methods instead of that one shot but also think that under use strict `.call(null)` whould not bring the global

Re: use strict VS setTimeout

2014-09-07 Thread Domenic Denicola
On Sep 7, 2014, at 19:54, Andrea Giammarchi andrea.giammar...@gmail.commailto:andrea.giammar...@gmail.com wrote: But here I go back to the utopia I've already mentioned on putting everyone together to fix this, and I'm fine if it won't change but it's good to know that use strict could

Re: use strict VS setTimeout

2014-09-07 Thread Garrett Smith
On 9/7/14, Mark Miller erig...@gmail.com wrote: On Sun, Sep 7, 2014 at 11:27 AM, Domenic Denicola dome...@domenicdenicola.com wrote: I don't understand why this is any more surprising than any other function that calls its callback with .call(something). The issue is what the something

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
**implicitly fail** from a user point of view that used use strict to avoid receiving the global context in there ... I am not sure how much you want to turn it back to me but you are missing the point and I've not much else to say. Regards On Sun, Sep 7, 2014 at 7:58 PM, Domenic Denicola

Re: use strict VS setTimeout

2014-09-07 Thread Anne van Kesteren
On Sun, Sep 7, 2014 at 7:29 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: I know this is probably W3C land ... First hit for callback use strict inurl:lists.w3.org: http://lists.w3.org/Archives/Public/public-script-coord/2011JulSep/thread.html#msg3 -- http://annevankesteren.nl/

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
Yes Anne, reason I've posted here was to ask opinions from JS land + I am not sure it's that easy to post in W3C mailing list as random chap while here I'm already registered (and here I was looking for opinions beside what specs say) Good to see MM was already on fire in there :D On Sun, Sep 7,

Re: use strict VS setTimeout

2014-09-07 Thread Anne van Kesteren
On Sun, Sep 7, 2014 at 9:06 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: Yes Anne, reason I've posted here was to ask opinions from JS land + I am not sure it's that easy to post in W3C mailing list as random chap while here I'm already registered (and here I was looking for

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
I might try again but they'll probably tell me specs say so, must be good as others here so not sure I should bother. Thanks though. Regards On Sun, Sep 7, 2014 at 8:11 PM, Anne van Kesteren ann...@annevk.nl wrote: On Sun, Sep 7, 2014 at 9:06 PM, Andrea Giammarchi andrea.giammar...@gmail.com

Re: use strict VS setTimeout

2014-09-07 Thread Garrett Smith
On 9/7/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote: **implicitly fail** from a user point of view that used use strict to avoid receiving the global context in there ... I am not sure how much you want to turn it back to me but you are missing the point and I've not much else to

Re: use strict VS setTimeout

2014-09-07 Thread Andrea Giammarchi
this is getting nowhere ... yeah Garret, you can use `.call` and we all know that ... Now I want you to answer this: why on earth would you expect a global context in a setTimeout or setInterval operation for a function/method you have explicitly defined as strict ? One single use case ... do

Re: use strict VS setTimeout

2014-09-07 Thread Garrett Smith
On 9/7/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote: this is getting nowhere ... yeah Garret, you can use `.call` and we all know that ... Now I want you to answer this: why on earth would you expect a global context in a setTimeout or setInterval operation for a function/method

Re: use strict VS setTimeout

2014-09-07 Thread Mark Miller
On Sun, Sep 7, 2014 at 12:50 PM, Garrett Smith dhtmlkitc...@gmail.com wrote: On 9/7/14, Andrea Giammarchi andrea.giammar...@gmail.com wrote: this is getting nowhere ... yeah Garret, you can use `.call` and we all know that ... Now I want you to answer this: why on earth would you expect

Re: use strict VS setTimeout

2014-09-07 Thread Boris Zbarsky
On 9/7/14, 1:29 PM, Andrea Giammarchi wrote: I know this is probably W3C land but the following code shows the global object Careful with your use of the word the. Your ES5-centric assumptions are showing. ;) The function passed to setTimeout will be invoked with this set to the window

Re: use strict VS setTimeout

2014-09-07 Thread Mark S. Miller
On Sun, Sep 7, 2014 at 6:35 PM, Boris Zbarsky bzbar...@mit.edu wrote: On 9/7/14, 1:29 PM, Andrea Giammarchi wrote: I know this is probably W3C land but the following code shows the global object Careful with your use of the word the. Your ES5-centric assumptions are showing. ;) The

Re: use strict VS setTimeout

2014-09-07 Thread Boris Zbarsky
On 9/7/14, 9:35 PM, Boris Zbarsky wrote: Now, and here's where I have a problem with your use of the: the Window that setTimeout is invoked on is NOT necessarily the same as the global object of the function. Just to make this concrete, see http://fiddle.jshell.net/tmt5e9m6/2/show/ which has