Skip to content
85 changes: 50 additions & 35 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -9294,19 +9294,15 @@ a reference to the same object that the IDL value represents.
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>
given a [=buffer source type=] instance |bufferSource|:

1. Let |jsBufferSource| be the result of [=converted to a JavaScript value|converting=]
|bufferSource| to a JavaScript value.
1. Let |jsArrayBuffer| be |jsBufferSource|.
1. Let |arrayBuffer| be |bufferSource|.
1. Let |offset| be 0.
1. Let |length| be 0.
1. If |jsBufferSource| has a \[[ViewedArrayBuffer]] [=/internal slot=], then:
1. Set |jsArrayBuffer| to |jsBufferSource|.\[[ViewedArrayBuffer]].
1. Set |offset| to |jsBufferSource|.\[[ByteOffset]].
1. Set |length| to |jsBufferSource|.\[[ByteLength]].
1. Otherwise:
1. Assert: |jsBufferSource| is an {{ArrayBuffer}} or
{{SharedArrayBuffer}} object.
1. Set |length| to |jsBufferSource|.\[[ArrayBufferByteLength]].
1. Let |length| be |bufferSource|'s [=BufferSource/byte length=].
1. If |bufferSource| is a [=buffer view type=] instance, then:
1. Set |arrayBuffer| to |bufferSource|'s [=underlying buffer=].
1. Set |offset| to |bufferSource|'s [=ArrayBufferView/byte offset=].
1. Assert: |arrayBuffer| is an {{ArrayBuffer}} or {{SharedArrayBuffer}} object.
1. Let |jsArrayBuffer| be the result of [=converted to a JavaScript value|converting=]
|arrayBuffer| to a JavaScript value.
1. If [$IsDetachedBuffer$](|jsArrayBuffer|) is true, then return the empty
[=byte sequence=].
1. Let |bytes| be a new [=byte sequence=] of [=byte sequence/length=] equal to |length|.
Expand All @@ -9316,15 +9312,40 @@ a reference to the same object that the IDL value represents.
1. Return |bytes|.
</div>

<div algorithm>
The <dfn export for="ArrayBufferView">byte offset</dfn> of an {{ArrayBufferView}}
|view| is the value returned by the following steps:

1. Let |jsView| be the result of [=converted to a JavaScript value|converting=] |view| to
a JavaScript value.
1. If [$IsArrayBufferViewOutOfBounds$](|jsView|) is true, throw a {{TypeError}} exception.
1. Return |jsView|.\[[ByteOffset]].
</div>

<div algorithm>
The <dfn export for="BufferSource">byte length</dfn> of a [=buffer source type=] instance
|bufferSource| is the value returned by the following steps:

1. Let |jsBufferSource| be the result of [=converted to a JavaScript value|converting=]
|bufferSource| to a JavaScript value.
1. If |jsBufferSource| has a \[[ViewedArrayBuffer]] internal slot, then return
|jsBufferSource|.\[[ByteLength]].
1. Return |jsBufferSource|.\[[ArrayBufferByteLength]].
1. If |jsBufferSource| has a \[[ViewedArrayBuffer]] [=/internal slot=], then:
1. If |jsBufferSource| has a \[[TypedArrayName]] [=/internal slot=]:
1. Assert: |jsBufferSource| is a [=typed array type=] instance.
1. Let |taRecord| be [$MakeTypedArrayWithBufferWitnessRecord$](|jsBufferSource|,
Seq-Cst).
1. Return [$TypedArrayByteLength$](|taRecord|).
1. Otherwise:
1. Assert: |jsBufferSource| is a {{DataView}}.
1. Let |viewRecord| be [$MakeDataViewWithBufferWitnessRecord$](|jsBufferSource|,
Seq-Cst).
1. If [$IsViewOutOfBounds$](|viewRecord|) is true, return 0.
1. Return [$GetViewByteLength$](|viewRecord|).
1. Otherwise, if [$IsSharedArrayBuffer$](|jsBufferSource|) is true, then:
1. Assert: |jsBufferSource| is a {{SharedArrayBuffer}}.
1. Return [$ArrayBufferByteLength$](|jsBufferSource|, Seq-Cst).
1. Otherwise:
1. Assert: |jsBufferSource| is an {{ArrayBuffer}}.
1. Return |jsBufferSource|.\[[ArrayBufferByteLength]].
</div>
<!-- TODO: should this be stricter around not being detached? -->

Expand All @@ -9348,10 +9369,10 @@ a reference to the same object that the IDL value represents.
<dfn id=arraybuffer-write-startingoffset export for="ArrayBuffer/write,SharedArrayBuffer/write">|startingOffset|</dfn>
(default 0):

