Bug 838813 part 6 - Remove SRC_BRACE. r=njn.
authorJason Orendorff <jorendorff@mozilla.com>
Fri, 08 Feb 2013 17:19:42 -0600
changeset 131294 1283960227765e952c5e722dec87e7426adae8bd
parent 131293 5324e333fcbe3a373d532c5722423c6fc19f2c48
child 131295 aaec15131513ea45295808822818ae9408e50cda
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs838813
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 838813 part 6 - Remove SRC_BRACE. r=njn.
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
js/src/frontend/ParseNode.h
js/src/frontend/Parser.cpp
js/src/shell/js.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -3553,35 +3553,16 @@ EmitAssignment(JSContext *cx, BytecodeEm
         break;
 #endif
       default:
         JS_ASSERT(0);
     }
     return true;
 }
 
-#ifdef DEBUG
-static bool
-GettableNoteForNextOp(BytecodeEmitter *bce)
-{
-    ptrdiff_t offset, target;
-    jssrcnote *sn, *end;
-
-    offset = 0;
-    target = bce->offset();
-    for (sn = bce->notes(), end = sn + bce->noteCount(); sn < end;
-         sn = SN_NEXT(sn)) {
-        if (offset == target && SN_IS_GETTABLE(sn))
-            return true;
-        offset += SN_DELTA(sn);
-    }
-    return false;
-}
-#endif
-
 /* Top-level named functions need a nop for decompilation. */
 static bool
 EmitFunctionDefNop(JSContext *cx, BytecodeEmitter *bce, unsigned index)
 {
     return NewSrcNote2(cx, bce, SRC_FUNCDEF, (ptrdiff_t)index) >= 0 &&
            Emit1(cx, bce, JSOP_NOP) >= 0;
 }
 
