| 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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| 11 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
| 12 #include "src/char-predicates-inl.h" | 12 #include "src/char-predicates-inl.h" |
| 13 #include "src/codegen.h" | 13 #include "src/codegen.h" |
| 14 #include "src/compiler.h" | 14 #include "src/compiler.h" |
| 15 #include "src/messages.h" | 15 #include "src/messages.h" |
| 16 #include "src/parser.h" | 16 #include "src/parser.h" |
| 17 #include "src/preparser.h" | 17 #include "src/preparser.h" |
| 18 #include "src/runtime/runtime.h" | 18 #include "src/runtime/runtime.h" |
| 19 #include "src/scanner-character-streams.h" | 19 #include "src/scanner-character-streams.h" |
| 20 #include "src/scopeinfo.h" | 20 #include "src/scopeinfo.h" |
| 21 #include "src/string-stream.h" | 21 #include "src/string-stream.h" |
| 22 | 22 |
| 23 namespace v8 { | 23 namespace v8 { |
| 24 namespace internal { | 24 namespace internal { |
| 25 | 25 |
| 26 ScriptData::ScriptData(const byte* data, int length) |
| 27 : owns_data_(false), rejected_(false), data_(data), length_(length) { |
| 28 if (!IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)) { |
| 29 byte* copy = NewArray<byte>(length); |
| 30 DCHECK(IsAligned(reinterpret_cast<intptr_t>(copy), kPointerAlignment)); |
| 31 CopyBytes(copy, data, length); |
| 32 data_ = copy; |
| 33 AcquireDataOwnership(); |
| 34 } |
| 35 } |
| 36 |
| 37 |
| 38 ParseInfo* ParseInfo::InitializeFromJSFunction(Handle<JSFunction> function) { |
| 39 Handle<SharedFunctionInfo> shared(function->shared()); |
| 40 InitializeFromSharedFunctionInfo(shared); |
| 41 set_closure(function); |
| 42 set_context(Handle<Context>(function->context())); |
| 43 return this; |
| 44 } |
| 45 |
| 46 |
| 47 ParseInfo* ParseInfo::InitializeFromSharedFunctionInfo( |
| 48 Handle<SharedFunctionInfo> shared) { |
| 49 isolate_ = shared->GetIsolate(); |
| 50 |
| 51 set_lazy(); |
| 52 set_this_has_uses(); |
| 53 set_hash_seed(isolate_->heap()->HashSeed()); |
| 54 set_stack_limit(isolate_->stack_guard()->real_climit()); |
| 55 set_unicode_cache(isolate_->unicode_cache()); |
| 56 set_language_mode(shared->language_mode()); |
| 57 set_shared_info(shared); |
| 58 |
| 59 Handle<Script> script(Script::cast(shared->script())); |
| 60 set_script(script); |
| 61 if (!script.is_null() && script->type()->value() == Script::TYPE_NATIVE) { |
| 62 set_native(); |
| 63 } |
| 64 return this; |
| 65 } |
| 66 |
| 67 |
| 68 ParseInfo* ParseInfo::InitializeFromScript(Handle<Script> script) { |
| 69 isolate_ = script->GetIsolate(); |
| 70 |
| 71 set_this_has_uses(); |
| 72 set_hash_seed(isolate_->heap()->HashSeed()); |
| 73 set_stack_limit(isolate_->stack_guard()->real_climit()); |
| 74 set_unicode_cache(isolate_->unicode_cache()); |
| 75 set_script(script); |
| 76 |
| 77 if (script->type()->value() == Script::TYPE_NATIVE) { |
| 78 set_native(); |
| 79 } |
| 80 return this; |
| 81 } |
| 82 |
| 83 |
| 26 RegExpBuilder::RegExpBuilder(Zone* zone) | 84 RegExpBuilder::RegExpBuilder(Zone* zone) |
| 27 : zone_(zone), | 85 : zone_(zone), |
| 28 pending_empty_(false), | 86 pending_empty_(false), |
| 29 characters_(NULL), | 87 characters_(NULL), |
| 30 terms_(), | 88 terms_(), |
| 31 alternatives_() | 89 alternatives_() |
| 32 #ifdef DEBUG | 90 #ifdef DEBUG |
| 33 , last_added_(ADD_NONE) | 91 , last_added_(ADD_NONE) |
| 34 #endif | 92 #endif |
| 35 {} | 93 {} |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 unsigned ParseData::Version() { | 302 unsigned ParseData::Version() { |
| 245 return Data()[PreparseDataConstants::kVersionOffset]; | 303 return Data()[PreparseDataConstants::kVersionOffset]; |
| 246 } | 304 } |
| 247 | 305 |
| 248 | 306 |
| 249 int ParseData::FunctionsSize() { | 307 int ParseData::FunctionsSize() { |
| 250 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); | 308 return static_cast<int>(Data()[PreparseDataConstants::kFunctionsSizeOffset]); |
| 251 } | 309 } |
| 252 | 310 |
| 253 | 311 |
| 254 void Parser::SetCachedData(CompilationInfo* info) { | 312 void Parser::SetCachedData(ParseInfo* info) { |
| 255 if (compile_options_ == ScriptCompiler::kNoCompileOptions) { | 313 if (compile_options_ == ScriptCompiler::kNoCompileOptions) { |
| 256 cached_parse_data_ = NULL; | 314 cached_parse_data_ = NULL; |
| 257 } else { | 315 } else { |
| 258 DCHECK(info->cached_data() != NULL); | 316 DCHECK(info->cached_data() != NULL); |
| 259 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { | 317 if (compile_options_ == ScriptCompiler::kConsumeParserCache) { |
| 260 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); | 318 cached_parse_data_ = ParseData::FromCachedData(*info->cached_data()); |
| 261 } | 319 } |
| 262 } | 320 } |
| 263 } | 321 } |
| 264 | 322 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 | 830 |
| 773 | 831 |
| 774 ClassLiteral* ParserTraits::ParseClassLiteral( | 832 ClassLiteral* ParserTraits::ParseClassLiteral( |
| 775 const AstRawString* name, Scanner::Location class_name_location, | 833 const AstRawString* name, Scanner::Location class_name_location, |
| 776 bool name_is_strict_reserved, int pos, bool* ok) { | 834 bool name_is_strict_reserved, int pos, bool* ok) { |
| 777 return parser_->ParseClassLiteral(name, class_name_location, | 835 return parser_->ParseClassLiteral(name, class_name_location, |
| 778 name_is_strict_reserved, pos, ok); | 836 name_is_strict_reserved, pos, ok); |
| 779 } | 837 } |
| 780 | 838 |
| 781 | 839 |
| 782 Parser::Parser(CompilationInfo* info, uintptr_t stack_limit, uint32_t hash_seed, | 840 Parser::Parser(ParseInfo* info) |
| 783 UnicodeCache* unicode_cache) | 841 : ParserBase<ParserTraits>(info->zone(), &scanner_, info->stack_limit(), |
| 784 : ParserBase<ParserTraits>(info->zone(), &scanner_, stack_limit, | |
| 785 info->extension(), info->ast_value_factory(), | 842 info->extension(), info->ast_value_factory(), |
| 786 NULL, this), | 843 NULL, this), |
| 787 scanner_(unicode_cache), | 844 scanner_(info->unicode_cache()), |
| 788 reusable_preparser_(NULL), | 845 reusable_preparser_(NULL), |
| 789 original_scope_(NULL), | 846 original_scope_(NULL), |
| 790 target_stack_(NULL), | 847 target_stack_(NULL), |
| 791 compile_options_(info->compile_options()), | 848 compile_options_(info->compile_options()), |
| 792 cached_parse_data_(NULL), | 849 cached_parse_data_(NULL), |
| 793 parsing_lazy_arrow_parameters_(false), | 850 parsing_lazy_arrow_parameters_(false), |
| 794 total_preparse_skipped_(0), | 851 total_preparse_skipped_(0), |
| 795 pre_parse_timer_(NULL), | 852 pre_parse_timer_(NULL), |
| 796 parsing_on_main_thread_(true) { | 853 parsing_on_main_thread_(true) { |
| 797 // Even though we were passed CompilationInfo, we should not store it in | 854 // Even though we were passed ParseInfo, we should not store it in |
| 798 // Parser - this makes sure that Isolate is not accidentally accessed via | 855 // Parser - this makes sure that Isolate is not accidentally accessed via |
| 799 // CompilationInfo during background parsing. | 856 // ParseInfo during background parsing. |
| 800 DCHECK(!info->script().is_null() || info->source_stream() != NULL); | 857 DCHECK(!info->script().is_null() || info->source_stream() != NULL); |
| 801 set_allow_lazy(false); // Must be explicitly enabled. | 858 set_allow_lazy(info->allow_lazy_parsing()); |
| 802 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); | 859 set_allow_natives(FLAG_allow_natives_syntax || info->is_native()); |
| 803 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 860 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
| 804 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); | 861 set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules); |
| 805 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); | 862 set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions); |
| 806 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); | 863 set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals); |
| 807 set_allow_harmony_classes(FLAG_harmony_classes); | 864 set_allow_harmony_classes(FLAG_harmony_classes); |
| 808 set_allow_harmony_object_literals(FLAG_harmony_object_literals); | 865 set_allow_harmony_object_literals(FLAG_harmony_object_literals); |
| 809 set_allow_harmony_templates(FLAG_harmony_templates); | 866 set_allow_harmony_templates(FLAG_harmony_templates); |
| 810 set_allow_harmony_sloppy(FLAG_harmony_sloppy); | 867 set_allow_harmony_sloppy(FLAG_harmony_sloppy); |
| 811 set_allow_harmony_unicode(FLAG_harmony_unicode); | 868 set_allow_harmony_unicode(FLAG_harmony_unicode); |
| 812 set_allow_harmony_computed_property_names( | 869 set_allow_harmony_computed_property_names( |
| 813 FLAG_harmony_computed_property_names); | 870 FLAG_harmony_computed_property_names); |
| 814 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); | 871 set_allow_harmony_rest_params(FLAG_harmony_rest_parameters); |
| 815 set_allow_strong_mode(FLAG_strong_mode); | 872 set_allow_strong_mode(FLAG_strong_mode); |
| 816 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; | 873 for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount; |
| 817 ++feature) { | 874 ++feature) { |
| 818 use_counts_[feature] = 0; | 875 use_counts_[feature] = 0; |
| 819 } | 876 } |
| 820 if (info->ast_value_factory() == NULL) { | 877 if (info->ast_value_factory() == NULL) { |
| 821 // info takes ownership of AstValueFactory. | 878 // info takes ownership of AstValueFactory. |
| 822 info->SetAstValueFactory(new AstValueFactory(zone(), hash_seed)); | 879 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
| 880 info->set_ast_value_factory_owned(); |
| 823 ast_value_factory_ = info->ast_value_factory(); | 881 ast_value_factory_ = info->ast_value_factory(); |
| 824 } | 882 } |
| 825 } | 883 } |
| 826 | 884 |
| 827 | 885 |
| 828 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, CompilationInfo* info) { | 886 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
| 829 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 887 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
| 830 // see comment for HistogramTimerScope class. | 888 // see comment for HistogramTimerScope class. |
| 831 | 889 |
| 832 // It's OK to use the Isolate & counters here, since this function is only | 890 // It's OK to use the Isolate & counters here, since this function is only |
| 833 // called in the main thread. | 891 // called in the main thread. |
| 834 DCHECK(parsing_on_main_thread_); | 892 DCHECK(parsing_on_main_thread_); |
| 835 | 893 |
| 836 HistogramTimerScope timer_scope(isolate->counters()->parse(), true); | 894 HistogramTimerScope timer_scope(isolate->counters()->parse(), true); |
| 837 Handle<String> source(String::cast(info->script()->source())); | 895 Handle<String> source(String::cast(info->script()->source())); |
| 838 isolate->counters()->total_parse_size()->Increment(source->length()); | 896 isolate->counters()->total_parse_size()->Increment(source->length()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 PrintF(" - took %0.3f ms]\n", ms); | 947 PrintF(" - took %0.3f ms]\n", ms); |
| 890 } | 948 } |
| 891 if (produce_cached_parse_data()) { | 949 if (produce_cached_parse_data()) { |
| 892 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); | 950 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); |
| 893 log_ = NULL; | 951 log_ = NULL; |
| 894 } | 952 } |
| 895 return result; | 953 return result; |
| 896 } | 954 } |
| 897 | 955 |
| 898 | 956 |
| 899 FunctionLiteral* Parser::DoParseProgram(CompilationInfo* info, Scope** scope, | 957 FunctionLiteral* Parser::DoParseProgram(ParseInfo* info, Scope** scope, |
| 900 Scope** eval_scope) { | 958 Scope** eval_scope) { |
| 901 // Note that this function can be called from the main thread or from a | 959 // Note that this function can be called from the main thread or from a |
| 902 // background thread. We should not access anything Isolate / heap dependent | 960 // background thread. We should not access anything Isolate / heap dependent |
| 903 // via CompilationInfo, and also not pass it forward. | 961 // via ParseInfo, and also not pass it forward. |
| 904 DCHECK(scope_ == NULL); | 962 DCHECK(scope_ == NULL); |
| 905 DCHECK(target_stack_ == NULL); | 963 DCHECK(target_stack_ == NULL); |
| 906 | 964 |
| 907 FunctionLiteral* result = NULL; | 965 FunctionLiteral* result = NULL; |
| 908 { | 966 { |
| 909 *scope = NewScope(scope_, SCRIPT_SCOPE); | 967 *scope = NewScope(scope_, SCRIPT_SCOPE); |
| 910 info->SetScriptScope(*scope); | 968 info->set_script_scope(*scope); |
| 911 if (!info->context().is_null() && !info->context()->IsNativeContext()) { | 969 if (!info->context().is_null() && !info->context()->IsNativeContext()) { |
| 912 *scope = Scope::DeserializeScopeChain(info->isolate(), zone(), | 970 *scope = Scope::DeserializeScopeChain(info->isolate(), zone(), |
| 913 *info->context(), *scope); | 971 *info->context(), *scope); |
| 914 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this | 972 // The Scope is backed up by ScopeInfo (which is in the V8 heap); this |
| 915 // means the Parser cannot operate independent of the V8 heap. Tell the | 973 // means the Parser cannot operate independent of the V8 heap. Tell the |
| 916 // string table to internalize strings and values right after they're | 974 // string table to internalize strings and values right after they're |
| 917 // created. This kind of parsing can only be done in the main thread. | 975 // created. This kind of parsing can only be done in the main thread. |
| 918 DCHECK(parsing_on_main_thread_); | 976 DCHECK(parsing_on_main_thread_); |
| 919 ast_value_factory()->Internalize(info->isolate()); | 977 ast_value_factory()->Internalize(info->isolate()); |
| 920 } | 978 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 } | 1043 } |
| 986 } | 1044 } |
| 987 | 1045 |
| 988 // Make sure the target stack is empty. | 1046 // Make sure the target stack is empty. |
| 989 DCHECK(target_stack_ == NULL); | 1047 DCHECK(target_stack_ == NULL); |
| 990 | 1048 |
| 991 return result; | 1049 return result; |
| 992 } | 1050 } |
| 993 | 1051 |
| 994 | 1052 |
| 995 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, CompilationInfo* info) { | 1053 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info) { |
| 996 // It's OK to use the Isolate & counters here, since this function is only | 1054 // It's OK to use the Isolate & counters here, since this function is only |
| 997 // called in the main thread. | 1055 // called in the main thread. |
| 998 DCHECK(parsing_on_main_thread_); | 1056 DCHECK(parsing_on_main_thread_); |
| 999 HistogramTimerScope timer_scope(isolate->counters()->parse_lazy()); | 1057 HistogramTimerScope timer_scope(isolate->counters()->parse_lazy()); |
| 1000 Handle<String> source(String::cast(info->script()->source())); | 1058 Handle<String> source(String::cast(info->script()->source())); |
| 1001 isolate->counters()->total_parse_size()->Increment(source->length()); | 1059 isolate->counters()->total_parse_size()->Increment(source->length()); |
| 1002 base::ElapsedTimer timer; | 1060 base::ElapsedTimer timer; |
| 1003 if (FLAG_trace_parse) { | 1061 if (FLAG_trace_parse) { |
| 1004 timer.Start(); | 1062 timer.Start(); |
| 1005 } | 1063 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1023 | 1081 |
| 1024 if (FLAG_trace_parse && result != NULL) { | 1082 if (FLAG_trace_parse && result != NULL) { |
| 1025 double ms = timer.Elapsed().InMillisecondsF(); | 1083 double ms = timer.Elapsed().InMillisecondsF(); |
| 1026 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); | 1084 SmartArrayPointer<char> name_chars = result->debug_name()->ToCString(); |
| 1027 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); | 1085 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); |
| 1028 } | 1086 } |
| 1029 return result; | 1087 return result; |
| 1030 } | 1088 } |
| 1031 | 1089 |
| 1032 | 1090 |
| 1033 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, CompilationInfo* info, | 1091 FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info, |
| 1034 Utf16CharacterStream* source) { | 1092 Utf16CharacterStream* source) { |
| 1035 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 1093 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
| 1036 scanner_.Initialize(source); | 1094 scanner_.Initialize(source); |
| 1037 DCHECK(scope_ == NULL); | 1095 DCHECK(scope_ == NULL); |
| 1038 DCHECK(target_stack_ == NULL); | 1096 DCHECK(target_stack_ == NULL); |
| 1039 | 1097 |
| 1040 Handle<String> name(String::cast(shared_info->name())); | 1098 Handle<String> name(String::cast(shared_info->name())); |
| 1041 DCHECK(ast_value_factory()); | 1099 DCHECK(ast_value_factory()); |
| 1042 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 1100 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
| 1043 const AstRawString* raw_name = ast_value_factory()->GetString(name); | 1101 const AstRawString* raw_name = ast_value_factory()->GetString(name); |
| 1044 fni_->PushEnclosingName(raw_name); | 1102 fni_->PushEnclosingName(raw_name); |
| 1045 | 1103 |
| 1046 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1104 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1047 | 1105 |
| 1048 // Place holder for the result. | 1106 // Place holder for the result. |
| 1049 FunctionLiteral* result = NULL; | 1107 FunctionLiteral* result = NULL; |
| 1050 | 1108 |
| 1051 { | 1109 { |
| 1052 // Parse the function literal. | 1110 // Parse the function literal. |
| 1053 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 1111 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
| 1054 info->SetScriptScope(scope); | 1112 info->set_script_scope(scope); |
| 1055 if (!info->closure().is_null()) { | 1113 if (!info->closure().is_null()) { |
| 1056 // Ok to use Isolate here, since lazy function parsing is only done in the | 1114 // Ok to use Isolate here, since lazy function parsing is only done in the |
| 1057 // main thread. | 1115 // main thread. |
| 1058 DCHECK(parsing_on_main_thread_); | 1116 DCHECK(parsing_on_main_thread_); |
| 1059 scope = Scope::DeserializeScopeChain(isolate, zone(), | 1117 scope = Scope::DeserializeScopeChain(isolate, zone(), |
| 1060 info->closure()->context(), scope); | 1118 info->closure()->context(), scope); |
| 1061 } | 1119 } |
| 1062 original_scope_ = scope; | 1120 original_scope_ = scope; |
| 1063 AstNodeFactory function_factory(ast_value_factory()); | 1121 AstNodeFactory function_factory(ast_value_factory()); |
| 1064 FunctionState function_state(&function_state_, &scope_, scope, | 1122 FunctionState function_state(&function_state_, &scope_, scope, |
| (...skipping 4175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5240 result->tree = tree; | 5298 result->tree = tree; |
| 5241 int capture_count = parser.captures_started(); | 5299 int capture_count = parser.captures_started(); |
| 5242 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; | 5300 result->simple = tree->IsAtom() && parser.simple() && capture_count == 0; |
| 5243 result->contains_anchor = parser.contains_anchor(); | 5301 result->contains_anchor = parser.contains_anchor(); |
| 5244 result->capture_count = capture_count; | 5302 result->capture_count = capture_count; |
| 5245 } | 5303 } |
| 5246 return !parser.failed(); | 5304 return !parser.failed(); |
| 5247 } | 5305 } |
| 5248 | 5306 |
| 5249 | 5307 |
| 5250 bool Parser::ParseStatic(CompilationInfo* info, bool allow_lazy) { | 5308 bool Parser::ParseStatic(ParseInfo* info) { |
| 5251 Parser parser(info, info->isolate()->stack_guard()->real_climit(), | 5309 Parser parser(info); |
| 5252 info->isolate()->heap()->HashSeed(), | |
| 5253 info->isolate()->unicode_cache()); | |
| 5254 parser.set_allow_lazy(allow_lazy); | |
| 5255 if (parser.Parse(info)) { | 5310 if (parser.Parse(info)) { |
| 5256 info->SetLanguageMode(info->function()->language_mode()); | 5311 info->set_language_mode(info->function()->language_mode()); |
| 5257 return true; | 5312 return true; |
| 5258 } | 5313 } |
| 5259 return false; | 5314 return false; |
| 5260 } | 5315 } |
| 5261 | 5316 |
| 5262 | 5317 |
| 5263 bool Parser::Parse(CompilationInfo* info) { | 5318 bool Parser::Parse(ParseInfo* info) { |
| 5264 DCHECK(info->function() == NULL); | 5319 DCHECK(info->function() == NULL); |
| 5265 FunctionLiteral* result = NULL; | 5320 FunctionLiteral* result = NULL; |
| 5266 // Ok to use Isolate here; this function is only called in the main thread. | 5321 // Ok to use Isolate here; this function is only called in the main thread. |
| 5267 DCHECK(parsing_on_main_thread_); | 5322 DCHECK(parsing_on_main_thread_); |
| 5268 Isolate* isolate = info->isolate(); | 5323 Isolate* isolate = info->isolate(); |
| 5269 pre_parse_timer_ = isolate->counters()->pre_parse(); | 5324 pre_parse_timer_ = isolate->counters()->pre_parse(); |
| 5270 if (FLAG_trace_parse || allow_natives() || extension_ != NULL) { | 5325 if (FLAG_trace_parse || allow_natives() || extension_ != NULL) { |
| 5271 // If intrinsics are allowed, the Parser cannot operate independent of the | 5326 // If intrinsics are allowed, the Parser cannot operate independent of the |
| 5272 // V8 heap because of Runtime. Tell the string table to internalize strings | 5327 // V8 heap because of Runtime. Tell the string table to internalize strings |
| 5273 // and values right after they're created. | 5328 // and values right after they're created. |
| 5274 ast_value_factory()->Internalize(isolate); | 5329 ast_value_factory()->Internalize(isolate); |
| 5275 } | 5330 } |
| 5276 | 5331 |
| 5277 if (info->is_lazy()) { | 5332 if (info->is_lazy()) { |
| 5278 DCHECK(!info->is_eval()); | 5333 DCHECK(!info->is_eval()); |
| 5279 if (info->shared_info()->is_function()) { | 5334 if (info->shared_info()->is_function()) { |
| 5280 result = ParseLazy(isolate, info); | 5335 result = ParseLazy(isolate, info); |
| 5281 } else { | 5336 } else { |
| 5282 result = ParseProgram(isolate, info); | 5337 result = ParseProgram(isolate, info); |
| 5283 } | 5338 } |
| 5284 } else { | 5339 } else { |
| 5285 SetCachedData(info); | 5340 SetCachedData(info); |
| 5286 result = ParseProgram(isolate, info); | 5341 result = ParseProgram(isolate, info); |
| 5287 } | 5342 } |
| 5288 info->SetFunction(result); | 5343 info->set_literal(result); |
| 5289 | 5344 |
| 5290 Internalize(isolate, info->script(), result == NULL); | 5345 Internalize(isolate, info->script(), result == NULL); |
| 5291 DCHECK(ast_value_factory()->IsInternalized()); | 5346 DCHECK(ast_value_factory()->IsInternalized()); |
| 5292 return (result != NULL); | 5347 return (result != NULL); |
| 5293 } | 5348 } |
| 5294 | 5349 |
| 5295 | 5350 |
| 5296 void Parser::ParseOnBackground(CompilationInfo* info) { | 5351 void Parser::ParseOnBackground(ParseInfo* info) { |
| 5297 parsing_on_main_thread_ = false; | 5352 parsing_on_main_thread_ = false; |
| 5298 | 5353 |
| 5299 DCHECK(info->function() == NULL); | 5354 DCHECK(info->function() == NULL); |
| 5300 FunctionLiteral* result = NULL; | 5355 FunctionLiteral* result = NULL; |
| 5301 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 5356 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
| 5302 | 5357 |
| 5303 CompleteParserRecorder recorder; | 5358 CompleteParserRecorder recorder; |
| 5304 if (produce_cached_parse_data()) log_ = &recorder; | 5359 if (produce_cached_parse_data()) log_ = &recorder; |
| 5305 | 5360 |
| 5306 DCHECK(info->source_stream() != NULL); | 5361 DCHECK(info->source_stream() != NULL); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5317 // scopes) and set their end position after we know the script length. | 5372 // scopes) and set their end position after we know the script length. |
| 5318 Scope* top_scope = NULL; | 5373 Scope* top_scope = NULL; |
| 5319 Scope* eval_scope = NULL; | 5374 Scope* eval_scope = NULL; |
| 5320 result = DoParseProgram(info, &top_scope, &eval_scope); | 5375 result = DoParseProgram(info, &top_scope, &eval_scope); |
| 5321 | 5376 |
| 5322 top_scope->set_end_position(scanner()->location().end_pos); | 5377 top_scope->set_end_position(scanner()->location().end_pos); |
| 5323 if (eval_scope != NULL) { | 5378 if (eval_scope != NULL) { |
| 5324 eval_scope->set_end_position(scanner()->location().end_pos); | 5379 eval_scope->set_end_position(scanner()->location().end_pos); |
| 5325 } | 5380 } |
| 5326 | 5381 |
| 5327 info->SetFunction(result); | 5382 info->set_literal(result); |
| 5328 | 5383 |
| 5329 // We cannot internalize on a background thread; a foreground task will take | 5384 // We cannot internalize on a background thread; a foreground task will take |
| 5330 // care of calling Parser::Internalize just before compilation. | 5385 // care of calling Parser::Internalize just before compilation. |
| 5331 | 5386 |
| 5332 if (produce_cached_parse_data()) { | 5387 if (produce_cached_parse_data()) { |
| 5333 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); | 5388 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); |
| 5334 log_ = NULL; | 5389 log_ = NULL; |
| 5335 } | 5390 } |
| 5336 } | 5391 } |
| 5337 | 5392 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5450 } else { | 5505 } else { |
| 5451 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5506 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
| 5452 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5507 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
| 5453 raw_string->length()); | 5508 raw_string->length()); |
| 5454 } | 5509 } |
| 5455 } | 5510 } |
| 5456 | 5511 |
| 5457 return running_hash; | 5512 return running_hash; |
| 5458 } | 5513 } |
| 5459 } } // namespace v8::internal | 5514 } } // namespace v8::internal |
| OLD | NEW |