1
1
//
2
2
// Created by Manuel Burghard. Licensed unter MIT.
3
3
//
4
- #if !hasFeature(Embedded)
5
4
import _CJavaScriptKit
6
5
7
6
/// A protocol that allows a Swift numeric type to be mapped to the JavaScript TypedArray that holds integers of its type
8
- public protocol TypedArrayElement : ConvertibleToJSValue , ConstructibleFromJSValue {
7
+ public protocol TypedArrayElement {
8
+ associatedtype Element : ConvertibleToJSValue , Construct ibleFromJSValue = Self
9
9
/// The constructor function for the TypedArray class for this particular kind of number
10
10
static var typedArrayClass : JSFunction { get }
11
11
}
12
12
13
13
/// A wrapper around all [JavaScript `TypedArray`
14
14
/// classes](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
15
15
/// that exposes their properties in a type-safe way.
16
- public class JSTypedArray < Element> : JSBridgedClass , ExpressibleByArrayLiteral where Element: TypedArrayElement {
17
- public class var constructor : JSFunction ? { Element . typedArrayClass }
16
+ public final class JSTypedArray < Traits> : JSBridgedClass , ExpressibleByArrayLiteral where Traits: TypedArrayElement {
17
+ public typealias Element = Traits . Element
18
+ public class var constructor : JSFunction ? { Traits . typedArrayClass }
18
19
public var jsObject : JSObject
19
20
20
21
public subscript( _ index: Int ) -> Element {
@@ -176,13 +177,6 @@ extension UInt8: TypedArrayElement {
176
177
public static var typedArrayClass : JSFunction { JSObject . global. Uint8Array. function! }
177
178
}
178
179
179
- /// A wrapper around [the JavaScript `Uint8ClampedArray`
180
- /// class](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
181
- /// that exposes its properties in a type-safe and Swifty way.
182
- public class JSUInt8ClampedArray : JSTypedArray < UInt8 > {
183
- override public class var constructor : JSFunction ? { JSObject . global. Uint8ClampedArray. function! }
184
- }
185
-
186
180
extension Int16 : TypedArrayElement {
187
181
public static var typedArrayClass : JSFunction { JSObject . global. Int16Array. function! }
188
182
}
@@ -206,4 +200,10 @@ extension Float32: TypedArrayElement {
206
200
extension Float64 : TypedArrayElement {
207
201
public static var typedArrayClass : JSFunction { JSObject . global. Float64Array. function! }
208
202
}
209
- #endif
203
+
204
+ public enum JSUInt8Clamped : TypedArrayElement {
205
+ public typealias Element = UInt8
206
+ public static var typedArrayClass : JSFunction { JSObject . global. Uint8ClampedArray. function! }
207
+ }
208
+
209
+ public typealias JSUInt8ClampedArray = JSTypedArray < JSUInt8Clamped >
0 commit comments