| 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/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/ast/ast.h" | 10 #include "src/ast/ast.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 script_scope_(nullptr), | 51 script_scope_(nullptr), |
| 52 unicode_cache_(nullptr), | 52 unicode_cache_(nullptr), |
| 53 stack_limit_(0), | 53 stack_limit_(0), |
| 54 hash_seed_(0), | 54 hash_seed_(0), |
| 55 compiler_hints_(0), | 55 compiler_hints_(0), |
| 56 start_position_(0), | 56 start_position_(0), |
| 57 end_position_(0), | 57 end_position_(0), |
| 58 isolate_(nullptr), | 58 isolate_(nullptr), |
| 59 cached_data_(nullptr), | 59 cached_data_(nullptr), |
| 60 ast_value_factory_(nullptr), | 60 ast_value_factory_(nullptr), |
| 61 function_name_(nullptr), |
| 61 literal_(nullptr), | 62 literal_(nullptr), |
| 62 scope_(nullptr) {} | 63 scope_(nullptr) {} |
| 63 | 64 |
| 64 ParseInfo::ParseInfo(Zone* zone, Handle<JSFunction> function) | 65 ParseInfo::ParseInfo(Zone* zone, Handle<JSFunction> function) |
| 65 : ParseInfo(zone, Handle<SharedFunctionInfo>(function->shared())) { | 66 : ParseInfo(zone, Handle<SharedFunctionInfo>(function->shared())) { |
| 66 set_context(Handle<Context>(function->context())); | 67 set_context(Handle<Context>(function->context())); |
| 67 } | 68 } |
| 68 | 69 |
| 69 | 70 |
| 70 ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared) | 71 ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared) |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 shared_info->start_position(), shared_info->end_position())); | 1111 shared_info->start_position(), shared_info->end_position())); |
| 1111 } else if (source->IsExternalOneByteString()) { | 1112 } else if (source->IsExternalOneByteString()) { |
| 1112 stream.reset(new ExternalOneByteStringUtf16CharacterStream( | 1113 stream.reset(new ExternalOneByteStringUtf16CharacterStream( |
| 1113 Handle<ExternalOneByteString>::cast(source), | 1114 Handle<ExternalOneByteString>::cast(source), |
| 1114 shared_info->start_position(), shared_info->end_position())); | 1115 shared_info->start_position(), shared_info->end_position())); |
| 1115 } else { | 1116 } else { |
| 1116 stream.reset(new GenericStringUtf16CharacterStream( | 1117 stream.reset(new GenericStringUtf16CharacterStream( |
| 1117 source, shared_info->start_position(), shared_info->end_position())); | 1118 source, shared_info->start_position(), shared_info->end_position())); |
| 1118 } | 1119 } |
| 1119 Handle<String> name(String::cast(shared_info->name())); | 1120 Handle<String> name(String::cast(shared_info->name())); |
| 1120 result = DoParseLazy(isolate, info, ast_value_factory()->GetString(name), | 1121 result = |
| 1121 stream.get()); | 1122 DoParseLazy(info, ast_value_factory()->GetString(name), stream.get()); |
| 1122 if (result != nullptr) { | 1123 if (result != nullptr) { |
| 1123 Handle<String> inferred_name(shared_info->inferred_name()); | 1124 Handle<String> inferred_name(shared_info->inferred_name()); |
| 1124 result->set_inferred_name(inferred_name); | 1125 result->set_inferred_name(inferred_name); |
| 1125 } | 1126 } |
| 1126 } | 1127 } |
| 1127 | 1128 |
| 1128 if (FLAG_trace_parse && result != NULL) { | 1129 if (FLAG_trace_parse && result != NULL) { |
| 1129 double ms = timer.Elapsed().InMillisecondsF(); | 1130 double ms = timer.Elapsed().InMillisecondsF(); |
| 1130 std::unique_ptr<char[]> name_chars = result->debug_name()->ToCString(); | 1131 std::unique_ptr<char[]> name_chars = result->debug_name()->ToCString(); |
| 1131 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); | 1132 PrintF("[parsing function: %s - took %0.3f ms]\n", name_chars.get(), ms); |
| 1132 } | 1133 } |
| 1133 return result; | 1134 return result; |
| 1134 } | 1135 } |
| 1135 | 1136 |
| 1136 static FunctionLiteral::FunctionType ComputeFunctionType(ParseInfo* info) { | 1137 static FunctionLiteral::FunctionType ComputeFunctionType(ParseInfo* info) { |
| 1137 if (info->is_declaration()) { | 1138 if (info->is_declaration()) { |
| 1138 return FunctionLiteral::kDeclaration; | 1139 return FunctionLiteral::kDeclaration; |
| 1139 } else if (info->is_named_expression()) { | 1140 } else if (info->is_named_expression()) { |
| 1140 return FunctionLiteral::kNamedExpression; | 1141 return FunctionLiteral::kNamedExpression; |
| 1141 } else if (IsConciseMethod(info->function_kind()) || | 1142 } else if (IsConciseMethod(info->function_kind()) || |
| 1142 IsAccessorFunction(info->function_kind())) { | 1143 IsAccessorFunction(info->function_kind())) { |
| 1143 return FunctionLiteral::kAccessorOrMethod; | 1144 return FunctionLiteral::kAccessorOrMethod; |
| 1144 } | 1145 } |
| 1145 return FunctionLiteral::kAnonymousExpression; | 1146 return FunctionLiteral::kAnonymousExpression; |
| 1146 } | 1147 } |
| 1147 | 1148 |
| 1148 FunctionLiteral* Parser::DoParseLazy(Isolate* isolate, ParseInfo* info, | 1149 FunctionLiteral* Parser::DoParseLazy(ParseInfo* info, |
| 1149 const AstRawString* raw_name, | 1150 const AstRawString* raw_name, |
| 1150 Utf16CharacterStream* source) { | 1151 Utf16CharacterStream* source) { |
| 1151 scanner_.Initialize(source); | 1152 scanner_.Initialize(source); |
| 1152 DCHECK_NULL(scope_state_); | 1153 DCHECK_NULL(scope_state_); |
| 1153 DCHECK_NULL(target_stack_); | 1154 DCHECK_NULL(target_stack_); |
| 1154 | 1155 |
| 1155 DCHECK(ast_value_factory()); | 1156 DCHECK(ast_value_factory()); |
| 1156 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | 1157 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
| 1157 fni_->PushEnclosingName(raw_name); | 1158 fni_->PushEnclosingName(raw_name); |
| 1158 | 1159 |
| (...skipping 4347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5506 DCHECK(ast_value_factory()->IsInternalized()); | 5507 DCHECK(ast_value_factory()->IsInternalized()); |
| 5507 return (result != NULL); | 5508 return (result != NULL); |
| 5508 } | 5509 } |
| 5509 | 5510 |
| 5510 | 5511 |
| 5511 void Parser::ParseOnBackground(ParseInfo* info) { | 5512 void Parser::ParseOnBackground(ParseInfo* info) { |
| 5512 parsing_on_main_thread_ = false; | 5513 parsing_on_main_thread_ = false; |
| 5513 | 5514 |
| 5514 DCHECK(info->literal() == NULL); | 5515 DCHECK(info->literal() == NULL); |
| 5515 FunctionLiteral* result = NULL; | 5516 FunctionLiteral* result = NULL; |
| 5516 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); | |
| 5517 | 5517 |
| 5518 CompleteParserRecorder recorder; | 5518 CompleteParserRecorder recorder; |
| 5519 if (produce_cached_parse_data()) log_ = &recorder; | 5519 if (produce_cached_parse_data()) log_ = &recorder; |
| 5520 | 5520 |
| 5521 std::unique_ptr<Utf16CharacterStream> stream; | 5521 std::unique_ptr<Utf16CharacterStream> stream; |
| 5522 Utf16CharacterStream* stream_ptr; | 5522 Utf16CharacterStream* stream_ptr; |
| 5523 if (info->character_stream()) { | 5523 if (info->character_stream()) { |
| 5524 DCHECK(info->source_stream() == nullptr); | 5524 DCHECK(info->source_stream() == nullptr); |
| 5525 stream_ptr = info->character_stream(); | 5525 stream_ptr = info->character_stream(); |
| 5526 } else { | 5526 } else { |
| 5527 DCHECK(info->character_stream() == nullptr); | 5527 DCHECK(info->character_stream() == nullptr); |
| 5528 stream.reset(new ExternalStreamingStream(info->source_stream(), | 5528 stream.reset(new ExternalStreamingStream(info->source_stream(), |
| 5529 info->source_stream_encoding())); | 5529 info->source_stream_encoding())); |
| 5530 stream_ptr = stream.get(); | 5530 stream_ptr = stream.get(); |
| 5531 } | 5531 } |
| 5532 scanner_.Initialize(stream_ptr); | |
| 5533 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); | 5532 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); |
| 5534 | 5533 |
| 5535 DCHECK(original_scope_); | 5534 DCHECK(original_scope_); |
| 5536 | 5535 |
| 5537 // When streaming, we don't know the length of the source until we have parsed | 5536 // When streaming, we don't know the length of the source until we have parsed |
| 5538 // it. The raw data can be UTF-8, so we wouldn't know the source length until | 5537 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
| 5539 // we have decoded it anyway even if we knew the raw data length (which we | 5538 // we have decoded it anyway even if we knew the raw data length (which we |
| 5540 // don't). We work around this by storing all the scopes which need their end | 5539 // don't). We work around this by storing all the scopes which need their end |
| 5541 // position set at the end of the script (the top scope and possible eval | 5540 // position set at the end of the script (the top scope and possible eval |
| 5542 // scopes) and set their end position after we know the script length. | 5541 // scopes) and set their end position after we know the script length. |
| 5543 result = DoParseProgram(info); | 5542 if (info->is_lazy()) { |
| 5543 result = DoParseLazy(info, info->function_name(), stream_ptr); |
| 5544 } else { |
| 5545 fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone()); |
| 5546 scanner_.Initialize(stream_ptr); |
| 5547 result = DoParseProgram(info); |
| 5548 } |
| 5544 | 5549 |
| 5545 info->set_literal(result); | 5550 info->set_literal(result); |
| 5546 | 5551 |
| 5547 // We cannot internalize on a background thread; a foreground task will take | 5552 // We cannot internalize on a background thread; a foreground task will take |
| 5548 // care of calling Parser::Internalize just before compilation. | 5553 // care of calling Parser::Internalize just before compilation. |
| 5549 | 5554 |
| 5550 if (produce_cached_parse_data()) { | 5555 if (produce_cached_parse_data()) { |
| 5551 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); | 5556 if (result != NULL) *info->cached_data() = recorder.GetScriptData(); |
| 5552 log_ = NULL; | 5557 log_ = NULL; |
| 5553 } | 5558 } |
| (...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7152 node->Print(Isolate::Current()); | 7157 node->Print(Isolate::Current()); |
| 7153 } | 7158 } |
| 7154 #endif // DEBUG | 7159 #endif // DEBUG |
| 7155 | 7160 |
| 7156 #undef CHECK_OK | 7161 #undef CHECK_OK |
| 7157 #undef CHECK_OK_VOID | 7162 #undef CHECK_OK_VOID |
| 7158 #undef CHECK_FAILED | 7163 #undef CHECK_FAILED |
| 7159 | 7164 |
| 7160 } // namespace internal | 7165 } // namespace internal |
| 7161 } // namespace v8 | 7166 } // namespace v8 |
| OLD | NEW |