diff --git a/document/js-api/index.bs b/document/js-api/index.bs index 19d19808..ead90362 100644 --- a/document/js-api/index.bs +++ b/document/js-api/index.bs @@ -100,6 +100,9 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: 𝗂πŸ₯𝟀.π–Όπ—ˆπ—‡π—Œπ— text: 𝖿πŸ₯𝟀.π–Όπ—ˆπ—‡π—Œπ— text: π–ΏπŸ¨πŸ¦.π–Όπ—ˆπ—‡π—Œπ— + text: ref.null + text: ref.func + text: ref.host text: function index; url: syntax/modules.html#syntax-funcidx text: function instance; url: exec/runtime.html#function-instances text: init_store; url: appendix/embedding.html#embed-init-store @@ -132,11 +135,16 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df text: table address; url: exec/runtime.html#syntax-tableaddr text: function address; url: exec/runtime.html#syntax-funcaddr text: memory address; url: exec/runtime.html#syntax-memaddr - url: syntax/types.html#syntax-valtype + text: host address; url: exec/runtime.html#syntax-hostaddr + url: syntax/types.html#syntax-numtype text: 𝗂πŸ₯𝟀 text: π—‚πŸ¨πŸ¦ text: 𝖿πŸ₯𝟀 text: π–ΏπŸ¨πŸ¦ + url: syntax/types.html#syntax-reftype + text: anyref + text: anyeqref + text: anyfunc text: function element; url: exec/runtime.html#syntax-funcelem text: import component; url: syntax/modules.html#imports text: external value; url: exec/runtime.html#syntax-externval @@ -223,6 +231,7 @@ Each [=agent=] is associated with the following [=ordered map=]s: * The Memory object cache, mapping [=memory address=]es to {{Memory}} objects. * The Table object cache, mapping [=table address=]es to {{Table}} objects. * The Exported Function cache, mapping [=function address=]es to [=Exported Function=] objects. + * The Host value cache, mapping [=host address=]es to values.

The WebAssembly Namespace

