aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/js-optimizer.js23
-rw-r--r--tools/test-js-optimizer-asm-pre-output.js2
2 files changed, 14 insertions, 11 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 57a3b1b3..89f65eda 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -539,16 +539,19 @@ function simplifyExpressionsPre(ast) {
}
}
}
- } else if (type == 'binary' && node[1] == '|') {
- // canonicalize order of |0 to end
- if (node[2][0] == 'num' && node[2][1] == 0) {
- var temp = node[2];
- node[2] = node[3];
- node[3] = temp;
- }
- // if a seq ends in an |0, remove an external |0
- if (node[2][0] == 'seq' && node[2][2][0] == 'binary' && node[2][2][1] in USEFUL_BINARY_OPS) {
- return node[2];
+ var value = node[3];
+ if (value[0] == 'binary' && value[1] == '|') {
+ // canonicalize order of |0 to end
+ if (value[2][0] == 'num' && value[2][1] == 0) {
+ var temp = value[2];
+ value[2] = value[3];
+ value[3] = temp;
+ }
+ // if a seq ends in an |0, remove an external |0
+ // note that it is only safe to do this in assigns, like we are doing here (return (x, y|0); is not valid)
+ if (value[2][0] == 'seq' && value[2][2][0] == 'binary' && value[2][2][1] in USEFUL_BINARY_OPS) {
+ node[3] = value[2];
+ }
}
}
});
diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js
index a41ba2f8..25d521ab 100644
--- a/tools/test-js-optimizer-asm-pre-output.js
+++ b/tools/test-js-optimizer-asm-pre-output.js
@@ -8,7 +8,7 @@ function a() {
HEAP[1024] = 5;
whee(12, 13);
whee(12, 13);
- f((g = t(), g + g | 0));
+ f((g = t(), g + g | 0) | 0);
}
function b($this, $__n) {
$this = $this | 0;