@@ -4238,52 +4219,22 @@ EmitLexicalScope(JSContext *cx, Bytecode
     JS_ASSERT(pn->getOp() == JSOP_LEAVEBLOCK);
 
     StmtInfoBCE stmtInfo(cx);
     ObjectBox *objbox = pn->pn_objbox;
     StaticBlockObject &blockObj = objbox->object->asStaticBlock();
     size_t slots = blockObj.slotCount();
     PushBlockScopeBCE(bce, &stmtInfo, blockObj, bce->offset());
 
-    /*
-     * For compound statements (i.e. { stmt-list }), the decompiler does not
-     * emit curlies by default. However, if this stmt-list contains a let
-     * declaration, this is semantically invalid so we need to add a srcnote to
-     * enterblock to tell the decompiler to add curlies. This condition
-     * shouldn't be so complicated; try to find a simpler condition.
-     */
-    ptrdiff_t noteIndex = -1;
-    if (pn->expr()->getKind() != PNK_FOR &&
-        pn->expr()->getKind() != PNK_CATCH &&
-        (stmtInfo.down
-         ? stmtInfo.down->type == STMT_BLOCK &&
-           (!stmtInfo.down->down || stmtInfo.down->down->type != STMT_FOR_IN_LOOP)
-         : !bce->sc->isFunctionBox()))
-    {
-        /* There must be no source note already output for the next op. */
-        JS_ASSERT(bce->noteCount() == 0 ||
-                  bce->lastNoteOffset() != bce->offset() ||
-                  !GettableNoteForNextOp(bce));
-        noteIndex = NewSrcNote2(cx, bce, SRC_BRACE, 0);
-        if (noteIndex < 0)
-            return false;
-    }
-
-    ptrdiff_t bodyBegin = bce->offset();
     if (!EmitEnterBlock(cx, bce, pn, JSOP_ENTERBLOCK))
         return false;
 
     if (!EmitTree(cx, bce, pn->pn_expr))
         return false;
 
-    if (noteIndex >= 0) {
-        if (!SetSrcNoteOffset(cx, bce, (unsigned)noteIndex, 0, bce->offset() - bodyBegin))
-            return false;
-    }
-
     EMIT_UINT16_IMM_OP(JSOP_LEAVEBLOCK, slots);
 
     return PopStatementBCE(cx, bce);
 }
 
 static bool
 EmitWith(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
 {
@@ -4938,40 +4889,29 @@ EmitReturn(JSContext *cx, BytecodeEmitte
     return true;
 }
 
 static bool
 EmitStatementList(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
 {
     JS_ASSERT(pn->isArity(PN_LIST));
 
-    ptrdiff_t noteIndex = -1;
-    ptrdiff_t tmp = bce->offset();
-    if (pn->pn_xflags & PNX_NEEDBRACES) {
-        noteIndex = NewSrcNote2(cx, bce, SRC_BRACE, 0);
-        if (noteIndex < 0 || Emit1(cx, bce, JSOP_NOP) < 0)
-            return false;
-    }
-
     StmtInfoBCE stmtInfo(cx);
     PushStatementBCE(bce, &stmtInfo, STMT_BLOCK, top);
 
     ParseNode *pnchild = pn->pn_head;
 
     if (pn->pn_xflags & PNX_DESTRUCT)
         pnchild = pnchild->pn_next;
 
     for (ParseNode *pn2 = pnchild; pn2; pn2 = pn2->pn_next) {
         if (!EmitTree(cx, bce, pn2))
             return false;
     }
 
-    if (noteIndex >= 0 && !SetSrcNoteOffset(cx, bce, (unsigned)noteIndex, 0, bce->offset() - tmp))
-        return false;
-
     return PopStatementBCE(cx, bce);
 }
 
 static bool
 EmitStatement(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
 {
     JS_ASSERT(pn->isKind(PNK_SEMI));
 
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -273,18 +273,16 @@ enum SrcNoteType {
                                    JSOP_POP at end of for-in */
     SRC_PCDELTA     = 7,        /* distance forward from comma-operator to
                                    next POP, or from CONDSWITCH to first CASE
                                    opcode, etc. -- always a forward delta */
     SRC_DESTRUCTLET = 7,        /* JSOP_DUP starting a destructuring let
                                    operation, with offset to JSOP_ENTERLET0 */
     SRC_ASSIGNOP    = 8,        /* += or another assign-op follows */
     SRC_COND        = 9,        /* JSOP_IFEQ is from conditional ?: operator */
-    SRC_BRACE       = 10,       /* mandatory brace, for scope or to avoid
-                                   dangling else */
     SRC_HIDDEN      = 11,       /* opcode shouldn't be decompiled */
     SRC_PCBASE      = 12,       /* distance back from annotated getprop or
                                    setprop op to left-most obj.prop.subprop
                                    bytecode -- always a backward delta */
     SRC_LABEL       = 13,       /* JSOP_LABEL for label: with atomid immediate */
     SRC_LABELBRACE  = 14,       /* JSOP_LABEL for label: {...} begin brace */
     SRC_ENDBRACE    = 15,       /* JSOP_NOP for label: {...} end brace */
     SRC_BREAK2LABEL = 16,       /* JSOP_GOTO for 'break label' with atomid */
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -633,18 +633,17 @@ struct ParseNode {
 #define PNX_STRCAT      0x01            /* PNK_ADD list has string term */
 #define PNX_CANTFOLD    0x02            /* PNK_ADD list has unfoldable term */
 #define PNX_POPVAR      0x04            /* PNK_VAR or PNK_CONST last result
                                            needs popping */
 #define PNX_FORINVAR    0x08            /* PNK_VAR is left kid of PNK_FORIN node
                                            which is left kid of PNK_FOR */
 #define PNX_ENDCOMMA    0x10            /* array literal has comma at end */
 #define PNX_GROUPINIT   0x20            /* var [a, b] = [c, d]; unit list */
-#define PNX_NEEDBRACES  0x40            /* braces necessary due to closure */
-#define PNX_FUNCDEFS    0x80            /* contains top-level function statements */
+#define PNX_FUNCDEFS    0x40            /* contains top-level function statements */
 #define PNX_SETCALL     0x80            /* call expression in lvalue context */
 #define PNX_DESTRUCT   0x100            /* destructuring special cases:
                                            1. shorthand syntax used, at present
                                               object destructuring ({x,y}) only;
                                            2. code evaluating destructuring
                                               arguments occurs before function
                                               body */
 #define PNX_HOLEY      0x200            /* array initialiser has holes */
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -3965,24 +3965,16 @@ Parser::statement()
             return NULL;
         bool hasFunctionStmt;
         pn = statements(&hasFunctionStmt);
         if (!pn)
             return NULL;
 
         MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_IN_COMPOUND);
         PopStatementPC(context, pc);
-
-        /*
-         * If we contain a function statement and our container is top-level
-         * or another block, flag pn to preserve braces when decompiling.
-         */
-        if (hasFunctionStmt && (!pc->topStmt || pc->topStmt->type == STMT_BLOCK))
-            pn->pn_xflags |= PNX_NEEDBRACES;
-
         return pn;
       }
 
       case TOK_SEMI:
         pn = UnaryNode::create(PNK_SEMI, this);
         if (!pn)
             return NULL;
         return pn;
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -1748,17 +1748,16 @@ SrcNotes(JSContext *cx, HandleScript scr
             Sprint(sp, " else %u elseif %u",
                    unsigned(js_GetSrcNoteOffset(sn, 0)),
                    unsigned(js_GetSrcNoteOffset(sn, 1)));
             break;
           case SRC_COND:
           case SRC_WHILE:
           case SRC_PCBASE:
           case SRC_PCDELTA:
-          case SRC_BRACE:
             Sprint(sp, " offset %u", unsigned(js_GetSrcNoteOffset(sn, 0)));
             break;
           case SRC_LABEL:
           case SRC_LABELBRACE:
           case SRC_BREAK2LABEL:
           case SRC_CONT2LABEL: {
             uint32_t index = js_GetSrcNoteOffset(sn, 0);
             JSAtom *atom = script->getAtom(index);