diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 15:12:12 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 15:12:12 -0800 |
commit | 486db79e93244b743b8ce8bef83ce93ef9470e16 (patch) | |
tree | ea8dc3bb76cb10a149a4b55ff75255da1350a387 /tools/js-optimizer.js | |
parent | 14bb76d546b774bf823e3a578aa69f7d1bff0f2c (diff) |
fix bug with lack of recursion in simplifyBitops
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 103fb1fe..22d0f4d1 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -418,20 +418,25 @@ function simplifyExpressionsPre(ast) { var rerun = true; while (rerun) { rerun = false; - traverseGenerated(ast, function(node, type, stack) { + traverseGenerated(ast, function process(node, type, stack) { if (type == 'binary' && node[1] == '|' && (jsonCompare(node[2], ZERO) || jsonCompare(node[3], ZERO))) { - stack.push(1); // From here on up, no need for this kind of correction, it's done at the top - // We might be able to remove this correction - for (var i = stack.length-2; i >= 0; i--) { + for (var i = stack.length-1; i >= 0; i--) { if (stack[i] == 1) { // Great, we can eliminate rerun = true; - return jsonCompare(node[2], ZERO) ? node[3] : node[2]; + // we will replace ourselves with the non-zero side. Recursively process that node. + var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other; + while (other = process(result, result[0], stack)) { + result = other; + } + return result; } else if (stack[i] == -1) { break; // Too bad, we can't } } + stack.push(1); // From here on up, no need for this kind of correction, it's done at the top + // (Add this at the end, so it is only added if we did not remove it) } else if (type == 'binary' && node[1] in USEFUL_BINARY_OPS) { stack.push(1); } else if ((type == 'binary' && node[1] in SAFE_BINARY_OPS) || type == 'num' || type == 'name') { |