Skip to content

Commit 666dc4c

Browse files
Ms2gerbinji
authored andcommitted
[js-api] Use IDL conventions around ambient values. (#1037)
1 parent 024e273 commit 666dc4c

File tree

1 file changed

+75
-38
lines changed

1 file changed

+75
-38
lines changed

document/js-api/index.bs

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
365365
</div>
366366

367367
<div algorithm>
368-
To <dfn>create an instance object</dfn> from a WebAssembly module |module| and instance |instance|, perform the following steps:
368+
To <dfn>create an exports object</dfn> from a WebAssembly module |module| and instance |instance|, perform the following steps:
369369
1. Let |exportsObject| be ! [=ObjectCreate=](null).
370370
1. For each pair (|name|, |externtype|) in [=module_exports=](|module|),
371371
1. Let |externval| be [=instance_export=](|instance|, |name|).
@@ -395,7 +395,15 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
395395

396396
Note: the validity and uniqueness checks performed during [=WebAssembly module validation=] ensure that each property name is valid and no properties are defined twice.
397397
1. Perform ! [=SetIntegrityLevel=](|exportsObject|, `"frozen"`).
398-
1. Return a new {{Instance}} object whose internal \[[Instance]] slot is set to |instance| and the \[[Exports]] slot to |exportsObject|.
398+
1. Return |exportsObject|.
399+
</div>
400+
401+
<div algorithm>
402+
To <dfn>initialize an instance object</dfn> |instanceObject| from a WebAssembly module |module| and instance |instance|, perform the following steps:
403+
404+
1. [=Create an exports object=] from |module| and |instance| and let |exportsObject| be the result.
405+
1. Set |instanceObject|.\[[Instance]] to |instance|.
406+
1. Set |instanceObject|.\[[Exports]] to |exportsObject|.
399407
</div>
400408

401409
<div algorithm>
@@ -420,7 +428,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
420428
1. [=Queue a task=] to perform the following steps:
421429
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
422430
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
423-
1. [=Create an instance object=] from |module| and |instance|, and let the result be |instanceObject|.
431+
1. Let |instanceObject| be a [=/new=] {{Instance}}.
432+
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
424433
If this throws an exception, catch it, [=reject=] |promise| with the exception, and terminate these substeps.
425434
1. [=Resolve=] |promise| with |instanceObject|.
426435
1. Return |promise|.
@@ -431,7 +440,8 @@ A {{Module}} object represents a single WebAssembly module. Each {{Module}} obje
431440
1. Let |module| be |moduleObject|.\[[Module]].
432441
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
433442
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
434-
1. [=Create an instance object=] from |module| and |instance|, and let the result be |instanceObject|.
443+
1. Let |instanceObject| be a [=/new=] {{Instance}}.
444+
1. [=initialize an instance object|Initialize=] |instanceObject| from |module| and |instance|.
435445
1. Return |instanceObject|.
436446
</div>
437447

@@ -542,7 +552,8 @@ interface Module {
542552
1. Let |stableBytes| be a [=get a copy of the buffer source|copy of the bytes held by the buffer=] |bytes|.
543553
1. [=Compile a WebAssembly module|Compile the WebAssembly module=] |stableBytes| and store the result as |module|.
544554
1. If |module| is [=error=], throw a {{CompileError}} exception.
545-
1. [=Construct a WebAssembly module object=] from |module| and |stableBytes|, and return the result.
555+
1. Set **this**.\[[Module]] to |module|.
556+
1. Set **this**.\[[Bytes]] to |stableBytes|.
546557
</div>
547558

548559
<h3 id="instances">Instances</h3>
@@ -555,11 +566,15 @@ interface Instance {
555566
</pre>
556567

557568
<div algorithm>
558-
The <dfn constructor for="Instance">Instance(|module|, |importObject|)</dfn> constructor, when invoked, [=instantiate a WebAssembly module|instantiates the WebAssembly module=] |module| importing |importObject| and returns the result.
569+
The <dfn constructor for="Instance">Instance(|module|, |importObject|)</dfn> constructor, when invoked, runs the following steps:
570+
1. Let |module| be |module|.\[[Module]].
571+
1. [=Read the imports=] of |module| with imports |importObject|, and let |imports| be the result.
572+
1. [=Instantiate the core of a WebAssembly module=] |module| with |imports|, and let |instance| be the result.
573+
1. [=initialize an instance object|Initialize=] **this** from |module| and |instance|.
559574
</div>
560575

561576
<div algorithm>
562-
The getter of the <dfn attribute for="Instance">exports</dfn> attribute of {{Instance}} returns the receiver's \[[Exports]] internal slot.
577+
The getter of the <dfn attribute for="Instance">exports</dfn> attribute of {{Instance}} returns **this**.\[[Exports]].
563578
</div>
564579

565580
<h3 id="memories">Memories</h3>
@@ -595,15 +610,24 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
595610
1. Return |buffer|.
596611
</div>
597612

613+
<div algorithm>
614+
To <dfn>initialize a memory object</dfn> |memory| from a [=memory address=] |memaddr|, perform the following steps:
615+
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
616+
1. Assert: |map|[|memaddr|] doesn't [=map/exist=].
617+
1. Let |buffer| be a the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
618+
1. Set |memory|.\[[Memory]] to |memaddr|.
619+
1. Set |memory|.\[[BufferObject]] to |buffer|.
620+
1. [=map/Set=] |map|[|memaddr|] to |memory|.
621+
</div>
622+
598623
<div algorithm>
599624
To <dfn>create a memory object</dfn> from a [=memory address=] |memaddr|, perform the following steps:
600625

601626
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
602627
1. If |map|[|memaddr|] [=map/exists=],
603628
1. Return |map|[|memaddr|].
604-
1. Let |buffer| be a the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
605-
1. Let |memory| be a new {{Memory}} instance with \[[Memory]] set to |memaddr| and \[[BufferObject]] set to |buffer|.
606-
1. [=map/Set=] |map|[|memaddr|] to |memory|.
629+
1. Let |memory| be a [=/new=] {{Memory}}.
630+
1. [=initialize a memory object|Initialize=] |memory| from |memaddr|.
607631
1. Return |memory|.
608632
</div>
609633

@@ -616,14 +640,14 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
616640
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
617641
1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception.
618642
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
619-
1. [=Create a memory object=] from the memory address |memaddr| and return the result.
643+
1. [=initialize a memory object|Initialize=] **this** from |memaddr|.
620644
</div>
621645

622646
<div algorithm>
623647
To <dfn>reset the Memory buffer</dfn> of |memaddr|, perform the following steps:
624648

625649
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
626-
1. Assert: |map|[|memaddr|] [=map/exists=]
650+
1. Assert: |map|[|memaddr|] [=map/exists=].
627651
1. Let |memory| be |map|[|memaddr|].
628652
1. Perform ! [=DetachArrayBuffer=](|memory|.\[[BufferObject]], "WebAssembly.Memory").
629653
1. Let |buffer| be a the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
@@ -632,9 +656,8 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
632656

633657
<div algorithm=dom-Memory-grow>
634658
The <dfn method for="Memory">grow(|delta|)</dfn> method, when invoked, performs the following steps:
635-
1. Let |memory| be the Memory instance.
636659
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
637-
1. Let |memaddr| be |memory|.\[[Memory]].
660+
1. Let |memaddr| be **this**.\[[Memory]].
638661
1. Let |ret| be the [=mem_size=](|store|, |memaddr|).
639662
1. Let |store| be [=mem_grow=](|store|, |memaddr|, |delta|).
640663
1. If |store| is [=error=], throw a {{RangeError}} exception.
@@ -654,7 +677,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
654677
</div>
655678

656679
<div algorithm>
657-
The getter of the <dfn attribute for="Memory">buffer</dfn> attribute of {{Memory}} returns the receiver's \[[BufferObject]] internal slot.
680+
The getter of the <dfn attribute for="Memory">buffer</dfn> attribute of {{Memory}} returns **this**.\[[BufferObject]].
658681
</div>
659682

660683
<h3 id="tables">Tables</h3>
@@ -691,14 +714,23 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
691714
</div>
692715

693716
<div algorithm>
694-
To <dfn>create a table object</dfn> from a [=table address=] |tableaddr|, perform the following steps:
717+
To <dfn>initialize a table object</dfn> |table| from a [=table address=] |tableaddr|, perform the following steps:
695718
1. Let |map| be the [=surrounding agent=]'s associated [=Table object cache=].
696-
1. If |map|[|tableaddr|] [=map/exists=],
697-
1. Return |map|[|tableaddr|].
719+
1. Assert: |map|[|tableaddr|] doesn't [=map/exist=].
698720
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
699721
1. Let |values| be a list whose length is [=table_size=](|store|, |tableaddr|) where each element is null.
700-
1. Let |table| be a new {{Table}} instance with \[[Table]] set to |tableaddr| and \[[Values]] set to |values|.
722+
1. Set |table|.\[[Table]] to |tableaddr|.
723+
1. Set |table|.\[[Values]] to |values|.
701724
1. [=map/Set=] |map|[|tableaddr|] to |table|.
725+
</div>
726+
727+
<div algorithm>
728+
To <dfn>create a table object</dfn> from a [=table address=] |tableaddr|, perform the following steps:
729+
1. Let |map| be the [=surrounding agent=]'s associated [=Table object cache=].
730+
1. If |map|[|tableaddr|] [=map/exists=],
731+
1. Return |map|[|tableaddr|].
732+
1. Let |table| be a [=/new=] {{Table}}.
733+
1. [=initialize a table object|Initialize=] |table| from |tableaddr|.
702734
1. Return |table|.
703735
</div>
704736

@@ -711,40 +743,40 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
711743
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
712744
1. Let (|store|, |tableaddr|) be [=table_alloc=](|store|, |type|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
713745
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
714-
1. [=Create a table object=] from the table address |tableaddr| and return the result.
746+
1. [=initialize a table object|Initialize=] **this** from |tableaddr|.
715747
</div>
716748

717749
<div algorithm=dom-Table-grow>
718750
The <dfn method for="Table">grow(|delta|)</dfn> method, when invoked, performs the following steps:
719-
1. Let |tableaddr| be the Table instance's \[[Table]] internal slot.
720-
1. Let |initialSize| be the length of the Table instance's \[[Values]] internal slot.
751+
1. Let |tableaddr| be **this**.\[[Table]].
752+
1. Let |initialSize| be the length of **this**.\[[Values]].
721753
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
722754
1. Let |result| be [=table_grow=](|store|, |tableaddr|, |delta|).
723755
1. If |result| is [=error=], throw a {{RangeError}} exception.
724756

725757
Note: The above exception may happen due to either insufficient memory or an invalid size parameter.
726758

727759
1. Set the [=surrounding agent=]'s [=associated store=] to |result|.
728-
1. [=Append=] null to the Table instance's \[[Values]] internal slot |delta| times.
760+
1. [=Append=] null to **this**.\[[Values]] |delta| times.
729761
1. Return |initialSize|.
730762
</div>
731763

732764
<div algorithm>
733-
The getter of the <dfn attribute for="Table">length</dfn> attribute of {{Table}} returns the length of the table's \[[Values]] internal slot.
765+
The getter of the <dfn attribute for="Table">length</dfn> attribute of {{Table}} returns the length of **this**.\[[Values]].
734766
</div>
735767

736768
<div algorithm>
737769
The <dfn method for="Table">get(|index|)</dfn> method, when invoked, performs the following steps:
738-
1. Let |values| be the Table instance's \[[Values]] internal slot.
770+
1. Let |values| be **this**.\[[Values]].
739771
1. Let |size| be the length of |values|.
740772
1. If |index| &ge; |size|, throw a {{RangeError}} exception.
741773
1. Return |values|[|index|].
742774
</div>
743775

744776
<div algorithm>
745777
The <dfn method for="Table">set(|index|, |value|)</dfn> method, when invoked, performs the following steps:
746-
1. Let |tableaddr| be the Table instance's \[[Table]] internal slot.
747-
1. Let |values| be the Table instance's \[[Values]] internal slot.
778+
1. Let |tableaddr| be **this**.\[[Table]].
779+
1. Let |values| be **this**.\[[Values]].
748780
1. If |value| is null, let |funcaddr| be an empty [=function element=].
749781
1. Otherwise,
750782
1. If |value| does not have a \[[FunctionAddress]] internal slot, throw a {{TypeError}} exception.
@@ -791,13 +823,21 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
791823
* \[[Global]] : a [=global address=]
792824
</div>
793825

826+
<div algorithm>
827+
To <dfn>initialize a global object</dfn> |global| from a [=global address=] |globaladdr|, perform the following steps:
828+
1. Let |map| be the [=surrounding agent=]'s associated [=Global object cache=].
829+
1. Assert: |map|[|globaladdr|] doesn't [=map/exist=].
830+
1. Set |global|.\[[Global]] to |globaladdr|.
831+
1. [=map/Set=] |map|[|globaladdr|] to |global|.
832+
</div>
833+
794834
<div algorithm>
795835
To <dfn>create a global object</dfn> from a [=global address=] |globaladdr|, perform the following steps:
796836
1. Let |map| be the current [=agent=]'s associated [=Global object cache=].
797837
1. If |map|[|globaladdr|] [=map/exists=],
798838
1. Return |map|[|globaladdr|].
799-
1. Let |global| be a new {{Global}} instance with \[[Global]] set to |globaladdr|.
800-
1. [=map/Set=] |map|[|globaladdr|] to |global|.
839+
1. Let |global| be a [=/new=] {{Global}}.
840+
1. [=initialize a global object|Initialize=] |global| from |globaladdr|.
801841
1. Return |global|.
802842
</div>
803843

@@ -831,7 +871,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
831871
1. Let |store| be the current agent's [=associated store=].
832872
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, |globaltype|, |value|). <!-- TODO(littledan): Report allocation failure https://github.com/WebAssembly/spec/issues/584 -->
833873
1. Set the current agent's [=associated store=] to |store|.
834-
1. [=Create a global object=] from the global address |globaladdr| and return the result.
874+
1. [=initialize a global object|Initialize=] **this** from |globaladdr|.
835875
</div>
836876

837877
<div algorithm>
@@ -846,26 +886,23 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
846886

847887
<div algorithm>
848888
The getter of the <dfn attribute for="Global">value</dfn> attribute of {{Global}}, when invoked, performs the following steps:
849-
1. Let |global| be the {{Global}} instance.
850-
1. Return [=GetGlobalValue=](|global|).
889+
1. Return [=GetGlobalValue=](**this**).
851890

852-
The setter of the value attribute of {{Global}}, when invoked with a value |v|, performs the following steps:
853-
1. Let |global| be the {{Global}} instance.
891+
The setter of the value attribute of {{Global}}, when invoked, performs the following steps:
854892
1. Let |store| be the current agent's [=associated store=].
855-
1. Let |globaladdr| be |global|.\[[Global]].
893+
1. Let |globaladdr| be **this**.\[[Global]].
856894
1. Let |globaltype| be [=global_type=](|store|, |globaladdr|), where |globaltype| is of the form |mut| |valuetype|.
857895
1. If |mut| is [=const=], throw a {{TypeError}}.
858896
1. If |valuetype| is [=𝗂𝟨𝟦=], throw a {{TypeError}}.
859-
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valuetype|).
897+
1. Let |value| be [=ToWebAssemblyValue=](**the given value**, |valuetype|).
860898
1. Let |store| be [=global_write=](|store|, |globaladdr|, |value|).
861899
1. If |store| is [=error=], throw a {{RangeError}} exception.
862900
1. Set the current agent's [=associated store=] to |store|.
863901
</div>
864902

865903
<div algorithm>
866904
The <dfn method for="Global">valueOf()</dfn> method, when invoked, performs the following steps:
867-
1. Let |global| be the {{Global}} instance.
868-
1. Return [=GetGlobalValue=](|global|).
905+
1. Return [=GetGlobalValue=](**this**).
869906
</div>
870907

871908
<h3 id="exported-function-exotic-objects">Exported Functions</h3>

0 commit comments

Comments
 (0)