Bug 736742 - Fix decompiler precedence for destructuring assignment with comma-expression (r=jorendorff)

--HG--
extra : rebase_source : d38dc6e2eec3a90e5bf1d86862da4734d374e6e2
This commit is contained in:
Luke Wagner 2012-03-27 14:48:10 -07:00
parent 910899696e
commit 57eb0b35a5
2 changed files with 17 additions and 2 deletions

View File

@ -73,6 +73,8 @@ test('return let (x = x + 1, [] = x, [[, , ]] = x, y = x) y;');
test('return let ([{a: x}] = x, [, {b: y}] = x) let (x = x + 1, y = y + 2) x + y;', [{a:"p"},{b:"p"}], "p1p2");
test('return let ([] = []) x;');
test('return let ([] = [x]) x;');
test('return let ([a] = (1, [x])) a;');
test('return let ([a] = (1, x, 1, x)) a;', ['ponies']);
test('return let ([x] = [x]) x;');
test('return let ([[a, [b, c]]] = [[x, []]]) a;');
test('return let ([x, y] = [x, x + 1]) x + y;', 1, 3);
@ -129,6 +131,8 @@ test('let (x = x + 1, [] = x, [[, , ]] = x, y = x) {return y;}');
test('let ([{a: x}] = x, [, {b: y}] = x) {let (x = x + 1, y = y + 2) {return x + y;}}', [{a:"p"},{b:"p"}], "p1p2");
test('let ([] = []) {return x;}');
test('let ([] = [x]) {return x;}');
test('let ([a] = (1, [x])) {return a;}');
test('let ([a] = (1, x, 1, x)) {return a;}', ['ponies']);
test('let ([x] = [x]) {return x;}');
test('let ([[a, [b, c]]] = [[x, []]]) {return a;}');
test('let ([x, y] = [x, x + 1]) {return x + y;}', 1, 3);
@ -174,6 +178,8 @@ test('var [{a: X}] = x, [, {b: y}] = x;var X = X + 1, y = y + 2;return X + y;',
test('var [x] = [x];return x;');
test('var [[a, [b, c]]] = [[x, []]];return a;');
test('var [y] = [x];return y;');
test('var [a] = (1, [x]);return a;');
test('var [a] = (1, x, 1, x);return a;', ['ponies']);
test('var [x, y] = [x, x + 1];return x + y;', 1, 3);
test('var [x, y, z] = [x, x + 1, x + 2];return x + y + z;', 1, 6);
test('var [[x]] = [[x]];return x;');
@ -213,6 +219,8 @@ test('if (x) {let [{a: X}] = x, [, {b: Y}] = x;var XX = X + 1, YY = Y + 2;return
test('if (x) {let [[a, [b, c]]] = [[x, []]];return a;}');
test('if (x) {let [X] = [x];return X;}');
test('if (x) {let [y] = [x];return y;}');
test('if (x) {let [a] = (1, [x]);return a;}');
test('if (x) {let [a] = (1, x, 1, x);return a;}', ['ponies']);
test('if (x) {let [X, y] = [x, x + 1];return X + y;}', 1, 3);
test('if (x) {let [X, y, z] = [x, x + 1, x + 2];return X + y + z;}', 1, 6);
test('if (x) {let [[X]] = [[x]];return X;}');
@ -279,6 +287,8 @@ test('for (let y;;) {let y;return x;}');
test('for (let a = x;;) {let c = x, d = x;return c;}');
test('for (let [a, b] = x;;) {let c = x, d = x;return c;}');
test('for (let [] = [[]] = {};;) {return x;}');
test('for (let [a] = (1, [x]);;) {return a;}');
test('for (let [a] = (1, x, 1, x);;) {return a;}', ['ponies']);
isError('for (let x = 1, x = 2;;) {}');
isError('for (let [x, y] = a, {a:x} = b;;) {}');
isError('for (let [x, y, x] = a;;) {}');

View File

@ -4095,8 +4095,13 @@ Decompile(SprintStack *ss, jsbytecode *pc, int nb)
if (!pc)
return NULL;
lval = POP_STR(); /* Pop the decompiler result. */
rval = POP_STR(); /* Pop the initializer expression. */
/* Left-hand side never needs parens. */
JS_ASSERT(js_CodeSpec[JSOP_POP].prec <= 3);
lval = PopStr(ss, JSOP_POP);
/* Make sure comma-expression on rhs gets parens. */
JS_ASSERT(js_CodeSpec[JSOP_SETNAME].prec > js_CodeSpec[JSOP_POP].prec);
rval = PopStr(ss, JSOP_SETNAME);
if (strcmp(rval, forelem_cookie) == 0) {
todo = Sprint(&ss->sprinter, ss_format,