| 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" |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 target_stack_(NULL), | 750 target_stack_(NULL), |
| 752 cached_parse_data_(NULL), | 751 cached_parse_data_(NULL), |
| 753 ast_value_factory_(info->ast_value_factory()), | 752 ast_value_factory_(info->ast_value_factory()), |
| 754 info_(info), | 753 info_(info), |
| 755 has_pending_error_(false), | 754 has_pending_error_(false), |
| 756 pending_error_message_(NULL), | 755 pending_error_message_(NULL), |
| 757 pending_error_arg_(NULL), | 756 pending_error_arg_(NULL), |
| 758 pending_error_char_arg_(NULL), | 757 pending_error_char_arg_(NULL), |
| 759 total_preparse_skipped_(0), | 758 total_preparse_skipped_(0), |
| 760 pre_parse_timer_(NULL) { | 759 pre_parse_timer_(NULL) { |
| 761 DCHECK(!script_.is_null()); | 760 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
| 762 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 761 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 763 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 762 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
| 764 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 763 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
| 765 set_allow_lazy(false); // Must be explicitly enabled. | 764 set_allow_lazy(false); // Must be explicitly enabled. |
| 766 set_allow_generators(FLAG_harmony_generators); | 765 set_allow_generators(FLAG_harmony_generators); |
| 767 set_allow_arrow_functions(FLAG_harmony_arrow_functions); | 766 set_allow_arrow_functions(FLAG_harmony_arrow_functions); |
| 768 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 767 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 769 set_allow_classes(FLAG_harmony_classes); | 768 set_allow_classes(FLAG_harmony_classes); |
| 770 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 769 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 771 ++feature) { | 770 ++feature) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 796 CompleteParserRecorder recorder; | 795 CompleteParserRecorder recorder; |
| 797 | 796 |
| 798 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 797 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 799 log_ = &recorder; | 798 log_ = &recorder; |
| 800 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) { | 799 } else if (compile_options() == ScriptCompiler::kConsumeParserCache) { |
| 801 cached_parse_data_->Initialize(); | 800 cached_parse_data_->Initialize(); |
| 802 } | 801 } |
| 803 | 802 |
| 804 source = String::Flatten(source); | 803 source = String::Flatten(source); |
| 805 FunctionLiteral* result; | 804 FunctionLiteral* result; |
| 805 |
| 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()); | |
| 868 | 875 |
| 869 // Compute the parsing mode. | 876 // Compute the parsing mode. |
| 870 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 877 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
| 871 if (allow_natives_syntax() || | 878 if (allow_natives_syntax() || extension_ != NULL || |
| 872 extension_ != NULL || | 879 (*scope)->is_eval_scope()) { |
| 873 scope->is_eval_scope()) { | |
| 874 mode = PARSE_EAGERLY; | 880 mode = PARSE_EAGERLY; |
| 875 } | 881 } |
| 876 ParsingModeScope parsing_mode(this, mode); | 882 ParsingModeScope parsing_mode(this, mode); |
| 877 | 883 |
| 878 // Enters 'scope'. | 884 // Enters 'scope'. |
| 879 FunctionState function_state(&function_state_, &scope_, scope, zone(), | 885 FunctionState function_state(&function_state_, &scope_, *scope, zone(), |
| 880 ast_value_factory_, info->ast_node_id_gen()); | 886 ast_value_factory_, info->ast_node_id_gen()); |
| 881 | 887 |
| 882 scope_->SetStrictMode(info->strict_mode()); | 888 scope_->SetStrictMode(info->strict_mode()); |
| 883 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 889 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 884 bool ok = true; | 890 bool ok = true; |
| 885 int beg_pos = scanner()->location().beg_pos; | 891 int beg_pos = scanner()->location().beg_pos; |
| 886 ParseSourceElements(body, Token::EOS, info->is_eval(), true, &ok); | 892 ParseSourceElements(body, Token::EOS, info->is_eval(), true, |
| 893 ad_hod_eval_scope, &ok); |
| 887 | 894 |
| 888 if (ok && strict_mode() == STRICT) { | 895 if (ok && strict_mode() == STRICT) { |
| 889 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); | 896 CheckOctalLiteral(beg_pos, scanner()->location().end_pos, &ok); |
| 890 } | 897 } |
| 891 | 898 |
| 892 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { | 899 if (ok && allow_harmony_scoping() && strict_mode() == STRICT) { |
| 893 CheckConflictingVarDeclarations(scope_, &ok); | 900 CheckConflictingVarDeclarations(scope_, &ok); |
| 894 } | 901 } |
| 895 | 902 |
| 896 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { | 903 if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1030 |
| 1024 if (result != NULL) { | 1031 if (result != NULL) { |
| 1025 Handle<String> inferred_name(shared_info->inferred_name()); | 1032 Handle<String> inferred_name(shared_info->inferred_name()); |
| 1026 result->set_inferred_name(inferred_name); | 1033 result->set_inferred_name(inferred_name); |
| 1027 } | 1034 } |
| 1028 return result; | 1035 return result; |
| 1029 } | 1036 } |
| 1030 | 1037 |
| 1031 | 1038 |
| 1032 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 1039 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
| 1033 int end_token, | 1040 int end_token, bool is_eval, bool is_global, |
| 1034 bool is_eval, | 1041 Scope** ad_hod_eval_scope, bool* ok) { |
| 1035 bool is_global, | |
| 1036 bool* ok) { | |
| 1037 // SourceElements :: | 1042 // SourceElements :: |
| 1038 // (ModuleElement)* <end_token> | 1043 // (ModuleElement)* <end_token> |
| 1039 | 1044 |
| 1040 // Allocate a target stack to use for this set of source | 1045 // Allocate a target stack to use for this set of source |
| 1041 // elements. This way, all scripts and functions get their own | 1046 // elements. This way, all scripts and functions get their own |
| 1042 // target stack thus avoiding illegal breaks and continues across | 1047 // target stack thus avoiding illegal breaks and continues across |
| 1043 // functions. | 1048 // functions. |
| 1044 TargetScope scope(&this->target_stack_); | 1049 TargetScope scope(&this->target_stack_); |
| 1045 | 1050 |
| 1046 DCHECK(processor != NULL); | 1051 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 | 1087 // 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 | 1088 // add this scope in DoParseProgram(), but that requires adaptations |
| 1084 // all over the code base, so we go with a quick-fix for now. | 1089 // 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. | 1090 // In the same manner, we have to patch the parsing mode. |
| 1086 if (is_eval && !scope_->is_eval_scope()) { | 1091 if (is_eval && !scope_->is_eval_scope()) { |
| 1087 DCHECK(scope_->is_global_scope()); | 1092 DCHECK(scope_->is_global_scope()); |
| 1088 Scope* scope = NewScope(scope_, EVAL_SCOPE); | 1093 Scope* scope = NewScope(scope_, EVAL_SCOPE); |
| 1089 scope->set_start_position(scope_->start_position()); | 1094 scope->set_start_position(scope_->start_position()); |
| 1090 scope->set_end_position(scope_->end_position()); | 1095 scope->set_end_position(scope_->end_position()); |
| 1091 scope_ = scope; | 1096 scope_ = scope; |
| 1097 if (ad_hod_eval_scope != NULL) { |
| 1098 *ad_hod_eval_scope = scope; |
| 1099 } |
| 1092 mode_ = PARSE_EAGERLY; | 1100 mode_ = PARSE_EAGERLY; |
| 1093 } | 1101 } |
| 1094 scope_->SetStrictMode(STRICT); | 1102 scope_->SetStrictMode(STRICT); |
| 1095 // "use strict" is the only directive for now. | 1103 // "use strict" is the only directive for now. |
| 1096 directive_prologue = false; | 1104 directive_prologue = false; |
| 1097 } else if (literal->raw_value()->AsString() == | 1105 } else if (literal->raw_value()->AsString() == |
| 1098 ast_value_factory_->use_asm_string() && | 1106 ast_value_factory_->use_asm_string() && |
| 1099 token_loc.end_pos - token_loc.beg_pos == | 1107 token_loc.end_pos - token_loc.beg_pos == |
| 1100 ast_value_factory_->use_asm_string()->length() + 2) { | 1108 ast_value_factory_->use_asm_string()->length() + 2) { |
| 1101 // Store the usage count; The actual use counter on the isolate is | 1109 // 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( | 3736 Assignment* assignment = factory()->NewAssignment( |
| 3729 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); | 3737 Token::INIT_VAR, init_proxy, allocation, RelocInfo::kNoPosition); |
| 3730 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3738 VariableProxy* get_proxy = factory()->NewVariableProxy( |
| 3731 function_state_->generator_object_variable()); | 3739 function_state_->generator_object_variable()); |
| 3732 Yield* yield = factory()->NewYield( | 3740 Yield* yield = factory()->NewYield( |
| 3733 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); | 3741 get_proxy, assignment, Yield::kInitial, RelocInfo::kNoPosition); |
| 3734 body->Add(factory()->NewExpressionStatement( | 3742 body->Add(factory()->NewExpressionStatement( |
| 3735 yield, RelocInfo::kNoPosition), zone()); | 3743 yield, RelocInfo::kNoPosition), zone()); |
| 3736 } | 3744 } |
| 3737 | 3745 |
| 3738 ParseSourceElements(body, Token::RBRACE, false, false, CHECK_OK); | 3746 ParseSourceElements(body, Token::RBRACE, false, false, NULL, CHECK_OK); |
| 3739 | 3747 |
| 3740 if (is_generator) { | 3748 if (is_generator) { |
| 3741 VariableProxy* get_proxy = factory()->NewVariableProxy( | 3749 VariableProxy* get_proxy = factory()->NewVariableProxy( |
| 3742 function_state_->generator_object_variable()); | 3750 function_state_->generator_object_variable()); |
| 3743 Expression* undefined = | 3751 Expression* undefined = |
| 3744 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); | 3752 factory()->NewUndefinedLiteral(RelocInfo::kNoPosition); |
| 3745 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, | 3753 Yield* yield = factory()->NewYield(get_proxy, undefined, Yield::kFinal, |
| 3746 RelocInfo::kNoPosition); | 3754 RelocInfo::kNoPosition); |
| 3747 body->Add(factory()->NewExpressionStatement( | 3755 body->Add(factory()->NewExpressionStatement( |
| 3748 yield, RelocInfo::kNoPosition), zone()); | 3756 yield, RelocInfo::kNoPosition), zone()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3930 Handle<String> source_mapping_url = | 3938 Handle<String> source_mapping_url = |
| 3931 scanner_.source_mapping_url()->Internalize(isolate()); | 3939 scanner_.source_mapping_url()->Internalize(isolate()); |
| 3932 info_->script()->set_source_mapping_url(*source_mapping_url); | 3940 info_->script()->set_source_mapping_url(*source_mapping_url); |
| 3933 } | 3941 } |
| 3934 } | 3942 } |
| 3935 | 3943 |
| 3936 | 3944 |
| 3937 void Parser::ThrowPendingError() { | 3945 void Parser::ThrowPendingError() { |
| 3938 DCHECK(ast_value_factory_->IsInternalized()); | 3946 DCHECK(ast_value_factory_->IsInternalized()); |
| 3939 if (has_pending_error_) { | 3947 if (has_pending_error_) { |
| 3940 MessageLocation location(script_, | 3948 MessageLocation location(info()->script(), pending_error_location_.beg_pos, |
| 3941 pending_error_location_.beg_pos, | |
| 3942 pending_error_location_.end_pos); | 3949 pending_error_location_.end_pos); |
| 3943 Factory* factory = isolate()->factory(); | 3950 Factory* factory = isolate()->factory(); |
| 3944 bool has_arg = | 3951 bool has_arg = |
| 3945 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; | 3952 pending_error_arg_ != NULL || pending_error_char_arg_ != NULL; |
| 3946 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); | 3953 Handle<FixedArray> elements = factory->NewFixedArray(has_arg ? 1 : 0); |
| 3947 if (pending_error_arg_ != NULL) { | 3954 if (pending_error_arg_ != NULL) { |
| 3948 Handle<String> arg_string = pending_error_arg_->string(); | 3955 Handle<String> arg_string = pending_error_arg_->string(); |
| 3949 elements->set(0, *arg_string); | 3956 elements->set(0, *arg_string); |
| 3950 } else if (pending_error_char_arg_ != NULL) { | 3957 } else if (pending_error_char_arg_ != NULL) { |
| 3951 Handle<String> arg_string = | 3958 Handle<String> arg_string = |
| 3952 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) | 3959 factory->NewStringFromUtf8(CStrVector(pending_error_char_arg_)) |
| 3953 .ToHandleChecked(); | 3960 .ToHandleChecked(); |
| 3954 elements->set(0, *arg_string); | 3961 elements->set(0, *arg_string); |
| 3955 } | 3962 } |
| 3956 isolate()->debug()->OnCompileError(script_); | 3963 isolate()->debug()->OnCompileError(info()->script()); |
| 3957 | 3964 |
| 3958 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); | 3965 Handle<JSArray> array = factory->NewJSArrayWithElements(elements); |
| 3959 Handle<Object> error; | 3966 Handle<Object> error; |
| 3960 MaybeHandle<Object> maybe_error = | 3967 MaybeHandle<Object> maybe_error = |
| 3961 pending_error_is_reference_error_ | 3968 pending_error_is_reference_error_ |
| 3962 ? factory->NewReferenceError(pending_error_message_, array) | 3969 ? factory->NewReferenceError(pending_error_message_, array) |
| 3963 : factory->NewSyntaxError(pending_error_message_, array); | 3970 : factory->NewSyntaxError(pending_error_message_, array); |
| 3964 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location); | 3971 if (maybe_error.ToHandle(&error)) isolate()->Throw(*error, &location); |
| 3965 } | 3972 } |
| 3966 } | 3973 } |
| (...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4849 Internalize(); | 4856 Internalize(); |
| 4850 DCHECK(ast_value_factory_->IsInternalized()); | 4857 DCHECK(ast_value_factory_->IsInternalized()); |
| 4851 // info takes ownership of ast_value_factory_. | 4858 // info takes ownership of ast_value_factory_. |
| 4852 if (info()->ast_value_factory() == NULL) { | 4859 if (info()->ast_value_factory() == NULL) { |
| 4853 info()->SetAstValueFactory(ast_value_factory_); | 4860 info()->SetAstValueFactory(ast_value_factory_); |
| 4854 } | 4861 } |
| 4855 ast_value_factory_ = NULL; | 4862 ast_value_factory_ = NULL; |
| 4856 return (result != NULL); | 4863 return (result != NULL); |
| 4857 } | 4864 } |
| 4858 | 4865 |
| 4866 |
| 4867 void Parser::ParseOnBackground() { |
| 4868 DCHECK(info()->function() == NULL); |
| 4869 FunctionLiteral* result = NULL; |
| 4870 fni_ = new (zone()) FuncNameInferrer(ast_value_factory_, zone()); |
| 4871 |
| 4872 CompleteParserRecorder recorder; |
| 4873 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4874 log_ = &recorder; |
| 4875 } |
| 4876 |
| 4877 DCHECK(info()->source_stream() != NULL); |
| 4878 ExternalStreamingStream stream(info()->source_stream()); |
| 4879 scanner_.Initialize(&stream); |
| 4880 DCHECK(info()->context().is_null() || info()->context()->IsNativeContext()); |
| 4881 |
| 4882 // When streaming, we don't know the length of the source until we have parsed |
| 4883 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
| 4884 // we have decoded it anyway even if we knew the raw data length (which we |
| 4885 // don't). We work around this by storing all the scopes which need their end |
| 4886 // position set at the end of the script (the top scope and possible eval |
| 4887 // scopes) and set their end position after we know the script length. |
| 4888 Scope* top_scope = NULL; |
| 4889 Scope* ad_hoc_eval_scope = NULL; |
| 4890 result = DoParseProgram(info(), &top_scope, &ad_hoc_eval_scope); |
| 4891 |
| 4892 top_scope->set_end_position(scanner()->location().end_pos); |
| 4893 if (ad_hoc_eval_scope != NULL) { |
| 4894 ad_hoc_eval_scope->set_end_position(scanner()->location().end_pos); |
| 4895 } |
| 4896 |
| 4897 if (info()->ast_value_factory() == NULL) { |
| 4898 info()->SetAstValueFactory(ast_value_factory_); |
| 4899 } |
| 4900 info()->SetFunction(result); |
| 4901 |
| 4902 // We cannot internalize on a background thread; a foreground task will take |
| 4903 // care of calling Parser::Internalize just before compilation. |
| 4904 |
| 4905 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
| 4906 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
| 4907 log_ = NULL; |
| 4908 } |
| 4909 } |
| 4859 } } // namespace v8::internal | 4910 } } // namespace v8::internal |
| OLD | NEW |