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" | |
10 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
11 #include "src/char-predicates-inl.h" | 10 #include "src/char-predicates-inl.h" |
12 #include "src/codegen.h" | 11 #include "src/codegen.h" |
13 #include "src/compiler.h" | 12 #include "src/compiler.h" |
14 #include "src/messages.h" | 13 #include "src/messages.h" |
15 #include "src/parser.h" | 14 #include "src/parser.h" |
16 #include "src/preparser.h" | 15 #include "src/preparser.h" |
17 #include "src/runtime.h" | 16 #include "src/runtime.h" |
18 #include "src/scanner-character-streams.h" | 17 #include "src/scanner-character-streams.h" |
19 #include "src/scopeinfo.h" | 18 #include "src/scopeinfo.h" |
20 #include "src/string-stream.h" | 19 #include "src/string-stream.h" |
21 | 20 |
| 21 #include "include/v8-platform.h" |
| 22 |
22 namespace v8 { | 23 namespace v8 { |
23 namespace internal { | 24 namespace internal { |
24 | 25 |
25 RegExpBuilder::RegExpBuilder(Zone* zone) | 26 RegExpBuilder::RegExpBuilder(Zone* zone) |
26 : zone_(zone), | 27 : zone_(zone), |
27 pending_empty_(false), | 28 pending_empty_(false), |
28 characters_(NULL), | 29 characters_(NULL), |
29 terms_(), | 30 terms_(), |
30 alternatives_() | 31 alternatives_() |
31 #ifdef DEBUG | 32 #ifdef DEBUG |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 FunctionLiteral::FunctionType type, | 699 FunctionLiteral::FunctionType type, |
699 FunctionLiteral::ArityRestriction arity_restriction, | 700 FunctionLiteral::ArityRestriction arity_restriction, |
700 bool* ok) { | 701 bool* ok) { |
701 return parser_->ParseFunctionLiteral(name, function_name_location, | 702 return parser_->ParseFunctionLiteral(name, function_name_location, |
702 name_is_strict_reserved, is_generator, | 703 name_is_strict_reserved, is_generator, |
703 function_token_position, type, | 704 function_token_position, type, |
704 arity_restriction, ok); | 705 arity_restriction, ok); |
705 } | 706 } |
706 | 707 |
707 | 708 |
708 Parser::Parser(CompilationInfo* info) | 709 Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed) |
709 : ParserBase<ParserTraits>(&scanner_, | 710 : ParserBase<ParserTraits>(&scanner_, stack_limit, info->extension(), NULL, |
710 info->isolate()->stack_guard()->real_climit(), | 711 info->zone(), this), |
711 info->extension(), NULL, info->zone(), this), | |
712 isolate_(info->isolate()), | 712 isolate_(info->isolate()), |
713 script_(info->script()), | 713 script_(info->script()), |
714 scanner_(isolate_->unicode_cache()), | 714 scanner_(isolate_->unicode_cache()), |
715 reusable_preparser_(NULL), | 715 reusable_preparser_(NULL), |
716 original_scope_(NULL), | 716 original_scope_(NULL), |
717 target_stack_(NULL), | 717 target_stack_(NULL), |
718 cached_parse_data_(NULL), | 718 cached_parse_data_(NULL), |
719 ast_value_factory_(NULL), | 719 ast_value_factory_(NULL), |
720 info_(info), | 720 info_(info), |
721 has_pending_error_(false), | 721 has_pending_error_(false), |
722 pending_error_message_(NULL), | 722 pending_error_message_(NULL), |
723 pending_error_arg_(NULL), | 723 pending_error_arg_(NULL), |
724 pending_error_char_arg_(NULL) { | 724 pending_error_char_arg_(NULL), |
725 DCHECK(!script_.is_null()); | 725 hash_seed_(hash_seed) { |
| 726 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
726 isolate_->set_ast_node_id(0); | 727 isolate_->set_ast_node_id(0); |
727 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 728 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
728 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 729 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
729 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 730 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
730 set_allow_lazy(false); // Must be explicitly enabled. | 731 set_allow_lazy(false); // Must be explicitly enabled. |
731 set_allow_generators(FLAG_harmony_generators); | 732 set_allow_generators(FLAG_harmony_generators); |
732 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 733 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
733 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 734 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
734 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 735 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
735 ++feature) { | 736 ++feature) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 792 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
792 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 793 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
793 log_ = NULL; | 794 log_ = NULL; |
794 } | 795 } |
795 return result; | 796 return result; |
796 } | 797 } |
797 | 798 |
798 | 799 |
799 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, | 800 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, |
800 Handle<String> source) { | 801 Handle<String> source) { |
| 802 Scope* scope = NULL; |
| 803 Scope* ad_hoc_eval_scope = NULL; |
| 804 FunctionLiteral* result = |
| 805 DoParseProgramInner(info, &scope, &ad_hoc_eval_scope); |
| 806 scope->set_end_position(source->length()); |
| 807 if (ad_hoc_eval_scope != NULL) { |
| 808 ad_hoc_eval_scope->set_end_position(source->length()); |
| 809 } |
| 810 |
| 811 ast_value_factory_->Internalize(isolate()); |
| 812 if (result == NULL) { |
| 813 if (stack_overflow()) { |
| 814 isolate()->StackOverflow(); |
| 815 } else { |
| 816 ThrowPendingError(); |
| 817 } |
| 818 } |
| 819 return result; |
| 820 } |
| 821 |
| 822 |
| 823 FunctionLiteral* Parser::DoParseProgramInner(CompilationInfo* info, |
| 824 Scope** scope, |
| 825 Scope** ad_hod_eval_scope) { |
801 DCHECK(scope_ == NULL); | 826 DCHECK(scope_ == NULL); |
802 DCHECK(target_stack_ == NULL); | 827 DCHECK(target_stack_ == NULL); |
803 | 828 |
804 FunctionLiteral* result = NULL; | 829 FunctionLiteral* result = NULL; |
805 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 830 { |
806 info->SetGlobalScope(scope); | 831 *scope = NewScope(scope_, GLOBAL_SCOPE); |
| 832 info->SetGlobalScope(*scope); |
807 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 833 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
808 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); | 834 *scope = Scope::DeserializeScopeChain(*info->context(), *scope, zone()); |
809 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 835 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
810 // means the Parser cannot operate independent of the V8 heap. Tell the | 836 // means the Parser cannot operate independent of the V8 heap. Tell the |
811 // string table to internalize strings and values right after they're | 837 // string table to internalize strings and values right after they're |
812 // created. | 838 // created. |
813 ast_value_factory_->Internalize(isolate()); | 839 ast_value_factory_->Internalize(isolate()); |
814 } | 840 } |
815 original_scope_ = scope; | 841 original_scope_ = *scope; |
816 if (info->is_eval()) { | 842 if (info->is_eval()) { |
817 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { | 843 if (!(*scope)->is_global_scope() || info->strict_mode() == STRICT) { |
818 scope = NewScope(scope, EVAL_SCOPE); | 844 *scope = NewScope(*scope, EVAL_SCOPE); |
819 } | 845 } |
820 } else if (info->is_global()) { | 846 } else if (info->is_global()) { |
821 scope = NewScope(scope, GLOBAL_SCOPE); | 847 *scope = NewScope(*scope, GLOBAL_SCOPE); |
822 } | 848 } |
823 scope->set_start_position(0); | 849 (*scope)->set_start_position(0); |
824 scope->set_end_position(source->length()); | |
825 | 850 |
826 // Compute the parsing mode. | 851 // Compute the parsing mode. |
827 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 852 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
828 if (allow_natives_syntax() || | 853 if (allow_natives_syntax() || extension_ != NULL || |
829 extension_ != NULL || | 854 (*scope)->is_eval_scope()) { |
830 scope->is_eval_scope()) { | |
831 mode = PARSE_EAGERLY; | 855 mode = PARSE_EAGERLY; |
832 } | 856 } |
833 ParsingModeScope parsing_mode(this, mode); | 857 ParsingModeScope parsing_mode(this, mode); |
834 | 858 |
835 // Enters 'scope'. | 859 // Enters 'scope'. |
836 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 860 FunctionState function_state(&function_state_, &scope_, *scope, zone(), |
837 ast_value_factory_); | 861 ast_value_factory_); |
838 | 862 |
839 scope_->SetStrictMode(info->strict_mode()); | 863 scope_->SetStrictMode(info->strict_mode()); |
840 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 864 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
841 bool ok = true; | 865 bool ok = true; |
842 int beg_pos = scanner()->location().beg_pos; | 866 int beg_pos = scanner()->location().beg_pos; |
843 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 867 ParseSourceElements(body, Token::EOS, info->is_eval(), true, |
| 868 ad_hod_eval_scope, &ok); |
844 | 869 |
845 HandleSourceURLComments(); | 870 HandleSourceURLComments(); |
846 | 871 |
847 if (ok && strict_mode() == STRICT) { | 872 if (ok && strict_mode() == STRICT) { |
848 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 873 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
849 } | 874 } |
850 | 875 |
851 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { | 876 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { |
852 CheckConflictingVarDeclarations(scope_, &ok); | 877 CheckConflictingVarDeclarations(scope_, &ok); |
853 } | 878 } |
854 | 879 |
855 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 880 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
856 if (body->length() != 1 || | 881 if (body->length() != 1 || |
857 !body->at(0)->IsExpressionStatement() || | 882 !body->at(0)->IsExpressionStatement() || |
858 !body->at(0)->AsExpressionStatement()-> | 883 !body->at(0)->AsExpressionStatement()-> |
859 expression()->IsFunctionLiteral()) { | 884 expression()->IsFunctionLiteral()) { |
860 ReportMessage("single_function_literal"); | 885 ReportMessage("single_function_literal"); |
861 ok = false; | 886 ok = false; |
862 } | 887 } |
863 } | 888 } |
864 | 889 |
865 ast_value_factory_->Internalize(isolate()); | |
866 if (ok) { | 890 if (ok) { |
867 result = factory()->NewFunctionLiteral( | 891 result = factory()->NewFunctionLiteral( |
868 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, | 892 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, |
869 function_state.materialized_literal_count(), | 893 function_state.materialized_literal_count(), |
870 function_state.expected_property_count(), | 894 function_state.expected_property_count(), |
871 function_state.handler_count(), 0, | 895 function_state.handler_count(), 0, |
872 FunctionLiteral::kNoDuplicateParameters, | 896 FunctionLiteral::kNoDuplicateParameters, |
873 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, | 897 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, |
874 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction, | 898 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction, |
875 0); | 899 0); |
876 result->set_ast_properties(factory()->visitor()->ast_properties()); | 900 result->set_ast_properties(factory()->visitor()->ast_properties()); |
877 result->set_dont_optimize_reason( | 901 result->set_dont_optimize_reason( |
878 factory()->visitor()->dont_optimize_reason()); | 902 factory()->visitor()->dont_optimize_reason()); |
879 } else if (stack_overflow()) { | |
880 isolate()->StackOverflow(); | |
881 } else { | |
882 ThrowPendingError(); | |
883 } | 903 } |
884 } | 904 } |
885 | 905 |
886 // Make sure the target stack is empty. | 906 // Make sure the target stack is empty. |
887 DCHECK(target_stack_ == NULL); | 907 DCHECK(target_stack_ == NULL); |
888 | 908 |
889 return result; | 909 return result; |
890 } | 910 } |
891 | 911 |
892 | 912 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 } | 1012 } |
993 } else { | 1013 } else { |
994 Handle<String> inferred_name(shared_info->inferred_name()); | 1014 Handle<String> inferred_name(shared_info->inferred_name()); |
995 result->set_inferred_name(inferred_name); | 1015 result->set_inferred_name(inferred_name); |
996 } | 1016 } |
997 return result; | 1017 return result; |
998 } | 1018 } |
999 | 1019 |
1000 | 1020 |
1001 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 1021 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
1002 int end_token, | 1022 int end_token, bool is_eval, bool is_global, |
1003 bool is_eval, | 1023 Scope** ad_hod_eval_scope, bool* ok) { |
1004 bool is_global, | |
1005 bool* ok) { | |
1006 // SourceElements :: | 1024 // SourceElements :: |
1007 // (ModuleElement)* <end_token> | 1025 // (ModuleElement)* <end_token> |
1008 | 1026 |
1009 // Allocate a target stack to use for this set of source | 1027 // Allocate a target stack to use for this set of source |
1010 // elements. This way, all scripts and functions get their own | 1028 // elements. This way, all scripts and functions get their own |
1011 // target stack thus avoiding illegal breaks and continues across | 1029 // target stack thus avoiding illegal breaks and continues across |
1012 // functions. | 1030 // functions. |
1013 TargetScope scope(&this->target_stack_); | 1031 TargetScope scope(&this->target_stack_); |
1014 | 1032 |
1015 DCHECK(processor != NULL); | 1033 DCHECK(processor != NULL); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 // as specified in ES5 10.4.2(3). The correct fix would be to always | 1069 // as specified in ES5 10.4.2(3). The correct fix would be to always |
1052 // add this scope in DoParseProgram(), but that requires adaptations | 1070 // add this scope in DoParseProgram(), but that requires adaptations |
1053 // all over the code base, so we go with a quick-fix for now. | 1071 // all over the code base, so we go with a quick-fix for now. |
1054 // In the same manner, we have to patch the parsing mode. | 1072 // In the same manner, we have to patch the parsing mode. |
1055 if (is_eval && !scope_->is_eval_scope()) { | 1073 if (is_eval && !scope_->is_eval_scope()) { |
1056 DCHECK(scope_->is_global_scope()); | 1074 DCHECK(scope_->is_global_scope()); |
1057 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 1075 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
1058 scope->set_start_position(scope_->start_position()); | 1076 scope->set_start_position(scope_->start_position()); |
1059 scope->set_end_position(scope_->end_position()); | 1077 scope->set_end_position(scope_->end_position()); |
1060 scope_ = scope; | 1078 scope_ = scope; |
| 1079 if (ad_hod_eval_scope != NULL) { |
| 1080 *ad_hod_eval_scope = scope; |
| 1081 } |
1061 mode_ = PARSE_EAGERLY; | 1082 mode_ = PARSE_EAGERLY; |
1062 } | 1083 } |
1063 scope_->SetStrictMode(STRICT); | 1084 scope_->SetStrictMode(STRICT); |
1064 // "use strict" is the only directive for now. | 1085 // "use strict" is the only directive for now. |
1065 directive_prologue = false; | 1086 directive_prologue = false; |
1066 } else if (literal->raw_value()->AsString() == | 1087 } else if (literal->raw_value()->AsString() == |
1067 ast_value_factory_->use_asm_string() && | 1088 ast_value_factory_->use_asm_string() && |
1068 token_loc.end_pos - token_loc.beg_pos == | 1089 token_loc.end_pos - token_loc.beg_pos == |
1069 ast_value_factory_->use_asm_string()->length() + 2) { | 1090 ast_value_factory_->use_asm_string()->length() + 2) { |
1070 // Store the usage count; The actual use counter on the isolate is | 1091 // Store the usage count; The actual use counter on the isolate is |
(...skipping 2628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3699 Assignment* assignment = factory()->NewAssignment( | 3720 Assignment* assignment = factory()->NewAssignment( |
3700 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); | 3721 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); |
3701 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3722 VariableProxy* get_proxy = factory()->NewVariableProxy( |
3702 function_state_->generator_object_variable()); | 3723 function_state_->generator_object_variable()); |
3703 Yield* yield = factory()->NewYield( | 3724 Yield* yield = factory()->NewYield( |
3704 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); | 3725 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); |
3705 body->Add(factory()->NewExpressionStatement( | 3726 body->Add(factory()->NewExpressionStatement( |
3706 yield, RelocInfo::kNoPosition), zone()); | 3727 yield, RelocInfo::kNoPosition), zone()); |
3707 } | 3728 } |
3708 | 3729 |
3709 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); | 3730 ParseSourceElements(body, Token::RBRACE, false, false, NULL, CHECK_OK); |
3710 | 3731 |
3711 if (is_generator) { | 3732 if (is_generator) { |
3712 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3733 VariableProxy* get_proxy = factory()->NewVariableProxy( |
3713 function_state_->generator_object_variable()); | 3734 function_state_->generator_object_variable()); |
3714 Expression* undefined = | 3735 Expression* undefined = |
3715 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); | 3736 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
3716 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL, | 3737 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL, |
3717 RelocInfo::kNoPosition); | 3738 RelocInfo::kNoPosition); |
3718 body->Add(factory()->NewExpressionStatement( | 3739 body->Add(factory()->NewExpressionStatement( |
3719 yield, RelocInfo::kNoPosition), zone()); | 3740 yield, RelocInfo::kNoPosition), zone()); |
3720 } | 3741 } |
3721 | 3742 |
3722 Expect(Token::RBRACE, CHECK_OK); | 3743 Expect(Token::RBRACE, CHECK_OK); |
3723 scope_->set_end_position(scanner()->location().end_pos); | 3744 scope_->set_end_position(scanner()->location().end_pos); |
3724 | 3745 |
3725 return body; | 3746 return body; |
3726 } | 3747 } |
3727 | 3748 |
3728 | 3749 |
3729 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( | 3750 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( |
3730 SingletonLogger* logger) { | 3751 SingletonLogger* logger) { |
3731 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); | 3752 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); |
3732 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); | 3753 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); |
3733 | 3754 |
3734 if (reusable_preparser_ == NULL) { | 3755 if (reusable_preparser_ == NULL) { |
3735 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); | 3756 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_); |
3736 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit); | |
3737 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); | 3757 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); |
3738 reusable_preparser_->set_allow_modules(allow_modules()); | 3758 reusable_preparser_->set_allow_modules(allow_modules()); |
3739 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); | 3759 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); |
3740 reusable_preparser_->set_allow_lazy(true); | 3760 reusable_preparser_->set_allow_lazy(true); |
3741 reusable_preparser_->set_allow_generators(allow_generators()); | 3761 reusable_preparser_->set_allow_generators(allow_generators()); |
3742 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); | 3762 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); |
3743 reusable_preparser_->set_allow_harmony_numeric_literals( | 3763 reusable_preparser_->set_allow_harmony_numeric_literals( |
3744 allow_harmony_numeric_literals()); | 3764 allow_harmony_numeric_literals()); |
3745 } | 3765 } |
3746 PreParser::PreParseResult result = | 3766 PreParser::PreParseResult result = |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4767 } | 4787 } |
4768 return !parser.failed(); | 4788 return !parser.failed(); |
4769 } | 4789 } |
4770 | 4790 |
4771 | 4791 |
4772 bool Parser::Parse() { | 4792 bool Parser::Parse() { |
4773 DCHECK(info()->function() == NULL); | 4793 DCHECK(info()->function() == NULL); |
4774 FunctionLiteral* result = NULL; | 4794 FunctionLiteral* result = NULL; |
4775 ast_value_factory_ = info()->ast_value_factory(); | 4795 ast_value_factory_ = info()->ast_value_factory(); |
4776 if (ast_value_factory_ == NULL) { | 4796 if (ast_value_factory_ == NULL) { |
4777 ast_value_factory_ = | 4797 ast_value_factory_ = new AstValueFactory(zone(), hash_seed_); |
4778 new AstValueFactory(zone(), isolate()->heap()->HashSeed()); | |
4779 } | 4798 } |
4780 if (allow_natives_syntax() || extension_ != NULL) { | 4799 if (allow_natives_syntax() || extension_ != NULL) { |
4781 // If intrinsics are allowed, the Parser cannot operate independent of the | 4800 // If intrinsics are allowed, the Parser cannot operate independent of the |
4782 // V8 heap because of Rumtime. Tell the string table to internalize strings | 4801 // V8 heap because of Rumtime. Tell the string table to internalize strings |
4783 // and values right after they're created. | 4802 // and values right after they're created. |
4784 ast_value_factory_->Internalize(isolate()); | 4803 ast_value_factory_->Internalize(isolate()); |
4785 } | 4804 } |
4786 | 4805 |
4787 if (info()->is_lazy()) { | 4806 if (info()->is_lazy()) { |
4788 DCHECK(!info()->is_eval()); | 4807 DCHECK(!info()->is_eval()); |
(...skipping 12 matching lines...) Expand all Loading... |
4801 if (info()->ast_value_factory() == NULL) { | 4820 if (info()->ast_value_factory() == NULL) { |
4802 info()->SetAstValueFactory(ast_value_factory_); | 4821 info()->SetAstValueFactory(ast_value_factory_); |
4803 } | 4822 } |
4804 ast_value_factory_ = NULL; | 4823 ast_value_factory_ = NULL; |
4805 | 4824 |
4806 InternalizeUseCounts(); | 4825 InternalizeUseCounts(); |
4807 | 4826 |
4808 return (result != NULL); | 4827 return (result != NULL); |
4809 } | 4828 } |
4810 | 4829 |
| 4830 |
| 4831 void Parser::ParseOnBackground() { |
| 4832 DCHECK(info()->function() == NULL); |
| 4833 FunctionLiteral* result = NULL; |
| 4834 ast_value_factory_ = info()->ast_value_factory(); |
| 4835 if (ast_value_factory_ == NULL) { |
| 4836 ast_value_factory_ = new AstValueFactory(zone(), hash_seed_); |
| 4837 } |
| 4838 fni_ = new (zone()) FuncNameInferrer(ast_value_factory_, zone()); |
| 4839 |
| 4840 CompleteParserRecorder recorder; |
| 4841 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4842 log_ = &recorder; |
| 4843 } |
| 4844 |
| 4845 DCHECK(info()->source_stream() != NULL); |
| 4846 ExternalStreamingStream stream(info()->source_stream()); |
| 4847 scanner_.Initialize(&stream); |
| 4848 DCHECK(info()->context().is_null() || info()->context()->IsNativeContext()); |
| 4849 |
| 4850 Scope* scope = NULL; |
| 4851 Scope* ad_hoc_eval_scope = NULL; |
| 4852 result = DoParseProgramInner(info(), &scope, &ad_hoc_eval_scope); |
| 4853 |
| 4854 scope->set_end_position(scanner()->location().end_pos); |
| 4855 if (ad_hoc_eval_scope != NULL) { |
| 4856 ad_hoc_eval_scope->set_end_position(scanner()->location().end_pos); |
| 4857 } |
| 4858 |
| 4859 if (info()->ast_value_factory() == NULL) { |
| 4860 info()->SetAstValueFactory(ast_value_factory_); |
| 4861 } |
| 4862 |
| 4863 info()->SetFunction(result); |
| 4864 |
| 4865 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4866 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 4867 log_ = NULL; |
| 4868 } |
| 4869 } |
4811 } } // namespace v8::internal | 4870 } } // namespace v8::internal |
OLD | NEW |