Skip to content

Commit 60b1777

Browse files
SamChou19815facebook-github-bot
authored andcommitted
Type structuredClone typed arrays as ArrayBuffer-backed
Summary: `cloneTypedArray` passes `value.buffer` to `cloneArrayBuffer(value: ArrayBuffer)`. With TypeScript's ES2024 `ArrayBuffer` definitions, `$TypedArray` (meaning `$TypedArray<ArrayBufferLike>`) has an `ArrayBufferLike` buffer, which is no longer an `ArrayBuffer`. Hermes, React Native's default engine, has no `SharedArrayBuffer`, and `cloneArrayBuffer` already treats its input and its `slice(0)` copy as an `ArrayBuffer`. This narrows `isTypedArray`'s refinement and `cloneTypedArray`'s parameter to `$TypedArray<ArrayBuffer>`. It is a type-only change. Changelog: [Internal] Differential Revision: D125721761
1 parent 11d5dd0 commit 60b1777

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎packages/react-native/src/private/webapis/structuredClone/structuredClone.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function cloneArrayBuffer(value: ArrayBuffer): ArrayBuffer {
308308
return result;
309309
}
310310

311-
function cloneTypedArray(value: $TypedArray): $TypedArray {
311+
function cloneTypedArray(value: $TypedArray<ArrayBuffer>): $TypedArray {
312312
const buffer = cloneArrayBuffer(value.buffer);
313313
const {byteOffset, length} = value;
314314

@@ -365,7 +365,9 @@ function defineEnumerableProperty(
365365
});
366366
}
367367

368-
declare function isTypedArray(value: unknown): implies value is $TypedArray;
368+
declare function isTypedArray(
369+
value: unknown,
370+
): implies value is $TypedArray<ArrayBuffer>;
369371
function isTypedArray(value: unknown): boolean {
370372
return ArrayBuffer.isView(value) && !(value instanceof DataView);
371373
}

0 commit comments

Comments
 (0)