From e841f94c64944aad7ff70182ce381c1dd0fe49e4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 15 Jul 2019 17:36:28 +0200 Subject: [PATCH] [js-api] Add support for exceptions. --- document/js-api/index.bs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 87598c6fa..f66dba74e 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -995,6 +995,9 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |argsSeq|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. If |ret| is [=error=], throw an exception. This exception should be a WebAssembly {{RuntimeError}} exception, unless otherwise indicated by the WebAssembly error mapping. + 1. If |ret| is an exception, + 1. If the exception is a value that was thrown by JavaScript code called by the Exported Function, throw the exception itself. + 1. Else, throw a {{RuntimeError}} exception. 1. If |ret| is empty, return undefined. 1. Otherwise, return [=ToJSValue=](|v|), where |v| is the singular element of |ret|. @@ -1024,7 +1027,9 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Let |hostfunc| be a [=host function=] which performs the following steps when called with arguments |arguments|: 1. Let |result| be the result of [=run a host function|running a host function=] from |func|, |functype|, and |arguments|. 1. Assert: |result|.\[[Type]] is throw or return. - 1. If |result|.\[[Type]] is throw, then trigger a WebAssembly trap, and propagate |result|.\[[Value]] to the enclosing JavaScript. + 1. If |result|.\[[Type]] is throw, then: + 1. Let |exception| be [=ToWebAssemblyValue=](|result|.\[[Value]], [=anyref=]). + 1. [=WebAssembly/Throw=] |exception| with the [=JavaScript exception tag=]. 1. Otherwise, return |result|.\[[Value]]. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). @@ -1096,6 +1101,22 @@ The algorithm ToWebAssemblyValue(|v|, |type|, |error|) coerces a Java +

Exceptions

+ +
+ +To throw a WebAssembly value |payload| given an exception tag |tag|, +perform the following steps: + +1. Let |exception| be a new [=exnref=] value with |payload| and |tag|. +1. Unwind the stack until reaching the *catching try block*. +1. Push |exception| onto the operand stack. +1. Transfer control to the catch block. + +Note: This algorithm is expected to be moved into the core specification. + +
+

Error Objects

WebAssembly defines the following Error classes: CompileError, LinkError, and RuntimeError.