Skip to content

Commit 16a70e9

Browse files
authored
fix(assert,streams): handle SharedArrayBuffer being disabled in some browser context (#6856)
Per MDN spec SharedArrayBuffer require secure context and cross-origin isolated. When these contextes are not given then equal and new Buffer fail when called in the Web.
1 parent 4595316 commit 16a70e9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

assert/equal.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ export function equal(a: unknown, b: unknown): boolean {
117117
if (a instanceof TypedArray) {
118118
return compareTypedArrays(a as TypedArray, b as TypedArray);
119119
}
120-
if (a instanceof ArrayBuffer || a instanceof SharedArrayBuffer) {
120+
if (
121+
a instanceof ArrayBuffer ||
122+
(globalThis.SharedArrayBuffer && a instanceof SharedArrayBuffer)
123+
) {
121124
return compareTypedArrays(
122125
new Uint8Array(a),
123126
new Uint8Array(b as ArrayBuffer | SharedArrayBuffer),

streams/buffer.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,8 @@ export class Buffer {
135135
constructor(ab?: ArrayBufferLike | ArrayLike<number>) {
136136
if (ab === undefined) {
137137
this.#buf = new Uint8Array(0);
138-
} else if (ab instanceof SharedArrayBuffer) {
139-
// Note: This is necessary to avoid type error
140-
this.#buf = new Uint8Array(ab);
141138
} else {
142-
this.#buf = new Uint8Array(ab);
139+
this.#buf = new Uint8Array(ab as ArrayBuffer | SharedArrayBuffer);
143140
}
144141
}
145142

0 commit comments

Comments
 (0)