@@ -7,6 +7,10 @@ import JavaScriptKit
77 @ JSFunction init ( id : String ) throws( JSException )
88}
99
10+ @ JS protocol ArrayElementProtocol {
11+ var value : Int { get set }
12+ }
13+
1014@ JSClass struct ArraySupportImports {
1115 @ JSFunction static func jsIntArrayLength ( _ items : [ Int ] ) throws( JSException ) -> Int
1216
@@ -22,12 +26,27 @@ import JavaScriptKit
2226 _ values : [ ArrayElementObject ]
2327 ) throws( JSException ) -> [ ArrayElementObject ]
2428
29+ @JSFunction static func jsRoundTripOptionalIntArray( _ values : [ Int ? ] ) throws( JSException ) -> [ Int ? ]
30+ @JSFunction static func jsRoundTripOptionalStringArray( _ values : [ String ? ] ) throws( JSException ) -> [ String ? ]
31+ @JSFunction static func jsRoundTripOptionalBoolArray( _ values : [ Bool ? ] ) throws( JSException ) -> [ Bool ? ]
32+ @JSFunction static func jsRoundTripOptionalJSValueArray( _ values : [ JSValue ? ] ) throws( JSException ) -> [ JSValue ? ]
33+ @JSFunction static func jsRoundTripOptionalJSObjectArray( _ values : [ JSObject ? ] ) throws( JSException ) -> [ JSObject ? ]
34+ @JSFunction static func jsRoundTripOptionalJSClassArray(
35+ _ values : [ ArrayElementObject ? ]
36+ ) throws( JSException ) -> [ ArrayElementObject ? ]
37+
2538 @JSFunction static func jsSumNumberArray( _ values : [ Double ] ) throws( JSException ) -> Double
2639 @JSFunction static func jsCreateNumberArray( ) throws( JSException ) -> [ Double ]
40+
41+ @JSFunction static func runJsArraySupportTests( ) throws( JSException )
2742}
2843
2944final class ArraySupportTests: XCTestCase {
3045
46+ func testRunJsArraySupportTests ( ) throws {
47+ try ArraySupportImports . runJsArraySupportTests ( )
48+ }
49+
3150 func testRoundTripIntArray ( ) throws {
3251 let values = [ 1 , 2 , 3 , 4 , 5 ]
3352 let result = try ArraySupportImports . jsRoundTripIntArray ( values )
@@ -105,4 +124,99 @@ final class ArraySupportTests: XCTestCase {
105124
106125 XCTAssertEqual ( try ArraySupportImports . jsRoundTripJSClassArray ( [ ] ) , [ ] )
107126 }
127+
128+ func testRoundTripOptionalIntArray ( ) throws {
129+ let values = [ 1 , nil , 3 , nil , 5 ]
130+ let result = try ArraySupportImports . jsRoundTripOptionalIntArray ( values )
131+ XCTAssertEqual ( result , values )
132+ }
133+
134+ func testRoundTripOptionalStringArray ( ) throws {
135+ let values = [ " hello " , nil , " world " , nil , " 🎉 " ]
136+ let result = try ArraySupportImports . jsRoundTripOptionalStringArray ( values )
137+ XCTAssertEqual ( result , values )
138+ }
139+
140+ func testRoundTripOptionalBoolArray ( ) throws {
141+ let values = [ true , nil , false , nil , true ]
142+ let result = try ArraySupportImports . jsRoundTripOptionalBoolArray ( values )
143+ XCTAssertEqual ( result , values )
144+ }
145+
146+ func testRoundTripOptionalJSValueArray ( ) throws {
147+ let values : [ JSValue ? ] = [ . number ( 1 ) , nil , . string ( " hello " ) , nil , . object ( . global ) ]
148+ let result = try ArraySupportImports . jsRoundTripOptionalJSValueArray ( values )
149+ XCTAssertEqual ( result , values )
150+ }
151+
152+ func testRoundTripOptionalJSObjectArray ( ) throws {
153+ let values = [ . global , nil , JSObject ( ) , nil , [ " a " : 1 , " b " : 2 ] ]
154+ let result = try ArraySupportImports . jsRoundTripOptionalJSObjectArray ( values )
155+ XCTAssertEqual ( result , values )
156+ }
157+
158+ func testRoundTripOptionalJSClassArray ( ) throws {
159+ let values = try [
160+ ArrayElementObject ( id : " 1 " ) , nil , ArrayElementObject ( id : " 2 " ) , nil , ArrayElementObject ( id : " 3 " ) ,
161+ ]
162+ let result = try ArraySupportImports . jsRoundTripOptionalJSClassArray ( values )
163+ XCTAssertEqual ( result , values )
164+ XCTAssertEqual ( try result [ 0 ] ? . id , " 1 " )
165+ XCTAssertEqual ( result [ 1 ] , nil )
166+ XCTAssertEqual ( try result [ 2 ] ? . id , " 2 " )
167+ XCTAssertEqual ( result [ 3 ] , nil )
168+ XCTAssertEqual ( try result [ 4 ] ? . id , " 3 " )
169+
170+ XCTAssertEqual ( try ArraySupportImports . jsRoundTripOptionalJSClassArray ( [ ] ) , [ ] )
171+ }
172+ }
173+
174+ @ JS enum ArraySupportExports {
175+ @ JS static func roundTripIntArray ( _ v : [ Int ] ) -> [ Int ] { v }
176+ @ JS static func roundTripStringArray ( _ v : [ String ] ) -> [ String ] { v }
177+ @ JS static func roundTripDoubleArray ( _ v : [ Double ] ) -> [ Double ] { v }
178+ @ JS static func roundTripBoolArray ( _ v : [ Bool ] ) -> [ Bool ] { v }
179+ @ JS static func roundTripUnsafeRawPointerArray ( _ v : [ UnsafeRawPointer ] ) -> [ UnsafeRawPointer ] { v }
180+ @ JS static func roundTripUnsafeMutableRawPointerArray ( _ v : [ UnsafeMutableRawPointer ] ) -> [ UnsafeMutableRawPointer ] {
181+ v
182+ }
183+ @ JS static func roundTripOpaquePointerArray ( _ v : [ OpaquePointer ] ) -> [ OpaquePointer ] { v }
184+ @ JS static func roundTripUnsafePointerArray ( _ v : [ UnsafePointer < UInt8 > ] ) -> [ UnsafePointer < UInt8 > ] { v }
185+ @ JS static func roundTripUnsafeMutablePointerArray (
186+ _ v : [ UnsafeMutablePointer < UInt8 > ]
187+ ) -> [ UnsafeMutablePointer < UInt8 > ] { v }
188+ @ JS static func roundTripJSValueArray ( _ v : [ JSValue ] ) -> [ JSValue ] { v }
189+ @ JS static func roundTripJSObjectArray ( _ v : [ JSObject ] ) -> [ JSObject ] { v }
190+ @ JS static func roundTripCaseEnumArray ( _ v : [ Direction ] ) -> [ Direction ] { v }
191+ @ JS static func roundTripStringRawValueEnumArray ( _ v : [ Theme ] ) -> [ Theme ] { v }
192+ @ JS static func roundTripIntRawValueEnumArray ( _ v : [ HttpStatus ] ) -> [ HttpStatus ] { v }
193+ @ JS static func roundTripStructArray ( _ v : [ DataPoint ] ) -> [ DataPoint ] { v }
194+ @ JS static func roundTripSwiftClassArray ( _ v : [ Greeter ] ) -> [ Greeter ] { v }
195+ @ JS static func roundTripNamespacedSwiftClassArray ( _ v : [ Utils . Converter ] ) -> [ Utils . Converter ] { v }
196+ @ JS static func roundTripProtocolArray ( _ v : [ ArrayElementProtocol ] ) -> [ ArrayElementProtocol ] { v }
197+ @ JS static func roundTripJSClassArray ( _ v : [ ArrayElementObject ] ) -> [ ArrayElementObject ] { v }
198+
199+ @ JS static func roundTripOptionalIntArray ( _ v : [ Int ? ] ) -> [ Int ? ] { v }
200+ @ JS static func roundTripOptionalStringArray ( _ v : [ String ? ] ) -> [ String ? ] { v }
201+ @ JS static func roundTripOptionalJSObjectArray ( _ v : [ JSObject ? ] ) -> [ JSObject ? ] { v }
202+ @ JS static func roundTripOptionalCaseEnumArray ( _ v : [ Direction ? ] ) -> [ Direction ? ] { v }
203+ @ JS static func roundTripOptionalStringRawValueEnumArray ( _ v : [ Theme ? ] ) -> [ Theme ? ] { v }
204+ @ JS static func roundTripOptionalIntRawValueEnumArray ( _ v : [ HttpStatus ? ] ) -> [ HttpStatus ? ] { v }
205+ @ JS static func roundTripOptionalStructArray ( _ v : [ DataPoint ? ] ) -> [ DataPoint ? ] { v }
206+ @ JS static func roundTripOptionalSwiftClassArray ( _ v : [ Greeter ? ] ) -> [ Greeter ? ] { v }
207+ @ JS static func roundTripOptionalJSClassArray ( _ v : [ ArrayElementObject ? ] ) -> [ ArrayElementObject ? ] { v }
208+
209+ @ JS static func roundTripNestedIntArray ( _ v : [ [ Int ] ] ) -> [ [ Int ] ] { v }
210+ @ JS static func roundTripNestedStringArray ( _ v : [ [ String ] ] ) -> [ [ String ] ] { v }
211+ @ JS static func roundTripNestedDoubleArray ( _ v : [ [ Double ] ] ) -> [ [ Double ] ] { v }
212+ @ JS static func roundTripNestedBoolArray ( _ v : [ [ Bool ] ] ) -> [ [ Bool ] ] { v }
213+ @ JS static func roundTripNestedStructArray ( _ v : [ [ DataPoint ] ] ) -> [ [ DataPoint ] ] { v }
214+ @ JS static func roundTripNestedCaseEnumArray ( _ v : [ [ Direction ] ] ) -> [ [ Direction ] ] { v }
215+ @ JS static func roundTripNestedSwiftClassArray ( _ v : [ [ Greeter ] ] ) -> [ [ Greeter ] ] { v }
216+
217+ // MARK: - Multiple Array Parameters
218+ @ JS static func multiArrayFirst ( _ a : [ Int ] , _ b : [ String ] ) -> [ Int ] { a }
219+ @ JS static func multiArraySecond ( _ a : [ Int ] , _ b : [ String ] ) -> [ String ] { b }
220+ @ JS static func multiOptionalArrayFirst ( _ a : [ Int ] ? , _ b : [ String ] ? ) -> [ Int ] ? { a }
221+ @ JS static func multiOptionalArraySecond ( _ a : [ Int ] ? , _ b : [ String ] ? ) -> [ String ] ? { b }
108222}
0 commit comments