diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index e52ab43daef16..118993dba53fd 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -6,6 +6,10 @@ var LibraryExceptions = { #if !WASM_EXCEPTIONS + $uncaughtExceptionCount: 0, +#if !DISABLE_EXCEPTION_CATCHING + $exceptionLast: null, +#endif $exceptionCaught: ' []', // This class is the exception metadata which is prepended to each thrown object (in WASM memory). @@ -80,7 +84,7 @@ var LibraryExceptions = { // Here, we throw an exception after recording a couple of values that we need to remember // We also remember that it was the last exception thrown as we need to know that later. - __cxa_throw__deps: ['$ExceptionInfo', + __cxa_throw__deps: ['$ExceptionInfo', '$uncaughtExceptionCount', #if !DISABLE_EXCEPTION_CATCHING '$exceptionLast', '__cxa_increment_exception_refcount', @@ -106,15 +110,16 @@ var LibraryExceptions = { info.init(type, destructor); #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); - ptr = new CppException(ptr); + ptr = exceptionLast = new CppException(ptr); #endif + uncaughtExceptionCount++; __Unwind_RaiseException(ptr); }, // This exception will be caught twice, but while begin_catch runs twice, // we early-exit from end_catch when the exception has been rethrown, so // pop that here from the caught exceptions. - __cxa_rethrow__deps: ['$exceptionCaught', + __cxa_rethrow__deps: ['$exceptionCaught', '$uncaughtExceptionCount', #if !DISABLE_EXCEPTION_CATCHING '$exceptionLast', '__cxa_increment_exception_refcount', @@ -129,13 +134,14 @@ var LibraryExceptions = { var ptr = info.excPtr; info.set_rethrown(true); info.set_caught(false); + uncaughtExceptionCount++; #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); #if EXCEPTION_DEBUG dbg('__cxa_rethrow: ' + [ptrToString(ptr), exceptionLast, 'stack', exceptionCaught]); #endif - ptr = new CppException(ptr); + ptr = exceptionLast = new CppException(ptr); #endif __Unwind_RaiseException(ptr); }, @@ -208,7 +214,7 @@ var LibraryExceptions = { return info.get_type(); }, - __cxa_rethrow_primary_exception__deps: ['$ExceptionInfo', + __cxa_rethrow_primary_exception__deps: ['$ExceptionInfo', '$uncaughtExceptionCount', #if !DISABLE_EXCEPTION_CATCHING '$exceptionLast', '__cxa_increment_exception_refcount', @@ -223,9 +229,10 @@ var LibraryExceptions = { var info = new ExceptionInfo(ptr); info.set_rethrown(true); info.set_caught(false); + uncaughtExceptionCount++; #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); - ptr = new CppException(ptr); + ptr = exceptionLast = new CppException(ptr); #endif __Unwind_RaiseException(ptr); }, @@ -300,7 +307,7 @@ var LibraryExceptions = { #if EXCEPTION_DEBUG dbg("__resumeException " + [ptrToString(ptr), exceptionLast]); #endif - ptr = exceptionLast ?? new CppException(ptr); + ptr = exceptionLast ??= new CppException(ptr); #endif __Unwind_Resume(ptr); }, diff --git a/src/lib/libunwind.js b/src/lib/libunwind.js index db11f26efbd02..26fb6fbb2c7c6 100644 --- a/src/lib/libunwind.js +++ b/src/lib/libunwind.js @@ -9,10 +9,6 @@ #endif var LibraryUnwind = { - $uncaughtExceptionCount: '0', -#if !DISABLE_EXCEPTION_CATCHING - $exceptionLast: null, -#endif _Unwind_Backtrace__deps: ['$getCallstack'], _Unwind_Backtrace: (func, arg) => { @@ -28,26 +24,11 @@ var LibraryUnwind = { _Unwind_FindEnclosingFunction: (ip) => 0, // we cannot succeed - _Unwind_RaiseException__deps: ['$uncaughtExceptionCount', -#if !DISABLE_EXCEPTION_CATCHING - '$exceptionLast', -#endif - ], _Unwind_RaiseException: (ex) => { -#if !DISABLE_EXCEPTION_CATCHING - exceptionLast = ex; - uncaughtExceptionCount++; -#endif {{{ makeThrow('ex') }}} }, -#if !DISABLE_EXCEPTION_CATCHING - _Unwind_Resume__deps: ['$exceptionLast'], -#endif _Unwind_Resume: (ex) => { -#if !DISABLE_EXCEPTION_CATCHING - exceptionLast = ex; -#endif {{{ makeThrow('ex') }}} }, diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index 45eec3cc55391..e613e803a93e1 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { - "a.out.js": 19198, - "a.out.js.gz": 8107, + "a.out.js": 19208, + "a.out.js.gz": 8121, "a.out.nodebug.wasm": 134739, "a.out.nodebug.wasm.gz": 51534, - "total": 153937, - "total_gz": 59641, + "total": 153947, + "total_gz": 59655, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index 302bf73dec880..aba761457982a 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { - "a.out.js": 19175, - "a.out.js.gz": 8091, + "a.out.js": 19185, + "a.out.js.gz": 8104, "a.out.nodebug.wasm": 134168, "a.out.nodebug.wasm.gz": 51198, - "total": 153343, - "total_gz": 59289, + "total": 153353, + "total_gz": 59302, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index d804ef6e2fcf7..c1bf0475d1b74 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { - "a.out.js": 22904, - "a.out.js.gz": 9078, + "a.out.js": 22901, + "a.out.js.gz": 9079, "a.out.nodebug.wasm": 177205, "a.out.nodebug.wasm.gz": 59111, - "total": 200109, - "total_gz": 68189, + "total": 200106, + "total_gz": 68190, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index af673129bcfaf..c232a3919ad31 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,9 +1,9 @@ { - "a.out.js": 22954, + "a.out.js": 22951, "a.out.js.gz": 9099, "a.out.nodebug.wasm": 243485, "a.out.nodebug.wasm.gz": 81306, - "total": 266439, + "total": 266436, "total_gz": 90405, "sent": [ "__cxa_begin_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 01e0ac0badd1b..619b895048795 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { - "a.out.js": 19198, - "a.out.js.gz": 8107, + "a.out.js": 19208, + "a.out.js.gz": 8121, "a.out.nodebug.wasm": 136649, "a.out.nodebug.wasm.gz": 52153, - "total": 155847, - "total_gz": 60260, + "total": 155857, + "total_gz": 60274, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 0a8e5f2ee0c6b..cb1bac1cd6e56 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 6594, - "a.out.js.gz": 3145, + "a.out.js": 6604, + "a.out.js.gz": 3154, "a.out.nodebug.wasm": 174371, "a.out.nodebug.wasm.gz": 64908, - "total": 180965, - "total_gz": 68053, + "total": 180975, + "total_gz": 68062, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 84b78a36b3cac..8ad48f5be16de 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 23494, - "a.out.js.gz": 8565, + "a.out.js": 23471, + "a.out.js.gz": 8555, "a.out.nodebug.wasm": 15115, "a.out.nodebug.wasm.gz": 7464, - "total": 38609, - "total_gz": 16029, + "total": 38586, + "total_gz": 16019, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index 3c2b4c0164320..1b627a7f0a2cf 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -1030,7 +1030,6 @@ missingLibrarySymbols.forEach(missingLibrarySymbol) 'emClearImmediate_deps', 'emClearImmediate', 'promiseMap', - 'uncaughtExceptionCount', 'Browser', 'requestFullscreen', 'setCanvasSize', diff --git a/test/codesize/test_codesize_minimal_O0.json b/test/codesize/test_codesize_minimal_O0.json index 80fb306ad0307..5cf6c7417b280 100644 --- a/test/codesize/test_codesize_minimal_O0.json +++ b/test/codesize/test_codesize_minimal_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 18703, - "a.out.js.gz": 6742, + "a.out.js": 18680, + "a.out.js.gz": 6732, "a.out.nodebug.wasm": 1015, "a.out.nodebug.wasm.gz": 602, - "total": 19718, - "total_gz": 7344, + "total": 19695, + "total_gz": 7334, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 9e4745e439d93..76798f8761f3a 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 54578, - "hello_world.js.gz": 17345, + "hello_world.js": 54550, + "hello_world.js.gz": 17328, "hello_world.wasm": 15115, "hello_world.wasm.gz": 7464, "no_asserts.js": 23629, "no_asserts.js.gz": 8288, "no_asserts.wasm": 12229, "no_asserts.wasm.gz": 6004, - "strict.js": 51729, - "strict.js.gz": 16348, + "strict.js": 51701, + "strict.js.gz": 16338, "strict.wasm": 15115, "strict.wasm.gz": 7461, - "total": 172395, - "total_gz": 62910 + "total": 172339, + "total_gz": 62883 }