Skip to content

Commit 8a3e8cb

Browse files
Fix conversions.ArrayBuffer with allowShared not accepting a SharedArrayBuffer
1 parent ec19d05 commit 8a3e8cb

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,13 @@ function isArrayBufferDetached(value) {
338338

339339
exports.ArrayBuffer = (value, options = {}) => {
340340
if (!isNonSharedArrayBuffer(value)) {
341-
if (options.allowShared && !isSharedArrayBuffer(value)) {
342-
throw makeException(TypeError, "is not an ArrayBuffer or SharedArrayBuffer", options);
341+
if (options.allowShared) {
342+
if (!isSharedArrayBuffer(value)) {
343+
throw makeException(TypeError, "is not an ArrayBuffer or SharedArrayBuffer", options);
344+
}
345+
} else {
346+
throw makeException(TypeError, "is not an ArrayBuffer", options);
343347
}
344-
throw makeException(TypeError, "is not an ArrayBuffer", options);
345348
}
346349
if (isArrayBufferDetached(value)) {
347350
throw makeException(TypeError, "is a detached ArrayBuffer", options);

test/buffer-source.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ for (const type of bufferSourceConstructors) {
211211
const allowSharedSUT = (v, opts) => conversions[typeName](v, { ...opts, allowShared: true });
212212

213213
for (const { label, creator, typeName: innerTypeName, isDetached, isForged } of bufferSourceCreators) {
214-
const testFunction = innerTypeName === typeName && !isDetached && !isForged ? testOk : testNotOk;
214+
const testFunction = (
215+
innerTypeName === typeName || (innerTypeName === "SharedArrayBuffer" && typeName === "ArrayBuffer")
216+
) && !isDetached && !isForged ?
217+
testOk :
218+
testNotOk;
215219
testFunction(label, allowSharedSUT, creator);
216220
}
217221

0 commit comments

Comments
 (0)