@@ -326,7 +335,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje 1. [=Append=] |externfunc| to |imports|. 1. If |externtype| is of the form [=π—€π—…π—ˆπ–»π–Ίπ—…=] |globaltype|, 1. If |globaltype| is [=π—‚πŸ¨πŸ¦=] or [=Type=](|v|) is not [=Number=], throw a {{LinkError}} exception. - 1. Let |value| be [=ToWebAssemblyValue=](|v|, |globaltype|.[=global type|valtype=]) + 1. Let |value| be [=ToWebAssemblyValue=](|v|, |globaltype|.[=global type|valtype=], {{LinkError}}) 1. Assert: |globaltype|.[=global type|mut=] is [=global type|π–Όπ—ˆπ—‡π—Œπ—=], as verified by WebAssembly validation. 1. Let |store| be the [=surrounding agent=]'s [=associated store=]. 1. Let (|store|, |globaladdr|) be [=alloc_global=](|store|, |globaltype|, |value|). @@ -590,6 +599,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
 enum TableKind {
+  "anyref",
+  "anyeqref",
   "anyfunc",
   // Note: More values may be added in future iterations,
   // e.g., typed function references, typed GC references
@@ -742,7 +753,7 @@ This slot holds a [=function address=] relative to the [=surrounding agent=]'s [
     1. For each type |t| of |parameters|,
         1. If the length of |argValues| > |i|, let |arg| be |argValues|[i].
         1. Otherwise, let |arg| be undefined.
-        1. [=Append=] [=ToWebAssemblyValue=](|arg|, |t|) to |args|.
+        1. [=Append=] [=ToWebAssemblyValue=](|arg|, |t|, {{TypeError}}) to |args|.
         1. Set |i| to |i| + 1.
     1. Let (|store|, |ret|) be the result of [=invoke_func=](|store|, |funcaddr|, |args|).
     1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -767,7 +778,7 @@ Note: Exported Functions do not have a \[[Construct]] method and thus it is not
         1. Let |ret| be ? [=Call=](|func|, undefined, |jsArguments|). If an exception is thrown, trigger a WebAssembly trap, and propagate the exception to the enclosing JavaScript.
         1. Let [|parameters|] β†’ [|results|] be |functype|.
         1. If |results| is empty, return undefined.
-        1. Otherwise, return [=ToWebAssemblyValue=](|ret|, |results|[0]).
+        1. Otherwise, return [=ToWebAssemblyValue=](|ret|, |results|[0], {{TypeError}}).
     1. Let |store| be the [=surrounding agent=]'s [=associated store=].
     1. Let (|store|, |funcaddr|) be [=alloc_func=](|store|, |functype|, |hostfunc|).
     1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -781,6 +792,9 @@ Assert: |w| is not of the form [=π—‚πŸ¨πŸ¦.π–Όπ—ˆπ—‡π—Œπ—=] |i64|.
 1. If |w| is of the form [=𝗂πŸ₯𝟀.π–Όπ—ˆπ—‡π—Œπ—=] |i32|, return [=the Number value=] for [=signed_32=](|i32|).
 1. If |w| is of the form [=𝖿πŸ₯𝟀.π–Όπ—ˆπ—‡π—Œπ—=] |f32|, return [=the Number value=] for |f32|.
 1. If |w| is of the form [=π–ΏπŸ¨πŸ¦.π–Όπ—ˆπ—‡π—Œπ—=] |f64|, return [=the Number value=] for |f64|.
+1. If |w| is of the form [=ref.null=], return null.
+1. If |w| is of the form [=ref.func=] |funcaddr|, return the result of creating [=a new Exported Function=] from |funcaddr|.
+1. If |w| is of the form [=ref.host=] |hostaddr|, return the result of [=retrieving a host value=] from |hostaddr|.
 
 
 
@@ -788,7 +802,14 @@ Note: Implementations may optionally replace the NaN payload with any other NaN
 
 
 
-The algorithm ToWebAssemblyValue(|v|, |type|) coerce a JavaScript value to a [=WebAssembly value=] performs the following steps: + For retrieving a host value from a [=host address=] |hostaddr|, perform the following steps: + 1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=]. + 1. Assert: |map|[|hostaddr|] [=map/exists=]. + 1. Return |map|[|hostaddr|]. +
+ +
+The algorithm ToWebAssemblyValue(|v|, |type|, |error|) coerces a JavaScript value to a [=WebAssembly value=] performs the following steps: Assert: |type| is not [=π—‚πŸ¨πŸ¦=]. @@ -801,9 +822,34 @@ Assert: |type| is not [=π—‚πŸ¨πŸ¦=]. 1. If |type| is [=π–ΏπŸ¨πŸ¦=], 1. Let |f64| be ? [=ToNumber=](|v|). 1. Return [=π–ΏπŸ¨πŸ¦.π–Όπ—ˆπ—‡π—Œπ—=] |f64|. +1. If |type| is [=anyref=], + 1. If |v| is a primitive value but not a string, symbol, or null, throw |error|. + 1. Return the result of [=allocating a host address=] for |v|. +1. If |type| is [=anyeqref=], + 1. If |v| is a primitive value but not a symbol or null, throw |error|. + 1. Return the result of [=allocating a host address=] for |v|. +1. If |type| is [=anyfunc=], + 1. If |v| is not an [=Exported function=] or null, throw |error|. + 1. Return the result of [=allocating a host address=] for |v|.
+
+ For allocating a host address for a value |v|, perform the following steps: + 1. If |v| is null, + 1. Return [=ref.null=]. + 1. If |v| is an [=Exported Function=], + 1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot. + 1. Return [=ref.func=] |funcaddr|. + 1. Let |map| be the [=surrounding agent=]'s associated [=host value cache=]. + 1. If a [=host address=] |hostaddr| exists such that |map|[|hostaddr|] is the same as |v|, + 1. Return [=ref.host=] |hostaddr|. + 1. Let [=host address=] |hostaddr| be the smallest address such that |map|[|hostaddr|] [=map/exists=] is false. + 1. [=map/Set=] |map|[|hostaddr|] to |v|. + 1. Return [=ref.host=] |hostaddr|. +
+ +

Error Objects

WebAssembly defines the following Error classes: {{CompileError}}, {{LinkError}}, and {{RuntimeError}}. WebAssembly errors have the following custom bindings: diff --git a/proposals/reference-types/Overview.md b/proposals/reference-types/Overview.md index 1182e5b6..3675bd7b 100644 --- a/proposals/reference-types/Overview.md +++ b/proposals/reference-types/Overview.md @@ -100,7 +100,7 @@ API extensions: * Any JS object (non-primitive value) or string or symbol or `null` can be passed as `anyref` to a Wasm function, stored in a global, or in a table. - It may be possible to allow all other non-primitive values as well, depending on details of existing engines. -* Any JS function object or `null` can be passed as `anyfunc` to a Wasm function, stored in a global, or in a table. +* Any Wasm exported function object or `null` can be passed as `anyfunc` to a Wasm function, stored in a global, or in a table. ## Possible Future Extensions