Changeset 192661 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Nov 19, 2015, 2:54:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r192603 r192661 61 61 #define semanticFailIfFalse(cond, ...) do { if (!(cond)) internalFailWithMessage(false, __VA_ARGS__); } while (0) 62 62 #define regexFail(failure) do { setErrorMessage(failure); return 0; } while (0) 63 #define restoreSavePointAndFail(savePoint, message) do { restoreSavePointWithError(savePoint, message); return 0; } while (0) 63 64 #define failDueToUnexpectedToken() do {\ 64 65 logError(true);\ … … 220 221 m_token.m_location.lineStartOffset = source.startOffset(); 221 222 m_functionCache = vm->addSourceProviderCache(source.provider()); 223 m_expressionErrorClassifier = nullptr; 222 224 223 225 ScopeRef scope = pushScope(); … … 713 715 714 716 template <typename LexerType> 717 template <class TreeBuilder> NEVER_INLINE TreeDestructuringPattern Parser<LexerType>::createAssignmentElement(TreeBuilder& context, TreeExpression& assignmentTarget, const JSTextPosition& startPosition, const JSTextPosition& endPosition) 718 { 719 return context.createAssignmentElement(assignmentTarget, startPosition, endPosition); 720 } 721 722 template <typename LexerType> 715 723 template <class TreeBuilder> TreeSourceElements Parser<LexerType>::parseArrowFunctionSingleExpressionBodySourceElements(TreeBuilder& context) 716 724 { … … 745 753 { 746 754 return parseDestructuringPattern(context, DestructureToExpressions, ExportType::NotExported, nullptr, nullptr, bindingContext); 755 } 756 757 template <typename LexerType> 758 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseBindingOrAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth) 759 { 760 if (kind == DestructureToExpressions) 761 return parseAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 762 return parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 763 } 764 765 template <typename LexerType> 766 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth) 767 { 768 SavePoint savePoint = createSavePoint(); 769 TreeDestructuringPattern assignmentTarget = 0; 770 771 if (match(OPENBRACE) || match(OPENBRACKET)) 772 assignmentTarget = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth); 773 if (!assignmentTarget || match(DOT) || match(OPENBRACKET) || match(OPENPAREN) || match(TEMPLATE)) { 774 restoreSavePoint(savePoint); 775 JSTextPosition startPosition = tokenStartPosition(); 776 auto element = parseMemberExpression(context); 777 778 semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target"); 779 780 return createAssignmentElement(context, element, startPosition, lastTokenEndPosition()); 781 } 782 return assignmentTarget; 747 783 } 748 784 … … 777 813 JSTokenLocation location = m_token.m_location; 778 814 next(); 779 auto innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);815 auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 780 816 if (kind == DestructureToExpressions && !innerPattern) 781 817 return 0; … … 790 826 791 827 JSTokenLocation location = m_token.m_location; 792 auto innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);828 auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 793 829 if (kind == DestructureToExpressions && !innerPattern) 794 830 return 0; … … 798 834 } while (consume(COMMA)); 799 835 800 if (kind == DestructureToExpressions && !match(CLOSEBRACKET))801 return 0;802 836 consumeOrFail(CLOSEBRACKET, restElementWasFound ? "Expected a closing ']' following a rest element destructuring pattern" : "Expected either a closing ']' or a ',' following an element destructuring pattern"); 803 837 context.finishArrayPattern(arrayPattern, divotStart, divotStart, lastTokenEndPosition()); … … 827 861 next(); 828 862 if (consume(COLON)) 829 innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);863 innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 830 864 else 831 865 innerPattern = createBindingPattern(context, kind, exportType, *propertyName, identifierToken, bindingContext, duplicateIdentifier); … … 860 894 failWithMessage("Expected a ':' prior to a named destructuring property"); 861 895 } 862 innerPattern = parse DestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);896 innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1); 863 897 } 864 898 if (kind == DestructureToExpressions && !innerPattern) … … 2671 2705 int initialAssignmentCount = m_assignmentCount; 2672 2706 int initialNonLHSCount = m_nonLHSCount; 2673 if (match(OPENBRACE) || match(OPENBRACKET)) { 2674 SavePoint savePoint = createSavePoint(); 2675 auto pattern = tryParseDestructuringPatternExpression(context, AssignmentContext::AssignmentExpression); 2676 if (pattern && consume(EQUAL)) { 2677 auto rhs = parseAssignmentExpression(context); 2678 if (rhs) 2679 return context.createDestructuringAssignment(location, pattern, rhs); 2680 } 2681 restoreSavePoint(savePoint); 2682 } 2707 bool maybeAssignmentPattern = match(OPENBRACE) || match(OPENBRACKET); 2708 SavePoint savePoint = createSavePoint(); 2709 ExpressionErrorClassifier classifier(this); 2683 2710 2684 2711 #if ENABLE(ES6_GENERATORS) … … 2693 2720 2694 2721 TreeExpression lhs = parseConditionalExpression(context); 2722 2723 if (!lhs && (!maybeAssignmentPattern || !classifier.indicatesPossiblePattern())) 2724 propagateError(); 2725 2726 if (maybeAssignmentPattern && (!lhs || (context.isObjectOrArrayLiteral(lhs) && match(EQUAL)))) { 2727 String expressionError = m_errorMessage; 2728 SavePoint expressionErrorLocation = createSavePointForError(); 2729 restoreSavePoint(savePoint); 2730 auto pattern = tryParseDestructuringPatternExpression(context, AssignmentContext::AssignmentExpression); 2731 if (classifier.indicatesPossiblePattern() && (!pattern || !match(EQUAL))) 2732 restoreSavePointAndFail(expressionErrorLocation, expressionError); 2733 failIfFalse(pattern, "Cannot parse assignment pattern"); 2734 consumeOrFail(EQUAL, "Expected '=' following assignment pattern"); 2735 auto rhs = parseAssignmentExpression(context); 2736 if (!rhs) 2737 propagateError(); 2738 return context.createDestructuringAssignment(location, pattern, rhs); 2739 } 2740 2695 2741 failIfFalse(lhs, "Cannot parse expression"); 2696 2742 if (initialNonLHSCount != m_nonLHSCount) { … … 2911 2957 return context.createProperty(ident, node, static_cast<PropertyNode::Type>(PropertyNode::Constant | PropertyNode::Shorthand), PropertyNode::KnownDirect, complete); 2912 2958 } 2959 2960 if (match(EQUAL)) // CoverInitializedName is exclusive to BindingPattern and AssignmentPattern 2961 classifyExpressionError(ErrorIndicatesPattern); 2913 2962 2914 2963 PropertyNode::Type type;
Note:
See TracChangeset
for help on using the changeset viewer.