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

Side by Side Diff: src/parser.cc

Issue 6681034: Merge r7110 from bleeding_edge to the 3.1 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/3.1/
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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 696
697 // Make sure the target stack is empty. 697 // Make sure the target stack is empty.
698 ASSERT(target_stack_ == NULL); 698 ASSERT(target_stack_ == NULL);
699 699
700 // If there was a syntax error we have to get rid of the AST 700 // If there was a syntax error we have to get rid of the AST
701 // and it is not safe to do so before the scope has been deleted. 701 // and it is not safe to do so before the scope has been deleted.
702 if (result == NULL) zone_scope->DeleteOnExit(); 702 if (result == NULL) zone_scope->DeleteOnExit();
703 return result; 703 return result;
704 } 704 }
705 705
706 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { 706 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) {
707 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 707 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
708 HistogramTimerScope timer(&Counters::parse_lazy); 708 HistogramTimerScope timer(&Counters::parse_lazy);
709 Handle<String> source(String::cast(script_->source())); 709 Handle<String> source(String::cast(script_->source()));
710 Counters::total_parse_size.Increment(source->length()); 710 Counters::total_parse_size.Increment(source->length());
711 711
712 Handle<SharedFunctionInfo> shared_info = info->shared_info();
712 // Initialize parser state. 713 // Initialize parser state.
713 source->TryFlatten(); 714 source->TryFlatten();
714 if (source->IsExternalTwoByteString()) { 715 if (source->IsExternalTwoByteString()) {
715 ExternalTwoByteStringUC16CharacterStream stream( 716 ExternalTwoByteStringUC16CharacterStream stream(
716 Handle<ExternalTwoByteString>::cast(source), 717 Handle<ExternalTwoByteString>::cast(source),
717 info->start_position(), 718 shared_info->start_position(),
718 info->end_position()); 719 shared_info->end_position());
719 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 720 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
720 return result; 721 return result;
721 } else { 722 } else {
722 GenericStringUC16CharacterStream stream(source, 723 GenericStringUC16CharacterStream stream(source,
723 info->start_position(), 724 shared_info->start_position(),
724 info->end_position()); 725 shared_info->end_position());
725 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 726 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
726 return result; 727 return result;
727 } 728 }
728 } 729 }
729 730
730 731
731 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info, 732 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
732 UC16CharacterStream* source, 733 UC16CharacterStream* source,
733 ZoneScope* zone_scope) { 734 ZoneScope* zone_scope) {
735 Handle<SharedFunctionInfo> shared_info = info->shared_info();
734 scanner_.Initialize(source); 736 scanner_.Initialize(source);
735 ASSERT(target_stack_ == NULL); 737 ASSERT(target_stack_ == NULL);
736 738
737 Handle<String> name(String::cast(info->name())); 739 Handle<String> name(String::cast(shared_info->name()));
738 fni_ = new FuncNameInferrer(); 740 fni_ = new FuncNameInferrer();
739 fni_->PushEnclosingName(name); 741 fni_->PushEnclosingName(name);
740 742
741 mode_ = PARSE_EAGERLY; 743 mode_ = PARSE_EAGERLY;
742 744
743 // Place holder for the result. 745 // Place holder for the result.
744 FunctionLiteral* result = NULL; 746 FunctionLiteral* result = NULL;
745 747
746 { 748 {
747 // Parse the function literal. 749 // Parse the function literal.
748 Handle<String> no_name = Factory::empty_symbol(); 750 Handle<String> no_name = Factory::empty_symbol();
749 Scope* scope = 751 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
750 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 752 if (!info->closure().is_null()) {
753 scope = Scope::DeserializeScopeChain(info, scope);
754 }
751 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 755 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
752 scope); 756 scope);
753 TemporaryScope temp_scope(&this->temp_scope_); 757 TemporaryScope temp_scope(&this->temp_scope_);
754 758
755 if (info->strict_mode()) { 759 if (shared_info->strict_mode()) {
756 temp_scope.EnableStrictMode(); 760 temp_scope.EnableStrictMode();
757 } 761 }
758 762
759 FunctionLiteralType type = 763 FunctionLiteralType type =
760 info->is_expression() ? EXPRESSION : DECLARATION; 764 shared_info->is_expression() ? EXPRESSION : DECLARATION;
761 bool ok = true; 765 bool ok = true;
762 result = ParseFunctionLiteral(name, 766 result = ParseFunctionLiteral(name,
763 false, // Strict mode name already checked. 767 false, // Strict mode name already checked.
764 RelocInfo::kNoPosition, type, &ok); 768 RelocInfo::kNoPosition, type, &ok);
765 // Make sure the results agree. 769 // Make sure the results agree.
766 ASSERT(ok == (result != NULL)); 770 ASSERT(ok == (result != NULL));
767 } 771 }
768 772
769 // Make sure the target stack is empty. 773 // Make sure the target stack is empty.
770 ASSERT(target_stack_ == NULL); 774 ASSERT(target_stack_ == NULL);
771 775
772 // If there was a stack overflow we have to get rid of AST and it is 776 // If there was a stack overflow we have to get rid of AST and it is
773 // not safe to do before scope has been deleted. 777 // not safe to do before scope has been deleted.
774 if (result == NULL) { 778 if (result == NULL) {
775 zone_scope->DeleteOnExit(); 779 zone_scope->DeleteOnExit();
776 if (stack_overflow_) Top::StackOverflow(); 780 if (stack_overflow_) Top::StackOverflow();
777 } else { 781 } else {
778 Handle<String> inferred_name(info->inferred_name()); 782 Handle<String> inferred_name(shared_info->inferred_name());
779 result->set_inferred_name(inferred_name); 783 result->set_inferred_name(inferred_name);
780 } 784 }
781 return result; 785 return result;
782 } 786 }
783 787
784 788
785 Handle<String> Parser::GetSymbol(bool* ok) { 789 Handle<String> Parser::GetSymbol(bool* ok) {
786 int symbol_id = -1; 790 int symbol_id = -1;
787 if (pre_data() != NULL) { 791 if (pre_data() != NULL) {
788 symbol_id = pre_data()->GetSymbolIdentifier(); 792 symbol_id = pre_data()->GetSymbolIdentifier();
(...skipping 4337 matching lines...) Expand 10 before | Expand all | Expand 10 after
5126 return !parser.failed(); 5130 return !parser.failed();
5127 } 5131 }
5128 5132
5129 5133
5130 bool ParserApi::Parse(CompilationInfo* info) { 5134 bool ParserApi::Parse(CompilationInfo* info) {
5131 ASSERT(info->function() == NULL); 5135 ASSERT(info->function() == NULL);
5132 FunctionLiteral* result = NULL; 5136 FunctionLiteral* result = NULL;
5133 Handle<Script> script = info->script(); 5137 Handle<Script> script = info->script();
5134 if (info->is_lazy()) { 5138 if (info->is_lazy()) {
5135 Parser parser(script, true, NULL, NULL); 5139 Parser parser(script, true, NULL, NULL);
5136 result = parser.ParseLazy(info->shared_info()); 5140 result = parser.ParseLazy(info);
5137 } else { 5141 } else {
5138 bool allow_natives_syntax = 5142 bool allow_natives_syntax =
5139 FLAG_allow_natives_syntax || Bootstrapper::IsActive(); 5143 FLAG_allow_natives_syntax || Bootstrapper::IsActive();
5140 ScriptDataImpl* pre_data = info->pre_parse_data(); 5144 ScriptDataImpl* pre_data = info->pre_parse_data();
5141 Parser parser(script, allow_natives_syntax, info->extension(), pre_data); 5145 Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
5142 if (pre_data != NULL && pre_data->has_error()) { 5146 if (pre_data != NULL && pre_data->has_error()) {
5143 Scanner::Location loc = pre_data->MessageLocation(); 5147 Scanner::Location loc = pre_data->MessageLocation();
5144 const char* message = pre_data->BuildMessage(); 5148 const char* message = pre_data->BuildMessage();
5145 Vector<const char*> args = pre_data->BuildArgs(); 5149 Vector<const char*> args = pre_data->BuildArgs();
5146 parser.ReportMessageAt(loc, message, args); 5150 parser.ReportMessageAt(loc, message, args);
5147 DeleteArray(message); 5151 DeleteArray(message);
5148 for (int i = 0; i < args.length(); i++) { 5152 for (int i = 0; i < args.length(); i++) {
5149 DeleteArray(args[i]); 5153 DeleteArray(args[i]);
5150 } 5154 }
5151 DeleteArray(args.start()); 5155 DeleteArray(args.start());
5152 ASSERT(Top::has_pending_exception()); 5156 ASSERT(Top::has_pending_exception());
5153 } else { 5157 } else {
5154 Handle<String> source = Handle<String>(String::cast(script->source())); 5158 Handle<String> source = Handle<String>(String::cast(script->source()));
5155 result = parser.ParseProgram(source, 5159 result = parser.ParseProgram(source,
5156 info->is_global(), 5160 info->is_global(),
5157 info->StrictMode()); 5161 info->StrictMode());
5158 } 5162 }
5159 } 5163 }
5160 5164
5161 info->SetFunction(result); 5165 info->SetFunction(result);
5162 return (result != NULL); 5166 return (result != NULL);
5163 } 5167 }
5164 5168
5165 } } // namespace v8::internal 5169 } } // 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