Changeset 192436 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Nov 13, 2015, 11:13:39 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r192147 r192436 732 732 733 733 template <typename LexerType> 734 template <class TreeBuilder> NEVER_INLINE TreeDestructuringPattern Parser<LexerType>::createAssignmentElement(TreeBuilder& context, TreeExpression& assignmentTarget, const JSTextPosition& startPosition, const JSTextPosition& endPosition) 735 { 736 return context.createAssignmentElement(assignmentTarget, startPosition, endPosition); 737 } 738 739 template <typename LexerType> 734 740 template <class TreeBuilder> TreeSourceElements Parser<LexerType>::parseArrowFunctionSingleExpressionBodySourceElements(TreeBuilder& context) 735 741 { … … 764 770 { 765 771 return parseDestructuringPattern(context, DestructureToExpressions, ExportType::NotExported, nullptr, nullptr, bindingContext); 772 } 773 774 template <typename LexerType> 775 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseBindingOrAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth) 776 { 777 if (kind == DestructureToExpressions) 778 return parseAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 779 return parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 780 } 781 782 template <typename LexerType> 783 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth) 784 { 785 SavePoint savePoint = createSavePoint(); 786 TreeDestructuringPattern assignmentTarget = 0; 787 788 if (match(OPENBRACE) || match(OPENBRACKET)) 789 assignmentTarget = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 790 if (!assignmentTarget || match(DOT) || match(OPENBRACKET) || match(OPENPAREN) || match(TEMPLATE)) { 791 restoreSavePoint(savePoint); 792 JSTextPosition startPosition = tokenStartPosition(); 793 auto element = parseMemberExpression(context); 794 795 semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target"); 796 797 return createAssignmentElement(context, element, startPosition, lastTokenEndPosition()); 798 } 799 return assignmentTarget; 766 800 } 767 801 … … 796 830 JSTokenLocation location = m_token.m_location; 797 831 next(); 798 auto innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);832 auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 799 833 if (kind == DestructureToExpressions && !innerPattern) 800 834 return 0; … … 809 843 810 844 JSTokenLocation location = m_token.m_location; 811 auto innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);845 auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 812 846 if (kind == DestructureToExpressions && !innerPattern) 813 847 return 0; … … 817 851 } while (consume(COMMA)); 818 852 819 if (kind == DestructureToExpressions && !match(CLOSEBRACKET))820 return 0;821 853 consumeOrFail(CLOSEBRACKET, restElementWasFound ? "Expected a closing ']' following a rest element destructuring pattern" : "Expected either a closing ']' or a ',' following an element destructuring pattern"); 822 854 context.finishArrayPattern(arrayPattern, divotStart, divotStart, lastTokenEndPosition()); … … 846 878 next(); 847 879 if (consume(COLON)) 848 innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);880 innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 849 881 else 850 882 innerPattern = createBindingPattern(context, kind, exportType, *propertyName, depth + 1, identifierToken, bindingContext, duplicateIdentifier); … … 879 911 failWithMessage("Expected a ':' prior to a named destructuring property"); 880 912 } 881 innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);913 innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 882 914 } 883 915 if (kind == DestructureToExpressions && !innerPattern) … … 2690 2722 int initialAssignmentCount = m_assignmentCount; 2691 2723 int initialNonLHSCount = m_nonLHSCount; 2724 String assignmentPatternError = String(); 2692 2725 if (match(OPENBRACE) || match(OPENBRACKET)) { 2693 2726 SavePoint savePoint = createSavePoint(); … … 2698 2731 return context.createDestructuringAssignment(location, pattern, rhs); 2699 2732 } 2733 assignmentPatternError = m_errorMessage; 2700 2734 restoreSavePoint(savePoint); 2701 2735 } … … 2712 2746 2713 2747 TreeExpression lhs = parseConditionalExpression(context); 2748 if (!assignmentPatternError.isNull() && (lhs && (context.isObjectOrArrayLiteral(lhs) && match(EQUAL)))) { 2749 setErrorMessage(assignmentPatternError); 2750 return 0; 2751 } 2714 2752 failIfFalse(lhs, "Cannot parse expression"); 2715 2753 if (initialNonLHSCount != m_nonLHSCount) {
Note:
See TracChangeset
for help on using the changeset viewer.