| 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-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 cached_parse_data_->Initialize(); | 609 cached_parse_data_->Initialize(); |
| 610 } | 610 } |
| 611 | 611 |
| 612 DeserializeScopeChain(info, info->context(), | 612 DeserializeScopeChain(info, info->context(), |
| 613 Scope::DeserializationMode::kKeepScopeInfo); | 613 Scope::DeserializationMode::kKeepScopeInfo); |
| 614 | 614 |
| 615 source = String::Flatten(source); | 615 source = String::Flatten(source); |
| 616 FunctionLiteral* result; | 616 FunctionLiteral* result; |
| 617 | 617 |
| 618 { | 618 { |
| 619 std::unique_ptr<Utf16CharacterStream> stream; | 619 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source)); |
| 620 if (source->IsExternalTwoByteString()) { | |
| 621 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( | |
| 622 Handle<ExternalTwoByteString>::cast(source), 0, source->length())); | |
| 623 } else if (source->IsExternalOneByteString()) { | |
| 624 stream.reset(new ExternalOneByteStringUtf16CharacterStream( | |
| 625 Handle<ExternalOneByteString>::cast(source), 0, source->length())); | |
| 626 } else { | |
| 627 stream.reset( | |
| 628 new GenericStringUtf16CharacterStream(source, 0, source->length())); | |
| 629 } | |
| 630 scanner_.Initialize(stream.get()); | 620 scanner_.Initialize(stream.get()); |
| 631 result = DoParseProgram(info); | 621 result = DoParseProgram(info); |
| 632 } | 622 } |
| 633 if (result != NULL) { | 623 if (result != NULL) { |
| 634 DCHECK_EQ(scanner_.peek_location().beg_pos, source->length()); | 624 DCHECK_EQ(scanner_.peek_location().beg_pos, source->length()); |
| 635 } | 625 } |
| 636 HandleSourceURLComments(isolate, info->script()); | 626 HandleSourceURLComments(isolate, info->script()); |
| 637 | 627 |
| 638 if (FLAG_trace_parse && result != NULL) { | 628 if (FLAG_trace_parse && result != NULL) { |
| 639 double ms = timer.Elapsed().InMillisecondsF(); | 629 double ms = timer.Elapsed().InMillisecondsF(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 timer.Start(); | 756 timer.Start(); |
| 767 } | 757 } |
| 768 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 758 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
| 769 DeserializeScopeChain(info, info->context(), | 759 DeserializeScopeChain(info, info->context(), |
| 770 Scope::DeserializationMode::kKeepScopeInfo); | 760 Scope::DeserializationMode::kKeepScopeInfo); |
| 771 | 761 |
| 772 // Initialize parser state. | 762 // Initialize parser state. |
| 773 source = String::Flatten(source); | 763 source = String::Flatten(source); |
| 774 FunctionLiteral* result; | 764 FunctionLiteral* result; |
| 775 { | 765 { |
| 776 std::unique_ptr<Utf16CharacterStream> stream; | 766 std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( |
| 777 if (source->IsExternalTwoByteString()) { | 767 source, shared_info->start_position(), shared_info->end_position())); |
| 778 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( | |
| 779 Handle<ExternalTwoByteString>::cast(source), | |
| 780 shared_info->start_position(), shared_info->end_position())); | |
| 781 } else if (source->IsExternalOneByteString()) { | |
| 782 stream.reset(new ExternalOneByteStringUtf16CharacterStream( | |
| 783 Handle<ExternalOneByteString>::cast(source), | |
| 784 shared_info->start_position(), shared_info->end_position())); | |
| 785 } else { | |
| 786 stream.reset(new GenericStringUtf16CharacterStream( | |
| 787 source, shared_info->start_position(), shared_info->end_position())); | |
| 788 } | |
| 789 Handle<String> name(String::cast(shared_info->name())); | 768 Handle<String> name(String::cast(shared_info->name())); |
| 790 result = | 769 result = |
| 791 DoParseLazy(info, ast_value_factory()->GetString(name), stream.get()); | 770 DoParseLazy(info, ast_value_factory()->GetString(name), stream.get()); |
| 792 if (result != nullptr) { | 771 if (result != nullptr) { |
| 793 Handle<String> inferred_name(shared_info->inferred_name()); | 772 Handle<String> inferred_name(shared_info->inferred_name()); |
| 794 result->set_inferred_name(inferred_name); | 773 result->set_inferred_name(inferred_name); |
| 795 } | 774 } |
| 796 } | 775 } |
| 797 | 776 |
| 798 if (FLAG_trace_parse && result != NULL) { | 777 if (FLAG_trace_parse && result != NULL) { |
| (...skipping 4116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4915 CompleteParserRecorder recorder; | 4894 CompleteParserRecorder recorder; |
| 4916 if (produce_cached_parse_data()) log_ = &recorder; | 4895 if (produce_cached_parse_data()) log_ = &recorder; |
| 4917 | 4896 |
| 4918 std::unique_ptr<Utf16CharacterStream> stream; | 4897 std::unique_ptr<Utf16CharacterStream> stream; |
| 4919 Utf16CharacterStream* stream_ptr; | 4898 Utf16CharacterStream* stream_ptr; |
| 4920 if (info->character_stream()) { | 4899 if (info->character_stream()) { |
| 4921 DCHECK(info->source_stream() == nullptr); | 4900 DCHECK(info->source_stream() == nullptr); |
| 4922 stream_ptr = info->character_stream(); | 4901 stream_ptr = info->character_stream(); |
| 4923 } else { | 4902 } else { |
| 4924 DCHECK(info->character_stream() == nullptr); | 4903 DCHECK(info->character_stream() == nullptr); |
| 4925 stream.reset(new ExternalStreamingStream(info->source_stream(), | 4904 stream.reset(ScannerStream::For(info->source_stream(), |
| 4926 info->source_stream_encoding())); | 4905 info->source_stream_encoding())); |
| 4927 stream_ptr = stream.get(); | 4906 stream_ptr = stream.get(); |
| 4928 } | 4907 } |
| 4929 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); | 4908 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); |
| 4930 | 4909 |
| 4931 DCHECK(original_scope_); | 4910 DCHECK(original_scope_); |
| 4932 | 4911 |
| 4933 // When streaming, we don't know the length of the source until we have parsed | 4912 // When streaming, we don't know the length of the source until we have parsed |
| 4934 // it. The raw data can be UTF-8, so we wouldn't know the source length until | 4913 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
| 4935 // we have decoded it anyway even if we knew the raw data length (which we | 4914 // we have decoded it anyway even if we knew the raw data length (which we |
| 4936 // don't). We work around this by storing all the scopes which need their end | 4915 // don't). We work around this by storing all the scopes which need their end |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6453 node->Print(Isolate::Current()); | 6432 node->Print(Isolate::Current()); |
| 6454 } | 6433 } |
| 6455 #endif // DEBUG | 6434 #endif // DEBUG |
| 6456 | 6435 |
| 6457 #undef CHECK_OK | 6436 #undef CHECK_OK |
| 6458 #undef CHECK_OK_VOID | 6437 #undef CHECK_OK_VOID |
| 6459 #undef CHECK_FAILED | 6438 #undef CHECK_FAILED |
| 6460 | 6439 |
| 6461 } // namespace internal | 6440 } // namespace internal |
| 6462 } // namespace v8 | 6441 } // namespace v8 |
| OLD | NEW |