ReferenceError during a const assignment leaves the variable in a half-declared state
Reported by
m.go...@gmail.com,
Mar 18 2016
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 Steps to reproduce the problem: const a = b; // Uncaught ReferenceError: b is not defined a; // Uncaught ReferenceError: a is not defined const a = 2; // Uncaught TypeError: Identifier 'a' has already been declared a = 3; // Uncaught TypeError: Identifier 'a' has already been declared What is the expected behavior? A const-declared variable should either be declared & have a value or not declared at all What went wrong? The variable is declared & can't be re-created in the current scope but it's not defined. Did this work before? N/A Chrome version: 51.0.2682.0 Channel: canary OS Version: OS X 10.11.3 Flash Version: Shockwave Flash 21.0 r0 In Chrome <50 block scoping in DevTools is broken (each instruction is wrapped in a block so declarations are invisible in subsequent code) so this can't be observed there.
,
Mar 21 2016
,
Mar 21 2016
,
Mar 21 2016
I'm pretty sure this is the correct behavior per spec (uninitialized lexical declarations throw ReferenceErrors when accessed), but assigning to littledan for confirmation.
,
Mar 21 2016
Yes, I agree that this is correct behavior per spec. You can also achieve it via classes!
class A extends B { } // where B doesn't exist
// now A is in limbo too
,
Mar 21 2016
Note that this has previously been called out as a concern for counter-intuitive behavior in the spec, both inside and outside of the committee. If enough developers complain about this issue, it could be changed in a future revision. But any change would start on the spec side, not in V8.
,
Mar 22 2016
Thanks for the explanation! I agree it seems counter-intuitive but the spec is the spec so as long as it doesn't change there v8 is fine.
,
May 13 2016
Issue 610817 has been merged into this issue. |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by caseq@chromium.org
, Mar 18 2016Components: -Platform>DevTools Blink>JavaScript