Chromium Code Reviews| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/ast.h" | 8 #include "src/ast.h" |
| 9 #include "src/base/platform/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 #define DUMMY ) // to make indentation work | 338 #define DUMMY ) // to make indentation work |
| 339 #undef DUMMY | 339 #undef DUMMY |
| 340 | 340 |
| 341 // ---------------------------------------------------------------------------- | 341 // ---------------------------------------------------------------------------- |
| 342 // Implementation of Parser | 342 // Implementation of Parser |
| 343 | 343 |
| 344 class ParserTraits::Checkpoint | 344 class ParserTraits::Checkpoint |
| 345 : public ParserBase<ParserTraits>::CheckpointBase { | 345 : public ParserBase<ParserTraits>::CheckpointBase { |
| 346 public: | 346 public: |
| 347 explicit Checkpoint(ParserBase<ParserTraits>* parser) | 347 explicit Checkpoint(ParserBase<ParserTraits>* parser) |
| 348 : CheckpointBase(parser) { | 348 : CheckpointBase(parser), parser_(parser) { |
| 349 isolate_ = parser->zone()->isolate(); | 349 saved_ast_node_id_gen_ = *(parser_->ast_node_id_gen_); |
| 350 saved_ast_node_id_ = isolate_->ast_node_id(); | |
| 351 } | 350 } |
| 352 | 351 |
| 353 void Restore() { | 352 void Restore() { |
| 354 CheckpointBase::Restore(); | 353 CheckpointBase::Restore(); |
| 355 isolate_->set_ast_node_id(saved_ast_node_id_); | 354 *(parser_->ast_node_id_gen_) = saved_ast_node_id_gen_; |
| 356 } | 355 } |
| 357 | 356 |
| 358 private: | 357 private: |
| 359 Isolate* isolate_; | 358 ParserBase<ParserTraits>* parser_; |
| 360 int saved_ast_node_id_; | 359 AstNode::IdGen saved_ast_node_id_gen_; |
| 361 }; | 360 }; |
| 362 | 361 |
| 363 | 362 |
| 364 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { | 363 bool ParserTraits::IsEvalOrArguments(const AstRawString* identifier) const { |
| 365 return identifier == parser_->ast_value_factory_->eval_string() || | 364 return identifier == parser_->ast_value_factory_->eval_string() || |
| 366 identifier == parser_->ast_value_factory_->arguments_string(); | 365 identifier == parser_->ast_value_factory_->arguments_string(); |
| 367 } | 366 } |
| 368 | 367 |
| 369 | 368 |
| 370 bool ParserTraits::IsThisProperty(Expression* expression) { | 369 bool ParserTraits::IsThisProperty(Expression* expression) { |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 FunctionLiteral::ArityRestriction arity_restriction, | 724 FunctionLiteral::ArityRestriction arity_restriction, |
| 726 bool* ok) { | 725 bool* ok) { |
| 727 return parser_->ParseFunctionLiteral(name, function_name_location, | 726 return parser_->ParseFunctionLiteral(name, function_name_location, |
| 728 name_is_strict_reserved, is_generator, | 727 name_is_strict_reserved, is_generator, |
| 729 function_token_position, type, | 728 function_token_position, type, |
| 730 arity_restriction, ok); | 729 arity_restriction, ok); |
| 731 } | 730 } |
| 732 | 731 |
| 733 | 732 |
| 734 Parser::Parser(CompilationInfo* info) | 733 Parser::Parser(CompilationInfo* info) |
| 735 : ParserBase<ParserTraits>(&scanner_, | 734 : ParserBase<ParserTraits>( |
| 736 info->isolate()->stack_guard()->real_climit(), | 735 &scanner_, info->isolate()->stack_guard()->real_climit(), |
| 737 info->extension(), NULL, info->zone(), this), | 736 info->extension(), NULL, info->zone(), info->ast_node_id_gen(), this), |
| 738 isolate_(info->isolate()), | 737 isolate_(info->isolate()), |
| 739 script_(info->script()), | 738 script_(info->script()), |
| 740 scanner_(isolate_->unicode_cache()), | 739 scanner_(isolate_->unicode_cache()), |
| 741 reusable_preparser_(NULL), | 740 reusable_preparser_(NULL), |
| 742 original_scope_(NULL), | 741 original_scope_(NULL), |
| 743 target_stack_(NULL), | 742 target_stack_(NULL), |
| 744 cached_parse_data_(NULL), | 743 cached_parse_data_(NULL), |
| 745 ast_value_factory_(NULL), | 744 ast_value_factory_(NULL), |
| 746 info_(info), | 745 info_(info), |
| 747 has_pending_error_(false), | 746 has_pending_error_(false), |
| 748 pending_error_message_(NULL), | 747 pending_error_message_(NULL), |
| 749 pending_error_arg_(NULL), | 748 pending_error_arg_(NULL), |
| 750 pending_error_char_arg_(NULL) { | 749 pending_error_char_arg_(NULL) { |
| 751 DCHECK(!script_.is_null()); | 750 DCHECK(!script_.is_null()); |
| 752 isolate_->set_ast_node_id(0); | 751 *(info->ast_node_id_gen()) = AstNode::IdGen(0); |
|
rossberg
2014/08/21 13:43:35
Isn't this default constructed in the CompilationI
marja
2014/08/22 07:59:07
This would only change things if we parse with the
rossberg
2014/08/22 08:47:58
Right, I don't think we should ever do such reuse.
| |
| 753 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 752 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 754 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 753 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
| 755 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 754 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 756 set_allow_lazy(false); // Must be explicitly enabled. | 755 set_allow_lazy(false); // Must be explicitly enabled. |
| 757 set_allow_generators(FLAG_harmony_generators); | 756 set_allow_generators(FLAG_harmony_generators); |
| 758 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 757 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
| 759 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 758 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 760 set_allow_classes(FLAG_harmony_classes); | 759 set_allow_classes(FLAG_harmony_classes); |
| 761 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 760 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 762 ++feature) { | 761 ++feature) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 853 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
| 855 if (allow_natives_syntax() || | 854 if (allow_natives_syntax() || |
| 856 extension_ != NULL || | 855 extension_ != NULL || |
| 857 scope->is_eval_scope()) { | 856 scope->is_eval_scope()) { |
| 858 mode = PARSE_EAGERLY; | 857 mode = PARSE_EAGERLY; |
| 859 } | 858 } |
| 860 ParsingModeScope parsing_mode(this, mode); | 859 ParsingModeScope parsing_mode(this, mode); |
| 861 | 860 |
| 862 // Enters 'scope'. | 861 // Enters 'scope'. |
| 863 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 862 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
| 864 ast_value_factory_); | 863 ast_value_factory_, info->ast_node_id_gen()); |
| 865 | 864 |
| 866 scope_->SetStrictMode(info->strict_mode()); | 865 scope_->SetStrictMode(info->strict_mode()); |
| 867 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 866 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 868 bool ok = true; | 867 bool ok = true; |
| 869 int beg_pos = scanner()->location().beg_pos; | 868 int beg_pos = scanner()->location().beg_pos; |
| 870 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 869 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); |
| 871 | 870 |
| 872 HandleSourceURLComments(); | 871 HandleSourceURLComments(); |
| 873 | 872 |
| 874 if (ok && strict_mode() == STRICT) { | 873 if (ok && strict_mode() == STRICT) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 972 { | 971 { |
| 973 // Parse the function literal. | 972 // Parse the function literal. |
| 974 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 973 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
| 975 info()->SetGlobalScope(scope); | 974 info()->SetGlobalScope(scope); |
| 976 if (!info()->closure().is_null()) { | 975 if (!info()->closure().is_null()) { |
| 977 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 976 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
| 978 zone()); | 977 zone()); |
| 979 } | 978 } |
| 980 original_scope_ = scope; | 979 original_scope_ = scope; |
| 981 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 980 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
| 982 ast_value_factory_); | 981 ast_value_factory_, info()->ast_node_id_gen()); |
| 983 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 982 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
| 984 DCHECK(info()->strict_mode() == shared_info->strict_mode()); | 983 DCHECK(info()->strict_mode() == shared_info->strict_mode()); |
| 985 scope->SetStrictMode(shared_info->strict_mode()); | 984 scope->SetStrictMode(shared_info->strict_mode()); |
| 986 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 985 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
| 987 ? (shared_info->is_anonymous() | 986 ? (shared_info->is_anonymous() |
| 988 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 987 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
| 989 : FunctionLiteral::NAMED_EXPRESSION) | 988 : FunctionLiteral::NAMED_EXPRESSION) |
| 990 : FunctionLiteral::DECLARATION; | 989 : FunctionLiteral::DECLARATION; |
| 991 bool is_generator = shared_info->is_generator(); | 990 bool is_generator = shared_info->is_generator(); |
| 992 bool ok = true; | 991 bool ok = true; |
| (...skipping 2442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3435 FunctionLiteral::ParameterFlag duplicate_parameters = | 3434 FunctionLiteral::ParameterFlag duplicate_parameters = |
| 3436 FunctionLiteral::kNoDuplicateParameters; | 3435 FunctionLiteral::kNoDuplicateParameters; |
| 3437 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 3436 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
| 3438 ? FunctionLiteral::kIsParenthesized | 3437 ? FunctionLiteral::kIsParenthesized |
| 3439 : FunctionLiteral::kNotParenthesized; | 3438 : FunctionLiteral::kNotParenthesized; |
| 3440 AstProperties ast_properties; | 3439 AstProperties ast_properties; |
| 3441 BailoutReason dont_optimize_reason = kNoReason; | 3440 BailoutReason dont_optimize_reason = kNoReason; |
| 3442 // Parse function body. | 3441 // Parse function body. |
| 3443 { | 3442 { |
| 3444 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 3443 FunctionState function_state(&function_state_, &scope_, scope, zone(), |
| 3445 ast_value_factory_); | 3444 ast_value_factory_, info()->ast_node_id_gen()); |
| 3446 scope_->SetScopeName(function_name); | 3445 scope_->SetScopeName(function_name); |
| 3447 | 3446 |
| 3448 if (is_generator) { | 3447 if (is_generator) { |
| 3449 // For generators, allocating variables in contexts is currently a win | 3448 // For generators, allocating variables in contexts is currently a win |
| 3450 // because it minimizes the work needed to suspend and resume an | 3449 // because it minimizes the work needed to suspend and resume an |
| 3451 // activation. | 3450 // activation. |
| 3452 scope_->ForceContextAllocation(); | 3451 scope_->ForceContextAllocation(); |
| 3453 | 3452 |
| 3454 // Calling a generator returns a generator object. That object is stored | 3453 // Calling a generator returns a generator object. That object is stored |
| 3455 // in a temporary variable, a definition that is used by "yield" | 3454 // in a temporary variable, a definition that is used by "yield" |
| (...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4830 info()->SetAstValueFactory(ast_value_factory_); | 4829 info()->SetAstValueFactory(ast_value_factory_); |
| 4831 } | 4830 } |
| 4832 ast_value_factory_ = NULL; | 4831 ast_value_factory_ = NULL; |
| 4833 | 4832 |
| 4834 InternalizeUseCounts(); | 4833 InternalizeUseCounts(); |
| 4835 | 4834 |
| 4836 return (result != NULL); | 4835 return (result != NULL); |
| 4837 } | 4836 } |
| 4838 | 4837 |
| 4839 } } // namespace v8::internal | 4838 } } // namespace v8::internal |
| OLD | NEW |