From 8773f0c67e5e7577fdfb659f78f6db4fc7955c70 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Wed, 12 Aug 2026 18:59:41 +0000 Subject: [PATCH 1/9] [EH] Move EH status management to exceptions.js (NFC) #27498 moved EH status management (`uncaughtExceptionCount` and `exceptionLast` from `libexceptions.js` to `libunwind.js`, but because in the native libcxxabi and libunwind, the management is done within libcxxabi, I think it'd be more consistent if we do the same for the JS libraries. --- src/lib/libexceptions.js | 27 ++++++++++++++++++++------- src/lib/libunwind.js | 19 ------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index e52ab43daef16..7ea77d8cf5933 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,17 @@ var LibraryExceptions = { info.init(type, destructor); #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); - ptr = new CppException(ptr); + exceptionLast = new CppException(ptr); + ptr = exceptionLast; #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 +135,15 @@ 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); + exceptionLast = new CppException(ptr); + ptr = exceptionLast; #endif __Unwind_RaiseException(ptr); }, @@ -208,7 +216,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 +231,11 @@ 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); + exceptionLast = new CppException(ptr); + ptr = exceptionLast; #endif __Unwind_RaiseException(ptr); }, @@ -300,7 +310,10 @@ var LibraryExceptions = { #if EXCEPTION_DEBUG dbg("__resumeException " + [ptrToString(ptr), exceptionLast]); #endif - ptr = exceptionLast ?? new CppException(ptr); + if (!exceptionLast) { + exceptionLast = new CppException(ptr); + } + ptr = exceptionLast; #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') }}} }, From da4a2d16a360a03c7c2371d22286593ef7ade023 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 01:14:15 +0000 Subject: [PATCH 2/9] ptr = exceptionLast ??= new CppException(ptr) --- emcc.py | 2 +- src/lib/libexceptions.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/emcc.py b/emcc.py index aae61e47b1655..d77f3456b0455 100644 --- a/emcc.py +++ b/emcc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python3SDfdlskjfdskl # Copyright 2011 The Emscripten Authors. All rights reserved. # Emscripten is available under two separate licenses, the MIT license and the # University of Illinois/NCSA Open Source License. Both these licenses can be diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index 7ea77d8cf5933..45641c51eebca 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -310,10 +310,7 @@ var LibraryExceptions = { #if EXCEPTION_DEBUG dbg("__resumeException " + [ptrToString(ptr), exceptionLast]); #endif - if (!exceptionLast) { - exceptionLast = new CppException(ptr); - } - ptr = exceptionLast; + ptr = exceptionLast ??= new CppException(ptr) #endif __Unwind_Resume(ptr); }, From 49803bde48df2ea562a73a3342a850ce35a0960b Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 04:24:56 +0000 Subject: [PATCH 3/9] Remove unexpected change --- emcc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index d77f3456b0455..aae61e47b1655 100644 --- a/emcc.py +++ b/emcc.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3SDfdlskjfdskl +#!/usr/bin/env python3 # Copyright 2011 The Emscripten Authors. All rights reserved. # Emscripten is available under two separate licenses, the MIT license and the # University of Illinois/NCSA Open Source License. Both these licenses can be From b3b0d7f4fffd05349d03c8952f85817dde52b0bb Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 04:30:35 +0000 Subject: [PATCH 4/9] dummy --- emcc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index aae61e47b1655..ed9480f495a81 100644 --- a/emcc.py +++ b/emcc.py @@ -3,7 +3,7 @@ # Emscripten is available under two separate licenses, the MIT license and the # University of Illinois/NCSA Open Source License. Both these licenses can be # found in the LICENSE file. - +dummy """\ emcc - compiler helper script ============================= From c6236469d43ae6897c391786dd49deb89a96f309 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 04:30:41 +0000 Subject: [PATCH 5/9] Revert "dummy" This reverts commit b3b0d7f4fffd05349d03c8952f85817dde52b0bb. --- emcc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emcc.py b/emcc.py index ed9480f495a81..aae61e47b1655 100644 --- a/emcc.py +++ b/emcc.py @@ -3,7 +3,7 @@ # Emscripten is available under two separate licenses, the MIT license and the # University of Illinois/NCSA Open Source License. Both these licenses can be # found in the LICENSE file. -dummy + """\ emcc - compiler helper script ============================= From 223c6eca1f307aae24c5f68a70d15dbd37b0dcd6 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 04:34:14 +0000 Subject: [PATCH 6/9] Missing semicolon? --- src/lib/libexceptions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index 45641c51eebca..9ca0564670ee5 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -310,7 +310,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); }, From b6b3bb20e675c26faea00f79d2490a5ca49aff20 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 04:38:24 +0000 Subject: [PATCH 7/9] Use ptr = exceptionLast = new CppException(ptr) --- src/lib/libexceptions.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index 9ca0564670ee5..9729b1db80f3c 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -110,8 +110,7 @@ var LibraryExceptions = { info.init(type, destructor); #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); - exceptionLast = new CppException(ptr); - ptr = exceptionLast; + ptr = exceptionLast = new CppException(ptr); #endif uncaughtExceptionCount++; __Unwind_RaiseException(ptr); @@ -142,8 +141,7 @@ var LibraryExceptions = { dbg('__cxa_rethrow: ' + [ptrToString(ptr), exceptionLast, 'stack', exceptionCaught]); #endif - exceptionLast = new CppException(ptr); - ptr = exceptionLast; + ptr = exceptionLast = new CppException(ptr); #endif __Unwind_RaiseException(ptr); }, @@ -234,8 +232,7 @@ var LibraryExceptions = { uncaughtExceptionCount++; #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); - exceptionLast = new CppException(ptr); - ptr = exceptionLast; + ptr = exceptionLast = new CppException(ptr); #endif __Unwind_RaiseException(ptr); }, From d09c2441d79aa06b04e1f8e7de17ff8466da0dd9 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 09:13:17 +0000 Subject: [PATCH 8/9] $uncaughtExceptionCount: 0 --- src/lib/libexceptions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index 9729b1db80f3c..118993dba53fd 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -6,7 +6,7 @@ var LibraryExceptions = { #if !WASM_EXCEPTIONS - $uncaughtExceptionCount: '0', + $uncaughtExceptionCount: 0, #if !DISABLE_EXCEPTION_CATCHING $exceptionLast: null, #endif From 98b8aeb72ca832a3abdf5d39a94dccada2c088a3 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Thu, 13 Aug 2026 09:19:38 +0000 Subject: [PATCH 9/9] Automatic rebaseline of codesize expectations. NFC This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (10) test expectation files were updated by running the tests with `--rebaseline`: ``` codesize/test_codesize_cxx_ctors1.json: 153937 => 153947 [+10 bytes / +0.01%] codesize/test_codesize_cxx_ctors2.json: 153343 => 153353 [+10 bytes / +0.01%] codesize/test_codesize_cxx_except.json: 200109 => 200106 [-3 bytes / -0.00%] codesize/test_codesize_cxx_mangle.json: 266439 => 266436 [-3 bytes / -0.00%] codesize/test_codesize_cxx_noexcept.json: 155847 => 155857 [+10 bytes / +0.01%] codesize/test_codesize_cxx_wasmfs.json: 180965 => 180975 [+10 bytes / +0.01%] codesize/test_codesize_hello_O0.json: 38609 => 38586 [-23 bytes / -0.06%] test/codesize/test_codesize_minimal_O0.expected.js updated codesize/test_codesize_minimal_O0.json: 19718 => 19695 [-23 bytes / -0.12%] codesize/test_unoptimized_code_size.json: 172395 => 172339 [-56 bytes / -0.03%] Average change: -0.02% (-0.12% - +0.01%) ``` --- test/codesize/test_codesize_cxx_ctors1.json | 8 ++++---- test/codesize/test_codesize_cxx_ctors2.json | 8 ++++---- test/codesize/test_codesize_cxx_except.json | 8 ++++---- test/codesize/test_codesize_cxx_mangle.json | 4 ++-- test/codesize/test_codesize_cxx_noexcept.json | 8 ++++---- test/codesize/test_codesize_cxx_wasmfs.json | 8 ++++---- test/codesize/test_codesize_hello_O0.json | 8 ++++---- test/codesize/test_codesize_minimal_O0.expected.js | 1 - test/codesize/test_codesize_minimal_O0.json | 8 ++++---- test/codesize/test_unoptimized_code_size.json | 12 ++++++------ 10 files changed, 36 insertions(+), 37 deletions(-) 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 }