1. Assert: |bytes|'s [=byte sequence/length=] ≤ |arrayBuffer|'s [=byte length=]
&minus; |startingOffset|.
1. Let |jsArrayBuffer| be the result of [=converted to a JavaScript value|converting=]
|arrayBuffer| to a JavaScript value.
1. Assert: |bytes|'s [=byte sequence/length=] ≤ |jsArrayBuffer|.\[[ArrayBufferByteLength]]
&minus; |startingOffset|.
1. For |i| in [=the range=] |startingOffset| to |startingOffset| + |bytes|'s [=byte
sequence/length=] &minus; 1, inclusive, perform [$SetValueInBuffer$](|jsArrayBuffer|,
|i|, Uint8, |bytes|[|i| - |startingOffset|], true, Unordered).
Expand All @@ -9362,16 +9383,12 @@ a reference to the same object that the IDL value represents.
{{ArrayBufferView}} |view|, optionally given a
<dfn export for="ArrayBufferView/write">|startingOffset|</dfn> (default 0):

1. Let |jsView| be the result of [=converted to a JavaScript value|converting=] |view| to
a JavaScript value.
1. Assert: |bytes|'s [=byte sequence/length=] ≤ |jsView|.\[[ByteLength]] &minus;
1. Assert: |bytes|'s [=byte sequence/length=] ≤ |view|'s [=byte length=] &minus;
|startingOffset|.
1. Assert: if |view| is not a {{DataView}}, then |bytes|'s [=byte sequence/length=] [=modulo=]
the [=element size=] of |view|'s type is 0.
1. Let |arrayBuffer| be the result of [=converted to an IDL value|converting=]
|jsView|.\[[ViewedArrayBuffer]] to an IDL value of type {{ArrayBuffer}}.
1. [=ArrayBuffer/Write=] |bytes| into |arrayBuffer| with
<i>[=ArrayBuffer/write/startingOffset=]</i> set to |jsView|.\[[ByteOffset]] +
1. [=ArrayBuffer/Write=] |bytes| into |view|'s [=underlying buffer=] with
<i>[=ArrayBuffer/write/startingOffset=]</i> set to |view|'s [=ArrayBufferView/byte offset=] +
|startingOffset|.
</div>

Expand Down Expand Up @@ -9429,22 +9446,20 @@ a reference to the same object that the IDL value represents.
1. Return true.
</div>

<div algorithm>
<div algorithm="ArrayBuffer/transfer">
To <dfn for="ArrayBuffer" export>transfer</dfn> an {{ArrayBuffer}} |arrayBuffer|, optionally
given a [=realm=] |targetRealm|:
given <dfn export for="ArrayBuffer/transfer">|preserveResizability|</dfn> (default false):

1. Let |jsArrayBuffer| be the result of [=converted to a JavaScript value|converting=]
|arrayBuffer| to a JavaScript value.
1. If [$IsDetachedBuffer$](|jsArrayBuffer|) is false, then [=JavaScript/throw=] a
1. If [$IsDetachedBuffer$](|jsArrayBuffer|) is true, then [=JavaScript/throw=] a
<l spec=ecmascript>{{TypeError}}</l>.
1. Let |arrayBufferData| be |jsArrayBuffer|.\[[ArrayBufferData]].
1. Let |arrayBufferByteLength| be |jsArrayBuffer|.\[[ArrayBufferByteLength]].
1. Perform [=?=] [$DetachArrayBuffer$](|jsArrayBuffer|).
1. If |targetRealm| is not given, let |targetRealm| be the [=current realm=].
1. Let |jsTransferred| be [=?=]
[$AllocateArrayBuffer$](|targetRealm|.\[[Intrinsics]].\[[{{%ArrayBuffer%}}]], 0).
1. Set |jsTransferred|.\[[ArrayBufferData]] to |arrayBufferData|.
1. Set |jsTransferred|.\[[ArrayBufferByteLength]] to |arrayBufferByteLength|.
1. If |preserveResizability| is true, then:
1. Let |jsTransferred| be [=?=] [$ArrayBufferCopyAndDetach$](|jsArrayBuffer|, undefined,
Preserve-Resizability).
1. Otherwise,
1. Let |jsTransferred| be [=?=] [$ArrayBufferCopyAndDetach$](|jsArrayBuffer|, undefined,
Fixed-Length).
1. Return the result of [=converted to an IDL value|converting=] |jsTransferred| to an IDL
value of type {{ArrayBuffer}}.

Expand Down