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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
781 source_location.beg_pos, source_location.end_pos); | 781 source_location.beg_pos, source_location.end_pos); |
782 Handle<JSArray> array = Factory::NewJSArray(args.length()); | 782 Handle<JSArray> array = Factory::NewJSArray(args.length()); |
783 for (int i = 0; i < args.length(); i++) { | 783 for (int i = 0; i < args.length(); i++) { |
784 SetElement(array, i, Factory::NewStringFromUtf8(CStrVector(args[i]))); | 784 SetElement(array, i, Factory::NewStringFromUtf8(CStrVector(args[i]))); |
785 } | 785 } |
786 Handle<Object> result = Factory::NewSyntaxError(type, array); | 786 Handle<Object> result = Factory::NewSyntaxError(type, array); |
787 Top::Throw(*result, &location); | 787 Top::Throw(*result, &location); |
788 } | 788 } |
789 | 789 |
790 | 790 |
791 void Parser::ReportMessageAt(Scanner::Location source_location, | |
792 const char* type, | |
793 Vector<Handle<String> > args) { | |
794 MessageLocation location(script_, | |
795 source_location.beg_pos, source_location.end_pos); | |
Mads Ager (chromium)
2011/01/17 09:29:13
I find one argument per line more readable.
Lasse Reichstein
2011/01/17 09:34:08
Fixed here and above.
| |
796 Handle<JSArray> array = Factory::NewJSArray(args.length()); | |
797 for (int i = 0; i < args.length(); i++) { | |
798 SetElement(array, i, args[i]); | |
799 } | |
800 Handle<Object> result = Factory::NewSyntaxError(type, array); | |
801 Top::Throw(*result, &location); | |
802 } | |
803 | |
804 | |
791 // Base class containing common code for the different finder classes used by | 805 // Base class containing common code for the different finder classes used by |
792 // the parser. | 806 // the parser. |
793 class ParserFinder { | 807 class ParserFinder { |
794 protected: | 808 protected: |
795 ParserFinder() {} | 809 ParserFinder() {} |
796 static Assignment* AsAssignment(Statement* stat) { | 810 static Assignment* AsAssignment(Statement* stat) { |
797 if (stat == NULL) return NULL; | 811 if (stat == NULL) return NULL; |
798 ExpressionStatement* exp_stat = stat->AsExpressionStatement(); | 812 ExpressionStatement* exp_stat = stat->AsExpressionStatement(); |
799 if (exp_stat == NULL) return NULL; | 813 if (exp_stat == NULL) return NULL; |
800 return exp_stat->expression()->AsAssignment(); | 814 return exp_stat->expression()->AsAssignment(); |
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1686 Expect(Token::CONTINUE, CHECK_OK); | 1700 Expect(Token::CONTINUE, CHECK_OK); |
1687 Handle<String> label = Handle<String>::null(); | 1701 Handle<String> label = Handle<String>::null(); |
1688 Token::Value tok = peek(); | 1702 Token::Value tok = peek(); |
1689 if (!scanner().has_line_terminator_before_next() && | 1703 if (!scanner().has_line_terminator_before_next() && |
1690 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1704 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
1691 label = ParseIdentifier(CHECK_OK); | 1705 label = ParseIdentifier(CHECK_OK); |
1692 } | 1706 } |
1693 IterationStatement* target = NULL; | 1707 IterationStatement* target = NULL; |
1694 target = LookupContinueTarget(label, CHECK_OK); | 1708 target = LookupContinueTarget(label, CHECK_OK); |
1695 if (target == NULL) { | 1709 if (target == NULL) { |
1696 // Illegal continue statement. To be consistent with KJS we delay | 1710 // Illegal continue statement. |
1697 // reporting of the syntax error until runtime. | 1711 const char* message = "illegal_continue"; |
1698 Handle<String> error_type = Factory::illegal_continue_symbol(); | 1712 Vector<Handle<String> > args; |
1699 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); | 1713 if (!label.is_null()) { |
1700 Expression* throw_error = NewThrowSyntaxError(error_type, label); | 1714 message = "unknown_label"; |
1701 return new ExpressionStatement(throw_error); | 1715 args = Vector<Handle<String> >(&label, 1); |
1716 } | |
1717 ReportMessageAt(scanner().location(), message, args); | |
1718 *ok = false; | |
1719 return NULL; | |
1702 } | 1720 } |
1703 ExpectSemicolon(CHECK_OK); | 1721 ExpectSemicolon(CHECK_OK); |
1704 return new ContinueStatement(target); | 1722 return new ContinueStatement(target); |
1705 } | 1723 } |
1706 | 1724 |
1707 | 1725 |
1708 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { | 1726 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
1709 // BreakStatement :: | 1727 // BreakStatement :: |
1710 // 'break' Identifier? ';' | 1728 // 'break' Identifier? ';' |
1711 | 1729 |
1712 Expect(Token::BREAK, CHECK_OK); | 1730 Expect(Token::BREAK, CHECK_OK); |
1713 Handle<String> label; | 1731 Handle<String> label; |
1714 Token::Value tok = peek(); | 1732 Token::Value tok = peek(); |
1715 if (!scanner().has_line_terminator_before_next() && | 1733 if (!scanner().has_line_terminator_before_next() && |
1716 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1734 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
1717 label = ParseIdentifier(CHECK_OK); | 1735 label = ParseIdentifier(CHECK_OK); |
1718 } | 1736 } |
1719 // Parse labeled break statements that target themselves into | 1737 // Parse labeled break statements that target themselves into |
1720 // empty statements, e.g. 'l1: l2: l3: break l2;' | 1738 // empty statements, e.g. 'l1: l2: l3: break l2;' |
1721 if (!label.is_null() && ContainsLabel(labels, label)) { | 1739 if (!label.is_null() && ContainsLabel(labels, label)) { |
1722 return EmptyStatement(); | 1740 return EmptyStatement(); |
1723 } | 1741 } |
1724 BreakableStatement* target = NULL; | 1742 BreakableStatement* target = NULL; |
1725 target = LookupBreakTarget(label, CHECK_OK); | 1743 target = LookupBreakTarget(label, CHECK_OK); |
1726 if (target == NULL) { | 1744 if (target == NULL) { |
1727 // Illegal break statement. To be consistent with KJS we delay | 1745 // Illegal break statement. |
1728 // reporting of the syntax error until runtime. | 1746 const char* message = "illegal_break"; |
1729 Handle<String> error_type = Factory::illegal_break_symbol(); | 1747 Vector<Handle<String> > args; |
1730 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); | 1748 if (!label.is_null()) { |
1731 Expression* throw_error = NewThrowSyntaxError(error_type, label); | 1749 message = "unknown_label"; |
1732 return new ExpressionStatement(throw_error); | 1750 args = Vector<Handle<String> >(&label, 1); |
1751 } | |
1752 ReportMessageAt(scanner().location(), message, args); | |
1753 *ok = false; | |
1754 return NULL; | |
1733 } | 1755 } |
1734 ExpectSemicolon(CHECK_OK); | 1756 ExpectSemicolon(CHECK_OK); |
1735 return new BreakStatement(target); | 1757 return new BreakStatement(target); |
1736 } | 1758 } |
1737 | 1759 |
1738 | 1760 |
1739 Statement* Parser::ParseReturnStatement(bool* ok) { | 1761 Statement* Parser::ParseReturnStatement(bool* ok) { |
1740 // ReturnStatement :: | 1762 // ReturnStatement :: |
1741 // 'return' Expression? ';' | 1763 // 'return' Expression? ';' |
1742 | 1764 |
(...skipping 2963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4706 Handle<String> source = Handle<String>(String::cast(script->source())); | 4728 Handle<String> source = Handle<String>(String::cast(script->source())); |
4707 result = parser.ParseProgram(source, info->is_global()); | 4729 result = parser.ParseProgram(source, info->is_global()); |
4708 } | 4730 } |
4709 } | 4731 } |
4710 | 4732 |
4711 info->SetFunction(result); | 4733 info->SetFunction(result); |
4712 return (result != NULL); | 4734 return (result != NULL); |
4713 } | 4735 } |
4714 | 4736 |
4715 } } // namespace v8::internal | 4737 } } // namespace v8::internal |
OLD | NEW |