You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: document/js-api/index.bs
+22-1Lines changed: 22 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -995,6 +995,9 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
995
995
1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |argsSeq|).
996
996
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
997
997
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>.
998
+
1. If |ret| is an exception,
999
+
1. If the exception is a value that was thrown by JavaScript code called by the Exported Function, throw the exception itself.
1000
+
1. Else, throw a {{RuntimeError}} exception.
998
1001
1. If |ret| is empty, return undefined.
999
1002
1. Otherwise, return [=ToJSValue=](|v|), where |v| is the singular element of |ret|.
1000
1003
</div>
@@ -1024,7 +1027,9 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
1024
1027
1. Let |hostfunc| be a [=host function=] which performs the following steps when called with arguments |arguments|:
1025
1028
1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|.
1026
1029
1. Assert: |result|.\[[Type]] is <emu-const>throw</emu-const> or <emu-const>return</emu-const>.
1027
-
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript.
1030
+
1. If |result|.\[[Type]] is <emu-const>throw</emu-const>, then:
1031
+
1. Let |exception| be [=ToWebAssemblyValue=](|result|.\[[Value]], [=anyref=]).
1032
+
1. [=WebAssembly/Throw=] |exception| with the [=JavaScript exception tag=].
1028
1033
1. Otherwise, return |result|.\[[Value]].
1029
1034
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
1030
1035
1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|).
@@ -1096,6 +1101,22 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a Java
1096
1101
</div>
1097
1102
1098
1103
1104
+
<h3 id="exceptions">Exceptions</h3>
1105
+
1106
+
<div algorithm>
1107
+
1108
+
To <dfn for=WebAssembly>throw</dfn> a WebAssembly value |payload| given an exception tag |tag|,
1109
+
perform the following steps:
1110
+
1111
+
1. Let |exception| be a new [=exnref=] value with |payload| and |tag|.
1112
+
1. Unwind the stack until reaching the *catching try block*.
1113
+
1. Push |exception| onto the operand stack.
1114
+
1. Transfer control to the catch block.
1115
+
1116
+
Note: This algorithm is expected to be moved into the core specification.
1117
+
1118
+
</div>
1119
+
1099
1120
<h3 id="error-objects">Error Objects</h3>
1100
1121
1101
1122
WebAssembly defines the following Error classes: <dfn exception>CompileError</dfn>, <dfn exception>LinkError</dfn>, and <dfn exception>RuntimeError</dfn>.
0 commit comments