55import _CJavaScriptKit
66
77public protocol TypedArrayElement : JSValueConvertible , JSValueConstructible {
8- static var typedArrayKind : JavaScriptTypedArrayKind { get }
98 static var typedArrayClass : JSFunction { get }
109}
1110
@@ -58,7 +57,7 @@ public class JSTypedArray<Element>: JSValueConvertible, ExpressibleByArrayLitera
5857 public convenience init ( _ array: [ Element ] ) {
5958 var resultObj = JavaScriptObjectRef ( )
6059 array. withUnsafeBufferPointer { ptr in
61- _create_typed_array ( Element . typedArrayKind , ptr. baseAddress!, Int32 ( array. count) , & resultObj)
60+ _create_typed_array ( Element . typedArrayClass . id , ptr. baseAddress!, Int32 ( array. count) , & resultObj)
6261 }
6362 self . init ( unsafe: JSObject ( id: resultObj) )
6463 }
@@ -83,67 +82,49 @@ func valueForBitWidth<T>(typeName: String, bitWidth: Int, when32: T) -> T {
8382}
8483
8584extension Int : TypedArrayElement {
86- public static var typedArrayClass : JSFunction {
85+ public static var typedArrayClass : JSFunction =
8786 valueForBitWidth ( typeName: " Int " , bitWidth: Int . bitWidth, when32: JSObject . global. Int32Array) . function!
88- }
89- public static var typedArrayKind : JavaScriptTypedArrayKind {
90- valueForBitWidth ( typeName: " Int " , bitWidth: Int . bitWidth, when32: . int32)
91- }
9287}
9388extension UInt : TypedArrayElement {
94- public static var typedArrayClass : JSFunction {
89+ public static var typedArrayClass : JSFunction =
9590 valueForBitWidth ( typeName: " UInt " , bitWidth: Int . bitWidth, when32: JSObject . global. Uint32Array) . function!
96- }
97- public static var typedArrayKind : JavaScriptTypedArrayKind {
98- valueForBitWidth ( typeName: " UInt " , bitWidth: UInt . bitWidth, when32: . uint32)
99- }
10091}
10192
10293// MARK: - Concrete TypedArray classes
10394
10495extension Int8 : TypedArrayElement {
105- public static var typedArrayClass : JSFunction { JSObject . global. Int8Array. function! }
106- public static var typedArrayKind : JavaScriptTypedArrayKind { . int8 }
96+ public static var typedArrayClass = JSObject . global. Int8Array. function!
10797}
10898extension UInt8 : TypedArrayElement {
109- public static var typedArrayClass : JSFunction { JSObject . global. Uint8Array. function! }
110- public static var typedArrayKind : JavaScriptTypedArrayKind { . uint8 }
99+ public static var typedArrayClass = JSObject . global. Uint8Array. function!
111100}
112101// TODO: Support Uint8ClampedArray?
113102
114103extension Int16 : TypedArrayElement {
115- public static var typedArrayClass : JSFunction { JSObject . global. Int16Array. function! }
116- public static var typedArrayKind : JavaScriptTypedArrayKind { . int16 }
104+ public static var typedArrayClass = JSObject . global. Int16Array. function!
117105}
118106extension UInt16 : TypedArrayElement {
119- public static var typedArrayClass : JSFunction { JSObject . global. Uint16Array. function! }
120- public static var typedArrayKind : JavaScriptTypedArrayKind { . uint16 }
107+ public static var typedArrayClass = JSObject . global. Uint16Array. function!
121108}
122109
123110extension Int32 : TypedArrayElement {
124- public static var typedArrayClass : JSFunction { JSObject . global. Int32Array. function! }
125- public static var typedArrayKind : JavaScriptTypedArrayKind { . int32 }
111+ public static var typedArrayClass = JSObject . global. Int32Array. function!
126112}
127113extension UInt32 : TypedArrayElement {
128- public static var typedArrayClass : JSFunction { JSObject . global. Uint32Array. function! }
129- public static var typedArrayKind : JavaScriptTypedArrayKind { . uint32 }
114+ public static var typedArrayClass = JSObject . global. Uint32Array. function!
130115}
131116
132117// FIXME: Support passing BigInts across the bridge
133118//extension Int64: TypedArrayElement {
134- // public static var typedArrayClass: JSFunction { JSObject.global.BigInt64Array.function! }
135- // public static var type: JavaScriptTypedArrayKind { .bigInt64 }
119+ // public static var typedArrayClass = JSObject.global.BigInt64Array.function!
136120//}
137121//extension UInt64: TypedArrayElement {
138- // public static var typedArrayClass: JSFunction { JSObject.global.BigUint64Array.function! }
139- // public static var type: JavaScriptTypedArrayKind { .bigUint64 }
122+ // public static var typedArrayClass = JSObject.global.BigUint64Array.function!
140123//}
141124
142125extension Float32 : TypedArrayElement {
143- public static var typedArrayClass : JSFunction { JSObject . global. Float32Array. function! }
144- public static var typedArrayKind : JavaScriptTypedArrayKind { . float32 }
126+ public static var typedArrayClass = JSObject . global. Float32Array. function!
145127}
146128extension Float64 : TypedArrayElement {
147- public static var typedArrayClass : JSFunction { JSObject . global. Float64Array. function! }
148- public static var typedArrayKind : JavaScriptTypedArrayKind { . float64 }
129+ public static var typedArrayClass = JSObject . global. Float64Array. function!
149130}
0 commit comments