@@ -9,40 +9,24 @@ public protocol TypedArrayElement: JSValueConvertible, JSValueConstructible {
9
9
static var typedArrayClass : JSFunction { get }
10
10
}
11
11
12
- public class JSTypedArray < Element> : JSValueConvertible , ExpressibleByArrayLiteral where Element: TypedArrayElement {
13
- let ref : JSObject
14
- public func jsValue( ) -> JSValue {
15
- . object( ref)
16
- }
17
-
12
+ public class JSTypedArray < Element> : JSBridgedClass , ExpressibleByArrayLiteral where Element: TypedArrayElement {
13
+ public static var classRef : JSFunction { Element . typedArrayClass }
14
+ public var objectRef : JSObject
18
15
public subscript( _ index: Int ) -> Element {
19
16
get {
20
- return Element . construct ( from: getJSValue ( this : ref , index: Int32 ( index ) ) ) !
17
+ return Element . construct ( from: objectRef [ index] ) !
21
18
}
22
19
set {
23
- setJSValue ( this : ref , index: Int32 ( index ) , value : newValue. jsValue ( ) )
20
+ self . objectRef [ index] = newValue. jsValue ( )
24
21
}
25
22
}
26
23
27
- // This private initializer assumes that the passed object is TypedArray
28
- private init ( unsafe object: JSObject ) {
29
- self . ref = object
30
- }
31
-
32
- public init ? ( _ object: JSObject ) {
33
- guard object. isInstanceOf ( Element . typedArrayClass) else { return nil }
34
- self . ref = object
35
- }
36
-
37
- public convenience init ( length: Int ) {
38
- let jsObject = Element . typedArrayClass. new ( length)
39
- self . init ( unsafe: jsObject)
24
+ public init ( length: Int ) {
25
+ objectRef = Element . typedArrayClass. new ( length)
40
26
}
41
27
42
- public init ? ( objectRef jsObject: JSObjectRef ) {
43
- guard jsObject. isInstanceOf ( Element . typedArrayClass) else { return nil }
44
- _retain ( jsObject. id)
45
- super. init ( id: jsObject. id)
28
+ required public init ( withCompatibleObject jsObject: JSObject ) {
29
+ objectRef = jsObject
46
30
}
47
31
48
32
required public convenience init ( arrayLiteral elements: Element ... ) {
@@ -54,7 +38,7 @@ public class JSTypedArray<Element>: JSValueConvertible, ExpressibleByArrayLitera
54
38
array. withUnsafeBufferPointer { ptr in
55
39
_create_typed_array ( Element . typedArrayKind, ptr. baseAddress!, Int32 ( array. count) , & resultObj)
56
40
}
57
- self . init ( unsafe : JSObject ( id: resultObj) )
41
+ self . init ( withCompatibleObject : JSObject ( id: resultObj) )
58
42
}
59
43
60
44
public convenience init ( _ stride: StrideTo < Element > ) where Element: Strideable {
0 commit comments