From a7ab4e552766bf127776c198d1b844fea72b86d0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 17 Jul 2012 16:36:50 -0700 Subject: [PATCH] Bug 771378 (part 1) - Remove use of MUST_FLOW_THROUGH from BytecodeEmitter.cpp. r=jwalden. --HG-- extra : rebase_source : c45808569daa61d10bd57fdc5b969e4880cc3ada --- js/src/frontend/BytecodeEmitter.cpp | 51 +++++++++-------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index 12c14a5ed5f..1b096e58368 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -2204,11 +2204,9 @@ MOZ_NEVER_INLINE static bool EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) { JSOp switchOp; - bool ok, hasDefault; + bool hasDefault; ptrdiff_t top, off, defaultOffset; ParseNode *pn2, *pn3, *pn4; - uint32_t caseCount, tableLength; - ParseNode **table; int32_t i, low, high; int noteIndex; size_t switchSize, tableSize; @@ -2217,7 +2215,6 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* Try for most optimal, fall back if not dense ints, and per ECMAv2. */ switchOp = JSOP_TABLESWITCH; - ok = true; hasDefault = false; defaultOffset = -1; @@ -2269,9 +2266,9 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } #endif - caseCount = pn2->pn_count; - tableLength = 0; - table = NULL; + uint32_t caseCount = pn2->pn_count; + uint32_t tableLength = 0; + js::ScopedFreePtr table(NULL); if (caseCount == 0 || (caseCount == 1 && @@ -2280,6 +2277,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) low = 0; high = -1; } else { + bool ok = true; #define INTMAP_LENGTH 256 jsbitmap intmap_space[INTMAP_LENGTH]; jsbitmap *intmap = NULL; @@ -2510,8 +2508,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* * Use malloc to avoid arena bloat for programs with many switches. - * We free table if non-null at label out, so all control flow must - * exit this function through goto out or goto bad. + * ScopedFreePtr takes care of freeing it on exit. */ if (tableLength != 0) { tableSize = (size_t)tableLength * sizeof *table; @@ -2535,13 +2532,6 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) SET_UINT16(pc, caseCount); pc += UINT16_LEN; } - - /* - * After this point, all control flow involving JSOP_TABLESWITCH - * must set ok and goto out to exit this function. To keep things - * simple, all switchOp cases exit that way. - */ - MUST_FLOW_THROUGH("out"); } /* Emit code for each case's statements, copying pn_offset up to pn3. */ @@ -2549,9 +2539,8 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (switchOp == JSOP_CONDSWITCH && !pn3->isKind(PNK_DEFAULT)) SetJumpOffsetAt(bce, pn3->pn_offset); pn4 = pn3->pn_right; - ok = EmitTree(cx, bce, pn4); - if (!ok) - goto out; + if (!EmitTree(cx, bce, pn4)) + return false; pn3->pn_offset = pn4->pn_offset; if (pn3->isKind(PNK_DEFAULT)) off = pn3->pn_offset - top; @@ -2578,9 +2567,8 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* Set the SRC_SWITCH note's offset operand to tell end of switch. */ off = bce->offset() - top; - ok = SetSrcNoteOffset(cx, bce, (unsigned)noteIndex, 0, off); - if (!ok) - goto out; + if (!SetSrcNoteOffset(cx, bce, (unsigned)noteIndex, 0, off)) + return false; if (switchOp == JSOP_TABLESWITCH) { /* Skip over the already-initialized switch bounds. */ @@ -2601,7 +2589,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (pn3->isKind(PNK_DEFAULT)) continue; if (!bce->constList.append(*pn3->pn_pval)) - goto bad; + return false; SET_UINT32_INDEX(pc, bce->constList.length() - 1); pc += UINT32_INDEX_LEN; @@ -2611,22 +2599,15 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } } -out: - if (table) - cx->free_(table); - if (ok) { - ok = PopStatementBCE(cx, bce); + if (!PopStatementBCE(cx, bce)) + return false; #if JS_HAS_BLOCK_SCOPE - if (ok && pn->pn_right->isKind(PNK_LEXICALSCOPE)) - EMIT_UINT16_IMM_OP(JSOP_LEAVEBLOCK, blockObjCount); + if (pn->pn_right->isKind(PNK_LEXICALSCOPE)) + EMIT_UINT16_IMM_OP(JSOP_LEAVEBLOCK, blockObjCount); #endif - } - return ok; -bad: - ok = false; - goto out; + return true; } bool