Skip to content

Commit 8deee83

Browse files
authored
Editorial: try to clarify the JS API (#212)
1 parent 8993431 commit 8deee83

1 file changed

Lines changed: 43 additions & 38 deletions

File tree

document/js-api/index.bs

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL
150150
type: dfn
151151
text: create a namespace object; url: create-a-namespace-object
152152
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal
153-
type: dfn
153+
type: abstract-op
154154
text: IsFixedLengthArrayBuffer; url: sec-isfixedarraybuffer
155155
text: HostResizeArrayBuffer; url: sec-hostresizearraybuffer
156156
text: HostGrowSharedArrayBuffer; url: sec-hostgrowsharedarraybuffer
@@ -618,41 +618,51 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
618618
<div algorithm>
619619
To <dfn>create a fixed length memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
620620

621-
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
622-
1. If |block| is a [=Shared Data Block=],
621+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
622+
1. Let <var ignore>limits</var> |share| be [=mem_type=](|store|, |memaddr|).
623+
1. If |share| is shared,
624+
1. Let |block| be a [=Shared Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
623625
1. Let |buffer| be a new {{SharedArrayBuffer}} with the internal slots \[[ArrayBufferData]] and \[[ArrayBufferByteLength]].
624626
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
625627
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
626628
1. Perform ! [$SetIntegrityLevel$](|buffer|, `"frozen"`).
627629
1. Otherwise,
630+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
628631
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferDetachKey]].
629632
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
630633
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
631634
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
632635
1. Return |buffer|.
633636
</div>
634637

635-
Note: (TODO) Check whether only SharedArrayBuffers need integrity level "frozen" (see the Threads Proposal Overview).
638+
Issue: (TODO) Check whether only SharedArrayBuffers need integrity level "frozen" (see the Threads Proposal Overview).
636639

637640
To create a resizable memory buffer we perform the same steps as above, but also setting the buffer's maximum size.
638641

639642
<div algorithm>
640-
To <dfn>create a resizable memory buffer</dfn> from a [=memory address=] |memaddr| and a |maxsize|, perform the following steps:
643+
To <dfn>create a resizable memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
641644

642-
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
643-
1. Let |length| be the length of |block|.
644-
1. If |maxsize| &gt; (65536 &times; 65536),
645-
1. Throw a {{RangeError}} exception.
646-
1. If |block| is a [=Shared Data Block=],
645+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
646+
1. Let { |min|, |max| } |share| be [=mem_type=](|store|, |memaddr|).
647+
1. If |max| is not empty,
648+
1. If |max| &gt; (65536 &times; 65536),
649+
1. Issue: Can this happen?
650+
1. Throw a {{RangeError}} exception.
651+
1. Let |maxsize| be |max|.
652+
1. Otherwise,
653+
1. Let |maxsize| be 65536 &times; 65536.
654+
1. If |share| is shared,
655+
1. Let |block| be a [=Shared Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
647656
1. Let |buffer| be a new {{SharedArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferMaxByteLength]].
648657
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
649-
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
658+
1. Set |buffer|.\[[ArrayBufferByteLength]] to |min|.
650659
1. Set |buffer|.\[[ArrayBufferMaxByteLength]] to |maxsize|.
651660
1. Perform ! [$SetIntegrityLevel$](|buffer|, `"frozen"`).
652661
1. Otherwise,
662+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
653663
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], \[[ArrayBufferMaxByteLength]], and \[[ArrayBufferDetachKey]].
654664
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
655-
1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|.
665+
1. Set |buffer|.\[[ArrayBufferByteLength]] to |min|.
656666
1. Set |buffer|.\[[ArrayBufferMaxByteLength]] to |maxsize|.
657667
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
658668
1. Return |buffer|.
@@ -684,9 +694,9 @@ To create a resizable memory buffer we perform the same steps as above, but also
684694
1. Let |initial| be |descriptor|["initial"].
685695
1. If |descriptor|["maximum"] [=map/exists=], let |maximum| be |descriptor|["maximum"]; otherwise, let |maximum| be empty.
686696
1. If |maximum| is not empty and |maximum| &lt; |initial|, throw a {{RangeError}} exception.
687-
1. Let |shared| be |descriptor|["shared"].
688-
1. If |shared| is true and |maximum| is empty, throw a {{TypeError}} exception.
689-
1. Let |memtype| be { min |initial|, max |maximum|, shared |shared| }.
697+
1. Let |share| be shared if |descriptor|["shared"] is true and unshared otherwise.
698+
1. If |share| is shared and |maximum| is empty, throw a {{TypeError}} exception.
699+
1. Let |memtype| be ({ min |initial|, max |maximum| }, |share|).
690700
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
691701
1. Let (|store|, |memaddr|) be [=mem_alloc=](|store|, |memtype|). If allocation fails, throw a {{RangeError}} exception.
692702
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
@@ -700,12 +710,13 @@ To create a resizable memory buffer we perform the same steps as above, but also
700710
1. Assert: |map|[|memaddr|] [=map/exists=].
701711
1. Let |memory| be |map|[|memaddr|].
702712
1. Let |buffer| be |memory|.\[[BufferObject]].
703-
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true,
704-
1. If |memory|.\[[BufferObject]] is an {{ArrayBuffer}},
713+
1. If [$IsFixedLengthArrayBuffer$](|buffer|) is true,
714+
1. If [$IsSharedArrayBuffer$](|buffer|) is false,
705715
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
706-
1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
707-
1. Set |memory|.\[[BufferObject]] to |buffer|.
716+
1. Let |newBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
717+
1. Set |memory|.\[[BufferObject]] to |newBuffer|.
708718
1. Otherwise,
719+
1. Issue: Is this safe for a SharedArrayBuffer?
709720
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
710721
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
711722
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
@@ -743,8 +754,8 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
743754
The <dfn method for="Memory">toFixedLengthBuffer()</dfn> method, when invoked, performs the following steps:
744755
1. Let |buffer| be **this**.\[[BufferObject]].
745756
1. Let |memaddr| be **this**.\[[Memory]].
746-
1. If |buffer| is an {{ArrayBuffer}},
747-
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, return |buffer|.
757+
1. If [$IsSharedArrayBuffer$](|buffer|) is false,
758+
1. If [$IsFixedLengthArrayBuffer$](|buffer|) is true, return |buffer|.
748759
1. Otherwise,
749760
1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
750761
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
@@ -762,31 +773,25 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
762773
<div algorithm=dom-Memory-toResizableBuffer>
763774
The <dfn method for="Memory">toResizableBuffer()</dfn> method, when invoked, performs the following steps:
764775
1. Let |buffer| be **this**.\[[BufferObject]].
765-
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is false, return |buffer|.
776+
1. If [$IsFixedLengthArrayBuffer$](|buffer|) is false, return |buffer|.
766777
1. Let |memaddr| be **this**.\[[Memory]].
767-
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
768-
1. Let |memtype| be [=mem_type=](|store|, |memaddr|).
769-
1. If |memtype| has a max,
770-
1. Let |maxsize| be the max value in |memtype|.
771-
1. Otherwise,
772-
1. Let |maxsize| be 65536 &times; 65536.
773-
1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|.
774-
1. If |buffer| is an {{ArrayBuffer}},
778+
1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr|.
779+
1. If [$IsSharedArrayBuffer$](|buffer|) is false,
775780
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
776781
1. Set **this**.\[[BufferObject]] to |resizableBuffer|.
777782
1. Return |resizableBuffer|.
778783
</div>
779784

