@@ -98,19 +98,20 @@ extension Dictionary: JSValueConvertible where Value == JSValueConvertible, Key
98
98
private let NativeJSArray = JSObject . global. Array. function!
99
99
extension Dictionary : JSValueConstructible where Value: JSValueConstructible , Key == String {
100
100
public static func construct( from value: JSValue ) -> Self ? {
101
- if let objectRef = value. object,
102
- let keys: [ String ] = Object . keys!( objectRef. jsValue ( ) ) . fromJSValue ( ) {
103
- var entries = [ ( String, Value) ] ( )
104
- entries. reserveCapacity ( keys. count)
105
- for key in keys {
106
- guard let value: Value = objectRef [ key] . fromJSValue ( ) else {
107
- return nil
108
- }
109
- entries. append ( ( key, value) )
101
+ guard
102
+ let objectRef = value. object,
103
+ let keys: [ String ] = Object . keys!( objectRef. jsValue ( ) ) . fromJSValue ( )
104
+ else { return nil }
105
+
106
+ var entries = [ ( String, Value) ] ( )
107
+ entries. reserveCapacity ( keys. count)
108
+ for key in keys {
109
+ guard let value: Value = objectRef [ key] . fromJSValue ( ) else {
110
+ return nil
110
111
}
111
- return Dictionary ( uniqueKeysWithValues : entries )
112
+ entries . append ( ( key , value ) )
112
113
}
113
- return nil
114
+ return Dictionary ( uniqueKeysWithValues : entries )
114
115
}
115
116
}
116
117
@@ -152,20 +153,21 @@ extension Array: JSValueConvertible where Element == JSValueConvertible {
152
153
153
154
extension Array : JSValueConstructible where Element: JSValueConstructible {
154
155
public static func construct( from value: JSValue ) -> [ Element ] ? {
155
- if let objectRef = value . object ,
156
- objectRef. isInstanceOf ( JSObject . global . Array . function! ) {
157
- let count : Int = objectRef. length . fromJSValue ( ) !
158
- var array = [ Element ] ( )
159
- array . reserveCapacity ( count )
160
-
161
- for i in 0 ..< count {
162
- guard let value : Element = objectRef [ i ] . fromJSValue ( ) else { return nil }
163
- array . append ( value )
164
- }
165
-
166
- return array
156
+ guard
157
+ let objectRef = value . object ,
158
+ objectRef. isInstanceOf ( JSObject . global . Array . function! )
159
+ else { return nil }
160
+
161
+ let count : Int = objectRef . length . fromJSValue ( ) !
162
+ var array = [ Element ] ( )
163
+ array . reserveCapacity ( count )
164
+
165
+ for i in 0 ..< count {
166
+ guard let value : Element = objectRef [ i ] . fromJSValue ( ) else { return nil }
167
+ array. append ( value )
167
168
}
168
- return nil
169
+
170
+ return array
169
171
}
170
172
}
171
173
0 commit comments