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