* Convert a Uint8Array to its backing ArrayBuffer, slicing if necessary. * Handles both ArrayBuffer and SharedArrayBuffer backing stores. * @param {Uint8Array} data * @returns {ArrayBuffer|SharedArrayBuffer}
(data)
| 161 | * @returns {ArrayBuffer|SharedArrayBuffer} |
| 162 | */ |
| 163 | function toArrayBuffer(data) { |
| 164 | const byteOffset = TypedArrayPrototypeGetByteOffset(data); |
| 165 | const byteLength = TypedArrayPrototypeGetByteLength(data); |
| 166 | const buffer = TypedArrayPrototypeGetBuffer(data); |
| 167 | // SharedArrayBuffer is not available in primordials, so use |
| 168 | // direct property access for its byteLength and slice. |
| 169 | if (isSharedArrayBuffer(buffer)) { |
| 170 | if (byteOffset === 0 && byteLength === buffer.byteLength) { |
| 171 | return buffer; |
| 172 | } |
| 173 | return buffer.slice(byteOffset, byteOffset + byteLength); |
| 174 | } |
| 175 | if (byteOffset === 0 && |
| 176 | byteLength === ArrayBufferPrototypeGetByteLength(buffer)) { |
| 177 | return buffer; |
| 178 | } |
| 179 | return ArrayBufferPrototypeSlice(buffer, byteOffset, |
| 180 | byteOffset + byteLength); |
| 181 | } |
| 182 | |
| 183 | // ============================================================================= |
| 184 | // Shared option validation |
no test coverage detected
searching dependent graphs…