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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 596 } |
597 if (info->ast_value_factory() == NULL) { | 597 if (info->ast_value_factory() == NULL) { |
598 // info takes ownership of AstValueFactory. | 598 // info takes ownership of AstValueFactory. |
599 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); | 599 info->set_ast_value_factory(new AstValueFactory(zone(), info->hash_seed())); |
600 info->set_ast_value_factory_owned(); | 600 info->set_ast_value_factory_owned(); |
601 ast_value_factory_ = info->ast_value_factory(); | 601 ast_value_factory_ = info->ast_value_factory(); |
602 ast_node_factory_.set_ast_value_factory(ast_value_factory_); | 602 ast_node_factory_.set_ast_value_factory(ast_value_factory_); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 void Parser::DeserializeScopeChain(ParseInfo* info, | 606 void Parser::DeserializeScopeChain( |
607 MaybeHandle<Context> maybe_context) { | 607 ParseInfo* info, MaybeHandle<ScopeInfo> maybe_outer_scope_info) { |
608 DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id())); | 608 DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id())); |
609 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native | 609 // TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native |
610 // context, which will have the "this" binding for script scopes. | 610 // context, which will have the "this" binding for script scopes. |
611 DeclarationScope* script_scope = NewScriptScope(); | 611 DeclarationScope* script_scope = NewScriptScope(); |
612 info->set_script_scope(script_scope); | 612 info->set_script_scope(script_scope); |
613 Scope* scope = script_scope; | 613 Scope* scope = script_scope; |
614 Handle<Context> context; | 614 Handle<ScopeInfo> outer_scope_info; |
615 if (maybe_context.ToHandle(&context) && !context->IsNativeContext()) { | 615 if (maybe_outer_scope_info.ToHandle(&outer_scope_info)) { |
616 scope = Scope::DeserializeScopeChain( | 616 scope = Scope::DeserializeScopeChain( |
617 info->isolate(), zone(), *context, script_scope, ast_value_factory(), | 617 info->isolate(), zone(), *outer_scope_info, script_scope, |
618 Scope::DeserializationMode::kScopesOnly); | 618 ast_value_factory(), Scope::DeserializationMode::kScopesOnly); |
619 DCHECK(!info->is_module() || scope->is_module_scope()); | 619 DCHECK(!info->is_module() || scope->is_module_scope()); |
620 } | 620 } |
621 original_scope_ = scope; | 621 original_scope_ = scope; |
622 } | 622 } |
623 | 623 |
624 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { | 624 FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) { |
625 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, | 625 // TODO(bmeurer): We temporarily need to pass allow_nesting = true here, |
626 // see comment for HistogramTimerScope class. | 626 // see comment for HistogramTimerScope class. |
627 | 627 |
628 // It's OK to use the Isolate & counters here, since this function is only | 628 // It's OK to use the Isolate & counters here, since this function is only |
(...skipping 13 matching lines...) Expand all Loading... |
642 | 642 |
643 // Initialize parser state. | 643 // Initialize parser state. |
644 CompleteParserRecorder recorder; | 644 CompleteParserRecorder recorder; |
645 | 645 |
646 if (produce_cached_parse_data()) { | 646 if (produce_cached_parse_data()) { |
647 log_ = &recorder; | 647 log_ = &recorder; |
648 } else if (consume_cached_parse_data()) { | 648 } else if (consume_cached_parse_data()) { |
649 cached_parse_data_->Initialize(); | 649 cached_parse_data_->Initialize(); |
650 } | 650 } |
651 | 651 |
652 DeserializeScopeChain(info, info->context()); | 652 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
653 | 653 |
654 source = String::Flatten(source); | 654 source = String::Flatten(source); |
655 FunctionLiteral* result; | 655 FunctionLiteral* result; |
656 | 656 |
657 { | 657 { |
658 std::unique_ptr<Utf16CharacterStream> stream; | 658 std::unique_ptr<Utf16CharacterStream> stream; |
659 if (source->IsExternalTwoByteString()) { | 659 if (source->IsExternalTwoByteString()) { |
660 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( | 660 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( |
661 Handle<ExternalTwoByteString>::cast(source), 0, source->length())); | 661 Handle<ExternalTwoByteString>::cast(source), 0, source->length())); |
662 } else if (source->IsExternalOneByteString()) { | 662 } else if (source->IsExternalOneByteString()) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 RuntimeCallTimerScope runtime_timer(isolate, &RuntimeCallStats::ParseLazy); | 807 RuntimeCallTimerScope runtime_timer(isolate, &RuntimeCallStats::ParseLazy); |
808 HistogramTimerScope timer_scope(isolate->counters()->parse_lazy()); | 808 HistogramTimerScope timer_scope(isolate->counters()->parse_lazy()); |
809 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseLazy"); | 809 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.ParseLazy"); |
810 Handle<String> source(String::cast(info->script()->source())); | 810 Handle<String> source(String::cast(info->script()->source())); |
811 isolate->counters()->total_parse_size()->Increment(source->length()); | 811 isolate->counters()->total_parse_size()->Increment(source->length()); |
812 base::ElapsedTimer timer; | 812 base::ElapsedTimer timer; |
813 if (FLAG_trace_parse) { | 813 if (FLAG_trace_parse) { |
814 timer.Start(); | 814 timer.Start(); |
815 } | 815 } |
816 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 816 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
817 DeserializeScopeChain(info, info->context()); | 817 DeserializeScopeChain(info, info->maybe_outer_scope_info()); |
818 | 818 |
819 // Initialize parser state. | 819 // Initialize parser state. |
820 source = String::Flatten(source); | 820 source = String::Flatten(source); |
821 FunctionLiteral* result; | 821 FunctionLiteral* result; |
822 { | 822 { |
823 std::unique_ptr<Utf16CharacterStream> stream; | 823 std::unique_ptr<Utf16CharacterStream> stream; |
824 if (source->IsExternalTwoByteString()) { | 824 if (source->IsExternalTwoByteString()) { |
825 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( | 825 stream.reset(new ExternalTwoByteStringUtf16CharacterStream( |
826 Handle<ExternalTwoByteString>::cast(source), | 826 Handle<ExternalTwoByteString>::cast(source), |
827 shared_info->start_position(), shared_info->end_position())); | 827 shared_info->start_position(), shared_info->end_position())); |
(...skipping 3217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4045 Utf16CharacterStream* stream_ptr; | 4045 Utf16CharacterStream* stream_ptr; |
4046 if (info->character_stream()) { | 4046 if (info->character_stream()) { |
4047 DCHECK(info->source_stream() == nullptr); | 4047 DCHECK(info->source_stream() == nullptr); |
4048 stream_ptr = info->character_stream(); | 4048 stream_ptr = info->character_stream(); |
4049 } else { | 4049 } else { |
4050 DCHECK(info->character_stream() == nullptr); | 4050 DCHECK(info->character_stream() == nullptr); |
4051 stream.reset(new ExternalStreamingStream(info->source_stream(), | 4051 stream.reset(new ExternalStreamingStream(info->source_stream(), |
4052 info->source_stream_encoding())); | 4052 info->source_stream_encoding())); |
4053 stream_ptr = stream.get(); | 4053 stream_ptr = stream.get(); |
4054 } | 4054 } |
4055 DCHECK(info->context().is_null() || info->context()->IsNativeContext()); | 4055 DCHECK(info->maybe_outer_scope_info().is_null()); |
4056 | 4056 |
4057 DCHECK(original_scope_); | 4057 DCHECK(original_scope_); |
4058 | 4058 |
4059 // When streaming, we don't know the length of the source until we have parsed | 4059 // When streaming, we don't know the length of the source until we have parsed |
4060 // it. The raw data can be UTF-8, so we wouldn't know the source length until | 4060 // it. The raw data can be UTF-8, so we wouldn't know the source length until |
4061 // we have decoded it anyway even if we knew the raw data length (which we | 4061 // we have decoded it anyway even if we knew the raw data length (which we |
4062 // don't). We work around this by storing all the scopes which need their end | 4062 // don't). We work around this by storing all the scopes which need their end |
4063 // position set at the end of the script (the top scope and possible eval | 4063 // position set at the end of the script (the top scope and possible eval |
4064 // scopes) and set their end position after we know the script length. | 4064 // scopes) and set their end position after we know the script length. |
4065 if (info->is_lazy()) { | 4065 if (info->is_lazy()) { |
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5602 node->Print(Isolate::Current()); | 5602 node->Print(Isolate::Current()); |
5603 } | 5603 } |
5604 #endif // DEBUG | 5604 #endif // DEBUG |
5605 | 5605 |
5606 #undef CHECK_OK | 5606 #undef CHECK_OK |
5607 #undef CHECK_OK_VOID | 5607 #undef CHECK_OK_VOID |
5608 #undef CHECK_FAILED | 5608 #undef CHECK_FAILED |
5609 | 5609 |
5610 } // namespace internal | 5610 } // namespace internal |
5611 } // namespace v8 | 5611 } // namespace v8 |
OLD | NEW |