@@ -88,6 +88,7 @@ extension JSObject: JSValueCompatible {
8888private let objectConstructor = JSObject . global. Object. function!
8989private let arrayConstructor = JSObject . global. Array. function!
9090
91+ #if !hasFeature(Embedded)
9192extension Dictionary where Value == ConvertibleToJSValue , Key == String {
9293 public var jsValue : JSValue {
9394 let object = objectConstructor. new ( )
@@ -97,6 +98,7 @@ extension Dictionary where Value == ConvertibleToJSValue, Key == String {
9798 return . object( object)
9899 }
99100}
101+ #endif
100102
101103extension Dictionary : ConvertibleToJSValue where Value: ConvertibleToJSValue , Key == String {
102104 public var jsValue : JSValue {
@@ -158,6 +160,7 @@ extension Array: ConvertibleToJSValue where Element: ConvertibleToJSValue {
158160 }
159161}
160162
163+ #if !hasFeature(Embedded)
161164extension Array where Element == ConvertibleToJSValue {
162165 public var jsValue : JSValue {
163166 let array = arrayConstructor. new ( count)
@@ -167,6 +170,7 @@ extension Array where Element == ConvertibleToJSValue {
167170 return . object( array)
168171 }
169172}
173+ #endif
170174
171175extension Array : ConstructibleFromJSValue where Element: ConstructibleFromJSValue {
172176 public static func construct( from value: JSValue ) -> [ Element ] ? {
@@ -252,13 +256,13 @@ extension JSValue {
252256 }
253257}
254258
255- extension Array where Element == ConvertibleToJSValue {
259+ extension Array where Element: ConvertibleToJSValue {
256260 func withRawJSValues< T> ( _ body: ( [ RawJSValue ] ) -> T ) -> T {
257261 // fast path for empty array
258262 guard self . count != 0 else { return body ( [ ] ) }
259263
260264 func _withRawJSValues(
261- _ values: [ ConvertibleToJSValue ] , _ index: Int ,
265+ _ values: Self , _ index: Int ,
262266 _ results: inout [ RawJSValue ] , _ body: ( [ RawJSValue ] ) -> T
263267 ) -> T {
264268 if index == values. count { return body ( results) }
@@ -272,8 +276,24 @@ extension Array where Element == ConvertibleToJSValue {
272276 }
273277}
274278
275- extension Array where Element: ConvertibleToJSValue {
279+ #if !hasFeature(Embedded)
280+ extension Array where Element == ConvertibleToJSValue {
276281 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)
278297 }
279298}
299+ #endif
0 commit comments