From 9fb0d43934e9947ba009e131fed19773e0b037b5 Mon Sep 17 00:00:00 2001 From: Luke Wagner Date: Tue, 27 Mar 2012 14:48:10 -0700 Subject: [PATCH] Bug 736742 - Fix decompiler precedence for destructuring assignment with comma-expression (r=jorendorff) --HG-- extra : rebase_source : d38dc6e2eec3a90e5bf1d86862da4734d374e6e2 --- js/src/jit-test/tests/basic/testLet.js | 10 ++++++++++ js/src/jsopcode.cpp | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/js/src/jit-test/tests/basic/testLet.js b/js/src/jit-test/tests/basic/testLet.js index d617259f323e..2dd0d4178c8d 100644 --- a/js/src/jit-test/tests/basic/testLet.js +++ b/js/src/jit-test/tests/basic/testLet.js @@ -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;;) {}'); diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp index 9b5b0c65af60..59347bfd675d 100644 --- a/js/src/jsopcode.cpp +++ b/js/src/jsopcode.cpp @@ -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,