In the web specification, an ArrayBufferView is explicitly a TypedArray/DataView that views an ArrayBuffer. Unless marked as AllowShared, an ArrayBufferView cannot be backed by a SharedArrayBuffer, nor can a BufferSource be a SharedArrayBuffer itself (whatwg/webidl#353), and compliant implementations will consider these invalid. This impacts many APIs that interact with byte sources.
The compliance with this in Node.js's various web API implementations is really hit-and-miss, and there's no indication that any divergence is deliberate. (WPT does not cover these cases.)
| API |
component |
compliance |
| Fetch |
BodyInit |
Partial. β
SharedArrayBuffers are rejected as invalid sources. β Views on SharedArrayBuffers are accepted, and result in the source being copied into a new SharedArrayBuffer internally. |
| WebSockets |
WebSocket#send() |
Partial. β
The data parameter rejects SharedArrayBuffers. β Views on SharedArrayBuffers are accepted. |
| File |
BlobPart |
β Both SharedArrayBuffers and views on SharedArrayBuffers are accepted as valid sources. |
| Streams |
ReadableStreamBYOBReader#read() |
β The view argument accepts views on SharedArrayBuffers. This will result in delayed errors, as the underlying SharedArrayBuffer cannot be transferred. |
ReadableByteStreamController#enqueue() |
β The chunk argument accepts views on SharedArrayBuffers. |
| Compression Streams |
CompressionStream and DecompressionStream chunk type |
β Does not accept ArrayBuffers at all, as the webstream wraps an underlying Duplex. (#43433) β Accepts views over SharedArrayBuffers. |
| Encoding |
TextDecoder#decode() |
β
The API specifies AllowSharedBufferSource. |
| Web Cryptography |
data parameters |
β
Validates input to be an ArrayBuffer or non-shared ArrayBufferView. |
internal/crypto/webidl already defines compatible validators for non-shared BufferSource and ArrayBufferView types. These should probably be moved into the internal/webidl namespace and used more widely across the various web API implementations.
cc: @nodejs/web-standards
In the web specification, an ArrayBufferView is explicitly a TypedArray/DataView that views an ArrayBuffer. Unless marked as AllowShared, an ArrayBufferView cannot be backed by a SharedArrayBuffer, nor can a BufferSource be a SharedArrayBuffer itself (whatwg/webidl#353), and compliant implementations will consider these invalid. This impacts many APIs that interact with byte sources.
The compliance with this in Node.js's various web API implementations is really hit-and-miss, and there's no indication that any divergence is deliberate. (WPT does not cover these cases.)
BodyInitβ SharedArrayBuffers are rejected as invalid sources.
β Views on SharedArrayBuffers are accepted, and result in the source being copied into a new SharedArrayBuffer internally.
WebSocket#send()β The
dataparameter rejects SharedArrayBuffers.β Views on SharedArrayBuffers are accepted.
BlobPartReadableStreamBYOBReader#read()viewargument accepts views on SharedArrayBuffers.This will result in delayed errors, as the underlying SharedArrayBuffer cannot be transferred.
ReadableByteStreamController#enqueue()chunkargument accepts views on SharedArrayBuffers.CompressionStreamandDecompressionStreamchunk typeβ Accepts views over SharedArrayBuffers.
TextDecoder#decode()dataparametersinternal/crypto/webidlalready defines compatible validators for non-shared BufferSource and ArrayBufferView types. These should probably be moved into theinternal/webidlnamespace and used more widely across the various web API implementations.cc: @nodejs/web-standards