| 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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 : FunctionKind::kDefaultBaseConstructor; | 212 : FunctionKind::kDefaultBaseConstructor; |
| 213 Scope* function_scope = NewFunctionScope(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()); | |
| 223 FunctionState function_state(&function_state_, &scope_state_, | 222 FunctionState function_state(&function_state_, &scope_state_, |
| 224 function_scope, kind, &function_factory); | 223 function_scope, kind); |
| 225 | 224 |
| 226 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); | 225 body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone()); |
| 227 if (call_super) { | 226 if (call_super) { |
| 228 // $super_constructor = %_GetSuperConstructor(<this-function>) | 227 // $super_constructor = %_GetSuperConstructor(<this-function>) |
| 229 // %reflect_construct( | 228 // %reflect_construct( |
| 230 // $super_constructor, InternalArray(...args), new.target) | 229 // $super_constructor, InternalArray(...args), new.target) |
| 231 auto constructor_args_name = ast_value_factory()->empty_string(); | 230 auto constructor_args_name = ast_value_factory()->empty_string(); |
| 232 bool is_duplicate; | 231 bool is_duplicate; |
| 233 bool is_rest = true; | 232 bool is_rest = true; |
| 234 bool is_optional = false; | 233 bool is_optional = false; |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); | 843 set_allow_harmony_trailing_commas(FLAG_harmony_trailing_commas); |
| 845 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 844 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 846 ++feature) { | 845 ++feature) { |
| 847 use_counts_[feature] = 0; | 846 use_counts_[feature] = 0; |
| 848 } | 847 } |
| 849 if (info->ast_value_factory() == NULL) { | 848 if (info->ast_value_factory() == NULL) { |
| 850 // info takes ownership of AstValueFactory. | 849 // info takes ownership of AstValueFactory. |
| 851 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 850 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
| 852 info->set_ast_value_factory_owned(); | 851 info->set_ast_value_factory_owned(); |
| 853 ast_value_factory_ = info->ast_value_factory(); | 852 ast_value_factory_ = info->ast_value_factory(); |
| 853 ast_node_factory_.set_ast_value_factory(ast_value_factory_); |
| 854 } | 854 } |
| 855 } | 855 } |
| 856 | 856 |
| 857 | 857 |
| 858 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { | 858 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
| 859 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 859 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| 860 // see comment for HistogramTimerScope class. | 860 // see comment for HistogramTimerScope class. |
| 861 | 861 |
| 862 // It's OK to use the Isolate & counters here, since this function is only | 862 // It's OK to use the Isolate & counters here, since this function is only |
| 863 // called in the main thread. | 863 // called in the main thread. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 } | 959 } |
| 960 scope = NewScopeWithParent(scope, EVAL_SCOPE); | 960 scope = NewScopeWithParent(scope, EVAL_SCOPE); |
| 961 } else if (info->is_module()) { | 961 } else if (info->is_module()) { |
| 962 scope = NewScopeWithParent(scope, MODULE_SCOPE); | 962 scope = NewScopeWithParent(scope, MODULE_SCOPE); |
| 963 } | 963 } |
| 964 | 964 |
| 965 scope->set_start_position(0); | 965 scope->set_start_position(0); |
| 966 | 966 |
| 967 // Enter 'scope' with the given parsing mode. | 967 // Enter 'scope' with the given parsing mode. |
| 968 ParsingModeScope parsing_mode_scope(this, parsing_mode); | 968 ParsingModeScope parsing_mode_scope(this, parsing_mode); |
| 969 AstNodeFactory function_factory(ast_value_factory()); | |
| 970 FunctionState function_state(&function_state_, &scope_state_, scope, | 969 FunctionState function_state(&function_state_, &scope_state_, scope, |
| 971 kNormalFunction, &function_factory); | 970 kNormalFunction); |
| 972 | 971 |
| 973 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 972 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 974 bool ok = true; | 973 bool ok = true; |
| 975 int beg_pos = scanner()->location().beg_pos; | 974 int beg_pos = scanner()->location().beg_pos; |
| 976 parsing_module_ = info->is_module(); | 975 parsing_module_ = info->is_module(); |
| 977 if (parsing_module_) { | 976 if (parsing_module_) { |
| 978 ParseModuleItemList(body, &ok); | 977 ParseModuleItemList(body, &ok); |
| 979 ok = ok && | 978 ok = ok && |
| 980 module()->Validate(this->scope(), &pending_error_handler_, zone()); | 979 module()->Validate(this->scope(), &pending_error_handler_, zone()); |
| 981 } else { | 980 } else { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 Scope* scope = NewScriptScope(); | 1105 Scope* scope = NewScriptScope(); |
| 1107 info->set_script_scope(scope); | 1106 info->set_script_scope(scope); |
| 1108 if (!info->context().is_null()) { | 1107 if (!info->context().is_null()) { |
| 1109 // Ok to use Isolate here, since lazy function parsing is only done in the | 1108 // Ok to use Isolate here, since lazy function parsing is only done in the |
| 1110 // main thread. | 1109 // main thread. |
| 1111 DCHECK(parsing_on_main_thread_); | 1110 DCHECK(parsing_on_main_thread_); |
| 1112 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), | 1111 scope = Scope::DeserializeScopeChain(isolate, zone(), *info->context(), |
| 1113 scope, ast_value_factory()); | 1112 scope, ast_value_factory()); |
| 1114 } | 1113 } |
| 1115 original_scope_ = scope; | 1114 original_scope_ = scope; |
| 1116 AstNodeFactory function_factory(ast_value_factory()); | |
| 1117 FunctionState function_state(&function_state_, &scope_state_, scope, | 1115 FunctionState function_state(&function_state_, &scope_state_, scope, |
| 1118 shared_info->kind(), &function_factory); | 1116 shared_info->kind()); |
| 1119 DCHECK(is_sloppy(scope->language_mode()) || | 1117 DCHECK(is_sloppy(scope->language_mode()) || |
| 1120 is_strict(info->language_mode())); | 1118 is_strict(info->language_mode())); |
| 1121 DCHECK(info->language_mode() == shared_info->language_mode()); | 1119 DCHECK(info->language_mode() == shared_info->language_mode()); |
| 1122 FunctionLiteral::FunctionType function_type = | 1120 FunctionLiteral::FunctionType function_type = |
| 1123 ComputeFunctionType(shared_info); | 1121 ComputeFunctionType(shared_info); |
| 1124 bool ok = true; | 1122 bool ok = true; |
| 1125 | 1123 |
| 1126 if (shared_info->is_arrow()) { | 1124 if (shared_info->is_arrow()) { |
| 1127 bool is_async = allow_harmony_async_await() && shared_info->is_async(); | 1125 bool is_async = allow_harmony_async_await() && shared_info->is_async(); |
| 1128 if (is_async) { | 1126 if (is_async) { |
| (...skipping 3171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4300 int arity = -1; | 4298 int arity = -1; |
| 4301 int materialized_literal_count = -1; | 4299 int materialized_literal_count = -1; |
| 4302 int expected_property_count = -1; | 4300 int expected_property_count = -1; |
| 4303 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); | 4301 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); |
| 4304 bool should_be_used_once_hint = false; | 4302 bool should_be_used_once_hint = false; |
| 4305 bool has_duplicate_parameters; | 4303 bool has_duplicate_parameters; |
| 4306 FunctionLiteral::EagerCompileHint eager_compile_hint; | 4304 FunctionLiteral::EagerCompileHint eager_compile_hint; |
| 4307 | 4305 |
| 4308 // Parse function. | 4306 // Parse function. |
| 4309 { | 4307 { |
| 4310 AstNodeFactory function_factory(ast_value_factory()); | 4308 FunctionState function_state(&function_state_, &scope_state_, scope, kind); |
| 4311 FunctionState function_state(&function_state_, &scope_state_, scope, kind, | |
| 4312 &function_factory); | |
| 4313 this->scope()->SetScopeName(function_name); | 4309 this->scope()->SetScopeName(function_name); |
| 4314 ExpressionClassifier formals_classifier(this, &duplicate_finder); | 4310 ExpressionClassifier formals_classifier(this, &duplicate_finder); |
| 4315 | 4311 |
| 4316 eager_compile_hint = function_state_->this_function_is_parenthesized() | 4312 eager_compile_hint = function_state_->this_function_is_parenthesized() |
| 4317 ? FunctionLiteral::kShouldEagerCompile | 4313 ? FunctionLiteral::kShouldEagerCompile |
| 4318 : FunctionLiteral::kShouldLazyCompile; | 4314 : FunctionLiteral::kShouldLazyCompile; |
| 4319 | 4315 |
| 4320 if (is_generator) { | 4316 if (is_generator) { |
| 4321 // For generators, allocating variables in contexts is currently a win | 4317 // For generators, allocating variables in contexts is currently a win |
| 4322 // because it minimizes the work needed to suspend and resume an | 4318 // because it minimizes the work needed to suspend and resume an |
| (...skipping 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7075 node->Print(Isolate::Current()); | 7071 node->Print(Isolate::Current()); |
| 7076 } | 7072 } |
| 7077 #endif // DEBUG | 7073 #endif // DEBUG |
| 7078 | 7074 |
| 7079 #undef CHECK_OK | 7075 #undef CHECK_OK |
| 7080 #undef CHECK_OK_VOID | 7076 #undef CHECK_OK_VOID |
| 7081 #undef CHECK_FAILED | 7077 #undef CHECK_FAILED |
| 7082 | 7078 |
| 7083 } // namespace internal | 7079 } // namespace internal |
| 7084 } // namespace v8 | 7080 } // namespace v8 |
| OLD | NEW |