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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 cached_parse_data_ = NULL; | 193 cached_parse_data_ = NULL; |
194 } else { | 194 } else { |
195 DCHECK(info->cached_data() != NULL); | 195 DCHECK(info->cached_data() != NULL); |
196 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { | 196 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { |
197 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); | 197 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, | 202 FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name, |
203 bool call_super, Scope* scope, | 203 bool call_super, int pos, |
204 int pos, int end_pos, | 204 int end_pos, |
205 LanguageMode language_mode) { | 205 LanguageMode language_mode) { |
206 int materialized_literal_count = -1; | 206 int materialized_literal_count = -1; |
207 int expected_property_count = -1; | 207 int expected_property_count = -1; |
208 int parameter_count = 0; | 208 int parameter_count = 0; |
209 if (name == nullptr) name = ast_value_factory()->empty_string(); | 209 if (name == nullptr) name = ast_value_factory()->empty_string(); |
210 | 210 |
211 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor | 211 FunctionKind kind = call_super ? FunctionKind::kDefaultSubclassConstructor |
212 : FunctionKind::kDefaultBaseConstructor; | 212 : FunctionKind::kDefaultBaseConstructor; |
213 Scope* function_scope = NewFunctionScope(scope, kind); | 213 Scope* function_scope = NewFunctionScope(kind); |
214 SetLanguageMode(function_scope, | 214 SetLanguageMode(function_scope, |
215 static_cast<LanguageMode>(language_mode | STRICT)); | 215 static_cast<LanguageMode>(language_mode | STRICT)); |
216 // Set start and end position to the same value | 216 // Set start and end position to the same value |
217 function_scope->set_start_position(pos); | 217 function_scope->set_start_position(pos); |
218 function_scope->set_end_position(pos); | 218 function_scope->set_end_position(pos); |
219 ZoneList<Statement*>* body = NULL; | 219 ZoneList<Statement*>* body = NULL; |
220 | 220 |
221 { | 221 { |
222 AstNodeFactory function_factory(ast_value_factory()); | 222 AstNodeFactory function_factory(ast_value_factory()); |
223 FunctionState function_state(&function_state_, &scope_state_, | 223 FunctionState function_state(&function_state_, &scope_state_, |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 CHECK(stack_overflow()); | 1131 CHECK(stack_overflow()); |
1132 return nullptr; | 1132 return nullptr; |
1133 } | 1133 } |
1134 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { | 1134 if (!(peek_any_identifier() || peek() == Token::LPAREN)) { |
1135 CHECK(stack_overflow()); | 1135 CHECK(stack_overflow()); |
1136 return nullptr; | 1136 return nullptr; |
1137 } | 1137 } |
1138 } | 1138 } |
1139 | 1139 |
1140 // TODO(adamk): We should construct this scope from the ScopeInfo. | 1140 // TODO(adamk): We should construct this scope from the ScopeInfo. |
1141 Scope* scope = | 1141 Scope* scope = NewFunctionScope(FunctionKind::kArrowFunction); |
1142 NewFunctionScope(this->scope(), FunctionKind::kArrowFunction); | |
1143 | 1142 |
1144 // These two bits only need to be explicitly set because we're | 1143 // These two bits only need to be explicitly set because we're |
1145 // not passing the ScopeInfo to the Scope constructor. | 1144 // not passing the ScopeInfo to the Scope constructor. |
1146 // TODO(adamk): Remove these calls once the above NewScope call | 1145 // TODO(adamk): Remove these calls once the above NewScope call |
1147 // passes the ScopeInfo. | 1146 // passes the ScopeInfo. |
1148 if (shared_info->scope_info()->CallsEval()) { | 1147 if (shared_info->scope_info()->CallsEval()) { |
1149 scope->RecordEvalCall(); | 1148 scope->RecordEvalCall(); |
1150 } | 1149 } |
1151 SetLanguageMode(scope, shared_info->language_mode()); | 1150 SetLanguageMode(scope, shared_info->language_mode()); |
1152 | 1151 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 // The pre-parser saw an arrow function here, so the full parser | 1189 // The pre-parser saw an arrow function here, so the full parser |
1191 // must produce a FunctionLiteral. | 1190 // must produce a FunctionLiteral. |
1192 DCHECK(expression->IsFunctionLiteral()); | 1191 DCHECK(expression->IsFunctionLiteral()); |
1193 result = expression->AsFunctionLiteral(); | 1192 result = expression->AsFunctionLiteral(); |
1194 } else { | 1193 } else { |
1195 ok = false; | 1194 ok = false; |
1196 } | 1195 } |
1197 } | 1196 } |
1198 } | 1197 } |
1199 } else if (shared_info->is_default_constructor()) { | 1198 } else if (shared_info->is_default_constructor()) { |
| 1199 DCHECK_EQ(this->scope(), scope); |
1200 result = DefaultConstructor( | 1200 result = DefaultConstructor( |
1201 raw_name, IsSubclassConstructor(shared_info->kind()), scope, | 1201 raw_name, IsSubclassConstructor(shared_info->kind()), |
1202 shared_info->start_position(), shared_info->end_position(), | 1202 shared_info->start_position(), shared_info->end_position(), |
1203 shared_info->language_mode()); | 1203 shared_info->language_mode()); |
1204 } else { | 1204 } else { |
1205 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), | 1205 result = ParseFunctionLiteral(raw_name, Scanner::Location::invalid(), |
1206 kSkipFunctionNameCheck, shared_info->kind(), | 1206 kSkipFunctionNameCheck, shared_info->kind(), |
1207 kNoSourcePosition, function_type, | 1207 kNoSourcePosition, function_type, |
1208 shared_info->language_mode(), &ok); | 1208 shared_info->language_mode(), &ok); |
1209 } | 1209 } |
1210 // Make sure the results agree. | 1210 // Make sure the results agree. |
1211 DCHECK(ok == (result != nullptr)); | 1211 DCHECK(ok == (result != nullptr)); |
(...skipping 3075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4287 // Anonymous functions were passed either the empty symbol or a null | 4287 // Anonymous functions were passed either the empty symbol or a null |
4288 // handle as the function name. Remember if we were passed a non-empty | 4288 // handle as the function name. Remember if we were passed a non-empty |
4289 // handle to decide whether to invoke function name inference. | 4289 // handle to decide whether to invoke function name inference. |
4290 bool should_infer_name = function_name == NULL; | 4290 bool should_infer_name = function_name == NULL; |
4291 | 4291 |
4292 // We want a non-null handle as the function name. | 4292 // We want a non-null handle as the function name. |
4293 if (should_infer_name) { | 4293 if (should_infer_name) { |
4294 function_name = ast_value_factory()->empty_string(); | 4294 function_name = ast_value_factory()->empty_string(); |
4295 } | 4295 } |
4296 | 4296 |
4297 Scope* scope = NewFunctionScope(this->scope(), kind); | 4297 Scope* scope = NewFunctionScope(kind); |
4298 SetLanguageMode(scope, language_mode); | 4298 SetLanguageMode(scope, language_mode); |
4299 ZoneList<Statement*>* body = NULL; | 4299 ZoneList<Statement*>* body = NULL; |
4300 int arity = -1; | 4300 int arity = -1; |
4301 int materialized_literal_count = -1; | 4301 int materialized_literal_count = -1; |
4302 int expected_property_count = -1; | 4302 int expected_property_count = -1; |
4303 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 4303 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
4304 bool should_be_used_once_hint = false; | 4304 bool should_be_used_once_hint = false; |
4305 bool has_duplicate_parameters; | 4305 bool has_duplicate_parameters; |
4306 FunctionLiteral::EagerCompileHint eager_compile_hint; | 4306 FunctionLiteral::EagerCompileHint eager_compile_hint; |
4307 | 4307 |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5084 | 5084 |
5085 if (property_name != ast_value_factory()->constructor_string()) { | 5085 if (property_name != ast_value_factory()->constructor_string()) { |
5086 SetFunctionNameFromPropertyName(property, property_name); | 5086 SetFunctionNameFromPropertyName(property, property_name); |
5087 } | 5087 } |
5088 } | 5088 } |
5089 | 5089 |
5090 Expect(Token::RBRACE, CHECK_OK); | 5090 Expect(Token::RBRACE, CHECK_OK); |
5091 int end_pos = scanner()->location().end_pos; | 5091 int end_pos = scanner()->location().end_pos; |
5092 | 5092 |
5093 if (constructor == NULL) { | 5093 if (constructor == NULL) { |
5094 constructor = DefaultConstructor(name, has_extends, block_scope, pos, | 5094 DCHECK_EQ(this->scope(), block_scope); |
5095 end_pos, block_scope->language_mode()); | 5095 constructor = DefaultConstructor(name, has_extends, pos, end_pos, |
| 5096 block_scope->language_mode()); |
5096 } | 5097 } |
5097 | 5098 |
5098 // Note that we do not finalize this block scope because it is | 5099 // Note that we do not finalize this block scope because it is |
5099 // used as a sentinel value indicating an anonymous class. | 5100 // used as a sentinel value indicating an anonymous class. |
5100 block_scope->set_end_position(end_pos); | 5101 block_scope->set_end_position(end_pos); |
5101 | 5102 |
5102 if (name != NULL) { | 5103 if (name != NULL) { |
5103 DCHECK_NOT_NULL(proxy); | 5104 DCHECK_NOT_NULL(proxy); |
5104 proxy->var()->set_initializer_position(end_pos); | 5105 proxy->var()->set_initializer_position(end_pos); |
5105 } | 5106 } |
(...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7074 node->Print(Isolate::Current()); | 7075 node->Print(Isolate::Current()); |
7075 } | 7076 } |
7076 #endif // DEBUG | 7077 #endif // DEBUG |
7077 | 7078 |
7078 #undef CHECK_OK | 7079 #undef CHECK_OK |
7079 #undef CHECK_OK_VOID | 7080 #undef CHECK_OK_VOID |
7080 #undef CHECK_FAILED | 7081 #undef CHECK_FAILED |
7081 | 7082 |
7082 } // namespace internal | 7083 } // namespace internal |
7083 } // namespace v8 | 7084 } // namespace v8 |
OLD | NEW |