diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-28 16:59:06 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-28 17:04:51 -0700 |
commit | 5ba1a0e94fdb1f230efa34bfe5e2725ff7abef39 (patch) | |
tree | a7997d3d818b28f4908fc9e572df8dd54fc2cf98 | |
parent | 1796e1798ec0664d937644308f016d65af7b216a (diff) |
do not swallow exceptions in invoke_* that are not C++ exceptions or longjmp
-rwxr-xr-x | emscripten.py | 2 | ||||
-rwxr-xr-x | tests/runner.py | 31 |
2 files changed, 33 insertions, 0 deletions
diff --git a/emscripten.py b/emscripten.py index 62f68fcd..6c758942 100755 --- a/emscripten.py +++ b/emscripten.py @@ -447,11 +447,13 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, ''' % (sig, i, args, arg_coercions, jsret)) args = ','.join(['a' + str(i) for i in range(1, len(sig))]) args = 'index' + (',' if args else '') + args + # C++ exceptions are numbers, and longjmp is a string 'longjmp' asm_setup += ''' function invoke_%s(%s) { try { %sModule.dynCall_%s(%s); } catch(e) { + if (typeof e !== 'number' && e !== 'longjmp') throw e; asm.setThrew(1, 0); } } diff --git a/tests/runner.py b/tests/runner.py index b7a7478f..4092d3de 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -2630,6 +2630,37 @@ back 12 ''') + def test_longjmp_exc(self): + src = r''' + #include <stdlib.h> + #include <stdio.h> + #include <setjmp.h> + #include <emscripten.h> + + jmp_buf abortframe; + + void dostuff(int a) { + printf("pre\n"); + if (a != 42) emscripten_run_script("waka_waka()"); // this should fail, and never reach "never" + printf("never\n"); + + if (a == 100) { + longjmp (abortframe, -1); + } + + if (setjmp(abortframe)) { + printf("got 100"); + } + } + + int main(int argc, char **argv) { + dostuff(argc); + exit(1); + return 1; + } + ''' + self.do_run(src, 'waka_waka'); + def test_setjmp_many(self): src = r''' #include <stdio.h> |