Throwing errors on mutating immutable bindings

2014-09-30 Thread Shu-yu Guo
Hi all,

In the current draft, I see 2 different places where assigning to an immutable 
binding ('const') throws an error:

1) Dynamically throwing a TypeError in SetMutableBinding, 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-declarative-environment-records-setmutablebinding-n-v-s
2) Statically throwing a Syntax Error in assignment expressions, 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-assignment-operators-static-semantics-early-errors

1) throws only in strict mode code, while 2) throws regardless. 2) is also best 
effort; seems to be implementation-dependent what can statically determine 
entails.

Is the intention that assigning to consts silently nops if the implementation 
cannot determine the assignment to be to a const statically, in non-strict 
code, but implementations *should* make a best effort to report such cases 
eagerly, regardless of strictness? Seems kind of odd to me; perhaps I am 
misreading?

-- 
shu

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


Body-level inner function declarations interaction with the let temporal dead zone

2014-07-18 Thread Shu-yu Guo
Hi all,

Am I correct in understanding that body-level inner functions hoist both 
declaration *and* initialization to the top of the outer function?

That is, given the following snippet:

Listing 1
-
function outer() {
  let x;
  function inner() {
x = 2;
  }
}

Is it equivalent to the following?

Listing 2
-
function outer() {
  var inner = function inner() {
x = 2;
  };
  let x;
}

If so, that means in inner functions, all free uses of let-declared variables 
from outer lexical scopes are in the ES6 temporal dead zone. More 
problematically, it means that there is no-easy-to-compute dominance relation 
(i.e., at parse time) to omit the dead zone checks for any upvar uses of let 
bindings, even though textually, listing 1 looks like the initialization 
dominates all uses.

-- 
shu

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