Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
| 10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
| (...skipping 1964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1975 // bound during variable resolution time unless it was pre-bound | 1975 // bound during variable resolution time unless it was pre-bound |
| 1976 // below. | 1976 // below. |
| 1977 // | 1977 // |
| 1978 // WARNING: This will lead to multiple declaration nodes for the | 1978 // WARNING: This will lead to multiple declaration nodes for the |
| 1979 // same variable if it is declared several times. This is not a | 1979 // same variable if it is declared several times. This is not a |
| 1980 // semantic issue as long as we keep the source order, but it may be | 1980 // semantic issue as long as we keep the source order, but it may be |
| 1981 // a performance issue since it may lead to repeated | 1981 // a performance issue since it may lead to repeated |
| 1982 // RuntimeHidden_DeclareLookupSlot calls. | 1982 // RuntimeHidden_DeclareLookupSlot calls. |
| 1983 declaration_scope->AddDeclaration(declaration); | 1983 declaration_scope->AddDeclaration(declaration); |
| 1984 | 1984 |
| 1985 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { | |
| 1986 // For global const variables we bind the proxy to a variable. | |
| 1987 DCHECK(resolve); // should be set by all callers | |
| 1988 Variable::Kind kind = Variable::NORMAL; | |
| 1989 var = new (zone()) Variable(declaration_scope, name, mode, kind, | |
| 1990 kNeedsInitialization, kNotAssigned); | |
| 1991 } | |
| 1992 | |
| 1993 // If requested and we have a local variable, bind the proxy to the variable | 1985 // If requested and we have a local variable, bind the proxy to the variable |
| 1994 // at parse-time. This is used for functions (and consts) declared inside | 1986 // at parse-time. This is used for functions (and consts) declared inside |
| 1995 // statements: the corresponding function (or const) variable must be in the | 1987 // statements: the corresponding function (or const) variable must be in the |
| 1996 // function scope and not a statement-local scope, e.g. as provided with a | 1988 // function scope and not a statement-local scope, e.g. as provided with a |
| 1997 // 'with' statement: | 1989 // 'with' statement: |
| 1998 // | 1990 // |
| 1999 // with (obj) { | 1991 // with (obj) { |
| 2000 // function f() {} | 1992 // function f() {} |
| 2001 // } | 1993 // } |
| 2002 // | 1994 // |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2359 if (parsing_result->descriptor.mode == CONST || | 2351 if (parsing_result->descriptor.mode == CONST || |
| 2360 !pattern->IsVariableProxy()) { | 2352 !pattern->IsVariableProxy()) { |
| 2361 ParserTraits::ReportMessageAt( | 2353 ParserTraits::ReportMessageAt( |
| 2362 Scanner::Location(decl_pos, scanner()->location().end_pos), | 2354 Scanner::Location(decl_pos, scanner()->location().end_pos), |
| 2363 MessageTemplate::kDeclarationMissingInitializer, | 2355 MessageTemplate::kDeclarationMissingInitializer, |
| 2364 !pattern->IsVariableProxy() ? "destructuring" : "const"); | 2356 !pattern->IsVariableProxy() ? "destructuring" : "const"); |
| 2365 *ok = false; | 2357 *ok = false; |
| 2366 return nullptr; | 2358 return nullptr; |
| 2367 } | 2359 } |
| 2368 | 2360 |
| 2369 // 'let x' and (legacy) 'const x' initialize 'x' to undefined. | 2361 // 'let x' initializes 'x' to undefined. |
| 2370 if (parsing_result->descriptor.mode == LET || | 2362 if (parsing_result->descriptor.mode == LET) { |
|
caitp (gmail)
2016/04/14 00:17:30
This is not really the job of this CL, but this lo
caitp (gmail)
2016/04/14 00:25:16
eh, other vendors seem to behave the same, did the
adamk
2016/04/14 00:37:24
Nope, nothing recent here. Let variables are hole-
| |
| 2371 parsing_result->descriptor.mode == CONST_LEGACY) { | |
| 2372 value = GetLiteralUndefined(position()); | 2363 value = GetLiteralUndefined(position()); |
| 2373 } | 2364 } |
| 2374 } | 2365 } |
| 2375 | 2366 |
| 2376 // End position of the initializer is after the variable. | 2367 // End position of the initializer is after the variable. |
| 2377 initializer_position = position(); | 2368 initializer_position = position(); |
| 2378 } | 2369 } |
| 2379 | 2370 |
| 2380 DeclarationParsingResult::Declaration decl(pattern, initializer_position, | 2371 DeclarationParsingResult::Declaration decl(pattern, initializer_position, |
| 2381 value); | 2372 value); |
| (...skipping 4477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6859 try_block, target); | 6850 try_block, target); |
| 6860 final_loop = target; | 6851 final_loop = target; |
| 6861 } | 6852 } |
| 6862 | 6853 |
| 6863 return final_loop; | 6854 return final_loop; |
| 6864 } | 6855 } |
| 6865 | 6856 |
| 6866 | 6857 |
| 6867 } // namespace internal | 6858 } // namespace internal |
| 6868 } // namespace v8 | 6859 } // namespace v8 |
| OLD | NEW |