diff options
-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> |