Try to return an error from call_protected when an exception occurs.

Something breaks pretty drastically sometimes, not sure why.
This commit is contained in:
Lachlan Sneff
2019-03-02 19:08:15 -08:00
parent caf2205936
commit 9cfda6800f
5 changed files with 98 additions and 30 deletions

View File

@ -141,6 +141,7 @@ extern "C" {
}
[[noreturn]] void throw_trap(WasmTrap::Type ty) {
std::cout << "throwing trap: " << ty << std::endl;
throw WasmTrap(ty);
}
@ -148,13 +149,30 @@ extern "C" {
delete module;
}
void invoke_trampoline(trampoline_t trampoline, void* ctx, void* func, void* params, void* results) {
bool invoke_trampoline(
trampoline_t trampoline,
void* ctx,
void* func,
void* params,
void* results,
WasmTrap::Type* trap_out
) throw() {
try {
trampoline(ctx, func, params, results);
std::cout << "Success" << std::endl;
return true;
} catch(const WasmTrap& e) {
std::cout << e.description() << std::endl;
*trap_out = e.type;
return false;
} catch(const WasmException& e) {
std::cout << e.description() << std::endl;
*trap_out = WasmTrap::Type::Unknown;
return false;
} catch (...) {
std::cout << "unknown exception" << std::endl;
std::cout << "unknown" << std::endl;
*trap_out = WasmTrap::Type::Unknown;
return false;
}
}