Skip to content

Commit 3258584

Browse files
authored
Add test for verifying exception handling for emscripten builds (#543)
1 parent e1ace51 commit 3258584

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lib/Interpreter/exports.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-Wl,--export=_ZN4llvm11raw_ostream16SetBufferAndModeEPcmNS0_10BufferKindE
33
-Wl,--export=_ZN4llvm11raw_ostream5writeEPKcm
44
-Wl,--export=_ZN4llvm11raw_ostreamD2Ev
5+
-Wl,--export=_ZN4llvm11raw_ostreamlsEm
56
-Wl,--export=_ZN4llvm15SmallVectorBaseIjE8grow_podEPvmm
67
-Wl,--export=_ZN4llvm15allocate_bufferEmm
78
-Wl,--export=_ZN4llvm21logAllUnhandledErrorsENS_5ErrorERNS_11raw_ostreamENS_5TwineE

unittests/CppInterOp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if(EMSCRIPTEN)
4343
# --preload-file ${SYSROOT_PATH}/include@/include:
4444
# Preloads the system include directory into the Emscripten virtual filesystem to make headers accessible at runtime.
4545
target_link_options(CppInterOpTests
46+
PUBLIC "SHELL: -fexceptions"
4647
PUBLIC "SHELL: -s MAIN_MODULE=1"
4748
PUBLIC "SHELL: -s WASM_BIGINT"
4849
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@ TEST(InterpreterTest, Process) {
104104
clang_Interpreter_dispose(CXI);
105105
}
106106

107+
TEST(InterpreterTest, EmscriptenExceptionHandling) {
108+
#ifndef EMSCRIPTEN
109+
GTEST_SKIP() << "This test is intended to check exception handling for Emscripten builds.";
110+
#endif
111+
112+
std::vector<const char*> Args = {
113+
"-std=c++20",
114+
"-v",
115+
"-fexceptions",
116+
"-fcxx-exceptions",
117+
"-mllvm", "-enable-emscripten-cxx-exceptions",
118+
"-mllvm", "-enable-emscripten-sjlj"
119+
};
120+
121+
Cpp::CreateInterpreter(Args);
122+
123+
const char* tryCatchCode = R"(
124+
try {
125+
throw 1;
126+
} catch (...) {
127+
0;
128+
}
129+
)";
130+
131+
EXPECT_TRUE(Cpp::Process(tryCatchCode) == 0);
132+
}
133+
107134
TEST(InterpreterTest, CreateInterpreter) {
108135
auto* I = Cpp::CreateInterpreter();
109136
EXPECT_TRUE(I);

0 commit comments

Comments
 (0)