diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 17:15:36 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-08 17:15:36 -0800 |
commit | ed106fefa47ea6d156d8ab9cad2dd479e853acbe (patch) | |
tree | 4eee5cffa69db22d1cf1cc84452d1c81be061ead /tools/js-optimizer.js | |
parent | 62ca2bf2fa47370ec845c91bb2c2e73d48d2c4f5 (diff) |
make sure there is a final return in functions that return value in asm
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index a8753e6f..446ca723 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -1400,6 +1400,7 @@ function registerize(ast, asm) { // We also mark local variables - i.e., having a var definition var localVars = {}; var hasSwitch = false; // we cannot optimize variables if there is a switch + var hasReturnValue = false; traverse(fun, function(node, type) { if (type == 'var') { node[1].forEach(function(defined) { localVars[defined[0]] = 1 }); @@ -1411,6 +1412,8 @@ function registerize(ast, asm) { } } else if (type == 'switch') { hasSwitch = true; + } else if (asm && type == 'return' && node[1]) { + hasReturnValue = true; } }); vacuum(fun); @@ -1587,6 +1590,15 @@ function registerize(ast, asm) { } } denormalizeAsm(fun, finalAsmData); + // Add a final return if one is missing. This is not strictly a register operation, but + // this pass traverses the entire AST anyhow so adding it here is efficient. + if (hasReturnValue) { + var stats = getStatements(fun); + var last = stats[stats.length-1]; + if (last[0] != 'return') { + stats.push(['return', ['num', 0]]); + } + } } }); } |