@@ -355,9 +355,9 @@ public class JavaScriptEnvironment: ComponentBase {
355355 registerObjectGroup ( . jsSharedArrayBuffers)
356356 for variant in [ " Uint8Array " , " Int8Array " , " Uint16Array " , " Int16Array " , " Uint32Array " , " Int32Array " , " Float16Array " , " Float32Array " , " Float64Array " , " Uint8ClampedArray " , " BigInt64Array " , " BigUint64Array " ] {
357357 registerObjectGroup ( . jsTypedArrays( variant) )
358+ registerObjectGroup ( . jsTypedArrayPrototype( variant) )
359+ registerObjectGroup ( . jsTypedArrayConstructor( variant) )
358360 }
359- registerObjectGroup ( . jsUint8ArrayConstructor)
360- registerObjectGroup ( . jsUint8ArrayPrototype)
361361 registerObjectGroup ( . jsDataViews)
362362 registerObjectGroup ( . jsDataViewPrototype)
363363 registerObjectGroup ( . jsDataViewConstructor)
@@ -591,11 +591,9 @@ public class JavaScriptEnvironment: ComponentBase {
591591 registerBuiltin ( " AggregateError " , ofType: . functionAndConstructor( [ . plain( . iterable) , . opt( . string) , . opt( . object( ) ) ] => . jsError( " AggregateError " ) ) )
592592 registerBuiltin ( " ArrayBuffer " , ofType: . jsArrayBufferConstructor)
593593 registerBuiltin ( " SharedArrayBuffer " , ofType: . jsSharedArrayBufferConstructor)
594- // Uint8Array handled below.
595- for variant in [ " Int8Array " , " Uint16Array " , " Int16Array " , " Uint32Array " , " Int32Array " , " Float16Array " , " Float32Array " , " Float64Array " , " Uint8ClampedArray " , " BigInt64Array " , " BigUint64Array " ] {
594+ for variant in [ " Uint8Array " , " Int8Array " , " Uint16Array " , " Int16Array " , " Uint32Array " , " Int32Array " , " Float16Array " , " Float32Array " , " Float64Array " , " Uint8ClampedArray " , " BigInt64Array " , " BigUint64Array " ] {
596595 registerBuiltin ( variant, ofType: . jsTypedArrayConstructor( variant) )
597596 }
598- registerBuiltin ( " Uint8Array " , ofType: . jsUint8ArrayConstructor)
599597 registerBuiltin ( " DataView " , ofType: . jsDataViewConstructor)
600598 registerBuiltin ( " Date " , ofType: . jsDateConstructor)
601599 registerBuiltin ( " Promise " , ofType: . jsPromiseConstructor)
@@ -1093,7 +1091,7 @@ public extension ILType {
10931091 /// Type of a JavaScript TypedArray object of the given variant.
10941092 static func jsTypedArray( _ variant: String ) -> ILType {
10951093 let extraMethods = variant == " Uint8Array " ? [ " setFromBase64 " , " setFromHex " , " toBase64 " , " toHex " ] : [ ]
1096- return . iterable + . object( ofGroup: variant, withProperties: [ " buffer " , " byteOffset " , " byteLength " , " length " ] , withMethods: [ " at " , " copyWithin " , " fill " , " find " , " findIndex " , " findLast " , " findLastIndex " , " reverse " , " slice " , " sort " , " includes " , " indexOf " , " keys " , " entries " , " forEach " , " filter " , " map " , " every " , " set " , " some " , " subarray " , " reduce " , " reduceRight " , " join " , " lastIndexOf " , " values " , " toLocaleString " , " toString " , " toReversed " , " toSorted " , " with " ]
1094+ return . iterable + . object( ofGroup: variant, withProperties: [ " BYTES_PER_ELEMENT " , " buffer " , " byteOffset " , " byteLength " , " length " ] , withMethods: [ " at " , " copyWithin " , " fill " , " find " , " findIndex " , " findLast " , " findLastIndex " , " reverse " , " slice " , " sort " , " includes " , " indexOf " , " keys " , " entries " , " forEach " , " filter " , " map " , " every " , " set " , " some " , " subarray " , " reduce " , " reduceRight " , " join " , " lastIndexOf " , " values " , " toLocaleString " , " toString " , " toReversed " , " toSorted " , " with " ]
10971095 + extraMethods)
10981096 }
10991097
@@ -1151,13 +1149,15 @@ public extension ILType {
11511149
11521150 /// Type of a JavaScript TypedArray constructor builtin.
11531151 static func jsTypedArrayConstructor( _ variant: String ) -> ILType {
1152+ let methods = variant == " Uint8Array " ? [ " fromBase64 " , " fromHex " ] : [ ]
11541153 // TODO Also allow SharedArrayBuffers for first argument
11551154 return . constructor( [ . opt( . integer | . jsArrayBuffer) , . opt( . integer) , . opt( . integer) ] => . jsTypedArray( variant) )
1155+ + . object(
1156+ ofGroup: " \( variant) Constructor " ,
1157+ withProperties: [ " prototype " , " BYTES_PER_ELEMENT " ] ,
1158+ withMethods: methods)
11561159 }
11571160
1158- static let jsUint8ArrayConstructor = jsTypedArrayConstructor ( " Uint8Array " )
1159- + . object( ofGroup: " Uint8ArrayConstructor " , withProperties: [ " prototype " ] , withMethods: [ " fromBase64 " , " fromHex " ] )
1160-
11611161 /// Type of the JavaScript DataView constructor builtin. (TODO Also allow SharedArrayBuffers for first argument)
11621162 static let jsDataViewConstructor = ILType . constructor ( [ . plain( . jsArrayBuffer) , . opt( . integer) , . opt( . integer) ] => . jsDataView) + . object( ofGroup: " DataViewConstructor " , withProperties: [ " prototype " ] )
11631163
@@ -1353,11 +1353,16 @@ public extension ObjectGroup {
13531353 static func createPrototypeObjectGroup(
13541354 _ receiver: ObjectGroup ,
13551355 constructor: ILType = . object( ) ,
1356- excludeProperties: [ String ] = [ ] ) -> ObjectGroup {
1356+ excludeProperties: [ String ] = [ ] ,
1357+ additionalProperties: [ String : ILType ] = [ : ] ) -> ObjectGroup {
13571358 let name = receiver. name + " .prototype "
13581359 var properties = Dictionary ( uniqueKeysWithValues: receiver. methods. map {
13591360 ( $0. 0 , ILType . unboundFunction ( $0. 1 . first, receiver: receiver. instanceType) ) } )
13601361
1362+ properties. merge ( additionalProperties) { _, _ in
1363+ fatalError ( " duplicate property " )
1364+ }
1365+
13611366 // Each <Builtin>.prototype has a constructor property.
13621367 // In general, the following should hold true:
13631368 // <Builtin>.prototype.constructor === <Builtin>;
@@ -1808,6 +1813,7 @@ public extension ObjectGroup {
18081813 name: variant,
18091814 instanceType: . jsTypedArray( variant) ,
18101815 properties: [
1816+ " BYTES_PER_ELEMENT " : . integer,
18111817 " buffer " : . jsArrayBuffer,
18121818 " byteLength " : . integer,
18131819 " byteOffset " : . integer,
@@ -1849,19 +1855,33 @@ public extension ObjectGroup {
18491855 )
18501856 }
18511857
1852- static let jsUint8ArrayPrototype = createPrototypeObjectGroup ( jsTypedArrays ( " Uint8Array " ) )
1858+ static func jsTypedArrayPrototype( _ variant: String ) -> ObjectGroup {
1859+ return createPrototypeObjectGroup (
1860+ jsTypedArrays ( variant) ,
1861+ constructor: . jsTypedArrayConstructor( variant) ,
1862+ additionalProperties: [
1863+ " BYTES_PER_ELEMENT " : . integer,
1864+ ] )
1865+ }
18531866
1854- static let jsUint8ArrayConstructor = ObjectGroup (
1855- name: " Uint8ArrayConstructor " ,
1856- instanceType: . jsUint8ArrayConstructor,
1857- properties: [
1858- " prototype " : jsUint8ArrayPrototype. instanceType,
1859- ] ,
1860- methods: [
1861- " fromBase64 " : [ . plain( . string) , . opt( OptionsBag . fromBase64Settings. group. instanceType) ] => . jsUint8Array,
1862- " fromHex " : [ . plain( . string) ] => . jsUint8Array,
1863- ]
1864- )
1867+ static func jsTypedArrayConstructor( _ variant: String ) -> ObjectGroup {
1868+ let methods : [ String : Signature ] = variant == " Uint8Array "
1869+ ? [
1870+ " fromBase64 " : [ . plain( . string) , . opt( OptionsBag . fromBase64Settings. group. instanceType) ] => . jsUint8Array,
1871+ " fromHex " : [ . plain( . string) ] => . jsUint8Array,
1872+ ]
1873+ : [ : ]
1874+ return ObjectGroup (
1875+ name: " \( variant) Constructor " ,
1876+ constructorPath: variant,
1877+ instanceType: . jsTypedArrayConstructor( variant) ,
1878+ properties: [
1879+ " prototype " : jsTypedArrayPrototype ( variant) . instanceType,
1880+ " BYTES_PER_ELEMENT " : . integer,
1881+ ] ,
1882+ methods: methods
1883+ )
1884+ }
18651885
18661886 /// ObjectGroup modelling JavaScript DataView objects
18671887 static let jsDataViews = ObjectGroup (
0 commit comments