- From: Mattias Buelens <notifications@github.com>
- Date: Mon, 24 Nov 2025 01:35:01 -0800
- To: whatwg/webidl <webidl@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/webidl/pull/1529/review/3499182121@github.com>
@MattiasBuelens commented on this pull request.
Quick self-review.
> <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=]:
+ 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|).
[TypedArrayByteLength](https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-typedarraybytelength) asserts that [IsTypedArrayOutOfBounds(taRecord)](https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-istypedarrayoutofbounds) is false, which we didn't explicitly check. We should check for that, to align with [%TypedArray%.prototype.byteLength](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-get-%typedarray%.prototype.bytelength).
```suggestion
1. If [$IsTypedArrayOutOfBounds$](|taRecord|) is true, return 0.
1. Return [$TypedArrayByteLength$](|taRecord|).
```
> + 1. Otherwise, if [$IsSharedArrayBuffer$](|jsBufferSource|) is true:
+ 1. [=/Assert=]: |jsBufferSource| is a {{SharedArrayBuffer}}.
+ 1. Return [$ArrayBufferByteLength$](|jsBufferSource|, Seq-Cst).
+ 1. Otherwise:
+ 1. [=/Assert=]: |jsBufferSource| is an {{ArrayBuffer}}.
+ 1. Return |jsBufferSource|.\[[ArrayBufferByteLength]].
[ArrayBufferByteLength](https://tc39.es/ecma262/multipage/structured-data.html#sec-arraybufferbytelength) supports both `ArrayBuffer` and `SharedArrayBuffer`, so we can combine these steps.
```suggestion
1. Otherwise:
1. [=/Assert=]: |jsBufferSource| is an {{ArrayBuffer}} or a {{SharedArrayBuffer}}.
1. Return [$ArrayBufferByteLength$](|jsBufferSource|, Seq-Cst).
```
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1529#pullrequestreview-3499182121
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/webidl/pull/1529/review/3499182121@github.com>
Received on Monday, 24 November 2025 09:35:07 UTC