You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Introduce algorithms for creating ArrayBuffers and ArrayBufferViews from byte sequences.
* Introduce algorithms for writing into ArrayBuffers and ArrayBufferViews, replacing "get a reference to the bytes held by the buffer source".
* Introduce "transfer" for an ArrayBuffer.
* Introduce "byte length", "underlying buffer", and "detached" for introspecting a BufferSource.
* Improve the specification for "get a copy of the bytes held by a buffer source" and "detach".
text: element size; url: table-the-typedarray-constructors
240
246
</pre>
241
247
242
248
<style>
@@ -6774,51 +6780,9 @@ There is no way to represent a constant value of any of these types in IDL.
6774
6780
The [=type name=] of all
6775
6781
of these types is the name of the type itself.
6776
6782
6777
-
At the specification prose level, IDL [=buffer source types=]
6778
-
are simply references to objects. To inspect or manipulate the bytes inside the buffer,
6779
-
specification prose must first either
6780
-
<dfn id="dfn-get-buffer-source-reference" export lt="get a reference to the buffer source">get a reference to the bytes held by the buffer source</dfn>
6781
-
or <dfn id="dfn-get-buffer-source-copy" export lt="get a copy of the buffer source">get a copy of the bytes held by the buffer source</dfn>.
6782
-
With a reference to the buffer source’s bytes, specification prose can get or set individual
6783
-
byte values using that reference.
6784
-
6785
-
<div class="advisement">
6786
-
6787
-
Extreme care must be taken when writing specification text that gets a reference
6788
-
to the bytes held by a buffer source, as the underlying data can easily be changed
6789
-
by the script author or other APIs at unpredictable times. If you are using a buffer source type
6790
-
as an operation argument to obtain a chunk of binary data that will not be modified,
6791
-
it is strongly recommended to get a copy of the buffer source’s bytes at the beginning
6792
-
of the prose defining the operation.
6793
-
6794
-
Requiring prose to explicitly get a reference to or copy of the bytes is intended to
6795
-
help specification reviewers look for problematic uses of these buffer source types.
6796
-
6797
-
</div>
6798
-
6799
-
<div class="note">
6800
-
6801
-
When designing APIs that take a buffer, it is recommended to use the
6802
-
{{BufferSource}} typedef rather than {{ArrayBuffer}}
6803
-
or any of the view types.
6804
-
6805
-
When designing APIs that create and return a buffer, it is recommended
6806
-
to use the {{ArrayBuffer}} type rather than
6807
-
{{Uint8Array}}.
6808
-
6809
-
</div>
6810
-
6811
-
Attempting to [=get a reference to the buffer source|get a reference to=] or
6812
-
[=get a copy of the buffer source|get a copy of the bytes held by a buffer source=]
6813
-
when the {{ArrayBuffer}} has been [=ArrayBuffer/detached=]
6814
-
will fail in a language binding-specific manner.
6815
-
6816
-
Note: See [[#es-buffer-source-types]] below for
6817
-
how interacting with buffer source types works in the ECMAScript language binding.
6818
-
6819
-
<p class="issue">
6820
-
We should include an example of specification text that uses these types and terms.
6821
-
</p>
6783
+
At the specification prose level, IDL [=buffer source types=] are simply references to objects. To
6784
+
inspect or manipulate the bytes inside the buffer, specification prose needs to use the algorithms
6785
+
in [[#es-buffer-source-types]].
6822
6786
6823
6787
<pre class="grammar" id="prod-BufferRelatedType">
6824
6788
BufferRelatedType :
@@ -8994,37 +8958,178 @@ an IDL value of any [=buffer source type=]
8994
8958
to an ECMAScript value is the Object value that represents
8995
8959
a reference to the same object that the IDL value represents.
8996
8960
8997
-
<div algorithm="get a reference to a buffer source">
8998
-
8999
-
When [=get a reference to the buffer source|getting a reference to=]
9000
-
or [=get a copy of the buffer source|getting a copy of the bytes held by a buffer source=]
9001
-
that is an ECMAScript {{ECMAScript/ArrayBuffer}}, {{ECMAScript/DataView}}
9002
-
or typed array object, these steps must be followed:
9003
-
9004
-
1. Let |O| be the ECMAScript object that is the buffer source.
9005
-
1. Initialize |arrayBuffer| to |O|.
9006
-
1. Initialize |offset| to 0.
9007
-
1. Initialize |length| to 0.
9008
-
1. If |O| has a \[[ViewedArrayBuffer]] [=internal slot=], then:
9009
-
1. Set |arrayBuffer| to the value of |O|’s \[[ViewedArrayBuffer]] [=internal slot=].
9010
-
1. Set |offset| to the value of |O|’s \[[ByteOffset]] [=internal slot=].
9011
-
1. Set |length| to the value of |O|’s \[[ByteLength]] [=internal slot=].
9012
-
1. Otherwise, set |length| to the value of |O|’s \[[ArrayBufferByteLength]] [=internal slot=].
9013
-
1. If <a abstract-op>IsDetachedBuffer</a>(|arrayBuffer|) is <emu-val>true</emu-val>, then
9014
-
return the empty byte sequence.
9015
-
1. Let |data| be the value of |O|’s \[[ArrayBufferData]] [=internal slot=].
9016
-
1. Return a reference to or copy of (as required) the |length| bytes in |data|
9017
-
starting at byte offset |offset|.
8961
+
<hr>
8962
+
8963
+
<div algorithm>
8964
+
To <dfn export for="ArrayBuffer">create</dfn> an {{ArrayBuffer}} from a [=byte sequence=]
1. Let |arrayBuffer| be the result of [=converted to an IDL value|converting=] |esArrayBuffer|
8971
+
to an IDL value of type {{ArrayBuffer}}.
8972
+
1. [=ArrayBuffer/Write=] |bytes| into |arrayBuffer|.
8973
+
1. Return |arrayBuffer|.
8974
+
</div>
8975
+
8976
+
<div algorithm>
8977
+
To <dfn export for="ArrayBufferView">create</dfn> one of the {{ArrayBufferView}} types from a
8978
+
[=byte sequence=] |bytes| in a [=Realm=] |realm|:
8979
+
8980
+
1. Assert: if the type is not {{DataView}}, then |bytes|'s [=byte sequence/length=] [=modulo=]
8981
+
the [=element size=] of that type is 0.
8982
+
1. Let |arrayBuffer| be the result of [=ArrayBuffer/creating=] an {{ArrayBuffer}} from |bytes|
8983
+
in |realm|.
8984
+
1. Let |esArrayBuffer| be the result of [=converted to an ECMAScript value|converting=]
8985
+
|arrayBuffer| to an ECMAScript value.
8986
+
1. Let |constructor| be the appropriate constructor from |realm|.\[[Intrinsics]] for the type
8987
+
of {{ArrayBufferView}} being created.
8988
+
1. Let |esView| be [=!=] [$Construct$](|constructor|, « |esArrayBuffer| »).
8989
+
1. Return the result of [=converted to an IDL value|converting=] |esView| into the given type.
8990
+
</div>
8991
+
8992
+
<div algorithm>
8993
+
To <dfn id="dfn-get-buffer-source-copy" export lt="get a copy of the buffer source|get a copy of the bytes held by the buffer source">get a copy of the bytes held by the buffer source</dfn>
8994
+
given a {{BufferSource}} |bufferSource|:
8995
+
8996
+
1. Let |esBufferSource| be be the result of [=converted to an ECMAScript value|converting=]
8997
+
|bufferSource| to an ECMAScript value.
8998
+
1. Let |esArrayBuffer| be |esBufferSource|.
8999
+
1. Let |offset| be 0.
9000
+
1. Let |length| be 0.
9001
+
1. If |esBufferSource| has a \[[ViewedArrayBuffer]] [=internal slot=], then:
9002
+
1. Set |esArrayBuffer| to |esBufferSource|.\[[ViewedArrayBuffer]].
9003
+
1. Set |offset| to |esBufferSource|.\[[ByteOffset]].
9004
+
1. Set |length| to |esBufferSource|.\[[ByteLength]].
9005
+
1. Otherwise:
9006
+
1. Assert: |esBufferSource| is an {{ECMAScript/ArrayBuffer}} or
9007
+
{{ECMAScript/SharedArrayBuffer}} object.
9008
+
1. Set |length| to |esBufferSource|.\[[ArrayBufferByteLength]].
9009
+
1. If [=!=] [$IsDetachedBuffer$](|esArrayBuffer|) is true, then return the empty
9010
+
[=byte sequence=].
9011
+
1. Let |bytes| be a new [=byte sequence=] of [=byte sequence/length=] equal to |length|.
9012
+
1. For |i| in [=the range=] |offset| to |offset| + |length| − 1, inclusive, set
9013
+
|bytes|[|i| − |offset|] to [=!=] [$GetValueFromBuffer$](|esArrayBuffer|, |i|, Uint8,
9014
+
true, Unordered).
9015
+
1. Return |bytes|.
9018
9016
</div>
9019
9017
9020
9018
<div algorithm>
9019
+
The <dfn export for="BufferSource">byte length</dfn> of a {{BufferSource}} |bufferSource| is
9020
+
the value returned by the following steps:
9021
9021
9022
-
To <dfn id="dfn-detach" for="ArrayBuffer" export>detach</dfn> an {{ArrayBuffer}}, these steps must be followed:
9022
+
1. Let |esBufferSource| be be the result of [=converted to an ECMAScript value|converting=]
9023
+
|bufferSource| to an ECMAScript value.
9024
+
1. If |esBufferSource| has a \[[ViewedArrayBuffer]] internal slot, then return
0 commit comments