1- public class JSArray {
2- static let classObject = JSObject . global. Array. function!
1+ public class JSArray : JSBridgedClass {
2+ public static let constructor = JSObject . global. Array. function!
33
44 static func isArray( _ object: JSObject ) -> Bool {
5- classObject . isArray!( object) . boolean!
5+ constructor . isArray!( object) . boolean!
66 }
77
8- let ref : JSObject
8+ public let jsObject : JSObject
99
10- public init ? ( _ ref: JSObject ) {
11- guard Self . isArray ( ref) else { return nil }
12- self . ref = ref
10+ public required convenience init ? ( from value: JSValue ) {
11+ guard let object = value. object else { return nil }
12+ self . init ( object)
13+ }
14+
15+ public convenience init ? ( _ jsObject: JSObject ) {
16+ guard Self . isArray ( jsObject) else { return nil }
17+ self . init ( withCompatibleObject: jsObject)
18+ }
19+ public required init ( withCompatibleObject jsObject: JSObject ) {
20+ self . jsObject = jsObject
1321 }
1422}
1523
1624extension JSArray : RandomAccessCollection {
1725 public typealias Element = JSValue
1826
1927 public func makeIterator( ) -> Iterator {
20- Iterator ( ref : ref )
28+ Iterator ( jsObject : jsObject )
2129 }
2230
2331 public class Iterator : IteratorProtocol {
24- let ref : JSObject
32+ let jsObject : JSObject
2533 var index = 0
26- init ( ref : JSObject ) {
27- self . ref = ref
34+ init ( jsObject : JSObject ) {
35+ self . jsObject = jsObject
2836 }
2937
3038 public func next( ) -> Element ? {
3139 let currentIndex = index
32- guard currentIndex < Int ( ref . length. number!) else {
40+ guard currentIndex < Int ( jsObject . length. number!) else {
3341 return nil
3442 }
3543 index += 1
36- guard ref . hasOwnProperty!( currentIndex) . boolean! else {
44+ guard jsObject . hasOwnProperty!( currentIndex) . boolean! else {
3745 return next ( )
3846 }
39- let value = ref [ currentIndex]
47+ let value = jsObject [ currentIndex]
4048 return value
4149 }
4250 }
4351
4452 public subscript( position: Int ) -> JSValue {
45- ref [ position]
53+ jsObject [ position]
4654 }
4755
4856 public var startIndex : Int { 0 }
@@ -62,14 +70,14 @@ extension JSArray: RandomAccessCollection {
6270 /// array.count // 2
6371 /// ```
6472 public var length : Int {
65- return Int ( ref . length. number!)
73+ Int ( jsObject . length. number!)
6674 }
6775
6876 /// The number of elements in that array **not** including empty hole.
6977 /// Note that `count` syncs with the number that `Iterator` can iterate.
7078 /// See also: `JSArray.length`
7179 public var count : Int {
72- return getObjectValuesLength ( ref )
80+ getObjectValuesLength ( jsObject )
7381 }
7482}
7583
0 commit comments