@@ -132,6 +132,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
132132 text: table address; url: exec/runtime.html#syntax-tableaddr
133133 text: function address; url: exec/runtime.html#syntax-funcaddr
134134 text: memory address; url: exec/runtime.html#syntax-memaddr
135+ text: global address; url: exec/runtime.html#syntax-globaladdr
135136 url: syntax/types.html#syntax-valtype
136137 text: 𝗂𝟥𝟤
137138 text: 𝗂𝟨𝟦
@@ -153,6 +154,9 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
153154 text: 𝗆𝖾𝗆
154155 text: 𝗀𝗅𝗈𝖻𝖺𝗅
155156 text: global type; url: syntax/types.html#syntax-globaltype
157+ url: syntax/types.html#syntax-mut
158+ text: var
159+ text: const
156160 text: address; url: exec/runtime.html#addresses
157161 text: signed_32; url: exec/numerics.html#aux-signed
158162 text: grow_memory; url: exec/instructions.html#exec-grow-memory
@@ -225,6 +229,7 @@ Each [=agent=] is associated with the following [=ordered map=]s:
225229 * The <dfn>Memory object cache</dfn> , mapping [=memory address=] es to {{Memory}} objects.
226230 * The <dfn>Table object cache</dfn> , mapping [=table address=] es to {{Table}} objects.
227231 * The <dfn>Exported Function cache</dfn> , mapping [=function address=] es to [=Exported Function=] objects.
232+ * The <dfn>Global object cache</dfn> , mapping [=global address=] es to {{Global}} objects.
228233
229234<h2 id="webassembly-namespace">The WebAssembly Namespace</h2>
230235
@@ -326,13 +331,17 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
326331 1. Let |index| be the number of external functions in |imports|. This value |index| is known as the <dfn>index of the host function</dfn> |funcaddr|.
327332 1. Let |externfunc| be the [=external value=] [=external value|𝖿𝗎𝗇𝖼=] |funcaddr|.
328333 1. [=Append=] |externfunc| to |imports|.
329- 1. If |externtype| is of the form [=𝗀𝗅𝗈𝖻𝖺𝗅=] |globaltype|,
330- 1. If |globaltype| is [=𝗂𝟨𝟦=] or [=Type=] (|v|) is not [=Number=] , throw a {{LinkError}} exception.
331- 1. Let |value| be [=ToWebAssemblyValue=] (|v|, |globaltype|.<em> [=global type|valtype=] </em> )
332- 1. Assert: |globaltype|.<em> [=global type|mut=] </em> is [=global type|𝖼𝗈𝗇𝗌𝗍=] , as verified by WebAssembly validation.
333- 1. Let |store| be the [=surrounding agent=] 's [=associated store=] .
334- 1. Let (|store|, |globaladdr|) be [=alloc_global=] (|store|, |globaltype|, |value|).
335- 1. Set the [=surrounding agent=] 's [=associated store=] to |store|.
334+ 1. If |externtype| is of the form [=𝗀𝗅𝗈𝖻𝖺𝗅=] |mut| |valtype|,
335+ 1. If [=Type=] (|v|) is [=Number=] ,
336+ 1. If |valtype| is [=𝗂𝟨𝟦=] , throw a {{LinkError}} exception.
337+ 1. Let |value| be [=ToWebAssemblyValue=] (|v|, |valtype|)
338+ 1. Let |store| be the [=surrounding agent=] 's [=associated store=] .
339+ 1. Let (|store|, |globaladdr|) be [=alloc_global=] (|store|, [=const=] |valtype|, |value|).
340+ 1. Set the [[surrounding agent=] 's [=associated store=] to |store|.
341+ 1. If |v| is a {{Global}} instance,
342+ 1. Let |globaladdr| be |v|.\[[Global]]
343+ 1. Otherwise,
344+ 1. Throw a {{LinkError}} exception.
336345 1. Let |externglobal| be [=external value|𝗀𝗅𝗈𝖻𝖺𝗅=] |globaladdr|.
337346 1. [=Append=] |externglobal| to |imports|.
338347 1. If |externtype| is of the form [=𝗆𝖾𝗆=] |memtype|,
@@ -365,11 +374,10 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
365374 1. Let |func| be the result of creating [=a new Exported Function=] from |funcaddr|.
366375 1. Let |value| be |func|.
367376 1. If |externtype| is of the form [=𝗀𝗅𝗈𝖻𝖺𝗅=] |globaltype|,
368- 1. If |globaltype|.<em> [=global type|valtype=] </em> is [=𝗂𝟨𝟦=] , throw a {{LinkError}} exception.
369- 1. Assert: |globaltype|.<em> [=global type|mut=] </em> is [=global type|𝖼𝗈𝗇𝗌𝗍=] , as verified by WebAssembly validation.
370377 1. Assert: |externval| is of the form [=external value|𝗀𝗅𝗈𝖻𝖺𝗅=] |globaladdr|.
371378 1. Let [=external value|𝗀𝗅𝗈𝖻𝖺𝗅=] |globaladdr| be |externval|.
372- 1. Let |value| be [=ToJSValue=] ([=read_global=] (|store|, |globaladdr|)).
379+ 1. Let |global| be [=create a global object|a new Global object=] created from |globaladdr|.
380+ 1. Let |value| be |global|.
373381 1. If |externtype| is of the form [=𝗆𝖾𝗆=] |memtype|,
374382 1. Assert: |externval| is of the form [=external value|𝗆𝖾𝗆=] |memaddr|.
375383 1. Let [=external value|𝗆𝖾𝗆=] |memaddr| be |externval|.
@@ -704,6 +712,93 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
704712 1. Return undefined.
705713</div>
706714
715+ <h3 id="globals">Globals</h3>
716+
717+ <pre class="idl">
718+ dictionary GlobalDescriptor {
719+ required USVString value;
720+ boolean mutable = false;
721+ };
722+
723+ [LegacyNamespace=WebAssembly, Constructor(GlobalDescriptor descriptor, unrestricted double value = 0), Exposed=(Window,Worker,Worklet)]
724+ interface Global {
725+ unrestricted double valueOf();
726+ attribute unrestricted double value;
727+ };
728+ </pre>
729+
730+ <div>
731+ A {{Global}} object represents a single [=global instance=]
732+ which can be simultaneously referenced by multiple {{Instance}} objects. Each
733+ {{Global}} object has one internal slot:
734+
735+ * \[[Global]] : a [=global address=]
736+ </div>
737+
738+ <div algorithm>
739+ To <dfn>create a global object</dfn> from a [=global address=] |globaladdr|, perform the following steps:
740+ 1. Let |map| be the current [=agent=] 's associated [=Global object cache=] .
741+ 1. If |map|[|globaladdr|] [=map/exists=] ,
742+ 1. Return |map|[|globaladdr|] .
743+ 1. Let |global| be a new {{Global}} instance with \[[Global]] set to |globaladdr|.
744+ 1. [=map/Set=] |map|[|globaladdr|] to |global|.
745+ 1. Return |global|.
746+ </div>
747+
748+ <div algorithm>
749+ The algorithm <dfn>ToValueType</dfn> (|s|) performs the following steps:
750+ 1. If |s| equals "i32", return [=𝗂𝟥𝟤=] .
751+ 1. If |s| equals "f32", return [=𝖿𝟥𝟤=] .
752+ 1. If |s| equals "f64", return [=𝖿𝟨𝟦=] .
753+ 1. Otherwise, throw a {{TypeError}} exception.
754+ </div>
755+
756+ <div algorithm>
757+ The <dfn constructor for="Global">Global(descriptor, v)</dfn> constructor, when invoked, performs the following steps:
758+ 1. Let |mutable| be |descriptor|["mutable"] .
759+ 1. Let |valuetype| be [=ToValueType=] (|descriptor|["value"] ).
760+ 1. Let |value| be [=ToWebAssemblyValue=] (|v|, |valuetype|).
761+ 1. If |mutable| is true, let |globaltype| be [=var=] |valuetype|; otherwise, let |globaltype| be [=const=] |valuetype|.
762+ 1. Let |store| be the current agent's [=associated store=] .
763+ 1. Let (|store|, |globaladdr|) be [=alloc_global=] (|store|, |globaltype|, |value|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
764+ 1. Set the current agent's [=associated store=] to |store|.
765+ 1. [=Create a global object=] from the global address |globaladdr| and return the result.
766+ </div>
767+
768+ <div algorithm>
769+ The algorithm <dfn>GetGlobalValue</dfn> ({{Global}} |global|) performs the following steps:
770+ 1. Let |store| be the current agent's [=associated store=] .
771+ 1. Let |globaladdr| be |global|.\[[Global]] .
772+ 1. Let |globaltype| be [=type_global=] (|store|, |globaladdr|).
773+ 1. If |globaltype| is of the form |mut| [=𝗂𝟨𝟦=] , throw a {{TypeError}} .
774+ 1. Let |value| be [=read_global=] (|store|, |globaladdr|).
775+ 1. Return [=ToJSValue=] (|value|).
776+ </div>
777+
778+ <div algorithm>
779+ The getter of the <dfn attribute for="Global">value</dfn> attribute of {{Global}} , when invoked, performs the following steps:
780+ 1. Let |global| be the {{Global}} instance.
781+ 1. Return [=GetGlobalValue=] (|global|).
782+
783+ The setter of the value attribute of {{Global}} , when invoked with a value |v|, performs the following steps:
784+ 1. Let |global| be the {{Global}} instance.
785+ 1. Let |store| be the current agent's [=associated store=] .
786+ 1. Let |globaladdr| be |global|.\[[Global]] .
787+ 1. Let |globaltype| be [=type_global=] (|store|, |globaladdr|), where |globaltype| is of the form |mut| |valuetype|.
788+ 1. If |mut| is [=const=] , throw a {{TypeError}.
789+ 1. If |valuetype| is [=𝗂𝟨𝟦=], throw a {{TypeError}} .
790+ 1. Let |value| be [=ToWebAssemblyValue=] (|v|, |valuetype|).
791+ 1. Let |store| be [=write_global=] (|store|, |globaladdr|, |value|).
792+ 1. If |store| is [=error=] , throw a {{RangeError}} exception.
793+ 1. Set the current agent's [=associated store=] to |store|.
794+ </div>
795+
796+ <div algorithm>
797+ The <dfn method for="Global">valueOf()</dfn> method, when invoked, performs the following steps:
798+ 1. Let |global| be the {{Global}} instance.
799+ 1. Return [=GetGlobalValue=] (|global|).
800+ </div>
801+
707802<h3 id="exported-function-exotic-objects">Exported Functions</h3>
708803
709804A WebAssembly function is made available in JavaScript as an <dfn>Exported Function</dfn> .
0 commit comments