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

Side by Side Diff: src/parser.cc

Issue 7607031: Update gc branch to bleeding_edge revision 8862. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Fix bug in weak-map merge Created 9 years, 4 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/platform.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 scope = Scope::DeserializeScopeChain(info, scope); 724 scope = Scope::DeserializeScopeChain(info, scope);
725 } 725 }
726 LexicalScope lexical_scope(this, scope, isolate()); 726 LexicalScope lexical_scope(this, scope, isolate());
727 727
728 if (shared_info->strict_mode()) { 728 if (shared_info->strict_mode()) {
729 top_scope_->EnableStrictMode(); 729 top_scope_->EnableStrictMode();
730 } 730 }
731 731
732 FunctionLiteralType type = 732 FunctionLiteralType type =
733 shared_info->is_expression() ? EXPRESSION : DECLARATION; 733 shared_info->is_expression() ? EXPRESSION : DECLARATION;
734 Handle<String> function_name =
735 shared_info->is_anonymous() ? Handle<String>::null() : name;
734 bool ok = true; 736 bool ok = true;
735 result = ParseFunctionLiteral(name, 737 result = ParseFunctionLiteral(function_name,
736 false, // Strict mode name already checked. 738 false, // Strict mode name already checked.
737 RelocInfo::kNoPosition, type, &ok); 739 RelocInfo::kNoPosition,
740 type,
741 &ok);
738 // Make sure the results agree. 742 // Make sure the results agree.
739 ASSERT(ok == (result != NULL)); 743 ASSERT(ok == (result != NULL));
740 } 744 }
741 745
742 // Make sure the target stack is empty. 746 // Make sure the target stack is empty.
743 ASSERT(target_stack_ == NULL); 747 ASSERT(target_stack_ == NULL);
744 748
745 // If there was a stack overflow we have to get rid of AST and it is 749 // If there was a stack overflow we have to get rid of AST and it is
746 // not safe to do before scope has been deleted. 750 // not safe to do before scope has been deleted.
747 if (result == NULL) { 751 if (result == NULL) {
(...skipping 2087 matching lines...) Expand 10 before | Expand all | Expand 10 after
2835 Expression* result = NULL; 2839 Expression* result = NULL;
2836 if (peek() == Token::FUNCTION) { 2840 if (peek() == Token::FUNCTION) {
2837 Expect(Token::FUNCTION, CHECK_OK); 2841 Expect(Token::FUNCTION, CHECK_OK);
2838 int function_token_position = scanner().location().beg_pos; 2842 int function_token_position = scanner().location().beg_pos;
2839 Handle<String> name; 2843 Handle<String> name;
2840 bool is_strict_reserved_name = false; 2844 bool is_strict_reserved_name = false;
2841 if (peek_any_identifier()) { 2845 if (peek_any_identifier()) {
2842 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name, 2846 name = ParseIdentifierOrStrictReservedWord(&is_strict_reserved_name,
2843 CHECK_OK); 2847 CHECK_OK);
2844 } 2848 }
2845 result = ParseFunctionLiteral(name, is_strict_reserved_name, 2849 result = ParseFunctionLiteral(name,
2846 function_token_position, NESTED, CHECK_OK); 2850 is_strict_reserved_name,
2851 function_token_position,
2852 EXPRESSION,
2853 CHECK_OK);
2847 } else { 2854 } else {
2848 result = ParsePrimaryExpression(CHECK_OK); 2855 result = ParsePrimaryExpression(CHECK_OK);
2849 } 2856 }
2850 2857
2851 while (true) { 2858 while (true) {
2852 switch (peek()) { 2859 switch (peek()) {
2853 case Token::LBRACK: { 2860 case Token::LBRACK: {
2854 Consume(Token::LBRACK); 2861 Consume(Token::LBRACK);
2855 int pos = scanner().location().beg_pos; 2862 int pos = scanner().location().beg_pos;
2856 Expression* index = ParseExpression(true, CHECK_OK); 2863 Expression* index = ParseExpression(true, CHECK_OK);
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
3405 Handle<String> name; 3412 Handle<String> name;
3406 if (is_keyword) { 3413 if (is_keyword) {
3407 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next)); 3414 name = isolate_->factory()->LookupAsciiSymbol(Token::String(next));
3408 } else { 3415 } else {
3409 name = GetSymbol(CHECK_OK); 3416 name = GetSymbol(CHECK_OK);
3410 } 3417 }
3411 FunctionLiteral* value = 3418 FunctionLiteral* value =
3412 ParseFunctionLiteral(name, 3419 ParseFunctionLiteral(name,
3413 false, // reserved words are allowed here 3420 false, // reserved words are allowed here
3414 RelocInfo::kNoPosition, 3421 RelocInfo::kNoPosition,
3415 DECLARATION, 3422 EXPRESSION,
3416 CHECK_OK); 3423 CHECK_OK);
3417 // Allow any number of parameters for compatiabilty with JSC. 3424 // Allow any number of parameters for compatiabilty with JSC.
3418 // Specification only allows zero parameters for get and one for set. 3425 // Specification only allows zero parameters for get and one for set.
3419 ObjectLiteral::Property* property = 3426 ObjectLiteral::Property* property =
3420 new(zone()) ObjectLiteral::Property(is_getter, value); 3427 new(zone()) ObjectLiteral::Property(is_getter, value);
3421 return property; 3428 return property;
3422 } else { 3429 } else {
3423 ReportUnexpectedToken(next); 3430 ReportUnexpectedToken(next);
3424 *ok = false; 3431 *ok = false;
3425 return NULL; 3432 return NULL;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3612 return NULL; 3619 return NULL;
3613 } 3620 }
3614 done = (peek() == Token::RPAREN); 3621 done = (peek() == Token::RPAREN);
3615 if (!done) Expect(Token::COMMA, CHECK_OK); 3622 if (!done) Expect(Token::COMMA, CHECK_OK);
3616 } 3623 }
3617 Expect(Token::RPAREN, CHECK_OK); 3624 Expect(Token::RPAREN, CHECK_OK);
3618 return result; 3625 return result;
3619 } 3626 }
3620 3627
3621 3628
3622 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name, 3629 FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> function_name,
3623 bool name_is_strict_reserved, 3630 bool name_is_strict_reserved,
3624 int function_token_position, 3631 int function_token_position,
3625 FunctionLiteralType type, 3632 FunctionLiteralType type,
3626 bool* ok) { 3633 bool* ok) {
3627 // Function :: 3634 // Function ::
3628 // '(' FormalParameterList? ')' '{' FunctionBody '}' 3635 // '(' FormalParameterList? ')' '{' FunctionBody '}'
3629 bool is_named = !var_name.is_null();
3630 3636
3631 // The name associated with this function. If it's a function expression, 3637 // Anonymous functions were passed either the empty symbol or a null
3632 // this is the actual function name, otherwise this is the name of the 3638 // handle as the function name. Remember if we were passed a non-empty
3633 // variable declared and initialized with the function (expression). In 3639 // handle to decide whether to invoke function name inference.
3634 // that case, we don't have a function name (it's empty). 3640 bool should_infer_name = function_name.is_null();
3635 Handle<String> name = 3641
3636 is_named ? var_name : isolate()->factory()->empty_symbol(); 3642 // We want a non-null handle as the function name.
3637 // The function name, if any. 3643 if (should_infer_name) {
3638 Handle<String> function_name = isolate()->factory()->empty_symbol(); 3644 function_name = isolate()->factory()->empty_symbol();
3639 if (is_named && (type == EXPRESSION || type == NESTED)) {
3640 function_name = name;
3641 } 3645 }
3642 3646
3643 int num_parameters = 0; 3647 int num_parameters = 0;
3644 Scope* scope = NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); 3648 // Function declarations are hoisted.
3649 Scope* scope = (type == DECLARATION)
3650 ? NewScope(top_scope_->DeclarationScope(), Scope::FUNCTION_SCOPE, false)
3651 : NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
3645 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8); 3652 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(8);
3646 int materialized_literal_count; 3653 int materialized_literal_count;
3647 int expected_property_count; 3654 int expected_property_count;
3648 int start_pos; 3655 int start_pos;
3649 int end_pos; 3656 int end_pos;
3650 bool only_simple_this_property_assignments; 3657 bool only_simple_this_property_assignments;
3651 Handle<FixedArray> this_property_assignments; 3658 Handle<FixedArray> this_property_assignments;
3652 bool has_duplicate_parameters = false; 3659 bool has_duplicate_parameters = false;
3653 // Parse function body. 3660 // Parse function body.
3654 { LexicalScope lexical_scope(this, scope, isolate()); 3661 { LexicalScope lexical_scope(this, scope, isolate());
3655 top_scope_->SetScopeName(name); 3662 top_scope_->SetScopeName(function_name);
3656 3663
3657 // FormalParameterList :: 3664 // FormalParameterList ::
3658 // '(' (Identifier)*[','] ')' 3665 // '(' (Identifier)*[','] ')'
3659 Expect(Token::LPAREN, CHECK_OK); 3666 Expect(Token::LPAREN, CHECK_OK);
3660 start_pos = scanner().location().beg_pos; 3667 start_pos = scanner().location().beg_pos;
3661 Scanner::Location name_loc = Scanner::Location::invalid(); 3668 Scanner::Location name_loc = Scanner::Location::invalid();
3662 Scanner::Location dupe_loc = Scanner::Location::invalid(); 3669 Scanner::Location dupe_loc = Scanner::Location::invalid();
3663 Scanner::Location reserved_loc = Scanner::Location::invalid(); 3670 Scanner::Location reserved_loc = Scanner::Location::invalid();
3664 3671
3665 bool done = (peek() == Token::RPAREN); 3672 bool done = (peek() == Token::RPAREN);
(...skipping 29 matching lines...) Expand all
3695 Expect(Token::RPAREN, CHECK_OK); 3702 Expect(Token::RPAREN, CHECK_OK);
3696 3703
3697 Expect(Token::LBRACE, CHECK_OK); 3704 Expect(Token::LBRACE, CHECK_OK);
3698 3705
3699 // If we have a named function expression, we add a local variable 3706 // If we have a named function expression, we add a local variable
3700 // declaration to the body of the function with the name of the 3707 // declaration to the body of the function with the name of the
3701 // function and let it refer to the function itself (closure). 3708 // function and let it refer to the function itself (closure).
3702 // NOTE: We create a proxy and resolve it here so that in the 3709 // NOTE: We create a proxy and resolve it here so that in the
3703 // future we can change the AST to only refer to VariableProxies 3710 // future we can change the AST to only refer to VariableProxies
3704 // instead of Variables and Proxis as is the case now. 3711 // instead of Variables and Proxis as is the case now.
3705 if (!function_name.is_null() && function_name->length() > 0) { 3712 if (type == EXPRESSION && function_name->length() > 0) {
3706 Variable* fvar = top_scope_->DeclareFunctionVar(function_name); 3713 Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
3707 VariableProxy* fproxy = 3714 VariableProxy* fproxy =
3708 top_scope_->NewUnresolved(function_name, inside_with()); 3715 top_scope_->NewUnresolved(function_name, inside_with());
3709 fproxy->BindTo(fvar); 3716 fproxy->BindTo(fvar);
3710 body->Add(new(zone()) ExpressionStatement( 3717 body->Add(new(zone()) ExpressionStatement(
3711 new(zone()) Assignment(isolate(), 3718 new(zone()) Assignment(isolate(),
3712 Token::INIT_CONST, 3719 Token::INIT_CONST,
3713 fproxy, 3720 fproxy,
3714 new(zone()) ThisFunction(isolate()), 3721 new(zone()) ThisFunction(isolate()),
3715 RelocInfo::kNoPosition))); 3722 RelocInfo::kNoPosition)));
3716 } 3723 }
3717 3724
3718 // Determine if the function will be lazily compiled. The mode can 3725 // Determine if the function will be lazily compiled. The mode can only
3719 // only be PARSE_LAZILY if the --lazy flag is true. 3726 // be PARSE_LAZILY if the --lazy flag is true. We will not lazily
3727 // compile if we do not have preparser data for the function.
3720 bool is_lazily_compiled = (mode() == PARSE_LAZILY && 3728 bool is_lazily_compiled = (mode() == PARSE_LAZILY &&
3721 top_scope_->outer_scope()->is_global_scope() && 3729 top_scope_->outer_scope()->is_global_scope() &&
3722 top_scope_->HasTrivialOuterContext() && 3730 top_scope_->HasTrivialOuterContext() &&
3723 !parenthesized_function_); 3731 !parenthesized_function_ &&
3732 pre_data() != NULL);
3724 parenthesized_function_ = false; // The bit was set for this function only. 3733 parenthesized_function_ = false; // The bit was set for this function only.
3725 3734
3726 int function_block_pos = scanner().location().beg_pos; 3735 if (is_lazily_compiled) {
3727 if (is_lazily_compiled && pre_data() != NULL) { 3736 int function_block_pos = scanner().location().beg_pos;
3728 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); 3737 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos);
3729 if (!entry.is_valid()) { 3738 if (!entry.is_valid()) {
3730 ReportInvalidPreparseData(name, CHECK_OK); 3739 // There is no preparser data for the function, we will not lazily
3740 // compile after all.
3741 is_lazily_compiled = false;
3742 } else {
3743 end_pos = entry.end_pos();
3744 if (end_pos <= function_block_pos) {
3745 // End position greater than end of stream is safe, and hard to check.
3746 ReportInvalidPreparseData(function_name, CHECK_OK);
3747 }
3748 isolate()->counters()->total_preparse_skipped()->Increment(
3749 end_pos - function_block_pos);
3750 // Seek to position just before terminal '}'.
3751 scanner().SeekForward(end_pos - 1);
3752 materialized_literal_count = entry.literal_count();
3753 expected_property_count = entry.property_count();
3754 if (entry.strict_mode()) top_scope_->EnableStrictMode();
3755 only_simple_this_property_assignments = false;
3756 this_property_assignments = isolate()->factory()->empty_fixed_array();
3757 Expect(Token::RBRACE, CHECK_OK);
3731 } 3758 }
3732 end_pos = entry.end_pos(); 3759 }
3733 if (end_pos <= function_block_pos) { 3760
3734 // End position greater than end of stream is safe, and hard to check. 3761 if (!is_lazily_compiled) {
3735 ReportInvalidPreparseData(name, CHECK_OK);
3736 }
3737 isolate()->counters()->total_preparse_skipped()->Increment(
3738 end_pos - function_block_pos);
3739 // Seek to position just before terminal '}'.
3740 scanner().SeekForward(end_pos - 1);
3741 materialized_literal_count = entry.literal_count();
3742 expected_property_count = entry.property_count();
3743 if (entry.strict_mode()) top_scope_->EnableStrictMode();
3744 only_simple_this_property_assignments = false;
3745 this_property_assignments = isolate()->factory()->empty_fixed_array();
3746 Expect(Token::RBRACE, CHECK_OK);
3747 } else {
3748 ParseSourceElements(body, Token::RBRACE, CHECK_OK); 3762 ParseSourceElements(body, Token::RBRACE, CHECK_OK);
3749 3763
3750 materialized_literal_count = lexical_scope.materialized_literal_count(); 3764 materialized_literal_count = lexical_scope.materialized_literal_count();
3751 expected_property_count = lexical_scope.expected_property_count(); 3765 expected_property_count = lexical_scope.expected_property_count();
3752 only_simple_this_property_assignments = 3766 only_simple_this_property_assignments =
3753 lexical_scope.only_simple_this_property_assignments(); 3767 lexical_scope.only_simple_this_property_assignments();
3754 this_property_assignments = lexical_scope.this_property_assignments(); 3768 this_property_assignments = lexical_scope.this_property_assignments();
3755 3769
3756 Expect(Token::RBRACE, CHECK_OK); 3770 Expect(Token::RBRACE, CHECK_OK);
3757 end_pos = scanner().location().end_pos; 3771 end_pos = scanner().location().end_pos;
3758 } 3772 }
3759 3773
3760 // Validate strict mode. 3774 // Validate strict mode.
3761 if (top_scope_->is_strict_mode()) { 3775 if (top_scope_->is_strict_mode()) {
3762 if (IsEvalOrArguments(name)) { 3776 if (IsEvalOrArguments(function_name)) {
3763 int position = function_token_position != RelocInfo::kNoPosition 3777 int position = function_token_position != RelocInfo::kNoPosition
3764 ? function_token_position 3778 ? function_token_position
3765 : (start_pos > 0 ? start_pos - 1 : start_pos); 3779 : (start_pos > 0 ? start_pos - 1 : start_pos);
3766 Scanner::Location location = Scanner::Location(position, start_pos); 3780 Scanner::Location location = Scanner::Location(position, start_pos);
3767 ReportMessageAt(location, 3781 ReportMessageAt(location,
3768 "strict_function_name", Vector<const char*>::empty()); 3782 "strict_function_name", Vector<const char*>::empty());
3769 *ok = false; 3783 *ok = false;
3770 return NULL; 3784 return NULL;
3771 } 3785 }
3772 if (name_loc.IsValid()) { 3786 if (name_loc.IsValid()) {
(...skipping 23 matching lines...) Expand all
3796 Vector<const char*>::empty()); 3810 Vector<const char*>::empty());
3797 *ok = false; 3811 *ok = false;
3798 return NULL; 3812 return NULL;
3799 } 3813 }
3800 CheckOctalLiteral(start_pos, end_pos, CHECK_OK); 3814 CheckOctalLiteral(start_pos, end_pos, CHECK_OK);
3801 } 3815 }
3802 } 3816 }
3803 3817
3804 FunctionLiteral* function_literal = 3818 FunctionLiteral* function_literal =
3805 new(zone()) FunctionLiteral(isolate(), 3819 new(zone()) FunctionLiteral(isolate(),
3806 name, 3820 function_name,
3807 scope, 3821 scope,
3808 body, 3822 body,
3809 materialized_literal_count, 3823 materialized_literal_count,
3810 expected_property_count, 3824 expected_property_count,
3811 only_simple_this_property_assignments, 3825 only_simple_this_property_assignments,
3812 this_property_assignments, 3826 this_property_assignments,
3813 num_parameters, 3827 num_parameters,
3814 start_pos, 3828 start_pos,
3815 end_pos, 3829 end_pos,
3816 (function_name->length() > 0), 3830 type == EXPRESSION,
3817 has_duplicate_parameters); 3831 has_duplicate_parameters);
3818 function_literal->set_function_token_position(function_token_position); 3832 function_literal->set_function_token_position(function_token_position);
3819 3833
3820 if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal); 3834 if (fni_ != NULL && should_infer_name) fni_->AddFunction(function_literal);
3821 return function_literal; 3835 return function_literal;
3822 } 3836 }
3823 3837
3824 3838
3825 Expression* Parser::ParseV8Intrinsic(bool* ok) { 3839 Expression* Parser::ParseV8Intrinsic(bool* ok) {
3826 // CallRuntime :: 3840 // CallRuntime ::
3827 // '%' Identifier Arguments 3841 // '%' Identifier Arguments
3828 3842
3829 Expect(Token::MOD, CHECK_OK); 3843 Expect(Token::MOD, CHECK_OK);
3830 Handle<String> name = ParseIdentifier(CHECK_OK); 3844 Handle<String> name = ParseIdentifier(CHECK_OK);
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
5111 info->is_global(), 5125 info->is_global(),
5112 info->StrictMode()); 5126 info->StrictMode());
5113 } 5127 }
5114 } 5128 }
5115 5129
5116 info->SetFunction(result); 5130 info->SetFunction(result);
5117 return (result != NULL); 5131 return (result != NULL);
5118 } 5132 }
5119 5133
5120 } } // namespace v8::internal 5134 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698