diff --git a/lib/Interpreter/exports.ld b/lib/Interpreter/exports.ld index d834500e0..1f7301dd4 100644 --- a/lib/Interpreter/exports.ld +++ b/lib/Interpreter/exports.ld @@ -2,6 +2,7 @@ -Wl,--export=_ZN4llvm11raw_ostream16SetBufferAndModeEPcmNS0_10BufferKindE -Wl,--export=_ZN4llvm11raw_ostream5writeEPKcm -Wl,--export=_ZN4llvm11raw_ostreamD2Ev +-Wl,--export=_ZN4llvm11raw_ostreamlsEm -Wl,--export=_ZN4llvm15SmallVectorBaseIjE8grow_podEPvmm -Wl,--export=_ZN4llvm15allocate_bufferEmm -Wl,--export=_ZN4llvm21logAllUnhandledErrorsENS_5ErrorERNS_11raw_ostreamENS_5TwineE diff --git a/unittests/CppInterOp/CMakeLists.txt b/unittests/CppInterOp/CMakeLists.txt index 734714238..1665110cb 100644 --- a/unittests/CppInterOp/CMakeLists.txt +++ b/unittests/CppInterOp/CMakeLists.txt @@ -43,6 +43,7 @@ if(EMSCRIPTEN) # --preload-file ${SYSROOT_PATH}/include@/include: # Preloads the system include directory into the Emscripten virtual filesystem to make headers accessible at runtime. target_link_options(CppInterOpTests + PUBLIC "SHELL: -fexceptions" PUBLIC "SHELL: -s MAIN_MODULE=1" PUBLIC "SHELL: -s WASM_BIGINT" PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1" diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 459b71bc3..55cd3f742 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -104,6 +104,33 @@ TEST(InterpreterTest, Process) { clang_Interpreter_dispose(CXI); } +TEST(InterpreterTest, EmscriptenExceptionHandling) { +#ifndef EMSCRIPTEN + GTEST_SKIP() << "This test is intended to check exception handling for Emscripten builds."; +#endif + + std::vector Args = { + "-std=c++20", + "-v", + "-fexceptions", + "-fcxx-exceptions", + "-mllvm", "-enable-emscripten-cxx-exceptions", + "-mllvm", "-enable-emscripten-sjlj" + }; + + Cpp::CreateInterpreter(Args); + + const char* tryCatchCode = R"( + try { + throw 1; + } catch (...) { + 0; + } + )"; + + EXPECT_TRUE(Cpp::Process(tryCatchCode) == 0); +} + TEST(InterpreterTest, CreateInterpreter) { auto* I = Cpp::CreateInterpreter(); EXPECT_TRUE(I);