5
5
import _CJavaScriptKit
6
6
7
7
public protocol TypedArrayElement : JSValueConvertible , JSValueConstructible {
8
- static var typedArrayKind : JavaScriptTypedArrayKind { get }
9
8
static var typedArrayClass : JSFunction { get }
10
9
}
11
10
@@ -58,7 +57,7 @@ public class JSTypedArray<Element>: JSValueConvertible, ExpressibleByArrayLitera
58
57
public convenience init ( _ array: [ Element ] ) {
59
58
var resultObj = JavaScriptObjectRef ( )
60
59
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)
62
61
}
63
62
self . init ( unsafe: JSObject ( id: resultObj) )
64
63
}
@@ -83,67 +82,49 @@ func valueForBitWidth<T>(typeName: String, bitWidth: Int, when32: T) -> T {
83
82
}
84
83
85
84
extension Int : TypedArrayElement {
86
- public static var typedArrayClass : JSFunction {
85
+ public static var typedArrayClass : JSFunction =
87
86
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
- }
92
87
}
93
88
extension UInt : TypedArrayElement {
94
- public static var typedArrayClass : JSFunction {
89
+ public static var typedArrayClass : JSFunction =
95
90
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
- }
100
91
}
101
92
102
93
// MARK: - Concrete TypedArray classes
103
94
104
95
extension 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!
107
97
}
108
98
extension 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!
111
100
}
112
101
// TODO: Support Uint8ClampedArray?
113
102
114
103
extension 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!
117
105
}
118
106
extension 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!
121
108
}
122
109
123
110
extension 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!
126
112
}
127
113
extension 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!
130
115
}
131
116
132
117
// FIXME: Support passing BigInts across the bridge
133
118
//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!
136
120
//}
137
121
//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!
140
123
//}
141
124
142
125
extension 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!
145
127
}
146
128
extension 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!
149
130
}
0 commit comments