Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1025)

Side by Side Diff: src/parser.cc

Issue 366153002: Add script streaming API (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: added tests + fixed compilation flags (!) Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 FunctionLiteral::FunctionType type, 733 FunctionLiteral::FunctionType type,
733 FunctionLiteral::ArityRestriction arity_restriction, 734 FunctionLiteral::ArityRestriction arity_restriction,
734 bool* ok) { 735 bool* ok) {
735 return parser_->ParseFunctionLiteral(name, function_name_location, 736 return parser_->ParseFunctionLiteral(name, function_name_location,
736 name_is_strict_reserved, is_generator, 737 name_is_strict_reserved, is_generator,
737 function_token_position, type, 738 function_token_position, type,
738 arity_restriction, ok); 739 arity_restriction, ok);
739 } 740 }
740 741
741 742
742 Parser::Parser(CompilationInfo* info) 743 Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed)
743 : ParserBase<ParserTraits>( 744 : ParserBase<ParserTraits>(&scanner_, stack_limit, info->extension(), NULL,
744 &scanner_, info->isolate()->stack_guard()->real_climit(), 745 info->zone(), info->ast_node_id_gen(), this),
745 info->extension(), NULL, info->zone(), info->ast_node_id_gen(), this),
746 isolate_(info->isolate()), 746 isolate_(info->isolate()),
747 script_(info->script()), 747 script_(info->script()),
748 scanner_(isolate_->unicode_cache()), 748 scanner_(isolate_->unicode_cache()),
749 reusable_preparser_(NULL), 749 reusable_preparser_(NULL),
750 original_scope_(NULL), 750 original_scope_(NULL),
751 target_stack_(NULL), 751 target_stack_(NULL),
752 cached_parse_data_(NULL), 752 cached_parse_data_(NULL),
753 ast_value_factory_(NULL), 753 ast_value_factory_(NULL),
754 info_(info), 754 info_(info),
755 has_pending_error_(false), 755 has_pending_error_(false),
756 pending_error_message_(NULL), 756 pending_error_message_(NULL),
757 pending_error_arg_(NULL), 757 pending_error_arg_(NULL),
758 pending_error_char_arg_(NULL) { 758 pending_error_char_arg_(NULL),
759 DCHECK(!script_.is_null()); 759 hash_seed_(hash_seed) {
760 DCHECK(!info->script().is_null() || info->source_stream() != NULL);
760 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); 761 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping);
761 set_allow_modules(!info->is_native() && FLAG_harmony_modules); 762 set_allow_modules(!info->is_native() && FLAG_harmony_modules);
762 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); 763 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
763 set_allow_lazy(false); // Must be explicitly enabled. 764 set_allow_lazy(false); // Must be explicitly enabled.
764 set_allow_generators(FLAG_harmony_generators); 765 set_allow_generators(FLAG_harmony_generators);
765 set_allow_arrow_functions(FLAG_harmony_arrow_functions); 766 set_allow_arrow_functions(FLAG_harmony_arrow_functions);
766 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); 767 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
767 set_allow_classes(FLAG_harmony_classes); 768 set_allow_classes(FLAG_harmony_classes);
768 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; 769 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
769 ++feature) { 770 ++feature) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 if (compile_options() == ScriptCompiler::kProduceParserCache) { 826 if (compile_options() == ScriptCompiler::kProduceParserCache) {
826 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); 827 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
827 log_ = NULL; 828 log_ = NULL;
828 } 829 }
829 return result; 830 return result;
830 } 831 }
831 832
832 833
833 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, 834 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info,
834 Handle<String> source) { 835 Handle<String> source) {
836 Scope* scope = NULL;
837 Scope* ad_hoc_eval_scope = NULL;
838 FunctionLiteral* result =
839 DoParseProgramInner(info, &scope, &ad_hoc_eval_scope);
840 scope->set_end_position(source->length());
841 if (ad_hoc_eval_scope != NULL) {
842 ad_hoc_eval_scope->set_end_position(source->length());
843 }
844
845 ast_value_factory_->Internalize(isolate());
846 if (result == NULL) {
847 if (stack_overflow()) {
848 isolate()->StackOverflow();
849 } else {
850 ThrowPendingError();
851 }
852 }
853 return result;
854 }
855
856
857 FunctionLiteral* Parser::DoParseProgramInner(CompilationInfo* info,
858 Scope** scope,
859 Scope** ad_hod_eval_scope) {
835 DCHECK(scope_ == NULL); 860 DCHECK(scope_ == NULL);
836 DCHECK(target_stack_ == NULL); 861 DCHECK(target_stack_ == NULL);
837 862
838 FunctionLiteral* result = NULL; 863 FunctionLiteral* result = NULL;
839 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); 864 {
840 info->SetGlobalScope(scope); 865 *scope = NewScope(scope_, GLOBAL_SCOPE);
866 info->SetGlobalScope(*scope);
841 if (!info->context().is_null() && !info->context()->IsNativeContext()) { 867 if (!info->context().is_null() && !info->context()->IsNativeContext()) {
842 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); 868 *scope = Scope::DeserializeScopeChain(*info->context(), *scope, zone());
843 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this 869 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this
844 // means the Parser cannot operate independent of the V8 heap. Tell the 870 // means the Parser cannot operate independent of the V8 heap. Tell the
845 // string table to internalize strings and values right after they're 871 // string table to internalize strings and values right after they're
846 // created. 872 // created.
847 ast_value_factory_->Internalize(isolate()); 873 ast_value_factory_->Internalize(isolate());
848 } 874 }
849 original_scope_ = scope; 875 original_scope_ = *scope;
850 if (info->is_eval()) { 876 if (info->is_eval()) {
851 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { 877 if (!(*scope)->is_global_scope() || info->strict_mode() == STRICT) {
852 scope = NewScope(scope, EVAL_SCOPE); 878 *scope = NewScope(*scope, EVAL_SCOPE);
853 } 879 }
854 } else if (info->is_global()) { 880 } else if (info->is_global()) {
855 scope = NewScope(scope, GLOBAL_SCOPE); 881 *scope = NewScope(*scope, GLOBAL_SCOPE);
856 } 882 }
857 scope->set_start_position(0); 883 (*scope)->set_start_position(0);
858 scope->set_end_position(source->length());
859 884
860 // Compute the parsing mode. 885 // Compute the parsing mode.
861 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; 886 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY;
862 if (allow_natives_syntax() || 887 if (allow_natives_syntax() || extension_ != NULL ||
863 extension_ != NULL || 888 (*scope)->is_eval_scope()) {
864 scope->is_eval_scope()) {
865 mode = PARSE_EAGERLY; 889 mode = PARSE_EAGERLY;
866 } 890 }
867 ParsingModeScope parsing_mode(this, mode); 891 ParsingModeScope parsing_mode(this, mode);
868 892
869 // Enters 'scope'. 893 // Enters 'scope'.
870 FunctionState function_state(&function_state_, &scope_, scope, zone(), 894 FunctionState function_state(&function_state_, &scope_, *scope, zone(),
871 ast_value_factory_, info->ast_node_id_gen()); 895 ast_value_factory_, info->ast_node_id_gen());
872 896
873 scope_->SetStrictMode(info->strict_mode()); 897 scope_->SetStrictMode(info->strict_mode());
874 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); 898 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
875 bool ok = true; 899 bool ok = true;
876 int beg_pos = scanner()->location().beg_pos; 900 int beg_pos = scanner()->location().beg_pos;
877 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); 901 ParseSourceElements(body, Token::EOS, info->is_eval(), true,
902 ad_hod_eval_scope, &ok);
878 903
879 HandleSourceURLComments(); 904 HandleSourceURLComments();
880 905
881 if (ok && strict_mode() == STRICT) { 906 if (ok && strict_mode() == STRICT) {
882 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); 907 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok);
883 } 908 }
884 909
885 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { 910 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) {
886 CheckConflictingVarDeclarations(scope_, &ok); 911 CheckConflictingVarDeclarations(scope_, &ok);
887 } 912 }
888 913
889 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { 914 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
890 if (body->length() != 1 || 915 if (body->length() != 1 ||
891 !body->at(0)->IsExpressionStatement() || 916 !body->at(0)->IsExpressionStatement() ||
892 !body->at(0)->AsExpressionStatement()-> 917 !body->at(0)->AsExpressionStatement()->
893 expression()->IsFunctionLiteral()) { 918 expression()->IsFunctionLiteral()) {
894 ReportMessage("single_function_literal"); 919 ReportMessage("single_function_literal");
895 ok = false; 920 ok = false;
896 } 921 }
897 } 922 }
898 923
899 ast_value_factory_->Internalize(isolate());
900 if (ok) { 924 if (ok) {
901 result = factory()->NewFunctionLiteral( 925 result = factory()->NewFunctionLiteral(
902 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body, 926 ast_value_factory_->empty_string(), ast_value_factory_, scope_, body,
903 function_state.materialized_literal_count(), 927 function_state.materialized_literal_count(),
904 function_state.expected_property_count(), 928 function_state.expected_property_count(),
905 function_state.handler_count(), 0, 929 function_state.handler_count(), 0,
906 FunctionLiteral::kNoDuplicateParameters, 930 FunctionLiteral::kNoDuplicateParameters,
907 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval, 931 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kGlobalOrEval,
908 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction, 932 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNormalFunction,
909 0); 933 0);
910 result->set_ast_properties(factory()->visitor()->ast_properties()); 934 result->set_ast_properties(factory()->visitor()->ast_properties());
911 result->set_dont_optimize_reason( 935 result->set_dont_optimize_reason(
912 factory()->visitor()->dont_optimize_reason()); 936 factory()->visitor()->dont_optimize_reason());
913 } else if (stack_overflow()) {
914 isolate()->StackOverflow();
915 } else {
916 ThrowPendingError();
917 } 937 }
918 } 938 }
919 939
920 // Make sure the target stack is empty. 940 // Make sure the target stack is empty.
921 DCHECK(target_stack_ == NULL); 941 DCHECK(target_stack_ == NULL);
922 942
923 return result; 943 return result;
924 } 944 }
925 945
926 946
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 } 1046 }
1027 } else { 1047 } else {
1028 Handle<String> inferred_name(shared_info->inferred_name()); 1048 Handle<String> inferred_name(shared_info->inferred_name());
1029 result->set_inferred_name(inferred_name); 1049 result->set_inferred_name(inferred_name);
1030 } 1050 }
1031 return result; 1051 return result;
1032 } 1052 }
1033 1053
1034 1054
1035 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, 1055 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
1036 int end_token, 1056 int end_token, bool is_eval, bool is_global,
1037 bool is_eval, 1057 Scope** ad_hod_eval_scope, bool* ok) {
1038 bool is_global,
1039 bool* ok) {
1040 // SourceElements :: 1058 // SourceElements ::
1041 // (ModuleElement)* <end_token> 1059 // (ModuleElement)* <end_token>
1042 1060
1043 // Allocate a target stack to use for this set of source 1061 // Allocate a target stack to use for this set of source
1044 // elements. This way, all scripts and functions get their own 1062 // elements. This way, all scripts and functions get their own
1045 // target stack thus avoiding illegal breaks and continues across 1063 // target stack thus avoiding illegal breaks and continues across
1046 // functions. 1064 // functions.
1047 TargetScope scope(&this->target_stack_); 1065 TargetScope scope(&this->target_stack_);
1048 1066
1049 DCHECK(processor != NULL); 1067 DCHECK(processor != NULL);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 // as specified in ES5 10.4.2(3). The correct fix would be to always 1103 // as specified in ES5 10.4.2(3). The correct fix would be to always
1086 // add this scope in DoParseProgram(), but that requires adaptations 1104 // add this scope in DoParseProgram(), but that requires adaptations
1087 // all over the code base, so we go with a quick-fix for now. 1105 // all over the code base, so we go with a quick-fix for now.
1088 // In the same manner, we have to patch the parsing mode. 1106 // In the same manner, we have to patch the parsing mode.
1089 if (is_eval && !scope_->is_eval_scope()) { 1107 if (is_eval && !scope_->is_eval_scope()) {
1090 DCHECK(scope_->is_global_scope()); 1108 DCHECK(scope_->is_global_scope());
1091 Scope* scope = NewScope(scope_, EVAL_SCOPE); 1109 Scope* scope = NewScope(scope_, EVAL_SCOPE);
1092 scope->set_start_position(scope_->start_position()); 1110 scope->set_start_position(scope_->start_position());
1093 scope->set_end_position(scope_->end_position()); 1111 scope->set_end_position(scope_->end_position());
1094 scope_ = scope; 1112 scope_ = scope;
1113 if (ad_hod_eval_scope != NULL) {
1114 *ad_hod_eval_scope = scope;
1115 }
1095 mode_ = PARSE_EAGERLY; 1116 mode_ = PARSE_EAGERLY;
1096 } 1117 }
1097 scope_->SetStrictMode(STRICT); 1118 scope_->SetStrictMode(STRICT);
1098 // "use strict" is the only directive for now. 1119 // "use strict" is the only directive for now.
1099 directive_prologue = false; 1120 directive_prologue = false;
1100 } else if (literal->raw_value()->AsString() == 1121 } else if (literal->raw_value()->AsString() ==
1101 ast_value_factory_->use_asm_string() && 1122 ast_value_factory_->use_asm_string() &&
1102 token_loc.end_pos - token_loc.beg_pos == 1123 token_loc.end_pos - token_loc.beg_pos ==
1103 ast_value_factory_->use_asm_string()->length() + 2) { 1124 ast_value_factory_->use_asm_string()->length() + 2) {
1104 // Store the usage count; The actual use counter on the isolate is 1125 // Store the usage count; The actual use counter on the isolate is
(...skipping 2628 matching lines...) Expand 10 before | Expand all | Expand 10 after
3733 Assignment* assignment = factory()->NewAssignment( 3754 Assignment* assignment = factory()->NewAssignment(
3734 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); 3755 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition);
3735 VariableProxy* get_proxy = factory()->NewVariableProxy( 3756 VariableProxy* get_proxy = factory()->NewVariableProxy(
3736 function_state_->generator_object_variable()); 3757 function_state_->generator_object_variable());
3737 Yield* yield = factory()->NewYield( 3758 Yield* yield = factory()->NewYield(
3738 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition); 3759 get_proxy, assignment, Yield::INITIAL, RelocInfo::kNoPosition);
3739 body->Add(factory()->NewExpressionStatement( 3760 body->Add(factory()->NewExpressionStatement(
3740 yield, RelocInfo::kNoPosition), zone()); 3761 yield, RelocInfo::kNoPosition), zone());
3741 } 3762 }
3742 3763
3743 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); 3764 ParseSourceElements(body, Token::RBRACE, false, false, NULL, CHECK_OK);
3744 3765
3745 if (is_generator) { 3766 if (is_generator) {
3746 VariableProxy* get_proxy = factory()->NewVariableProxy( 3767 VariableProxy* get_proxy = factory()->NewVariableProxy(
3747 function_state_->generator_object_variable()); 3768 function_state_->generator_object_variable());
3748 Expression* undefined = 3769 Expression* undefined =
3749 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); 3770 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition);
3750 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL, 3771 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::FINAL,
3751 RelocInfo::kNoPosition); 3772 RelocInfo::kNoPosition);
3752 body->Add(factory()->NewExpressionStatement( 3773 body->Add(factory()->NewExpressionStatement(
3753 yield, RelocInfo::kNoPosition), zone()); 3774 yield, RelocInfo::kNoPosition), zone());
3754 } 3775 }
3755 3776
3756 Expect(Token::RBRACE, CHECK_OK); 3777 Expect(Token::RBRACE, CHECK_OK);
3757 scope_->set_end_position(scanner()->location().end_pos); 3778 scope_->set_end_position(scanner()->location().end_pos);
3758 3779
3759 return body; 3780 return body;
3760 } 3781 }
3761 3782
3762 3783
3763 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( 3784 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
3764 SingletonLogger* logger) { 3785 SingletonLogger* logger) {
3765 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse()); 3786 HistogramTimerScope preparse_scope(isolate()->counters()->pre_parse());
3766 DCHECK_EQ(Token::LBRACE, scanner()->current_token()); 3787 DCHECK_EQ(Token::LBRACE, scanner()->current_token());
3767 3788
3768 if (reusable_preparser_ == NULL) { 3789 if (reusable_preparser_ == NULL) {
3769 intptr_t stack_limit = isolate()->stack_guard()->real_climit(); 3790 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit_);
3770 reusable_preparser_ = new PreParser(&scanner_, NULL, stack_limit);
3771 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping()); 3791 reusable_preparser_->set_allow_harmony_scoping(allow_harmony_scoping());
3772 reusable_preparser_->set_allow_modules(allow_modules()); 3792 reusable_preparser_->set_allow_modules(allow_modules());
3773 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax()); 3793 reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax());
3774 reusable_preparser_->set_allow_lazy(true); 3794 reusable_preparser_->set_allow_lazy(true);
3775 reusable_preparser_->set_allow_generators(allow_generators()); 3795 reusable_preparser_->set_allow_generators(allow_generators());
3776 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions()); 3796 reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions());
3777 reusable_preparser_->set_allow_harmony_numeric_literals( 3797 reusable_preparser_->set_allow_harmony_numeric_literals(
3778 allow_harmony_numeric_literals()); 3798 allow_harmony_numeric_literals());
3779 reusable_preparser_->set_allow_classes(allow_classes()); 3799 reusable_preparser_->set_allow_classes(allow_classes());
3780 } 3800 }
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after
4802 } 4822 }
4803 return !parser.failed(); 4823 return !parser.failed();
4804 } 4824 }
4805 4825
4806 4826
4807 bool Parser::Parse() { 4827 bool Parser::Parse() {
4808 DCHECK(info()->function() == NULL); 4828 DCHECK(info()->function() == NULL);
4809 FunctionLiteral* result = NULL; 4829 FunctionLiteral* result = NULL;
4810 ast_value_factory_ = info()->ast_value_factory(); 4830 ast_value_factory_ = info()->ast_value_factory();
4811 if (ast_value_factory_ == NULL) { 4831 if (ast_value_factory_ == NULL) {
4812 ast_value_factory_ = 4832 ast_value_factory_ = new AstValueFactory(zone(), hash_seed_);
4813 new AstValueFactory(zone(), isolate()->heap()->HashSeed());
4814 } 4833 }
4815 if (allow_natives_syntax() || extension_ != NULL) { 4834 if (allow_natives_syntax() || extension_ != NULL) {
4816 // If intrinsics are allowed, the Parser cannot operate independent of the 4835 // If intrinsics are allowed, the Parser cannot operate independent of the
4817 // V8 heap because of Rumtime. Tell the string table to internalize strings 4836 // V8 heap because of Rumtime. Tell the string table to internalize strings
4818 // and values right after they're created. 4837 // and values right after they're created.
4819 ast_value_factory_->Internalize(isolate()); 4838 ast_value_factory_->Internalize(isolate());
4820 } 4839 }
4821 4840
4822 if (info()->is_lazy()) { 4841 if (info()->is_lazy()) {
4823 DCHECK(!info()->is_eval()); 4842 DCHECK(!info()->is_eval());
(...skipping 12 matching lines...) Expand all
4836 if (info()->ast_value_factory() == NULL) { 4855 if (info()->ast_value_factory() == NULL) {
4837 info()->SetAstValueFactory(ast_value_factory_); 4856 info()->SetAstValueFactory(ast_value_factory_);
4838 } 4857 }
4839 ast_value_factory_ = NULL; 4858 ast_value_factory_ = NULL;
4840 4859
4841 InternalizeUseCounts(); 4860 InternalizeUseCounts();
4842 4861
4843 return (result != NULL); 4862 return (result != NULL);
4844 } 4863 }
4845 4864
4865
4866 void Parser::ParseOnBackground() {
4867 HistogramTimerScope preparse_scope(isolate()->counters()->background_parse());
4868 DCHECK(info()->function() == NULL);
4869 FunctionLiteral* result = NULL;
4870 ast_value_factory_ = info()->ast_value_factory();
4871 if (ast_value_factory_ == NULL) {
4872 ast_value_factory_ = new AstValueFactory(zone(), hash_seed_);
4873 }
4874 fni_ = new (zone()) FuncNameInferrer(ast_value_factory_, zone());
4875
4876 CompleteParserRecorder recorder;
4877 if (compile_options() == ScriptCompiler::kProduceParserCache) {
4878 log_ = &recorder;
4879 }
4880
4881 DCHECK(info()->source_stream() != NULL);
4882 ExternalStreamingStream stream(info()->source_stream());
4883 scanner_.Initialize(&stream);
4884 DCHECK(info()->context().is_null() || info()->context()->IsNativeContext());
4885
4886 Scope* scope = NULL;
4887 Scope* ad_hoc_eval_scope = NULL;
4888 result = DoParseProgramInner(info(), &scope, &ad_hoc_eval_scope);
4889
4890 scope->set_end_position(scanner()->location().end_pos);
4891 if (ad_hoc_eval_scope != NULL) {
4892 ad_hoc_eval_scope->set_end_position(scanner()->location().end_pos);
4893 }
4894
4895 if (info()->ast_value_factory() == NULL) {
4896 info()->SetAstValueFactory(ast_value_factory_);
4897 }
4898
4899 info()->SetFunction(result);
4900
4901 if (compile_options() == ScriptCompiler::kProduceParserCache) {
4902 if (result != NULL) *info_->cached_data() = recorder.GetScriptData();
4903 log_ = NULL;
4904 }
4905 }
4846 } } // namespace v8::internal 4906 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698