From 587dafb42fe07e81ab779d987ff3bb0682da6d47 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 16 Mar 2023 16:25:47 -0700 Subject: [PATCH 01/20] Add exceptional return to func_invoke in embedding doc This is a basic start of what we'll need to add to the embedder spec. I'm not sure if we also need a way to allow exceptions to bubble from the embedder into wasm ; I don't see any reference to what happens when the instance wants to call an import, so maybe not. Also the references aren't quite right, but I may need help to fix that --- document/core/appendix/embedding.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index b4ad120d7..c8b8a85e1 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -293,14 +293,16 @@ Functions .. index:: invocation, value, result .. _embed-func-invoke: -:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error)` -........................................................................................ +:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error ~|~ \exception)` +...................................................................................................... 1. Try :ref:`invoking ` the function :math:`\funcaddr` in :math:`\store` with :ref:`values ` :math:`\val^\ast` as arguments: a. If it succeeds with :ref:`values ` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`. - b. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. + b. Else if the result is a :ref:`throw context ` for an uncaught exception with :ref:`tag ` :math:`{\tag}` and payload :ref:`values ` :math:`{\val'}^\ast`, let :math:`\X{result}` be :math:`{tag'}`, :math:`{\val'}`. + + c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. 2. Return the new store paired with :math:`\X{result}`. @@ -309,6 +311,7 @@ Functions \begin{array}{lclll} \F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\ \F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\ + \F{func\_invoke}(S, a, v^\ast) &=& (S', {v}, {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \THROW) \\ \end{array} .. note:: From 15a47cff3cf5b52390e4ae8d0a76d3effa934a5b Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Mon, 27 Mar 2023 10:27:01 -0700 Subject: [PATCH 02/20] review comments --- document/core/Makefile | 4 ++-- document/core/appendix/embedding.rst | 17 +++++++++++++++-- document/core/util/macros.def | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/document/core/Makefile b/document/core/Makefile index 3ff1a87cb..3cd7c9470 100644 --- a/document/core/Makefile +++ b/document/core/Makefile @@ -136,13 +136,13 @@ singlehtml: bikeshed: $(SPHINXBUILD) -b singlehtml -c util/bikeshed \ $(ALLSPHINXOPTS) $(BUILDDIR)/bikeshed_singlehtml - python util/bikeshed_fixup.py $(BUILDDIR)/bikeshed_singlehtml/index.html \ + python3 util/bikeshed_fixup.py $(BUILDDIR)/bikeshed_singlehtml/index.html \ >$(BUILDDIR)/bikeshed_singlehtml/index_fixed.html mkdir -p $(BUILDDIR)/bikeshed_mathjax/ bikeshed spec index.bs $(BUILDDIR)/bikeshed_mathjax/index.html mkdir -p $(BUILDDIR)/html/bikeshed/ (cd util/katex/ && yarn && yarn build && npm install --only=prod) - python util/mathjax2katex.py $(BUILDDIR)/bikeshed_mathjax/index.html \ + python3 util/mathjax2katex.py $(BUILDDIR)/bikeshed_mathjax/index.html \ >$(BUILDDIR)/html/bikeshed/index.html mkdir -p $(BUILDDIR)/html/bikeshed/katex/dist/ cp -r util/katex/dist/* $(BUILDDIR)/html/bikeshed/katex/dist/ diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index c8b8a85e1..11a475475 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -43,6 +43,19 @@ In addition to the error conditions specified explicitly in this section, implem Implementations can refine it to carry suitable classifications and diagnostic messages. +.. _embed-exception: + +Exceptions +~~~~~~~~~~ + +Invoke operations may throw or propagate exceptions, indicated by an auxiliary syntactic class: + +.. math:: + \begin{array}{llllll} + \production{exception} & \exception &::=& \ETHROW & exnaddr & val^\ast \\ + \end{array} + + Pre- and Post-Conditions ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -300,7 +313,7 @@ Functions a. If it succeeds with :ref:`values ` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`. - b. Else if the result is a :ref:`throw context ` for an uncaught exception with :ref:`tag ` :math:`{\tag}` and payload :ref:`values ` :math:`{\val'}^\ast`, let :math:`\X{result}` be :math:`{tag'}`, :math:`{\val'}`. + b. Else if the outcome is an exception with :ref:`tag ` :math:`\tagaddr` and payload :ref:`values ` :math:`{\val'}^\ast`, let :math:`\X{result}` be :math:`\ETHROW~\tagaddr~{\val'}^\ast`. c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. @@ -310,8 +323,8 @@ Functions ~ \\ \begin{array}{lclll} \F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\ + \F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a'~{v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\THROWadm~a')]) \\ \F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\ - \F{func\_invoke}(S, a, v^\ast) &=& (S', {v}, {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \THROW) \\ \end{array} .. note:: diff --git a/document/core/util/macros.def b/document/core/util/macros.def index eae5e93f4..df1d63686 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -1323,3 +1323,5 @@ .. |error| mathdef:: \xref{appendix/embedding}{embed-error}{\X{error}} .. |ERROR| mathdef:: \xref{appendix/embedding}{embed-error}{\K{error}} +.. |exception| mathdef:: \xref{appendix/embedding}{embed-exception}{\X{exception}} +.. |ETHROW| mathdef:: \xref{appendix/embedding}{embed-exception}{\K{THROW}} From 904a8fbc0abb5f14e5112f154afb5a2938f6e37f Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 30 Mar 2023 16:21:12 -0700 Subject: [PATCH 03/20] swap order of error/exception in func_invoke --- document/core/appendix/embedding.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 11a475475..c27c02328 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -306,7 +306,7 @@ Functions .. index:: invocation, value, result .. _embed-func-invoke: -:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error ~|~ \exception)` +:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \exception ~|~ \error)` ...................................................................................................... 1. Try :ref:`invoking ` the function :math:`\funcaddr` in :math:`\store` with :ref:`values ` :math:`\val^\ast` as arguments: From ec302e1aeb76364816fd51f6e437ef27d73fba5c Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 11 Apr 2023 15:33:13 -0700 Subject: [PATCH 04/20] review suggestions --- document/core/appendix/embedding.rst | 24 +++++++++++------------- document/core/util/macros.def | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index c27c02328..d827edcaa 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -26,8 +26,17 @@ For numeric parameters, notation like :math:`n:\u32` is used to specify a symbol .. _embed-error: -Errors -~~~~~~ +Exceptions and Errors +~~~~~~~~~~~~~~~~~~~~~ + +Invoke operations may throw or propagate exceptions, indicated by an auxiliary syntactic class: + +.. math:: + \begin{array}{llll} + \production{exception} & \exception &::=& \ETHROW ~ \tagaddr ~ val^\ast \\ + \end{array} + +The tag instance :math:`tagaddr` identifies the :ref:`type ` of exception thrown. The values :math:`val^\ast` are the exception's payload; their types match the tag type's parameters. Failure of an interface operation is indicated by an auxiliary syntactic class: @@ -43,17 +52,6 @@ In addition to the error conditions specified explicitly in this section, implem Implementations can refine it to carry suitable classifications and diagnostic messages. -.. _embed-exception: - -Exceptions -~~~~~~~~~~ - -Invoke operations may throw or propagate exceptions, indicated by an auxiliary syntactic class: - -.. math:: - \begin{array}{llllll} - \production{exception} & \exception &::=& \ETHROW & exnaddr & val^\ast \\ - \end{array} Pre- and Post-Conditions diff --git a/document/core/util/macros.def b/document/core/util/macros.def index df1d63686..13e904d7a 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -1323,5 +1323,5 @@ .. |error| mathdef:: \xref{appendix/embedding}{embed-error}{\X{error}} .. |ERROR| mathdef:: \xref{appendix/embedding}{embed-error}{\K{error}} -.. |exception| mathdef:: \xref{appendix/embedding}{embed-exception}{\X{exception}} -.. |ETHROW| mathdef:: \xref{appendix/embedding}{embed-exception}{\K{THROW}} +.. |exception| mathdef:: \xref{appendix/embedding}{embed-error}{\X{exception}} +.. |ETHROW| mathdef:: \xref{appendix/embedding}{embed-error}{\K{THROW}} From fdf1b7c2a9553fec8734b3c15199a16b0cb47ca8 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 3 May 2023 17:35:56 -0700 Subject: [PATCH 05/20] Apply suggestions from code review Co-authored-by: Andreas Rossberg --- document/core/appendix/embedding.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index d827edcaa..d11da93bf 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -29,16 +29,16 @@ For numeric parameters, notation like :math:`n:\u32` is used to specify a symbol Exceptions and Errors ~~~~~~~~~~~~~~~~~~~~~ -Invoke operations may throw or propagate exceptions, indicated by an auxiliary syntactic class: +Invoking an exported function may throw or propagate exceptions, expressed by an auxiliary syntactic class: .. math:: \begin{array}{llll} \production{exception} & \exception &::=& \ETHROW ~ \tagaddr ~ val^\ast \\ \end{array} -The tag instance :math:`tagaddr` identifies the :ref:`type ` of exception thrown. The values :math:`val^\ast` are the exception's payload; their types match the tag type's parameters. +The tag instance :math:`tagaddr` identifies the exception thrown. The values :math:`val^\ast` are the exception's payload; their types match the tag type's parameters. -Failure of an interface operation is indicated by an auxiliary syntactic class: +Failure of an interface operation is also indicated by an auxiliary syntactic class: .. math:: \begin{array}{llll} From f57cdb8cc4c5e374cc5ae59e9de2eee38c843d80 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 21 Mar 2024 17:30:31 -0700 Subject: [PATCH 06/20] add exception allocation --- document/core/appendix/embedding.rst | 38 ++++++++++++++++++++++++++++ document/core/exec/instructions.rst | 16 +++++------- document/core/exec/modules.rst | 28 +++++++++++++++++++- document/core/util/macros.def | 1 + 4 files changed, 73 insertions(+), 10 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 5413799f8..13dd1ed37 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -576,6 +576,44 @@ Tags \end{array} +.. _embed-tag-type: + +:math:`\F{tag\_type}(\store, \tagaddr) : \tagtype` +........................................................ + +1. Return :math:`S.\STAGS[a].\TAGITYPE`. + +2. Post-condition: the returned :ref:`tag type ` is :ref:`valid `. + +.. math:: + \begin{array}{lclll} + \F{tag\_type}(S, a) &=& S.\STAGS[a].\TAGITYPE \\ + \end{array} + + +.. index:: exception, exception address, store, exception instance, exception type +.. _embed-exception: + +Exceptions +~~~~~~~~~~ + +.. _embed-exception-alloc: + +:math:`\F{exception\_alloc}(\store, \tagaddr, \val) : (\store, \exnaddr)` +............................................................................ + +1. Pre-condition: :math:`\tagaddr` is an allocated :ref:`tag address `. + +2. Let :math:`\exnaddr` be the result of :ref:`allocating an exception ` in :math:`\store` with :ref:`tag address ` :math:`\tagaddr` and initialization values :math:`\val^\ast`. + +3. Return the new store paired with :math:`\exnaddr`. + +.. math:: + \begin{array}{lclll} + \F{exception\_alloc}(S, \X{gt}, v) &=& (S', \X{a}) && (\iff \allocglobal(S, \X{gt}, v) = S', \X{a}) \\ + \end{array} + + .. index:: global, global address, store, global instance, global type, value .. _embed-global: diff --git a/document/core/exec/instructions.rst b/document/core/exec/instructions.rst index 5d19010c1..5ee4a6051 100644 --- a/document/core/exec/instructions.rst +++ b/document/core/exec/instructions.rst @@ -2719,11 +2719,11 @@ Control Instructions 2. Assert: due to :ref:`validation `, :math:`F.\AMODULE.\MITAGS[x]` exists. -3. Let :math:`a` be the :ref:`tag address ` :math:`F.\AMODULE.\MITAGS[x]`. +3. Let :math:`ta` be the :ref:`tag address ` :math:`F.\AMODULE.\MITAGS[x]`. -4. Assert: due to :ref:`validation `, :math:`S.\STAGS[a]` exists. +4. Assert: due to :ref:`validation `, :math:`S.\STAGS[ta]` exists. -5. Let :math:`\X{ti}` be the :ref:`tag instance ` :math:`S.\STAGS[a]`. +5. Let :math:`\X{ti}` be the :ref:`tag instance ` :math:`S.\STAGS[ta]`. 6. Let :math:`[t^n] \toF [{t'}^\ast]` be the :ref:`tag type ` :math:`\X{ti}.\TAGITYPE`. @@ -2731,15 +2731,13 @@ Control Instructions 8. Pop the :math:`n` values :math:`\val^n` from the stack. -9. Let :math:`\X{exn}` be the :ref:`exception instance ` :math:`\{ \EITAG~a, \EIFIELDS~\val^n \}`. +9. Let :math:`\X{ea}` be the :ref:`exception address ` resulting from :ref:`allocating ` an exception instance with tag address :math:`ta` and initializer values :math:`\val^n`. -10. Let :math:`\X{ea}` be the length of :math:`S.\SEXNS`. +10. Let :math:`\X{exn}` be :math:`S.\SEXNS[ea]` -11. Append :math:`\X{exn}` to :math:`S.\SEXNS`. +11. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack. -12. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack. - -13. Execute the instruction |THROWREF|. +12. Execute the instruction |THROWREF|. .. math:: ~\\[-1ex] diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index a43f55e91..4f1335f1d 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -190,7 +190,7 @@ The following auxiliary typing rules specify this typing relation relative to a Allocation ~~~~~~~~~~ -New instances of :ref:`functions `, :ref:`tables `, :ref:`memories `, :ref:`tags `, and :ref:`globals ` are *allocated* in a :ref:`store ` :math:`S`, as defined by the following auxiliary functions. +New instances of :ref:`functions `, :ref:`tables `, :ref:`memories `, :ref:`tags `, :ref:`exceptions `, and :ref:`globals ` are *allocated* in a :ref:`store ` :math:`S`, as defined by the following auxiliary functions. .. index:: function, function instance, function address, module instance, function type @@ -338,6 +338,32 @@ New instances of :ref:`functions `, :ref:`tables ` +.................................. + +1. Let :math:`ta` be the :ref:`tag address ` associated with the exception to allocate and :math:`\EIFIELDS~\val^\ast` be the values to initialize the exception with. + +2. Let :math:`a` be the first free :ref:`exception address ` in :math:`S`. + +3. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`. + +4. Append :math:`\exninst` to the |SEXNS| of :math:`S`. + +5. Return :math:`a`. + +.. math:: + \begin{array}{rlll} + \allocexn(S, \tagaddr, \val^ast) &=& S', \exnaddr \\[1ex] + \mbox{where:} \hfill \\ + \exnaddr &=& |S.\SEXNS| \\ + \exninst &=& \{ \EITAG~\tagaddr, \GIVALUE~\val^\ast \} \\ + S' &=& S \compose \{\SEXNS~\exninst\} \\ + \end{array} + + .. index:: global, global instance, global address, global type, value type, mutability, value .. _alloc-global: diff --git a/document/core/util/macros.def b/document/core/util/macros.def index ca40cd52b..ed0da3328 100644 --- a/document/core/util/macros.def +++ b/document/core/util/macros.def @@ -981,6 +981,7 @@ .. |alloctable| mathdef:: \xref{exec/modules}{alloc-table}{\F{alloctable}} .. |allocmem| mathdef:: \xref{exec/modules}{alloc-mem}{\F{allocmem}} .. |alloctag| mathdef:: \xref{exec/modules}{alloc-tag}{\F{alloctag}} +.. |allocexn| mathdef:: \xref{exec/modules}{alloc-exception}{\F{allocexn}} .. |allocglobal| mathdef:: \xref{exec/modules}{alloc-global}{\F{allocglobal}} .. |allocelem| mathdef:: \xref{exec/modules}{alloc-elem}{\F{allocelem}} .. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}} From ccbee0f7e15d277067fc81fdbad5100eb91c253e Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 22 Mar 2024 10:42:43 -0700 Subject: [PATCH 07/20] udpate for exnref --- document/core/appendix/embedding.rst | 4 ++-- document/core/exec/modules.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 13dd1ed37..7f75fb76d 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -311,7 +311,7 @@ Functions a. If it succeeds with :ref:`values ` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`. - b. Else if the outcome is an exception with :ref:`tag ` :math:`\tagaddr` and payload :ref:`values ` :math:`{\val'}^\ast`, let :math:`\X{result}` be :math:`\ETHROW~\tagaddr~{\val'}^\ast`. + b. Else if the outcome is an exception with a thrown :ref:`exception ` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\exnaddr` c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. @@ -321,7 +321,7 @@ Functions ~ \\ \begin{array}{lclll} \F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\ - \F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a'~{v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\THROWadm~a')]) \\ + \F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a'~{v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\REFEXNADDR~\exnaddr)~\THROWREF] \\ \F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\ \end{array} diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index 4f1335f1d..b2ebe665b 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -348,7 +348,7 @@ New instances of :ref:`functions `, :ref:`tables ` in :math:`S`. -3. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`. +3. Let :math:`\exninst` be the :ref:`exception instance ` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`. 4. Append :math:`\exninst` to the |SEXNS| of :math:`S`. From 4d08a587f5cb8654c2347027cb1a6a3940c554d5 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 29 Mar 2024 10:29:10 -0700 Subject: [PATCH 08/20] apply all suggestions other than exn_read --- document/core/appendix/embedding.rst | 14 +++++++------- document/core/exec/modules.rst | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 7f75fb76d..65723a471 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -33,10 +33,10 @@ Invoking an exported function may throw or propagate exceptions, expressed by an .. math:: \begin{array}{llll} - \production{exception} & \exception &::=& \ETHROW ~ \tagaddr ~ val^\ast \\ + \production{exception} & \exception &::=& \ETHROW ~ \exnaddr \\ \end{array} -The tag instance :math:`tagaddr` identifies the exception thrown. The values :math:`val^\ast` are the exception's payload; their types match the tag type's parameters. +The exception instance :math:`exnaddr` identifies the exception thrown. Failure of an interface operation is also indicated by an auxiliary syntactic class: @@ -311,7 +311,7 @@ Functions a. If it succeeds with :ref:`values ` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`. - b. Else if the outcome is an exception with a thrown :ref:`exception ` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\exnaddr` + b. Else if the outcome is an exception with a thrown :ref:`exception ` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\ETHROW~\exnaddr` c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`. @@ -321,7 +321,7 @@ Functions ~ \\ \begin{array}{lclll} \F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\ - \F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a'~{v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\REFEXNADDR~\exnaddr)~\THROWREF] \\ + \F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a') && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\REFEXNADDR~\exnaddr)~\THROWREF] \\ \F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\ \end{array} @@ -597,9 +597,9 @@ Tags Exceptions ~~~~~~~~~~ -.. _embed-exception-alloc: +.. _embed-exn-alloc: -:math:`\F{exception\_alloc}(\store, \tagaddr, \val) : (\store, \exnaddr)` +:math:`\F{exn\_alloc}(\store, \tagaddr, \val^\ast) : (\store, \exnaddr)` ............................................................................ 1. Pre-condition: :math:`\tagaddr` is an allocated :ref:`tag address `. @@ -610,7 +610,7 @@ Exceptions .. math:: \begin{array}{lclll} - \F{exception\_alloc}(S, \X{gt}, v) &=& (S', \X{a}) && (\iff \allocglobal(S, \X{gt}, v) = S', \X{a}) \\ + \F{exn\_alloc}(S, \tagaddr, \val^\ast) &=& (S', a) && (\iff \allocexn(S, \tagaddr, \val^\ast) = S', a) \\ \end{array} diff --git a/document/core/exec/modules.rst b/document/core/exec/modules.rst index b2ebe665b..2a52bc96f 100644 --- a/document/core/exec/modules.rst +++ b/document/core/exec/modules.rst @@ -356,10 +356,10 @@ New instances of :ref:`functions `, :ref:`tables Date: Fri, 29 Mar 2024 10:50:20 -0700 Subject: [PATCH 09/20] add exn_read --- document/core/appendix/embedding.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/document/core/appendix/embedding.rst b/document/core/appendix/embedding.rst index 65723a471..4c6791ae3 100644 --- a/document/core/appendix/embedding.rst +++ b/document/core/appendix/embedding.rst @@ -614,6 +614,21 @@ Exceptions \end{array} +.. _embed-exn-read: + +:math:`\F{exn\_read}(\store, \exnaddr) : (\tagaddr, \val^\ast)` +...................................................................... + +1. Let :math:`\X{ei}` be the :ref:`exception instance ` :math:`\store.\SEXNS[\exnaddr]`. + +2. Return the :ref:`tag address ` :math:`\X{ei}.\EITAG~\tagaddr` paired with :ref:`values ` :math:`\X{ei}.\EIFIELDS~\val^\ast`. + +.. math:: + \begin{array}{lcll} + \F{exn\_read}(S, a) &=& (a', v^\ast) \\ + \end{array} + + .. index:: global, global address, store, global instance, global type, value .. _embed-global: From b17459a537a527b5671c19163bf6176f49e39369 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 29 Mar 2024 14:18:29 -0700 Subject: [PATCH 10/20] Update allocation, initialization, construction and call-exported-fn --- document/js-api/index.bs | 62 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 1519c0494..415b98160 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -27,7 +27,7 @@ Prepare For TR: true
 urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
     type: interface; for: ECMAScript
-        text: ArrayBuffer; url: sec-arraybuffer-objects
+        text: ArrayBuffer; url: sec-arraybuffπer-objects
     type: exception; for: ECMAScript
         text: Error; url: sec-error-objects
         text: NativeError; url: sec-nativeerror-constructors
@@ -238,6 +238,8 @@ Each [=agent=] is associated with the following [=ordered map=]s:
     * The Global object cache, mapping [=global address=]es to {{Global}} objects.
     * The Extern value cache, mapping [=extern address=]es to values.
     * The Tag object cache, mapping [=tag addresses=] to {{Tag}} objects.
+    * The Exception object cache, mapping [=exception address=]es to {{Exception}} objects.
+
 
 

The WebAssembly Namespace

@@ -760,7 +762,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. @@ -1014,11 +1016,8 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [ 1. Note: The expectation is that [=func_invoke=] will be updated to return (|store|, val* | [=error=] | (exception |exntag| |payload| |opaqueData|)). 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 |opaqueData| is not [=ref.null=] [=externref=], - 1. Let « [=ref.extern=] |externaddr| » be |opaqueData|. - 1. Throw the result of [=retrieving an extern value=] from |externaddr|. - 1. Let |exception| be [=create an Exception object|a new Exception=] for |exntag| and |payload|. + 1. If |ret| is [=THROW=] [=ref.exn=] |exnaddr|, then + 1. Let |exception| be [=create an Exception object|a new Exception=] created from |exnaddr|. 1. Throw |exception|. 1. Let |outArity| be the [=list/size=] of |ret|. 1. If |outArity| is 0, return undefined. @@ -1048,7 +1047,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. @@ -1263,21 +1262,31 @@ interface Exception { An {{Exception}} value represents an exception. +
+To initialize an Exception object |exn| from an [=Exception address=] |exnAddress|, perform the following steps: + +1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. +1. Assert: |map|[|exnAddress|] doesn't [=map/exist=]. +1. Set |exn|.\[[Address]] to |exnAddress|. +1. [=map/Set=] |map|[|exnAddress|] to |exn|. +1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, |exnAddress|). +1. Set |exn|.\[[Type]] to |tagaddr|. +1. Set |exn|.\[[Payload]] to |payload|. (XXX use a getter?) +1. Set |exn|.\[[Stack]] to undefined. +
+
-To create an Exception object from a [=tag address=] |tagAddress| and a [=list=] of +To create an Exception object from a [=exception address=] |exnAddress| and a [=list=] of WebAssembly values |payload|, perform the following steps: -1. Let |store| be the [=surrounding agent=]'s [=associated store=]. -1. Let |types| be [=tag_parameters=](|store|, |tagAddress|). -1. Assert: |types|'s [=list/size=] is |payload|'s [=list/size=]. -1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, - 1. Assert: |value|'s type matches |resultType|. -1. Let |exception| be a [=new=] {{Exception}}. -1. Set |exception|.\[[Type]] to |tagAddress|. -1. Set |exception|.\[[Payload]] to |payload|. -1. Set |exception|.\[[Stack]] to undefined. -1. Return |exception|. +1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. +1. If |map|[|exnAddress|] [=map/exists=], + 1. Return |map|[|exnAddress|]. +1. Let |exn| be a [=new=] {{Exception}}. +1. [=initialize an Exception object|Initialize=] |exn| from |exnAddress|. +1. Return |exn|. +
@@ -1294,22 +1303,21 @@ constructor steps are: 1. Let |wasmPayload| be « ». 1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, 1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. -1. Set **this**.\[[Type]] to |exceptionTag|.\[[Address]]. -1. Set **this**.\[[Payload]] to |wasmPayload|. +1. Let (|store|, |exceptionAddr|) be [=exn_alloc=](|store|, |exceptionTag|.\[[Address]], |wasmPayload|) +1. [=initialize an Exception object|Initialize=] **this** from |exceptionAddr|. 1. If |options|["traceStack"] is true, 1. Set **this**.\[[Stack]] to either a {{DOMString}} representation of the current call stack or undefined. -1. Otherwise, - 1. Set **this**.\[[Stack]] to undefined. +
-The getArg(|exceptionTag|, |index|) method steps are: +The getArg(|index|) method steps are: +(XXX maybe rename this method? exns don't really have 'args' the way func types do and also for backward compatibility) -1. If **this**.\[[Type]] is not equal to |exceptionTag|.\[[Address]], - 1. Throw a {{TypeError}}. -1. Let |payload| be **this**.\[[Payload]]. +1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, **this**.\[[Address]]). +1. Assert: |tagaddr| is equal to **this**.\[[Type]]. 1. If |index| ≥ |payload|'s [=list/size=], 1. Throw a {{RangeError}}. 1. Return [=ToJSValue=](|payload|[|index|]). From fa07dea79dc04e900d0815c57eb373fc5b5ab60b Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 29 Mar 2024 15:12:28 -0700 Subject: [PATCH 11/20] fix linkage, syntax --- document/js-api/index.bs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 415b98160..06518c0e6 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -64,6 +64,7 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: ref.null text: ref.func text: ref.extern + text: ref.exn text: function index; url: syntax/modules.html#syntax-funcidx text: function instance; url: exec/runtime.html#function-instances text: store_init; url: appendix/embedding.html#embed-store-init @@ -101,6 +102,9 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr text: tag address; url: exec/runtime.html#syntax-tagaddr + text: exception address; url: exec/runtime.html#syntax-exnaddr + text: exn_alloc; url: appendix/embedding.html#embed-exn-alloc + text: exn_read; url: appendix/embedding.html#embed-exn-read url: syntax/types.html#syntax-numtype text: i32 text: i64 @@ -1013,7 +1017,6 @@ 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. 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 [=THROW=] [=ref.exn=] |exnaddr|, then @@ -1273,6 +1276,7 @@ To initialize an Exception object |exn| from an [=Exception address=] 1. Set |exn|.\[[Type]] to |tagaddr|. 1. Set |exn|.\[[Payload]] to |payload|. (XXX use a getter?) 1. Set |exn|.\[[Stack]] to undefined. +
From ea5217b8b482d9419821d3635b473e83d45ca41c Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 29 Mar 2024 15:19:29 -0700 Subject: [PATCH 12/20] 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 06518c0e6..7a607a5fb 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -27,7 +27,7 @@ Prepare For TR: true
 urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
     type: interface; for: ECMAScript
-        text: ArrayBuffer; url: sec-arraybuffπer-objects
+        text: ArrayBuffer; url: sec-arraybuffer-objects
     type: exception; for: ECMAScript
         text: Error; url: sec-error-objects
         text: NativeError; url: sec-nativeerror-constructors

From 1c958c2f8c50c64daab12fa92ef053512f4cd08a Mon Sep 17 00:00:00 2001
From: Derek Schuff 
Date: Fri, 29 Mar 2024 15:38:22 -0700
Subject: [PATCH 13/20] fix vars

---
 document/js-api/index.bs | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/document/js-api/index.bs b/document/js-api/index.bs
index 7a607a5fb..60702057d 100644
--- a/document/js-api/index.bs
+++ b/document/js-api/index.bs
@@ -1272,17 +1272,17 @@ To initialize an Exception object |exn| from an [=Exception address=]
 1. Assert: |map|[|exnAddress|] doesn't [=map/exist=].
 1. Set |exn|.\[[Address]] to |exnAddress|.
 1. [=map/Set=] |map|[|exnAddress|] to |exn|.
+1. Let |store| be the [=surrounding agent=]'s [=associated store=].
 1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, |exnAddress|).
 1. Set |exn|.\[[Type]] to |tagaddr|.
-1. Set |exn|.\[[Payload]] to |payload|. (XXX use a getter?)
+1. Set |exn|.\[[Payload]] to |payload|.
 1. Set |exn|.\[[Stack]] to undefined.
 
 
-To create an Exception object from a [=exception address=] |exnAddress| and a [=list=] of -WebAssembly values |payload|, perform the following steps: +To create an Exception object from a [=exception address=] |exnAddress|, perform the following steps: 1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. 1. If |map|[|exnAddress|] [=map/exists=], @@ -1320,6 +1320,7 @@ constructor steps are: The getArg(|index|) method steps are: (XXX maybe rename this method? exns don't really have 'args' the way func types do and also for backward compatibility) +1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, **this**.\[[Address]]). 1. Assert: |tagaddr| is equal to **this**.\[[Type]]. 1. If |index| ≥ |payload|'s [=list/size=], From 5b8380ad9c60ac0f239885ba7164e333569e0480 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 3 Apr 2024 17:00:01 -0700 Subject: [PATCH 14/20] address comments --- document/js-api/index.bs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 60702057d..050be8b1d 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1266,6 +1266,7 @@ interface Exception { An {{Exception}} value represents an exception.
+ To initialize an Exception object |exn| from an [=Exception address=] |exnAddress|, perform the following steps: 1. Let |map| be the [=surrounding agent=]'s associated [=Exception object cache=]. @@ -1308,6 +1309,7 @@ constructor steps are: 1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, 1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. 1. Let (|store|, |exceptionAddr|) be [=exn_alloc=](|store|, |exceptionTag|.\[[Address]], |wasmPayload|) +1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. [=initialize an Exception object|Initialize=] **this** from |exceptionAddr|. 1. If |options|["traceStack"] is true, 1. Set **this**.\[[Stack]] to either a {{DOMString}} representation of the current call stack or undefined. From 4d03423cc3f256e3b61b473e182ddcfac7df3703 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 4 Apr 2024 14:42:45 -0700 Subject: [PATCH 15/20] remove Tag parameter from getArg --- document/js-api/index.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 050be8b1d..259325a0c 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1257,7 +1257,7 @@ dictionary ExceptionOptions { [LegacyNamespace=WebAssembly, Exposed=(Window,Worker,Worklet)] interface Exception { constructor(Tag exceptionTag, sequence<any> payload, optional ExceptionOptions options = {}); - any getArg(Tag exceptionTag, [EnforceRange] unsigned long index); + any getArg([EnforceRange] unsigned long index); boolean is(Tag exceptionTag); readonly attribute (DOMString or undefined) stack; }; @@ -1320,7 +1320,6 @@ constructor steps are:
The getArg(|index|) method steps are: -(XXX maybe rename this method? exns don't really have 'args' the way func types do and also for backward compatibility) 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, **this**.\[[Address]]). From d073cfe3870dea38430ca97b938fed23ce52aa1f Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 4 Apr 2024 15:36:28 -0700 Subject: [PATCH 16/20] remove 2 more spurious references to webassembly throw --- document/js-api/index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 259325a0c..8e9b89423 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -813,7 +813,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (limits, |elementType|) be [=table_type=](|store|, |tableaddr|). 1. If |elementType| is [=exnref=], - 1. [=Throw=] a {{TypeError}} exception. + 1. Throw a {{TypeError}} exception. 1. Let |result| be [=table_read=](|store|, |tableaddr|, |index|). 1. If |result| is [=error=], throw a {{RangeError}} exception. 1. Return [=ToJSValue=](|result|). @@ -825,7 +825,7 @@ Each {{Table}} object has a \[[Table]] internal slot, which is a [=table address 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (limits, |elementType|) be [=table_type=](|store|, |tableaddr|). 1. If |elementType| is [=exnref=], - 1. [=Throw=] a {{TypeError}} exception. + 1. Throw a {{TypeError}} exception. 1. If |value| is missing, 1. Let |ref| be [=DefaultValue=](|elementType|). 1. Otherwise, From b6a79f9118d2d01f5d226e85731a6eb7ec552350 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 4 Apr 2024 17:38:36 -0700 Subject: [PATCH 17/20] more properly allocate the JS exception tag, and wrap/unwrap JS exceptions. Wasm throwing is still not properly defined. --- document/js-api/index.bs | 54 ++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 8e9b89423..6b30c375f 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -102,6 +102,8 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr text: tag address; url: exec/runtime.html#syntax-tagaddr + text: tag_alloc; url: appendix/embedding.html#embed-tag-alloc + text: tag_type; url: appendix/embedding.html#embed-tag-type text: exception address; url: exec/runtime.html#syntax-exnaddr text: exn_alloc; url: appendix/embedding.html#embed-exn-alloc text: exn_read; url: appendix/embedding.html#embed-exn-read @@ -1020,8 +1022,13 @@ 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 [=THROW=] [=ref.exn=] |exnaddr|, then - 1. Let |exception| be [=create an Exception object|a new Exception=] created from |exnaddr|. - 1. Throw |exception|. + 1. Let (|tagaddr|, |payload|) be [=exn_read=](|store|, |exnaddr|). + 1. Let |jsTagAddr| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=]. + 1. If |tagaddr| is equal to |jsTagAddr|, + 1. Throw the result of [=retrieving an extern value=] from |payload|[0]. + 1. Otherwise, + 1. Let |exception| be [=create an Exception object|a new Exception=] created from |exnaddr|. + 1. Throw |exception|. 1. Let |outArity| be the [=list/size=] of |ret|. 1. If |outArity| is 0, return undefined. 1. Otherwise, if |outArity| is 1, return [=ToJSValue=](|ret|[0]). @@ -1078,11 +1085,13 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. If |v| [=implements=] {{Exception}}, 1. Let |type| be |v|.\[[Type]]. 1. Let |payload| be |v|.\[[Payload]]. + 1. Let |address| be |v|.\[[Address]]. + 1. [=WebAssembly/Throw=] with |address|. 1. Otherwise, - 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. Let |type| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=]. + 1. Let |payload| be [=ToWebAssemblyValue=](|v|, [=externref=]). + 1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »). + 1. [=WebAssembly/Throw=] with |address|. 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|). @@ -1173,10 +1182,6 @@ The algorithm ToWebAssemblyValue(|v|, |type|) coerces a JavaScript va

Tags

-The tag_alloc(|store|, |parameters|) algorithm creates a new [=tag address=] for |parameters| in |store| and returns the updated store and the [=tag address=]. - -The tag_parameters(|store|, |tagAddress|) algorithm returns the [=list=] of types for |tagAddress| in |store|. -

Exception types

@@ -1237,7 +1242,7 @@ The new Tag(|type|) constructor
 The type() method steps are:
 
 1. Let |store| be the [=surrounding agent=]'s [=associated store=].
-1. Let |parameters| be [=tag_parameters=](|store|, **this**.\[[Address]]).
+1. Let [|parameters|] → [] be [=tag_type=](|store|, **this**.\[[Address]]).
 1. Let |idlParameters| be «».
 1. [=list/iterate|For each=] |type| of |parameters|,
     1. [=list/Append=] [$FromValueType$](|type|) to |idlParameters|.
@@ -1302,7 +1307,7 @@ lt="Exception(exceptionTag, payload, options)">new Exception(|exceptionTag|, |pa
 constructor steps are:
 
 1. Let |store| be the [=surrounding agent=]'s [=associated store=].
-1. Let |types| be [=tag_parameters=](|store|, |exceptionTag|.\[[Address]]).
+1. Let [|types|] → [] be [=tag_type=](|store|, |exceptionTag|.\[[Address]]).
 1. If |types|'s [=list/size=] is not |payload|'s [=list/size=],
     1. Throw a {{TypeError}}.
 1. Let |wasmPayload| be « ».
@@ -1350,18 +1355,31 @@ The stack getter steps are:
 
 

JavaScript exceptions

-The JavaScript exception tag is a [=tag address=] reserved by this -specification to distinguish exceptions originating from JavaScript. +The JavaScript exception tag is a [=tag address=] associated with +the surrounding agent. It is allocated in the agent's [=associated store=] on +first use and cached. It always has the tag type « [=externref=] » → « ». + + +
+ +To get the JavaScript exception tag, perform the following steps: -For any [=associated store=] |store|, the result of -[=tag_parameters=](|store|, [=JavaScript exception tag=]) must be « ». + 1. If the [=surrounding agent=]'s associated [=JavaScript exception tag=] has been initialized, + 1. return the [=surrounding agent=]'s associated [=JavaScript exception tag=] + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. + 1. Let (|store|, |tagAddress|) be [=tag_alloc=](|store|, « [=externref=] » → « »). + 1. Set the current agent's [=associated store=] to |store|. + 1. Set the current agent's associated [=JavaScript exception tag=] to |tagAddress|. + 1. return |tagAddress|. + +
-To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=externref=] |opaqueData|, perform the following steps: +To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=exception address=] |address|, perform the following steps: 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| and |address|. Note: This algorithm is expected to be moved into the core specification. From 51338d7e32f1129a9409e6f7c3d9436d5ff14b51 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 5 Apr 2024 11:37:42 -0700 Subject: [PATCH 18/20] apply review comments --- document/js-api/index.bs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 6b30c375f..1b06f0dc2 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -101,6 +101,7 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: memory address; url: exec/runtime.html#syntax-memaddr text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr + text: tag type; url: syntax/types.html#syntax-tagtype text: tag address; url: exec/runtime.html#syntax-tagaddr text: tag_alloc; url: appendix/embedding.html#embed-tag-alloc text: tag_type; url: appendix/embedding.html#embed-tag-type @@ -1080,20 +1081,18 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. [=Clean up after running a callback=] with |stored settings|. 1. [=Clean up after running script=] with |relevant settings|. 1. Assert: |result|.\[[Type]] is throw or normal. + 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. If |result|.\[[Type]] is throw, then: 1. Let |v| be |result|.\[[Value]]. 1. If |v| [=implements=] {{Exception}}, - 1. Let |type| be |v|.\[[Type]]. - 1. Let |payload| be |v|.\[[Payload]]. 1. Let |address| be |v|.\[[Address]]. - 1. [=WebAssembly/Throw=] with |address|. 1. Otherwise, 1. Let |type| be the result of [=get the JavaScript exception tag |getting the JavaScript exception tag=]. - 1. Let |payload| be [=ToWebAssemblyValue=](|v|, [=externref=]). + 1. Let |payload| be [=!=] [=ToWebAssemblyValue=](|v|, [=externref=]). 1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »). + 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. [=WebAssembly/Throw=] with |address|. 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|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. Return |funcaddr|. @@ -1312,7 +1311,7 @@ constructor steps are: 1. Throw a {{TypeError}}. 1. Let |wasmPayload| be « ». 1. [=list/iterate|For each=] |value| and |resultType| of |payload| and |types|, paired linearly, - 1. [=list/Append=] ? [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. + 1. [=list/Append=] [=?=] [=ToWebAssemblyValue=](|value|, |resultType|) to |wasmPayload|. 1. Let (|store|, |exceptionAddr|) be [=exn_alloc=](|store|, |exceptionTag|.\[[Address]], |wasmPayload|) 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. 1. [=initialize an Exception object|Initialize=] **this** from |exceptionAddr|. @@ -1357,7 +1356,7 @@ The stack getter steps are: The JavaScript exception tag is a [=tag address=] associated with the surrounding agent. It is allocated in the agent's [=associated store=] on -first use and cached. It always has the tag type « [=externref=] » → « ». +first use and cached. It always has the [=tag type=] « [=externref=] » → « ».
@@ -1376,7 +1375,7 @@ To get the JavaScript exception tag, perform the following steps:
-To throw with a [=tag address=] |type|, a matching [=list=] of WebAssembly values |payload|, and an [=exception address=] |address|, perform the following steps: +To throw with an [=exception address=] |address|, perform the following steps: 1. Unwind the stack until reaching the *catching try block* given |type|. 1. Invoke the catch block with |payload| and |address|. From dfdd0b938077b318f4d880e2520a2fa342c2803d Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Fri, 5 Apr 2024 11:52:18 -0700 Subject: [PATCH 19/20] inline throwing into 'create a host function' and define in terms of throw_ref --- document/js-api/index.bs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 1b06f0dc2..021e3def7 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -101,13 +101,13 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: memory address; url: exec/runtime.html#syntax-memaddr text: global address; url: exec/runtime.html#syntax-globaladdr text: extern address; url: exec/runtime.html#syntax-externaddr - text: tag type; url: syntax/types.html#syntax-tagtype text: tag address; url: exec/runtime.html#syntax-tagaddr text: tag_alloc; url: appendix/embedding.html#embed-tag-alloc text: tag_type; url: appendix/embedding.html#embed-tag-type text: exception address; url: exec/runtime.html#syntax-exnaddr text: exn_alloc; url: appendix/embedding.html#embed-exn-alloc text: exn_read; url: appendix/embedding.html#embed-exn-read + text: tag type; url: syntax/types.html#syntax-tagtype url: syntax/types.html#syntax-numtype text: i32 text: i64 @@ -152,6 +152,7 @@ urlPrefix: https://webassembly.github.io/exception-handling/core/; spec: WebAsse text: address; url: exec/runtime.html#addresses text: signed_32; url: exec/numerics.html#aux-signed text: memory.grow; url: exec/instructions.html#exec-memory-grow + text: throw_ref; url: exec/instructions.html#exec-throw-ref text: current frame; url: exec/conventions.html#exec-notation-textual text: module; for: frame; url: exec/runtime.html#syntax-frame text: memaddrs; for: moduleinst; url: exec/runtime.html#syntax-moduleinst @@ -1091,7 +1092,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Let |payload| be [=!=] [=ToWebAssemblyValue=](|v|, [=externref=]). 1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. - 1. [=WebAssembly/Throw=] with |address|. + 1. Execute the wasm instructions ([=ref.exn=] |address|) ([=throw_ref=]) 1. Otherwise, return |result|.\[[Value]]. 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. @@ -1373,17 +1374,6 @@ To get the JavaScript exception tag, perform the following steps:
-
- -To throw with an [=exception address=] |address|, perform the following steps: - -1. Unwind the stack until reaching the *catching try block* given |type|. -1. Invoke the catch block with |payload| and |address|. - -Note: This algorithm is expected to be moved into the core specification. - -
-

Error Objects

WebAssembly defines the following Error classes: CompileError, LinkError, and RuntimeError. From 624bcca8c553764a879c643543168114156744e2 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 9 Apr 2024 14:10:35 -0700 Subject: [PATCH 20/20] apply suggestion --- 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 021e3def7..ba25a4cc5 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -1092,7 +1092,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not 1. Let |payload| be [=!=] [=ToWebAssemblyValue=](|v|, [=externref=]). 1. Let (|store|, |address|) be [=exn_alloc=](|store|, |type|, « |payload| »). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|. - 1. Execute the wasm instructions ([=ref.exn=] |address|) ([=throw_ref=]) + 1. Execute the WebAssembly instructions ([=ref.exn=] |address|) ([=throw_ref=]). 1. Otherwise, return |result|.\[[Value]]. 1. Let (|store|, |funcaddr|) be [=func_alloc=](|store|, |functype|, |hostfunc|). 1. Set the [=surrounding agent=]'s [=associated store=] to |store|.