Move DECOMPOSE tests in Decompile() into individual cases, bug 673710.
authorBrian Hackett <bhackett1024@gmail.com>
Mon, 25 Jul 2011 10:32:56 -0700
changeset 76069 7e5a5d2e28f86a93c36b8473591411c212be870f
parent 76068 bdf006d7b67dad1430b7cabd384d6c956c8a3b87
child 76070 62f32efb087c7213d5d86580ed0cccc782268a74
child 76071 4d1506b097db00d81d4b06c594f86220195b3cf9
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
bugs673710
milestone8.0a1
Move DECOMPOSE tests in Decompile() into individual cases, bug 673710.
js/src/jit-test/tests/basic/bug673710.js
js/src/jsopcode.cpp
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug673710.js
@@ -0,0 +1,9 @@
+function test() {
+  3 && x++;
+}
+assertEq(test.toString(), "function test() {\n    3 && x++;\n}");
+
+function f() {
+    a[1, 2]++;
+}
+assertEq(f.toString(), "function f() {\n    a[1, 2]++;\n}");
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -3744,32 +3744,35 @@ Decompile(SprintStack *ss, jsbytecode *p
               do_incatom:
                 lval = QuoteString(&ss->sprinter, atom, 0);
                 if (!lval)
                     return NULL;
                 RETRACT(&ss->sprinter, lval);
               do_inclval:
                 todo = Sprint(&ss->sprinter, ss_format,
                               js_incop_strs[!(cs->format & JOF_INC)], lval);
+                if (js_CodeSpec[*pc].format & JOF_DECOMPOSE)
+                    len += GetDecomposeLength(pc, js_CodeSpec[*pc].length);
                 break;
 
               case JSOP_INCPROP:
               case JSOP_DECPROP:
                 GET_ATOM_QUOTE_AND_FMT(preindex_format, predot_format, rval);
 
                 /*
                  * Force precedence below the numeric literal opcodes, so that
                  * 42..foo or 10000..toString(16), e.g., decompile with parens
                  * around the left-hand side of dot.
                  */
                 op = JSOP_GETPROP;
                 lval = POP_STR();
                 todo = Sprint(&ss->sprinter, fmt,
                               js_incop_strs[!(cs->format & JOF_INC)],
                               lval, rval);
+                len += GetDecomposeLength(pc, JSOP_INCPROP_LENGTH);
                 break;
 
               case JSOP_INCELEM:
               case JSOP_DECELEM:
                 op = JSOP_NOP;          /* turn off parens */
                 xval = POP_STR();
                 op = JSOP_GETELEM;
                 lval = POP_STR();
@@ -3779,16 +3782,17 @@ Decompile(SprintStack *ss, jsbytecode *p
                                   ? predot_format
                                   : preindex_format,
                                   js_incop_strs[!(cs->format & JOF_INC)],
                                   lval, xval);
                 } else {
                     todo = Sprint(&ss->sprinter, ss_format,
                                   js_incop_strs[!(cs->format & JOF_INC)], lval);
                 }
+                len += GetDecomposeLength(pc, JSOP_INCELEM_LENGTH);
                 break;
 
               case JSOP_ARGINC:
               case JSOP_ARGDEC:
                 atom = GetArgOrVarAtom(jp, GET_ARGNO(pc));
                 LOCAL_ASSERT(atom);
                 goto do_atominc;
 
@@ -3800,31 +3804,34 @@ Decompile(SprintStack *ss, jsbytecode *p
               do_atominc:
                 lval = QuoteString(&ss->sprinter, atom, 0);
                 if (!lval)
                     return NULL;
                 RETRACT(&ss->sprinter, lval);
               do_lvalinc:
                 todo = Sprint(&ss->sprinter, ss_format,
                               lval, js_incop_strs[!(cs->format & JOF_INC)]);
+                if (js_CodeSpec[*pc].format & JOF_DECOMPOSE)
+                    len += GetDecomposeLength(pc, js_CodeSpec[*pc].length);
                 break;
 
               case JSOP_PROPINC:
               case JSOP_PROPDEC:
                 GET_ATOM_QUOTE_AND_FMT(postindex_format, postdot_format, rval);
 
                 /*
                  * Force precedence below the numeric literal opcodes, so that
                  * 42..foo or 10000..toString(16), e.g., decompile with parens
                  * around the left-hand side of dot.
                  */
                 op = JSOP_GETPROP;
                 lval = POP_STR();
                 todo = Sprint(&ss->sprinter, fmt, lval, rval,
                               js_incop_strs[!(cs->format & JOF_INC)]);
+                len += GetDecomposeLength(pc, JSOP_PROPINC_LENGTH);
                 break;
 
               case JSOP_ELEMINC:
               case JSOP_ELEMDEC:
                 op = JSOP_NOP;          /* turn off parens */
                 xval = POP_STR();
                 op = JSOP_GETELEM;
                 lval = POP_STR();
@@ -3834,16 +3841,17 @@ Decompile(SprintStack *ss, jsbytecode *p
                                   ? postdot_format
                                   : postindex_format,
                                   lval, xval,
                                   js_incop_strs[!(cs->format & JOF_INC)]);
                 } else {
                     todo = Sprint(&ss->sprinter, ss_format,
                                   lval, js_incop_strs[!(cs->format & JOF_INC)]);
                 }
+                len += GetDecomposeLength(pc, JSOP_ELEMINC_LENGTH);
                 break;
 
               case JSOP_GETPROP2:
                 op = JSOP_GETPROP;
                 (void) PopOff(ss, lastop);
                 /* FALL THROUGH */
 
               case JSOP_CALLPROP:
@@ -4760,19 +4768,16 @@ Decompile(SprintStack *ss, jsbytecode *p
         }
 
         if (cs->format & JOF_CALLOP) {
             todo = Sprint(&ss->sprinter, "");
             if (todo < 0 || !PushOff(ss, todo, saveop))
                 return NULL;
         }
 
-        if (js_CodeSpec[*pc].format & JOF_DECOMPOSE)
-            pc += GetDecomposeLength(pc, js_CodeSpec[*pc].length);
-
         pc += len;
     }
 
 /*
  * Undefine local macros.
  */
 #undef inXML
 #undef DECOMPILE_CODE