diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-09-30 17:50:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-03 10:53:57 -0700 |
commit | c182633f18453cd5c46459ccdce2280ccc591644 (patch) | |
tree | fb7d23ab9f9eb44639a4da5fe86a5755bf9cda84 /src | |
parent | 04732d022bfaa3ea08a78886d0d8dec5658fc58d (diff) |
emit final missing returns in compiler itself
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index d7f00a1b..64da4228 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -821,9 +821,17 @@ function JSify(data, functionsOnly, givenFunctions) { // Finalize function if (LABEL_DEBUG && functionNameFilterTest(func.ident)) func.JS += " INDENT = INDENT.substr(0, INDENT.length-2);\n"; // Ensure a return in a function with a type that returns, even if it lacks a return (e.g., if it aborts()) - if (RELOOP && func.lines.length > 0 && func.returnType != 'void') { - var returns = func.labels.filter(function(label) { return label.lines[label.lines.length-1].intertype == 'return' }).length; - if (returns == 0) func.JS += INDENTATION + 'return ' + asmCoercion('0', func.returnType); + if (RELOOP && ASM_JS && func.lines.length > 0 && func.returnType != 'void') { + var lastCurly = func.JS.lastIndexOf('}'); + var lastReturn = func.JS.lastIndexOf('return '); + if ((lastCurly < 0 && lastReturn < 0) || // no control flow, no return + (lastCurly >= 0 && lastReturn < lastCurly)) { // control flow, no return past last join + if (func.returnType in Runtime.FLOAT_TYPES) { + func.JS += ' return +0;\n'; + } else { + func.JS += ' return 0;\n'; + } + } } func.JS += '}\n'; |