summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2021-12-28 17:03:13 -0800
committerGitHub <noreply@github.com>2021-12-28 17:03:13 -0800
commitdb23896425e78fbccff5ac3e4ec1799097cf3cac (patch)
tree91d91c730f89ac3a204fde22e7b5e0e9b3704dec /src
parent75988573cef85d1f678c55246aeb2d29b0fa0a77 (diff)
downloadbinaryen-db23896425e78fbccff5ac3e4ec1799097cf3cac.tar.gz
binaryen-db23896425e78fbccff5ac3e4ec1799097cf3cac.tar.bz2
binaryen-db23896425e78fbccff5ac3e4ec1799097cf3cac.zip
[EH] Support try-delegate in interpreter (#4408)
Diffstat (limited to 'src')
-rw-r--r--src/wasm-interpreter.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index caccef654..ecfc00d93 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -2697,6 +2697,9 @@ private:
FunctionScope& scope;
// Stack of <caught exception, caught catch's try label>
SmallVector<std::pair<WasmException, Name>, 4> exceptionStack;
+ // The current delegate target, if delegation of an exception is in
+ // progress. If no delegation is in progress, this will be an empty Name.
+ Name currDelegateTarget;
protected:
// Returns the instance that defines the memory used by this one.
@@ -3443,6 +3446,16 @@ private:
try {
return this->visit(curr->body);
} catch (const WasmException& e) {
+ // If delegation is in progress and the current try is not the target of
+ // the delegation, don't handle it and just rethrow.
+ if (currDelegateTarget.is()) {
+ if (currDelegateTarget == curr->name) {
+ currDelegateTarget.clear();
+ } else {
+ throw;
+ }
+ }
+
auto processCatchBody = [&](Expression* catchBody) {
// Push the current exception onto the exceptionStack in case
// 'rethrow's use it
@@ -3469,6 +3482,9 @@ private:
if (curr->hasCatchAll()) {
return processCatchBody(curr->catchBodies.back());
}
+ if (curr->isDelegate()) {
+ currDelegateTarget = curr->delegateTarget;
+ }
// This exception is not caught by this try-catch. Rethrow it.
throw;
}