@@ -338,9 +338,6 @@ function isArrayBufferDetached(value) {
338
338
339
339
exports . ArrayBuffer = ( value , options = { } ) => {
340
340
if ( ! isNonSharedArrayBuffer ( value ) ) {
341
- if ( options . allowShared && ! isSharedArrayBuffer ( value ) ) {
342
- throw makeException ( TypeError , "is not an ArrayBuffer or SharedArrayBuffer" , options ) ;
343
- }
344
341
throw makeException ( TypeError , "is not an ArrayBuffer" , options ) ;
345
342
}
346
343
if ( isArrayBufferDetached ( value ) ) {
@@ -350,6 +347,17 @@ exports.ArrayBuffer = (value, options = {}) => {
350
347
return value ;
351
348
} ;
352
349
350
+ exports . SharedArrayBuffer = ( value , options = { } ) => {
351
+ if ( ! isSharedArrayBuffer ( value ) ) {
352
+ throw makeException ( TypeError , "is not a SharedArrayBuffer" , options ) ;
353
+ }
354
+ if ( isArrayBufferDetached ( value ) ) {
355
+ throw makeException ( TypeError , "is a detached SharedArrayBuffer" , options ) ;
356
+ }
357
+
358
+ return value ;
359
+ } ;
360
+
353
361
const dvByteLengthGetter =
354
362
Object . getOwnPropertyDescriptor ( DataView . prototype , "byteLength" ) . get ;
355
363
exports . DataView = ( value , options = { } ) => {
@@ -358,15 +366,7 @@ exports.DataView = (value, options = {}) => {
358
366
} catch ( e ) {
359
367
throw makeException ( TypeError , "is not a DataView" , options ) ;
360
368
}
361
-
362
- if ( ! options . allowShared && isSharedArrayBuffer ( value . buffer ) ) {
363
- throw makeException ( TypeError , "is backed by a SharedArrayBuffer, which is not allowed" , options ) ;
364
- }
365
- if ( isArrayBufferDetached ( value . buffer ) ) {
366
- throw makeException ( TypeError , "is backed by a detached ArrayBuffer" , options ) ;
367
- }
368
-
369
- return value ;
369
+ return exports . ArrayBufferView ( value , options ) ;
370
370
} ;
371
371
372
372
// Returns the unforgeable `TypedArray` constructor name or `undefined`,
@@ -394,14 +394,7 @@ const typedArrayNameGetter = Object.getOwnPropertyDescriptor(
394
394
if ( ! ArrayBuffer . isView ( value ) || typedArrayNameGetter . call ( value ) !== name ) {
395
395
throw makeException ( TypeError , `is not ${ article } ${ name } object` , options ) ;
396
396
}
397
- if ( ! options . allowShared && isSharedArrayBuffer ( value . buffer ) ) {
398
- throw makeException ( TypeError , "is a view on a SharedArrayBuffer, which is not allowed" , options ) ;
399
- }
400
- if ( isArrayBufferDetached ( value . buffer ) ) {
401
- throw makeException ( TypeError , "is a view on a detached ArrayBuffer" , options ) ;
402
- }
403
-
404
- return value ;
397
+ return exports . ArrayBufferView ( value , options ) ;
405
398
} ;
406
399
} ) ;
407
400
@@ -424,27 +417,20 @@ exports.ArrayBufferView = (value, options = {}) => {
424
417
425
418
exports . BufferSource = ( value , options = { } ) => {
426
419
if ( ArrayBuffer . isView ( value ) ) {
427
- if ( ! options . allowShared && isSharedArrayBuffer ( value . buffer ) ) {
428
- throw makeException ( TypeError , "is a view on a SharedArrayBuffer, which is not allowed" , options ) ;
429
- }
430
-
431
- if ( isArrayBufferDetached ( value . buffer ) ) {
432
- throw makeException ( TypeError , "is a view on a detached ArrayBuffer" , options ) ;
433
- }
434
- return value ;
420
+ return exports . ArrayBufferView ( value , options ) ;
435
421
}
436
422
437
- if ( ! options . allowShared && ! isNonSharedArrayBuffer ( value ) ) {
438
- throw makeException ( TypeError , "is not an ArrayBuffer or a view on one" , options ) ;
423
+ if ( isNonSharedArrayBuffer ( value ) ) {
424
+ return exports . ArrayBuffer ( value , options ) ;
425
+ } else if ( options . allowShared && isSharedArrayBuffer ( value ) ) {
426
+ return exports . SharedArrayBuffer ( value , options ) ;
439
427
}
440
- if ( options . allowShared && ! isSharedArrayBuffer ( value ) && ! isNonSharedArrayBuffer ( value ) ) {
428
+
429
+ if ( options . allowShared ) {
441
430
throw makeException ( TypeError , "is not an ArrayBuffer, SharedArrayBuffer, or a view on one" , options ) ;
431
+ } else {
432
+ throw makeException ( TypeError , "is not an ArrayBuffer or a view on one" , options ) ;
442
433
}
443
- if ( isArrayBufferDetached ( value ) ) {
444
- throw makeException ( TypeError , "is a detached ArrayBuffer" , options ) ;
445
- }
446
-
447
- return value ;
448
434
} ;
449
435
450
436
exports . DOMTimeStamp = exports [ "unsigned long long" ] ;
0 commit comments