From 269b6d752a6c29c34a760f185960fda94fa79de6 Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Tue, 10 Feb 2015 01:00:02 -0800 Subject: [PATCH] Bug 1130811 - When parsing an array that later turns out to be a legacy array comprehension, explicitly discard the array literal, rather than needlessly setting its kind to PNK_ARRAYCOMP and then implicitly dropping it on the floor. r=efaust --HG-- extra : rebase_source : ddd1af2eb8754f78d329a5d9f9cea8792367e20f --- js/src/frontend/Parser.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index c414aecd8bb..4ec41d6e86b 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -7008,26 +7008,30 @@ template <> ParseNode* Parser::legacyArrayComprehension(ParseNode *array) { - array->setKind(PNK_ARRAYCOMP); - - // Remove the single element from array's linked list, leaving us with an - // empty array literal and a comprehension expression. + // Discard our presumed array literal containing only a single element, and + // instead return an array comprehension node. Extract the few bits of + // information needed from the array literal, then free it. + MOZ_ASSERT(array->isKind(PNK_ARRAY)); MOZ_ASSERT(array->pn_count == 1); - ParseNode *bodyExpr = array->last(); + + uint32_t arrayBegin = handler.getPosition(array).begin; + uint32_t blockid = array->pn_blockid; + + ParseNode *bodyExpr = array->pn_head; array->pn_count = 0; array->pn_tail = &array->pn_head; *array->pn_tail = nullptr; - ParseNode *comp = legacyComprehensionTail(bodyExpr, array->pn_blockid, NotGenerator, - nullptr, LegacyComprehensionHeadBlockScopeDepth(pc)); + handler.freeTree(array); + + ParseNode *comp = legacyComprehensionTail(bodyExpr, blockid, NotGenerator, nullptr, + LegacyComprehensionHeadBlockScopeDepth(pc)); if (!comp) return null(); MUST_MATCH_TOKEN(TOK_RB, JSMSG_BRACKET_AFTER_ARRAY_COMPREHENSION); - TokenPos p = handler.getPosition(array); - p.end = pos().end; - return handler.newArrayComprehension(comp, array->pn_blockid, p); + return handler.newArrayComprehension(comp, blockid, TokenPos(arrayBegin, pos().end)); } template <>