@@ -88,6 +88,7 @@ extension JSObject: JSValueCompatible {
88
88
private let objectConstructor = JSObject . global. Object. function!
89
89
private let arrayConstructor = JSObject . global. Array. function!
90
90
91
+ #if !hasFeature(Embedded)
91
92
extension Dictionary where Value == ConvertibleToJSValue , Key == String {
92
93
public var jsValue : JSValue {
93
94
let object = objectConstructor. new ( )
@@ -97,6 +98,7 @@ extension Dictionary where Value == ConvertibleToJSValue, Key == String {
97
98
return . object( object)
98
99
}
99
100
}
101
+ #endif
100
102
101
103
extension Dictionary : ConvertibleToJSValue where Value: ConvertibleToJSValue , Key == String {
102
104
public var jsValue : JSValue {
@@ -158,6 +160,7 @@ extension Array: ConvertibleToJSValue where Element: ConvertibleToJSValue {
158
160
}
159
161
}
160
162
163
+ #if !hasFeature(Embedded)
161
164
extension Array where Element == ConvertibleToJSValue {
162
165
public var jsValue : JSValue {
163
166
let array = arrayConstructor. new ( count)
@@ -167,6 +170,7 @@ extension Array where Element == ConvertibleToJSValue {
167
170
return . object( array)
168
171
}
169
172
}
173
+ #endif
170
174
171
175
extension Array : ConstructibleFromJSValue where Element: ConstructibleFromJSValue {
172
176
public static func construct( from value: JSValue ) -> [ Element ] ? {
@@ -252,13 +256,13 @@ extension JSValue {
252
256
}
253
257
}
254
258
255
- extension Array where Element == ConvertibleToJSValue {
259
+ extension Array where Element: ConvertibleToJSValue {
256
260
func withRawJSValues< T> ( _ body: ( [ RawJSValue ] ) -> T ) -> T {
257
261
// fast path for empty array
258
262
guard self . count != 0 else { return body ( [ ] ) }
259
263
260
264
func _withRawJSValues(
261
- _ values: [ ConvertibleToJSValue ] , _ index: Int ,
265
+ _ values: Self , _ index: Int ,
262
266
_ results: inout [ RawJSValue ] , _ body: ( [ RawJSValue ] ) -> T
263
267
) -> T {
264
268
if index == values. count { return body ( results) }
@@ -272,8 +276,24 @@ extension Array where Element == ConvertibleToJSValue {
272
276
}
273
277
}
274
278
275
- extension Array where Element: ConvertibleToJSValue {
279
+ #if !hasFeature(Embedded)
280
+ extension Array where Element == ConvertibleToJSValue {
276
281
func withRawJSValues< T> ( _ body: ( [ RawJSValue ] ) -> T ) -> T {
277
- [ ConvertibleToJSValue ] . withRawJSValues ( self ) ( body)
282
+ // fast path for empty array
283
+ guard self . count != 0 else { return body ( [ ] ) }
284
+
285
+ func _withRawJSValues(
286
+ _ values: [ ConvertibleToJSValue ] , _ index: Int ,
287
+ _ results: inout [ RawJSValue ] , _ body: ( [ RawJSValue ] ) -> T
288
+ ) -> T {
289
+ if index == values. count { return body ( results) }
290
+ return values [ index] . jsValue. withRawJSValue { ( rawValue) -> T in
291
+ results. append ( rawValue)
292
+ return _withRawJSValues ( values, index + 1 , & results, body)
293
+ }
294
+ }
295
+ var _results = [ RawJSValue] ( )
296
+ return _withRawJSValues ( self , 0 , & _results, body)
278
297
}
279
298
}
299
+ #endif
0 commit comments