@@ -338,9 +338,6 @@ function isArrayBufferDetached(value) {
338338
339339exports . ArrayBuffer = ( value , options = { } ) => {
340340 if ( ! isNonSharedArrayBuffer ( value ) ) {
341- if ( options . allowShared && ! isSharedArrayBuffer ( value ) ) {
342- throw makeException ( TypeError , "is not an ArrayBuffer or SharedArrayBuffer" , options ) ;
343- }
344341 throw makeException ( TypeError , "is not an ArrayBuffer" , options ) ;
345342 }
346343 if ( isArrayBufferDetached ( value ) ) {
@@ -350,6 +347,17 @@ exports.ArrayBuffer = (value, options = {}) => {
350347 return value ;
351348} ;
352349
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+
353361const dvByteLengthGetter =
354362 Object . getOwnPropertyDescriptor ( DataView . prototype , "byteLength" ) . get ;
355363exports . DataView = ( value , options = { } ) => {
@@ -358,15 +366,7 @@ exports.DataView = (value, options = {}) => {
358366 } catch ( e ) {
359367 throw makeException ( TypeError , "is not a DataView" , options ) ;
360368 }
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 ) ;
370370} ;
371371
372372// Returns the unforgeable `TypedArray` constructor name or `undefined`,
@@ -394,14 +394,7 @@ const typedArrayNameGetter = Object.getOwnPropertyDescriptor(
394394 if ( ! ArrayBuffer . isView ( value ) || typedArrayNameGetter . call ( value ) !== name ) {
395395 throw makeException ( TypeError , `is not ${ article } ${ name } object` , options ) ;
396396 }
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 ) ;
405398 } ;
406399} ) ;
407400
@@ -424,27 +417,20 @@ exports.ArrayBufferView = (value, options = {}) => {
424417
425418exports . BufferSource = ( value , options = { } ) => {
426419 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 ) ;
435421 }
436422
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 ) ;
439427 }
440- if ( options . allowShared && ! isSharedArrayBuffer ( value ) && ! isNonSharedArrayBuffer ( value ) ) {
428+
429+ if ( options . allowShared ) {
441430 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 ) ;
442433 }
443- if ( isArrayBufferDetached ( value ) ) {
444- throw makeException ( TypeError , "is a detached ArrayBuffer" , options ) ;
445- }
446-
447- return value ;
448434} ;
449435
450436exports . DOMTimeStamp = exports [ "unsigned long long" ] ;
0 commit comments