780-
{{ArrayBuffer}} and {{SharedArrayBuffer}} objects returned by a {{Memory}} object must have size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [=HostResizeArrayBuffer=] and [=HostGrowSharedArrayBuffer=] are redefined as follows.
785+
{{ArrayBuffer}} and {{SharedArrayBuffer}} objects returned by a {{Memory}} object must have size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [$HostResizeArrayBuffer$] and [$HostGrowSharedArrayBuffer$] are redefined as follows.
781786

782-
<div algorithm>
783-
The <dfn>abstract operation [=HostResizeArrayBuffer=]</dfn> takes arguments an {{ArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called.
787+
<div algorithm export>
788+
The <dfn>abstract operation [$HostResizeArrayBuffer$]</dfn> takes arguments an {{ArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called.
784789

785790
1. If |buffer|.\[[ArrayBufferDetachKey]] is "WebAssembly.Memory",
786791
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
787792
1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|.
788793
1. [=map/iterate|For each=] |memaddr| &rarr; |mem| in |map|,
789-
1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true,
794+
1. If [=SameValue=](|mem|.\[[BufferObject]], |buffer|) is true,
790795
1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0.
791796
1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]].
792797
1. If |lengthDelta| &lt; 0 or |lengthDelta| modulo 65536 is not 0,
@@ -797,13 +802,13 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
797802
1. Otherwise, return unhandled.
798803
</div>
799804

800-
<div algorithm>
801-
The <dfn>abstract operation [=HostGrowSharedArrayBuffer=]</dfn> takes arguments a {{SharedArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called.
805+
<div algorithm export>
806+
The <dfn>abstract operation [$HostGrowSharedArrayBuffer$]</dfn> takes arguments a {{SharedArrayBuffer}} |buffer| and |newLength|. It performs the following steps when called.
802807

803808
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
804809
1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|.
805810
1. [=map/iterate|For each=] |memaddr| &rarr; |mem| in |map|,
806-
1. If [=SameValue=](mem.\[[BufferObject]], |buffer|) is true,
811+
1. If [=SameValue=](|mem|.\[[BufferObject]], |buffer|) is true,
807812
1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0.
808813
1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]].
809814
1. If |lengthDelta| &lt; 0 or |lengthDelta| modulo 65536 is not 0,
@@ -813,7 +818,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
813818
1. If |newLength| &lt; |buffer|.\[[ArrayBufferByteLength]] or |newLength| &gt; |buffer|.\[[ArrayBufferMaxByteLength]], throw a {{RangeError}} exception.
814819
1. Let |agentRecord| be the surrounding agent's [=Agent Record=].
815820
1. Let |isLittleEndian| be |agentRecord|.\[[LittleEndian]] .
816-
1. Let |event| be an implementation defined [=ReadModifyWriteSharedMemory=] event, whose \[[Order]] is "SeqCst", \[[Payload]] is NumericToRawBytes$](Bigint, |newLength|, |isLittleEndian|), \[[Block]] is |buffer|.\[[ArrayBufferByteLengthData]], \[[ByteIndex]] is 0, and \[[ElementSize]] is 8.
821+
1. Let |event| be an implementation defined [=ReadModifyWriteSharedMemory=] event, whose \[[Order]] is "SeqCst", \[[Payload]] is [$NumericToRawBytes$](Bigint, |newLength|, |isLittleEndian|), \[[Block]] is |buffer|.\[[ArrayBufferByteLengthData]], \[[ByteIndex]] is 0, and \[[ElementSize]] is 8.
817822
1. Let |eventsRecord| be the [=Agent Events Record|EventsRecord=] in |agentRecord|.\[[CandidateExecution]].\[[EventsRecords]] that corresponds to the surrounding agent's signifier |agentRecord|.\[[Signifier]].
818823
1. Append |event| to |eventsRecord|.\[[EventsList]].
819824
1. Return handled.

0 commit comments

Comments
 (0)