From b87068db52f1dd293b35afc67b3e8037ad7408ca Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 14 Feb 2023 18:16:35 -0800 Subject: [PATCH 1/4] Update JS API to better specify opaqueData exception identity --- document/js-api/index.bs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 3da64d69..4e8c7f85 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -798,7 +798,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address The Table(|descriptor|, |value|) constructor, when invoked, performs the following steps: 1. Let |elementType| be [=ToValueType=](|descriptor|["element"]). 1. If |elementType| is not a [=reftype=], - 1. [=Throw=] a {{TypeError}} exception. + 1. Throw a {{TypeError}} exception. 1. Let |initial| be |descriptor|["initial"]. 1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty. 1. If |maximum| is not empty and |maximum| < |initial|, throw a {{RangeError}} exception. @@ -1044,10 +1044,12 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 1. [=list/Append=] [=ToWebAssemblyValue=](|arg|, |t|) to |args|. 1. Set |i| to |i| + 1. 1. Let (|store|, |ret|) be the result of [=func_invoke=](|store|, |funcaddr|, |args|). - 1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, val* | [=error=] | (exception |exntag| |payload| |opaqueData|)). + 1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, val* | [=error=] | (exception |exntag| |payload|)). XXX (we still need to update document/core/appendix/embedding.rst for this) + 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 exception |exntag| |payload| |opaqueData|, then + 1. If |ret| is exception |exntag| |payload|, then + 1. Let |opaqueData| be the [=externref=] assocated with the returned exception. 1. If |opaqueData| is not [=ref.null=] [=externref=], 1. Let « [=ref.extern=] |externaddr| » be |opaqueData|. 1. Throw the result of [=retrieving an extern value=] from |externaddr|. @@ -1081,7 +1083,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Otherwise, if |resultsSize| is 1, return « [=?=] [=ToWebAssemblyValue=](|ret|, |results|[0]) ». 1. Otherwise, 1. Let |method| be [=?=] [=GetMethod=](|ret|, [=@@iterator=]). - 1. If |method| is undefined, [=throw=] a {{TypeError}}. + 1. If |method| is undefined, throw a {{TypeError}}. 1. Let |values| be [=?=] [=IterableToList=](|ret|, |method|). 1. Let |wasmValues| be a new, empty [=list=]. 1. If |values|'s [=list/size=] is not |resultsSize|, throw a {{TypeError}} exception. @@ -1113,7 +1115,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Let |type| be the [=JavaScript exception tag=]. 1. Let |payload| be « ». 1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=]) - 1. [=WebAssembly/Throw=] with |type|, |payload| and |opaqueData|. + 1. [=WebAssembly/Throw=] with |type|, |payload|, associating |opaqueData| with the thrown exception. 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|). @@ -1361,10 +1363,14 @@ For any [=associated store=] |store|, the result of To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps: +1. Associate |opaqueData| with the thrown exception. 1. Unwind the stack until reaching the *catching try block* given |type|. -1. Invoke the catch block with |payload| and |opaqueData|. +1. Invoke the catch block with |payload|. -Note: This algorithm is expected to be moved into the core specification. +Note: The identity represented by |opaqueData| is not exposed to core wasm code, but remains with the exception as it propagates through the wasm frames on the stack. +If the exception propagates back to JavaScript (by returning from [=func_invoke=]), the same |opaqueData| is returned with it. +If the exception is caught and rethrown with the rethrow instruction, the identity remains the same. +Exceptions that originate from core WebAssembly (using the WebAssembly throw instruction) have a |ref.null| identity returned from [=func_invoke=] From af87b7212d4eb3acbf313e8913b9f9f0695002b2 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 16 Feb 2023 15:27:22 -0800 Subject: [PATCH 2/4] review --- document/js-api/index.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 4e8c7f85..87a1480f 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1115,7 +1115,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Let |type| be the [=JavaScript exception tag=]. 1. Let |payload| be « ». 1. Let |opaqueData| be [=ToWebAssemblyValue=](|v|, [=externref=]) - 1. [=WebAssembly/Throw=] with |type|, |payload|, associating |opaqueData| with the thrown exception. + 1. [=WebAssembly/Throw=] with |type|, |payload|, and |opaqueData|. 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|). @@ -1363,11 +1363,11 @@ For any [=associated store=] |store|, the result of To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps: -1. Associate |opaqueData| with the thrown exception. +1. Associate |opaqueData| with the identity of the thrown exception. 1. Unwind the stack until reaching the *catching try block* given |type|. 1. Invoke the catch block with |payload|. -Note: The identity represented by |opaqueData| is not exposed to core wasm code, but remains with the exception as it propagates through the wasm frames on the stack. +Note: The identity represented by |opaqueData| is not exposed to core wasm code, but remains with the exception as it propagates through the wasm frames on the stack. If the exception propagates back to JavaScript (by returning from [=func_invoke=]), the same |opaqueData| is returned with it. If the exception is caught and rethrown with the rethrow instruction, the identity remains the same. Exceptions that originate from core WebAssembly (using the WebAssembly throw instruction) have a |ref.null| identity returned from [=func_invoke=] From b6df4c2d72e050c6cd12b0b5dd00201cdbad4626 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 3 Mar 2023 15:20:43 -0800 Subject: [PATCH 3/4] clarify language about null identity from wasm throw --- document/js-api/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 87a1480f..26ad4189 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1370,7 +1370,7 @@ To throw with a [=tag address=] |type|, a matching [= Note: The identity represented by |opaqueData| is not exposed to core wasm code, but remains with the exception as it propagates through the wasm frames on the stack. If the exception propagates back to JavaScript (by returning from [=func_invoke=]), the same |opaqueData| is returned with it. If the exception is caught and rethrown with the rethrow instruction, the identity remains the same. -Exceptions that originate from core WebAssembly (using the WebAssembly throw instruction) have a |ref.null| identity returned from [=func_invoke=] +Exceptions that originate from core WebAssembly (using the WebAssembly throw instruction) have a |ref.null| identity associated with them. From 38bbc2745fc7b43dd3882dd3582c992ed6adde2b Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 16 Mar 2023 14:43:53 -0700 Subject: [PATCH 4/4] fix typo --- document/js-api/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 26ad4189..d49dc934 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1049,7 +1049,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 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 exception |exntag| |payload|, then - 1. Let |opaqueData| be the [=externref=] assocated with the returned exception. + 1. Let |opaqueData| be the [=externref=] associated with the returned exception. 1. If |opaqueData| is not [=ref.null=] [=externref=], 1. Let « [=ref.extern=] |externaddr| » be |opaqueData|. 1. Throw the result of [=retrieving an extern value=] from |externaddr|.