Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/parser.cc

Issue 6646017: Rebuild scope chain from serialized scope info before parsing lazily. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 685
686 // Make sure the target stack is empty. 686 // Make sure the target stack is empty.
687 ASSERT(target_stack_ == NULL); 687 ASSERT(target_stack_ == NULL);
688 688
689 // If there was a syntax error we have to get rid of the AST 689 // If there was a syntax error we have to get rid of the AST
690 // and it is not safe to do so before the scope has been deleted. 690 // and it is not safe to do so before the scope has been deleted.
691 if (result == NULL) zone_scope->DeleteOnExit(); 691 if (result == NULL) zone_scope->DeleteOnExit();
692 return result; 692 return result;
693 } 693 }
694 694
695 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { 695 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) {
696 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 696 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
697 HistogramTimerScope timer(&Counters::parse_lazy); 697 HistogramTimerScope timer(&Counters::parse_lazy);
698 Handle<String> source(String::cast(script_->source())); 698 Handle<String> source(String::cast(script_->source()));
699 Counters::total_parse_size.Increment(source->length()); 699 Counters::total_parse_size.Increment(source->length());
700 700
701 Handle<SharedFunctionInfo> shared_info = info->shared_info();
701 // Initialize parser state. 702 // Initialize parser state.
702 source->TryFlatten(); 703 source->TryFlatten();
703 if (source->IsExternalTwoByteString()) { 704 if (source->IsExternalTwoByteString()) {
704 ExternalTwoByteStringUC16CharacterStream stream( 705 ExternalTwoByteStringUC16CharacterStream stream(
705 Handle<ExternalTwoByteString>::cast(source), 706 Handle<ExternalTwoByteString>::cast(source),
706 info->start_position(), 707 shared_info->start_position(),
707 info->end_position()); 708 shared_info->end_position());
708 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 709 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
709 return result; 710 return result;
710 } else { 711 } else {
711 GenericStringUC16CharacterStream stream(source, 712 GenericStringUC16CharacterStream stream(source,
712 info->start_position(), 713 shared_info->start_position(),
713 info->end_position()); 714 shared_info->end_position());
714 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 715 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
715 return result; 716 return result;
716 } 717 }
717 } 718 }
718 719
719 720
720 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info, 721 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
721 UC16CharacterStream* source, 722 UC16CharacterStream* source,
722 ZoneScope* zone_scope) { 723 ZoneScope* zone_scope) {
724 Handle<SharedFunctionInfo> shared_info = info->shared_info();
723 scanner_.Initialize(source); 725 scanner_.Initialize(source);
724 ASSERT(target_stack_ == NULL); 726 ASSERT(target_stack_ == NULL);
725 727
726 Handle<String> name(String::cast(info->name())); 728 Handle<String> name(String::cast(shared_info->name()));
727 fni_ = new FuncNameInferrer(); 729 fni_ = new FuncNameInferrer();
728 fni_->PushEnclosingName(name); 730 fni_->PushEnclosingName(name);
729 731
730 mode_ = PARSE_EAGERLY; 732 mode_ = PARSE_EAGERLY;
731 733
732 // Place holder for the result. 734 // Place holder for the result.
733 FunctionLiteral* result = NULL; 735 FunctionLiteral* result = NULL;
734 736
735 { 737 {
736 // Parse the function literal. 738 // Parse the function literal.
737 Handle<String> no_name = Factory::empty_symbol(); 739 Handle<String> no_name = Factory::empty_symbol();
738 Scope* scope = 740 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
739 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 741 if (!info->closure().is_null()) {
742 scope = Scope::DeserializeScopeChain(info, scope);
743 }
740 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 744 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
741 scope); 745 scope);
742 TemporaryScope temp_scope(&this->temp_scope_); 746 TemporaryScope temp_scope(&this->temp_scope_);
743 747
744 if (info->strict_mode()) { 748 if (shared_info->strict_mode()) {
745 top_scope_->EnableStrictMode(); 749 top_scope_->EnableStrictMode();
746 } 750 }
747 751
748 FunctionLiteralType type = 752 FunctionLiteralType type =
749 info->is_expression() ? EXPRESSION : DECLARATION; 753 shared_info->is_expression() ? EXPRESSION : DECLARATION;
750 bool ok = true; 754 bool ok = true;
751 result = ParseFunctionLiteral(name, 755 result = ParseFunctionLiteral(name,
752 false, // Strict mode name already checked. 756 false, // Strict mode name already checked.
753 RelocInfo::kNoPosition, type, &ok); 757 RelocInfo::kNoPosition, type, &ok);
754 // Make sure the results agree. 758 // Make sure the results agree.
755 ASSERT(ok == (result != NULL)); 759 ASSERT(ok == (result != NULL));
756 } 760 }
757 761
758 // Make sure the target stack is empty. 762 // Make sure the target stack is empty.
759 ASSERT(target_stack_ == NULL); 763 ASSERT(target_stack_ == NULL);
760 764
761 // If there was a stack overflow we have to get rid of AST and it is 765 // If there was a stack overflow we have to get rid of AST and it is
762 // not safe to do before scope has been deleted. 766 // not safe to do before scope has been deleted.
763 if (result == NULL) { 767 if (result == NULL) {
764 zone_scope->DeleteOnExit(); 768 zone_scope->DeleteOnExit();
765 if (stack_overflow_) Top::StackOverflow(); 769 if (stack_overflow_) Top::StackOverflow();
766 } else { 770 } else {
767 Handle<String> inferred_name(info->inferred_name()); 771 Handle<String> inferred_name(shared_info->inferred_name());
768 result->set_inferred_name(inferred_name); 772 result->set_inferred_name(inferred_name);
769 } 773 }
770 return result; 774 return result;
771 } 775 }
772 776
773 777
774 Handle<String> Parser::GetSymbol(bool* ok) { 778 Handle<String> Parser::GetSymbol(bool* ok) {
775 int symbol_id = -1; 779 int symbol_id = -1;
776 if (pre_data() != NULL) { 780 if (pre_data() != NULL) {
777 symbol_id = pre_data()->GetSymbolIdentifier(); 781 symbol_id = pre_data()->GetSymbolIdentifier();
(...skipping 4341 matching lines...) Expand 10 before | Expand all | Expand 10 after
5119 return !parser.failed(); 5123 return !parser.failed();
5120 } 5124 }
5121 5125
5122 5126
5123 bool ParserApi::Parse(CompilationInfo* info) { 5127 bool ParserApi::Parse(CompilationInfo* info) {
5124 ASSERT(info->function() == NULL); 5128 ASSERT(info->function() == NULL);
5125 FunctionLiteral* result = NULL; 5129 FunctionLiteral* result = NULL;
5126 Handle<Script> script = info->script(); 5130 Handle<Script> script = info->script();
5127 if (info->is_lazy()) { 5131 if (info->is_lazy()) {
5128 Parser parser(script, true, NULL, NULL); 5132 Parser parser(script, true, NULL, NULL);
5129 result = parser.ParseLazy(info->shared_info()); 5133 result = parser.ParseLazy(info);
5130 } else { 5134 } else {
5131 bool allow_natives_syntax = 5135 bool allow_natives_syntax =
5132 FLAG_allow_natives_syntax || Bootstrapper::IsActive(); 5136 FLAG_allow_natives_syntax || Bootstrapper::IsActive();
5133 ScriptDataImpl* pre_data = info->pre_parse_data(); 5137 ScriptDataImpl* pre_data = info->pre_parse_data();
5134 Parser parser(script, allow_natives_syntax, info->extension(), pre_data); 5138 Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
5135 if (pre_data != NULL && pre_data->has_error()) { 5139 if (pre_data != NULL && pre_data->has_error()) {
5136 Scanner::Location loc = pre_data->MessageLocation(); 5140 Scanner::Location loc = pre_data->MessageLocation();
5137 const char* message = pre_data->BuildMessage(); 5141 const char* message = pre_data->BuildMessage();
5138 Vector<const char*> args = pre_data->BuildArgs(); 5142 Vector<const char*> args = pre_data->BuildArgs();
5139 parser.ReportMessageAt(loc, message, args); 5143 parser.ReportMessageAt(loc, message, args);
5140 DeleteArray(message); 5144 DeleteArray(message);
5141 for (int i = 0; i < args.length(); i++) { 5145 for (int i = 0; i < args.length(); i++) {
5142 DeleteArray(args[i]); 5146 DeleteArray(args[i]);
5143 } 5147 }
5144 DeleteArray(args.start()); 5148 DeleteArray(args.start());
5145 ASSERT(Top::has_pending_exception()); 5149 ASSERT(Top::has_pending_exception());
5146 } else { 5150 } else {
5147 Handle<String> source = Handle<String>(String::cast(script->source())); 5151 Handle<String> source = Handle<String>(String::cast(script->source()));
5148 result = parser.ParseProgram(source, 5152 result = parser.ParseProgram(source,
5149 info->is_global(), 5153 info->is_global(),
5150 info->StrictMode()); 5154 info->StrictMode());
5151 } 5155 }
5152 } 5156 }
5153 5157
5154 info->SetFunction(result); 5158 info->SetFunction(result);
5155 return (result != NULL); 5159 return (result != NULL);
5156 } 5160 }
5157 5161
5158 } } // namespace v8::internal 5162 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698