From 9bf1c59b453a892ceeae321e8e37ce80820f361a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 20 Feb 2026 00:59:25 +0900 Subject: [PATCH 1/2] [Tests] BridgeJS: Move Array-related tests to their own test file --- .../ArraySupportTests.swift | 88 +++ .../Generated/BridgeJS.Macros.swift | 14 - .../Generated/BridgeJS.swift | 530 ++++++++-------- .../Generated/JavaScript/BridgeJS.json | 592 ++++++++++-------- .../BridgeJSRuntimeTests/ImportAPITests.swift | 87 --- .../ImportArrayAPIs.swift | 17 - .../JSClassSupportTests.swift | 38 ++ .../JavaScript/ArraySupportTests.mjs | 36 ++ .../JavaScript/JSClassSupportTests.mjs | 27 + Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 8 - Tests/prelude.mjs | 52 +- 11 files changed, 773 insertions(+), 716 deletions(-) create mode 100644 Tests/BridgeJSRuntimeTests/ArraySupportTests.swift delete mode 100644 Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift create mode 100644 Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift create mode 100644 Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs create mode 100644 Tests/BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs diff --git a/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift new file mode 100644 index 000000000..59bd2ca66 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift @@ -0,0 +1,88 @@ +import XCTest +import JavaScriptKit + +@JSClass struct ArraySupportImports { + @JSFunction static func jsIntArrayLength(_ items: [Int]) throws(JSException) -> Int + + @JSFunction static func jsRoundTripIntArray(_ items: [Int]) throws(JSException) -> [Int] + @JSFunction static func jsRoundTripNumberArray(_ values: [Double]) throws(JSException) -> [Double] + @JSFunction static func jsRoundTripStringArray(_ values: [String]) throws(JSException) -> [String] + @JSFunction static func jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] + + @JSFunction static func jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] + @JSFunction static func jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> + + @JSFunction static func jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double + @JSFunction static func jsCreateNumberArray() throws(JSException) -> [Double] +} + +final class ArraySupportTests: XCTestCase { + + func testRoundTripIntArray() throws { + let values = [1, 2, 3, 4, 5] + let result = try ArraySupportImports.jsRoundTripIntArray(values) + XCTAssertEqual(result, values) + XCTAssertEqual(try ArraySupportImports.jsIntArrayLength(values), values.count) + XCTAssertEqual(try ArraySupportImports.jsRoundTripIntArray([]), []) + } + + func testRoundTripNumberArray() throws { + let input: [Double] = [1.0, 2.5, 3.0, -4.5] + let result = try ArraySupportImports.jsRoundTripNumberArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try ArraySupportImports.jsRoundTripNumberArray([]), []) + XCTAssertEqual(try ArraySupportImports.jsRoundTripNumberArray([42.0]), [42.0]) + } + + func testRoundTripStringArray() throws { + let input = ["Hello", "World", "🎉"] + let result = try ArraySupportImports.jsRoundTripStringArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try ArraySupportImports.jsRoundTripStringArray([]), []) + XCTAssertEqual(try ArraySupportImports.jsRoundTripStringArray(["", "a", ""]), ["", "a", ""]) + } + + func testRoundTripBoolArray() throws { + let input = [true, false, true, false] + let result = try ArraySupportImports.jsRoundTripBoolArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try ArraySupportImports.jsRoundTripBoolArray([]), []) + } + + func testSumNumberArray() throws { + XCTAssertEqual(try ArraySupportImports.jsSumNumberArray([1.0, 2.0, 3.0, 4.0]), 10.0) + XCTAssertEqual(try ArraySupportImports.jsSumNumberArray([]), 0.0) + XCTAssertEqual(try ArraySupportImports.jsSumNumberArray([42.0]), 42.0) + } + + func testCreateNumberArray() throws { + let result = try ArraySupportImports.jsCreateNumberArray() + XCTAssertEqual(result, [1.0, 2.0, 3.0, 4.0, 5.0]) + } + + func testRoundTripJSValueArray() throws { + let object = JSObject.global + let symbol = JSSymbol("array") + let bigInt = JSBigInt(_slowBridge: Int64(42)) + let values: [JSValue] = [ + .boolean(false), + .number(123.5), + .string(JSString("hello")), + .object(object), + .null, + .undefined, + .symbol(symbol), + .bigInt(bigInt), + ] + let roundTripped = try ArraySupportImports.jsRoundTripJSValueArray(values) + XCTAssertEqual(roundTripped, values) + XCTAssertEqual(try ArraySupportImports.jsRoundTripJSValueArray([]), []) + } + + func testRoundTripOptionalJSValueArray() throws { + XCTAssertNil(try ArraySupportImports.jsRoundTripOptionalJSValueArray(nil)) + let values: [JSValue] = [.number(1), .undefined, .null] + let result = try ArraySupportImports.jsRoundTripOptionalJSValueArray(values) + XCTAssertEqual(result, values) + } +} diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index c63a421e0..ac9ad0bc6 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -16,10 +16,6 @@ @JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue -@JSFunction func jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] - -@JSFunction func jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> - @JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void @JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double @@ -63,16 +59,6 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @JSFunction(jsName: "with-dashes") static func with_dashes() throws(JSException) -> StaticBox } -@JSFunction func jsRoundTripNumberArray(_ values: [Double]) throws(JSException) -> [Double] - -@JSFunction func jsRoundTripStringArray(_ values: [String]) throws(JSException) -> [String] - -@JSFunction func jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] - -@JSFunction func jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double - -@JSFunction func jsCreateNumberArray() throws(JSException) -> [Double] - @JSFunction(from: .global) func parseInt(_ string: String) throws(JSException) -> Double @JSClass(from: .global) struct Animal { diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index d9c671c77..db98de0dd 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -9229,6 +9229,194 @@ fileprivate func _bjs_LeakCheck_wrap_extern(_ pointer: UnsafeMutableRawPointer) return _bjs_LeakCheck_wrap_extern(pointer) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsIntArrayLength_static") +fileprivate func bjs_ArraySupportImports_jsIntArrayLength_static_extern() -> Int32 +#else +fileprivate func bjs_ArraySupportImports_jsIntArrayLength_static_extern() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsIntArrayLength_static() -> Int32 { + return bjs_ArraySupportImports_jsIntArrayLength_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripIntArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripIntArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripIntArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripIntArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripIntArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripNumberArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripNumberArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripNumberArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripNumberArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripNumberArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripStringArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripStringArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripStringArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripStringArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripStringArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripBoolArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripBoolArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripBoolArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripBoolArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripBoolArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripJSValueArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripJSValueArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripJSValueArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripJSValueArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripJSValueArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static_extern(_ v: Int32) -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static_extern(_ v: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static(_ v: Int32) -> Void { + return bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static_extern(v) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsSumNumberArray_static") +fileprivate func bjs_ArraySupportImports_jsSumNumberArray_static_extern() -> Float64 +#else +fileprivate func bjs_ArraySupportImports_jsSumNumberArray_static_extern() -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsSumNumberArray_static() -> Float64 { + return bjs_ArraySupportImports_jsSumNumberArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsCreateNumberArray_static") +fileprivate func bjs_ArraySupportImports_jsCreateNumberArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsCreateNumberArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsCreateNumberArray_static() -> Void { + return bjs_ArraySupportImports_jsCreateNumberArray_static_extern() +} + +func _$ArraySupportImports_jsIntArrayLength(_ items: [Int]) throws(JSException) -> Int { + let _ = items.bridgeJSLowerParameter() + let ret = bjs_ArraySupportImports_jsIntArrayLength_static() + if let error = _swift_js_take_exception() { + throw error + } + return Int.bridgeJSLiftReturn(ret) +} + +func _$ArraySupportImports_jsRoundTripIntArray(_ items: [Int]) throws(JSException) -> [Int] { + let _ = items.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripIntArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [Int].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripNumberArray(_ values: [Double]) throws(JSException) -> [Double] { + let _ = values.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripNumberArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [Double].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripStringArray(_ values: [String]) throws(JSException) -> [String] { + let _ = values.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripStringArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [String].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] { + let _ = values.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripBoolArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [Bool].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] { + let _ = v.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripJSValueArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [JSValue].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> { + let vIsSome = v.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static(vIsSome) + if let error = _swift_js_take_exception() { + throw error + } + return Optional<[JSValue]>.bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double { + let _ = values.bridgeJSLowerParameter() + let ret = bjs_ArraySupportImports_jsSumNumberArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return Double.bridgeJSLiftReturn(ret) +} + +func _$ArraySupportImports_jsCreateNumberArray() throws(JSException) -> [Double] { + bjs_ArraySupportImports_jsCreateNumberArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [Double].bridgeJSLiftReturn() +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ClosureSupportImports_jsApplyVoid_static") fileprivate func bjs_ClosureSupportImports_jsApplyVoid_static_extern(_ callback: Int32) -> Void @@ -9938,48 +10126,6 @@ func _$jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue { return JSValue.bridgeJSLiftReturn() } -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripJSValueArray") -fileprivate func bjs_jsRoundTripJSValueArray_extern() -> Void -#else -fileprivate func bjs_jsRoundTripJSValueArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripJSValueArray() -> Void { - return bjs_jsRoundTripJSValueArray_extern() -} - -func _$jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] { - let _ = v.bridgeJSLowerParameter() - bjs_jsRoundTripJSValueArray() - if let error = _swift_js_take_exception() { - throw error - } - return [JSValue].bridgeJSLiftReturn() -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalJSValueArray") -fileprivate func bjs_jsRoundTripOptionalJSValueArray_extern(_ v: Int32) -> Void -#else -fileprivate func bjs_jsRoundTripOptionalJSValueArray_extern(_ v: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripOptionalJSValueArray(_ v: Int32) -> Void { - return bjs_jsRoundTripOptionalJSValueArray_extern(v) -} - -func _$jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> { - let vIsSome = v.bridgeJSLowerParameter() - bjs_jsRoundTripOptionalJSValueArray(vIsSome) - if let error = _swift_js_take_exception() { - throw error - } - return Optional<[JSValue]>.bridgeJSLiftReturn() -} - #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsThrowOrVoid") fileprivate func bjs_jsThrowOrVoid_extern(_ shouldThrow: Int32) -> Void @@ -10124,110 +10270,6 @@ func _$_jsWeirdFunction() throws(JSException) -> Double { return Double.bridgeJSLiftReturn(ret) } -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripNumberArray") -fileprivate func bjs_jsRoundTripNumberArray_extern() -> Void -#else -fileprivate func bjs_jsRoundTripNumberArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripNumberArray() -> Void { - return bjs_jsRoundTripNumberArray_extern() -} - -func _$jsRoundTripNumberArray(_ values: [Double]) throws(JSException) -> [Double] { - let _ = values.bridgeJSLowerParameter() - bjs_jsRoundTripNumberArray() - if let error = _swift_js_take_exception() { - throw error - } - return [Double].bridgeJSLiftReturn() -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripStringArray") -fileprivate func bjs_jsRoundTripStringArray_extern() -> Void -#else -fileprivate func bjs_jsRoundTripStringArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripStringArray() -> Void { - return bjs_jsRoundTripStringArray_extern() -} - -func _$jsRoundTripStringArray(_ values: [String]) throws(JSException) -> [String] { - let _ = values.bridgeJSLowerParameter() - bjs_jsRoundTripStringArray() - if let error = _swift_js_take_exception() { - throw error - } - return [String].bridgeJSLiftReturn() -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripBoolArray") -fileprivate func bjs_jsRoundTripBoolArray_extern() -> Void -#else -fileprivate func bjs_jsRoundTripBoolArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripBoolArray() -> Void { - return bjs_jsRoundTripBoolArray_extern() -} - -func _$jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] { - let _ = values.bridgeJSLowerParameter() - bjs_jsRoundTripBoolArray() - if let error = _swift_js_take_exception() { - throw error - } - return [Bool].bridgeJSLiftReturn() -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsSumNumberArray") -fileprivate func bjs_jsSumNumberArray_extern() -> Float64 -#else -fileprivate func bjs_jsSumNumberArray_extern() -> Float64 { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsSumNumberArray() -> Float64 { - return bjs_jsSumNumberArray_extern() -} - -func _$jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double { - let _ = values.bridgeJSLowerParameter() - let ret = bjs_jsSumNumberArray() - if let error = _swift_js_take_exception() { - throw error - } - return Double.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsCreateNumberArray") -fileprivate func bjs_jsCreateNumberArray_extern() -> Void -#else -fileprivate func bjs_jsCreateNumberArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsCreateNumberArray() -> Void { - return bjs_jsCreateNumberArray_extern() -} - -func _$jsCreateNumberArray() throws(JSException) -> [Double] { - bjs_jsCreateNumberArray() - if let error = _swift_js_take_exception() { - throw error - } - return [Double].bridgeJSLiftReturn() -} - #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_parseInt") fileprivate func bjs_parseInt_extern(_ string: Int32) -> Float64 @@ -10732,235 +10774,194 @@ func _$Animal_getIsCat(_ self: JSObject) throws(JSException) -> Bool { } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripIntArray") -fileprivate func bjs_jsRoundTripIntArray_extern() -> Void -#else -fileprivate func bjs_jsRoundTripIntArray_extern() -> Void { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsRoundTripIntArray() -> Void { - return bjs_jsRoundTripIntArray_extern() -} - -func _$jsRoundTripIntArray(_ items: [Int]) throws(JSException) -> [Int] { - let _ = items.bridgeJSLowerParameter() - bjs_jsRoundTripIntArray() - if let error = _swift_js_take_exception() { - throw error - } - return [Int].bridgeJSLiftReturn() -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsArrayLength") -fileprivate func bjs_jsArrayLength_extern() -> Int32 -#else -fileprivate func bjs_jsArrayLength_extern() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif -@inline(never) fileprivate func bjs_jsArrayLength() -> Int32 { - return bjs_jsArrayLength_extern() -} - -func _$jsArrayLength(_ items: [Int]) throws(JSException) -> Int { - let _ = items.bridgeJSLowerParameter() - let ret = bjs_jsArrayLength() - if let error = _swift_js_take_exception() { - throw error - } - return Int.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_makeArrayHost") -fileprivate func bjs_makeArrayHost_extern() -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsTranslatePoint") +fileprivate func bjs_jsTranslatePoint_extern(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 #else -fileprivate func bjs_makeArrayHost_extern() -> Int32 { +fileprivate func bjs_jsTranslatePoint_extern(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_makeArrayHost() -> Int32 { - return bjs_makeArrayHost_extern() +@inline(never) fileprivate func bjs_jsTranslatePoint(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { + return bjs_jsTranslatePoint_extern(point, dx, dy) } -func _$makeArrayHost(_ numbers: [Int], _ labels: [String]) throws(JSException) -> ArrayHost { - let _ = labels.bridgeJSLowerParameter() - let _ = numbers.bridgeJSLowerParameter() - let ret = bjs_makeArrayHost() +func _$jsTranslatePoint(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException) -> Point { + let pointObjectId = point.bridgeJSLowerParameter() + let dxValue = dx.bridgeJSLowerParameter() + let dyValue = dy.bridgeJSLowerParameter() + let ret = bjs_jsTranslatePoint(pointObjectId, dxValue, dyValue) if let error = _swift_js_take_exception() { throw error } - return ArrayHost.bridgeJSLiftReturn(ret) + return Point.bridgeJSLiftReturn(ret) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_init") -fileprivate func bjs_ArrayHost_init_extern() -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_init") +fileprivate func bjs_JSClassWithArrayMembers_init_extern() -> Int32 #else -fileprivate func bjs_ArrayHost_init_extern() -> Int32 { +fileprivate func bjs_JSClassWithArrayMembers_init_extern() -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_init() -> Int32 { - return bjs_ArrayHost_init_extern() +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_init() -> Int32 { + return bjs_JSClassWithArrayMembers_init_extern() } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_numbers_get") -fileprivate func bjs_ArrayHost_numbers_get_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_numbers_get") +fileprivate func bjs_JSClassWithArrayMembers_numbers_get_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_numbers_get_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_numbers_get_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_numbers_get(_ self: Int32) -> Void { - return bjs_ArrayHost_numbers_get_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_numbers_get(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_numbers_get_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_labels_get") -fileprivate func bjs_ArrayHost_labels_get_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_labels_get") +fileprivate func bjs_JSClassWithArrayMembers_labels_get_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_labels_get_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_labels_get_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_labels_get(_ self: Int32) -> Void { - return bjs_ArrayHost_labels_get_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_labels_get(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_labels_get_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_numbers_set") -fileprivate func bjs_ArrayHost_numbers_set_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_numbers_set") +fileprivate func bjs_JSClassWithArrayMembers_numbers_set_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_numbers_set_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_numbers_set_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_numbers_set(_ self: Int32) -> Void { - return bjs_ArrayHost_numbers_set_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_numbers_set(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_numbers_set_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_labels_set") -fileprivate func bjs_ArrayHost_labels_set_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_labels_set") +fileprivate func bjs_JSClassWithArrayMembers_labels_set_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_labels_set_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_labels_set_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_labels_set(_ self: Int32) -> Void { - return bjs_ArrayHost_labels_set_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_labels_set(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_labels_set_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_concatNumbers") -fileprivate func bjs_ArrayHost_concatNumbers_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_concatNumbers") +fileprivate func bjs_JSClassWithArrayMembers_concatNumbers_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_concatNumbers_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_concatNumbers_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_concatNumbers(_ self: Int32) -> Void { - return bjs_ArrayHost_concatNumbers_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_concatNumbers(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_concatNumbers_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_concatLabels") -fileprivate func bjs_ArrayHost_concatLabels_extern(_ self: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_concatLabels") +fileprivate func bjs_JSClassWithArrayMembers_concatLabels_extern(_ self: Int32) -> Void #else -fileprivate func bjs_ArrayHost_concatLabels_extern(_ self: Int32) -> Void { +fileprivate func bjs_JSClassWithArrayMembers_concatLabels_extern(_ self: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_concatLabels(_ self: Int32) -> Void { - return bjs_ArrayHost_concatLabels_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_concatLabels(_ self: Int32) -> Void { + return bjs_JSClassWithArrayMembers_concatLabels_extern(self) } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_firstLabel") -fileprivate func bjs_ArrayHost_firstLabel_extern(_ self: Int32) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassWithArrayMembers_firstLabel") +fileprivate func bjs_JSClassWithArrayMembers_firstLabel_extern(_ self: Int32) -> Int32 #else -fileprivate func bjs_ArrayHost_firstLabel_extern(_ self: Int32) -> Int32 { +fileprivate func bjs_JSClassWithArrayMembers_firstLabel_extern(_ self: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_ArrayHost_firstLabel(_ self: Int32) -> Int32 { - return bjs_ArrayHost_firstLabel_extern(self) +@inline(never) fileprivate func bjs_JSClassWithArrayMembers_firstLabel(_ self: Int32) -> Int32 { + return bjs_JSClassWithArrayMembers_firstLabel_extern(self) } -func _$ArrayHost_init(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSObject { +func _$JSClassWithArrayMembers_init(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSObject { let _ = labels.bridgeJSLowerParameter() let _ = numbers.bridgeJSLowerParameter() - let ret = bjs_ArrayHost_init() + let ret = bjs_JSClassWithArrayMembers_init() if let error = _swift_js_take_exception() { throw error } return JSObject.bridgeJSLiftReturn(ret) } -func _$ArrayHost_numbers_get(_ self: JSObject) throws(JSException) -> [Int] { +func _$JSClassWithArrayMembers_numbers_get(_ self: JSObject) throws(JSException) -> [Int] { let selfValue = self.bridgeJSLowerParameter() - bjs_ArrayHost_numbers_get(selfValue) + bjs_JSClassWithArrayMembers_numbers_get(selfValue) if let error = _swift_js_take_exception() { throw error } return [Int].bridgeJSLiftReturn() } -func _$ArrayHost_labels_get(_ self: JSObject) throws(JSException) -> [String] { +func _$JSClassWithArrayMembers_labels_get(_ self: JSObject) throws(JSException) -> [String] { let selfValue = self.bridgeJSLowerParameter() - bjs_ArrayHost_labels_get(selfValue) + bjs_JSClassWithArrayMembers_labels_get(selfValue) if let error = _swift_js_take_exception() { throw error } return [String].bridgeJSLiftReturn() } -func _$ArrayHost_numbers_set(_ self: JSObject, _ newValue: [Int]) throws(JSException) -> Void { +func _$JSClassWithArrayMembers_numbers_set(_ self: JSObject, _ newValue: [Int]) throws(JSException) -> Void { let selfValue = self.bridgeJSLowerParameter() let _ = newValue.bridgeJSLowerParameter() - bjs_ArrayHost_numbers_set(selfValue) + bjs_JSClassWithArrayMembers_numbers_set(selfValue) if let error = _swift_js_take_exception() { throw error } } -func _$ArrayHost_labels_set(_ self: JSObject, _ newValue: [String]) throws(JSException) -> Void { +func _$JSClassWithArrayMembers_labels_set(_ self: JSObject, _ newValue: [String]) throws(JSException) -> Void { let selfValue = self.bridgeJSLowerParameter() let _ = newValue.bridgeJSLowerParameter() - bjs_ArrayHost_labels_set(selfValue) + bjs_JSClassWithArrayMembers_labels_set(selfValue) if let error = _swift_js_take_exception() { throw error } } -func _$ArrayHost_concatNumbers(_ self: JSObject, _ values: [Int]) throws(JSException) -> [Int] { +func _$JSClassWithArrayMembers_concatNumbers(_ self: JSObject, _ values: [Int]) throws(JSException) -> [Int] { let selfValue = self.bridgeJSLowerParameter() let _ = values.bridgeJSLowerParameter() - bjs_ArrayHost_concatNumbers(selfValue) + bjs_JSClassWithArrayMembers_concatNumbers(selfValue) if let error = _swift_js_take_exception() { throw error } return [Int].bridgeJSLiftReturn() } -func _$ArrayHost_concatLabels(_ self: JSObject, _ values: [String]) throws(JSException) -> [String] { +func _$JSClassWithArrayMembers_concatLabels(_ self: JSObject, _ values: [String]) throws(JSException) -> [String] { let selfValue = self.bridgeJSLowerParameter() let _ = values.bridgeJSLowerParameter() - bjs_ArrayHost_concatLabels(selfValue) + bjs_JSClassWithArrayMembers_concatLabels(selfValue) if let error = _swift_js_take_exception() { throw error } return [String].bridgeJSLiftReturn() } -func _$ArrayHost_firstLabel(_ self: JSObject, _ values: [String]) throws(JSException) -> String { +func _$JSClassWithArrayMembers_firstLabel(_ self: JSObject, _ values: [String]) throws(JSException) -> String { let selfValue = self.bridgeJSLowerParameter() let _ = values.bridgeJSLowerParameter() - let ret = bjs_ArrayHost_firstLabel(selfValue) + let ret = bjs_JSClassWithArrayMembers_firstLabel(selfValue) if let error = _swift_js_take_exception() { throw error } @@ -10968,26 +10969,25 @@ func _$ArrayHost_firstLabel(_ self: JSObject, _ values: [String]) throws(JSExcep } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsTranslatePoint") -fileprivate func bjs_jsTranslatePoint_extern(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static") +fileprivate func bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static_extern() -> Int32 #else -fileprivate func bjs_jsTranslatePoint_extern(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { +fileprivate func bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static_extern() -> Int32 { fatalError("Only available on WebAssembly") } #endif -@inline(never) fileprivate func bjs_jsTranslatePoint(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { - return bjs_jsTranslatePoint_extern(point, dx, dy) +@inline(never) fileprivate func bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static() -> Int32 { + return bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static_extern() } -func _$jsTranslatePoint(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException) -> Point { - let pointObjectId = point.bridgeJSLowerParameter() - let dxValue = dx.bridgeJSLowerParameter() - let dyValue = dy.bridgeJSLowerParameter() - let ret = bjs_jsTranslatePoint(pointObjectId, dxValue, dyValue) +func _$JSClassSupportImports_makeJSClassWithArrayMembers(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSClassWithArrayMembers { + let _ = labels.bridgeJSLowerParameter() + let _ = numbers.bridgeJSLowerParameter() + let ret = bjs_JSClassSupportImports_makeJSClassWithArrayMembers_static() if let error = _swift_js_take_exception() { throw error } - return Point.bridgeJSLiftReturn(ret) + return JSClassWithArrayMembers.bridgeJSLiftReturn(ret) } #if arch(wasm32) diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index cb9a6cccd..dcd78119b 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -13374,6 +13374,252 @@ }, "imported" : { "children" : [ + { + "functions" : [ + + ], + "types" : [ + { + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "ArraySupportImports", + "setters" : [ + + ], + "staticMethods" : [ + { + "name" : "jsIntArrayLength", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "name" : "jsRoundTripIntArray", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripNumberArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripStringArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripBoolArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripOptionalJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + }, + { + "name" : "jsSumNumberArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "name" : "jsCreateNumberArray", + "parameters" : [ + + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ] + } + ] + }, { "functions" : [ @@ -14378,92 +14624,30 @@ } }, { - "name" : "jsRoundTripJSValueArray", + "name" : "jsThrowOrVoid", "parameters" : [ { - "name" : "v", + "name" : "shouldThrow", "type" : { - "array" : { - "_0" : { - "jsValue" : { + "bool" : { - } - } } } } ], "returnType" : { - "array" : { - "_0" : { - "jsValue" : { + "void" : { - } - } } } }, { - "name" : "jsRoundTripOptionalJSValueArray", + "name" : "jsThrowOrNumber", "parameters" : [ { - "name" : "v", + "name" : "shouldThrow", "type" : { - "nullable" : { - "_0" : { - "array" : { - "_0" : { - "jsValue" : { - - } - } - } - }, - "_1" : "null" - } - } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "array" : { - "_0" : { - "jsValue" : { - - } - } - } - }, - "_1" : "null" - } - } - }, - { - "name" : "jsThrowOrVoid", - "parameters" : [ - { - "name" : "shouldThrow", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "name" : "jsThrowOrNumber", - "parameters" : [ - { - "name" : "shouldThrow", - "type" : { - "bool" : { + "bool" : { } } @@ -14554,121 +14738,6 @@ } } }, - { - "name" : "jsRoundTripNumberArray", - "parameters" : [ - { - "name" : "values", - "type" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - }, - { - "name" : "jsRoundTripStringArray", - "parameters" : [ - { - "name" : "values", - "type" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "name" : "jsRoundTripBoolArray", - "parameters" : [ - { - "name" : "values", - "type" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - }, - { - "name" : "jsSumNumberArray", - "parameters" : [ - { - "name" : "values", - "type" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "double" : { - - } - } - }, - { - "name" : "jsCreateNumberArray", - "parameters" : [ - - ], - "returnType" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - }, { "from" : "global", "name" : "parseInt", @@ -15026,87 +15095,47 @@ { "functions" : [ { - "name" : "jsRoundTripIntArray", - "parameters" : [ - { - "name" : "items", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "name" : "jsArrayLength", + "name" : "jsTranslatePoint", "parameters" : [ { - "name" : "items", + "name" : "point", "type" : { - "array" : { - "_0" : { - "int" : { - - } - } + "swiftStruct" : { + "_0" : "Point" } } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "name" : "makeArrayHost", - "parameters" : [ + }, { - "name" : "numbers", + "name" : "dx", "type" : { - "array" : { - "_0" : { - "int" : { + "int" : { - } - } } } }, { - "name" : "labels", + "name" : "dy", "type" : { - "array" : { - "_0" : { - "string" : { + "int" : { - } - } } } } ], "returnType" : { - "jsObject" : { - "_0" : "ArrayHost" + "swiftStruct" : { + "_0" : "Point" } } } + ], + "types" : [ + + ] + }, + { + "functions" : [ + ], "types" : [ { @@ -15240,7 +15269,7 @@ } } ], - "name" : "ArrayHost", + "name" : "JSClassWithArrayMembers", "setters" : [ { "functionName" : "numbers_set", @@ -15272,48 +15301,55 @@ "staticMethods" : [ ] - } - ] - }, - { - "functions" : [ + }, { - "name" : "jsTranslatePoint", - "parameters" : [ - { - "name" : "point", - "type" : { - "swiftStruct" : { - "_0" : "Point" - } - } - }, - { - "name" : "dx", - "type" : { - "int" : { + "getters" : [ - } - } - }, + ], + "methods" : [ + + ], + "name" : "JSClassSupportImports", + "setters" : [ + + ], + "staticMethods" : [ { - "name" : "dy", - "type" : { - "int" : { + "name" : "makeJSClassWithArrayMembers", + "parameters" : [ + { + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + } + } + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "JSClassWithArrayMembers" } } } - ], - "returnType" : { - "swiftStruct" : { - "_0" : "Point" - } - } + ] } - ], - "types" : [ - ] }, { diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index fa97c3197..8f02af2ef 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -53,32 +53,6 @@ class ImportAPITests: XCTestCase { } } - func testRoundTripJSValueArray() throws { - let object = JSObject.global - let symbol = JSSymbol("array") - let bigInt = JSBigInt(_slowBridge: Int64(42)) - let values: [JSValue] = [ - .boolean(false), - .number(123.5), - .string(JSString("hello")), - .object(object), - .null, - .undefined, - .symbol(symbol), - .bigInt(bigInt), - ] - let roundTripped = try jsRoundTripJSValueArray(values) - XCTAssertEqual(roundTripped, values) - XCTAssertEqual(try jsRoundTripJSValueArray([]), []) - } - - func testRoundTripOptionalJSValueArray() throws { - XCTAssertNil(try jsRoundTripOptionalJSValueArray(nil)) - let values: [JSValue] = [.number(1), .undefined, .null] - let result = try jsRoundTripOptionalJSValueArray(values) - XCTAssertEqual(result, values) - } - func testRoundTripFeatureFlag() throws { for v in [FeatureFlag.foo, .bar] { try XCTAssertEqual(jsRoundTripFeatureFlag(v), v) @@ -135,33 +109,6 @@ class ImportAPITests: XCTestCase { XCTAssertEqual(try greeter.prefix, "Hello") } - func testRoundTripIntArray() throws { - let values = [1, 2, 3, 4, 5] - let result = try jsRoundTripIntArray(values) - XCTAssertEqual(result, values) - XCTAssertEqual(try jsArrayLength(values), values.count) - XCTAssertEqual(try jsRoundTripIntArray([]), []) - } - - func testJSClassArrayMembers() throws { - let numbers = [1, 2, 3] - let labels = ["alpha", "beta"] - let host = try makeArrayHost(numbers, labels) - - XCTAssertEqual(try host.numbers, numbers) - XCTAssertEqual(try host.labels, labels) - - try host.setNumbers([10, 20]) - try host.setLabels(["gamma"]) - XCTAssertEqual(try host.numbers, [10, 20]) - XCTAssertEqual(try host.labels, ["gamma"]) - - XCTAssertEqual(try host.concatNumbers([30, 40]), [10, 20, 30, 40]) - XCTAssertEqual(try host.concatLabels(["delta", "epsilon"]), ["gamma", "delta", "epsilon"]) - XCTAssertEqual(try host.firstLabel([]), "gamma") - XCTAssertEqual(try host.firstLabel(["zeta"]), "zeta") - } - func testJSNameFunctionAndClass() throws { XCTAssertEqual(try _jsWeirdFunction(), 42) @@ -181,38 +128,4 @@ class ImportAPITests: XCTestCase { let dashed = try StaticBox.with_dashes() XCTAssertEqual(try dashed.value(), 7) } - - func testRoundTripNumberArray() throws { - let input: [Double] = [1.0, 2.5, 3.0, -4.5] - let result = try jsRoundTripNumberArray(input) - XCTAssertEqual(result, input) - XCTAssertEqual(try jsRoundTripNumberArray([]), []) - XCTAssertEqual(try jsRoundTripNumberArray([42.0]), [42.0]) - } - - func testRoundTripStringArray() throws { - let input = ["Hello", "World", "🎉"] - let result = try jsRoundTripStringArray(input) - XCTAssertEqual(result, input) - XCTAssertEqual(try jsRoundTripStringArray([]), []) - XCTAssertEqual(try jsRoundTripStringArray(["", "a", ""]), ["", "a", ""]) - } - - func testRoundTripBoolArray() throws { - let input = [true, false, true, false] - let result = try jsRoundTripBoolArray(input) - XCTAssertEqual(result, input) - XCTAssertEqual(try jsRoundTripBoolArray([]), []) - } - - func testSumNumberArray() throws { - XCTAssertEqual(try jsSumNumberArray([1.0, 2.0, 3.0, 4.0]), 10.0) - XCTAssertEqual(try jsSumNumberArray([]), 0.0) - XCTAssertEqual(try jsSumNumberArray([42.0]), 42.0) - } - - func testCreateNumberArray() throws { - let result = try jsCreateNumberArray() - XCTAssertEqual(result, [1.0, 2.0, 3.0, 4.0, 5.0]) - } } diff --git a/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift b/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift deleted file mode 100644 index 104304d5b..000000000 --- a/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift +++ /dev/null @@ -1,17 +0,0 @@ -@_spi(BridgeJS) import JavaScriptKit - -@JSFunction func jsRoundTripIntArray(_ items: [Int]) throws(JSException) -> [Int] -@JSFunction func jsArrayLength(_ items: [Int]) throws(JSException) -> Int - -@JSClass struct ArrayHost { - @JSGetter var numbers: [Int] - @JSGetter var labels: [String] - @JSSetter func setNumbers(_ value: [Int]) throws(JSException) - @JSSetter func setLabels(_ value: [String]) throws(JSException) - @JSFunction init(_ numbers: [Int], _ labels: [String]) throws(JSException) - @JSFunction func concatNumbers(_ values: [Int]) throws(JSException) -> [Int] - @JSFunction func concatLabels(_ values: [String]) throws(JSException) -> [String] - @JSFunction func firstLabel(_ values: [String]) throws(JSException) -> String -} - -@JSFunction func makeArrayHost(_ numbers: [Int], _ labels: [String]) throws(JSException) -> ArrayHost diff --git a/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift b/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift new file mode 100644 index 000000000..410a103f6 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift @@ -0,0 +1,38 @@ +import XCTest +import JavaScriptKit + +@JSClass struct JSClassWithArrayMembers { + @JSGetter var numbers: [Int] + @JSGetter var labels: [String] + @JSSetter func setNumbers(_ value: [Int]) throws(JSException) + @JSSetter func setLabels(_ value: [String]) throws(JSException) + @JSFunction init(_ numbers: [Int], _ labels: [String]) throws(JSException) + @JSFunction func concatNumbers(_ values: [Int]) throws(JSException) -> [Int] + @JSFunction func concatLabels(_ values: [String]) throws(JSException) -> [String] + @JSFunction func firstLabel(_ values: [String]) throws(JSException) -> String +} + +@JSClass struct JSClassSupportImports { + @JSFunction static func makeJSClassWithArrayMembers(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSClassWithArrayMembers +} + +final class JSClassSupportTests: XCTestCase { + func testJSClassArrayMembers() throws { + let numbers = [1, 2, 3] + let labels = ["alpha", "beta"] + let host = try JSClassSupportImports.makeJSClassWithArrayMembers(numbers, labels) + + XCTAssertEqual(try host.numbers, numbers) + XCTAssertEqual(try host.labels, labels) + + try host.setNumbers([10, 20]) + try host.setLabels(["gamma"]) + XCTAssertEqual(try host.numbers, [10, 20]) + XCTAssertEqual(try host.labels, ["gamma"]) + + XCTAssertEqual(try host.concatNumbers([30, 40]), [10, 20, 30, 40]) + XCTAssertEqual(try host.concatLabels(["delta", "epsilon"]), ["gamma", "delta", "epsilon"]) + XCTAssertEqual(try host.firstLabel([]), "gamma") + XCTAssertEqual(try host.firstLabel(["zeta"]), "zeta") + } +} \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs new file mode 100644 index 000000000..2d708fe94 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs @@ -0,0 +1,36 @@ +// @ts-check + +/** + * @returns {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Imports["ArraySupportImports"]} + */ +export function getImports(importsContext) { + return { + jsIntArrayLength: function (items) { + return items.length; + }, + jsRoundTripIntArray: function (items) { + return items; + }, + jsRoundTripNumberArray: function (values) { + return values; + }, + jsRoundTripStringArray: function (values) { + return values; + }, + jsRoundTripBoolArray: function (values) { + return values; + }, + jsRoundTripJSValueArray: (values) => { + return values; + }, + jsRoundTripOptionalJSValueArray: (values) => { + return values ?? null; + }, + jsSumNumberArray: (values) => { + return values.reduce((a, b) => a + b, 0); + }, + jsCreateNumberArray: function () { + return [1, 2, 3, 4, 5]; + } + }; +} \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs new file mode 100644 index 000000000..d7b0b94ec --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs @@ -0,0 +1,27 @@ +export class JSClassWithArrayMembers { + constructor(numbers, labels) { + this.numbers = numbers; + this.labels = labels; + } + concatNumbers(values) { + return [...this.numbers, ...values]; + } + concatLabels(values) { + return [...this.labels, ...values]; + } + firstLabel(values) { + const merged = [...values, ...this.labels]; + return merged.length > 0 ? merged[0] : ""; + } +}; + +/** + * @returns {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Imports["JSClassSupportImports"]} + */ +export function getImports(importsContext) { + return { + makeJSClassWithArrayMembers: (numbers, labels) => { + return new JSClassWithArrayMembers(numbers, labels); + }, + }; +} \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index ff69f5de9..e8533a3d8 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -4,8 +4,6 @@ export function jsRoundTripBool(v: boolean): boolean export function jsRoundTripString(v: string): string export type JSValue = any export function jsRoundTripJSValue(v: JSValue): JSValue -export function jsRoundTripJSValueArray(v: JSValue[]): JSValue[] -export function jsRoundTripOptionalJSValueArray(v: JSValue[] | null): JSValue[] | null export function jsThrowOrVoid(shouldThrow: boolean): void export function jsThrowOrNumber(shouldThrow: boolean): number export function jsThrowOrBool(shouldThrow: boolean): boolean @@ -44,9 +42,3 @@ export class StaticBox { static makeDefault(): StaticBox; static "with-dashes"(): StaticBox; } - -export function jsRoundTripNumberArray(values: number[]): number[]; -export function jsRoundTripStringArray(values: string[]): string[]; -export function jsRoundTripBoolArray(values: boolean[]): boolean[]; -export function jsSumNumberArray(values: number[]): number; -export function jsCreateNumberArray(): number[]; diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index e55266e9c..dbf47df12 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -8,6 +8,8 @@ import { runJsOptionalSupportTests } from './BridgeJSRuntimeTests/JavaScript/Opt import { getImports as getClosureSupportImports } from './BridgeJSRuntimeTests/JavaScript/ClosureSupportTests.mjs'; import { getImports as getSwiftClassSupportImports } from './BridgeJSRuntimeTests/JavaScript/SwiftClassSupportTests.mjs'; import { getImports as getOptionalSupportImports } from './BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs'; +import { getImports as getArraySupportImports } from './BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs'; +import { getImports as getJSClassSupportImports, JSClassWithArrayMembers } from './BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs'; /** @type {import('../.build/plugins/PackageToJS/outputs/PackageTests/test.d.ts').SetupOptionsFn} */ export async function setupOptions(options, context) { @@ -38,22 +40,6 @@ export async function setupOptions(options, context) { return { ...options, getImports: (importsContext) => { - const ArrayHost = class { - constructor(numbers, labels) { - this.numbers = numbers; - this.labels = labels; - } - concatNumbers(values) { - return [...this.numbers, ...values]; - } - concatLabels(values) { - return [...this.labels, ...values]; - } - firstLabel(values) { - const merged = [...values, ...this.labels]; - return merged.length > 0 ? merged[0] : ""; - } - }; return { "jsRoundTripVoid": () => { return; @@ -94,18 +80,6 @@ export async function setupOptions(options, context) { "jsRoundTripJSValue": (v) => { return v; }, - "jsRoundTripJSValueArray": (values) => { - return values; - }, - "jsRoundTripOptionalJSValueArray": (values) => { - return values ?? null; - }, - "jsRoundTripIntArray": (items) => { - return items; - }, - "jsArrayLength": (items) => { - return items.length; - }, "jsThrowOrVoid": (shouldThrow) => { if (shouldThrow) { throw new Error("TestError"); @@ -138,10 +112,7 @@ export async function setupOptions(options, context) { "$jsWeirdFunction": () => { return 42; }, - ArrayHost, - makeArrayHost: (numbers, labels) => { - return new ArrayHost(numbers, labels); - }, + JSClassWithArrayMembers, JsGreeter: class { /** * @param {string} name @@ -179,21 +150,6 @@ export async function setupOptions(options, context) { jsTranslatePoint: (point, dx, dy) => { return { x: (point.x | 0) + (dx | 0), y: (point.y | 0) + (dy | 0) }; }, - jsRoundTripNumberArray: (values) => { - return values; - }, - jsRoundTripStringArray: (values) => { - return values; - }, - jsRoundTripBoolArray: (values) => { - return values; - }, - jsSumNumberArray: (values) => { - return values.reduce((a, b) => a + b, 0); - }, - jsCreateNumberArray: () => { - return [1, 2, 3, 4, 5]; - }, roundTripArrayMembers: (value) => { return value; }, @@ -205,6 +161,8 @@ export async function setupOptions(options, context) { ClosureSupportImports: getClosureSupportImports(importsContext), SwiftClassSupportImports: getSwiftClassSupportImports(importsContext), OptionalSupportImports: getOptionalSupportImports(importsContext), + ArraySupportImports: getArraySupportImports(importsContext), + JSClassSupportImports: getJSClassSupportImports(importsContext), }; }, addToCoreImports(importObject, importsContext) { From f75e36560b58840d036d5f6190796905f1630de0 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 20 Feb 2026 01:45:48 +0900 Subject: [PATCH 2/2] BridgeJS: Fix `Array<@JSClass struct>` support on imported interfaces --- .../JavaScriptKit/BridgeJSIntrinsics.swift | 11 +-- Sources/JavaScriptKit/JSBridgedType.swift | 8 +- .../ArraySupportTests.swift | 33 ++++++- .../Generated/BridgeJS.swift | 84 ++++++++++++++++++ .../Generated/JavaScript/BridgeJS.json | 86 +++++++++++++++++++ .../JSClassSupportTests.swift | 7 +- .../JavaScript/ArraySupportTests.mjs | 14 ++- Tests/prelude.mjs | 3 +- 8 files changed, 235 insertions(+), 11 deletions(-) diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index cc249a071..069e649af 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -510,12 +510,13 @@ extension _JSBridgedClass { @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ id: Int32) -> Self { Self(unsafelyWrapping: JSObject.bridgeJSLiftParameter(id)) } - @_spi(BridgeJS) public static func bridgeJSStackPop() -> Self { - bridgeJSLiftParameter(_swift_js_pop_i32()) - } @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Int32 { jsObject.bridgeJSLowerReturn() } - @_spi(BridgeJS) public consuming func bridgeJSStackPush() { - _swift_js_push_i32(bridgeJSLowerReturn()) + + public static func bridgeJSStackPop() -> Self { + Self(unsafelyWrapping: JSObject.bridgeJSStackPop()) + } + public consuming func bridgeJSStackPush() { + jsObject.bridgeJSStackPush() } } diff --git a/Sources/JavaScriptKit/JSBridgedType.swift b/Sources/JavaScriptKit/JSBridgedType.swift index bb23cc00c..0eb282d8b 100644 --- a/Sources/JavaScriptKit/JSBridgedType.swift +++ b/Sources/JavaScriptKit/JSBridgedType.swift @@ -16,7 +16,7 @@ extension JSBridgedType { /// A protocol that Swift classes that are exposed to JavaScript via `@JS class` conform to. /// /// The conformance is automatically synthesized by `@JSClass` for BridgeJS-generated declarations. -public protocol _JSBridgedClass { +public protocol _JSBridgedClass: Equatable, _BridgedSwiftStackType { /// The JavaScript object wrapped by this instance. /// You may assume that `jsObject instanceof Self.constructor == true` var jsObject: JSObject { get } @@ -26,6 +26,12 @@ public protocol _JSBridgedClass { init(unsafelyWrapping jsObject: JSObject) } +extension _JSBridgedClass { + public static func == (lhs: Self, rhs: Self) -> Bool { + lhs.jsObject == rhs.jsObject + } +} + /// Conform to this protocol when your Swift class wraps a JavaScript class. public protocol JSBridgedClass: JSBridgedType, _JSBridgedClass { /// The constructor function for the JavaScript class diff --git a/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift index 59bd2ca66..ea4ffea44 100644 --- a/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift +++ b/Tests/BridgeJSRuntimeTests/ArraySupportTests.swift @@ -1,6 +1,12 @@ import XCTest import JavaScriptKit +@JSClass struct ArrayElementObject { + @JSGetter var id: String + + @JSFunction init(id: String) throws(JSException) +} + @JSClass struct ArraySupportImports { @JSFunction static func jsIntArrayLength(_ items: [Int]) throws(JSException) -> Int @@ -10,7 +16,15 @@ import JavaScriptKit @JSFunction static func jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] @JSFunction static func jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] - @JSFunction static func jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> + @JSFunction static func jsRoundTripOptionalJSValueArray( + _ v: Optional<[JSValue]> + ) throws(JSException) -> Optional<[JSValue]> + + @JSFunction static func jsRoundTripJSObjectArray(_ values: [JSObject]) throws(JSException) -> [JSObject] + + @JSFunction static func jsRoundTripJSClassArray( + _ values: [ArrayElementObject] + ) throws(JSException) -> [ArrayElementObject] @JSFunction static func jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double @JSFunction static func jsCreateNumberArray() throws(JSException) -> [Double] @@ -85,4 +99,21 @@ final class ArraySupportTests: XCTestCase { let result = try ArraySupportImports.jsRoundTripOptionalJSValueArray(values) XCTAssertEqual(result, values) } + + func testRoundTripJSObjectArray() throws { + let values: [JSObject] = [.global, JSObject(), ["a": 1, "b": 2]] + let result = try ArraySupportImports.jsRoundTripJSObjectArray(values) + XCTAssertEqual(result, values) + } + + func testRoundTripJSClassArray() throws { + let values = try [ArrayElementObject(id: "1"), ArrayElementObject(id: "2"), ArrayElementObject(id: "3")] + let result = try ArraySupportImports.jsRoundTripJSClassArray(values) + XCTAssertEqual(result, values) + XCTAssertEqual(try result[0].id, "1") + XCTAssertEqual(try result[1].id, "2") + XCTAssertEqual(try result[2].id, "3") + + XCTAssertEqual(try ArraySupportImports.jsRoundTripJSClassArray([]), []) + } } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index db98de0dd..90f2e76b6 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -9229,6 +9229,48 @@ fileprivate func _bjs_LeakCheck_wrap_extern(_ pointer: UnsafeMutableRawPointer) return _bjs_LeakCheck_wrap_extern(pointer) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayElementObject_init") +fileprivate func bjs_ArrayElementObject_init_extern(_ id: Int32) -> Int32 +#else +fileprivate func bjs_ArrayElementObject_init_extern(_ id: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArrayElementObject_init(_ id: Int32) -> Int32 { + return bjs_ArrayElementObject_init_extern(id) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayElementObject_id_get") +fileprivate func bjs_ArrayElementObject_id_get_extern(_ self: Int32) -> Int32 +#else +fileprivate func bjs_ArrayElementObject_id_get_extern(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArrayElementObject_id_get(_ self: Int32) -> Int32 { + return bjs_ArrayElementObject_id_get_extern(self) +} + +func _$ArrayElementObject_init(_ id: String) throws(JSException) -> JSObject { + let idValue = id.bridgeJSLowerParameter() + let ret = bjs_ArrayElementObject_init(idValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$ArrayElementObject_id_get(_ self: JSObject) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_ArrayElementObject_id_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsIntArrayLength_static") fileprivate func bjs_ArraySupportImports_jsIntArrayLength_static_extern() -> Int32 @@ -9313,6 +9355,30 @@ fileprivate func bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static_ return bjs_ArraySupportImports_jsRoundTripOptionalJSValueArray_static_extern(v) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripJSObjectArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripJSObjectArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripJSObjectArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripJSObjectArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripJSObjectArray_static_extern() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsRoundTripJSClassArray_static") +fileprivate func bjs_ArraySupportImports_jsRoundTripJSClassArray_static_extern() -> Void +#else +fileprivate func bjs_ArraySupportImports_jsRoundTripJSClassArray_static_extern() -> Void { + fatalError("Only available on WebAssembly") +} +#endif +@inline(never) fileprivate func bjs_ArraySupportImports_jsRoundTripJSClassArray_static() -> Void { + return bjs_ArraySupportImports_jsRoundTripJSClassArray_static_extern() +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArraySupportImports_jsSumNumberArray_static") fileprivate func bjs_ArraySupportImports_jsSumNumberArray_static_extern() -> Float64 @@ -9400,6 +9466,24 @@ func _$ArraySupportImports_jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValu return Optional<[JSValue]>.bridgeJSLiftReturn() } +func _$ArraySupportImports_jsRoundTripJSObjectArray(_ values: [JSObject]) throws(JSException) -> [JSObject] { + let _ = values.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripJSObjectArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [JSObject].bridgeJSLiftReturn() +} + +func _$ArraySupportImports_jsRoundTripJSClassArray(_ values: [ArrayElementObject]) throws(JSException) -> [ArrayElementObject] { + let _ = values.bridgeJSLowerParameter() + bjs_ArraySupportImports_jsRoundTripJSClassArray_static() + if let error = _swift_js_take_exception() { + throw error + } + return [ArrayElementObject].bridgeJSLiftReturn() +} + func _$ArraySupportImports_jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double { let _ = values.bridgeJSLowerParameter() let ret = bjs_ArraySupportImports_jsSumNumberArray_static() diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index dcd78119b..e682dffd3 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -13379,6 +13379,40 @@ ], "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "id", + "type" : { + "string" : { + + } + } + } + ] + }, + "getters" : [ + { + "name" : "id", + "type" : { + "string" : { + + } + } + } + ], + "methods" : [ + + ], + "name" : "ArrayElementObject", + "setters" : [ + + ], + "staticMethods" : [ + + ] + }, { "getters" : [ @@ -13579,6 +13613,58 @@ } } }, + { + "name" : "jsRoundTripJSObjectArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripJSClassArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "ArrayElementObject" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "ArrayElementObject" + } + } + } + } + }, { "name" : "jsSumNumberArray", "parameters" : [ diff --git a/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift b/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift index 410a103f6..dbfc1cdab 100644 --- a/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift +++ b/Tests/BridgeJSRuntimeTests/JSClassSupportTests.swift @@ -13,7 +13,10 @@ import JavaScriptKit } @JSClass struct JSClassSupportImports { - @JSFunction static func makeJSClassWithArrayMembers(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSClassWithArrayMembers + @JSFunction static func makeJSClassWithArrayMembers( + _ numbers: [Int], + _ labels: [String] + ) throws(JSException) -> JSClassWithArrayMembers } final class JSClassSupportTests: XCTestCase { @@ -35,4 +38,4 @@ final class JSClassSupportTests: XCTestCase { XCTAssertEqual(try host.firstLabel([]), "gamma") XCTAssertEqual(try host.firstLabel(["zeta"]), "zeta") } -} \ No newline at end of file +} diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs index 2d708fe94..5c3b20e63 100644 --- a/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs +++ b/Tests/BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs @@ -1,5 +1,11 @@ // @ts-check +export class ArrayElementObject { + constructor(id) { + this.id = id; + } +} + /** * @returns {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Imports["ArraySupportImports"]} */ @@ -31,6 +37,12 @@ export function getImports(importsContext) { }, jsCreateNumberArray: function () { return [1, 2, 3, 4, 5]; - } + }, + jsRoundTripJSObjectArray: (values) => { + return values; + }, + jsRoundTripJSClassArray: (values) => { + return values; + }, }; } \ No newline at end of file diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index dbf47df12..030ec270d 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -8,7 +8,7 @@ import { runJsOptionalSupportTests } from './BridgeJSRuntimeTests/JavaScript/Opt import { getImports as getClosureSupportImports } from './BridgeJSRuntimeTests/JavaScript/ClosureSupportTests.mjs'; import { getImports as getSwiftClassSupportImports } from './BridgeJSRuntimeTests/JavaScript/SwiftClassSupportTests.mjs'; import { getImports as getOptionalSupportImports } from './BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs'; -import { getImports as getArraySupportImports } from './BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs'; +import { getImports as getArraySupportImports, ArrayElementObject } from './BridgeJSRuntimeTests/JavaScript/ArraySupportTests.mjs'; import { getImports as getJSClassSupportImports, JSClassWithArrayMembers } from './BridgeJSRuntimeTests/JavaScript/JSClassSupportTests.mjs'; /** @type {import('../.build/plugins/PackageToJS/outputs/PackageTests/test.d.ts').SetupOptionsFn} */ @@ -112,6 +112,7 @@ export async function setupOptions(options, context) { "$jsWeirdFunction": () => { return 42; }, + ArrayElementObject, JSClassWithArrayMembers, JsGreeter: class { /**