From ad6c5e50296c243f99740f16be607bc9f73fcfea Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Thu, 9 Jul 2015 20:49:36 -0700 Subject: [PATCH] Bug 1183400 - Fold while and do-while loops by kind, not arity. r=efaust --HG-- extra : rebase_source : e4e8a02bab6c8807dd1a010beed0a32c4f063ca7 --- js/src/frontend/FoldConstants.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index 1b25bc85bd51..f76e9974fccc 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -519,12 +519,6 @@ enum class SyntacticContext : int { Other }; -static SyntacticContext -condIf(const ParseNode* pn, ParseNodeKind kind) -{ - return pn->isKind(kind) ? SyntacticContext::Condition : SyntacticContext::Other; -} - static bool Fold(ExclusiveContext* cx, ParseNode** pnp, Parser& parser, bool inGenexpLambda, SyntacticContext sc); @@ -1816,10 +1810,18 @@ Fold(ExclusiveContext* cx, ParseNode** pnp, Parser& parser, bo return Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Other) && Fold(cx, &pn->pn_right, parser, inGenexpLambda, SyntacticContext::Other); + case PNK_DOWHILE: + MOZ_ASSERT(pn->isArity(PN_BINARY)); + return Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Other) && + Fold(cx, &pn->pn_right, parser, inGenexpLambda, SyntacticContext::Condition); + + case PNK_WHILE: + MOZ_ASSERT(pn->isArity(PN_BINARY)); + return Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Condition) && + Fold(cx, &pn->pn_right, parser, inGenexpLambda, SyntacticContext::Other); + case PNK_EXPORT: case PNK_SHORTHAND: - case PNK_DOWHILE: - case PNK_WHILE: case PNK_SWITCH: case PNK_LETBLOCK: case PNK_FOR: @@ -1870,7 +1872,10 @@ Fold(ExclusiveContext* cx, ParseNode** pnp, Parser& parser, bo } if (pn->pn_kid2) { - if (!Fold(cx, &pn->pn_kid2, parser, inGenexpLambda, condIf(pn, PNK_FORHEAD))) + SyntacticContext kidsc = pn->isKind(PNK_FORHEAD) + ? SyntacticContext::Condition + : SyntacticContext::Other; + if (!Fold(cx, &pn->pn_kid2, parser, inGenexpLambda, kidsc)) return false; if (pn->isKind(PNK_FORHEAD) && pn->pn_kid2->isKind(PNK_TRUE)) { parser.freeTree(pn->pn_kid2); @@ -1888,12 +1893,12 @@ Fold(ExclusiveContext* cx, ParseNode** pnp, Parser& parser, bo case PN_BINARY_OBJ: /* First kid may be null (for default case in switch). */ if (pn->pn_left) { - if (!Fold(cx, &pn->pn_left, parser, inGenexpLambda, condIf(pn, PNK_WHILE))) + if (!Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Other)) return false; } /* Second kid may be null (for return in non-generator). */ if (pn->pn_right) { - if (!Fold(cx, &pn->pn_right, parser, inGenexpLambda, condIf(pn, PNK_DOWHILE))) + if (!Fold(cx, &pn->pn_right, parser, inGenexpLambda, SyntacticContext::Other)) return false; } break;