Bug 704369: Move break emit. (r=Waldo)
authorChris Leary <cdleary@mozilla.com>
Tue, 22 Nov 2011 10:40:06 -0800
changeset 82890 89da5f4649408c3bd46cb4e02bbae5c48551fdf0
parent 82889 52f6d44759e9bc058f356295a8d0270912b7f80d
child 82891 2a4220da28dbc978c96dd61255c70aacf93f4c53
push idunknown
push userunknown
push dateunknown
reviewersWaldo
bugs704369
milestone11.0a1
Bug 704369: Move break emit. (r=Waldo)
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -6006,16 +6006,43 @@ EmitWhile(JSContext *cx, BytecodeEmitter
     if (!SetSrcNoteOffset(cx, bce, noteIndex2, 0, beq - top))
         return false;
     if (!SetSrcNoteOffset(cx, bce, noteIndex, 0, beq - jmp))
         return false;
 
     return PopStatementBCE(cx, bce);
 }
 
+static bool
+EmitBreak(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
+{
+    StmtInfo *stmt = bce->topStmt;
+    JSAtom *atom = pn->pn_atom;
+
+    SrcNoteType noteType;
+    jsatomid labelIndex;
+    if (atom) {
+        if (!bce->makeAtomIndex(atom, &labelIndex))
+            return JS_FALSE;
+
+        while (stmt->type != STMT_LABEL || stmt->label != atom)
+            stmt = stmt->down;
+        noteType = SRC_BREAK2LABEL;
+    } else {
+        labelIndex = INVALID_ATOMID;
+        while (!STMT_IS_LOOP(stmt) && stmt->type != STMT_SWITCH)
+            stmt = stmt->down;
+        noteType = (stmt->type == STMT_SWITCH) ? SRC_SWITCHBREAK : SRC_BREAK;
+    }
+
+    if (EmitGoto(cx, bce, stmt, &stmt->breaks, labelIndex, noteType) < 0)
+        return JS_FALSE;
+    return true;
+}
+
 JSBool
 frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
 {
     JSBool useful, wantval;
     StmtInfo stmtInfo;
     StmtInfo *stmt;
     ptrdiff_t top, off, tmp, beq, jmp;
     ParseNode *pn2, *pn3;
@@ -6082,39 +6109,19 @@ frontend::EmitTree(JSContext *cx, Byteco
       case PNK_DOWHILE:
         ok = EmitDo(cx, bce, pn);
         break;
 
       case PNK_FOR:
         ok = EmitFor(cx, bce, pn, top);
         break;
 
-      case PNK_BREAK: {
-        stmt = bce->topStmt;
-        atom = pn->pn_atom;
-
-        jsatomid labelIndex;
-        if (atom) {
-            if (!bce->makeAtomIndex(atom, &labelIndex))
-                return JS_FALSE;
-
-            while (stmt->type != STMT_LABEL || stmt->label != atom)
-                stmt = stmt->down;
-            noteType = SRC_BREAK2LABEL;
-        } else {
-            labelIndex = INVALID_ATOMID;
-            while (!STMT_IS_LOOP(stmt) && stmt->type != STMT_SWITCH)
-                stmt = stmt->down;
-            noteType = (stmt->type == STMT_SWITCH) ? SRC_SWITCHBREAK : SRC_BREAK;
-        }
-
-        if (EmitGoto(cx, bce, stmt, &stmt->breaks, labelIndex, noteType) < 0)
-            return JS_FALSE;
+      case PNK_BREAK:
+        ok = EmitBreak(cx, bce, pn);
         break;
-      }
 
       case PNK_CONTINUE: {
         stmt = bce->topStmt;
         atom = pn->pn_atom;
 
         jsatomid labelIndex;
         if (atom) {
             /* Find the loop statement enclosed by the matching label. */