diff --git a/js/src/frontend/BinSource.cpp b/js/src/frontend/BinSource.cpp index 1a46871a9aeb..3df50053ec34 100644 --- a/js/src/frontend/BinSource.cpp +++ b/js/src/frontend/BinSource.cpp @@ -982,7 +982,7 @@ BinASTParser::parseFunctionAux(const BinKind kind, const BinFields& fields) syntax = Statement; break; case BinKind::FunctionExpression: - syntax = PrimaryExpression; // FIXME: Probably doesn't work. + syntax = Expression; // FIXME: Probably doesn't work. break; case BinKind::ObjectMethod: syntax = Method; diff --git a/js/src/frontend/ParseNode.h b/js/src/frontend/ParseNode.h index 3c5fa163a9de..8c993e8cb748 100644 --- a/js/src/frontend/ParseNode.h +++ b/js/src/frontend/ParseNode.h @@ -1440,21 +1440,8 @@ AccessorTypeToJSOp(AccessorType atype) enum FunctionSyntaxKind { - // A non-arrow function expression that is a PrimaryExpression and *also* a - // complete AssignmentExpression. For example, in - // - // var x = (function y() {}); - // - // |y| is such a function expression. - AssignmentExpression, - - // A non-arrow function expression that is a PrimaryExpression but *not* a - // complete AssignmentExpression. For example, in - // - // var x = (1 + function y() {}); - // - // |y| is such a function expression. - PrimaryExpression, + // A non-arrow function expression. + Expression, // A named function appearing as a Statement. Statement, @@ -1467,12 +1454,6 @@ enum FunctionSyntaxKind Setter, }; -static inline bool -IsFunctionExpression(FunctionSyntaxKind kind) -{ - return kind == AssignmentExpression || kind == PrimaryExpression; -} - static inline bool IsConstructorKind(FunctionSyntaxKind kind) { diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index ce58c02c4ce3..405b60c8c820 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -2794,8 +2794,7 @@ ParserBase::newFunction(HandleAtom atom, FunctionSyntaxKind kind, bool isGlobalSelfHostedBuiltin = false; #endif switch (kind) { - case AssignmentExpression: - case PrimaryExpression: + case Expression: flags = (generatorKind == GeneratorKind::NotGenerator && asyncKind == FunctionAsyncKind::SyncFunction ? JSFunction::INTERPRETED_LAMBDA @@ -3798,7 +3797,7 @@ GeneralParser::functionFormalParametersAndBody(InHandling i } // Revalidate the function name when we transitioned to strict mode. - if ((kind == Statement || IsFunctionExpression(kind)) && + if ((kind == Statement || kind == Expression) && fun->explicitName() && !inheritedStrict && pc->sc()->strict()) @@ -3808,7 +3807,7 @@ GeneralParser::functionFormalParametersAndBody(InHandling i PropertyName* propertyName = fun->explicitName()->asPropertyName(); YieldHandling nameYieldHandling; - if (IsFunctionExpression(kind)) { + if (kind == Expression) { // Named lambda has binding inside it. nameYieldHandling = bodyYieldHandling; } else { @@ -3948,7 +3947,6 @@ GeneralParser::functionStmt(uint32_t toStringStart, template typename ParseHandler::Node GeneralParser::functionExpr(uint32_t toStringStart, - ExpressionClosure expressionClosureHandling, InvokedPrediction invoked, FunctionAsyncKind asyncKind) { @@ -3984,12 +3982,8 @@ GeneralParser::functionExpr(uint32_t toStringStart, if (invoked) pn = handler.setLikelyIIFE(pn); - FunctionSyntaxKind kind = expressionClosureHandling == ExpressionClosure::Allowed - ? AssignmentExpression - : PrimaryExpression; - - return functionDefinition(pn, toStringStart, InAllowed, yieldHandling, name, kind, - generatorKind, asyncKind); + return functionDefinition(pn, toStringStart, InAllowed, yieldHandling, name, + FunctionSyntaxKind::Expression, generatorKind, asyncKind); } /* @@ -7234,8 +7228,7 @@ GeneralParser::classDefinition(YieldHandling yieldHandling, if (hasHeritage) { if (!tokenStream.getToken(&tt)) return null(); - classHeritage = memberExpr(yieldHandling, TripledotProhibited, - ExpressionClosure::Forbidden, tt); + classHeritage = memberExpr(yieldHandling, TripledotProhibited, tt); if (!classHeritage) return null(); } @@ -7972,7 +7965,6 @@ template MOZ_ALWAYS_INLINE typename ParseHandler::Node GeneralParser::orExpr(InHandling inHandling, YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, PossibleError* possibleError, InvokedPrediction invoked /* = PredictUninvoked */) { @@ -7986,13 +7978,10 @@ GeneralParser::orExpr(InHandling inHandling, YieldHandling int depth = 0; Node pn; for (;;) { - pn = unaryExpr(yieldHandling, tripledotHandling, expressionClosureHandling, possibleError, - invoked); + pn = unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked); if (!pn) return null(); - expressionClosureHandling = ExpressionClosure::Forbidden; - // If a binary operator follows, consume it and compute the // corresponding operator. TokenKind tok; @@ -8057,12 +8046,10 @@ template MOZ_ALWAYS_INLINE typename ParseHandler::Node GeneralParser::condExpr(InHandling inHandling, YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, PossibleError* possibleError, InvokedPrediction invoked /* = PredictUninvoked */) { - Node condition = orExpr(inHandling, yieldHandling, tripledotHandling, - expressionClosureHandling, possibleError, invoked); + Node condition = orExpr(inHandling, yieldHandling, tripledotHandling, possibleError, invoked); if (!condition) return null(); @@ -8190,8 +8177,7 @@ GeneralParser::assignExpr(InHandling inHandling, YieldHandl isArrow = true; } else { - lhs = condExpr(inHandling, yieldHandling, tripledotHandling, ExpressionClosure::Allowed, - &possibleErrorInner, invoked); + lhs = condExpr(inHandling, yieldHandling, tripledotHandling, &possibleErrorInner, invoked); if (!lhs) return null(); @@ -8383,7 +8369,7 @@ typename ParseHandler::Node GeneralParser::unaryOpExpr(YieldHandling yieldHandling, ParseNodeKind kind, uint32_t begin) { - Node kid = unaryExpr(yieldHandling, TripledotProhibited, ExpressionClosure::Forbidden); + Node kid = unaryExpr(yieldHandling, TripledotProhibited); if (!kid) return null(); return handler.newUnary(kind, begin, kid); @@ -8393,7 +8379,6 @@ template typename ParseHandler::Node GeneralParser::unaryExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, PossibleError* possibleError /* = nullptr */, InvokedPrediction invoked /* = PredictUninvoked */) { @@ -8428,7 +8413,7 @@ GeneralParser::unaryExpr(YieldHandling yieldHandling, // // Evaluates expression, triggering a runtime ReferenceError for // // the undefined name. // typeof (1, nonExistentName); - Node kid = unaryExpr(yieldHandling, TripledotProhibited, ExpressionClosure::Forbidden); + Node kid = unaryExpr(yieldHandling, TripledotProhibited); if (!kid) return null(); @@ -8444,7 +8429,7 @@ GeneralParser::unaryExpr(YieldHandling yieldHandling, uint32_t operandOffset = pos().begin; Node operand = - memberExpr(yieldHandling, TripledotProhibited, ExpressionClosure::Forbidden, tt2); + memberExpr(yieldHandling, TripledotProhibited, tt2); if (!operand || !checkIncDecOperand(operand, operandOffset)) return null(); ParseNodeKind pnk = (tt == TokenKind::Inc) @@ -8458,7 +8443,7 @@ GeneralParser::unaryExpr(YieldHandling yieldHandling, if (!tokenStream.peekOffset(&exprOffset, TokenStream::Operand)) return null(); - Node expr = unaryExpr(yieldHandling, TripledotProhibited, ExpressionClosure::Forbidden); + Node expr = unaryExpr(yieldHandling, TripledotProhibited); if (!expr) return null(); @@ -8476,8 +8461,7 @@ GeneralParser::unaryExpr(YieldHandling yieldHandling, case TokenKind::Await: { if (pc->isAsync()) { - Node kid = unaryExpr(yieldHandling, tripledotHandling, ExpressionClosure::Forbidden, - possibleError, invoked); + Node kid = unaryExpr(yieldHandling, tripledotHandling, possibleError, invoked); if (!kid) return null(); pc->lastAwaitOffset = begin; @@ -8488,7 +8472,7 @@ GeneralParser::unaryExpr(YieldHandling yieldHandling, MOZ_FALLTHROUGH; default: { - Node expr = memberExpr(yieldHandling, tripledotHandling, expressionClosureHandling, tt, + Node expr = memberExpr(yieldHandling, tripledotHandling, tt, /* allowCallSyntax = */ true, possibleError, invoked); if (!expr) return null(); @@ -8602,7 +8586,6 @@ template typename ParseHandler::Node GeneralParser::memberExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, TokenKind tt, bool allowCallSyntax /* = true */, PossibleError* possibleError /* = nullptr */, InvokedPrediction invoked /* = PredictUninvoked */) @@ -8626,8 +8609,7 @@ GeneralParser::memberExpr(YieldHandling yieldHandling, } else { // Gotten by tryNewTarget tt = anyChars.currentToken().type; - Node ctorExpr = memberExpr(yieldHandling, TripledotProhibited, - ExpressionClosure::Forbidden, tt, + Node ctorExpr = memberExpr(yieldHandling, TripledotProhibited, tt, /* allowCallSyntax = */ false, /* possibleError = */ nullptr, PredictInvoked); if (!ctorExpr) @@ -8656,8 +8638,7 @@ GeneralParser::memberExpr(YieldHandling yieldHandling, if (!lhs) return null(); } else { - lhs = primaryExpr(yieldHandling, tripledotHandling, expressionClosureHandling, tt, - possibleError, invoked); + lhs = primaryExpr(yieldHandling, tripledotHandling, tt, possibleError, invoked); if (!lhs) return null(); } @@ -9832,7 +9813,6 @@ template typename ParseHandler::Node GeneralParser::primaryExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, TokenKind tt, PossibleError* possibleError, InvokedPrediction invoked /* = PredictUninvoked */) { @@ -9842,8 +9822,7 @@ GeneralParser::primaryExpr(YieldHandling yieldHandling, switch (tt) { case TokenKind::Function: - return functionExpr(pos().begin, expressionClosureHandling, invoked, - FunctionAsyncKind::SyncFunction); + return functionExpr(pos().begin, invoked, FunctionAsyncKind::SyncFunction); case TokenKind::Class: return classDefinition(yieldHandling, ClassExpression, NameRequired); @@ -9908,8 +9887,7 @@ GeneralParser::primaryExpr(YieldHandling yieldHandling, if (nextSameLine == TokenKind::Function) { uint32_t toStringStart = pos().begin; tokenStream.consumeKnownToken(TokenKind::Function); - return functionExpr(toStringStart, expressionClosureHandling, PredictUninvoked, - FunctionAsyncKind::AsyncFunction); + return functionExpr(toStringStart, PredictUninvoked, FunctionAsyncKind::AsyncFunction); } } diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index aca151707623..f366c6f37f9c 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -616,8 +616,6 @@ PerHandlerParser::clearAbortedSyntaxParse() { } -enum class ExpressionClosure { Allowed, Forbidden }; - template class ParserAnyCharsAccess { @@ -974,8 +972,8 @@ class GeneralParser Node functionStmt(uint32_t toStringStart, YieldHandling yieldHandling, DefaultHandling defaultHandling, FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction); - Node functionExpr(uint32_t toStringStart, ExpressionClosure expressionClosureHandling, - InvokedPrediction invoked, FunctionAsyncKind asyncKind); + Node functionExpr(uint32_t toStringStart, InvokedPrediction invoked, + FunctionAsyncKind asyncKind); Node statement(YieldHandling yieldHandling); bool maybeParseDirective(Node list, Node pn, bool* cont); @@ -1094,24 +1092,20 @@ class GeneralParser Node assignExprWithoutYieldOrAwait(YieldHandling yieldHandling); Node yieldExpression(InHandling inHandling); Node condExpr(InHandling inHandling, YieldHandling yieldHandling, - TripledotHandling tripledotHandling, ExpressionClosure expressionClosureHandling, - PossibleError* possibleError, + TripledotHandling tripledotHandling, PossibleError* possibleError, InvokedPrediction invoked = PredictUninvoked); Node orExpr(InHandling inHandling, YieldHandling yieldHandling, - TripledotHandling tripledotHandling, ExpressionClosure expressionClosureHandling, - PossibleError* possibleError, + TripledotHandling tripledotHandling, PossibleError* possibleError, InvokedPrediction invoked = PredictUninvoked); Node unaryExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, PossibleError* possibleError = nullptr, InvokedPrediction invoked = PredictUninvoked); - Node memberExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, TokenKind tt, + Node memberExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, TokenKind tt, bool allowCallSyntax = true, PossibleError* possibleError = nullptr, InvokedPrediction invoked = PredictUninvoked); Node primaryExpr(YieldHandling yieldHandling, TripledotHandling tripledotHandling, - ExpressionClosure expressionClosureHandling, TokenKind tt, - PossibleError* possibleError, InvokedPrediction invoked = PredictUninvoked); + TokenKind tt, PossibleError* possibleError, + InvokedPrediction invoked = PredictUninvoked); Node exprInParens(InHandling inHandling, YieldHandling yieldHandling, TripledotHandling tripledotHandling, PossibleError* possibleError = nullptr);