Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread François REMY
I think that what he meant is that we know for sure in which scope we can find 
the property/variable. That the propery exists or not in the that scope is 
another issue.

So, in the code “function getOoops(t) { t(); return function() { return ooops; 
} }” we know statically that the scope where the “ooops” variable is defined is 
the global scope. At runtime, we just need to do “globalScope.get(‘oops’) to 
retreive the value (or throw). In non-strict ES, the “t” function may be eval, 
and eval could add a “oops” variable in the parent function getOoops. So, we 
don’t know at compilation if “ooops” belong the the global scope of from the 
function’s scope (we can only find that out at runtime).



From: Šime Vidas 
Sent: Wednesday, October 03, 2012 6:41 PM
To: es-discuss@mozilla.org 
Subject: Is ES5 Strict a fully statically scoped language?
In the talk Changes to JavaScript, Part 1: EcmaScript 5, Mark Miller states 
that ES5 Default contains four static scope violations (direct link: 
http://www.youtube.com/watch?v=Kq4FpMe6cRst=42m53s). He also states that ES5 
Strict corrects these violations, making ES5 Strict is a statically scoped 
language. I don't understand how that can be true, since it is possible to 
dynamically add bindings to the global environment by creating new global 
properties (during code evaluation). Isn't this a static scope violation, too?

-- Šime Vidas




___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Gavin Barraclough
On Oct 3, 2012, at 10:05 AM, François REMY wrote:

  In non-strict ES, the “t” function may be eval, and eval could add a “oops” 
 variable in the parent function getOoops.

I don't believe this is true.  This does not constitute a direct call to eval 
(15.1.2.1.1), and as such the eval will take place in a fresh execution 
context, rather than the calling function's context.

cheers,
G.

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread François REMY
Indirect eval is something introduced for ES5 Strict only, I believe. Try 
the following code in your browser’s console, and you may be surprised:


((function(t) { t(var body=true); return function() { return 
body; }; })(eval))()) 


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Gavin Barraclough
On Oct 3, 2012, at 12:40 PM, François REMY wrote:

 Indirect eval is something introduced for ES5 Strict only, I believe.

Nope.  See 15.1.2.1.1, no reference to strict.

Here's a better example:
(function(t){ var x = 'foo'; t(x = 'bar'); alert(x); })(eval)
The indirect eval does not modify the function's local variable.

cheers,
G.

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread François REMY

|  That just puts 'body' on the window.

Indee, I'm false on that one. But if you use a direct eval, you can get the 
same behavior in ES5, which is want I wanted to demonstrate:


   window.a = true;
   (function x(t) { eval(t); return a==window.a; })(var a=false)

So in plain ES5, the scope of an identifer is not always defined lexically. 


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Mark S. Miller
On Wed, Oct 3, 2012 at 10:05 AM, François REMY fremycompany_...@yahoo.frwrote:

   I think that what he meant is that we know for sure in which scope we
 can find the property/variable. That the propery exists or not in the that
 scope is another issue.

 So, in the code “function getOoops(t) { t(); return function() { return
 ooops; } }” we know statically that the scope where the “ooops” variable is
 defined is the global scope. At runtime, we just need to do
 “globalScope.get(‘oops’) to retreive the value (or throw).


Exactly.




 In non-strict ES, the “t” function may be eval, and eval could add a
 “oops” variable in the parent function getOoops. So, we don’t know at
 compilation if “ooops” belong the the global scope of from the function’s
 scope (we can only find that out at runtime).


As clarified in the rest of the thread. If t's value is the original eval
function, this will still be an indirect call. But in non-strict

function getOoops(str) { eval(str); return function() { return ooops; }
}

we no longer no which ooops this code refers to.




   *From:* Šime Vidas sime.vi...@gmail.com
 *Sent:* Wednesday, October 03, 2012 6:41 PM
 *To:* es-discuss@mozilla.org
 *Subject:* Is ES5 Strict a fully statically scoped language?
  In the talk Changes to JavaScript, Part 1: EcmaScript 5, Mark Miller
 states that ES5 Default contains four static scope violations (direct link:
 http://www.youtube.com/watch?v=Kq4FpMe6cRst=42m53s). He also states that
 ES5 Strict corrects these violations, making ES5 Strict is a statically
 scoped language. I don't understand how that can be true, since it is
 possible to dynamically add bindings to the global environment by creating
 new global properties (during code evaluation). Isn't this a static scope
 violation, too?

 -- Šime Vidas

 --
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Šime Vidas
On Wed, Oct 3, 2012 at 7:05 PM, François REMY fremycompany_...@yahoo.frwrote:

   I think that what he meant is that we know for sure in which scope we
 can find the property/variable. That the propery exists or not in the that
 scope is another issue.


So, it doesn't matter that the global environment is dynamic (as in
bindings can be added/removed dynamically), since it's the top-most
environment. Only the nested (function) environments must be static, and if
they are, i.e. if we know which bindings are defined in each function
environment (in the scope chain), then we can safely assume that a name
that doesn't exist in any of those function environments, can only either
be a global binding, or a name that doesn't exist in any environment. Did I
get this correctly?




