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 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 // bound during variable resolution time unless it was pre-bound | 1965 // bound during variable resolution time unless it was pre-bound |
1966 // below. | 1966 // below. |
1967 // | 1967 // |
1968 // WARNING: This will lead to multiple declaration nodes for the | 1968 // WARNING: This will lead to multiple declaration nodes for the |
1969 // same variable if it is declared several times. This is not a | 1969 // same variable if it is declared several times. This is not a |
1970 // semantic issue as long as we keep the source order, but it may be | 1970 // semantic issue as long as we keep the source order, but it may be |
1971 // a performance issue since it may lead to repeated | 1971 // a performance issue since it may lead to repeated |
1972 // RuntimeHidden_DeclareLookupSlot calls. | 1972 // RuntimeHidden_DeclareLookupSlot calls. |
1973 declaration_scope->AddDeclaration(declaration); | 1973 declaration_scope->AddDeclaration(declaration); |
1974 | 1974 |
1975 if (mode == CONST_LEGACY && declaration_scope->is_script_scope()) { | |
1976 // For global const variables we bind the proxy to a variable. | |
1977 DCHECK(resolve); // should be set by all callers | |
1978 Variable::Kind kind = Variable::NORMAL; | |
1979 var = new (zone()) Variable(declaration_scope, name, mode, kind, | |
1980 kNeedsInitialization, kNotAssigned); | |
1981 } | |
1982 | |
1983 // If requested and we have a local variable, bind the proxy to the variable | 1975 // If requested and we have a local variable, bind the proxy to the variable |
1984 // at parse-time. This is used for functions (and consts) declared inside | 1976 // at parse-time. This is used for functions (and consts) declared inside |
1985 // statements: the corresponding function (or const) variable must be in the | 1977 // statements: the corresponding function (or const) variable must be in the |
1986 // function scope and not a statement-local scope, e.g. as provided with a | 1978 // function scope and not a statement-local scope, e.g. as provided with a |
1987 // 'with' statement: | 1979 // 'with' statement: |
1988 // | 1980 // |
1989 // with (obj) { | 1981 // with (obj) { |
1990 // function f() {} | 1982 // function f() {} |
1991 // } | 1983 // } |
1992 // | 1984 // |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2337 if (parsing_result->descriptor.mode == CONST || | 2329 if (parsing_result->descriptor.mode == CONST || |
2338 !pattern->IsVariableProxy()) { | 2330 !pattern->IsVariableProxy()) { |
2339 ParserTraits::ReportMessageAt( | 2331 ParserTraits::ReportMessageAt( |
2340 Scanner::Location(decl_pos, scanner()->location().end_pos), | 2332 Scanner::Location(decl_pos, scanner()->location().end_pos), |
2341 MessageTemplate::kDeclarationMissingInitializer, | 2333 MessageTemplate::kDeclarationMissingInitializer, |
2342 !pattern->IsVariableProxy() ? "destructuring" : "const"); | 2334 !pattern->IsVariableProxy() ? "destructuring" : "const"); |
2343 *ok = false; | 2335 *ok = false; |
2344 return nullptr; | 2336 return nullptr; |
2345 } | 2337 } |
2346 | 2338 |
2347 // 'let x' and (legacy) 'const x' initialize 'x' to undefined. | 2339 // 'let x' initializes 'x' to undefined. |
2348 if (parsing_result->descriptor.mode == LET || | 2340 if (parsing_result->descriptor.mode == LET) { |
2349 parsing_result->descriptor.mode == CONST_LEGACY) { | |
2350 value = GetLiteralUndefined(position()); | 2341 value = GetLiteralUndefined(position()); |
2351 } | 2342 } |
2352 } | 2343 } |
2353 | 2344 |
2354 // End position of the initializer is after the variable. | 2345 // End position of the initializer is after the variable. |
2355 initializer_position = position(); | 2346 initializer_position = position(); |
2356 } | 2347 } |
2357 | 2348 |
2358 DeclarationParsingResult::Declaration decl(pattern, initializer_position, | 2349 DeclarationParsingResult::Declaration decl(pattern, initializer_position, |
2359 value); | 2350 value); |
(...skipping 4431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6791 try_block, target); | 6782 try_block, target); |
6792 final_loop = target; | 6783 final_loop = target; |
6793 } | 6784 } |
6794 | 6785 |
6795 return final_loop; | 6786 return final_loop; |
6796 } | 6787 } |
6797 | 6788 |
6798 | 6789 |
6799 } // namespace internal | 6790 } // namespace internal |
6800 } // namespace v8 | 6791 } // namespace v8 |
OLD | NEW |