@@ -160,7 +160,7 @@ webidl.util.TypeValueToString = function (o) {
160160webidl . util . markAsUncloneable = markAsUncloneable || ( ( ) => { } )
161161
162162// https://webidl.spec.whatwg.org/#abstract-opdef-converttoint
163- webidl . util . ConvertToInt = function ( V , bitLength , signedness , opts ) {
163+ webidl . util . ConvertToInt = function ( V , bitLength , signedness , flags ) {
164164 let upperBound
165165 let lowerBound
166166
@@ -204,7 +204,7 @@ webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
204204
205205 // 6. If the conversion is to an IDL type associated
206206 // with the [EnforceRange] extended attribute, then:
207- if ( opts ?. enforceRange === true ) {
207+ if ( webidl . util . HasFlag ( flags , webidl . attributes . EnforceRange ) ) {
208208 // 1. If x is NaN, +∞, or −∞, then throw a TypeError.
209209 if (
210210 Number . isNaN ( x ) ||
@@ -236,7 +236,7 @@ webidl.util.ConvertToInt = function (V, bitLength, signedness, opts) {
236236 // 7. If x is not NaN and the conversion is to an IDL
237237 // type associated with the [Clamp] extended
238238 // attribute, then:
239- if ( ! Number . isNaN ( x ) && opts ?. clamp === true ) {
239+ if ( ! Number . isNaN ( x ) && webidl . util . HasFlag ( flags , webidl . attributes . Clamp ) ) {
240240 // 1. Set x to min(max(x, lowerBound), upperBound).
241241 x = Math . min ( Math . max ( x , lowerBound ) , upperBound )
242242
@@ -325,6 +325,10 @@ webidl.util.IsResizableArrayBuffer = function (V) {
325325 } )
326326}
327327
328+ webidl . util . HasFlag = function ( flags , attributes ) {
329+ return typeof flags === 'number' && ( flags & attributes ) === attributes
330+ }
331+
328332// https://webidl.spec.whatwg.org/#es-sequence
329333webidl . sequenceConverter = function ( converter ) {
330334 return ( V , prefix , argument , Iterable ) => {
@@ -537,12 +541,12 @@ webidl.is.BufferSource = function (V) {
537541}
538542
539543// https://webidl.spec.whatwg.org/#es-DOMString
540- webidl . converters . DOMString = function ( V , prefix , argument , opts ) {
544+ webidl . converters . DOMString = function ( V , prefix , argument , flags ) {
541545 // 1. If V is null and the conversion is to an IDL type
542546 // associated with the [LegacyNullToEmptyString]
543547 // extended attribute, then return the DOMString value
544548 // that represents the empty string.
545- if ( V === null && opts ?. legacyNullToEmptyString ) {
549+ if ( V === null && webidl . util . HasFlag ( flags , webidl . attributes . LegacyNullToEmptyString ) ) {
546550 return ''
547551 }
548552
@@ -621,7 +625,7 @@ webidl.converters.any = function (V) {
621625// https://webidl.spec.whatwg.org/#es-long-long
622626webidl . converters [ 'long long' ] = function ( V , prefix , argument ) {
623627 // 1. Let x be ? ConvertToInt(V, 64, "signed").
624- const x = webidl . util . ConvertToInt ( V , 64 , 'signed' , undefined , prefix , argument )
628+ const x = webidl . util . ConvertToInt ( V , 64 , 'signed' , 0 , prefix , argument )
625629
626630 // 2. Return the IDL long long value that represents
627631 // the same numeric value as x.
@@ -631,7 +635,7 @@ webidl.converters['long long'] = function (V, prefix, argument) {
631635// https://webidl.spec.whatwg.org/#es-unsigned-long-long
632636webidl . converters [ 'unsigned long long' ] = function ( V , prefix , argument ) {
633637 // 1. Let x be ? ConvertToInt(V, 64, "unsigned").
634- const x = webidl . util . ConvertToInt ( V , 64 , 'unsigned' , undefined , prefix , argument )
638+ const x = webidl . util . ConvertToInt ( V , 64 , 'unsigned' , 0 , prefix , argument )
635639
636640 // 2. Return the IDL unsigned long long value that
637641 // represents the same numeric value as x.
@@ -641,25 +645,25 @@ webidl.converters['unsigned long long'] = function (V, prefix, argument) {
641645// https://webidl.spec.whatwg.org/#es-unsigned-long
642646webidl . converters [ 'unsigned long' ] = function ( V , prefix , argument ) {
643647 // 1. Let x be ? ConvertToInt(V, 32, "unsigned").
644- const x = webidl . util . ConvertToInt ( V , 32 , 'unsigned' , undefined , prefix , argument )
648+ const x = webidl . util . ConvertToInt ( V , 32 , 'unsigned' , 0 , prefix , argument )
645649
646650 // 2. Return the IDL unsigned long value that
647651 // represents the same numeric value as x.
648652 return x
649653}
650654
651655// https://webidl.spec.whatwg.org/#es-unsigned-short
652- webidl . converters [ 'unsigned short' ] = function ( V , prefix , argument , opts ) {
656+ webidl . converters [ 'unsigned short' ] = function ( V , prefix , argument , flags ) {
653657 // 1. Let x be ? ConvertToInt(V, 16, "unsigned").
654- const x = webidl . util . ConvertToInt ( V , 16 , 'unsigned' , opts , prefix , argument )
658+ const x = webidl . util . ConvertToInt ( V , 16 , 'unsigned' , flags , prefix , argument )
655659
656660 // 2. Return the IDL unsigned short value that represents
657661 // the same numeric value as x.
658662 return x
659663}
660664
661665// https://webidl.spec.whatwg.org/#idl-ArrayBuffer
662- webidl . converters . ArrayBuffer = function ( V , prefix , argument , opts ) {
666+ webidl . converters . ArrayBuffer = function ( V , prefix , argument , flags ) {
663667 // 1. If V is not an Object, or V does not have an
664668 // [[ArrayBufferData]] internal slot, then throw a
665669 // TypeError.
@@ -681,7 +685,7 @@ webidl.converters.ArrayBuffer = function (V, prefix, argument, opts) {
681685 // with the [AllowResizable] extended attribute, and
682686 // IsResizableArrayBuffer(V) is true, then throw a
683687 // TypeError.
684- if ( ! opts ?. allowResizable && webidl . util . IsResizableArrayBuffer ( V ) ) {
688+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowResizable ) && webidl . util . IsResizableArrayBuffer ( V ) ) {
685689 throw webidl . errors . exception ( {
686690 header : prefix ,
687691 message : `${ argument } cannot be a resizable ArrayBuffer.`
@@ -694,7 +698,7 @@ webidl.converters.ArrayBuffer = function (V, prefix, argument, opts) {
694698}
695699
696700// https://webidl.spec.whatwg.org/#idl-SharedArrayBuffer
697- webidl . converters . SharedArrayBuffer = function ( V , prefix , argument , opts ) {
701+ webidl . converters . SharedArrayBuffer = function ( V , prefix , argument , flags ) {
698702 // 1. If V is not an Object, or V does not have an
699703 // [[ArrayBufferData]] internal slot, then throw a
700704 // TypeError.
@@ -716,7 +720,7 @@ webidl.converters.SharedArrayBuffer = function (V, prefix, argument, opts) {
716720 // with the [AllowResizable] extended attribute, and
717721 // IsResizableArrayBuffer(V) is true, then throw a
718722 // TypeError.
719- if ( ! opts ?. allowResizable && webidl . util . IsResizableArrayBuffer ( V ) ) {
723+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowResizable ) && webidl . util . IsResizableArrayBuffer ( V ) ) {
720724 throw webidl . errors . exception ( {
721725 header : prefix ,
722726 message : `${ argument } cannot be a resizable SharedArrayBuffer.`
@@ -729,7 +733,7 @@ webidl.converters.SharedArrayBuffer = function (V, prefix, argument, opts) {
729733}
730734
731735// https://webidl.spec.whatwg.org/#dfn-typed-array-type
732- webidl . converters . TypedArray = function ( V , T , prefix , argument , opts ) {
736+ webidl . converters . TypedArray = function ( V , T , prefix , argument , flags ) {
733737 // 1. Let T be the IDL type V is being converted to.
734738
735739 // 2. If Type(V) is not Object, or V does not have a
@@ -751,7 +755,7 @@ webidl.converters.TypedArray = function (V, T, prefix, argument, opts) {
751755 // with the [AllowShared] extended attribute, and
752756 // IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is
753757 // true, then throw a TypeError.
754- if ( ! opts ?. allowShared && types . isSharedArrayBuffer ( V . buffer ) ) {
758+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowShared ) && types . isSharedArrayBuffer ( V . buffer ) ) {
755759 throw webidl . errors . exception ( {
756760 header : prefix ,
757761 message : `${ argument } cannot be a view on a shared array buffer.`
@@ -762,7 +766,7 @@ webidl.converters.TypedArray = function (V, T, prefix, argument, opts) {
762766 // with the [AllowResizable] extended attribute, and
763767 // IsResizableArrayBuffer(V.[[ViewedArrayBuffer]]) is
764768 // true, then throw a TypeError.
765- if ( ! opts ?. allowResizable && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
769+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowResizable ) && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
766770 throw webidl . errors . exception ( {
767771 header : prefix ,
768772 message : `${ argument } cannot be a view on a resizable array buffer.`
@@ -775,7 +779,7 @@ webidl.converters.TypedArray = function (V, T, prefix, argument, opts) {
775779}
776780
777781// https://webidl.spec.whatwg.org/#idl-DataView
778- webidl . converters . DataView = function ( V , prefix , argument , opts ) {
782+ webidl . converters . DataView = function ( V , prefix , argument , flags ) {
779783 // 1. If Type(V) is not Object, or V does not have a
780784 // [[DataView]] internal slot, then throw a TypeError.
781785 if ( webidl . util . Type ( V ) !== OBJECT || ! types . isDataView ( V ) ) {
@@ -790,7 +794,7 @@ webidl.converters.DataView = function (V, prefix, argument, opts) {
790794 // with the [AllowShared] extended attribute, and
791795 // IsSharedArrayBuffer(V.[[ViewedArrayBuffer]]) is true,
792796 // then throw a TypeError.
793- if ( ! opts ?. allowShared && types . isSharedArrayBuffer ( V . buffer ) ) {
797+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowShared ) && types . isSharedArrayBuffer ( V . buffer ) ) {
794798 throw webidl . errors . exception ( {
795799 header : prefix ,
796800 message : `${ argument } cannot be a view on a shared array buffer.`
@@ -801,7 +805,7 @@ webidl.converters.DataView = function (V, prefix, argument, opts) {
801805 // with the [AllowResizable] extended attribute, and
802806 // IsResizableArrayBuffer(V.[[ViewedArrayBuffer]]) is
803807 // true, then throw a TypeError.
804- if ( ! opts ?. allowResizable && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
808+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowResizable ) && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
805809 throw webidl . errors . exception ( {
806810 header : prefix ,
807811 message : `${ argument } cannot be a view on a resizable array buffer.`
@@ -814,7 +818,7 @@ webidl.converters.DataView = function (V, prefix, argument, opts) {
814818}
815819
816820// https://webidl.spec.whatwg.org/#ArrayBufferView
817- webidl . converters . ArrayBufferView = function ( V , prefix , argument , opts ) {
821+ webidl . converters . ArrayBufferView = function ( V , prefix , argument , flags ) {
818822 if (
819823 webidl . util . Type ( V ) !== OBJECT ||
820824 ! types . isArrayBufferView ( V )
@@ -826,14 +830,14 @@ webidl.converters.ArrayBufferView = function (V, prefix, argument, opts) {
826830 } )
827831 }
828832
829- if ( ! opts ?. allowShared && types . isSharedArrayBuffer ( V . buffer ) ) {
833+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowShared ) && types . isSharedArrayBuffer ( V . buffer ) ) {
830834 throw webidl . errors . exception ( {
831835 header : prefix ,
832836 message : `${ argument } cannot be a view on a shared array buffer.`
833837 } )
834838 }
835839
836- if ( ! opts ?. allowResizable && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
840+ if ( ! webidl . util . HasFlag ( flags , webidl . attributes . AllowResizable ) && webidl . util . IsResizableArrayBuffer ( V . buffer ) ) {
837841 throw webidl . errors . exception ( {
838842 header : prefix ,
839843 message : `${ argument } cannot be a view on a resizable array buffer.`
@@ -844,16 +848,15 @@ webidl.converters.ArrayBufferView = function (V, prefix, argument, opts) {
844848}
845849
846850// https://webidl.spec.whatwg.org/#BufferSource
847- webidl . converters . BufferSource = function ( V , prefix , argument , opts ) {
851+ webidl . converters . BufferSource = function ( V , prefix , argument , flags ) {
848852 if ( types . isArrayBuffer ( V ) ) {
849- return webidl . converters . ArrayBuffer ( V , prefix , argument , opts )
853+ return webidl . converters . ArrayBuffer ( V , prefix , argument , flags )
850854 }
851855
852856 if ( types . isArrayBufferView ( V ) ) {
853- return webidl . converters . ArrayBufferView ( V , prefix , argument , {
854- ...opts ,
855- allowShared : false
856- } )
857+ flags &= ~ webidl . attributes . AllowShared
858+
859+ return webidl . converters . ArrayBufferView ( V , prefix , argument , flags )
857860 }
858861
859862 // Make this explicit for easier debugging
@@ -872,20 +875,18 @@ webidl.converters.BufferSource = function (V, prefix, argument, opts) {
872875}
873876
874877// https://webidl.spec.whatwg.org/#AllowSharedBufferSource
875- webidl . converters . AllowSharedBufferSource = function ( V , prefix , argument , opts ) {
878+ webidl . converters . AllowSharedBufferSource = function ( V , prefix , argument , flags ) {
876879 if ( types . isArrayBuffer ( V ) ) {
877- return webidl . converters . ArrayBuffer ( V , prefix , argument , opts )
880+ return webidl . converters . ArrayBuffer ( V , prefix , argument , flags )
878881 }
879882
880883 if ( types . isSharedArrayBuffer ( V ) ) {
881- return webidl . converters . SharedArrayBuffer ( V , prefix , argument , opts )
884+ return webidl . converters . SharedArrayBuffer ( V , prefix , argument , flags )
882885 }
883886
884887 if ( types . isArrayBufferView ( V ) ) {
885- return webidl . converters . ArrayBufferView ( V , prefix , argument , {
886- ...opts ,
887- allowShared : true
888- } )
888+ flags |= webidl . attributes . AllowShared
889+ return webidl . converters . ArrayBufferView ( V , prefix , argument , flags )
889890 }
890891
891892 throw webidl . errors . conversionFailed ( {
@@ -935,6 +936,14 @@ webidl.converters.EventHandlerNonNull = function (V) {
935936 return ( ) => { }
936937}
937938
939+ webidl . attributes = {
940+ Clamp : 1 << 0 ,
941+ EnforceRange : 1 << 1 ,
942+ AllowShared : 1 << 2 ,
943+ AllowResizable : 1 << 3 ,
944+ LegacyNullToEmptyString : 1 << 4
945+ }
946+
938947module . exports = {
939948 webidl
940949}
0 commit comments