Skip to content

Commit 4c7ea17

Browse files
Unlock JSTypedArray for Embedded Swift
1 parent fe6d2e5 commit 4c7ea17

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Diff for: Sources/JavaScriptKit/BasicObjects/JSTypedArray.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
//
22
// Created by Manuel Burghard. Licensed unter MIT.
33
//
4-
#if !hasFeature(Embedded)
54
import _CJavaScriptKit
65

76
/// 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, ConstructibleFromJSValue = Self
99
/// The constructor function for the TypedArray class for this particular kind of number
1010
static var typedArrayClass: JSFunction { get }
1111
}
1212

1313
/// A wrapper around all [JavaScript `TypedArray`
1414
/// classes](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
1515
/// 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 }
1819
public var jsObject: JSObject
1920

2021
public subscript(_ index: Int) -> Element {
@@ -176,13 +177,6 @@ extension UInt8: TypedArrayElement {
176177
public static var typedArrayClass: JSFunction { JSObject.global.Uint8Array.function! }
177178
}
178179

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-
186180
extension Int16: TypedArrayElement {
187181
public static var typedArrayClass: JSFunction { JSObject.global.Int16Array.function! }
188182
}
@@ -206,4 +200,10 @@ extension Float32: TypedArrayElement {
206200
extension Float64: TypedArrayElement {
207201
public static var typedArrayClass: JSFunction { JSObject.global.Float64Array.function! }
208202
}
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

Comments
 (0)