Skip to content

Commit 3ce53e8

Browse files
authored
[emscripten] Fix handleFatalError to match recent emscripten changes (#8521)
Since emscripten-core/emscripten#26523 emscripten no longer throws raw pointers/numbers.
1 parent 10c876d commit 3ce53e8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/js/binaryen.js-post.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,15 +3274,22 @@ function handleFatalError(func) {
32743274
try {
32753275
return func();
32763276
} catch (e) {
3277-
// Fatal errors begin with that prefix. Strip it out, and the newline.
3278-
// C++ exceptions are thrown as pointers (numbers) in release builds
3279-
// but CppException JS class in debug builds.
3277+
// Fatal errors begin with a specific prefix. Strip it out, and the newline.
32803278
if (typeof e === 'number') {
3279+
// Older version of emscripten can throw C++ exceptions as pointers
3280+
// (numbers) in release builds.
32813281
var [_, message] = getExceptionMessage(e);
32823282
if (message?.startsWith('Fatal: ')) {
32833283
throw new Error(message.substr(7).trim());
32843284
}
32853285
} else {
3286+
// Newer version of emscripten always throw CppException object but don't
3287+
// always populate the `.message` field.
3288+
// TODO: Set EXCEPTION_STACK_TRACES instead?
3289+
if (!e.message) {
3290+
var [_, message] = getExceptionMessage(e);
3291+
e.message = message;
3292+
}
32863293
e.message = e.message.replace('Fatal:', '');
32873294
e.message = e.message.trim();
32883295
}

0 commit comments

Comments
 (0)