Ignore:
Timestamp:
Nov 18, 2015, 4:03:26 PM (10 years ago)
Author:
[email protected]
Message:

Unreviewed, rolling out r192436 and r192586.
https://bugs.webkit.org/show_bug.cgi?id=151417

Caused a hang in the inspector and a crash @ google.com.
(Requested by saamyjoon on #webkit).

Reverted changesets:

"Allow any LeftHandSideExpression as a valid
AssignmentElement"
https://bugs.webkit.org/show_bug.cgi?id=151026
http://trac.webkit.org/changeset/192436

"There is a bug when default parameter values are mixed with
destructuring parameter values"
https://bugs.webkit.org/show_bug.cgi?id=151369
http://trac.webkit.org/changeset/192586

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r192586 r192597  
    668668
    669669template <typename LexerType>
    670 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier& name, JSToken token, AssignmentContext bindingContext, const Identifier** duplicateIdentifier)
     670template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier& name, int depth, JSToken token, AssignmentContext bindingContext, const Identifier** duplicateIdentifier)
    671671{
    672672    ASSERT(!name.isNull());
     
    686686        }
    687687    } else if (kind == DestructureToParameters) {
    688         DeclarationResultMask declarationResult = declareParameter(&name);
    689         if ((declarationResult & DeclarationResult::InvalidStrictMode) && strictMode()) {
    690             semanticFailIfTrue(isEvalOrArguments(&name), "Cannot destructure to a parameter name '", name.impl(), "' in strict mode");
    691             if (m_lastFunctionName && name == *m_lastFunctionName)
    692                 semanticFail("Cannot declare a parameter named '", name.impl(), "' as it shadows the name of a strict mode function");
    693             semanticFailureDueToKeyword("parameter name");
    694             if (hasDeclaredParameter(name))
    695                 semanticFail("Cannot declare a parameter named '", name.impl(), "' in strict mode as it has already been declared");
    696             semanticFail("Cannot declare a parameter named '", name.impl(), "' in strict mode");
    697         }
    698         if (declarationResult & DeclarationResult::InvalidDuplicateDeclaration) {
    699             // It's not always an error to define a duplicate parameter.
    700             // It's only an error when there are default parameter values or destructuring parameters.
    701             // We note this value now so we can check it later.
    702             if (duplicateIdentifier)
    703                 *duplicateIdentifier = &name;
     688        if (depth) {
     689            auto bindingResult = declareBoundParameter(&name);
     690            if (bindingResult == Scope::StrictBindingFailed && strictMode()) {
     691                semanticFailIfTrue(isEvalOrArguments(&name), "Cannot destructure to a parameter name '", name.impl(), "' in strict mode");
     692                if (m_lastFunctionName && name == *m_lastFunctionName)
     693                    semanticFail("Cannot destructure to '", name.impl(), "' as it shadows the name of a strict mode function");
     694                semanticFailureDueToKeyword("bound parameter name");
     695                if (hasDeclaredParameter(name))
     696                    semanticFail("Cannot destructure to '", name.impl(), "' as it has already been declared");
     697                semanticFail("Cannot bind to a parameter named '", name.impl(), "' in strict mode");
     698            }
     699            if (bindingResult == Scope::BindingFailed) {
     700                semanticFailureDueToKeyword("bound parameter name");
     701                if (hasDeclaredParameter(name))
     702                    semanticFail("Cannot destructure to '", name.impl(), "' as it has already been declared");
     703                semanticFail("Cannot destructure to a parameter named '", name.impl(), "'");
     704            }
     705        } else {
     706            DeclarationResultMask declarationResult = declareParameter(&name);
     707            if ((declarationResult & DeclarationResult::InvalidStrictMode) && strictMode()) {
     708                semanticFailIfTrue(isEvalOrArguments(&name), "Cannot destructure to a parameter name '", name.impl(), "' in strict mode");
     709                if (m_lastFunctionName && name == *m_lastFunctionName)
     710                    semanticFail("Cannot declare a parameter named '", name.impl(), "' as it shadows the name of a strict mode function");
     711                semanticFailureDueToKeyword("parameter name");
     712                if (hasDeclaredParameter(name))
     713                    semanticFail("Cannot declare a parameter named '", name.impl(), "' in strict mode as it has already been declared");
     714                semanticFail("Cannot declare a parameter named '", name.impl(), "' in strict mode");
     715            }
     716            if (declarationResult & DeclarationResult::InvalidDuplicateDeclaration) {
     717                // It's not always an error to define a duplicate parameter.
     718                // It's only an error when there are default parameter values or destructuring parameters.
     719                // We note this value now so we can check it later.
     720                if (duplicateIdentifier)
     721                    *duplicateIdentifier = &name;
     722            }
    704723        }
    705724    }
     
    710729    }
    711730    return context.createBindingLocation(token.m_location, name, token.m_startPosition, token.m_endPosition, bindingContext);
    712 }
    713 
    714 template <typename LexerType>
    715 template <class TreeBuilder> NEVER_INLINE TreeDestructuringPattern Parser<LexerType>::createAssignmentElement(TreeBuilder& context, TreeExpression& assignmentTarget, const JSTextPosition& startPosition, const JSTextPosition& endPosition)
    716 {
    717     return context.createAssignmentElement(assignmentTarget, startPosition, endPosition);
    718731}
    719732
     
    751764{
    752765    return parseDestructuringPattern(context, DestructureToExpressions, ExportType::NotExported, nullptr, nullptr, bindingContext);
    753 }
    754 
    755 template <typename LexerType>
    756 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseBindingOrAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth)
    757 {
    758     if (kind == DestructureToExpressions)
    759         return parseAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth);
    760     return parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth);
    761 }
    762 
    763 template <typename LexerType>
    764 template <class TreeBuilder> TreeDestructuringPattern Parser<LexerType>::parseAssignmentElement(TreeBuilder& context, DestructuringKind kind, ExportType exportType, const Identifier** duplicateIdentifier, bool* hasDestructuringPattern, AssignmentContext bindingContext, int depth)
    765 {
    766     SavePoint savePoint = createSavePoint();
    767     TreeDestructuringPattern assignmentTarget = 0;
    768 
    769     if (match(OPENBRACE) || match(OPENBRACKET))
    770         assignmentTarget = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth);
    771     if (!assignmentTarget || match(DOT) || match(OPENBRACKET) || match(OPENPAREN) || match(TEMPLATE)) {
    772         restoreSavePoint(savePoint);
    773         JSTextPosition startPosition = tokenStartPosition();
    774         auto element = parseMemberExpression(context);
    775 
    776         semanticFailIfFalse(element && context.isAssignmentLocation(element), "Invalid destructuring assignment target");
    777 
    778         return createAssignmentElement(context, element, startPosition, lastTokenEndPosition());
    779     }
    780     return assignmentTarget;
    781766}
    782767
     
    811796                JSTokenLocation location = m_token.m_location;
    812797                next();
    813                 auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
     798                auto innerPattern = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
    814799                if (kind == DestructureToExpressions && !innerPattern)
    815800                    return 0;
     
    824809
    825810            JSTokenLocation location = m_token.m_location;
    826             auto innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
     811            auto innerPattern = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
    827812            if (kind == DestructureToExpressions && !innerPattern)
    828813                return 0;
     
    832817        } while (consume(COMMA));
    833818
     819        if (kind == DestructureToExpressions && !match(CLOSEBRACKET))
     820            return 0;
    834821        consumeOrFail(CLOSEBRACKET, restElementWasFound ? "Expected a closing ']' following a rest element destructuring pattern" : "Expected either a closing ']' or a ',' following an element destructuring pattern");
    835822        context.finishArrayPattern(arrayPattern, divotStart, divotStart, lastTokenEndPosition());
     
    859846                next();
    860847                if (consume(COLON))
    861                     innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
     848                    innerPattern = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
    862849                else
    863                     innerPattern = createBindingPattern(context, kind, exportType, *propertyName, identifierToken, bindingContext, duplicateIdentifier);
     850                    innerPattern = createBindingPattern(context, kind, exportType, *propertyName, depth + 1, identifierToken, bindingContext, duplicateIdentifier);
    864851            } else {
    865852                JSTokenType tokenType = m_token.m_type;
     
    892879                    failWithMessage("Expected a ':' prior to a named destructuring property");
    893880                }
    894                 innerPattern = parseBindingOrAssignmentElement(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
     881                innerPattern = parseDestructuringPattern(context, kind, exportType, duplicateIdentifier, hasDestructuringPattern, bindingContext, depth + 1);
    895882            }
    896883            if (kind == DestructureToExpressions && !innerPattern)
     
    917904        }
    918905        failIfTrue(match(LET) && (kind == DestructureToLet || kind == DestructureToConst), "Can't use 'let' as an identifier name for a LexicalDeclaration");
    919         pattern = createBindingPattern(context, kind, exportType, *m_token.m_data.ident, m_token, bindingContext, duplicateIdentifier);
     906        pattern = createBindingPattern(context, kind, exportType, *m_token.m_data.ident, depth, m_token, bindingContext, duplicateIdentifier);
    920907        next();
    921908        break;
     
    27032690    int initialAssignmentCount = m_assignmentCount;
    27042691    int initialNonLHSCount = m_nonLHSCount;
    2705     String assignmentPatternError = String();
    27062692    if (match(OPENBRACE) || match(OPENBRACKET)) {
    27072693        SavePoint savePoint = createSavePoint();
     
    27122698                return context.createDestructuringAssignment(location, pattern, rhs);
    27132699        }
    2714         assignmentPatternError = m_errorMessage;
    27152700        restoreSavePoint(savePoint);
    27162701    }
     
    27272712   
    27282713    TreeExpression lhs = parseConditionalExpression(context);
    2729     if (!assignmentPatternError.isNull() && (lhs && (context.isObjectOrArrayLiteral(lhs) && match(EQUAL)))) {
    2730         setErrorMessage(assignmentPatternError);
    2731         return 0;
    2732     }
    27332714    failIfFalse(lhs, "Cannot parse expression");
    27342715    if (initialNonLHSCount != m_nonLHSCount) {
Note: See TracChangeset for help on using the changeset viewer.