| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3018 // In parsing the first assignment expression in conditional | 3018 // In parsing the first assignment expression in conditional |
| 3019 // expressions we always accept the 'in' keyword; see ECMA-262, | 3019 // expressions we always accept the 'in' keyword; see ECMA-262, |
| 3020 // section 11.12, page 58. | 3020 // section 11.12, page 58. |
| 3021 Expression* left = ParseAssignmentExpression(true, CHECK_OK); | 3021 Expression* left = ParseAssignmentExpression(true, CHECK_OK); |
| 3022 Expect(Token::COLON, CHECK_OK); | 3022 Expect(Token::COLON, CHECK_OK); |
| 3023 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); | 3023 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); |
| 3024 return factory()->NewConditional(expression, left, right, pos); | 3024 return factory()->NewConditional(expression, left, right, pos); |
| 3025 } | 3025 } |
| 3026 | 3026 |
| 3027 | 3027 |
| 3028 static int Precedence(Token::Value tok, bool accept_IN) { | 3028 int ParserBase::Precedence(Token::Value tok, bool accept_IN) { |
| 3029 if (tok == Token::IN && !accept_IN) | 3029 if (tok == Token::IN && !accept_IN) |
| 3030 return 0; // 0 precedence will terminate binary expression parsing | 3030 return 0; // 0 precedence will terminate binary expression parsing |
| 3031 | 3031 |
| 3032 return Token::Precedence(tok); | 3032 return Token::Precedence(tok); |
| 3033 } | 3033 } |
| 3034 | 3034 |
| 3035 | 3035 |
| 3036 // Precedence >= 4 | 3036 // Precedence >= 4 |
| 3037 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { | 3037 Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { |
| 3038 ASSERT(prec >= 4); | 3038 ASSERT(prec >= 4); |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3838 constant_properties->set(position++, *key); | 3838 constant_properties->set(position++, *key); |
| 3839 constant_properties->set(position++, *value); | 3839 constant_properties->set(position++, *value); |
| 3840 } | 3840 } |
| 3841 *fast_elements = | 3841 *fast_elements = |
| 3842 (max_element_index <= 32) || ((2 * elements) >= max_element_index); | 3842 (max_element_index <= 32) || ((2 * elements) >= max_element_index); |
| 3843 *is_simple = is_simple_acc; | 3843 *is_simple = is_simple_acc; |
| 3844 *depth = depth_acc; | 3844 *depth = depth_acc; |
| 3845 } | 3845 } |
| 3846 | 3846 |
| 3847 | 3847 |
| 3848 // Force instantiation of template instances class. | |
| 3849 template void ObjectLiteralChecker<Parser>::CheckProperty( | |
| 3850 Token::Value property, PropertyKind type, bool* ok); | |
| 3851 | |
| 3852 | |
| 3853 Expression* Parser::ParseObjectLiteral(bool* ok) { | 3848 Expression* Parser::ParseObjectLiteral(bool* ok) { |
| 3854 // ObjectLiteral :: | 3849 // ObjectLiteral :: |
| 3855 // '{' ( | 3850 // '{' ( |
| 3856 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 3851 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
| 3857 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 3852 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
| 3858 // )*[','] '}' | 3853 // )*[','] '}' |
| 3859 | 3854 |
| 3860 int pos = peek_position(); | 3855 int pos = peek_position(); |
| 3861 ZoneList<ObjectLiteral::Property*>* properties = | 3856 ZoneList<ObjectLiteral::Property*>* properties = |
| 3862 new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); | 3857 new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); |
| 3863 int number_of_boilerplate_properties = 0; | 3858 int number_of_boilerplate_properties = 0; |
| 3864 bool has_function = false; | 3859 bool has_function = false; |
| 3865 | 3860 |
| 3866 ObjectLiteralChecker<Parser> checker(this, &scanner_, | 3861 ObjectLiteralChecker checker(this, top_scope_->language_mode()); |
| 3867 top_scope_->language_mode()); | |
| 3868 | 3862 |
| 3869 Expect(Token::LBRACE, CHECK_OK); | 3863 Expect(Token::LBRACE, CHECK_OK); |
| 3870 | 3864 |
| 3871 while (peek() != Token::RBRACE) { | 3865 while (peek() != Token::RBRACE) { |
| 3872 if (fni_ != NULL) fni_->Enter(); | 3866 if (fni_ != NULL) fni_->Enter(); |
| 3873 | 3867 |
| 3874 Literal* key = NULL; | 3868 Literal* key = NULL; |
| 3875 Token::Value next = peek(); | 3869 Token::Value next = peek(); |
| 3876 int next_pos = peek_position(); | 3870 int next_pos = peek_position(); |
| 3877 | 3871 |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4611 | 4605 |
| 4612 bool ParserBase::peek_any_identifier() { | 4606 bool ParserBase::peek_any_identifier() { |
| 4613 Token::Value next = peek(); | 4607 Token::Value next = peek(); |
| 4614 return next == Token::IDENTIFIER || | 4608 return next == Token::IDENTIFIER || |
| 4615 next == Token::FUTURE_RESERVED_WORD || | 4609 next == Token::FUTURE_RESERVED_WORD || |
| 4616 next == Token::FUTURE_STRICT_RESERVED_WORD || | 4610 next == Token::FUTURE_STRICT_RESERVED_WORD || |
| 4617 next == Token::YIELD; | 4611 next == Token::YIELD; |
| 4618 } | 4612 } |
| 4619 | 4613 |
| 4620 | 4614 |
| 4621 bool Parser::CheckContextualKeyword(Vector<const char> keyword) { | 4615 bool ParserBase::CheckContextualKeyword(Vector<const char> keyword) { |
| 4622 if (peek() == Token::IDENTIFIER && | 4616 if (peek() == Token::IDENTIFIER && |
| 4623 scanner().is_next_contextual_keyword(keyword)) { | 4617 scanner()->is_next_contextual_keyword(keyword)) { |
| 4624 Consume(Token::IDENTIFIER); | 4618 Consume(Token::IDENTIFIER); |
| 4625 return true; | 4619 return true; |
| 4626 } | 4620 } |
| 4627 return false; | 4621 return false; |
| 4628 } | 4622 } |
| 4629 | 4623 |
| 4630 | 4624 |
| 4631 void ParserBase::ExpectSemicolon(bool* ok) { | 4625 void ParserBase::ExpectSemicolon(bool* ok) { |
| 4632 // Check for automatic semicolon insertion according to | 4626 // Check for automatic semicolon insertion according to |
| 4633 // the rules given in ECMA-262, section 7.9, page 21. | 4627 // the rules given in ECMA-262, section 7.9, page 21. |
| 4634 Token::Value tok = peek(); | 4628 Token::Value tok = peek(); |
| 4635 if (tok == Token::SEMICOLON) { | 4629 if (tok == Token::SEMICOLON) { |
| 4636 Next(); | 4630 Next(); |
| 4637 return; | 4631 return; |
| 4638 } | 4632 } |
| 4639 if (scanner()->HasAnyLineTerminatorBeforeNext() || | 4633 if (scanner()->HasAnyLineTerminatorBeforeNext() || |
| 4640 tok == Token::RBRACE || | 4634 tok == Token::RBRACE || |
| 4641 tok == Token::EOS) { | 4635 tok == Token::EOS) { |
| 4642 return; | 4636 return; |
| 4643 } | 4637 } |
| 4644 Expect(Token::SEMICOLON, ok); | 4638 Expect(Token::SEMICOLON, ok); |
| 4645 } | 4639 } |
| 4646 | 4640 |
| 4647 | 4641 |
| 4648 void Parser::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { | 4642 void ParserBase::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { |
| 4649 Expect(Token::IDENTIFIER, ok); | 4643 Expect(Token::IDENTIFIER, ok); |
| 4650 if (!*ok) return; | 4644 if (!*ok) return; |
| 4651 if (!scanner().is_literal_contextual_keyword(keyword)) { | 4645 if (!scanner()->is_literal_contextual_keyword(keyword)) { |
| 4646 ReportUnexpectedToken(scanner()->current_token()); |
| 4652 *ok = false; | 4647 *ok = false; |
| 4653 ReportUnexpectedToken(scanner().current_token()); | |
| 4654 } | 4648 } |
| 4655 } | 4649 } |
| 4656 | 4650 |
| 4657 | 4651 |
| 4658 Literal* Parser::GetLiteralUndefined(int position) { | 4652 Literal* Parser::GetLiteralUndefined(int position) { |
| 4659 return factory()->NewLiteral( | 4653 return factory()->NewLiteral( |
| 4660 isolate()->factory()->undefined_value(), position); | 4654 isolate()->factory()->undefined_value(), position); |
| 4661 } | 4655 } |
| 4662 | 4656 |
| 4663 | 4657 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4738 | 4732 |
| 4739 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { | 4733 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { |
| 4740 ReportMessage(error, Vector<const char*>::empty()); | 4734 ReportMessage(error, Vector<const char*>::empty()); |
| 4741 *ok = false; | 4735 *ok = false; |
| 4742 } | 4736 } |
| 4743 } | 4737 } |
| 4744 | 4738 |
| 4745 | 4739 |
| 4746 // Checks whether an octal literal was last seen between beg_pos and end_pos. | 4740 // Checks whether an octal literal was last seen between beg_pos and end_pos. |
| 4747 // If so, reports an error. Only called for strict mode. | 4741 // If so, reports an error. Only called for strict mode. |
| 4748 void Parser::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 4742 void ParserBase::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
| 4749 Scanner::Location octal = scanner().octal_position(); | 4743 Scanner::Location octal = scanner()->octal_position(); |
| 4750 if (octal.IsValid() && | 4744 if (octal.IsValid() && beg_pos <= octal.beg_pos && octal.end_pos <= end_pos) { |
| 4751 beg_pos <= octal.beg_pos && | 4745 ReportMessageAt(octal, "strict_octal_literal"); |
| 4752 octal.end_pos <= end_pos) { | 4746 scanner()->clear_octal_position(); |
| 4753 ReportMessageAt(octal, "strict_octal_literal", | |
| 4754 Vector<const char*>::empty()); | |
| 4755 scanner().clear_octal_position(); | |
| 4756 *ok = false; | 4747 *ok = false; |
| 4757 } | 4748 } |
| 4758 } | 4749 } |
| 4759 | 4750 |
| 4760 | 4751 |
| 4761 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { | 4752 void Parser::CheckConflictingVarDeclarations(Scope* scope, bool* ok) { |
| 4762 Declaration* decl = scope->CheckConflictingVarDeclarations(); | 4753 Declaration* decl = scope->CheckConflictingVarDeclarations(); |
| 4763 if (decl != NULL) { | 4754 if (decl != NULL) { |
| 4764 // In harmony mode we treat conflicting variable bindinds as early | 4755 // In harmony mode we treat conflicting variable bindinds as early |
| 4765 // errors. See ES5 16 for a definition of early errors. | 4756 // errors. See ES5 16 for a definition of early errors. |
| (...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5857 ASSERT(info()->isolate()->has_pending_exception()); | 5848 ASSERT(info()->isolate()->has_pending_exception()); |
| 5858 } else { | 5849 } else { |
| 5859 result = ParseProgram(); | 5850 result = ParseProgram(); |
| 5860 } | 5851 } |
| 5861 } | 5852 } |
| 5862 info()->SetFunction(result); | 5853 info()->SetFunction(result); |
| 5863 return (result != NULL); | 5854 return (result != NULL); |
| 5864 } | 5855 } |
| 5865 | 5856 |
| 5866 } } // namespace v8::internal | 5857 } } // namespace v8::internal |
| OLD | NEW |