Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 1fe9cff

Browse files
committed
[js-api] Add support for exceptions.
1 parent e7196b7 commit 1fe9cff

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

document/js-api/index.bs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,9 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
977977
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |argsSeq|).
978978
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
979979
1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by <a href="#errors">the WebAssembly error mapping</a>.
980+
1. If |ret| is an exception,
981+
1. If the exception is a value that was thrown by JavaScript code called by the Exported Function, throw the exception itself.
982+
1. Else, throw a {{RuntimeError}} exception.
980983
1. If |ret| is empty, return undefined.
981984
1. Otherwise, return [=ToJSValue=](|v|), where |v| is the singular element of |ret|.
982985
</div>
@@ -1006,7 +1009,9 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
10061009
1. Let |hostfunc| be a [=host function=] which performs the following steps when called:
10071010
1. Let |result| be the result of [=run a host function|running a host function=] from |func| and |functype|.
10081011
1. Assert: |result|.\[[Type]] is throw or return.
1009-
1. If |result|.\[[Type]] is [=throw=], then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript.
1012+
1. If |result|.\[[Type]] is [=throw=], then:
1013+
1. Let |exception| be [=ToWebAssemblyValue=](|result|.\[[Value]], [=anyref=]).
1014+
1. Throw |exception|.
10101015
1. Otherwise, return |result|.\[[Value]].
10111016
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
10121017
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).

0 commit comments

Comments
 (0)