| 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 FunctionLiteral* Parser::ParseProgram(Handle<String> source, | 602 FunctionLiteral* Parser::ParseProgram(Handle<String> source, |
| 603 bool in_global_context) { | 603 bool in_global_context) { |
| 604 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 604 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
| 605 | 605 |
| 606 HistogramTimerScope timer(&Counters::parse); | 606 HistogramTimerScope timer(&Counters::parse); |
| 607 Counters::total_parse_size.Increment(source->length()); | 607 Counters::total_parse_size.Increment(source->length()); |
| 608 fni_ = new FuncNameInferrer(); | 608 fni_ = new FuncNameInferrer(); |
| 609 | 609 |
| 610 // Initialize parser state. | 610 // Initialize parser state. |
| 611 source->TryFlatten(); | 611 source->TryFlatten(); |
| 612 if (source->IsExternalTwoByteString()) { | 612 scanner_.Initialize(source); |
| 613 // Notice that the stream is destroyed at the end of the branch block. | |
| 614 // The last line of the blocks can't be moved outside, even though they're | |
| 615 // identical calls. | |
| 616 ExternalTwoByteStringUC16CharacterStream stream( | |
| 617 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | |
| 618 scanner_.Initialize(&stream, JavaScriptScanner::kAllLiterals); | |
| 619 return DoParseProgram(source, in_global_context, &zone_scope); | |
| 620 } else { | |
| 621 GenericStringUC16CharacterStream stream(source, 0, source->length()); | |
| 622 scanner_.Initialize(&stream, JavaScriptScanner::kAllLiterals); | |
| 623 return DoParseProgram(source, in_global_context, &zone_scope); | |
| 624 } | |
| 625 } | |
| 626 | |
| 627 | |
| 628 FunctionLiteral* Parser::DoParseProgram(Handle<String> source, | |
| 629 bool in_global_context, | |
| 630 ZoneScope* zone_scope) { | |
| 631 ASSERT(target_stack_ == NULL); | 613 ASSERT(target_stack_ == NULL); |
| 632 if (pre_data_ != NULL) pre_data_->Initialize(); | 614 if (pre_data_ != NULL) pre_data_->Initialize(); |
| 633 | 615 |
| 634 // Compute the parsing mode. | 616 // Compute the parsing mode. |
| 635 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; | 617 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; |
| 636 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 618 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
| 637 | 619 |
| 638 Scope::Type type = | 620 Scope::Type type = |
| 639 in_global_context | 621 in_global_context |
| 640 ? Scope::GLOBAL_SCOPE | 622 ? Scope::GLOBAL_SCOPE |
| (...skipping 25 matching lines...) Expand all Loading... |
| 666 } else if (stack_overflow_) { | 648 } else if (stack_overflow_) { |
| 667 Top::StackOverflow(); | 649 Top::StackOverflow(); |
| 668 } | 650 } |
| 669 } | 651 } |
| 670 | 652 |
| 671 // Make sure the target stack is empty. | 653 // Make sure the target stack is empty. |
| 672 ASSERT(target_stack_ == NULL); | 654 ASSERT(target_stack_ == NULL); |
| 673 | 655 |
| 674 // If there was a syntax error we have to get rid of the AST | 656 // If there was a syntax error we have to get rid of the AST |
| 675 // and it is not safe to do so before the scope has been deleted. | 657 // and it is not safe to do so before the scope has been deleted. |
| 676 if (result == NULL) zone_scope->DeleteOnExit(); | 658 if (result == NULL) zone_scope.DeleteOnExit(); |
| 677 return result; | 659 return result; |
| 678 } | 660 } |
| 679 | 661 |
| 662 |
| 680 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { | 663 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { |
| 681 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); | 664 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); |
| 682 HistogramTimerScope timer(&Counters::parse_lazy); | 665 HistogramTimerScope timer(&Counters::parse_lazy); |
| 683 Handle<String> source(String::cast(script_->source())); | 666 Handle<String> source(String::cast(script_->source())); |
| 684 Counters::total_parse_size.Increment(source->length()); | 667 Counters::total_parse_size.Increment(source->length()); |
| 685 | 668 |
| 686 // Initialize parser state. | |
| 687 source->TryFlatten(); | |
| 688 if (source->IsExternalTwoByteString()) { | |
| 689 ExternalTwoByteStringUC16CharacterStream stream( | |
| 690 Handle<ExternalTwoByteString>::cast(source), | |
| 691 info->start_position(), | |
| 692 info->end_position()); | |
| 693 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); | |
| 694 return result; | |
| 695 } else { | |
| 696 GenericStringUC16CharacterStream stream(source, | |
| 697 info->start_position(), | |
| 698 info->end_position()); | |
| 699 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); | |
| 700 return result; | |
| 701 } | |
| 702 } | |
| 703 | |
| 704 | |
| 705 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info, | |
| 706 UC16CharacterStream* source, | |
| 707 ZoneScope* zone_scope) { | |
| 708 scanner_.Initialize(source, JavaScriptScanner::kAllLiterals); | |
| 709 ASSERT(target_stack_ == NULL); | |
| 710 | |
| 711 Handle<String> name(String::cast(info->name())); | 669 Handle<String> name(String::cast(info->name())); |
| 712 fni_ = new FuncNameInferrer(); | 670 fni_ = new FuncNameInferrer(); |
| 713 fni_->PushEnclosingName(name); | 671 fni_->PushEnclosingName(name); |
| 714 | 672 |
| 673 // Initialize parser state. |
| 674 source->TryFlatten(); |
| 675 scanner_.Initialize(source, info->start_position(), info->end_position()); |
| 676 ASSERT(target_stack_ == NULL); |
| 715 mode_ = PARSE_EAGERLY; | 677 mode_ = PARSE_EAGERLY; |
| 716 | 678 |
| 717 // Place holder for the result. | 679 // Place holder for the result. |
| 718 FunctionLiteral* result = NULL; | 680 FunctionLiteral* result = NULL; |
| 719 | 681 |
| 720 { | 682 { |
| 721 // Parse the function literal. | 683 // Parse the function literal. |
| 722 Handle<String> no_name = Factory::empty_symbol(); | 684 Handle<String> no_name = Factory::empty_symbol(); |
| 723 Scope* scope = | 685 Scope* scope = |
| 724 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); | 686 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 736 ASSERT(ok || stack_overflow_); | 698 ASSERT(ok || stack_overflow_); |
| 737 } | 699 } |
| 738 | 700 |
| 739 // Make sure the target stack is empty. | 701 // Make sure the target stack is empty. |
| 740 ASSERT(target_stack_ == NULL); | 702 ASSERT(target_stack_ == NULL); |
| 741 | 703 |
| 742 // If there was a stack overflow we have to get rid of AST and it is | 704 // If there was a stack overflow we have to get rid of AST and it is |
| 743 // not safe to do before scope has been deleted. | 705 // not safe to do before scope has been deleted. |
| 744 if (result == NULL) { | 706 if (result == NULL) { |
| 745 Top::StackOverflow(); | 707 Top::StackOverflow(); |
| 746 zone_scope->DeleteOnExit(); | 708 zone_scope.DeleteOnExit(); |
| 747 } else { | 709 } else { |
| 748 Handle<String> inferred_name(info->inferred_name()); | 710 Handle<String> inferred_name(info->inferred_name()); |
| 749 result->set_inferred_name(inferred_name); | 711 result->set_inferred_name(inferred_name); |
| 750 } | 712 } |
| 751 return result; | 713 return result; |
| 752 } | 714 } |
| 753 | 715 |
| 754 | 716 |
| 755 Handle<String> Parser::GetSymbol(bool* ok) { | 717 Handle<String> Parser::GetSymbol(bool* ok) { |
| 756 int symbol_id = -1; | 718 int symbol_id = -1; |
| 757 if (pre_data() != NULL) { | 719 if (pre_data() != NULL) { |
| 758 symbol_id = pre_data()->GetSymbolIdentifier(); | 720 symbol_id = pre_data()->GetSymbolIdentifier(); |
| 759 } | 721 } |
| 760 return LookupSymbol(symbol_id, scanner().literal()); | 722 return LookupSymbol(symbol_id, scanner_.literal()); |
| 761 } | 723 } |
| 762 | 724 |
| 763 | 725 |
| 764 void Parser::ReportMessage(const char* type, Vector<const char*> args) { | 726 void Parser::ReportMessage(const char* type, Vector<const char*> args) { |
| 765 Scanner::Location source_location = scanner().location(); | 727 Scanner::Location source_location = scanner_.location(); |
| 766 ReportMessageAt(source_location, type, args); | 728 ReportMessageAt(source_location, type, args); |
| 767 } | 729 } |
| 768 | 730 |
| 769 | 731 |
| 770 void Parser::ReportMessageAt(Scanner::Location source_location, | 732 void Parser::ReportMessageAt(Scanner::Location source_location, |
| 771 const char* type, | 733 const char* type, |
| 772 Vector<const char*> args) { | 734 Vector<const char*> args) { |
| 773 MessageLocation location(script_, | 735 MessageLocation location(script_, |
| 774 source_location.beg_pos, source_location.end_pos); | 736 source_location.beg_pos, source_location.end_pos); |
| 775 Handle<JSArray> array = Factory::NewJSArray(args.length()); | 737 Handle<JSArray> array = Factory::NewJSArray(args.length()); |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 } | 1634 } |
| 1673 | 1635 |
| 1674 | 1636 |
| 1675 Statement* Parser::ParseContinueStatement(bool* ok) { | 1637 Statement* Parser::ParseContinueStatement(bool* ok) { |
| 1676 // ContinueStatement :: | 1638 // ContinueStatement :: |
| 1677 // 'continue' Identifier? ';' | 1639 // 'continue' Identifier? ';' |
| 1678 | 1640 |
| 1679 Expect(Token::CONTINUE, CHECK_OK); | 1641 Expect(Token::CONTINUE, CHECK_OK); |
| 1680 Handle<String> label = Handle<String>::null(); | 1642 Handle<String> label = Handle<String>::null(); |
| 1681 Token::Value tok = peek(); | 1643 Token::Value tok = peek(); |
| 1682 if (!scanner().has_line_terminator_before_next() && | 1644 if (!scanner_.has_line_terminator_before_next() && |
| 1683 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1645 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 1684 label = ParseIdentifier(CHECK_OK); | 1646 label = ParseIdentifier(CHECK_OK); |
| 1685 } | 1647 } |
| 1686 IterationStatement* target = NULL; | 1648 IterationStatement* target = NULL; |
| 1687 target = LookupContinueTarget(label, CHECK_OK); | 1649 target = LookupContinueTarget(label, CHECK_OK); |
| 1688 if (target == NULL) { | 1650 if (target == NULL) { |
| 1689 // Illegal continue statement. To be consistent with KJS we delay | 1651 // Illegal continue statement. To be consistent with KJS we delay |
| 1690 // reporting of the syntax error until runtime. | 1652 // reporting of the syntax error until runtime. |
| 1691 Handle<String> error_type = Factory::illegal_continue_symbol(); | 1653 Handle<String> error_type = Factory::illegal_continue_symbol(); |
| 1692 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); | 1654 if (!label.is_null()) error_type = Factory::unknown_label_symbol(); |
| 1693 Expression* throw_error = NewThrowSyntaxError(error_type, label); | 1655 Expression* throw_error = NewThrowSyntaxError(error_type, label); |
| 1694 return new ExpressionStatement(throw_error); | 1656 return new ExpressionStatement(throw_error); |
| 1695 } | 1657 } |
| 1696 ExpectSemicolon(CHECK_OK); | 1658 ExpectSemicolon(CHECK_OK); |
| 1697 return new ContinueStatement(target); | 1659 return new ContinueStatement(target); |
| 1698 } | 1660 } |
| 1699 | 1661 |
| 1700 | 1662 |
| 1701 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { | 1663 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { |
| 1702 // BreakStatement :: | 1664 // BreakStatement :: |
| 1703 // 'break' Identifier? ';' | 1665 // 'break' Identifier? ';' |
| 1704 | 1666 |
| 1705 Expect(Token::BREAK, CHECK_OK); | 1667 Expect(Token::BREAK, CHECK_OK); |
| 1706 Handle<String> label; | 1668 Handle<String> label; |
| 1707 Token::Value tok = peek(); | 1669 Token::Value tok = peek(); |
| 1708 if (!scanner().has_line_terminator_before_next() && | 1670 if (!scanner_.has_line_terminator_before_next() && |
| 1709 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { | 1671 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { |
| 1710 label = ParseIdentifier(CHECK_OK); | 1672 label = ParseIdentifier(CHECK_OK); |
| 1711 } | 1673 } |
| 1712 // Parse labeled break statements that target themselves into | 1674 // Parse labeled break statements that target themselves into |
| 1713 // empty statements, e.g. 'l1: l2: l3: break l2;' | 1675 // empty statements, e.g. 'l1: l2: l3: break l2;' |
| 1714 if (!label.is_null() && ContainsLabel(labels, label)) { | 1676 if (!label.is_null() && ContainsLabel(labels, label)) { |
| 1715 return EmptyStatement(); | 1677 return EmptyStatement(); |
| 1716 } | 1678 } |
| 1717 BreakableStatement* target = NULL; | 1679 BreakableStatement* target = NULL; |
| 1718 target = LookupBreakTarget(label, CHECK_OK); | 1680 target = LookupBreakTarget(label, CHECK_OK); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1743 // function. See ECMA-262, section 12.9, page 67. | 1705 // function. See ECMA-262, section 12.9, page 67. |
| 1744 // | 1706 // |
| 1745 // To be consistent with KJS we report the syntax error at runtime. | 1707 // To be consistent with KJS we report the syntax error at runtime. |
| 1746 if (!top_scope_->is_function_scope()) { | 1708 if (!top_scope_->is_function_scope()) { |
| 1747 Handle<String> type = Factory::illegal_return_symbol(); | 1709 Handle<String> type = Factory::illegal_return_symbol(); |
| 1748 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); | 1710 Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null()); |
| 1749 return new ExpressionStatement(throw_error); | 1711 return new ExpressionStatement(throw_error); |
| 1750 } | 1712 } |
| 1751 | 1713 |
| 1752 Token::Value tok = peek(); | 1714 Token::Value tok = peek(); |
| 1753 if (scanner().has_line_terminator_before_next() || | 1715 if (scanner_.has_line_terminator_before_next() || |
| 1754 tok == Token::SEMICOLON || | 1716 tok == Token::SEMICOLON || |
| 1755 tok == Token::RBRACE || | 1717 tok == Token::RBRACE || |
| 1756 tok == Token::EOS) { | 1718 tok == Token::EOS) { |
| 1757 ExpectSemicolon(CHECK_OK); | 1719 ExpectSemicolon(CHECK_OK); |
| 1758 return new ReturnStatement(GetLiteralUndefined()); | 1720 return new ReturnStatement(GetLiteralUndefined()); |
| 1759 } | 1721 } |
| 1760 | 1722 |
| 1761 Expression* expr = ParseExpression(true, CHECK_OK); | 1723 Expression* expr = ParseExpression(true, CHECK_OK); |
| 1762 ExpectSemicolon(CHECK_OK); | 1724 ExpectSemicolon(CHECK_OK); |
| 1763 return new ReturnStatement(expr); | 1725 return new ReturnStatement(expr); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 return statement; | 1837 return statement; |
| 1876 } | 1838 } |
| 1877 | 1839 |
| 1878 | 1840 |
| 1879 Statement* Parser::ParseThrowStatement(bool* ok) { | 1841 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 1880 // ThrowStatement :: | 1842 // ThrowStatement :: |
| 1881 // 'throw' Expression ';' | 1843 // 'throw' Expression ';' |
| 1882 | 1844 |
| 1883 Expect(Token::THROW, CHECK_OK); | 1845 Expect(Token::THROW, CHECK_OK); |
| 1884 int pos = scanner().location().beg_pos; | 1846 int pos = scanner().location().beg_pos; |
| 1885 if (scanner().has_line_terminator_before_next()) { | 1847 if (scanner_.has_line_terminator_before_next()) { |
| 1886 ReportMessage("newline_after_throw", Vector<const char*>::empty()); | 1848 ReportMessage("newline_after_throw", Vector<const char*>::empty()); |
| 1887 *ok = false; | 1849 *ok = false; |
| 1888 return NULL; | 1850 return NULL; |
| 1889 } | 1851 } |
| 1890 Expression* exception = ParseExpression(true, CHECK_OK); | 1852 Expression* exception = ParseExpression(true, CHECK_OK); |
| 1891 ExpectSemicolon(CHECK_OK); | 1853 ExpectSemicolon(CHECK_OK); |
| 1892 | 1854 |
| 1893 return new ExpressionStatement(new Throw(exception, pos)); | 1855 return new ExpressionStatement(new Throw(exception, pos)); |
| 1894 } | 1856 } |
| 1895 | 1857 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2439 return ParsePostfixExpression(ok); | 2401 return ParsePostfixExpression(ok); |
| 2440 } | 2402 } |
| 2441 } | 2403 } |
| 2442 | 2404 |
| 2443 | 2405 |
| 2444 Expression* Parser::ParsePostfixExpression(bool* ok) { | 2406 Expression* Parser::ParsePostfixExpression(bool* ok) { |
| 2445 // PostfixExpression :: | 2407 // PostfixExpression :: |
| 2446 // LeftHandSideExpression ('++' | '--')? | 2408 // LeftHandSideExpression ('++' | '--')? |
| 2447 | 2409 |
| 2448 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); | 2410 Expression* expression = ParseLeftHandSideExpression(CHECK_OK); |
| 2449 if (!scanner().has_line_terminator_before_next() && | 2411 if (!scanner_.has_line_terminator_before_next() && Token::IsCountOp(peek())) { |
| 2450 Token::IsCountOp(peek())) { | |
| 2451 // Signal a reference error if the expression is an invalid | 2412 // Signal a reference error if the expression is an invalid |
| 2452 // left-hand side expression. We could report this as a syntax | 2413 // left-hand side expression. We could report this as a syntax |
| 2453 // error here but for compatibility with JSC we choose to report the | 2414 // error here but for compatibility with JSC we choose to report the |
| 2454 // error at runtime. | 2415 // error at runtime. |
| 2455 if (expression == NULL || !expression->IsValidLeftHandSide()) { | 2416 if (expression == NULL || !expression->IsValidLeftHandSide()) { |
| 2456 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); | 2417 Handle<String> type = Factory::invalid_lhs_in_postfix_op_symbol(); |
| 2457 expression = NewThrowReferenceError(type); | 2418 expression = NewThrowReferenceError(type); |
| 2458 } | 2419 } |
| 2459 Token::Value next = Next(); | 2420 Token::Value next = Next(); |
| 2460 int position = scanner().location().beg_pos; | 2421 int position = scanner().location().beg_pos; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2709 case Token::IDENTIFIER: { | 2670 case Token::IDENTIFIER: { |
| 2710 Handle<String> name = ParseIdentifier(CHECK_OK); | 2671 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 2711 if (fni_ != NULL) fni_->PushVariableName(name); | 2672 if (fni_ != NULL) fni_->PushVariableName(name); |
| 2712 result = top_scope_->NewUnresolved(name, inside_with()); | 2673 result = top_scope_->NewUnresolved(name, inside_with()); |
| 2713 break; | 2674 break; |
| 2714 } | 2675 } |
| 2715 | 2676 |
| 2716 case Token::NUMBER: { | 2677 case Token::NUMBER: { |
| 2717 Consume(Token::NUMBER); | 2678 Consume(Token::NUMBER); |
| 2718 double value = | 2679 double value = |
| 2719 StringToDouble(scanner().literal(), ALLOW_HEX | ALLOW_OCTALS); | 2680 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS); |
| 2720 result = NewNumberLiteral(value); | 2681 result = NewNumberLiteral(value); |
| 2721 break; | 2682 break; |
| 2722 } | 2683 } |
| 2723 | 2684 |
| 2724 case Token::STRING: { | 2685 case Token::STRING: { |
| 2725 Consume(Token::STRING); | 2686 Consume(Token::STRING); |
| 2726 Handle<String> symbol = GetSymbol(CHECK_OK); | 2687 Handle<String> symbol = GetSymbol(CHECK_OK); |
| 2727 result = new Literal(symbol); | 2688 result = new Literal(symbol); |
| 2728 if (fni_ != NULL) fni_->PushLiteralName(symbol); | 2689 if (fni_ != NULL) fni_->PushLiteralName(symbol); |
| 2729 break; | 2690 break; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3060 if (!string.is_null() && string->AsArrayIndex(&index)) { | 3021 if (!string.is_null() && string->AsArrayIndex(&index)) { |
| 3061 key = NewNumberLiteral(index); | 3022 key = NewNumberLiteral(index); |
| 3062 break; | 3023 break; |
| 3063 } | 3024 } |
| 3064 key = new Literal(string); | 3025 key = new Literal(string); |
| 3065 break; | 3026 break; |
| 3066 } | 3027 } |
| 3067 case Token::NUMBER: { | 3028 case Token::NUMBER: { |
| 3068 Consume(Token::NUMBER); | 3029 Consume(Token::NUMBER); |
| 3069 double value = | 3030 double value = |
| 3070 StringToDouble(scanner().literal(), ALLOW_HEX | ALLOW_OCTALS); | 3031 StringToDouble(scanner_.literal(), ALLOW_HEX | ALLOW_OCTALS); |
| 3071 key = NewNumberLiteral(value); | 3032 key = NewNumberLiteral(value); |
| 3072 break; | 3033 break; |
| 3073 } | 3034 } |
| 3074 default: | 3035 default: |
| 3075 if (Token::IsKeyword(next)) { | 3036 if (Token::IsKeyword(next)) { |
| 3076 Consume(next); | 3037 Consume(next); |
| 3077 Handle<String> string = GetSymbol(CHECK_OK); | 3038 Handle<String> string = GetSymbol(CHECK_OK); |
| 3078 key = new Literal(string); | 3039 key = new Literal(string); |
| 3079 } else { | 3040 } else { |
| 3080 // Unexpected token. | 3041 // Unexpected token. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3121 return new ObjectLiteral(constant_properties, | 3082 return new ObjectLiteral(constant_properties, |
| 3122 properties, | 3083 properties, |
| 3123 literal_index, | 3084 literal_index, |
| 3124 is_simple, | 3085 is_simple, |
| 3125 fast_elements, | 3086 fast_elements, |
| 3126 depth); | 3087 depth); |
| 3127 } | 3088 } |
| 3128 | 3089 |
| 3129 | 3090 |
| 3130 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { | 3091 Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) { |
| 3131 if (!scanner().ScanRegExpPattern(seen_equal)) { | 3092 if (!scanner_.ScanRegExpPattern(seen_equal)) { |
| 3132 Next(); | 3093 Next(); |
| 3133 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); | 3094 ReportMessage("unterminated_regexp", Vector<const char*>::empty()); |
| 3134 *ok = false; | 3095 *ok = false; |
| 3135 return NULL; | 3096 return NULL; |
| 3136 } | 3097 } |
| 3137 | 3098 |
| 3138 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); | 3099 int literal_index = temp_scope_->NextMaterializedLiteralIndex(); |
| 3139 | 3100 |
| 3140 Handle<String> js_pattern = | 3101 Handle<String> js_pattern = |
| 3141 Factory::NewStringFromUtf8(scanner().next_literal(), TENURED); | 3102 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED); |
| 3142 scanner().ScanRegExpFlags(); | 3103 scanner_.ScanRegExpFlags(); |
| 3143 Handle<String> js_flags = | 3104 Handle<String> js_flags = |
| 3144 Factory::NewStringFromUtf8(scanner().next_literal(), TENURED); | 3105 Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED); |
| 3145 Next(); | 3106 Next(); |
| 3146 | 3107 |
| 3147 return new RegExpLiteral(js_pattern, js_flags, literal_index); | 3108 return new RegExpLiteral(js_pattern, js_flags, literal_index); |
| 3148 } | 3109 } |
| 3149 | 3110 |
| 3150 | 3111 |
| 3151 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { | 3112 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { |
| 3152 // Arguments :: | 3113 // Arguments :: |
| 3153 // '(' (AssignmentExpression)*[','] ')' | 3114 // '(' (AssignmentExpression)*[','] ')' |
| 3154 | 3115 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3190 { Scope* scope = | 3151 { Scope* scope = |
| 3191 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); | 3152 NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with()); |
| 3192 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, | 3153 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, |
| 3193 scope); | 3154 scope); |
| 3194 TemporaryScope temp_scope(&this->temp_scope_); | 3155 TemporaryScope temp_scope(&this->temp_scope_); |
| 3195 top_scope_->SetScopeName(name); | 3156 top_scope_->SetScopeName(name); |
| 3196 | 3157 |
| 3197 // FormalParameterList :: | 3158 // FormalParameterList :: |
| 3198 // '(' (Identifier)*[','] ')' | 3159 // '(' (Identifier)*[','] ')' |
| 3199 Expect(Token::LPAREN, CHECK_OK); | 3160 Expect(Token::LPAREN, CHECK_OK); |
| 3200 int start_pos = scanner().location().beg_pos; | 3161 int start_pos = scanner_.location().beg_pos; |
| 3201 bool done = (peek() == Token::RPAREN); | 3162 bool done = (peek() == Token::RPAREN); |
| 3202 while (!done) { | 3163 while (!done) { |
| 3203 Handle<String> param_name = ParseIdentifier(CHECK_OK); | 3164 Handle<String> param_name = ParseIdentifier(CHECK_OK); |
| 3204 top_scope_->AddParameter(top_scope_->DeclareLocal(param_name, | 3165 top_scope_->AddParameter(top_scope_->DeclareLocal(param_name, |
| 3205 Variable::VAR)); | 3166 Variable::VAR)); |
| 3206 num_parameters++; | 3167 num_parameters++; |
| 3207 done = (peek() == Token::RPAREN); | 3168 done = (peek() == Token::RPAREN); |
| 3208 if (!done) Expect(Token::COMMA, CHECK_OK); | 3169 if (!done) Expect(Token::COMMA, CHECK_OK); |
| 3209 } | 3170 } |
| 3210 Expect(Token::RPAREN, CHECK_OK); | 3171 Expect(Token::RPAREN, CHECK_OK); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3227 new Assignment(Token::INIT_CONST, fproxy, | 3188 new Assignment(Token::INIT_CONST, fproxy, |
| 3228 new ThisFunction(), | 3189 new ThisFunction(), |
| 3229 RelocInfo::kNoPosition))); | 3190 RelocInfo::kNoPosition))); |
| 3230 } | 3191 } |
| 3231 | 3192 |
| 3232 // Determine if the function will be lazily compiled. The mode can | 3193 // Determine if the function will be lazily compiled. The mode can |
| 3233 // only be PARSE_LAZILY if the --lazy flag is true. | 3194 // only be PARSE_LAZILY if the --lazy flag is true. |
| 3234 bool is_lazily_compiled = | 3195 bool is_lazily_compiled = |
| 3235 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext(); | 3196 mode() == PARSE_LAZILY && top_scope_->HasTrivialOuterContext(); |
| 3236 | 3197 |
| 3237 int function_block_pos = scanner().location().beg_pos; | 3198 int function_block_pos = scanner_.location().beg_pos; |
| 3238 int materialized_literal_count; | 3199 int materialized_literal_count; |
| 3239 int expected_property_count; | 3200 int expected_property_count; |
| 3240 int end_pos; | 3201 int end_pos; |
| 3241 bool only_simple_this_property_assignments; | 3202 bool only_simple_this_property_assignments; |
| 3242 Handle<FixedArray> this_property_assignments; | 3203 Handle<FixedArray> this_property_assignments; |
| 3243 if (is_lazily_compiled && pre_data() != NULL) { | 3204 if (is_lazily_compiled && pre_data() != NULL) { |
| 3244 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); | 3205 FunctionEntry entry = pre_data()->GetFunctionEntry(function_block_pos); |
| 3245 if (!entry.is_valid()) { | 3206 if (!entry.is_valid()) { |
| 3246 ReportInvalidPreparseData(name, CHECK_OK); | 3207 ReportInvalidPreparseData(name, CHECK_OK); |
| 3247 } | 3208 } |
| 3248 end_pos = entry.end_pos(); | 3209 end_pos = entry.end_pos(); |
| 3249 if (end_pos <= function_block_pos) { | 3210 if (end_pos <= function_block_pos) { |
| 3250 // End position greater than end of stream is safe, and hard to check. | 3211 // End position greater than end of stream is safe, and hard to check. |
| 3251 ReportInvalidPreparseData(name, CHECK_OK); | 3212 ReportInvalidPreparseData(name, CHECK_OK); |
| 3252 } | 3213 } |
| 3253 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); | 3214 Counters::total_preparse_skipped.Increment(end_pos - function_block_pos); |
| 3254 // Seek to position just before terminal '}'. | 3215 scanner_.SeekForward(end_pos); |
| 3255 scanner().SeekForward(end_pos - 1); | |
| 3256 materialized_literal_count = entry.literal_count(); | 3216 materialized_literal_count = entry.literal_count(); |
| 3257 expected_property_count = entry.property_count(); | 3217 expected_property_count = entry.property_count(); |
| 3258 only_simple_this_property_assignments = false; | 3218 only_simple_this_property_assignments = false; |
| 3259 this_property_assignments = Factory::empty_fixed_array(); | 3219 this_property_assignments = Factory::empty_fixed_array(); |
| 3260 Expect(Token::RBRACE, CHECK_OK); | 3220 Expect(Token::RBRACE, CHECK_OK); |
| 3261 } else { | 3221 } else { |
| 3262 ParseSourceElements(body, Token::RBRACE, CHECK_OK); | 3222 ParseSourceElements(body, Token::RBRACE, CHECK_OK); |
| 3263 | 3223 |
| 3264 materialized_literal_count = temp_scope.materialized_literal_count(); | 3224 materialized_literal_count = temp_scope.materialized_literal_count(); |
| 3265 expected_property_count = temp_scope.expected_property_count(); | 3225 expected_property_count = temp_scope.expected_property_count(); |
| 3266 only_simple_this_property_assignments = | 3226 only_simple_this_property_assignments = |
| 3267 temp_scope.only_simple_this_property_assignments(); | 3227 temp_scope.only_simple_this_property_assignments(); |
| 3268 this_property_assignments = temp_scope.this_property_assignments(); | 3228 this_property_assignments = temp_scope.this_property_assignments(); |
| 3269 | 3229 |
| 3270 Expect(Token::RBRACE, CHECK_OK); | 3230 Expect(Token::RBRACE, CHECK_OK); |
| 3271 end_pos = scanner().location().end_pos; | 3231 end_pos = scanner_.location().end_pos; |
| 3272 } | 3232 } |
| 3273 | 3233 |
| 3274 FunctionLiteral* function_literal = | 3234 FunctionLiteral* function_literal = |
| 3275 new FunctionLiteral(name, | 3235 new FunctionLiteral(name, |
| 3276 top_scope_, | 3236 top_scope_, |
| 3277 body, | 3237 body, |
| 3278 materialized_literal_count, | 3238 materialized_literal_count, |
| 3279 expected_property_count, | 3239 expected_property_count, |
| 3280 only_simple_this_property_assignments, | 3240 only_simple_this_property_assignments, |
| 3281 this_property_assignments, | 3241 this_property_assignments, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3365 | 3325 |
| 3366 | 3326 |
| 3367 void Parser::ExpectSemicolon(bool* ok) { | 3327 void Parser::ExpectSemicolon(bool* ok) { |
| 3368 // Check for automatic semicolon insertion according to | 3328 // Check for automatic semicolon insertion according to |
| 3369 // the rules given in ECMA-262, section 7.9, page 21. | 3329 // the rules given in ECMA-262, section 7.9, page 21. |
| 3370 Token::Value tok = peek(); | 3330 Token::Value tok = peek(); |
| 3371 if (tok == Token::SEMICOLON) { | 3331 if (tok == Token::SEMICOLON) { |
| 3372 Next(); | 3332 Next(); |
| 3373 return; | 3333 return; |
| 3374 } | 3334 } |
| 3375 if (scanner().has_line_terminator_before_next() || | 3335 if (scanner_.has_line_terminator_before_next() || |
| 3376 tok == Token::RBRACE || | 3336 tok == Token::RBRACE || |
| 3377 tok == Token::EOS) { | 3337 tok == Token::EOS) { |
| 3378 return; | 3338 return; |
| 3379 } | 3339 } |
| 3380 Expect(Token::SEMICOLON, ok); | 3340 Expect(Token::SEMICOLON, ok); |
| 3381 } | 3341 } |
| 3382 | 3342 |
| 3383 | 3343 |
| 3384 Literal* Parser::GetLiteralUndefined() { | 3344 Literal* Parser::GetLiteralUndefined() { |
| 3385 return new Literal(Factory::undefined_value()); | 3345 return new Literal(Factory::undefined_value()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3416 | 3376 |
| 3417 // This function reads an identifier and determines whether or not it | 3377 // This function reads an identifier and determines whether or not it |
| 3418 // is 'get' or 'set'. The reason for not using ParseIdentifier and | 3378 // is 'get' or 'set'. The reason for not using ParseIdentifier and |
| 3419 // checking on the output is that this involves heap allocation which | 3379 // checking on the output is that this involves heap allocation which |
| 3420 // we can't do during preparsing. | 3380 // we can't do during preparsing. |
| 3421 Handle<String> Parser::ParseIdentifierOrGetOrSet(bool* is_get, | 3381 Handle<String> Parser::ParseIdentifierOrGetOrSet(bool* is_get, |
| 3422 bool* is_set, | 3382 bool* is_set, |
| 3423 bool* ok) { | 3383 bool* ok) { |
| 3424 Expect(Token::IDENTIFIER, ok); | 3384 Expect(Token::IDENTIFIER, ok); |
| 3425 if (!*ok) return Handle<String>(); | 3385 if (!*ok) return Handle<String>(); |
| 3426 if (scanner().literal_length() == 3) { | 3386 if (scanner_.literal_length() == 3) { |
| 3427 const char* token = scanner().literal_string(); | 3387 const char* token = scanner_.literal_string(); |
| 3428 *is_get = strcmp(token, "get") == 0; | 3388 *is_get = strcmp(token, "get") == 0; |
| 3429 *is_set = !*is_get && strcmp(token, "set") == 0; | 3389 *is_set = !*is_get && strcmp(token, "set") == 0; |
| 3430 } | 3390 } |
| 3431 return GetSymbol(ok); | 3391 return GetSymbol(ok); |
| 3432 } | 3392 } |
| 3433 | 3393 |
| 3434 | 3394 |
| 3435 // ---------------------------------------------------------------------------- | 3395 // ---------------------------------------------------------------------------- |
| 3436 // Parser support | 3396 // Parser support |
| 3437 | 3397 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3536 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); | 3496 ZoneList<Expression*>* args = new ZoneList<Expression*>(2); |
| 3537 args->Add(new Literal(type)); | 3497 args->Add(new Literal(type)); |
| 3538 args->Add(new Literal(array)); | 3498 args->Add(new Literal(array)); |
| 3539 return new Throw(new CallRuntime(constructor, NULL, args), | 3499 return new Throw(new CallRuntime(constructor, NULL, args), |
| 3540 scanner().location().beg_pos); | 3500 scanner().location().beg_pos); |
| 3541 } | 3501 } |
| 3542 | 3502 |
| 3543 // ---------------------------------------------------------------------------- | 3503 // ---------------------------------------------------------------------------- |
| 3544 // JSON | 3504 // JSON |
| 3545 | 3505 |
| 3546 Handle<Object> JsonParser::ParseJson(Handle<String> script, | 3506 Handle<Object> JsonParser::ParseJson(Handle<String> source) { |
| 3547 UC16CharacterStream* source) { | 3507 source->TryFlatten(); |
| 3548 scanner_.Initialize(source); | 3508 scanner_.Initialize(source); |
| 3549 stack_overflow_ = false; | 3509 stack_overflow_ = false; |
| 3550 Handle<Object> result = ParseJsonValue(); | 3510 Handle<Object> result = ParseJsonValue(); |
| 3551 if (result.is_null() || scanner_.Next() != Token::EOS) { | 3511 if (result.is_null() || scanner_.Next() != Token::EOS) { |
| 3552 if (stack_overflow_) { | 3512 if (stack_overflow_) { |
| 3553 // Scanner failed. | 3513 // Scanner failed. |
| 3554 Top::StackOverflow(); | 3514 Top::StackOverflow(); |
| 3555 } else { | 3515 } else { |
| 3556 // Parse failed. Scanner's current token is the unexpected token. | 3516 // Parse failed. Scanner's current token is the unexpected token. |
| 3557 Token::Value token = scanner_.current_token(); | 3517 Token::Value token = scanner_.current_token(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3573 message = "unexpected_token_identifier"; | 3533 message = "unexpected_token_identifier"; |
| 3574 break; | 3534 break; |
| 3575 default: | 3535 default: |
| 3576 message = "unexpected_token"; | 3536 message = "unexpected_token"; |
| 3577 name_opt = Token::String(token); | 3537 name_opt = Token::String(token); |
| 3578 ASSERT(name_opt != NULL); | 3538 ASSERT(name_opt != NULL); |
| 3579 break; | 3539 break; |
| 3580 } | 3540 } |
| 3581 | 3541 |
| 3582 Scanner::Location source_location = scanner_.location(); | 3542 Scanner::Location source_location = scanner_.location(); |
| 3583 MessageLocation location(Factory::NewScript(script), | 3543 MessageLocation location(Factory::NewScript(source), |
| 3584 source_location.beg_pos, | 3544 source_location.beg_pos, |
| 3585 source_location.end_pos); | 3545 source_location.end_pos); |
| 3586 int argc = (name_opt == NULL) ? 0 : 1; | 3546 int argc = (name_opt == NULL) ? 0 : 1; |
| 3587 Handle<JSArray> array = Factory::NewJSArray(argc); | 3547 Handle<JSArray> array = Factory::NewJSArray(argc); |
| 3588 if (name_opt != NULL) { | 3548 if (name_opt != NULL) { |
| 3589 SetElement(array, | 3549 SetElement(array, |
| 3590 0, | 3550 0, |
| 3591 Factory::NewStringFromUtf8(CStrVector(name_opt))); | 3551 Factory::NewStringFromUtf8(CStrVector(name_opt))); |
| 3592 } | 3552 } |
| 3593 Handle<Object> result = Factory::NewSyntaxError(message, array); | 3553 Handle<Object> result = Factory::NewSyntaxError(message, array); |
| (...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4442 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); | 4402 uc32 c = ParseClassCharacterEscape(CHECK_FAILED); |
| 4443 return CharacterRange::Singleton(c); | 4403 return CharacterRange::Singleton(c); |
| 4444 } | 4404 } |
| 4445 } else { | 4405 } else { |
| 4446 Advance(); | 4406 Advance(); |
| 4447 return CharacterRange::Singleton(first); | 4407 return CharacterRange::Singleton(first); |
| 4448 } | 4408 } |
| 4449 } | 4409 } |
| 4450 | 4410 |
| 4451 | 4411 |
| 4452 static const uc16 kNoCharClass = 0; | |
| 4453 | |
| 4454 // Adds range or pre-defined character class to character ranges. | |
| 4455 // If char_class is not kInvalidClass, it's interpreted as a class | |
| 4456 // escape (i.e., 's' means whitespace, from '\s'). | |
| 4457 static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, | |
| 4458 uc16 char_class, | |
| 4459 CharacterRange range) { | |
| 4460 if (char_class != kNoCharClass) { | |
| 4461 CharacterRange::AddClassEscape(char_class, ranges); | |
| 4462 } else { | |
| 4463 ranges->Add(range); | |
| 4464 } | |
| 4465 } | |
| 4466 | |
| 4467 | |
| 4468 RegExpTree* RegExpParser::ParseCharacterClass() { | 4412 RegExpTree* RegExpParser::ParseCharacterClass() { |
| 4469 static const char* kUnterminated = "Unterminated character class"; | 4413 static const char* kUnterminated = "Unterminated character class"; |
| 4470 static const char* kRangeOutOfOrder = "Range out of order in character class"; | 4414 static const char* kRangeOutOfOrder = "Range out of order in character class"; |
| 4415 static const char* kInvalidRange = "Invalid character range"; |
| 4471 | 4416 |
| 4472 ASSERT_EQ(current(), '['); | 4417 ASSERT_EQ(current(), '['); |
| 4473 Advance(); | 4418 Advance(); |
| 4474 bool is_negated = false; | 4419 bool is_negated = false; |
| 4475 if (current() == '^') { | 4420 if (current() == '^') { |
| 4476 is_negated = true; | 4421 is_negated = true; |
| 4477 Advance(); | 4422 Advance(); |
| 4478 } | 4423 } |
| 4424 // A CharacterClass is a sequence of single characters, character class |
| 4425 // escapes or ranges. Ranges are on the form "x-y" where x and y are |
| 4426 // single characters (and not character class escapes like \s). |
| 4427 // A "-" may occur at the start or end of the character class (just after |
| 4428 // "[" or "[^", or just before "]") without being considered part of a |
| 4429 // range. A "-" may also appear as the beginning or end of a range. |
| 4430 // I.e., [--+] is valid, so is [!--]. |
| 4431 |
| 4479 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); | 4432 ZoneList<CharacterRange>* ranges = new ZoneList<CharacterRange>(2); |
| 4480 while (has_more() && current() != ']') { | 4433 while (has_more() && current() != ']') { |
| 4481 uc16 char_class = kNoCharClass; | 4434 uc16 char_class = 0; |
| 4482 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); | 4435 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
| 4436 if (char_class) { |
| 4437 CharacterRange::AddClassEscape(char_class, ranges); |
| 4438 if (current() == '-') { |
| 4439 Advance(); |
| 4440 ranges->Add(CharacterRange::Singleton('-')); |
| 4441 if (current() != ']') { |
| 4442 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); |
| 4443 } |
| 4444 break; |
| 4445 } |
| 4446 continue; |
| 4447 } |
| 4483 if (current() == '-') { | 4448 if (current() == '-') { |
| 4484 Advance(); | 4449 Advance(); |
| 4485 if (current() == kEndMarker) { | 4450 if (current() == kEndMarker) { |
| 4486 // If we reach the end we break out of the loop and let the | 4451 // If we reach the end we break out of the loop and let the |
| 4487 // following code report an error. | 4452 // following code report an error. |
| 4488 break; | 4453 break; |
| 4489 } else if (current() == ']') { | 4454 } else if (current() == ']') { |
| 4490 AddRangeOrEscape(ranges, char_class, first); | 4455 ranges->Add(first); |
| 4491 ranges->Add(CharacterRange::Singleton('-')); | 4456 ranges->Add(CharacterRange::Singleton('-')); |
| 4492 break; | 4457 break; |
| 4493 } | 4458 } |
| 4494 uc16 char_class_2 = kNoCharClass; | 4459 CharacterRange next = ParseClassAtom(&char_class CHECK_FAILED); |
| 4495 CharacterRange next = ParseClassAtom(&char_class_2 CHECK_FAILED); | 4460 if (char_class) { |
| 4496 if (char_class != kNoCharClass || char_class_2 != kNoCharClass) { | 4461 ReportError(CStrVector(kInvalidRange) CHECK_FAILED); |
| 4497 // Either end is an escaped character class. Treat the '-' verbatim. | |
| 4498 AddRangeOrEscape(ranges, char_class, first); | |
| 4499 ranges->Add(CharacterRange::Singleton('-')); | |
| 4500 AddRangeOrEscape(ranges, char_class_2, next); | |
| 4501 continue; | |
| 4502 } | 4462 } |
| 4503 if (first.from() > next.to()) { | 4463 if (first.from() > next.to()) { |
| 4504 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); | 4464 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); |
| 4505 } | 4465 } |
| 4506 ranges->Add(CharacterRange::Range(first.from(), next.to())); | 4466 ranges->Add(CharacterRange::Range(first.from(), next.to())); |
| 4507 } else { | 4467 } else { |
| 4508 AddRangeOrEscape(ranges, char_class, first); | 4468 ranges->Add(first); |
| 4509 } | 4469 } |
| 4510 } | 4470 } |
| 4511 if (!has_more()) { | 4471 if (!has_more()) { |
| 4512 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); | 4472 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); |
| 4513 } | 4473 } |
| 4514 Advance(); | 4474 Advance(); |
| 4515 if (ranges->length() == 0) { | 4475 if (ranges->length() == 0) { |
| 4516 ranges->Add(CharacterRange::Everything()); | 4476 ranges->Add(CharacterRange::Everything()); |
| 4517 is_negated = !is_negated; | 4477 is_negated = !is_negated; |
| 4518 } | 4478 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4588 input = *data; | 4548 input = *data; |
| 4589 result = (result << 7) | (input & 0x7f); | 4549 result = (result << 7) | (input & 0x7f); |
| 4590 data++; | 4550 data++; |
| 4591 } | 4551 } |
| 4592 *source = data; | 4552 *source = data; |
| 4593 return result; | 4553 return result; |
| 4594 } | 4554 } |
| 4595 | 4555 |
| 4596 | 4556 |
| 4597 // Create a Scanner for the preparser to use as input, and preparse the source. | 4557 // Create a Scanner for the preparser to use as input, and preparse the source. |
| 4598 static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, | 4558 static ScriptDataImpl* DoPreParse(Handle<String> source, |
| 4559 unibrow::CharacterStream* stream, |
| 4599 bool allow_lazy, | 4560 bool allow_lazy, |
| 4600 ParserRecorder* recorder, | 4561 ParserRecorder* recorder, |
| 4601 int literal_flags) { | 4562 int literal_flags) { |
| 4602 V8JavaScriptScanner scanner; | 4563 V8JavaScriptScanner scanner; |
| 4603 scanner.Initialize(source, literal_flags); | 4564 scanner.Initialize(source, stream, literal_flags); |
| 4604 intptr_t stack_limit = StackGuard::real_climit(); | 4565 intptr_t stack_limit = StackGuard::real_climit(); |
| 4605 if (!preparser::PreParser::PreParseProgram(&scanner, | 4566 if (!preparser::PreParser::PreParseProgram(&scanner, |
| 4606 recorder, | 4567 recorder, |
| 4607 allow_lazy, | 4568 allow_lazy, |
| 4608 stack_limit)) { | 4569 stack_limit)) { |
| 4609 Top::StackOverflow(); | 4570 Top::StackOverflow(); |
| 4610 return NULL; | 4571 return NULL; |
| 4611 } | 4572 } |
| 4612 | 4573 |
| 4613 // Extract the accumulated data from the recorder as a single | 4574 // Extract the accumulated data from the recorder as a single |
| 4614 // contiguous vector that we are responsible for disposing. | 4575 // contiguous vector that we are responsible for disposing. |
| 4615 Vector<unsigned> store = recorder->ExtractData(); | 4576 Vector<unsigned> store = recorder->ExtractData(); |
| 4616 return new ScriptDataImpl(store); | 4577 return new ScriptDataImpl(store); |
| 4617 } | 4578 } |
| 4618 | 4579 |
| 4619 | 4580 |
| 4620 // Preparse, but only collect data that is immediately useful, | 4581 // Preparse, but only collect data that is immediately useful, |
| 4621 // even if the preparser data is only used once. | 4582 // even if the preparser data is only used once. |
| 4622 ScriptDataImpl* ParserApi::PartialPreParse(UC16CharacterStream* source, | 4583 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source, |
| 4584 unibrow::CharacterStream* stream, |
| 4623 v8::Extension* extension) { | 4585 v8::Extension* extension) { |
| 4624 bool allow_lazy = FLAG_lazy && (extension == NULL); | 4586 bool allow_lazy = FLAG_lazy && (extension == NULL); |
| 4625 if (!allow_lazy) { | 4587 if (!allow_lazy) { |
| 4626 // Partial preparsing is only about lazily compiled functions. | 4588 // Partial preparsing is only about lazily compiled functions. |
| 4627 // If we don't allow lazy compilation, the log data will be empty. | 4589 // If we don't allow lazy compilation, the log data will be empty. |
| 4628 return NULL; | 4590 return NULL; |
| 4629 } | 4591 } |
| 4630 PartialParserRecorder recorder; | 4592 PartialParserRecorder recorder; |
| 4631 return DoPreParse(source, allow_lazy, &recorder, | 4593 |
| 4594 return DoPreParse(source, stream, allow_lazy, &recorder, |
| 4632 JavaScriptScanner::kNoLiterals); | 4595 JavaScriptScanner::kNoLiterals); |
| 4633 } | 4596 } |
| 4634 | 4597 |
| 4635 | 4598 |
| 4636 ScriptDataImpl* ParserApi::PreParse(UC16CharacterStream* source, | 4599 ScriptDataImpl* ParserApi::PreParse(Handle<String> source, |
| 4600 unibrow::CharacterStream* stream, |
| 4637 v8::Extension* extension) { | 4601 v8::Extension* extension) { |
| 4638 Handle<Script> no_script; | 4602 Handle<Script> no_script; |
| 4639 bool allow_lazy = FLAG_lazy && (extension == NULL); | 4603 bool allow_lazy = FLAG_lazy && (extension == NULL); |
| 4640 CompleteParserRecorder recorder; | 4604 CompleteParserRecorder recorder; |
| 4641 int kPreParseLiteralsFlags = | 4605 int kPreParseLiteralsFlags = |
| 4642 JavaScriptScanner::kLiteralString | JavaScriptScanner::kLiteralIdentifier; | 4606 JavaScriptScanner::kLiteralString | JavaScriptScanner::kLiteralIdentifier; |
| 4643 return DoPreParse(source, allow_lazy, &recorder, kPreParseLiteralsFlags); | 4607 return DoPreParse(source, stream, allow_lazy, |
| 4608 &recorder, kPreParseLiteralsFlags); |
| 4644 } | 4609 } |
| 4645 | 4610 |
| 4646 | 4611 |
| 4647 bool RegExpParser::ParseRegExp(FlatStringReader* input, | 4612 bool RegExpParser::ParseRegExp(FlatStringReader* input, |
| 4648 bool multiline, | 4613 bool multiline, |
| 4649 RegExpCompileData* result) { | 4614 RegExpCompileData* result) { |
| 4650 ASSERT(result != NULL); | 4615 ASSERT(result != NULL); |
| 4651 RegExpParser parser(input, &result->error, multiline); | 4616 RegExpParser parser(input, &result->error, multiline); |
| 4652 RegExpTree* tree = parser.ParsePattern(); | 4617 RegExpTree* tree = parser.ParsePattern(); |
| 4653 if (parser.failed()) { | 4618 if (parser.failed()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4693 Handle<String> source = Handle<String>(String::cast(script->source())); | 4658 Handle<String> source = Handle<String>(String::cast(script->source())); |
| 4694 result = parser.ParseProgram(source, info->is_global()); | 4659 result = parser.ParseProgram(source, info->is_global()); |
| 4695 } | 4660 } |
| 4696 } | 4661 } |
| 4697 | 4662 |
| 4698 info->SetFunction(result); | 4663 info->SetFunction(result); |
| 4699 return (result != NULL); | 4664 return (result != NULL); |
| 4700 } | 4665 } |
| 4701 | 4666 |
| 4702 } } // namespace v8::internal | 4667 } } // namespace v8::internal |
| OLD | NEW |