| 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 target_stack_(NULL), | 751 target_stack_(NULL), |
| 752 cached_parse_data_(NULL), | 752 cached_parse_data_(NULL), |
| 753 ast_value_factory_(info->ast_value_factory()), | 753 ast_value_factory_(info->ast_value_factory()), |
| 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 total_preparse_skipped_(0), | 759 total_preparse_skipped_(0), |
| 760 pre_parse_timer_(NULL) { | 760 pre_parse_timer_(NULL) { |
| 761 DCHECK(!script_.is_null()); | 761 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
| 762 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 762 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 763 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 763 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
| 764 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 764 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 765 set_allow_lazy(false); // Must be explicitly enabled. | 765 set_allow_lazy(false); // Must be explicitly enabled. |
| 766 set_allow_generators(FLAG_harmony_generators); | 766 set_allow_generators(FLAG_harmony_generators); |
| 767 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 767 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
| 768 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 768 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 769 set_allow_classes(FLAG_harmony_classes); | 769 set_allow_classes(FLAG_harmony_classes); |
| 770 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 770 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 771 ++feature) { | 771 ++feature) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 796 CompleteParserRecorder recorder; | 796 CompleteParserRecorder recorder; |
| 797 | 797 |
| 798 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 798 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 799 log_ = &recorder; | 799 log_ = &recorder; |
| 800 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) { | 800 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) { |
| 801 cached_parse_data_->Initialize(); | 801 cached_parse_data_->Initialize(); |
| 802 } | 802 } |
| 803 | 803 |
| 804 source = String::Flatten(source); | 804 source = String::Flatten(source); |
| 805 FunctionLiteral* result; | 805 FunctionLiteral* result; |
| 806 |
| 807 Scope* top_scope = NULL; |
| 808 Scope* ad_hoc_eval_scope = NULL; |
| 806 if (source->IsExternalTwoByteString()) { | 809 if (source->IsExternalTwoByteString()) { |
| 807 // Notice that the stream is destroyed at the end of the branch block. | 810 // Notice that the stream is destroyed at the end of the branch block. |
| 808 // The last line of the blocks can't be moved outside, even though they're | 811 // The last line of the blocks can't be moved outside, even though they're |
| 809 // identical calls. | 812 // identical calls. |
| 810 ExternalTwoByteStringUtf16CharacterStream stream( | 813 ExternalTwoByteStringUtf16CharacterStream stream( |
| 811 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 814 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
| 812 scanner_.Initialize(&stream); | 815 scanner_.Initialize(&stream); |
| 813 result = DoParseProgram(info(), source); | 816 result = DoParseProgram(info(), &top_scope, &ad_hoc_eval_scope); |
| 814 } else { | 817 } else { |
| 815 GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 818 GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 816 scanner_.Initialize(&stream); | 819 scanner_.Initialize(&stream); |
| 817 result = DoParseProgram(info(), source); | 820 result = DoParseProgram(info(), &top_scope, &ad_hoc_eval_scope); |
| 821 } |
| 822 top_scope->set_end_position(source->length()); |
| 823 if (ad_hoc_eval_scope != NULL) { |
| 824 ad_hoc_eval_scope->set_end_position(source->length()); |
| 818 } | 825 } |
| 819 HandleSourceURLComments(); | 826 HandleSourceURLComments(); |
| 820 | 827 |
| 821 if (FLAG_trace_parse && result != NULL) { | 828 if (FLAG_trace_parse && result != NULL) { |
| 822 double ms = timer.Elapsed().InMillisecondsF(); | 829 double ms = timer.Elapsed().InMillisecondsF(); |
| 823 if (info()->is_eval()) { | 830 if (info()->is_eval()) { |
| 824 PrintF("[parsing eval"); | 831 PrintF("[parsing eval"); |
| 825 } else if (info()->script()->name()->IsString()) { | 832 } else if (info()->script()->name()->IsString()) { |
| 826 String* name = String::cast(info()->script()->name()); | 833 String* name = String::cast(info()->script()->name()); |
| 827 SmartArrayPointer<char> name_chars = name->ToCString(); | 834 SmartArrayPointer<char> name_chars = name->ToCString(); |
| 828 PrintF("[parsing script: %s", name_chars.get()); | 835 PrintF("[parsing script: %s", name_chars.get()); |
| 829 } else { | 836 } else { |
| 830 PrintF("[parsing script"); | 837 PrintF("[parsing script"); |
| 831 } | 838 } |
| 832 PrintF(" - took %0.3f ms]\n", ms); | 839 PrintF(" - took %0.3f ms]\n", ms); |
| 833 } | 840 } |
| 834 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 841 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 835 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 842 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 836 log_ = NULL; | 843 log_ = NULL; |
| 837 } | 844 } |
| 838 return result; | 845 return result; |
| 839 } | 846 } |
| 840 | 847 |
| 841 | 848 |
| 842 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, | 849 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope, |
| 843 Handle<String> source) { | 850 Scope** ad_hod_eval_scope) { |
| 844 DCHECK(scope_ == NULL); | 851 DCHECK(scope_ == NULL); |
| 845 DCHECK(target_stack_ == NULL); | 852 DCHECK(target_stack_ == NULL); |
| 846 | 853 |
| 847 FunctionLiteral* result = NULL; | 854 FunctionLiteral* result = NULL; |
| 848 { Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 855 { |
| 849 info->SetGlobalScope(scope); | 856 *scope = NewScope(scope_, GLOBAL_SCOPE); |
| 857 info->SetGlobalScope(*scope); |
| 850 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 858 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
| 851 scope = Scope::DeserializeScopeChain(*info->context(), scope, zone()); | 859 *scope = Scope::DeserializeScopeChain(*info->context(), *scope, zone()); |
| 852 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 860 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
| 853 // means the Parser cannot operate independent of the V8 heap. Tell the | 861 // means the Parser cannot operate independent of the V8 heap. Tell the |
| 854 // string table to internalize strings and values right after they're | 862 // string table to internalize strings and values right after they're |
| 855 // created. | 863 // created. |
| 856 ast_value_factory_->Internalize(isolate()); | 864 ast_value_factory_->Internalize(isolate()); |
| 857 } | 865 } |
| 858 original_scope_ = scope; | 866 original_scope_ = *scope; |
| 859 if (info->is_eval()) { | 867 if (info->is_eval()) { |
| 860 if (!scope->is_global_scope() || info->strict_mode() == STRICT) { | 868 if (!(*scope)->is_global_scope() || info->strict_mode() == STRICT) { |
| 861 scope = NewScope(scope, EVAL_SCOPE); | 869 *scope = NewScope(*scope, EVAL_SCOPE); |
| 862 } | 870 } |
| 863 } else if (info->is_global()) { | 871 } else if (info->is_global()) { |
| 864 scope = NewScope(scope, GLOBAL_SCOPE); | 872 *scope = NewScope(*scope, GLOBAL_SCOPE); |
| 865 } | 873 } |
| 866 scope->set_start_position(0); | 874 (*scope)->set_start_position(0); |
| 867 scope->set_end_position(source->length()); | 875 // End position will be set by the caller. |
| 868 | 876 |
| 869 // Compute the parsing mode. | 877 // Compute the parsing mode. |
| 870 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 878 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
| 871 if (allow_natives_syntax() || | 879 if (allow_natives_syntax() || extension_ != NULL || |
| 872 extension_ != NULL || | 880 (*scope)->is_eval_scope()) { |
| 873 scope->is_eval_scope()) { | |
| 874 mode = PARSE_EAGERLY; | 881 mode = PARSE_EAGERLY; |
| 875 } | 882 } |
| 876 ParsingModeScope parsing_mode(this, mode); | 883 ParsingModeScope parsing_mode(this, mode); |
| 877 | 884 |
| 878 // Enters 'scope'. | 885 // Enters 'scope'. |
| 879 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 886 FunctionState function_state(&function_state_, &scope_, *scope, zone(), |
| 880 ast_value_factory_, info->ast_node_id_gen()); | 887 ast_value_factory_, info->ast_node_id_gen()); |
| 881 | 888 |
| 882 scope_->SetStrictMode(info->strict_mode()); | 889 scope_->SetStrictMode(info->strict_mode()); |
| 883 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 890 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 884 bool ok = true; | 891 bool ok = true; |
| 885 int beg_pos = scanner()->location().beg_pos; | 892 int beg_pos = scanner()->location().beg_pos; |
| 886 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 893 ParseSourceElements(body, Token::EOS, info->is_eval(), true, |
| 894 ad_hod_eval_scope, &ok); |
| 887 | 895 |
| 888 if (ok && strict_mode() == STRICT) { | 896 if (ok && strict_mode() == STRICT) { |
| 889 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 897 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
| 890 } | 898 } |
| 891 | 899 |
| 892 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { | 900 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { |
| 893 CheckConflictingVarDeclarations(scope_, &ok); | 901 CheckConflictingVarDeclarations(scope_, &ok); |
| 894 } | 902 } |
| 895 | 903 |
| 896 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 904 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1031 |
| 1024 if (result != NULL) { | 1032 if (result != NULL) { |
| 1025 Handle<String> inferred_name(shared_info->inferred_name()); | 1033 Handle<String> inferred_name(shared_info->inferred_name()); |
| 1026 result->set_inferred_name(inferred_name); | 1034 result->set_inferred_name(inferred_name); |
| 1027 } | 1035 } |
| 1028 return result; | 1036 return result; |
| 1029 } | 1037 } |
| 1030 | 1038 |
| 1031 | 1039 |
| 1032 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 1040 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
| 1033 int end_token, | 1041 int end_token, bool is_eval, bool is_global, |
| 1034 bool is_eval, | 1042 Scope** ad_hod_eval_scope, bool* ok) { |
| 1035 bool is_global, | |
| 1036 bool* ok) { | |
| 1037 // SourceElements :: | 1043 // SourceElements :: |
| 1038 // (ModuleElement)* <end_token> | 1044 // (ModuleElement)* <end_token> |
| 1039 | 1045 |
| 1040 // Allocate a target stack to use for this set of source | 1046 // Allocate a target stack to use for this set of source |
| 1041 // elements. This way, all scripts and functions get their own | 1047 // elements. This way, all scripts and functions get their own |
| 1042 // target stack thus avoiding illegal breaks and continues across | 1048 // target stack thus avoiding illegal breaks and continues across |
| 1043 // functions. | 1049 // functions. |
| 1044 TargetScope scope(&this->target_stack_); | 1050 TargetScope scope(&this->target_stack_); |
| 1045 | 1051 |
| 1046 DCHECK(processor != NULL); | 1052 DCHECK(processor != NULL); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 // as specified in ES5 10.4.2(3). The correct fix would be to always | 1088 // as specified in ES5 10.4.2(3). The correct fix would be to always |
| 1083 // add this scope in DoParseProgram(), but that requires adaptations | 1089 // add this scope in DoParseProgram(), but that requires adaptations |
| 1084 // all over the code base, so we go with a quick-fix for now. | 1090 // all over the code base, so we go with a quick-fix for now. |
| 1085 // In the same manner, we have to patch the parsing mode. | 1091 // In the same manner, we have to patch the parsing mode. |
| 1086 if (is_eval && !scope_->is_eval_scope()) { | 1092 if (is_eval && !scope_->is_eval_scope()) { |
| 1087 DCHECK(scope_->is_global_scope()); | 1093 DCHECK(scope_->is_global_scope()); |
| 1088 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 1094 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
| 1089 scope->set_start_position(scope_->start_position()); | 1095 scope->set_start_position(scope_->start_position()); |
| 1090 scope->set_end_position(scope_->end_position()); | 1096 scope->set_end_position(scope_->end_position()); |
| 1091 scope_ = scope; | 1097 scope_ = scope; |
| 1098 if (ad_hod_eval_scope != NULL) { |
| 1099 // Caller will correct the positions of the ad hoc eval scope. |
| 1100 *ad_hod_eval_scope = scope; |
| 1101 } |
| 1092 mode_ = PARSE_EAGERLY; | 1102 mode_ = PARSE_EAGERLY; |
| 1093 } | 1103 } |
| 1094 scope_->SetStrictMode(STRICT); | 1104 scope_->SetStrictMode(STRICT); |
| 1095 // "use strict" is the only directive for now. | 1105 // "use strict" is the only directive for now. |
| 1096 directive_prologue = false; | 1106 directive_prologue = false; |
| 1097 } else if (literal->raw_value()->AsString() == | 1107 } else if (literal->raw_value()->AsString() == |
| 1098 ast_value_factory_->use_asm_string() && | 1108 ast_value_factory_->use_asm_string() && |
| 1099 token_loc.end_pos - token_loc.beg_pos == | 1109 token_loc.end_pos - token_loc.beg_pos == |
| 1100 ast_value_factory_->use_asm_string()->length() + 2) { | 1110 ast_value_factory_->use_asm_string()->length() + 2) { |
| 1101 // Store the usage count; The actual use counter on the isolate is | 1111 // Store the usage count; The actual use counter on the isolate is |
| (...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3728 Assignment* assignment = factory()->NewAssignment( | 3738 Assignment* assignment = factory()->NewAssignment( |
| 3729 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); | 3739 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); |
| 3730 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3740 VariableProxy* get_proxy = factory()->NewVariableProxy( |
| 3731 function_state_->generator_object_variable()); | 3741 function_state_->generator_object_variable()); |
| 3732 Yield* yield = factory()->NewYield( | 3742 Yield* yield = factory()->NewYield( |
| 3733 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); | 3743 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); |
| 3734 body->Add(factory()->NewExpressionStatement( | 3744 body->Add(factory()->NewExpressionStatement( |
| 3735 yield, RelocInfo::kNoPosition), zone()); | 3745 yield, RelocInfo::kNoPosition), zone()); |
| 3736 } | 3746 } |
| 3737 | 3747 |
| 3738 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); | 3748 ParseSourceElements(body, Token::RBRACE, false, false, NULL, CHECK_OK); |
| 3739 | 3749 |
| 3740 if (is_generator) { | 3750 if (is_generator) { |
| 3741 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3751 VariableProxy* get_proxy = factory()->NewVariableProxy( |
| 3742 function_state_->generator_object_variable()); | 3752 function_state_->generator_object_variable()); |
| 3743 Expression* undefined = | 3753 Expression* undefined = |
| 3744 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); | 3754 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
| 3745 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, | 3755 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, |
| 3746 RelocInfo::kNoPosition); | 3756 RelocInfo::kNoPosition); |
| 3747 body->Add(factory()->NewExpressionStatement( | 3757 body->Add(factory()->NewExpressionStatement( |
| 3748 yield, RelocInfo::kNoPosition), zone()); | 3758 yield, RelocInfo::kNoPosition), zone()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3930 Handle<String> source_mapping_url = | 3940 Handle<String> source_mapping_url = |
| 3931 scanner_.source_mapping_url()->Internalize(isolate()); | 3941 scanner_.source_mapping_url()->Internalize(isolate()); |
| 3932 info_->script()->set_source_mapping_url(*source_mapping_url); | 3942 info_->script()->set_source_mapping_url(*source_mapping_url); |
| 3933 } | 3943 } |
| 3934 } | 3944 } |
| 3935 | 3945 |
| 3936 | 3946 |
| 3937 void Parser::ThrowPendingError() { | 3947 void Parser::ThrowPendingError() { |
| 3938 DCHECK(ast_value_factory_->IsInternalized()); | 3948 DCHECK(ast_value_factory_->IsInternalized()); |
| 3939 if (has_pending_error_) { | 3949 if (has_pending_error_) { |
| 3940 MessageLocation location(script_, | 3950 MessageLocation location(info()->script(), pending_error_location_.beg_pos, |
| 3941 pending_error_location_.beg_pos, | |
| 3942 pending_error_location_.end_pos); | 3951 pending_error_location_.end_pos); |
| 3943 Factory* factory = isolate()->factory(); | 3952 Factory* factory = isolate()->factory(); |
| 3944 bool has_arg = | 3953 bool has_arg = |
| 3945 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; | 3954 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; |
| 3946 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); | 3955 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); |
| 3947 if (pending_error_arg_ != NULL) { | 3956 if (pending_error_arg_ != NULL) { |
| 3948 Handle<String> arg_string = pending_error_arg_->string(); | 3957 Handle<String> arg_string = pending_error_arg_->string(); |
| 3949 elements->set(0, *arg_string); | 3958 elements->set(0, *arg_string); |
| 3950 } else if (pending_error_char_arg_ != NULL) { | 3959 } else if (pending_error_char_arg_ != NULL) { |
| 3951 Handle<String> arg_string = | 3960 Handle<String> arg_string = |
| 3952 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) | 3961 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) |
| 3953 .ToHandleChecked(); | 3962 .ToHandleChecked(); |
| 3954 elements->set(0, *arg_string); | 3963 elements->set(0, *arg_string); |
| 3955 } | 3964 } |
| 3956 isolate()->debug()->OnCompileError(script_); | 3965 isolate()->debug()->OnCompileError(info()->script()); |
| 3957 | 3966 |
| 3958 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 3967 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
| 3959 Handle<Object> error; | 3968 Handle<Object> error; |
| 3960 MaybeHandle<Object> maybe_error = | 3969 MaybeHandle<Object> maybe_error = |
| 3961 pending_error_is_reference_error_ | 3970 pending_error_is_reference_error_ |
| 3962 ? factory->NewReferenceError(pending_error_message_, array) | 3971 ? factory->NewReferenceError(pending_error_message_, array) |
| 3963 : factory->NewSyntaxError(pending_error_message_, array); | 3972 : factory->NewSyntaxError(pending_error_message_, array); |
| 3964 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location); | 3973 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location); |
| 3965 } | 3974 } |
| 3966 } | 3975 } |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4849 Internalize(); | 4858 Internalize(); |
| 4850 DCHECK(ast_value_factory_->IsInternalized()); | 4859 DCHECK(ast_value_factory_->IsInternalized()); |
| 4851 // info takes ownership of ast_value_factory_. | 4860 // info takes ownership of ast_value_factory_. |
| 4852 if (info()->ast_value_factory() == NULL) { | 4861 if (info()->ast_value_factory() == NULL) { |
| 4853 info()->SetAstValueFactory(ast_value_factory_); | 4862 info()->SetAstValueFactory(ast_value_factory_); |
| 4854 } | 4863 } |
| 4855 ast_value_factory_ = NULL; | 4864 ast_value_factory_ = NULL; |
| 4856 return (result != NULL); | 4865 return (result != NULL); |
| 4857 } | 4866 } |
| 4858 | 4867 |
| 4868 |
| 4869 void Parser::ParseOnBackground() { |
| 4870 DCHECK(info()->function() == NULL); |
| 4871 FunctionLiteral* result = NULL; |
| 4872 fni_ = new (zone()) FuncNameInferrer(ast_value_factory_, zone()); |
| 4873 |
| 4874 CompleteParserRecorder recorder; |
| 4875 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4876 log_ = &recorder; |
| 4877 } |
| 4878 |
| 4879 DCHECK(info()->source_stream() != NULL); |
| 4880 ExternalStreamingStream stream(info()->source_stream(), |
| 4881 info()->source_stream_encoding()); |
| 4882 scanner_.Initialize(&stream); |
| 4883 DCHECK(info()->context().is_null() || info()->context()->IsNativeContext()); |
| 4884 |
| 4885 // When streaming, we don't know the length of the source until we have parsed |
| 4886 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
| 4887 // we have decoded it anyway even if we knew the raw data length (which we |
| 4888 // don't). We work around this by storing all the scopes which need their end |
| 4889 // position set at the end of the script (the top scope and possible eval |
| 4890 // scopes) and set their end position after we know the script length. |
| 4891 Scope* top_scope = NULL; |
| 4892 Scope* ad_hoc_eval_scope = NULL; |
| 4893 result = DoParseProgram(info(), &top_scope, &ad_hoc_eval_scope); |
| 4894 |
| 4895 top_scope->set_end_position(scanner()->location().end_pos); |
| 4896 if (ad_hoc_eval_scope != NULL) { |
| 4897 ad_hoc_eval_scope->set_end_position(scanner()->location().end_pos); |
| 4898 } |
| 4899 |
| 4900 if (info()->ast_value_factory() == NULL) { |
| 4901 info()->SetAstValueFactory(ast_value_factory_); |
| 4902 } |
| 4903 info()->SetFunction(result); |
| 4904 |
| 4905 // We cannot internalize on a background thread; a foreground task will take |
| 4906 // care of calling Parser::Internalize just before compilation. |
| 4907 |
| 4908 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4909 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 4910 log_ = NULL; |
| 4911 } |
| 4912 } |
| 4859 } } // namespace v8::internal | 4913 } } // namespace v8::internal |
| OLD | NEW |