| OLD | NEW |
| 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 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 top_scope_->RemoveUnresolved(var); | 1769 top_scope_->RemoveUnresolved(var); |
| 1770 Expect(Token::COLON, CHECK_OK); | 1770 Expect(Token::COLON, CHECK_OK); |
| 1771 return ParseStatement(labels, ok); | 1771 return ParseStatement(labels, ok); |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 // If we have an extension, we allow a native function declaration. | 1774 // If we have an extension, we allow a native function declaration. |
| 1775 // A native function declaration starts with "native function" with | 1775 // A native function declaration starts with "native function" with |
| 1776 // no line-terminator between the two words. | 1776 // no line-terminator between the two words. |
| 1777 if (extension_ != NULL && | 1777 if (extension_ != NULL && |
| 1778 peek() == Token::FUNCTION && | 1778 peek() == Token::FUNCTION && |
| 1779 !scanner().has_line_terminator_before_next() && | 1779 !scanner().HasAnyLineTerminatorBeforeNext() && |
| 1780 expr != NULL && | 1780 expr != NULL && |
| 1781 expr->AsVariableProxy() != NULL && | 1781 expr->AsVariableProxy() != NULL && |
| 1782 expr->AsVariableProxy()->name()->Equals( | 1782 expr->AsVariableProxy()->name()->Equals( |
| 1783 isolate()->heap()->native_symbol()) && | 1783 isolate()->heap()->native_symbol()) && |
| 1784 !scanner().literal_contains_escapes()) { | 1784 !scanner().literal_contains_escapes()) { |
| 1785 return ParseNativeDeclaration(ok); | 1785 return ParseNativeDeclaration(ok); |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 // Parsed expression statement. | 1788 // Parsed expression statement. |
| 1789 ExpectSemicolon(CHECK_OK); | 1789 ExpectSemicolon(CHECK_OK); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1811 } | 1811 } |
| 1812 | 1812 |
| 1813 | 1813 |
| 1814 Statement* Parser::ParseContinueStatement(bool* ok) { | 1814 Statement* Parser::ParseContinueStatement(bool* ok) { |
| 1815 // ContinueStatement :: | 1815 // ContinueStatement :: |
| 1816 // 'continue' Identifier? ';' | 1816 // 'continue' Identifier? ';' |
| 1817 | 1817 |
| 1818 Expect(Token::CONTINUE, CHECK_OK); | 1818 Expect(Token::CONTINUE, CHECK_OK); |
| 1819 Handle<String> label = Handle<String>::null(); | 1819 Handle<String> label = Handle<String>::null(); |
| 1820 Token::Value tok = peek(); | 1820 Token::Value tok = peek(); |
| 1821 if (!scanner().has_line_terminator_before_next() && | 1821 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
| 1822 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1822 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 1823 label = ParseIdentifier(CHECK_OK); | 1823 label = ParseIdentifier(CHECK_OK); |
| 1824 } | 1824 } |
| 1825 IterationStatement* target = NULL; | 1825 IterationStatement* target = NULL; |
| 1826 target = LookupContinueTarget(label, CHECK_OK); | 1826 target = LookupContinueTarget(label, CHECK_OK); |
| 1827 if (target == NULL) { | 1827 if (target == NULL) { |
| 1828 // Illegal continue statement. | 1828 // Illegal continue statement. |
| 1829 const char* message = "illegal_continue"; | 1829 const char* message = "illegal_continue"; |
| 1830 Vector<Handle<String> > args; | 1830 Vector<Handle<String> > args; |
| 1831 if (!label.is_null()) { | 1831 if (!label.is_null()) { |
| 1832 message = "unknown_label"; | 1832 message = "unknown_label"; |
| 1833 args = Vector<Handle<String> >(&label, 1); | 1833 args = Vector<Handle<String> >(&label, 1); |
| 1834 } | 1834 } |
| 1835 ReportMessageAt(scanner().location(), message, args); | 1835 ReportMessageAt(scanner().location(), message, args); |
| 1836 *ok = false; | 1836 *ok = false; |
| 1837 return NULL; | 1837 return NULL; |
| 1838 } | 1838 } |
| 1839 ExpectSemicolon(CHECK_OK); | 1839 ExpectSemicolon(CHECK_OK); |
| 1840 return new(zone()) ContinueStatement(target); | 1840 return new(zone()) ContinueStatement(target); |
| 1841 } | 1841 } |
| 1842 | 1842 |
| 1843 | 1843 |
| 1844 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { | 1844 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
| 1845 // BreakStatement :: | 1845 // BreakStatement :: |
| 1846 // 'break' Identifier? ';' | 1846 // 'break' Identifier? ';' |
| 1847 | 1847 |
| 1848 Expect(Token::BREAK, CHECK_OK); | 1848 Expect(Token::BREAK, CHECK_OK); |
| 1849 Handle<String> label; | 1849 Handle<String> label; |
| 1850 Token::Value tok = peek(); | 1850 Token::Value tok = peek(); |
| 1851 if (!scanner().has_line_terminator_before_next() && | 1851 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
| 1852 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1852 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 1853 label = ParseIdentifier(CHECK_OK); | 1853 label = ParseIdentifier(CHECK_OK); |
| 1854 } | 1854 } |
| 1855 // Parse labeled break statements that target themselves into | 1855 // Parse labeled break statements that target themselves into |
| 1856 // empty statements, e.g. 'l1: l2: l3: break l2;' | 1856 // empty statements, e.g. 'l1: l2: l3: break l2;' |
| 1857 if (!label.is_null() && ContainsLabel(labels, label)) { | 1857 if (!label.is_null() && ContainsLabel(labels, label)) { |
| 1858 return EmptyStatement(); | 1858 return EmptyStatement(); |
| 1859 } | 1859 } |
| 1860 BreakableStatement* target = NULL; | 1860 BreakableStatement* target = NULL; |
| 1861 target = LookupBreakTarget(label, CHECK_OK); | 1861 target = LookupBreakTarget(label, CHECK_OK); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1890 // function. See ECMA-262, section 12.9, page 67. | 1890 // function. See ECMA-262, section 12.9, page 67. |
| 1891 // | 1891 // |
| 1892 // To be consistent with KJS we report the syntax error at runtime. | 1892 // To be consistent with KJS we report the syntax error at runtime. |
| 1893 if (!top_scope_->is_function_scope()) { | 1893 if (!top_scope_->is_function_scope()) { |
| 1894 Handle<String> type = isolate()->factory()->illegal_return_symbol(); | 1894 Handle<String> type = isolate()->factory()->illegal_return_symbol(); |
| 1895 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 1895 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
| 1896 return new(zone()) ExpressionStatement(throw_error); | 1896 return new(zone()) ExpressionStatement(throw_error); |
| 1897 } | 1897 } |
| 1898 | 1898 |
| 1899 Token::Value tok = peek(); | 1899 Token::Value tok = peek(); |
| 1900 if (scanner().has_line_terminator_before_next() || | 1900 if (scanner().HasAnyLineTerminatorBeforeNext() || |
| 1901 tok == Token::SEMICOLON || | 1901 tok == Token::SEMICOLON || |
| 1902 tok == Token::RBRACE || | 1902 tok == Token::RBRACE || |
| 1903 tok == Token::EOS) { | 1903 tok == Token::EOS) { |
| 1904 ExpectSemicolon(CHECK_OK); | 1904 ExpectSemicolon(CHECK_OK); |
| 1905 return new(zone()) ReturnStatement(GetLiteralUndefined()); | 1905 return new(zone()) ReturnStatement(GetLiteralUndefined()); |
| 1906 } | 1906 } |
| 1907 | 1907 |
| 1908 Expression* expr = ParseExpression(true, CHECK_OK); | 1908 Expression* expr = ParseExpression(true, CHECK_OK); |
| 1909 ExpectSemicolon(CHECK_OK); | 1909 ExpectSemicolon(CHECK_OK); |
| 1910 return new(zone()) ReturnStatement(expr); | 1910 return new(zone()) ReturnStatement(expr); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 return statement; | 2025 return statement; |
| 2026 } | 2026 } |
| 2027 | 2027 |
| 2028 | 2028 |
| 2029 Statement* Parser::ParseThrowStatement(bool* ok) { | 2029 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 2030 // ThrowStatement :: | 2030 // ThrowStatement :: |
| 2031 // 'throw' Expression ';' | 2031 // 'throw' Expression ';' |
| 2032 | 2032 |
| 2033 Expect(Token::THROW, CHECK_OK); | 2033 Expect(Token::THROW, CHECK_OK); |
| 2034 int pos = scanner().location().beg_pos; | 2034 int pos = scanner().location().beg_pos; |
| 2035 if (scanner().has_line_terminator_before_next()) { | 2035 if (scanner().HasAnyLineTerminatorBeforeNext()) { |
| 2036 ReportMessage("newline_after_throw", Vector<const char*>::empty()); | 2036 ReportMessage("newline_after_throw", Vector<const char*>::empty()); |
| 2037 *ok = false; | 2037 *ok = false; |
| 2038 return NULL; | 2038 return NULL; |
| 2039 } | 2039 } |
| 2040 Expression* exception = ParseExpression(true, CHECK_OK); | 2040 Expression* exception = ParseExpression(true, CHECK_OK); |
| 2041 ExpectSemicolon(CHECK_OK); | 2041 ExpectSemicolon(CHECK_OK); |
| 2042 | 2042 |
| 2043 return new(zone()) ExpressionStatement(new(zone()) Throw(exception, pos)); | 2043 return new(zone()) ExpressionStatement(new(zone()) Throw(exception, pos)); |
| 2044 } | 2044 } |
| 2045 | 2045 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2612 return ParsePostfixExpression(ok); | 2612 return ParsePostfixExpression(ok); |
| 2613 } | 2613 } |
| 2614 } | 2614 } |
| 2615 | 2615 |
| 2616 | 2616 |
| 2617 Expression* Parser::ParsePostfixExpression(bool* ok) { | 2617 Expression* Parser::ParsePostfixExpression(bool* ok) { |
| 2618 // PostfixExpression :: | 2618 // PostfixExpression :: |
| 2619 // LeftHandSideExpression ('++' | '--')? | 2619 // LeftHandSideExpression ('++' | '--')? |
| 2620 | 2620 |
| 2621 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 2621 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
| 2622 if (!scanner().has_line_terminator_before_next() && | 2622 if (!scanner().HasAnyLineTerminatorBeforeNext() && |
| 2623 Token::IsCountOp(peek())) { | 2623 Token::IsCountOp(peek())) { |
| 2624 // Signal a reference error if the expression is an invalid | 2624 // Signal a reference error if the expression is an invalid |
| 2625 // left-hand side expression. We could report this as a syntax | 2625 // left-hand side expression. We could report this as a syntax |
| 2626 // error here but for compatibility with JSC we choose to report the | 2626 // error here but for compatibility with JSC we choose to report the |
| 2627 // error at runtime. | 2627 // error at runtime. |
| 2628 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2628 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
| 2629 Handle<String> type = | 2629 Handle<String> type = |
| 2630 isolate()->factory()->invalid_lhs_in_postfix_op_symbol(); | 2630 isolate()->factory()->invalid_lhs_in_postfix_op_symbol(); |
| 2631 expression = NewThrowReferenceError(type); | 2631 expression = NewThrowReferenceError(type); |
| 2632 } | 2632 } |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3811 | 3811 |
| 3812 | 3812 |
| 3813 void Parser::ExpectSemicolon(bool* ok) { | 3813 void Parser::ExpectSemicolon(bool* ok) { |
| 3814 // Check for automatic semicolon insertion according to | 3814 // Check for automatic semicolon insertion according to |
| 3815 // the rules given in ECMA-262, section 7.9, page 21. | 3815 // the rules given in ECMA-262, section 7.9, page 21. |
| 3816 Token::Value tok = peek(); | 3816 Token::Value tok = peek(); |
| 3817 if (tok == Token::SEMICOLON) { | 3817 if (tok == Token::SEMICOLON) { |
| 3818 Next(); | 3818 Next(); |
| 3819 return; | 3819 return; |
| 3820 } | 3820 } |
| 3821 if (scanner().has_line_terminator_before_next() || | 3821 if (scanner().HasAnyLineTerminatorBeforeNext() || |
| 3822 tok == Token::RBRACE || | 3822 tok == Token::RBRACE || |
| 3823 tok == Token::EOS) { | 3823 tok == Token::EOS) { |
| 3824 return; | 3824 return; |
| 3825 } | 3825 } |
| 3826 Expect(Token::SEMICOLON, ok); | 3826 Expect(Token::SEMICOLON, ok); |
| 3827 } | 3827 } |
| 3828 | 3828 |
| 3829 | 3829 |
| 3830 Literal* Parser::GetLiteralUndefined() { | 3830 Literal* Parser::GetLiteralUndefined() { |
| 3831 return new(zone()) Literal(isolate()->factory()->undefined_value()); | 3831 return new(zone()) Literal(isolate()->factory()->undefined_value()); |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5008 info->is_global(), | 5008 info->is_global(), |
| 5009 info->StrictMode()); | 5009 info->StrictMode()); |
| 5010 } | 5010 } |
| 5011 } | 5011 } |
| 5012 | 5012 |
| 5013 info->SetFunction(result); | 5013 info->SetFunction(result); |
| 5014 return (result != NULL); | 5014 return (result != NULL); |
| 5015 } | 5015 } |
| 5016 | 5016 |
| 5017 } } // namespace v8::internal | 5017 } } // namespace v8::internal |
| OLD | NEW |