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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/ast/ast-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1960 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); | 1960 factory()->NewBlock(nullptr, 1, true, kNoSourcePosition); |
1961 { | 1961 { |
1962 auto descriptor = for_info->parsing_result.descriptor; | 1962 auto descriptor = for_info->parsing_result.descriptor; |
1963 descriptor.declaration_pos = kNoSourcePosition; | 1963 descriptor.declaration_pos = kNoSourcePosition; |
1964 descriptor.initialization_pos = kNoSourcePosition; | 1964 descriptor.initialization_pos = kNoSourcePosition; |
1965 decl.initializer = factory()->NewVariableProxy(temp); | 1965 decl.initializer = factory()->NewVariableProxy(temp); |
1966 | 1966 |
1967 bool is_for_var_of = | 1967 bool is_for_var_of = |
1968 for_info->mode == ForEachStatement::ITERATE && | 1968 for_info->mode == ForEachStatement::ITERATE && |
1969 for_info->parsing_result.descriptor.mode == VariableMode::VAR; | 1969 for_info->parsing_result.descriptor.mode == VariableMode::VAR; |
| 1970 bool collect_names = |
| 1971 IsLexicalVariableMode(for_info->parsing_result.descriptor.mode) || |
| 1972 is_for_var_of; |
1970 | 1973 |
1971 PatternRewriter::DeclareAndInitializeVariables( | 1974 PatternRewriter::DeclareAndInitializeVariables( |
1972 this, each_initialization_block, &descriptor, &decl, | 1975 this, each_initialization_block, &descriptor, &decl, |
1973 (IsLexicalVariableMode(for_info->parsing_result.descriptor.mode) || | 1976 collect_names ? &for_info->bound_names : nullptr, CHECK_OK_VOID); |
1974 is_for_var_of) | |
1975 ? &for_info->bound_names | |
1976 : nullptr, | |
1977 CHECK_OK_VOID); | |
1978 | 1977 |
1979 // Annex B.3.5 prohibits the form | 1978 // Annex B.3.5 prohibits the form |
1980 // `try {} catch(e) { for (var e of {}); }` | 1979 // `try {} catch(e) { for (var e of {}); }` |
1981 // So if we are parsing a statement like `for (var ... of ...)` | 1980 // So if we are parsing a statement like `for (var ... of ...)` |
1982 // we need to walk up the scope chain and look for catch scopes | 1981 // we need to walk up the scope chain and look for catch scopes |
1983 // which have a simple binding, then compare their binding against | 1982 // which have a simple binding, then compare their binding against |
1984 // all of the names declared in the init of the for-of we're | 1983 // all of the names declared in the init of the for-of we're |
1985 // parsing. | 1984 // parsing. |
1986 if (is_for_var_of) { | 1985 if (is_for_var_of) { |
1987 Scope* catch_scope = scope(); | 1986 Scope* catch_scope = scope(); |
(...skipping 3040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5028 | 5027 |
5029 return final_loop; | 5028 return final_loop; |
5030 } | 5029 } |
5031 | 5030 |
5032 #undef CHECK_OK | 5031 #undef CHECK_OK |
5033 #undef CHECK_OK_VOID | 5032 #undef CHECK_OK_VOID |
5034 #undef CHECK_FAILED | 5033 #undef CHECK_FAILED |
5035 | 5034 |
5036 } // namespace internal | 5035 } // namespace internal |
5037 } // namespace v8 | 5036 } // namespace v8 |
OLD | NEW |