So, in the code “function getOoops(t) { t(); return function() { return
 ooops; } }” we know statically that the scope where the “ooops” variable is
 defined is the global scope. At runtime, we just need to do
 “globalScope.get(‘oops’) to retreive the value (or throw). In non-strict
 ES, the “t” function may be eval, and eval could add a “oops” variable in
 the parent function getOoops. So, we don’t know at compilation if “ooops”
 belong the the global scope of from the function’s scope (we can only find
 that out at runtime).



   *From:* Šime Vidas sime.vi...@gmail.com
 *Sent:* Wednesday, October 03, 2012 6:41 PM
 *To:* es-discuss@mozilla.org
 *Subject:* Is ES5 Strict a fully statically scoped language?
  In the talk Changes to JavaScript, Part 1: EcmaScript 5, Mark Miller
 states that ES5 Default contains four static scope violations (direct link:
 http://www.youtube.com/watch?v=Kq4FpMe6cRst=42m53s). He also states that
 ES5 Strict corrects these violations, making ES5 Strict is a statically
 scoped language. I don't understand how that can be true, since it is
 possible to dynamically add bindings to the global environment by creating
 new global properties (during code evaluation). Isn't this a static scope
 violation, too?

 -- Šime Vidas

 --
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss


___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Mark S. Miller
On Wed, Oct 3, 2012 at 3:16 PM, Šime Vidas sime.vi...@gmail.com wrote:

 On Wed, Oct 3, 2012 at 7:05 PM, François REMY 
 fremycompany_...@yahoo.frwrote:

   I think that what he meant is that we know for sure in which scope we
 can find the property/variable. That the propery exists or not in the that
 scope is another issue.


 So, it doesn't matter that the global environment is dynamic (as in
 bindings can be added/removed dynamically), since it's the top-most
 environment. Only the nested (function) environments must be static, and if
 they are, i.e. if we know which bindings are defined in each function
 environment (in the scope chain), then we can safely assume that a name
 that doesn't exist in any of those function environments, can only either
 be a global binding, or a name that doesn't exist in any environment. Did I
 get this correctly?


Exactly correct. Thanks for the clarification!







 So, in the code “function getOoops(t) { t(); return function() { return
 ooops; } }” we know statically that the scope where the “ooops” variable is
 defined is the global scope. At runtime, we just need to do
 “globalScope.get(‘oops’) to retreive the value (or throw). In non-strict
 ES, the “t” function may be eval, and eval could add a “oops” variable in
 the parent function getOoops. So, we don’t know at compilation if “ooops”
 belong the the global scope of from the function’s scope (we can only find
 that out at runtime).



   *From:* Šime Vidas sime.vi...@gmail.com
 *Sent:* Wednesday, October 03, 2012 6:41 PM
 *To:* es-discuss@mozilla.org
 *Subject:* Is ES5 Strict a fully statically scoped language?
  In the talk Changes to JavaScript, Part 1: EcmaScript 5, Mark Miller
 states that ES5 Default contains four static scope violations (direct link:
 http://www.youtube.com/watch?v=Kq4FpMe6cRst=42m53s). He also states
 that ES5 Strict corrects these violations, making ES5 Strict is a
 statically scoped language. I don't understand how that can be true, since
 it is possible to dynamically add bindings to the global environment by
 creating new global properties (during code evaluation). Isn't this a
 static scope violation, too?

 -- Šime Vidas

 --
 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss



 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss




-- 
Cheers,
--MarkM
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Šime Vidas
On Thu, Oct 4, 2012 at 12:31 AM, Mark S. Miller erig...@google.com wrote:


 On Wed, Oct 3, 2012 at 3:16 PM, Šime Vidas sime.vi...@gmail.com wrote:

 On Wed, Oct 3, 2012 at 7:05 PM, François REMY 
 fremycompany_...@yahoo.frwrote:

   I think that what he meant is that we know for sure in which scope we
 can find the property/variable. That the propery exists or not in the that
 scope is another issue.


 So, it doesn't matter that the global environment is dynamic (as in
 bindings can be added/removed dynamically), since it's the top-most
 environment. Only the nested (function) environments must be static, and if
 they are, i.e. if we know which bindings are defined in each function
 environment (in the scope chain), then we can safely assume that a name
 that doesn't exist in any of those function environments, can only either
 be a global binding, or a name that doesn't exist in any environment. Did I
 get this correctly?


 Exactly correct. Thanks for the clarification!




Well, thank you for your excellent video. The dynamic scopes in the default
language are a disaster... I've just written a short code example (see
below) which demonstrates this. Thank goodness ES5 Strict is statically
scoped. :-)

// global code
this.foo = 1;

(function () {
eval('var foo = 2');

with ({ foo: 3 }) {
foo // = 3
delete foo;
foo // = 2
delete foo;
foo // = 1
delete foo;
foo // ReferenceError
}
}());
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Is ES5 Strict a fully statically scoped language?

2012-10-03 Thread Brendan Eich
You should eval an initialized var declaration of foo inside the with, 
and check foo's value after the with body, for real head-exploding. ;-)


/be

Šime Vidas wrote:
Well, thank you for your excellent video. The dynamic scopes in the 
default language are a disaster... I've just written a short code 
example (see below) which demonstrates this. Thank goodness ES5 Strict 
is statically scoped. :-)


// global code
this.foo = 1;

(function () {
eval('var foo = 2');

with ({ foo: 3 }) {
foo // = 3
delete foo;
foo // = 2
delete foo;
foo // = 1
delete foo;
foo // ReferenceError
}
}());

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss