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/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 } | 1025 } |
1026 | 1026 |
1027 void Scope::DeclareVariableName(const AstRawString* name, VariableMode mode) { | 1027 void Scope::DeclareVariableName(const AstRawString* name, VariableMode mode) { |
1028 DCHECK(IsDeclaredVariableMode(mode)); | 1028 DCHECK(IsDeclaredVariableMode(mode)); |
1029 DCHECK(!already_resolved_); | 1029 DCHECK(!already_resolved_); |
1030 DCHECK(GetDeclarationScope()->is_being_lazily_parsed()); | 1030 DCHECK(GetDeclarationScope()->is_being_lazily_parsed()); |
1031 | 1031 |
1032 if (mode == VAR && !is_declaration_scope()) { | 1032 if (mode == VAR && !is_declaration_scope()) { |
1033 return GetDeclarationScope()->DeclareVariableName(name, mode); | 1033 return GetDeclarationScope()->DeclareVariableName(name, mode); |
1034 } | 1034 } |
1035 DCHECK(!is_catch_scope()); | |
1036 DCHECK(!is_with_scope()); | 1035 DCHECK(!is_with_scope()); |
1037 DCHECK(!is_eval_scope()); | 1036 DCHECK(!is_eval_scope()); |
1038 DCHECK(is_declaration_scope() || | 1037 // Unlike DeclareVariable, DeclareVariableName allows declaring variables in |
1039 (IsLexicalVariableMode(mode) && is_block_scope())); | 1038 // catch scopes: Parser::RewriteCatchPattern bypasses DeclareVariable by |
| 1039 // calling DeclareLocal directly, and it doesn't make sense to add a similar |
| 1040 // bypass mechanism for PreParser. |
| 1041 DCHECK(is_declaration_scope() || (IsLexicalVariableMode(mode) && |
| 1042 (is_block_scope() || is_catch_scope()))); |
1040 DCHECK(scope_info_.is_null()); | 1043 DCHECK(scope_info_.is_null()); |
1041 | 1044 |
1042 // Declare the variable in the declaration scope. | 1045 // Declare the variable in the declaration scope. |
1043 variables_.DeclareName(zone(), name); | 1046 variables_.DeclareName(zone(), name); |
1044 } | 1047 } |
1045 | 1048 |
1046 VariableProxy* Scope::NewUnresolved(AstNodeFactory* factory, | 1049 VariableProxy* Scope::NewUnresolved(AstNodeFactory* factory, |
1047 const AstRawString* name, | 1050 const AstRawString* name, |
1048 int start_position, VariableKind kind) { | 1051 int start_position, VariableKind kind) { |
1049 // Note that we must not share the unresolved variables with | 1052 // Note that we must not share the unresolved variables with |
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2126 Variable* function = | 2129 Variable* function = |
2127 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 2130 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
2128 bool is_function_var_in_context = | 2131 bool is_function_var_in_context = |
2129 function != nullptr && function->IsContextSlot(); | 2132 function != nullptr && function->IsContextSlot(); |
2130 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 2133 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
2131 (is_function_var_in_context ? 1 : 0); | 2134 (is_function_var_in_context ? 1 : 0); |
2132 } | 2135 } |
2133 | 2136 |
2134 } // namespace internal | 2137 } // namespace internal |
2135 } // namespace v8 | 2138 } // namespace v8 |
OLD | NEW |