diff options
author | Heejin Ahn <aheejin@gmail.com> | 2023-04-23 15:47:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-23 15:47:28 +0900 |
commit | 3dd36ab00f6eb117fafbcd0e55170ca2a3796c13 (patch) | |
tree | 1cdfdc8048781733eaebd15c1ad377c54c05d1e5 /src | |
parent | bd1822dde2b08c79c6e98667a5317194ca913545 (diff) | |
download | binaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.tar.gz binaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.tar.bz2 binaryen-3dd36ab00f6eb117fafbcd0e55170ca2a3796c13.zip |
[EH] Support assert_exception (#5684)
`assert_exception` is similar to `assert_trap` but for exceptions, which
is supported in the interpreter of the EH proposal
(https://github.com/WebAssembly/exception-handling/tree/main/interpreter).
We've been using `assert_trap` for both traps and exceptions, but this
PR distinguishes them.
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/wasm-shell.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index 70f52a038..29ccc6c7f 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -35,6 +35,7 @@ using namespace wasm; Name ASSERT_RETURN("assert_return"); Name ASSERT_TRAP("assert_trap"); +Name ASSERT_EXCEPTION("assert_exception"); Name ASSERT_INVALID("assert_invalid"); Name ASSERT_MALFORMED("assert_malformed"); Name ASSERT_UNLINKABLE("assert_unlinkable"); @@ -114,6 +115,8 @@ protected: parseAssertReturn(s); } else if (id == ASSERT_TRAP) { parseAssertTrap(s); + } else if (id == ASSERT_EXCEPTION) { + parseAssertException(s); } else if ((id == ASSERT_INVALID) || (id == ASSERT_MALFORMED)) { parseModuleAssertion(s); } @@ -203,11 +206,24 @@ protected: parseOperation(inner); } catch (const TrapException&) { trapped = true; + } + assert(trapped); + } + + void parseAssertException(Element& s) { + [[maybe_unused]] bool thrown = false; + auto& inner = *s[1]; + if (inner[0]->str() == MODULE) { + return parseModuleAssertion(s); + } + + try { + parseOperation(inner); } catch (const WasmException& e) { std::cout << "[exception thrown: " << e << "]" << std::endl; - trapped = true; + thrown = true; } - assert(trapped); + assert(thrown); } void parseAssertReturn(Element& s) { @@ -284,7 +300,7 @@ protected: ModuleUtils::iterImportedMemories(wasm, reportUnknownImport); } - if (!invalid && id == ASSERT_TRAP) { + if (!invalid && (id == ASSERT_TRAP || id == ASSERT_EXCEPTION)) { try { instantiate(&wasm); } catch (const TrapException&) { |