diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b5ace046..7b5a808bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,9 @@ on: pull_request: push: branches: [main] +concurrency: + group: ${{ github.workflow }} / ${{ startsWith(github.event_name, 'pull') && github.ref_name || github.sha }} + cancel-in-progress: ${{ startsWith(github.event_name, 'pull') }} jobs: test: name: Build and Test @@ -86,7 +89,7 @@ jobs: with: node-version: '20' - name: Install TypeScript - run: npm install --prefix Plugins/BridgeJS/Sources/TS2Swift/JavaScript + run: npm install - name: Run BridgeJS tests # NOTE: Seems like the prebuilt SwiftSyntax binaries are not compatible with # non-macro dependents, so disable experimental prebuilts for now. @@ -150,7 +153,7 @@ jobs: - uses: actions/checkout@v6 - uses: ./.github/actions/install-swift with: - download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a/swift-DEVELOPMENT-SNAPSHOT-2025-09-14-a-ubuntu22.04.tar.gz + download-url: https://download.swift.org/development/ubuntu2204/swift-DEVELOPMENT-SNAPSHOT-2026-02-02-a/swift-DEVELOPMENT-SNAPSHOT-2026-02-02-a-ubuntu22.04.tar.gz - uses: swiftwasm/setup-swiftwasm@v2 id: setup-wasm32-unknown-wasip1 with: { target: wasm32-unknown-wasip1 } diff --git a/.gitignore b/.gitignore index 8dba07278..c34d4dfe2 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ xcuserdata/ Examples/*/Bundle Examples/*/package-lock.json Package.resolved -Plugins/BridgeJS/Sources/JavaScript/package-lock.json +Plugins/BridgeJS/Sources/TS2Swift/JavaScript/package-lock.json Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/**/*.actual bridge-js.config.local.json _site/ diff --git a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift index bc2ceb32b..39a46d22c 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift @@ -4,10 +4,10 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -@_spi(Experimental) import JavaScriptKit +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func benchmarkHelperNoop() throws (JSException) -> Void +@JSFunction func benchmarkHelperNoop() throws(JSException) -> Void -@JSFunction func benchmarkHelperNoopWithNumber(_ n: Double) throws (JSException) -> Void +@JSFunction func benchmarkHelperNoopWithNumber(_ n: Double) throws(JSException) -> Void -@JSFunction func benchmarkRunner(_ name: String, _ body: JSObject) throws (JSException) -> Void +@JSFunction func benchmarkRunner(_ name: String, _ body: JSObject) throws(JSException) -> Void diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 86f4c87dc..5a480694c 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.swift @@ -11,15 +11,15 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) case 2: - return .flag(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .flag(Bool.bridgeJSLiftParameter()) case 3: - return .rate(Float.bridgeJSLiftParameter(_swift_js_pop_f32())) + return .rate(Float.bridgeJSLiftParameter()) case 4: - return .precise(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + return .precise(Double.bridgeJSLiftParameter()) case 5: return .info default: @@ -32,22 +32,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) case .flag(let param0): - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() return Int32(2) case .rate(let param0): - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() return Int32(3) case .precise(let param0): - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() return Int32(4) case .info: return Int32(5) @@ -67,23 +64,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) case .flag(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) case .rate(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) case .precise(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) case .info: _swift_js_push_tag(Int32(5)) } @@ -94,17 +88,17 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> ComplexResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .error(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .error(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) case 2: - return .location(Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .location(Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 3: - return .status(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .status(Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 4: - return .coordinates(Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + return .coordinates(Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter()) case 5: - return .comprehensive(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .comprehensive(Bool.bridgeJSLiftParameter(), Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 6: return .info default: @@ -117,58 +111,37 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .error(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() return Int32(1) case .location(let param0, let param1, let param2): - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(2) case .status(let param0, let param1, let param2): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(3) case .coordinates(let param0, let param1, let param2): - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(4) case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() return Int32(5) case .info: return Int32(6) @@ -188,59 +161,38 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .error(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) case .location(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(3)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .coordinates(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(5)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .info: _swift_js_push_tag(Int32(6)) } @@ -249,23 +201,20 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { extension SimpleStruct: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> SimpleStruct { - let precise = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let rate = Float.bridgeJSLiftParameter(_swift_js_pop_f32()) - let flag = Bool.bridgeJSLiftParameter(_swift_js_pop_i32()) - let count = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let precise = Double.bridgeJSLiftParameter() + let rate = Float.bridgeJSLiftParameter() + let flag = Bool.bridgeJSLiftParameter() + let count = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return SimpleStruct(name: name, count: count, flag: flag, rate: rate, precise: precise) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.count)) - _swift_js_push_i32(self.flag ? 1 : 0) - _swift_js_push_f32(self.rate) - _swift_js_push_f64(self.precise) + self.name.bridgeJSLowerStackReturn() + self.count.bridgeJSLowerStackReturn() + self.flag.bridgeJSLowerStackReturn() + self.rate.bridgeJSLowerStackReturn() + self.precise.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -303,22 +252,16 @@ fileprivate func _bjs_struct_lift_SimpleStruct() -> Int32 { extension Address: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Address { - let zipCode = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let city = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let street = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let zipCode = Int.bridgeJSLiftParameter() + let city = String.bridgeJSLiftParameter() + let street = String.bridgeJSLiftParameter() return Address(street: street, city: city, zipCode: zipCode) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_street = self.street - __bjs_street.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_city = self.city - __bjs_city.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.zipCode)) + self.street.bridgeJSLowerStackReturn() + self.city.bridgeJSLowerStackReturn() + self.zipCode.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -356,26 +299,20 @@ fileprivate func _bjs_struct_lift_Address() -> Int32 { extension Person: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Person { - let email = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32()) + let email = Optional.bridgeJSLiftParameter() let address = Address.bridgeJSLiftParameter() - let age = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let age = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return Person(name: name, age: age, address: address, email: email) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.age)) + self.name.bridgeJSLowerStackReturn() + self.age.bridgeJSLowerStackReturn() self.address.bridgeJSLowerReturn() let __bjs_isSome_email = self.email != nil if let __bjs_unwrapped_email = self.email { - var __bjs_str_email = __bjs_unwrapped_email - __bjs_str_email.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_email.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_email ? 1 : 0) } @@ -415,31 +352,22 @@ fileprivate func _bjs_struct_lift_Person() -> Int32 { extension ComplexStruct: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> ComplexStruct { - let metadata = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let tags = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let score = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let active = Bool.bridgeJSLiftParameter(_swift_js_pop_i32()) - let title = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let metadata = String.bridgeJSLiftParameter() + let tags = String.bridgeJSLiftParameter() + let score = Double.bridgeJSLiftParameter() + let active = Bool.bridgeJSLiftParameter() + let title = String.bridgeJSLiftParameter() + let id = Int.bridgeJSLiftParameter() return ComplexStruct(id: id, title: title, active: active, score: score, tags: tags, metadata: metadata) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) - var __bjs_title = self.title - __bjs_title.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(self.active ? 1 : 0) - _swift_js_push_f64(self.score) - var __bjs_tags = self.tags - __bjs_tags.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_metadata = self.metadata - __bjs_metadata.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.id.bridgeJSLowerStackReturn() + self.title.bridgeJSLowerStackReturn() + self.active.bridgeJSLowerStackReturn() + self.score.bridgeJSLowerStackReturn() + self.tags.bridgeJSLowerStackReturn() + self.metadata.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -477,14 +405,14 @@ fileprivate func _bjs_struct_lift_ComplexStruct() -> Int32 { extension Point: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { - let y = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let x = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let y = Double.bridgeJSLiftParameter() + let x = Double.bridgeJSLiftParameter() return Point(x: x, y: y) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.x) - _swift_js_push_f64(self.y) + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -1487,16 +1415,7 @@ public func _bjs_ArrayRoundtrip_init() -> UnsafeMutableRawPointer { @_cdecl("bjs_ArrayRoundtrip_takeIntArray") public func _bjs_ArrayRoundtrip_takeIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takeIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takeIntArray(_: [Int].bridgeJSLiftParameter()) #else fatalError("Only available on WebAssembly") #endif @@ -1507,9 +1426,7 @@ public func _bjs_ArrayRoundtrip_takeIntArray(_ _self: UnsafeMutableRawPointer) - public func _bjs_ArrayRoundtrip_makeIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeIntArray() - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1519,19 +1436,8 @@ public func _bjs_ArrayRoundtrip_makeIntArray(_ _self: UnsafeMutableRawPointer) - @_cdecl("bjs_ArrayRoundtrip_roundtripIntArray") public func _bjs_ArrayRoundtrip_roundtripIntArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripIntArray(_: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1542,9 +1448,7 @@ public func _bjs_ArrayRoundtrip_roundtripIntArray(_ _self: UnsafeMutableRawPoint public func _bjs_ArrayRoundtrip_makeIntArrayLarge(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeIntArrayLarge() - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1554,16 +1458,7 @@ public func _bjs_ArrayRoundtrip_makeIntArrayLarge(_ _self: UnsafeMutableRawPoint @_cdecl("bjs_ArrayRoundtrip_takeDoubleArray") public func _bjs_ArrayRoundtrip_takeDoubleArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takeDoubleArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takeDoubleArray(_: [Double].bridgeJSLiftParameter()) #else fatalError("Only available on WebAssembly") #endif @@ -1574,9 +1469,7 @@ public func _bjs_ArrayRoundtrip_takeDoubleArray(_ _self: UnsafeMutableRawPointer public func _bjs_ArrayRoundtrip_makeDoubleArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeDoubleArray() - for __bjs_elem_ret in ret { - _swift_js_push_f64(__bjs_elem_ret)} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1586,19 +1479,8 @@ public func _bjs_ArrayRoundtrip_makeDoubleArray(_ _self: UnsafeMutableRawPointer @_cdecl("bjs_ArrayRoundtrip_roundtripDoubleArray") public func _bjs_ArrayRoundtrip_roundtripDoubleArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripDoubleArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_f64(__bjs_elem_ret)} - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripDoubleArray(_: [Double].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1608,16 +1490,7 @@ public func _bjs_ArrayRoundtrip_roundtripDoubleArray(_ _self: UnsafeMutableRawPo @_cdecl("bjs_ArrayRoundtrip_takeStringArray") public func _bjs_ArrayRoundtrip_takeStringArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takeStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takeStringArray(_: [String].bridgeJSLiftParameter()) #else fatalError("Only available on WebAssembly") #endif @@ -1628,12 +1501,7 @@ public func _bjs_ArrayRoundtrip_takeStringArray(_ _self: UnsafeMutableRawPointer public func _bjs_ArrayRoundtrip_makeStringArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeStringArray() - for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1643,22 +1511,8 @@ public func _bjs_ArrayRoundtrip_makeStringArray(_ _self: UnsafeMutableRawPointer @_cdecl("bjs_ArrayRoundtrip_roundtripStringArray") public func _bjs_ArrayRoundtrip_roundtripStringArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripStringArray(_: [String].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1668,16 +1522,7 @@ public func _bjs_ArrayRoundtrip_roundtripStringArray(_ _self: UnsafeMutableRawPo @_cdecl("bjs_ArrayRoundtrip_takePointArray") public func _bjs_ArrayRoundtrip_takePointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - ArrayRoundtrip.bridgeJSLiftParameter(_self).takePointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) + ArrayRoundtrip.bridgeJSLiftParameter(_self).takePointArray(_: [Point].bridgeJSLiftParameter()) #else fatalError("Only available on WebAssembly") #endif @@ -1688,9 +1533,7 @@ public func _bjs_ArrayRoundtrip_takePointArray(_ _self: UnsafeMutableRawPointer) public func _bjs_ArrayRoundtrip_makePointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makePointArray() - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1700,19 +1543,8 @@ public func _bjs_ArrayRoundtrip_makePointArray(_ _self: UnsafeMutableRawPointer) @_cdecl("bjs_ArrayRoundtrip_roundtripPointArray") public func _bjs_ArrayRoundtrip_roundtripPointArray(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).roundtripPointArray(_: [Point].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1723,9 +1555,7 @@ public func _bjs_ArrayRoundtrip_roundtripPointArray(_ _self: UnsafeMutableRawPoi public func _bjs_ArrayRoundtrip_makePointArrayLarge(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makePointArrayLarge() - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -1740,16 +1570,7 @@ public func _bjs_ArrayRoundtrip_takeNestedIntArray(_ _self: UnsafeMutableRawPoin var __result: [[Int]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + __result.append([Int].bridgeJSLiftParameter()) } __result.reverse() return __result @@ -1765,9 +1586,7 @@ public func _bjs_ArrayRoundtrip_makeNestedIntArray(_ _self: UnsafeMutableRawPoin #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeNestedIntArray() for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret_elem))} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -1783,24 +1602,13 @@ public func _bjs_ArrayRoundtrip_roundtripNestedIntArray(_ _self: UnsafeMutableRa var __result: [[Int]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + __result.append([Int].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret_elem))} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -1816,16 +1624,7 @@ public func _bjs_ArrayRoundtrip_takeNestedPointArray(_ _self: UnsafeMutableRawPo var __result: [[Point]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) + __result.append([Point].bridgeJSLiftParameter()) } __result.reverse() return __result @@ -1841,9 +1640,7 @@ public func _bjs_ArrayRoundtrip_makeNestedPointArray(_ _self: UnsafeMutableRawPo #if arch(wasm32) let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeNestedPointArray() for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - __bjs_elem_ret_elem.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -1859,24 +1656,13 @@ public func _bjs_ArrayRoundtrip_roundtripNestedPointArray(_ _self: UnsafeMutable var __result: [[Point]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) + __result.append([Point].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - __bjs_elem_ret_elem.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -1892,7 +1678,7 @@ public func _bjs_ArrayRoundtrip_takeOptionalIntArray(_ _self: UnsafeMutableRawPo var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -1910,7 +1696,7 @@ public func _bjs_ArrayRoundtrip_makeOptionalIntArray(_ _self: UnsafeMutableRawPo for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_unwrapped_ret_elem))} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -1927,7 +1713,7 @@ public func _bjs_ArrayRoundtrip_roundtripOptionalIntArray(_ _self: UnsafeMutable var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -1935,7 +1721,7 @@ public func _bjs_ArrayRoundtrip_roundtripOptionalIntArray(_ _self: UnsafeMutable for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_unwrapped_ret_elem))} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -1952,7 +1738,7 @@ public func _bjs_ArrayRoundtrip_takeOptionalPointArray(_ _self: UnsafeMutableRaw var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -1987,7 +1773,7 @@ public func _bjs_ArrayRoundtrip_roundtripOptionalPointArray(_ _self: UnsafeMutab var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -2011,16 +1797,7 @@ public func _bjs_ArrayRoundtrip_takeOptionalArray(_ _self: UnsafeMutableRawPoint if values == 0 { return Optional<[Int]>.none } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }() + return [Int].bridgeJSLiftParameter() } }()) #else @@ -2035,9 +1812,7 @@ public func _bjs_ArrayRoundtrip_makeOptionalArraySome(_ _self: UnsafeMutableRawP let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeOptionalArraySome() let __bjs_isSome_ret = ret != nil if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") @@ -2051,9 +1826,7 @@ public func _bjs_ArrayRoundtrip_makeOptionalArrayNone(_ _self: UnsafeMutableRawP let ret = ArrayRoundtrip.bridgeJSLiftParameter(_self).makeOptionalArrayNone() let __bjs_isSome_ret = ret != nil if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") @@ -2068,23 +1841,12 @@ public func _bjs_ArrayRoundtrip_roundtripOptionalArray(_ _self: UnsafeMutableRaw if values == 0 { return Optional<[Int]>.none } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }() + return [Int].bridgeJSLiftParameter() } }()) let __bjs_isSome_ret = ret != nil if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") diff --git a/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json index cb081ab39..eacd18cb3 100644 --- a/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json +++ b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json @@ -449,12 +449,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -470,12 +471,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -491,12 +493,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, @@ -512,12 +515,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, @@ -533,12 +537,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -554,12 +559,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -575,12 +581,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -596,12 +603,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1844,12 +1852,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1876,12 +1885,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1902,12 +1912,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1917,12 +1928,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1943,12 +1955,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -1975,12 +1988,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -2001,12 +2015,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -2016,12 +2031,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -2040,7 +2056,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -2049,7 +2065,8 @@ } } } - } + }, + "_1" : "null" } } } @@ -2072,7 +2089,7 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -2081,7 +2098,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -2097,7 +2115,7 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -2106,7 +2124,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -2123,7 +2142,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -2132,13 +2151,14 @@ } } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -2147,7 +2167,8 @@ } } } - } + }, + "_1" : "null" } } } @@ -2601,12 +2622,13 @@ "isStatic" : false, "name" : "email", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -2715,14 +2737,6 @@ }, "imported" : { "children" : [ - { - "functions" : [ - - ], - "types" : [ - - ] - }, { "functions" : [ { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 339a268ee..d984555e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,6 +60,12 @@ Tests for `BridgeJS` plugin: swift test --package-path ./Plugins/BridgeJS ``` +This runs both the TS2Swift Vitest suite (TypeScript `.d.ts` -> Swift macro output) and the Swift codegen/link tests. For fast iteration on the ts2swift tool only, run Vitest directly: + +```bash +cd Plugins/BridgeJS/Sources/TS2Swift/JavaScript && npm test +``` + To update snapshot test files when expected output changes: ```bash diff --git a/Examples/Embedded/build.sh b/Examples/Embedded/build.sh index 7b33e4b74..2d035493a 100755 --- a/Examples/Embedded/build.sh +++ b/Examples/Embedded/build.sh @@ -2,4 +2,4 @@ set -euxo pipefail package_dir="$(cd "$(dirname "$0")" && pwd)" swift package --package-path "$package_dir" \ - -c release --swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm-embedded" js + -c release --swift-sdk "${SWIFT_SDK_ID_wasm32_unknown_wasip1:-${SWIFT_SDK_ID:-wasm32-unknown-wasip1}}-embedded" js diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift index 221302716..c619a8883 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift @@ -4,10 +4,10 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -@_spi(Experimental) import JavaScriptKit +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func createTS2Swift() throws (JSException) -> TS2Swift +@JSFunction func createTS2Swift() throws(JSException) -> TS2Swift @JSClass struct TS2Swift { - @JSFunction func convert(_ ts: String) throws (JSException) -> String + @JSFunction func convert(_ ts: String) throws(JSException) -> String } diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json index 1cf8e64c6..743925c5f 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json @@ -191,17 +191,12 @@ "name" : "TS2Swift", "setters" : [ + ], + "staticMethods" : [ + ] } ] - }, - { - "functions" : [ - - ], - "types" : [ - - ] } ] }, diff --git a/Package.swift b/Package.swift index 1d4c8fb06..c7f3517e8 100644 --- a/Package.swift +++ b/Package.swift @@ -183,6 +183,7 @@ let package = Package( "bridge-js.d.ts", "bridge-js.global.d.ts", "Generated/JavaScript", + "JavaScript", ], swiftSettings: [ .enableExperimentalFeature("Extern") diff --git a/Package@swift-6.2.swift b/Package@swift-6.2.swift index 456a87ca0..f640feeb7 100644 --- a/Package@swift-6.2.swift +++ b/Package@swift-6.2.swift @@ -194,6 +194,7 @@ let package = Package( "bridge-js.d.ts", "bridge-js.global.d.ts", "Generated/JavaScript", + "JavaScript", ], swiftSettings: [ .enableExperimentalFeature("Extern") diff --git a/Plugins/BridgeJS/Package.swift b/Plugins/BridgeJS/Package.swift index a03172f17..49aa161c9 100644 --- a/Plugins/BridgeJS/Package.swift +++ b/Plugins/BridgeJS/Package.swift @@ -59,7 +59,7 @@ let package = Package( "BridgeJSLink", "TS2Swift", ], - exclude: ["__Snapshots__", "Inputs", "MultifileInputs", "ImportMacroInputs"] + exclude: ["__Snapshots__", "Inputs"] ), .macro( name: "BridgeJSMacros", diff --git a/Plugins/BridgeJS/README.md b/Plugins/BridgeJS/README.md index 0e84674ac..0559dc3fb 100644 --- a/Plugins/BridgeJS/README.md +++ b/Plugins/BridgeJS/README.md @@ -100,7 +100,7 @@ graph LR | `Foundation.URL` | `string` | - | [#496](https://github.com/swiftwasm/JavaScriptKit/issues/496) | | Generics | - | - | [#398](https://github.com/swiftwasm/JavaScriptKit/issues/398) | -### Import-specific (TypeScript → Swift) +### Import-specific (TypeScript -> Swift) | TypeScript Type | Swift Type | Status | |:----------------|:-----------|:-------| @@ -163,6 +163,12 @@ Return values use direct Wasm returns for primitives, and imported intrinsic fun For detailed semantics, see the [How It Works sections](https://swiftpackageindex.com/swiftwasm/JavaScriptKit/documentation/javascriptkit/exporting-swift-class#How-It-Works) in the user documentation. +## Testing + +- **Full BridgeJS tests** (Swift + TS2Swift Vitest): `swift test --package-path ./Plugins/BridgeJS` +- **TS2Swift only** (fast iteration on `.d.ts` -> Swift): `npm -C Sources/TS2Swift/JavaScript test` +- **Regenerate snapshot artifacts**: `UPDATE_SNAPSHOTS=1 swift test --package-path ./Plugins/BridgeJS` + ## Debug utilities `BridgeJSToolInternal` exposes pipeline stages for debugging: diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ClosureCodegen.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ClosureCodegen.swift index 5d6545668..30cf8b2c2 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ClosureCodegen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ClosureCodegen.swift @@ -22,7 +22,7 @@ public struct ClosureCodegen { collectClosureSignatures(from: paramType, into: &signatures) } collectClosureSignatures(from: signature.returnType, into: &signatures) - case .optional(let wrapped): + case .nullable(let wrapped, _): collectClosureSignatures(from: wrapped, into: &signatures) default: break diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index d7d5c8200..51ff91695 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -133,17 +133,27 @@ public class ExportSwift { case .array: typeNameForIntrinsic = param.type.swiftType liftingExpr = StackCodegen().liftExpression(for: param.type) - case .optional(let wrappedType): + case .nullable(let wrappedType, let kind): + let optionalSwiftType: String + if case .null = kind { + optionalSwiftType = "Optional" + } else { + optionalSwiftType = "JSUndefinedOr" + } if case .array(let elementType) = wrappedType { let arrayLift = StackCodegen().liftArrayExpression(elementType: elementType) let isSomeParam = argumentsToLift[0] let swiftTypeName = elementType.swiftType - typeNameForIntrinsic = "Optional<[\(swiftTypeName)]>" + typeNameForIntrinsic = "\(optionalSwiftType)<[\(swiftTypeName)]>" + let absentExpr = + kind == .null + ? "\(optionalSwiftType)<[\(swiftTypeName)]>.none" + : "\(optionalSwiftType)<[\(swiftTypeName)]>.undefinedValue" liftingExpr = ExprSyntax( """ { if \(raw: isSomeParam) == 0 { - return Optional<[\(raw: swiftTypeName)]>.none + return \(raw: absentExpr) } else { return \(arrayLift) } @@ -152,12 +162,12 @@ public class ExportSwift { ) } else if case .swiftProtocol(let protocolName) = wrappedType { let wrapperName = "Any\(protocolName)" - typeNameForIntrinsic = "Optional<\(wrapperName)>" + typeNameForIntrinsic = "\(optionalSwiftType)<\(wrapperName)>" liftingExpr = ExprSyntax( "\(raw: typeNameForIntrinsic).bridgeJSLiftParameter(\(raw: argumentsToLift.joined(separator: ", ")))" ) } else { - typeNameForIntrinsic = "Optional<\(wrappedType.swiftType)>" + typeNameForIntrinsic = "\(optionalSwiftType)<\(wrappedType.swiftType)>" liftingExpr = ExprSyntax( "\(raw: typeNameForIntrinsic).bridgeJSLiftParameter(\(raw: argumentsToLift.joined(separator: ", ")))" ) @@ -220,7 +230,7 @@ public class ExportSwift { return CodeBlockItemSyntax( item: .init(DeclSyntax("let ret = \(raw: callExpr) as! \(raw: wrapperName)")) ) - case .optional(let wrappedType): + case .nullable(let wrappedType, _): if case .swiftProtocol(let protocolName) = wrappedType { let wrapperName = "Any\(protocolName)" return CodeBlockItemSyntax( @@ -251,7 +261,7 @@ public class ExportSwift { case .swiftProtocol(let protocolName): let wrapperName = "Any\(protocolName)" append("let ret = \(raw: name) as! \(raw: wrapperName)") - case .optional(let wrappedType): + case .nullable(let wrappedType, _): if case .swiftProtocol(let protocolName) = wrappedType { let wrapperName = "Any\(protocolName)" append("let ret = \(raw: name).flatMap { $0 as? \(raw: wrapperName) }") @@ -278,8 +288,8 @@ public class ExportSwift { private func generateParameterLifting() { let stackParamIndices = parameters.enumerated().compactMap { index, param -> Int? in switch param.type { - case .swiftStruct, .optional(.swiftStruct), - .associatedValueEnum, .optional(.associatedValueEnum), + case .swiftStruct, .nullable(.swiftStruct, _), + .associatedValueEnum, .nullable(.associatedValueEnum, _), .array: return index default: @@ -308,7 +318,7 @@ public class ExportSwift { case .swiftProtocol(let protocolName): let wrapperName = "Any\(protocolName)" append("let ret = \(raw: selfExpr).\(raw: propertyName) as! \(raw: wrapperName)") - case .optional(let wrappedType): + case .nullable(let wrappedType, _): if case .swiftProtocol(let protocolName) = wrappedType { let wrapperName = "Any\(protocolName)" append("let ret = \(raw: selfExpr).\(raw: propertyName).flatMap { $0 as? \(raw: wrapperName) }") @@ -356,7 +366,7 @@ public class ExportSwift { switch returnType { case .closure(let signature): append("return _BJS_Closure_\(raw: signature.mangleName).bridgeJSLower(ret)") - case .array, .optional(.array): + case .array, .nullable(.array, _): let stackCodegen = StackCodegen() for stmt in stackCodegen.lowerStatements(for: returnType, accessor: "ret", varPrefix: "ret") { append(stmt) @@ -533,14 +543,9 @@ public class ExportSwift { if function.effects.isStatic, let staticContext = function.staticContext { let callName: String switch staticContext { - case .className(let baseName), .enumName(let baseName), .structName(let baseName): + case .className(let baseName), .enumName(let baseName), .structName(let baseName), + .namespaceEnum(let baseName): callName = "\(baseName).\(function.name)" - case .namespaceEnum: - if let namespace = function.namespace, !namespace.isEmpty { - callName = "\(namespace.joined(separator: ".")).\(function.name)" - } else { - callName = function.name - } } builder.call(name: callName, returnType: function.returnType) } else { @@ -798,60 +803,60 @@ struct StackCodegen { /// - Returns: An ExprSyntax representing the lift expression func liftExpression(for type: BridgeType) -> ExprSyntax { switch type { - case .string: - return "String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - case .int, .uint: - return "Int.bridgeJSLiftParameter(_swift_js_pop_i32())" - case .bool: - return "Bool.bridgeJSLiftParameter(_swift_js_pop_i32())" - case .float: - return "Float.bridgeJSLiftParameter(_swift_js_pop_f32())" - case .double: - return "Double.bridgeJSLiftParameter(_swift_js_pop_f64())" - case .jsObject: - return "JSObject.bridgeJSLiftParameter(_swift_js_pop_i32())" - case .swiftHeapObject(let className): - return "\(raw: className).bridgeJSLiftParameter(_swift_js_pop_pointer())" + case .string, .int, .uint, .bool, .float, .double, + .jsObject(nil), .jsValue, .swiftStruct, .swiftHeapObject: + return "\(raw: type.swiftType).bridgeJSLiftParameter()" + case .jsObject(let className?): + return "\(raw: className)(unsafelyWrapping: JSObject.bridgeJSLiftParameter())" case .unsafePointer: - return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_pointer())" + return "\(raw: type.swiftType).bridgeJSLiftParameter()" case .swiftProtocol(let protocolName): - // Protocols use their Any wrapper type for lifting - let wrapperName = "Any\(protocolName)" - return "\(raw: wrapperName).bridgeJSLiftParameter(_swift_js_pop_i32())" - case .caseEnum(let enumName): - return "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_i32())" - case .rawValueEnum(let enumName, let rawType): + return "Any\(raw: protocolName).bridgeJSLiftParameter(_swift_js_pop_i32())" + case .caseEnum: + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" + case .rawValueEnum(_, let rawType): switch rawType { case .string: return - "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" + "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" case .float: - return "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_f32())" + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_f32())" case .double: - return "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_f64())" + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_f64())" case .bool, .int, .int32, .int64, .uint, .uint32, .uint64: - return "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_i32())" + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" } - case .associatedValueEnum(let enumName): - return "\(raw: enumName).bridgeJSLiftParameter(_swift_js_pop_i32())" - case .swiftStruct(let structName): - return "\(raw: structName).bridgeJSLiftParameter()" - case .optional(let wrappedType): - return liftOptionalExpression(wrappedType: wrappedType) - case .void: - // Void shouldn't be lifted, but return a placeholder - return "()" - case .namespaceEnum: - // Namespace enums are not passed as values - return "()" - case .closure: - return "JSObject.bridgeJSLiftParameter(_swift_js_pop_i32())" + case .associatedValueEnum: + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" + case .nullable(let wrappedType, let kind): + return liftNullableExpression(wrappedType: wrappedType, kind: kind) case .array(let elementType): return liftArrayExpression(elementType: elementType) + case .closure: + return "JSObject.bridgeJSLiftParameter()" + case .void, .namespaceEnum: + return "()" } } func liftArrayExpression(elementType: BridgeType) -> ExprSyntax { + switch elementType { + case .int, .uint, .float, .double, .string, .bool, .jsValue, + .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()" + case .jsObject(_?): + return liftArrayExpressionInline(elementType: elementType) + case .swiftProtocol(let protocolName): + return "[Any\(raw: protocolName)].bridgeJSLiftParameter()" + case .nullable, .array, .closure: + return liftArrayExpressionInline(elementType: elementType) + case .void, .namespaceEnum: + fatalError("Invalid array element type: \(elementType)") + } + } + + private func liftArrayExpressionInline(elementType: BridgeType) -> ExprSyntax { let elementLift = liftExpression(for: elementType) let swiftTypeName = elementType.swiftType return """ @@ -868,63 +873,32 @@ struct StackCodegen { """ } - private func liftOptionalExpression(wrappedType: BridgeType) -> ExprSyntax { + private func liftNullableExpression(wrappedType: BridgeType, kind: JSOptionalKind) -> ExprSyntax { + let typeName = kind == .null ? "Optional" : "JSUndefinedOr" switch wrappedType { - case .string: - return - "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())" - case .int, .uint: - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - case .bool: - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - case .float: - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f32())" - case .double: - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f64())" - case .caseEnum(let enumName): - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - case .rawValueEnum(let enumName, let rawType): - switch rawType { - case .string: - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())" - case .float: - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f32())" - case .double: - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f64())" - case .bool, .int, .int32, .int64, .uint, .uint32, .uint64: - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - } - case .swiftStruct(let nestedName): - return "Optional<\(raw: nestedName)>.bridgeJSLiftParameter(_swift_js_pop_i32())" - case .swiftHeapObject(let className): - return - "Optional<\(raw: className)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_pointer())" - case .associatedValueEnum(let enumName): - return - "Optional<\(raw: enumName)>.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" - case .jsObject: - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" + case .string, .int, .uint, .bool, .float, .double, .jsObject(nil), .jsValue, + .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: + return "\(raw: typeName)<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" + case .jsObject(let className?): + return "\(raw: typeName).bridgeJSLiftParameter().map { \(raw: className)(unsafelyWrapping: $0) }" case .array(let elementType): let arrayLift = liftArrayExpression(elementType: elementType) let swiftTypeName = elementType.swiftType + let absentExpr = + kind == .null + ? "\(typeName)<[\(swiftTypeName)]>.none" : "\(typeName)<[\(swiftTypeName)]>.undefinedValue" return """ { let __isSome = _swift_js_pop_i32() if __isSome == 0 { - return Optional<[\(raw: swiftTypeName)]>.none + return \(raw: absentExpr) } else { return \(arrayLift) } }() """ - default: - // Fallback for other optional types - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" + case .nullable, .void, .namespaceEnum, .closure, .unsafePointer, .swiftProtocol: + fatalError("Invalid nullable wrapped type: \(wrappedType)") } } @@ -940,56 +914,25 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch type { - case .string: - return [ - "var __bjs_\(raw: varPrefix) = \(raw: accessor)", - "__bjs_\(raw: varPrefix).withUTF8 { ptr in _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) }", - ] - case .int, .uint: - return ["_swift_js_push_i32(Int32(\(raw: accessor)))"] - case .bool: - return ["_swift_js_push_i32(\(raw: accessor) ? 1 : 0)"] - case .float: - return ["_swift_js_push_f32(\(raw: accessor))"] - case .double: - return ["_swift_js_push_f64(\(raw: accessor))"] - case .jsObject: - return ["_swift_js_push_i32(\(raw: accessor).bridgeJSLowerReturn())"] - case .swiftHeapObject: - return ["_swift_js_push_pointer(\(raw: accessor).bridgeJSLowerReturn())"] - case .unsafePointer: - return ["_swift_js_push_pointer(\(raw: accessor).bridgeJSLowerReturn())"] + case .string, .int, .uint, .bool, .float, .double, .jsValue: + return ["\(raw: accessor).bridgeJSLowerStackReturn()"] + case .jsObject(nil): + return ["\(raw: accessor).bridgeJSLowerStackReturn()"] + case .jsObject(_?): + return ["\(raw: accessor).jsObject.bridgeJSLowerStackReturn()"] + case .swiftHeapObject, .unsafePointer, .closure: + return ["\(raw: accessor).bridgeJSLowerStackReturn()"] case .swiftProtocol(let protocolName): let wrapperName = "Any\(protocolName)" - return ["_swift_js_push_i32((\(raw: accessor) as! \(raw: wrapperName)).bridgeJSLowerReturn())"] - case .caseEnum: - return ["_swift_js_push_i32(Int32(\(raw: accessor).bridgeJSLowerParameter()))"] - case .rawValueEnum(_, let rawType): - switch rawType { - case .string: - return [ - "var __bjs_\(raw: varPrefix) = \(raw: accessor).rawValue", - "__bjs_\(raw: varPrefix).withUTF8 { ptr in _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) }", - ] - case .float: - return ["_swift_js_push_f32(\(raw: accessor).bridgeJSLowerParameter())"] - case .double: - return ["_swift_js_push_f64(\(raw: accessor).bridgeJSLowerParameter())"] - default: - return ["_swift_js_push_i32(Int32(\(raw: accessor).bridgeJSLowerParameter()))"] - } - case .associatedValueEnum: - return ["\(raw: accessor).bridgeJSLowerReturn()"] - case .swiftStruct: + return ["(\(raw: accessor) as! \(raw: wrapperName)).bridgeJSLowerStackReturn()"] + case .caseEnum, .rawValueEnum: + return ["\(raw: accessor).bridgeJSLowerStackReturn()"] + case .associatedValueEnum, .swiftStruct: return ["\(raw: accessor).bridgeJSLowerReturn()"] - case .optional(let wrappedType): + case .nullable(let wrappedType, _): return lowerOptionalStatements(wrappedType: wrappedType, accessor: accessor, varPrefix: varPrefix) - case .void: + case .void, .namespaceEnum: return [] - case .namespaceEnum: - return [] - case .closure: - return ["_swift_js_push_pointer(\(raw: accessor).bridgeJSLowerReturn())"] case .array(let elementType): return lowerArrayStatements(elementType: elementType, accessor: accessor, varPrefix: varPrefix) } @@ -999,6 +942,31 @@ struct StackCodegen { elementType: BridgeType, accessor: String, varPrefix: String + ) -> [CodeBlockItemSyntax] { + switch elementType { + case .int, .uint, .float, .double, .string, .bool, .jsValue, + .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return ["\(raw: accessor).bridgeJSLowerReturn()"] + case .jsObject(_?): + return ["\(raw: accessor).map { $0.jsObject }.bridgeJSLowerReturn()"] + case .swiftProtocol(let protocolName): + return ["\(raw: accessor).map { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"] + case .nullable, .array, .closure: + return lowerArrayStatementsInline( + elementType: elementType, + accessor: accessor, + varPrefix: varPrefix + ) + case .void, .namespaceEnum: + fatalError("Invalid array element type: \(elementType)") + } + } + + private func lowerArrayStatementsInline( + elementType: BridgeType, + accessor: String, + varPrefix: String ) -> [CodeBlockItemSyntax] { var statements: [CodeBlockItemSyntax] = [] let elementVarName = "__bjs_elem_\(varPrefix)" @@ -1047,43 +1015,22 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch wrappedType { - case .string: - return [ - "var __bjs_str_\(raw: varPrefix) = \(raw: unwrappedVar)", - "__bjs_str_\(raw: varPrefix).withUTF8 { ptr in _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) }", - ] - case .int, .uint: - return ["_swift_js_push_i32(Int32(\(raw: unwrappedVar)))"] - case .bool: - return ["_swift_js_push_i32(\(raw: unwrappedVar) ? 1 : 0)"] - case .float: - return ["_swift_js_push_f32(\(raw: unwrappedVar))"] - case .double: - return ["_swift_js_push_f64(\(raw: unwrappedVar))"] - case .caseEnum: - return ["_swift_js_push_i32(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - case .rawValueEnum(_, let rawType): - switch rawType { - case .string: - return [ - "var __bjs_str_\(raw: varPrefix) = \(raw: unwrappedVar).rawValue", - "__bjs_str_\(raw: varPrefix).withUTF8 { ptr in _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) }", - ] - case .float: - return ["_swift_js_push_f32(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - case .double: - return ["_swift_js_push_f64(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - default: - return ["_swift_js_push_i32(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - } + case .string, .int, .uint, .bool, .float, .double, .jsValue: + return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] + case .caseEnum, .rawValueEnum: + // Enums conform to _BridgedSwiftStackType + return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] case .swiftStruct: return ["\(raw: unwrappedVar).bridgeJSLowerReturn()"] case .swiftHeapObject: - return ["_swift_js_push_pointer(\(raw: unwrappedVar).bridgeJSLowerReturn())"] + return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] case .associatedValueEnum: + // Push payloads via bridgeJSLowerParameter(), then push the returned case ID return ["_swift_js_push_i32(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - case .jsObject: - return ["_swift_js_push_i32(\(raw: unwrappedVar).bridgeJSLowerReturn())"] + case .jsObject(nil): + return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] + case .jsObject(_?): + return ["\(raw: unwrappedVar).jsObject.bridgeJSLowerStackReturn()"] case .array(let elementType): return lowerArrayStatements(elementType: elementType, accessor: unwrappedVar, varPrefix: varPrefix) default: @@ -1150,7 +1097,17 @@ struct EnumCodegen { } private func renderRawValueEnumHelpers(_ enumDef: ExportedEnum) -> DeclSyntax { - return "extension \(raw: enumDef.swiftCallName): _BridgedSwiftEnumNoPayload {}" + let typeName = enumDef.swiftCallName + guard enumDef.rawType != nil else { + return """ + extension \(raw: typeName): _BridgedSwiftEnumNoPayload {} + """ + } + // When rawType is present, conform to _BridgedSwiftRawValueEnum which provides + // default implementations for _BridgedSwiftStackType methods via protocol extension. + return """ + extension \(raw: typeName): _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} + """ } private func renderAssociatedValueEnumHelpers(_ enumDef: ExportedEnum) -> DeclSyntax { @@ -1264,9 +1221,11 @@ struct EnumCodegen { .map { index, associatedValue in "let \(associatedValue.label ?? "param\(index)")" } .joined(separator: ", ") cases.append("case .\(enumCase.name)(\(pattern)):") - cases.append("_swift_js_push_tag(Int32(\(caseIndex)))") let payloadCode = generatePayloadPushingCode(associatedValues: enumCase.associatedValues) cases.append(contentsOf: payloadCode) + // Push tag AFTER payloads so it's popped first (LIFO) by the JS lift function. + // This ensures nested enum tags don't overwrite the outer tag. + cases.append("_swift_js_push_tag(Int32(\(caseIndex)))") } } return cases @@ -1647,13 +1606,15 @@ extension BridgeType { case .float: return "Float" case .double: return "Double" case .string: return "String" + case .jsValue: return "JSValue" case .jsObject(nil): return "JSObject" case .jsObject(let name?): return name case .swiftHeapObject(let name): return name case .unsafePointer(let ptr): return ptr.swiftType case .swiftProtocol(let name): return "Any\(name)" case .void: return "Void" - case .optional(let wrappedType): return "Optional<\(wrappedType.swiftType)>" + case .nullable(let wrappedType, let kind): + return kind == .null ? "Optional<\(wrappedType.swiftType)>" : "JSUndefinedOr<\(wrappedType.swiftType)>" case .array(let elementType): return "[\(elementType.swiftType)]" case .caseEnum(let name): return name case .rawValueEnum(let name, _): return name @@ -1676,6 +1637,7 @@ extension BridgeType { static let double = LiftingIntrinsicInfo(parameters: [("value", .f64)]) static let string = LiftingIntrinsicInfo(parameters: [("bytes", .i32), ("length", .i32)]) static let jsObject = LiftingIntrinsicInfo(parameters: [("value", .i32)]) + static let jsValue = LiftingIntrinsicInfo(parameters: [("kind", .i32), ("payload1", .i32), ("payload2", .f64)]) static let swiftHeapObject = LiftingIntrinsicInfo(parameters: [("value", .pointer)]) static let unsafePointer = LiftingIntrinsicInfo(parameters: [("pointer", .pointer)]) static let void = LiftingIntrinsicInfo(parameters: []) @@ -1693,11 +1655,12 @@ extension BridgeType { case .double: return .double case .string: return .string case .jsObject: return .jsObject + case .jsValue: return .jsValue case .swiftHeapObject: return .swiftHeapObject case .unsafePointer: return .unsafePointer case .swiftProtocol: return .jsObject case .void: return .void - case .optional(let wrappedType): + case .nullable(let wrappedType, _): var optionalParams: [(name: String, type: WasmCoreType)] = [("isSome", .i32)] optionalParams.append(contentsOf: try wrappedType.liftParameterInfo().parameters) return LiftingIntrinsicInfo(parameters: optionalParams) @@ -1726,6 +1689,7 @@ extension BridgeType { static let double = LoweringIntrinsicInfo(returnType: .f64) static let string = LoweringIntrinsicInfo(returnType: nil) static let jsObject = LoweringIntrinsicInfo(returnType: .i32) + static let jsValue = LoweringIntrinsicInfo(returnType: nil) static let swiftHeapObject = LoweringIntrinsicInfo(returnType: .pointer) static let unsafePointer = LoweringIntrinsicInfo(returnType: .pointer) static let void = LoweringIntrinsicInfo(returnType: nil) @@ -1745,11 +1709,12 @@ extension BridgeType { case .double: return .double case .string: return .string case .jsObject: return .jsObject + case .jsValue: return .jsValue case .swiftHeapObject: return .swiftHeapObject case .unsafePointer: return .unsafePointer case .swiftProtocol: return .jsObject case .void: return .void - case .optional: return .optional + case .nullable: return .optional case .caseEnum: return .caseEnum case .rawValueEnum(_, let rawType): return rawType.loweringIntrinsicInfo diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 7c391eea0..8db872c6e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -83,6 +83,8 @@ public struct ImportTS { var abiReturnType: WasmCoreType? // Track destructured variable names for multiple lowered parameters var destructuredVarNames: [String] = [] + // Stack-lowered parameters should be evaluated in reverse order to match LIFO stacks + var stackLoweringStmts: [CodeBlockItemSyntax] = [] init(moduleName: String, abiName: String, context: BridgeContext = .importTS) { self.moduleName = moduleName @@ -93,11 +95,6 @@ public struct ImportTS { func lowerParameter(param: Parameter) throws { let loweringInfo = try param.type.loweringParameterInfo(context: context) - // Generate destructured variable names for all lowered parameters - let destructuredNames = loweringInfo.loweredParameters.map { - "\(param.name)\($0.name.capitalizedFirstLetter)" - } - let initializerExpr: ExprSyntax switch param.type { case .closure(let signature): @@ -108,6 +105,33 @@ public struct ImportTS { initializerExpr = ExprSyntax("\(raw: param.name).bridgeJSLowerParameter()") } + if loweringInfo.loweredParameters.isEmpty { + let stmt = CodeBlockItemSyntax( + item: .decl( + DeclSyntax( + VariableDeclSyntax( + bindingSpecifier: .keyword(.let), + bindings: PatternBindingListSyntax { + PatternBindingSyntax( + pattern: PatternSyntax( + IdentifierPatternSyntax(identifier: .wildcardToken()) + ), + initializer: InitializerClauseSyntax(value: initializerExpr) + ) + } + ) + ) + ) + ) + stackLoweringStmts.insert(stmt, at: 0) + return + } + + // Generate destructured variable names for all lowered parameters + let destructuredNames = loweringInfo.loweredParameters.map { + "\(param.name)\($0.name.capitalizedFirstLetter)" + } + // Always add destructuring statement to body (unified for single and multiple) let pattern: PatternSyntax if destructuredNames.count == 1 { @@ -166,7 +190,9 @@ public struct ImportTS { } func call(returnType: BridgeType) throws { - // Build function call expression + let liftingInfo = try returnType.liftingReturnInfo(context: context) + body.append(contentsOf: stackLoweringStmts) + let callExpr = FunctionCallExprSyntax( calledExpression: ExprSyntax("\(raw: abiName)"), leftParen: .leftParenToken(), @@ -183,6 +209,8 @@ public struct ImportTS { } else if returnType.usesSideChannelForOptionalReturn() { // Side channel returns don't need "let ret =" body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) + } else if liftingInfo.valueToLift == nil { + body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) } else { body.append("let ret = \(raw: callExpr)") } @@ -398,6 +426,24 @@ public struct ImportTS { ] } + func renderStaticMethod(method: ImportedFunctionSkeleton) throws -> [DeclSyntax] { + let abiName = method.abiName(context: type, operation: "static") + let builder = CallJSEmission(moduleName: moduleName, abiName: abiName) + for param in method.parameters { + try builder.lowerParameter(param: param) + } + try builder.call(returnType: method.returnType) + try builder.liftReturnValue(returnType: method.returnType) + topLevelDecls.append(builder.renderImportDecl()) + return [ + builder.renderThunkDecl( + name: Self.thunkName(type: type, method: method), + parameters: method.parameters, + returnType: method.returnType + ) + ] + } + func renderConstructorDecl(constructor: ImportedConstructorSkeleton) throws -> [DeclSyntax] { let builder = CallJSEmission(moduleName: moduleName, abiName: constructor.abiName(context: type)) for param in constructor.parameters { @@ -462,6 +508,10 @@ public struct ImportTS { decls.append(contentsOf: try renderConstructorDecl(constructor: constructor)) } + for method in type.staticMethods { + decls.append(contentsOf: try renderStaticMethod(method: method)) + } + for getter in type.getters { decls.append(try renderGetterDecl(getter: getter)) } @@ -861,6 +911,11 @@ extension BridgeType { static let double = LoweringParameterInfo(loweredParameters: [("value", .f64)]) static let string = LoweringParameterInfo(loweredParameters: [("value", .i32)]) static let jsObject = LoweringParameterInfo(loweredParameters: [("value", .i32)]) + static let jsValue = LoweringParameterInfo(loweredParameters: [ + ("kind", .i32), + ("payload1", .i32), + ("payload2", .f64), + ]) static let void = LoweringParameterInfo(loweredParameters: []) } @@ -872,6 +927,7 @@ extension BridgeType { case .double: return .double case .string: return .string case .jsObject: return .jsObject + case .jsValue: return .jsValue case .void: return .void case .closure: // Swift closure is boxed and passed to JS as a pointer. @@ -900,13 +956,8 @@ extension BridgeType { return LoweringParameterInfo(loweredParameters: [("value", .i32)]) } case .rawValueEnum(_, let rawType): - switch context { - case .importTS: - return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) - case .exportSwift: - // For protocol export we return .i32 for String raw value type instead of nil - return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) - } + let wasmType = rawType.wasmCoreType ?? .i32 + return LoweringParameterInfo(loweredParameters: [("value", wasmType)]) case .associatedValueEnum: switch context { case .importTS: @@ -924,23 +975,13 @@ extension BridgeType { } case .namespaceEnum: throw BridgeJSCoreError("Namespace enums cannot be used as parameters") - case .optional(let wrappedType): - switch context { - case .importTS: - throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift: - let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) - var params = [("isSome", WasmCoreType.i32)] - params.append(contentsOf: wrappedInfo.loweredParameters) - return LoweringParameterInfo(loweredParameters: params) - } + case .nullable(let wrappedType, _): + let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) + var params = [("isSome", WasmCoreType.i32)] + params.append(contentsOf: wrappedInfo.loweredParameters) + return LoweringParameterInfo(loweredParameters: params) case .array: - switch context { - case .importTS: - throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift: - return LoweringParameterInfo(loweredParameters: []) - } + return LoweringParameterInfo(loweredParameters: []) } } @@ -953,6 +994,7 @@ extension BridgeType { static let double = LiftingReturnInfo(valueToLift: .f64) static let string = LiftingReturnInfo(valueToLift: .i32) static let jsObject = LiftingReturnInfo(valueToLift: .i32) + static let jsValue = LiftingReturnInfo(valueToLift: nil) static let void = LiftingReturnInfo(valueToLift: nil) } @@ -966,6 +1008,7 @@ extension BridgeType { case .double: return .double case .string: return .string case .jsObject: return .jsObject + case .jsValue: return .jsValue case .void: return .void case .closure: // JS returns a callback ID for closures, which Swift lifts to a typed closure. @@ -994,13 +1037,8 @@ extension BridgeType { return LiftingReturnInfo(valueToLift: .i32) } case .rawValueEnum(_, let rawType): - switch context { - case .importTS: - return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) - case .exportSwift: - // For protocol export we return .i32 for String raw value type instead of nil - return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) - } + let wasmType = rawType.wasmCoreType ?? .i32 + return LiftingReturnInfo(valueToLift: wasmType) case .associatedValueEnum: switch context { case .importTS: @@ -1018,21 +1056,11 @@ extension BridgeType { } case .namespaceEnum: throw BridgeJSCoreError("Namespace enums cannot be used as return values") - case .optional(let wrappedType): - switch context { - case .importTS: - throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift: - let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) - return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) - } + case .nullable(let wrappedType, _): + let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) + return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) case .array: - switch context { - case .importTS: - throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift: - return LiftingReturnInfo(valueToLift: nil) - } + return LiftingReturnInfo(valueToLift: nil) } } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index ea79d3f3b..3de74f74b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -66,13 +66,14 @@ public final class SwiftToSkeleton { ) } - importedFiles.append( - ImportedFileSkeleton( - functions: importCollector.importedFunctions, - types: importCollector.importedTypes, - globalGetters: importCollector.importedGlobalGetters - ) + let importedFile = ImportedFileSkeleton( + functions: importCollector.importedFunctions, + types: importCollector.importedTypes, + globalGetters: importCollector.importedGlobalGetters ) + if !importedFile.isEmpty { + importedFiles.append(importedFile) + } exportCollector.finalize(&exported) } @@ -90,7 +91,8 @@ public final class SwiftToSkeleton { return module }() - return BridgeJSSkeleton(moduleName: moduleName, exported: exported, imported: importedSkeleton) + let exportedSkeleton: ExportedSkeleton? = exported.isEmpty ? nil : exported + return BridgeJSSkeleton(moduleName: moduleName, exported: exportedSkeleton, imported: importedSkeleton) } func lookupType(for type: TypeSyntax, errors: inout [DiagnosticError]) -> BridgeType? { @@ -130,7 +132,31 @@ public final class SwiftToSkeleton { if let optionalType = type.as(OptionalTypeSyntax.self) { let wrappedType = optionalType.wrappedType if let baseType = lookupType(for: wrappedType, errors: &errors) { - return .optional(baseType) + return .nullable(baseType, .null) + } + } + // JSUndefinedOr + if let identifierType = type.as(IdentifierTypeSyntax.self), + identifierType.name.text == "JSUndefinedOr", + let genericArgs = identifierType.genericArgumentClause?.arguments, + genericArgs.count == 1, + let argType = TypeSyntax(genericArgs.first?.argument) + { + if let baseType = lookupType(for: argType, errors: &errors) { + return .nullable(baseType, .undefined) + } + } + // JavaScriptKit.JSUndefinedOr + if let memberType = type.as(MemberTypeSyntax.self), + let baseType = memberType.baseType.as(IdentifierTypeSyntax.self), + baseType.name.text == "JavaScriptKit", + memberType.name.text == "JSUndefinedOr", + let genericArgs = memberType.genericArgumentClause?.arguments, + genericArgs.count == 1, + let argType = TypeSyntax(genericArgs.first?.argument) + { + if let wrappedType = lookupType(for: argType, errors: &errors) { + return .nullable(wrappedType, .undefined) } } // Optional @@ -141,7 +167,7 @@ public final class SwiftToSkeleton { let argType = TypeSyntax(genericArgs.first?.argument) { if let baseType = lookupType(for: argType, errors: &errors) { - return .optional(baseType) + return .nullable(baseType, .null) } } // Swift.Optional @@ -154,7 +180,7 @@ public final class SwiftToSkeleton { let argType = TypeSyntax(genericArgs.first?.argument) { if let wrappedType = lookupType(for: argType, errors: &errors) { - return .optional(wrappedType) + return .nullable(wrappedType, .null) } } // [T] @@ -368,22 +394,28 @@ private enum ExportSwiftConstants { static let supportedRawTypes = SwiftEnumRawType.allCases.map { $0.rawValue } } +extension AttributeSyntax { + /// The attribute name as text when it is a simple identifier (e.g. "JS", "JSFunction"). + /// Prefer this over `attributeName.trimmedDescription` for name checks to avoid unnecessary string work. + fileprivate var attributeNameText: String? { + attributeName.as(IdentifierTypeSyntax.self)?.name.text + } +} + extension AttributeListSyntax { func hasJSAttribute() -> Bool { firstJSAttribute != nil } var firstJSAttribute: AttributeSyntax? { - first(where: { - $0.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JS" - })?.as(AttributeSyntax.self) + first(where: { $0.as(AttributeSyntax.self)?.attributeNameText == "JS" })?.as(AttributeSyntax.self) } /// Returns true if any attribute has the given name (e.g. "JSClass"). func hasAttribute(name: String) -> Bool { contains { attribute in guard let syntax = attribute.as(AttributeSyntax.self) else { return false } - return syntax.attributeName.trimmedDescription == name + return syntax.attributeNameText == name } } } @@ -535,7 +567,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { switch type { case .caseEnum(let name), .rawValueEnum(let name, _), .associatedValueEnum(let name): enumName = name - case .optional(let wrappedType): + case .nullable(let wrappedType, _): switch wrappedType { case .caseEnum(let name), .rawValueEnum(let name, _), .associatedValueEnum(let name): enumName = name @@ -584,7 +616,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { let expr = defaultClause.value if expr.is(NilLiteralExprSyntax.self) { - guard case .optional(_) = type else { + guard case .nullable = type else { diagnose( node: expr, message: "nil is only valid for optional parameters", @@ -640,10 +672,10 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { let isStructType: Bool let expectedTypeName: String? switch type { - case .swiftStruct(let name), .optional(.swiftStruct(let name)): + case .swiftStruct(let name), .nullable(.swiftStruct(let name), _): isStructType = true expectedTypeName = name.split(separator: ".").last.map(String.init) - case .swiftHeapObject(let name), .optional(.swiftHeapObject(let name)): + case .swiftHeapObject(let name), .nullable(.swiftHeapObject(let name), _): isStructType = false expectedTypeName = name.split(separator: ".").last.map(String.init) default: @@ -779,7 +811,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { switch type { case .array(let element): elementType = element - case .optional(.array(let element)): + case .nullable(.array(let element), _): elementType = element default: diagnose( @@ -834,11 +866,11 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { continue } } - if case .optional(let wrappedType) = type, wrappedType.isOptional { + if case .nullable(let wrappedType, _) = type, wrappedType.isOptional { diagnoseNestedOptional(node: param.type, type: param.type.trimmedDescription) continue } - if case .optional(let wrappedType) = type, wrappedType.isOptional { + if case .nullable(let wrappedType, _) = type, wrappedType.isOptional { diagnoseNestedOptional(node: param.type, type: param.type.trimmedDescription) continue } @@ -960,7 +992,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { if let returnClause = node.signature.returnClause { let resolvedType = withLookupErrors { self.parent.lookupType(for: returnClause.type, errors: &$0) } - if let type = resolvedType, case .optional(let wrappedType) = type, wrappedType.isOptional { + if let type = resolvedType, case .nullable(let wrappedType, _) = type, wrappedType.isOptional { diagnoseNestedOptional(node: returnClause.type, type: returnClause.type.trimmedDescription) return nil } @@ -990,7 +1022,8 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { } let isNamespaceEnum = exportedEnumByName[enumKey]?.cases.isEmpty ?? true - staticContext = isNamespaceEnum ? .namespaceEnum : .enumName(enumName) + let swiftCallName = exportedEnumByName[enumKey]?.swiftCallName ?? enumName + staticContext = isNamespaceEnum ? .namespaceEnum(swiftCallName) : .enumName(enumName) case .protocolBody(_, _): return nil case .structBody(let structName, _): @@ -1187,7 +1220,10 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { return .skipChildren } let isNamespaceEnum = exportedEnumByName[enumKey]?.cases.isEmpty ?? true - staticContext = isStatic ? (isNamespaceEnum ? .namespaceEnum : .enumName(enumName)) : nil + // Use swiftCallName for the full Swift call path (handles nested enums correctly) + let swiftCallName = exportedEnumByName[enumKey]?.swiftCallName ?? enumName + staticContext = + isStatic ? (isNamespaceEnum ? .namespaceEnum(swiftCallName) : .enumName(swiftCallName)) : nil case .topLevel: diagnose(node: node, message: "@JS var must be inside a @JS class or enum") return .skipChildren @@ -1392,18 +1428,20 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { for enumCase in exportedEnum.cases { for associatedValue in enumCase.associatedValues { switch associatedValue.type { - case .string, .int, .float, .double, .bool: + case .string, .int, .float, .double, .bool, .caseEnum, .rawValueEnum, + .swiftStruct, .swiftHeapObject, .jsObject, .associatedValueEnum, .array: break - case .optional(let wrappedType): + case .nullable(let wrappedType, _): switch wrappedType { - case .string, .int, .float, .double, .bool: + case .string, .int, .float, .double, .bool, .caseEnum, .rawValueEnum, + .swiftStruct, .swiftHeapObject, .jsObject, .associatedValueEnum, .array: break default: diagnose( node: node, message: "Unsupported associated value type: \(associatedValue.type.swiftType)", hint: - "Only primitive types and optional primitives (String?, Int?, Float?, Double?, Bool?) are supported in associated-value enums" + "Only primitive types, enums, structs, classes, JSObject, arrays, and their optionals are supported in associated-value enums" ) } default: @@ -1411,7 +1449,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { node: node, message: "Unsupported associated value type: \(associatedValue.type.swiftType)", hint: - "Only primitive types and optional primitives (String?, Int?, Float?, Double?, Bool?) are supported in associated-value enums" + "Only primitive types, enums, structs, classes, JSObject, arrays, and their optionals are supported in associated-value enums" ) } } @@ -1583,7 +1621,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { if let returnClause = node.signature.returnClause { let resolvedType = withLookupErrors { self.parent.lookupType(for: returnClause.type, errors: &$0) } - if let type = resolvedType, case .optional(let wrappedType) = type, wrappedType.isOptional { + if let type = resolvedType, case .nullable(let wrappedType, _) = type, wrappedType.isOptional { diagnoseNestedOptional(node: returnClause.type, type: returnClause.type.trimmedDescription) return nil } @@ -1808,7 +1846,7 @@ fileprivate extension BridgeType { switch (self, expectedType) { case let (lhs, rhs) where lhs == rhs: return true - case (.optional(let wrapped), expectedType): + case (.nullable(let wrapped, _), expectedType): return wrapped == expectedType default: return false @@ -1852,7 +1890,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private let inputFilePath: String private var jsClassNames: Set private let parent: SwiftToSkeleton - // MARK: - State Management enum State { @@ -1872,6 +1909,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { let from: JSImportFrom? var constructor: ImportedConstructorSkeleton? var methods: [ImportedFunctionSkeleton] + var staticMethods: [ImportedFunctionSkeleton] var getters: [ImportedGetterSkeleton] var setters: [ImportedSetterSkeleton] } @@ -1886,9 +1924,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } static func firstJSFunctionAttribute(_ attributes: AttributeListSyntax?) -> AttributeSyntax? { - attributes?.first { attribute in - attribute.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JSFunction" - }?.as(AttributeSyntax.self) + firstAttribute(attributes, named: "JSFunction") } static func hasJSGetterAttribute(_ attributes: AttributeListSyntax?) -> Bool { @@ -1896,9 +1932,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } static func firstJSGetterAttribute(_ attributes: AttributeListSyntax?) -> AttributeSyntax? { - attributes?.first { attribute in - attribute.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JSGetter" - }?.as(AttributeSyntax.self) + firstAttribute(attributes, named: "JSGetter") } static func hasJSSetterAttribute(_ attributes: AttributeListSyntax?) -> Bool { @@ -1906,9 +1940,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } static func firstJSSetterAttribute(_ attributes: AttributeListSyntax?) -> AttributeSyntax? { - attributes?.first { attribute in - attribute.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JSSetter" - }?.as(AttributeSyntax.self) + firstAttribute(attributes, named: "JSSetter") } static func hasJSClassAttribute(_ attributes: AttributeListSyntax?) -> Bool { @@ -1916,16 +1948,18 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } static func firstJSClassAttribute(_ attributes: AttributeListSyntax?) -> AttributeSyntax? { - attributes?.first { attribute in - attribute.as(AttributeSyntax.self)?.attributeName.trimmedDescription == "JSClass" - }?.as(AttributeSyntax.self) + firstAttribute(attributes, named: "JSClass") + } + + static func firstAttribute(_ attributes: AttributeListSyntax?, named name: String) -> AttributeSyntax? { + attributes?.first { $0.as(AttributeSyntax.self)?.attributeNameText == name }?.as(AttributeSyntax.self) } static func hasAttribute(_ attributes: AttributeListSyntax?, name: String) -> Bool { guard let attributes else { return false } return attributes.contains { attribute in guard let syntax = attribute.as(AttributeSyntax.self) else { return false } - return syntax.attributeName.trimmedDescription == name + return syntax.attributeNameText == name } } @@ -1983,7 +2017,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { DiagnosticError( node: node, message: "@\(attributeName) declarations must be throws.", - hint: "Declare the function as 'throws (JSException)'." + hint: "Declare the function as 'throws(JSException)'." ) ) return nil @@ -2090,6 +2124,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: nil, constructor: nil, methods: [], + staticMethods: [], getters: [], setters: [] ) @@ -2103,6 +2138,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: from, constructor: nil, methods: [], + staticMethods: [], getters: [], setters: [] ) @@ -2117,6 +2153,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: type.from, constructor: type.constructor, methods: type.methods, + staticMethods: type.staticMethods, getters: type.getters, setters: type.setters, documentation: nil @@ -2161,12 +2198,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { // MARK: - Visitor Methods - override func visit(_ node: ExtensionDeclSyntax) -> SyntaxVisitorContinueKind { - let typeName = node.extendedType.trimmedDescription - collectStaticMembers(in: node.memberBlock.members, typeName: typeName) - return .skipChildren - } - override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind { switch state { case .topLevel: @@ -2187,7 +2218,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private func handleTopLevelFunction(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind { if let jsFunction = AttributeChecker.firstJSFunctionAttribute(node.attributes), - let function = parseFunction(jsFunction, node, enclosingTypeName: nil, isStaticMember: true) + let function = parseFunction(jsFunction, node) { importedFunctions.append(function) return .skipChildren @@ -2212,13 +2243,11 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { type: inout CurrentType ) -> Bool { if let jsFunction = AttributeChecker.firstJSFunctionAttribute(node.attributes) { - if isStaticMember { - parseFunction(jsFunction, node, enclosingTypeName: typeName, isStaticMember: true).map { - importedFunctions.append($0) - } - } else { - parseFunction(jsFunction, node, enclosingTypeName: typeName, isStaticMember: false).map { - type.methods.append($0) + if let method = parseFunction(jsFunction, node) { + if isStaticMember { + type.staticMethods.append(method) + } else { + type.methods.append(method) } } return true @@ -2309,38 +2338,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { } } - // MARK: - Member Collection - - private func collectStaticMembers(in members: MemberBlockItemListSyntax, typeName: String) { - for member in members { - if let function = member.decl.as(FunctionDeclSyntax.self) { - if let jsFunction = AttributeChecker.firstJSFunctionAttribute(function.attributes), - let parsed = parseFunction(jsFunction, function, enclosingTypeName: typeName, isStaticMember: true) - { - importedFunctions.append(parsed) - } else if AttributeChecker.hasJSSetterAttribute(function.attributes) { - errors.append( - DiagnosticError( - node: function, - message: - "@JSSetter is not supported for static members. Use it only for instance members in @JSClass types." - ) - ) - } - } else if let variable = member.decl.as(VariableDeclSyntax.self), - AttributeChecker.hasJSGetterAttribute(variable.attributes) - { - errors.append( - DiagnosticError( - node: variable, - message: - "@JSGetter is not supported for static members. Use it only for instance members in @JSClass types." - ) - ) - } - } - } - // MARK: - Parsing Methods private func parseConstructor( @@ -2361,8 +2358,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private func parseFunction( _ jsFunction: AttributeSyntax, _ node: FunctionDeclSyntax, - enclosingTypeName: String?, - isStaticMember: Bool ) -> ImportedFunctionSkeleton? { guard validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSFunction") != nil else { @@ -2372,12 +2367,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { let baseName = SwiftToSkeleton.normalizeIdentifier(node.name.text) let jsName = AttributeChecker.extractJSName(from: jsFunction) let from = AttributeChecker.extractJSImportFrom(from: jsFunction) - let name: String - if isStaticMember, let enclosingTypeName { - name = "\(enclosingTypeName)_\(baseName)" - } else { - name = baseName - } + let name = baseName let parameters = parseParameters(from: node.signature.parameterClause) let returnType: BridgeType diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 60b55cd47..7a5e02f2d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -11,6 +11,7 @@ public struct BridgeJSLink { var skeletons: [BridgeJSSkeleton] = [] let sharedMemory: Bool private let namespaceBuilder = NamespaceBuilder() + private let intrinsicRegistry = JSIntrinsicRegistry() public init( skeletons: [BridgeJSSkeleton] = [], @@ -245,7 +246,7 @@ public struct BridgeJSLink { "let \(JSGlueVariableScope.reservedStorageToReturnOptionalFloat);", "let \(JSGlueVariableScope.reservedStorageToReturnOptionalDouble);", "let \(JSGlueVariableScope.reservedStorageToReturnOptionalHeapObject);", - "let \(JSGlueVariableScope.reservedTmpRetTag);", + "let \(JSGlueVariableScope.reservedTmpRetTag) = [];", "let \(JSGlueVariableScope.reservedTmpRetStrings) = [];", "let \(JSGlueVariableScope.reservedTmpRetInts) = [];", "let \(JSGlueVariableScope.reservedTmpRetF32s) = [];", @@ -297,7 +298,7 @@ public struct BridgeJSLink { switch type { case .closure: return true - case .optional(let wrapped): + case .nullable(let wrapped, _): return containsClosureType(in: wrapped) default: return false @@ -387,7 +388,7 @@ public struct BridgeJSLink { printer.write("}") printer.write("bjs[\"swift_js_push_tag\"] = function(tag) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetTag) = tag;") + printer.write("\(JSGlueVariableScope.reservedTmpRetTag).push(tag);") } printer.write("}") printer.write("bjs[\"swift_js_push_i32\"] = function(v) {") @@ -746,7 +747,7 @@ public struct BridgeJSLink { collectClosureSignatures(from: paramType, into: &signatures) } collectClosureSignatures(from: signature.returnType, into: &signatures) - case .optional(let wrapped): + case .nullable(let wrapped, _): collectClosureSignatures(from: wrapped, into: &signatures) default: break @@ -758,13 +759,13 @@ public struct BridgeJSLink { functionName: String ) -> [String] { let printer = CodeFragmentPrinter() - let scope = JSGlueVariableScope() + let scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) let cleanupCode = CodeFragmentPrinter() // Build parameter list for invoke function var invokeParams: [String] = ["callbackId"] for (index, paramType) in signature.parameters.enumerated() { - if case .optional = paramType { + if case .nullable = paramType { invokeParams.append("param\(index)IsSome") invokeParams.append("param\(index)Value") } else { @@ -782,7 +783,7 @@ public struct BridgeJSLink { for (index, paramType) in signature.parameters.enumerated() { let fragment = try! IntrinsicJSFragment.closureLiftParameter(type: paramType) let args: [String] - if case .optional = paramType { + if case .nullable = paramType { args = ["param\(index)IsSome", "param\(index)Value", "param\(index)"] } else { args = ["param\(index)Id", "param\(index)"] @@ -827,7 +828,7 @@ public struct BridgeJSLink { functionName: String ) -> [String] { let printer = CodeFragmentPrinter() - let scope = JSGlueVariableScope() + let scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) let cleanupCode = CodeFragmentPrinter() printer.nextLine() @@ -1036,23 +1037,49 @@ public struct BridgeJSLink { ) printer.write(lines: topLevelNamespaceCode) + let propertyAssignments = try generateNamespacePropertyAssignments( + data: data, + exportedSkeletons: exportedSkeletons, + namespaceBuilder: namespaceBuilder + ) + // Main function declaration printer.write("export async function createInstantiator(options, \(JSGlueVariableScope.reservedSwift)) {") printer.indent { printer.write(lines: generateVariableDeclarations()) + let bodyPrinter = CodeFragmentPrinter() let allStructs = exportedSkeletons.flatMap { $0.structs } for structDef in allStructs { let structPrinter = CodeFragmentPrinter() - let structScope = JSGlueVariableScope() + let structScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) let structCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.structHelper(structDefinition: structDef, allStructs: allStructs) _ = fragment.printCode([structDef.name], structScope, structPrinter, structCleanup) - printer.write(lines: structPrinter.lines) + bodyPrinter.write(lines: structPrinter.lines) + } + + let allAssocEnums = exportedSkeletons.flatMap { + $0.enums.filter { $0.enumType == .associatedValue } + } + for enumDef in allAssocEnums { + let enumPrinter = CodeFragmentPrinter() + let enumScope = JSGlueVariableScope() + let enumCleanup = CodeFragmentPrinter() + let fragment = IntrinsicJSFragment.associatedValueEnumHelperFactory(enumDefinition: enumDef) + _ = fragment.printCode([enumDef.valuesName], enumScope, enumPrinter, enumCleanup) + bodyPrinter.write(lines: enumPrinter.lines) + } + bodyPrinter.nextLine() + bodyPrinter.write(contentsOf: generateAddImports(needsImportsObject: data.needsImportsObject)) + + if !intrinsicRegistry.isEmpty { + printer.write(lines: intrinsicRegistry.emitLines()) + printer.nextLine() } - printer.nextLine() - printer.write(contentsOf: generateAddImports(needsImportsObject: data.needsImportsObject)) + + printer.write(lines: bodyPrinter.lines) } printer.indent() @@ -1079,8 +1106,6 @@ public struct BridgeJSLink { "\(JSGlueVariableScope.reservedMemory) = \(JSGlueVariableScope.reservedInstance).exports.memory;", ]) printer.nextLine() - // Enum helpers section - printer.write(contentsOf: enumHelperAssignments()) // Error handling printer.write("\(JSGlueVariableScope.reservedSetException) = (error) => {") printer.indent { @@ -1094,28 +1119,24 @@ public struct BridgeJSLink { } // createExports method - try printer.indent { + printer.indent { printer.write(lines: [ "/** @param {WebAssembly.Instance} instance */", "createExports: (instance) => {", ]) - try printer.indent { + printer.indent { printer.write("const js = \(JSGlueVariableScope.reservedSwift).memory.heap;") printer.write(lines: data.classLines) - // Struct helpers must be initialized AFTER classes are defined (to allow _exports access) + // Struct and enum helpers must be initialized AFTER classes are defined (to allow _exports access) printer.write(contentsOf: structHelperAssignments()) + printer.write(contentsOf: enumHelperAssignments()) let namespaceInitCode = namespaceBuilder.buildNamespaceInitialization( exportedSkeletons: exportedSkeletons ) printer.write(lines: namespaceInitCode) - let propertyAssignments = try generateNamespacePropertyAssignments( - data: data, - exportedSkeletons: exportedSkeletons, - namespaceBuilder: namespaceBuilder - ) printer.write(lines: propertyAssignments) } printer.write("},") @@ -1128,6 +1149,7 @@ public struct BridgeJSLink { } public func link() throws -> (outputJs: String, outputDts: String) { + intrinsicRegistry.reset() let data = try collectLinkData() let outputJs = try generateJavaScript(data: data) let outputDts = generateTypeScript(data: data) @@ -1140,7 +1162,7 @@ public struct BridgeJSLink { for skeleton in skeletons.compactMap(\.exported) { for enumDef in skeleton.enums where enumDef.enumType == .associatedValue { printer.write( - "const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift));" + "const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers));" ) printer.write("\(JSGlueVariableScope.reservedEnumHelpers).\(enumDef.name) = \(enumDef.name)Helpers;") printer.nextLine() @@ -1222,6 +1244,7 @@ public struct BridgeJSLink { let hierarchicalLines = try namespaceBuilder.buildHierarchicalExportsObject( exportedSkeletons: exportedSkeletons, + intrinsicRegistry: intrinsicRegistry, renderFunctionImpl: { function in let (js, _) = try self.renderExportedFunction(function: function) return js @@ -1293,9 +1316,9 @@ public struct BridgeJSLink { let effects: Effects let scope: JSGlueVariableScope - init(effects: Effects) { + init(effects: Effects, intrinsicRegistry: JSIntrinsicRegistry) { self.effects = effects - self.scope = JSGlueVariableScope() + self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) self.body = CodeFragmentPrinter() self.cleanupCode = CodeFragmentPrinter() } @@ -1428,8 +1451,9 @@ public struct BridgeJSLink { return type.tsType case .swiftStruct(let name): return name.components(separatedBy: ".").last ?? name - case .optional(let wrapped): - return "\(resolveTypeScriptType(wrapped, exportedSkeletons: exportedSkeletons)) | null" + case .nullable(let wrapped, let kind): + let base = resolveTypeScriptType(wrapped, exportedSkeletons: exportedSkeletons) + return "\(base) | \(kind.absenceLiteral)" case .array(let elementType): let elementTypeStr = resolveTypeScriptType(elementType, exportedSkeletons: exportedSkeletons) // Parenthesize compound types so `[]` binds correctly in TypeScript @@ -1515,7 +1539,10 @@ public struct BridgeJSLink { try jsPrinter.indent { // Constructor as 'init' function if let constructor = structDefinition.constructor { - let thunkBuilder = ExportedThunkBuilder(effects: constructor.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: constructor.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in constructor.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1600,7 +1627,7 @@ public struct BridgeJSLink { _ = fragment.printCode([enumValuesName], scope, printer, cleanup) jsTopLevelLines.append(contentsOf: printer.lines) case .associatedValue: - let fragment = IntrinsicJSFragment.associatedValueEnumHelper(enumDefinition: enumDefinition) + let fragment = IntrinsicJSFragment.associatedValueEnumValues(enumDefinition: enumDefinition) _ = fragment.printCode([enumValuesName], scope, printer, cleanup) jsTopLevelLines.append(contentsOf: printer.lines) case .namespace: @@ -1751,12 +1778,17 @@ public struct BridgeJSLink { extension BridgeJSLink { - func renderExportedFunction(function: ExportedFunction) throws -> (js: [String], dts: [String]) { + func renderExportedFunction( + function: ExportedFunction + ) throws -> (js: [String], dts: [String]) { if function.effects.isStatic, let staticContext = function.staticContext { return try renderStaticFunction(function: function, staticContext: staticContext) } - let thunkBuilder = ExportedThunkBuilder(effects: function.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: function.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in function.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1789,7 +1821,10 @@ extension BridgeJSLink { return try renderEnumStaticFunction(function: function, enumName: enumName) case .namespaceEnum: if let namespace = function.namespace, !namespace.isEmpty { - return try renderNamespaceFunction(function: function, namespace: namespace.joined(separator: ".")) + return try renderNamespaceFunction( + function: function, + namespace: namespace.joined(separator: ".") + ) } else { return try renderExportedFunction(function: function) } @@ -1800,7 +1835,10 @@ extension BridgeJSLink { function: ExportedFunction, className: String ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ExportedThunkBuilder(effects: function.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: function.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in function.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1828,7 +1866,10 @@ extension BridgeJSLink { function: ExportedFunction, enumName: String ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ExportedThunkBuilder(effects: function.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: function.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in function.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1856,7 +1897,10 @@ extension BridgeJSLink { function: ExportedFunction, namespace: String ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ExportedThunkBuilder(effects: function.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: function.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in function.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1878,7 +1922,10 @@ extension BridgeJSLink { private func renderStaticMethodForExportObject( method: ExportedFunction ) throws -> [String] { - let thunkBuilder = ExportedThunkBuilder(effects: method.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: method.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in method.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1903,7 +1950,10 @@ extension BridgeJSLink { let propertyPrinter = CodeFragmentPrinter() // Generate getter - let getterThunkBuilder = ExportedThunkBuilder(effects: Effects(isAsync: false, isThrows: false)) + let getterThunkBuilder = ExportedThunkBuilder( + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry + ) let getterReturnExpr = try getterThunkBuilder.call( abiName: className != nil ? property.getterAbiName(className: className!) @@ -1920,7 +1970,8 @@ extension BridgeJSLink { // Generate setter if not readonly if !property.isReadonly { let setterThunkBuilder = ExportedThunkBuilder( - effects: Effects(isAsync: false, isThrows: false) + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry ) try setterThunkBuilder.lowerParameter( param: Parameter(label: "value", name: "value", type: property.type) @@ -1966,7 +2017,10 @@ extension BridgeJSLink { } if let constructor: ExportedConstructor = klass.constructor { - let thunkBuilder = ExportedThunkBuilder(effects: constructor.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: constructor.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in constructor.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -1998,7 +2052,10 @@ extension BridgeJSLink { for method in klass.methods { if method.effects.isStatic { - let thunkBuilder = ExportedThunkBuilder(effects: method.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: method.effects, + intrinsicRegistry: intrinsicRegistry + ) for param in method.parameters { try thunkBuilder.lowerParameter(param: param) } @@ -2021,7 +2078,10 @@ extension BridgeJSLink { ) } } else { - let thunkBuilder = ExportedThunkBuilder(effects: method.effects) + let thunkBuilder = ExportedThunkBuilder( + effects: method.effects, + intrinsicRegistry: intrinsicRegistry + ) thunkBuilder.lowerSelf() for param in method.parameters { try thunkBuilder.lowerParameter(param: param) @@ -2072,7 +2132,10 @@ extension BridgeJSLink { jsPrinter: CodeFragmentPrinter, dtsPrinter: CodeFragmentPrinter ) throws { - let getterThunkBuilder = ExportedThunkBuilder(effects: Effects(isAsync: false, isThrows: false)) + let getterThunkBuilder = ExportedThunkBuilder( + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry + ) if !isStatic { getterThunkBuilder.lowerSelf() } @@ -2094,7 +2157,10 @@ extension BridgeJSLink { // Generate setter if not readonly if !property.isReadonly { - let setterThunkBuilder = ExportedThunkBuilder(effects: Effects(isAsync: false, isThrows: false)) + let setterThunkBuilder = ExportedThunkBuilder( + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry + ) if !isStatic { setterThunkBuilder.lowerSelf() } @@ -2133,9 +2199,9 @@ extension BridgeJSLink { var parameterNames: [String] = [] var parameterForwardings: [String] = [] - init(context: BridgeContext = .importTS) { + init(context: BridgeContext = .importTS, intrinsicRegistry: JSIntrinsicRegistry) { self.body = CodeFragmentPrinter() - self.scope = JSGlueVariableScope() + self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) self.cleanupCode = CodeFragmentPrinter() self.context = context } @@ -2146,12 +2212,10 @@ extension BridgeJSLink { func liftParameter(param: Parameter) throws { let liftingFragment = try IntrinsicJSFragment.liftParameter(type: param.type, context: context) - assert( - liftingFragment.parameters.count >= 1, - "Lifting fragment should have at least one parameter to lift" - ) let valuesToLift: [String] - if liftingFragment.parameters.count == 1 { + if liftingFragment.parameters.count == 0 { + valuesToLift = [] + } else if liftingFragment.parameters.count == 1 { parameterNames.append(param.name) valuesToLift = [scope.variable(param.name)] } else { @@ -2246,11 +2310,19 @@ extension BridgeJSLink { ) } + func callStaticMethod(on objectExpr: String, name: String, returnType: BridgeType) throws -> String? { + let calleeExpr = Self.propertyAccessExpr(objectExpr: objectExpr, propertyName: name) + return try call( + calleeExpr: calleeExpr, + returnType: returnType + ) + } + func callPropertyGetter(name: String, returnType: BridgeType) throws -> String? { let objectExpr = "\(JSGlueVariableScope.reservedSwift).memory.getObject(self)" let accessExpr = Self.propertyAccessExpr(objectExpr: objectExpr, propertyName: name) if context == .exportSwift, returnType.usesSideChannelForOptionalReturn() { - guard case .optional(let wrappedType) = returnType else { + guard case .nullable(let wrappedType, _) = returnType else { fatalError("usesSideChannelForOptionalReturn returned true for non-optional type") } @@ -2318,7 +2390,7 @@ extension BridgeJSLink { return loweredValues.first } - private static func propertyAccessExpr(objectExpr: String, propertyName: String) -> String { + static func propertyAccessExpr(objectExpr: String, propertyName: String) -> String { if propertyName.range(of: #"^[$A-Z_][0-9A-Z_$]*$"#, options: [.regularExpression, .caseInsensitive]) != nil { return "\(objectExpr).\(propertyName)" @@ -2613,6 +2685,7 @@ extension BridgeJSLink { fileprivate func buildHierarchicalExportsObject( exportedSkeletons: [ExportedSkeleton], + intrinsicRegistry: JSIntrinsicRegistry, renderFunctionImpl: (ExportedFunction) throws -> [String] ) throws -> [String] { let printer = CodeFragmentPrinter() @@ -2622,7 +2695,10 @@ extension BridgeJSLink { try populateJavaScriptExportLines(node: rootNode, renderFunctionImpl: renderFunctionImpl) - try populatePropertyImplementations(node: rootNode) + try populatePropertyImplementations( + node: rootNode, + intrinsicRegistry: intrinsicRegistry + ) printExportsObjectHierarchy(node: rootNode, printer: printer, currentPath: []) @@ -2643,10 +2719,16 @@ extension BridgeJSLink { } } - private func populatePropertyImplementations(node: NamespaceNode) throws { + private func populatePropertyImplementations( + node: NamespaceNode, + intrinsicRegistry: JSIntrinsicRegistry + ) throws { for property in node.content.staticProperties { // Generate getter - let getterThunkBuilder = ExportedThunkBuilder(effects: Effects(isAsync: false, isThrows: false)) + let getterThunkBuilder = ExportedThunkBuilder( + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry + ) let getterReturnExpr = try getterThunkBuilder.call( abiName: property.getterAbiName(), returnType: property.type @@ -2669,14 +2751,15 @@ extension BridgeJSLink { // Generate setter if not readonly if !property.isReadonly { let setterThunkBuilder = ExportedThunkBuilder( - effects: Effects(isAsync: false, isThrows: false) + effects: Effects(isAsync: false, isThrows: false), + intrinsicRegistry: intrinsicRegistry ) try setterThunkBuilder.lowerParameter( param: Parameter(label: "value", name: "value", type: property.type) ) _ = try setterThunkBuilder.call( abiName: property.setterAbiName(), - returnType: .void + returnType: BridgeType.void ) let setterPrinter = CodeFragmentPrinter() @@ -2696,7 +2779,10 @@ extension BridgeJSLink { // Recursively process child nodes for (_, childNode) in node.children { - try populatePropertyImplementations(node: childNode) + try populatePropertyImplementations( + node: childNode, + intrinsicRegistry: intrinsicRegistry + ) } } @@ -3036,7 +3122,7 @@ extension BridgeJSLink { importObjectBuilder: ImportObjectBuilder, function: ImportedFunctionSkeleton ) throws { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) for param in function.parameters { try thunkBuilder.liftParameter(param: param) } @@ -3067,7 +3153,7 @@ extension BridgeJSLink { importObjectBuilder: ImportObjectBuilder, getter: ImportedGetterSkeleton ) throws { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) let jsName = getter.jsName ?? getter.name let importRootExpr = getter.from == .global ? "globalThis" : "imports" let returnExpr = try thunkBuilder.getImportProperty( @@ -3130,6 +3216,32 @@ extension BridgeJSLink { importObjectBuilder.assignToImportObject(name: setterAbiName, function: js) importObjectBuilder.appendDts(dts) } + for method in type.staticMethods { + let abiName = method.abiName(context: type, operation: "static") + let (js, dts) = try renderImportedStaticMethod(context: type, method: method) + importObjectBuilder.assignToImportObject(name: abiName, function: js) + importObjectBuilder.appendDts(dts) + } + if type.from == nil, type.constructor != nil || !type.staticMethods.isEmpty { + let dtsPrinter = CodeFragmentPrinter() + dtsPrinter.write("\(type.name): {") + dtsPrinter.indent { + if let constructor = type.constructor { + let returnType = BridgeType.jsObject(type.name) + dtsPrinter.write( + "new\(renderTSSignature(parameters: constructor.parameters, returnType: returnType, effects: Effects(isAsync: false, isThrows: false)));" + ) + } + for method in type.staticMethods { + let methodName = method.jsName ?? method.name + let signature = + "\(renderTSPropertyName(methodName))\(renderTSSignature(parameters: method.parameters, returnType: method.returnType, effects: Effects(isAsync: false, isThrows: false)));" + dtsPrinter.write(signature) + } + } + dtsPrinter.write("}") + importObjectBuilder.appendDts(dtsPrinter.lines) + } for method in type.methods { let (js, dts) = try renderImportedMethod(context: type, method: method) importObjectBuilder.assignToImportObject(name: method.abiName(context: type), function: js) @@ -3142,7 +3254,7 @@ extension BridgeJSLink { type: ImportedTypeSkeleton, constructor: ImportedConstructorSkeleton ) throws { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) for param in constructor.parameters { try thunkBuilder.liftParameter(param: param) } @@ -3160,19 +3272,6 @@ extension BridgeJSLink { returnType: returnType ) importObjectBuilder.assignToImportObject(name: abiName, function: funcLines) - - if type.from == nil { - let dtsPrinter = CodeFragmentPrinter() - dtsPrinter.write("\(type.name): {") - dtsPrinter.indent { - dtsPrinter.write( - "new\(renderTSSignature(parameters: constructor.parameters, returnType: returnType, effects: Effects(isAsync: false, isThrows: false)));" - ) - } - dtsPrinter.write("}") - - importObjectBuilder.appendDts(dtsPrinter.lines) - } } func renderImportedGetter( @@ -3180,7 +3279,7 @@ extension BridgeJSLink { abiName: String, emitCall: (ImportedThunkBuilder) throws -> String? ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) thunkBuilder.liftSelf() let returnExpr = try emitCall(thunkBuilder) let funcLines = thunkBuilder.renderFunction( @@ -3196,7 +3295,7 @@ extension BridgeJSLink { abiName: String, emitCall: (ImportedThunkBuilder) throws -> String? ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) thunkBuilder.liftSelf() let returnExpr = try emitCall(thunkBuilder) let funcLines = thunkBuilder.renderFunction( @@ -3207,11 +3306,37 @@ extension BridgeJSLink { return (funcLines, []) } + func renderImportedStaticMethod( + context: ImportedTypeSkeleton, + method: ImportedFunctionSkeleton + ) throws -> (js: [String], dts: [String]) { + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) + for param in method.parameters { + try thunkBuilder.liftParameter(param: param) + } + let importRootExpr = context.from == .global ? "globalThis" : "imports" + let constructorExpr = ImportedThunkBuilder.propertyAccessExpr( + objectExpr: importRootExpr, + propertyName: context.jsName ?? context.name + ) + let returnExpr = try thunkBuilder.callStaticMethod( + on: constructorExpr, + name: method.jsName ?? method.name, + returnType: method.returnType + ) + let funcLines = thunkBuilder.renderFunction( + name: method.abiName(context: context, operation: "static"), + returnExpr: returnExpr, + returnType: method.returnType + ) + return (funcLines, []) + } + func renderImportedMethod( context: ImportedTypeSkeleton, method: ImportedFunctionSkeleton ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) thunkBuilder.liftSelf() for param in method.parameters { try thunkBuilder.liftParameter(param: param) @@ -3238,7 +3363,10 @@ extension BridgeJSLink { className: `protocol`.name ) - let getterThunkBuilder = ImportedThunkBuilder(context: .exportSwift) + let getterThunkBuilder = ImportedThunkBuilder( + context: .exportSwift, + intrinsicRegistry: intrinsicRegistry + ) getterThunkBuilder.liftSelf() let returnExpr = try getterThunkBuilder.callPropertyGetter(name: property.name, returnType: property.type) let getterLines = getterThunkBuilder.renderFunction( @@ -3256,7 +3384,10 @@ extension BridgeJSLink { operation: "set", className: `protocol`.name ) - let setterThunkBuilder = ImportedThunkBuilder(context: .exportSwift) + let setterThunkBuilder = ImportedThunkBuilder( + context: .exportSwift, + intrinsicRegistry: intrinsicRegistry + ) setterThunkBuilder.liftSelf() try setterThunkBuilder.liftParameter( param: Parameter(label: nil, name: "value", type: property.type) @@ -3276,7 +3407,10 @@ extension BridgeJSLink { protocol: ExportedProtocol, method: ExportedFunction ) throws { - let thunkBuilder = ImportedThunkBuilder(context: .exportSwift) + let thunkBuilder = ImportedThunkBuilder( + context: .exportSwift, + intrinsicRegistry: intrinsicRegistry + ) thunkBuilder.liftSelf() for param in method.parameters { try thunkBuilder.liftParameter(param: param) @@ -3399,12 +3533,14 @@ extension BridgeType { return "boolean" case .jsObject(let name): return name ?? "any" + case .jsValue: + return "any" case .swiftHeapObject(let name): return name case .unsafePointer: return "number" - case .optional(let wrappedType): - return "\(wrappedType.tsType) | null" + case .nullable(let wrappedType, let kind): + return "\(wrappedType.tsType) | \(kind.absenceLiteral)" case .caseEnum(let name): return "\(name)Tag" case .rawValueEnum(let name, _): diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift index c4624e694..8c5a47b23 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift @@ -1,3 +1,37 @@ +/// Registry for JS helper intrinsics used during code generation. +final class JSIntrinsicRegistry { + private var entries: [String: [String]] = [:] + + var isEmpty: Bool { + entries.isEmpty + } + + func register(name: String, build: (CodeFragmentPrinter) -> Void) { + guard entries[name] == nil else { return } + let printer = CodeFragmentPrinter() + build(printer) + entries[name] = printer.lines + } + + func reset() { + entries.removeAll() + } + + func emitLines() -> [String] { + var emitted: [String] = [] + for key in entries.keys.sorted() { + if let lines = entries[key] { + emitted.append(contentsOf: lines) + emitted.append("") + } + } + if emitted.last == "" { + emitted.removeLast() + } + return emitted + } +} + /// A printer for code fragments. final class CodeFragmentPrinter { private(set) var lines: [String] = [] @@ -12,6 +46,11 @@ final class CodeFragmentPrinter { } func write(_ line: S) { + if line.isEmpty { + // Empty lines should not have trailing spaces + lines.append("") + return + } lines.append(String(repeating: " ", count: indentLevel * 4) + String(line)) } diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 28f756a43..1619c2cd2 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -34,6 +34,8 @@ final class JSGlueVariableScope { static let reservedEnumHelpers = "enumHelpers" static let reservedStructHelpers = "structHelpers" + private let intrinsicRegistry: JSIntrinsicRegistry? + private var variables: Set = [ reservedSwift, reservedInstance, @@ -64,6 +66,10 @@ final class JSGlueVariableScope { reservedStructHelpers, ] + init(intrinsicRegistry: JSIntrinsicRegistry? = nil) { + self.intrinsicRegistry = intrinsicRegistry + } + /// Returns a unique variable name in the scope based on the given name hint. /// /// - Parameter hint: A hint for the variable name. @@ -80,6 +86,14 @@ final class JSGlueVariableScope { } while !variables.insert(suffixedName).inserted return suffixedName } + + func registerIntrinsic(_ name: String, build: (CodeFragmentPrinter) -> Void) { + intrinsicRegistry?.register(name: name, build: build) + } + + func makeChildScope() -> JSGlueVariableScope { + JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) + } } /// A fragment of JS code used to convert a value between Swift and JS. @@ -238,6 +252,274 @@ struct IntrinsicJSFragment: Sendable { } ) + private static let jsValueLowerHelperName = "__bjs_jsValueLower" + private static let jsValueLiftHelperName = "__bjs_jsValueLift" + + private static func registerJSValueHelpers(scope: JSGlueVariableScope) { + scope.registerIntrinsic("jsValueHelpers") { helperPrinter in + helperPrinter.write("function \(jsValueLowerHelperName)(value) {") + helperPrinter.indent { + emitJSValueLowerBody( + value: "value", + kindVar: "kind", + payload1Var: "payload1", + payload2Var: "payload2", + printer: helperPrinter + ) + helperPrinter.write("return [kind, payload1, payload2];") + } + helperPrinter.write("}") + helperPrinter.write("function \(jsValueLiftHelperName)(kind, payload1, payload2) {") + helperPrinter.indent { + let helperScope = JSGlueVariableScope() + let resultVar = emitJSValueConstruction( + kind: "kind", + payload1: "payload1", + payload2: "payload2", + scope: helperScope, + printer: helperPrinter + ) + helperPrinter.write("return \(resultVar);") + } + helperPrinter.write("}") + } + } + + private static func emitJSValueLowerBody( + value: String, + kindVar: String, + payload1Var: String, + payload2Var: String, + printer: CodeFragmentPrinter + ) { + printer.write("let \(kindVar);") + printer.write("let \(payload1Var);") + printer.write("let \(payload2Var);") + printer.write("if (\(value) === null) {") + printer.indent { + printer.write("\(kindVar) = 4;") + printer.write("\(payload1Var) = 0;") + printer.write("\(payload2Var) = 0;") + } + printer.write("} else {") + printer.indent { + printer.write("switch (typeof \(value)) {") + printer.indent { + printer.write("case \"boolean\":") + printer.indent { + printer.write("\(kindVar) = 0;") + printer.write("\(payload1Var) = \(value) ? 1 : 0;") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"number\":") + printer.indent { + printer.write("\(kindVar) = 2;") + printer.write("\(payload1Var) = 0;") + printer.write("\(payload2Var) = \(value);") + printer.write("break;") + } + printer.write("case \"string\":") + printer.indent { + printer.write("\(kindVar) = 1;") + printer.write("\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"undefined\":") + printer.indent { + printer.write("\(kindVar) = 5;") + printer.write("\(payload1Var) = 0;") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"object\":") + printer.indent { + printer.write("\(kindVar) = 3;") + printer.write("\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"function\":") + printer.indent { + printer.write("\(kindVar) = 3;") + printer.write("\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"symbol\":") + printer.indent { + printer.write("\(kindVar) = 7;") + printer.write("\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("case \"bigint\":") + printer.indent { + printer.write("\(kindVar) = 8;") + printer.write("\(payload1Var) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(payload2Var) = 0;") + printer.write("break;") + } + printer.write("default:") + printer.indent { + printer.write("throw new TypeError(\"Unsupported JSValue type\");") + } + } + printer.write("}") + } + printer.write("}") + } + + static let jsValueLower = IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanupCode in + let value = arguments[0] + let kindVar = scope.variable("\(value)Kind") + let payload1Var = scope.variable("\(value)Payload1") + let payload2Var = scope.variable("\(value)Payload2") + registerJSValueHelpers(scope: scope) + printer.write( + "const [\(kindVar), \(payload1Var), \(payload2Var)] = \(jsValueLowerHelperName)(\(value));" + ) + return [kindVar, payload1Var, payload2Var] + } + ) + + private static func emitJSValueConstruction( + kind: String, + payload1: String, + payload2: String, + scope: JSGlueVariableScope, + printer: CodeFragmentPrinter + ) -> String { + let resultVar = scope.variable("jsValue") + printer.write("let \(resultVar);") + printer.write("switch (\(kind)) {") + printer.indent { + printer.write("case 0:") + printer.indent { + printer.write("\(resultVar) = \(payload1) !== 0;") + printer.write("break;") + } + printer.write("case 1:") + printer.indent { + printer.write( + "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" + ) + printer.write("break;") + } + printer.write("case 2:") + printer.indent { + printer.write("\(resultVar) = \(payload2);") + printer.write("break;") + } + printer.write("case 3:") + printer.indent { + printer.write( + "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" + ) + printer.write("break;") + } + printer.write("case 4:") + printer.indent { + printer.write("\(resultVar) = null;") + printer.write("break;") + } + printer.write("case 5:") + printer.indent { + printer.write("\(resultVar) = undefined;") + printer.write("break;") + } + printer.write("case 7:") + printer.indent { + printer.write( + "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" + ) + printer.write("break;") + } + printer.write("case 8:") + printer.indent { + printer.write( + "\(resultVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(payload1));" + ) + printer.write("break;") + } + printer.write("default:") + printer.indent { + printer.write("throw new TypeError(\"Unsupported JSValue kind \" + \(kind));") + } + } + printer.write("}") + return resultVar + } + + static func jsValueLowerReturn(context: BridgeContext) -> IntrinsicJSFragment { + switch context { + case .importTS: + // Return values from imported JS functions should be delivered to the Swift side + // via the parameter stacks that `_swift_js_pop_*` read from. + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanupCode in + let lowered = jsValueLower.printCode(arguments, scope, printer, cleanupCode) + let kindVar = lowered[0] + let payload1Var = lowered[1] + let payload2Var = lowered[2] + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(kindVar));") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(payload1Var));") + printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(payload2Var));") + return [] + } + ) + case .exportSwift: + // Kept for symmetry, though JSValue return for export currently relies on Swift pushing + // to tmpRet stacks directly. + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanupCode in + let lowered = jsValueLower.printCode(arguments, scope, printer, cleanupCode) + let kindVar = lowered[0] + let payload1Var = lowered[1] + let payload2Var = lowered[2] + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(kindVar));") + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(payload1Var));") + printer.write("\(JSGlueVariableScope.reservedTmpRetF64s).push(\(payload2Var));") + return [] + } + ) + } + } + + static let jsValueLift = IntrinsicJSFragment( + parameters: [], + printCode: { _, scope, printer, cleanupCode in + let payload2 = scope.variable("jsValuePayload2") + let payload1 = scope.variable("jsValuePayload1") + let kind = scope.variable("jsValueKind") + printer.write("const \(payload2) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") + printer.write("const \(payload1) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(kind) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + let resultVar = scope.variable("jsValue") + registerJSValueHelpers(scope: scope) + printer.write( + "const \(resultVar) = \(jsValueLiftHelperName)(\(kind), \(payload1), \(payload2));" + ) + return [resultVar] + } + ) + static let jsValueLiftParameter = IntrinsicJSFragment( + parameters: ["kind", "payload1", "payload2"], + printCode: { arguments, scope, printer, cleanupCode in + let resultVar = scope.variable("jsValue") + registerJSValueHelpers(scope: scope) + printer.write( + "const \(resultVar) = \(jsValueLiftHelperName)(\(arguments[0]), \(arguments[1]), \(arguments[2]));" + ) + return [resultVar] + } + ) + static let swiftHeapObjectLowerParameter = IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanupCode in @@ -289,26 +571,44 @@ struct IntrinsicJSFragment: Sendable { printCode: { _, scope, printer, _ in let retName = scope.variable("ret") printer.write( - "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(JSGlueVariableScope.reservedTmpRetTag), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(JSGlueVariableScope.reservedTmpRetTag).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [retName] } ) } - static func optionalLiftParameter(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + static func optionalLiftParameter(wrappedType: BridgeType, kind: JSOptionalKind) throws -> IntrinsicJSFragment { + if case .jsValue = wrappedType { + return IntrinsicJSFragment( + parameters: ["isSome", "kind", "payload1", "payload2"], + printCode: { arguments, scope, printer, cleanupCode in + let isSome = arguments[0] + let lifted = jsValueLiftParameter.printCode( + [arguments[1], arguments[2], arguments[3]], + scope, + printer, + cleanupCode + ) + let valueExpr = lifted.first ?? "undefined" + return ["\(isSome) ? \(valueExpr) : null"] + } + ) + } + return IntrinsicJSFragment( parameters: ["isSome", "wrappedValue"], printCode: { arguments, scope, printer, cleanupCode in let isSome = arguments[0] let wrappedValue = arguments[1] let resultExpr: String + let absenceLiteral = kind.absenceLiteral switch wrappedType { case .int, .float, .double, .caseEnum: - resultExpr = "\(isSome) ? \(wrappedValue) : null" + resultExpr = "\(isSome) ? \(wrappedValue) : \(absenceLiteral)" case .bool: - resultExpr = "\(isSome) ? \(wrappedValue) !== 0 : null" + resultExpr = "\(isSome) ? \(wrappedValue) !== 0 : \(absenceLiteral)" case .string: let objectLabel = scope.variable("obj") printer.write("let \(objectLabel);") @@ -320,12 +620,12 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(wrappedValue));") } printer.write("}") - resultExpr = "\(isSome) ? \(objectLabel) : null" + resultExpr = "\(isSome) ? \(objectLabel) : \(absenceLiteral)" case .swiftHeapObject(let name): - resultExpr = "\(isSome) ? \(name).__construct(\(wrappedValue)) : null" + resultExpr = "\(isSome) ? \(name).__construct(\(wrappedValue)) : \(absenceLiteral)" case .jsObject: resultExpr = - "\(isSome) ? \(JSGlueVariableScope.reservedSwift).memory.getObject(\(wrappedValue)) : null" + "\(isSome) ? \(JSGlueVariableScope.reservedSwift).memory.getObject(\(wrappedValue)) : \(absenceLiteral)" case .rawValueEnum(_, let rawType): switch rawType { case .string: @@ -339,11 +639,11 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(wrappedValue));") } printer.write("}") - resultExpr = "\(isSome) ? \(objectLabel) : null" + resultExpr = "\(isSome) ? \(objectLabel) : \(absenceLiteral)" case .bool: - resultExpr = "\(isSome) ? \(wrappedValue) !== 0 : null" + resultExpr = "\(isSome) ? \(wrappedValue) !== 0 : \(absenceLiteral)" default: - resultExpr = "\(isSome) ? \(wrappedValue) : null" + resultExpr = "\(isSome) ? \(wrappedValue) : \(absenceLiteral)" } case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName @@ -352,11 +652,11 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSome)) {") printer.indent { printer.write( - "\(enumVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(wrappedValue), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "\(enumVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(wrappedValue), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) } printer.write("}") - resultExpr = "\(isSome) ? \(enumVar) : null" + resultExpr = "\(isSome) ? \(enumVar) : \(absenceLiteral)" case .swiftStruct(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let structVar = scope.variable("structValue") @@ -369,7 +669,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(structVar) = null;") + printer.write("\(structVar) = \(absenceLiteral);") } printer.write("}") resultExpr = structVar @@ -378,7 +678,6 @@ struct IntrinsicJSFragment: Sendable { printer.write("let \(arrayVar);") printer.write("if (\(isSome)) {") printer.indent { - // Lift array from stacks - reuse array lift return logic let arrayLiftFragment = try! arrayLift(elementType: elementType) let liftResults = arrayLiftFragment.printCode([], scope, printer, cleanupCode) if let liftResult = liftResults.first { @@ -387,12 +686,12 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(arrayVar) = null;") + printer.write("\(arrayVar) = \(absenceLiteral);") } printer.write("}") resultExpr = arrayVar default: - resultExpr = "\(isSome) ? \(wrappedValue) : null" + resultExpr = "\(isSome) ? \(wrappedValue) : \(absenceLiteral)" } return [resultExpr] @@ -442,6 +741,9 @@ struct IntrinsicJSFragment: Sendable { cleanupCode.write("}") return ["+\(isSomeVar)", "\(isSomeVar) ? \(idVar) : 0", "\(isSomeVar) ? \(bytesVar).length : 0"] + case .jsValue: + let lowered = jsValueLower.printCode([value], scope, printer, cleanupCode) + return ["+\(isSomeVar)"] + lowered case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let caseIdVar = scope.variable("\(value)CaseId") @@ -514,8 +816,10 @@ struct IntrinsicJSFragment: Sendable { static func optionalLiftReturn( wrappedType: BridgeType, - context: BridgeContext = .exportSwift + context: BridgeContext = .exportSwift, + kind: JSOptionalKind ) -> IntrinsicJSFragment { + let absenceLiteral = kind.absenceLiteral return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanupCode in @@ -550,7 +854,7 @@ struct IntrinsicJSFragment: Sendable { ? "\(className).__construct(\(pointerVar))" : "_exports['\(className)'].__construct(\(pointerVar))" printer.write( - "const \(resultVar) = \(pointerVar) === null ? null : \(constructExpr);" + "const \(resultVar) = \(pointerVar) === null ? \(absenceLiteral) : \(constructExpr);" ) case .caseEnum: printer.write("const \(resultVar) = \(JSGlueVariableScope.reservedStorageToReturnOptionalInt);") @@ -581,17 +885,19 @@ struct IntrinsicJSFragment: Sendable { } case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName + let tagVar = scope.variable("tag") + printer.write("const \(tagVar) = \(JSGlueVariableScope.reservedTmpRetTag).pop();") let isNullVar = scope.variable("isNull") - printer.write("const \(isNullVar) = (\(JSGlueVariableScope.reservedTmpRetTag) === -1);") + printer.write("const \(isNullVar) = (\(tagVar) === -1);") printer.write("let \(resultVar);") printer.write("if (\(isNullVar)) {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("} else {") printer.indent { printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(tagVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) } printer.write("}") @@ -608,7 +914,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("}") case .array(let elementType): @@ -624,6 +930,22 @@ struct IntrinsicJSFragment: Sendable { } } printer.write("} else {") + printer.indent { + printer.write("\(resultVar) = \(absenceLiteral);") + } + printer.write("}") + case .jsValue: + let isSomeVar = scope.variable("isSome") + printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("let \(resultVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let lifted = jsValueLift.printCode([], scope, printer, cleanupCode) + if let liftedValue = lifted.first { + printer.write("\(resultVar) = \(liftedValue);") + } + } + printer.write("} else {") printer.indent { printer.write("\(resultVar) = null;") } @@ -637,9 +959,9 @@ struct IntrinsicJSFragment: Sendable { ) } - static func optionalLowerReturn(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + static func optionalLowerReturn(wrappedType: BridgeType, kind: JSOptionalKind) throws -> IntrinsicJSFragment { switch wrappedType { - case .void, .optional, .namespaceEnum, .closure: + case .void, .nullable, .namespaceEnum, .closure: throw BridgeJSLinkError(message: "Unsupported optional wrapped type for protocol export: \(wrappedType)") default: break } @@ -649,7 +971,8 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanupCode in let value = arguments[0] let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(value) != null;") + let presenceExpr = kind.presenceCheck(value: value) + printer.write("const \(isSomeVar) = \(presenceExpr);") switch wrappedType { case .bool: @@ -671,19 +994,13 @@ struct IntrinsicJSFragment: Sendable { "bjs[\"swift_js_return_optional_double\"](\(isSomeVar) ? 1 : 0, \(isSomeVar) ? \(value) : 0.0);" ) case .string: - let bytesVar = scope.variable("bytes") printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write( - "const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" - ) - printer.write("bjs[\"swift_js_return_optional_string\"](1, \(bytesVar), \(bytesVar).length);") - printer.write("return \(bytesVar).length;") + printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = \(value);") } printer.write("} else {") printer.indent { - printer.write("bjs[\"swift_js_return_optional_string\"](0, 0, 0);") - printer.write("return -1;") + printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = null;") } printer.write("}") case .jsObject, .swiftProtocol: @@ -695,22 +1012,41 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") printer.write("bjs[\"swift_js_return_optional_object\"](\(isSomeVar) ? 1 : 0, \(idVar));") + case .jsValue: + if value != "undefined" { + let lowered = jsValueLower.printCode([value], scope, printer, cleanupCode) + let kindVar = lowered[0] + let payload1Var = lowered[1] + let payload2Var = lowered[2] + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(kindVar));") + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(payload1Var));") + printer.write("\(JSGlueVariableScope.reservedTmpRetF64s).push(\(payload2Var));") + } + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(isSomeVar) ? 1 : 0);") + case .array(let elementType): + printer.write("if (\(isSomeVar)) {") + printer.indent { + let arrayLowerFragment = try! arrayLower(elementType: elementType) + let arrayCleanup = CodeFragmentPrinter() + let _ = arrayLowerFragment.printCode([value], scope, printer, arrayCleanup) + if !arrayCleanup.lines.isEmpty { + for line in arrayCleanup.lines { + printer.write(line) + } + } + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") case .rawValueEnum(_, let rawType): switch rawType { case .string: - let bytesVar = scope.variable("bytes") printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write( - "const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" - ) - printer.write( - "bjs[\"swift_js_return_optional_string\"](1, \(bytesVar), \(bytesVar).length);" - ) + printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = \(value);") } printer.write("} else {") printer.indent { - printer.write("bjs[\"swift_js_return_optional_string\"](0, 0, 0);") + printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = null;") } printer.write("}") default: @@ -900,20 +1236,24 @@ struct IntrinsicJSFragment: Sendable { let targetVar = arguments[1] let base = fullName.components(separatedBy: ".").last ?? fullName printer.write( - "let \(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "let \(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [] } ) - case .optional(let wrappedType): - return try closureOptionalLiftParameter(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return try closureOptionalLiftParameter(wrappedType: wrappedType, kind: kind) default: throw BridgeJSLinkError(message: "Unsupported closure parameter type for lifting: \(type)") } } - /// Handles optional parameter lifting for closure invocation - private static func closureOptionalLiftParameter(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + /// Handles optional parameter lifting for closure invocation. + private static func closureOptionalLiftParameter( + wrappedType: BridgeType, + kind: JSOptionalKind + ) throws -> IntrinsicJSFragment { + let absenceLiteral = kind.absenceLiteral switch wrappedType { case .string, .rawValueEnum, .int, .bool, .double, .float, .jsObject, .swiftHeapObject, .caseEnum, .associatedValueEnum: @@ -967,7 +1307,7 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName printer.write( - "\(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(value), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "\(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(value), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) default: fatalError("Unsupported optional wrapped type in closure parameter lifting: \(wrappedType)") @@ -975,7 +1315,7 @@ struct IntrinsicJSFragment: Sendable { printer.unindent() printer.write("} else {") printer.indent() - printer.write("\(targetVar) = null;") + printer.write("\(targetVar) = \(absenceLiteral);") printer.unindent() printer.write("}") @@ -1106,7 +1446,7 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType): + case .nullable(let wrappedType, _): return try closureOptionalLowerReturn(wrappedType: wrappedType) default: throw BridgeJSLinkError(message: "Unsupported closure return type for lowering: \(type)") @@ -1295,27 +1635,34 @@ struct IntrinsicJSFragment: Sendable { let base = fullName.components(separatedBy: ".").last ?? fullName let resultVar = scope.variable("result") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) printer.write("return \(resultVar);") return [] } ) - case .optional(let wrappedType): - return try closureOptionalLiftReturn(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return try closureOptionalLiftReturn(wrappedType: wrappedType, kind: kind) default: throw BridgeJSLinkError(message: "Unsupported closure return type for lifting: \(type)") } } /// Handles optional return lifting for Swift closure returns - private static func closureOptionalLiftReturn(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + private static func closureOptionalLiftReturn( + wrappedType: BridgeType, + kind: JSOptionalKind + ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["invokeCall"], printCode: { arguments, scope, printer, cleanupCode in let invokeCall = arguments[0] printer.write("\(invokeCall);") - let baseFragment = optionalLiftReturn(wrappedType: wrappedType, context: .importTS) + let baseFragment = optionalLiftReturn( + wrappedType: wrappedType, + context: .importTS, + kind: kind + ) let lifted = baseFragment.printCode([], scope, printer, cleanupCode) if !lifted.isEmpty { printer.write("return \(lifted[0]);") @@ -1354,7 +1701,7 @@ struct IntrinsicJSFragment: Sendable { } case .associatedValueEnum: printer.write("return;") - case .optional(let wrappedType): + case .nullable(let wrappedType, _): switch wrappedType { case .swiftHeapObject: printer.write("return 0;") @@ -1378,11 +1725,12 @@ struct IntrinsicJSFragment: Sendable { case .int, .uint, .float, .double, .bool, .unsafePointer: return .identity case .string: return .stringLowerParameter case .jsObject: return .jsObjectLowerParameter + case .jsValue: return .jsValueLower case .swiftHeapObject: return .swiftHeapObjectLowerParameter case .swiftProtocol: return .jsObjectLowerParameter case .void: return .void - case .optional(let wrappedType): + case .nullable(let wrappedType, _): return try .optionalLowerParameter(wrappedType: wrappedType) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): @@ -1423,11 +1771,13 @@ struct IntrinsicJSFragment: Sendable { case .bool: return .boolLiftReturn case .string: return .stringLiftReturn case .jsObject: return .jsObjectLiftReturn + case .jsValue: return .jsValueLift case .swiftHeapObject(let name): return .swiftHeapObjectLiftReturn(name) case .unsafePointer: return .identity case .swiftProtocol: return .jsObjectLiftReturn case .void: return .void - case .optional(let wrappedType): return .optionalLiftReturn(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return .optionalLiftReturn(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1470,6 +1820,7 @@ struct IntrinsicJSFragment: Sendable { case .bool: return .boolLiftParameter case .string: return .stringLiftParameter case .jsObject: return .jsObjectLiftParameter + case .jsValue: return .jsValueLiftParameter case .unsafePointer: return .identity case .swiftHeapObject(let name): switch context { @@ -1485,15 +1836,8 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Void can't appear in parameters of imported JS functions" ) - case .optional(let wrappedType): - switch context { - case .importTS: - throw BridgeJSLinkError( - message: "Optional types are not supported for imported JS functions: \(wrappedType)" - ) - case .exportSwift: - return try .optionalLiftParameter(wrappedType: wrappedType) - } + case .nullable(let wrappedType, let kind): + return try .optionalLiftParameter(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1516,7 +1860,7 @@ struct IntrinsicJSFragment: Sendable { let caseId = arguments[0] let resultVar = scope.variable("enumValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [resultVar] } @@ -1553,14 +1897,7 @@ struct IntrinsicJSFragment: Sendable { "Namespace enums are not supported to be passed as parameters to imported JS functions: \(string)" ) case .array(let elementType): - switch context { - case .importTS: - throw BridgeJSLinkError( - message: "Arrays are not yet supported to be passed as parameters to imported JS functions" - ) - case .exportSwift: - return try arrayLift(elementType: elementType) - } + return try arrayLift(elementType: elementType) } } @@ -1571,6 +1908,7 @@ struct IntrinsicJSFragment: Sendable { case .bool: return .boolLowerReturn case .string: return .stringLowerReturn case .jsObject: return .jsObjectLowerReturn + case .jsValue: return .jsValueLowerReturn(context: context) case .unsafePointer: return .identity case .swiftHeapObject(let name): switch context { @@ -1583,15 +1921,8 @@ struct IntrinsicJSFragment: Sendable { } case .swiftProtocol: return .jsObjectLowerReturn case .void: return .void - case .optional(let wrappedType): - switch context { - case .importTS: - throw BridgeJSLinkError( - message: "Optional types are not supported for imported JS functions: \(wrappedType)" - ) - case .exportSwift: - return try .optionalLowerReturn(wrappedType: wrappedType) - } + case .nullable(let wrappedType, let kind): + return try .optionalLowerReturn(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1635,14 +1966,7 @@ struct IntrinsicJSFragment: Sendable { message: "Namespace enums are not supported to be returned from imported JS functions: \(string)" ) case .array(let elementType): - switch context { - case .importTS: - throw BridgeJSLinkError( - message: "Arrays are not yet supported to be returned from imported JS functions" - ) - case .exportSwift: - return try arrayLower(elementType: elementType) - } + return try arrayLower(elementType: elementType) } } @@ -1666,13 +1990,14 @@ struct IntrinsicJSFragment: Sendable { ) } /// Fragment for generating an entire associated value enum helper - static func associatedValueEnumHelper(enumDefinition: ExportedEnum) -> IntrinsicJSFragment { + /// Generates the enum tag constants (e.g. `const XValues = { Tag: { ... } }`) + /// This is placed at module level for exports/imports. + static func associatedValueEnumValues(enumDefinition: ExportedEnum) -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["enumName"], printCode: { arguments, scope, printer, cleanup in let enumName = arguments[0] - // Generate the enum tag object printer.write("const \(enumName) = {") printer.indent { printer.write("Tag: {") @@ -1685,13 +2010,25 @@ struct IntrinsicJSFragment: Sendable { printer.write("},") } printer.write("};") - printer.nextLine() - // Generate the helper function + return [] + } + ) + } + + /// Generates the enum helper factory function (lower/lift closures). + /// This is placed inside `createInstantiator` alongside struct helpers, + /// so it has access to `_exports` for class references. + static func associatedValueEnumHelperFactory(enumDefinition: ExportedEnum) -> IntrinsicJSFragment { + return IntrinsicJSFragment( + parameters: ["enumName"], + printCode: { arguments, scope, printer, cleanup in + let enumName = arguments[0] + printer.write("const __bjs_create\(enumName)Helpers = () => {") printer.indent() printer.write( - "return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), textEncoder, \(JSGlueVariableScope.reservedSwift)) => ({" + "return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), textEncoder, \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers)) => ({" ) printer.indent() @@ -1704,7 +2041,7 @@ struct IntrinsicJSFragment: Sendable { let lowerPrinter = CodeFragmentPrinter() for enumCase in enumDefinition.cases { let caseName = enumCase.name.capitalizedFirstLetter - let caseScope = JSGlueVariableScope() + let caseScope = scope.makeChildScope() let caseCleanup = CodeFragmentPrinter() caseCleanup.indent() let fragment = IntrinsicJSFragment.associatedValuePushPayload(enumCase: enumCase) @@ -1723,16 +2060,16 @@ struct IntrinsicJSFragment: Sendable { // Generate lift function printer.write( - "lift: (\(JSGlueVariableScope.reservedTmpRetTag), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s)) => {" + "lift: (tag, \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers)) => {" ) printer.indent { - printer.write("const tag = tmpRetTag | 0;") + printer.write("tag = tag | 0;") printer.write("switch (tag) {") printer.indent { let liftPrinter = CodeFragmentPrinter() for enumCase in enumDefinition.cases { let caseName = enumCase.name.capitalizedFirstLetter - let caseScope = JSGlueVariableScope() + let caseScope = scope.makeChildScope() let caseCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.associatedValuePopPayload(enumCase: enumCase) @@ -1893,182 +2230,263 @@ struct IntrinsicJSFragment: Sendable { private static func associatedValuePushPayload(type: BridgeType) -> IntrinsicJSFragment { switch type { - case .string: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - let bytesVar = scope.variable("bytes") - let idVar = scope.variable("id") - printer.write("const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));") - printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - return [] - } - ) - case .bool: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(arguments[0]) ? 1 : 0);") - return [] - } - ) - case .int, .uint: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") - return [] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") - return [] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") - return [] - } - ) - case .optional(let wrappedType): - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(value) != null;") + case .nullable(let wrappedType, let kind): + return associatedValueOptionalPushPayload(wrappedType: wrappedType, kind: kind) + default: + return try! stackLowerFragment(elementType: type) + } + } - switch wrappedType { - case .string: - let idVar = scope.variable("id") - printer.write("let \(idVar);") - printer.write("if (\(isSomeVar)) {") - printer.indent { - let bytesVar = scope.variable("bytes") - printer.write( - "let \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" - ) - printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") - } - printer.write("} else {") - printer.indent { + private static func associatedValueOptionalPushPayload( + wrappedType: BridgeType, + kind: JSOptionalKind + ) -> IntrinsicJSFragment { + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + let value = arguments[0] + let isSomeVar = scope.variable("isSome") + printer.write("const \(isSomeVar) = \(kind.presenceCheck(value: value));") + + switch wrappedType { + case .string: + let idVar = scope.variable("id") + printer.write("let \(idVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let bytesVar = scope.variable("bytes") + printer.write( + "let \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" + ) + printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + } + printer.write("} else {") + printer.indent { + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + cleanup.write("if(\(idVar)) {") + cleanup.indent { + cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") + } + cleanup.write("}") + case .int, .uint: + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .bool: + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) ? 1 : 0) : 0);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .float: + printer.write( + "\(JSGlueVariableScope.reservedTmpParamF32s).push(\(isSomeVar) ? Math.fround(\(value)) : 0.0);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .double: + printer.write( + "\(JSGlueVariableScope.reservedTmpParamF64s).push(\(isSomeVar) ? \(value) : 0.0);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .caseEnum: + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .rawValueEnum(_, let rawType): + switch rawType { + case .string: + let idVar = scope.variable("id") + printer.write("let \(idVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let bytesVar = scope.variable("bytes") + printer.write( + "let \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" + ) + printer.write( + "\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" + ) + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);" + ) + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + } + printer.write("} else {") + printer.indent { printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" + ) cleanup.write("if(\(idVar)) {") cleanup.indent { - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") + cleanup.write( + "\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));" + ) } cleanup.write("}") - case .int, .uint: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") - case .bool: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) ? 1 : 0) : 0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") case .float: printer.write( "\(JSGlueVariableScope.reservedTmpParamF32s).push(\(isSomeVar) ? Math.fround(\(value)) : 0.0);" ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" + ) case .double: printer.write( "\(JSGlueVariableScope.reservedTmpParamF64s).push(\(isSomeVar) ? \(value) : 0.0);" ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" + ) default: - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" + ) + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" + ) } - - return [] - } - ) - default: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - return [] + case .swiftStruct(let structName): + let structBase = structName.components(separatedBy: ".").last ?? structName + let nestedCleanupVar = scope.variable("nestedCleanup") + printer.write("let \(nestedCleanupVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let structResultVar = scope.variable("structResult") + printer.write( + "const \(structResultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" + ) + printer.write("\(nestedCleanupVar) = \(structResultVar).cleanup;") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + cleanup.write("if (\(nestedCleanupVar)) { \(nestedCleanupVar)(); }") + case .swiftHeapObject: + printer.write("if (\(isSomeVar)) {") + printer.indent { + printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(value).pointer);") + } + printer.write("} else {") + printer.indent { + printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(0);") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .jsObject: + let idVar = scope.variable("id") + printer.write("let \(idVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + } + printer.write("} else {") + printer.indent { + printer.write("\(idVar) = undefined;") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + case .associatedValueEnum(let enumName): + let base = enumName.components(separatedBy: ".").last ?? enumName + let caseIdVar = scope.variable("enumCaseId") + let enumCleanupVar = scope.variable("enumCleanup") + printer.write("let \(caseIdVar), \(enumCleanupVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let enumResultVar = scope.variable("enumResult") + printer.write( + "const \(enumResultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + ) + printer.write("\(caseIdVar) = \(enumResultVar).caseId;") + printer.write("\(enumCleanupVar) = \(enumResultVar).cleanup;") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") + } + printer.write("} else {") + printer.indent { + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + cleanup.write("if (\(enumCleanupVar)) { \(enumCleanupVar)(); }") + case .array(let elementType): + // Array cleanup references variables declared inside the if block, + // so capture cleanup into a variable declared at the outer scope. + let arrCleanupVar = scope.variable("arrCleanup") + printer.write("let \(arrCleanupVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let localCleanup = CodeFragmentPrinter() + let arrFragment = try! arrayLower(elementType: elementType) + _ = arrFragment.printCode([value], scope, printer, localCleanup) + let cleanupLines = localCleanup.lines.filter { + !$0.trimmingCharacters(in: .whitespaces).isEmpty + } + if !cleanupLines.isEmpty { + printer.write("\(arrCleanupVar) = () => {") + printer.indent { + for line in cleanupLines { + printer.write(line) + } + } + printer.write("};") + } + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + cleanup.write("if (\(arrCleanupVar)) { \(arrCleanupVar)(); }") + default: + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") } - ) - } + + return [] + } + ) } private static func associatedValuePopPayload(type: BridgeType) -> IntrinsicJSFragment { switch type { - case .string: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let strVar = scope.variable("string") - printer.write("const \(strVar) = \(JSGlueVariableScope.reservedTmpRetStrings).pop();") - return [strVar] - } - ) - case .bool: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let bVar = scope.variable("bool") - printer.write("const \(bVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - return [bVar] - } - ) - case .int, .uint: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let iVar = scope.variable("int") - printer.write("const \(iVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - return [iVar] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let fVar = scope.variable("f32") - printer.write("const \(fVar) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") - return [fVar] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let dVar = scope.variable("f64") - printer.write("const \(dVar) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") - return [dVar] - } - ) - case .optional(let wrappedType): - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let optVar = scope.variable("optional") - let isSomeVar = scope.variable("isSome") + case .nullable(let wrappedType, let kind): + return associatedValueOptionalPopPayload(wrappedType: wrappedType, kind: kind) + default: + return try! stackLiftFragment(elementType: type) + } + } - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - printer.write("let \(optVar);") - printer.write("if (\(isSomeVar)) {") - printer.indent { + private static func associatedValueOptionalPopPayload( + wrappedType: BridgeType, + kind: JSOptionalKind + ) -> IntrinsicJSFragment { + return IntrinsicJSFragment( + parameters: [], + printCode: { arguments, scope, printer, cleanup in + let optVar = scope.variable("optional") + let isSomeVar = scope.variable("isSome") + + printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("let \(optVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + // For optional associated value enums, Swift uses bridgeJSLowerParameter() + // which pushes caseId to tmpRetInts (not tmpRetTag like bridgeJSLowerReturn()). + if case .associatedValueEnum(let fullName) = wrappedType { + let base = fullName.components(separatedBy: ".").last ?? fullName + let caseIdVar = scope.variable("caseId") + printer.write("const \(caseIdVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write( + "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + ) + } else { let wrappedFragment = associatedValuePopPayload(type: wrappedType) let wrappedResults = wrappedFragment.printCode([], scope, printer, cleanup) if let wrappedResult = wrappedResults.first { @@ -2077,23 +2495,16 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(optVar) = undefined;") } } - printer.write("} else {") - printer.indent { - printer.write("\(optVar) = null;") - } - printer.write("}") - - return [optVar] } - ) - default: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - return ["undefined"] + printer.write("} else {") + printer.indent { + printer.write("\(optVar) = \(kind.absenceLiteral);") } - ) - } + printer.write("}") + + return [optVar] + } + ) } static func swiftStructLowerReturn(fullName: String) -> IntrinsicJSFragment { @@ -2154,7 +2565,7 @@ struct IntrinsicJSFragment: Sendable { let elemVar = scope.variable("elem") printer.write("for (const \(elemVar) of \(arr)) {") printer.indent { - let elementFragment = try! arrayElementLowerFragment(elementType: elementType) + let elementFragment = try! stackLowerFragment(elementType: elementType) let elementCleanup = CodeFragmentPrinter() let _ = elementFragment.printCode([elemVar], scope, printer, elementCleanup) if !elementCleanup.lines.isEmpty { @@ -2188,7 +2599,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("const \(resultVar) = [];") printer.write("for (let \(iVar) = 0; \(iVar) < \(lenVar); \(iVar)++) {") printer.indent { - let elementFragment = try! arrayElementRaiseFragment(elementType: elementType) + let elementFragment = try! stackLiftFragment(elementType: elementType) let elementResults = elementFragment.printCode([], scope, printer, cleanupCode) if let elementExpr = elementResults.first { printer.write("\(resultVar).push(\(elementExpr));") @@ -2201,8 +2612,26 @@ struct IntrinsicJSFragment: Sendable { ) } - private static func arrayElementRaiseFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { + private static func stackLiftFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { + case .jsValue: + return IntrinsicJSFragment( + parameters: [], + printCode: { _, scope, printer, cleanup in + registerJSValueHelpers(scope: scope) + let payload2Var = scope.variable("jsValuePayload2") + let payload1Var = scope.variable("jsValuePayload1") + let kindVar = scope.variable("jsValueKind") + printer.write("const \(payload2Var) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") + printer.write("const \(payload1Var) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(kindVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + let resultVar = scope.variable("jsValue") + printer.write( + "const \(resultVar) = \(jsValueLiftHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" + ) + return [resultVar] + } + ) case .string: return IntrinsicJSFragment( parameters: [], @@ -2255,7 +2684,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let resultVar = scope.variable("struct") printer.write( - "const \(resultVar) = structHelpers.\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [resultVar] } @@ -2280,6 +2709,24 @@ struct IntrinsicJSFragment: Sendable { return [varName] } ) + case .float: + return IntrinsicJSFragment( + parameters: [], + printCode: { arguments, scope, printer, cleanup in + let varName = scope.variable("rawValue") + printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") + return [varName] + } + ) + case .double: + return IntrinsicJSFragment( + parameters: [], + printCode: { arguments, scope, printer, cleanup in + let varName = scope.variable("rawValue") + printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") + return [varName] + } + ) default: return IntrinsicJSFragment( parameters: [], @@ -2295,11 +2742,9 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in - let caseIdVar = scope.variable("caseId") let resultVar = scope.variable("enumValue") - printer.write("const \(caseIdVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") printer.write( - "const \(resultVar) = enumHelpers.\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [resultVar] } @@ -2311,7 +2756,7 @@ struct IntrinsicJSFragment: Sendable { let ptrVar = scope.variable("ptr") let objVar = scope.variable("obj") printer.write("const \(ptrVar) = \(JSGlueVariableScope.reservedTmpRetPointers).pop();") - printer.write("const \(objVar) = \(className).__construct(\(ptrVar));") + printer.write("const \(objVar) = _exports['\(className)'].__construct(\(ptrVar));") return [objVar] } ) @@ -2329,8 +2774,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLift(elementType: innerElementType) - case .optional(let wrappedType): - return try optionalElementRaiseFragment(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return try optionalElementRaiseFragment(wrappedType: wrappedType, kind: kind) case .unsafePointer: return IntrinsicJSFragment( parameters: [], @@ -2345,8 +2790,23 @@ struct IntrinsicJSFragment: Sendable { } } - private static func arrayElementLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { + private static func stackLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { + case .jsValue: + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + registerJSValueHelpers(scope: scope) + let lowered = jsValueLower.printCode([arguments[0]], scope, printer, cleanup) + let kindVar = lowered[0] + let payload1Var = lowered[1] + let payload2Var = lowered[2] + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(kindVar));") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(payload1Var));") + printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(payload2Var));") + return [] + } + ) case .string: return IntrinsicJSFragment( parameters: ["value"], @@ -2354,7 +2814,7 @@ struct IntrinsicJSFragment: Sendable { let value = arguments[0] let bytesVar = scope.variable("bytes") let idVar = scope.variable("id") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") + printer.write("const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));") printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") @@ -2400,8 +2860,10 @@ struct IntrinsicJSFragment: Sendable { parameters: ["value"], printCode: { arguments, scope, printer, cleanup in let value = arguments[0] - let cleanupVar = scope.variable("cleanup") - printer.write("const { cleanup: \(cleanupVar) } = structHelpers.\(structBase).lower(\(value));") + let cleanupVar = scope.variable("structCleanup") + printer.write( + "const { cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" + ) cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } @@ -2423,7 +2885,9 @@ struct IntrinsicJSFragment: Sendable { let value = arguments[0] let bytesVar = scope.variable("bytes") let idVar = scope.variable("id") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") + printer.write( + "const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" + ) printer.write( "const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" ) @@ -2433,6 +2897,22 @@ struct IntrinsicJSFragment: Sendable { return [] } ) + case .float: + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") + return [] + } + ) + case .double: + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") + return [] + } + ) default: return IntrinsicJSFragment( parameters: ["value"], @@ -2451,7 +2931,7 @@ struct IntrinsicJSFragment: Sendable { let caseIdVar = scope.variable("caseId") let cleanupVar = scope.variable("enumCleanup") printer.write( - "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = enumHelpers.\(base).lower(\(value));" + "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") @@ -2474,14 +2954,16 @@ struct IntrinsicJSFragment: Sendable { let idVar = scope.variable("objId") printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [] } ) case .array(let innerElementType): return try! arrayLower(elementType: innerElementType) - case .optional(let wrappedType): - return try optionalElementLowerFragment(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return try optionalElementLowerFragment( + wrappedType: wrappedType, + kind: kind + ) case .swiftProtocol: // Same as jsObject but no cleanup — Swift's AnyProtocol wrapper releases via deinit return IntrinsicJSFragment( @@ -2507,7 +2989,11 @@ struct IntrinsicJSFragment: Sendable { } } - private static func optionalElementRaiseFragment(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + private static func optionalElementRaiseFragment( + wrappedType: BridgeType, + kind: JSOptionalKind + ) throws -> IntrinsicJSFragment { + let absenceLiteral = kind.absenceLiteral return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -2518,11 +3004,11 @@ struct IntrinsicJSFragment: Sendable { printer.write("let \(resultVar);") printer.write("if (\(isSomeVar) === 0) {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("} else {") printer.indent { - let innerFragment = try! arrayElementRaiseFragment(elementType: wrappedType) + let innerFragment = try! stackLiftFragment(elementType: wrappedType) let innerResults = innerFragment.printCode([], scope, printer, cleanup) if let innerResult = innerResults.first { printer.write("\(resultVar) = \(innerResult);") @@ -2537,19 +3023,23 @@ struct IntrinsicJSFragment: Sendable { ) } - private static func optionalElementLowerFragment(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + private static func optionalElementLowerFragment( + wrappedType: BridgeType, + kind: JSOptionalKind + ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in let value = arguments[0] let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(value) != null ? 1 : 0;") + let presenceExpr = kind.presenceCheck(value: value) + printer.write("const \(isSomeVar) = \(presenceExpr) ? 1 : 0;") // Cleanup is written inside the if block so retained id is in scope let localCleanupWriter = CodeFragmentPrinter() printer.write("if (\(isSomeVar)) {") printer.indent { - let innerFragment = try! arrayElementLowerFragment(elementType: wrappedType) + let innerFragment = try! stackLowerFragment(elementType: wrappedType) let _ = innerFragment.printCode([value], scope, printer, localCleanupWriter) let localCleanupLines = localCleanupWriter.lines.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty @@ -2607,6 +3097,7 @@ struct IntrinsicJSFragment: Sendable { generateStructLowerCode( structDef: capturedStructDef, allStructs: capturedAllStructs, + scope: scope, printer: printer ) } @@ -2619,6 +3110,7 @@ struct IntrinsicJSFragment: Sendable { generateStructLiftCode( structDef: capturedStructDef, allStructs: capturedAllStructs, + scope: scope, printer: printer, attachMethods: true ) @@ -2641,10 +3133,11 @@ struct IntrinsicJSFragment: Sendable { private static func generateStructLowerCode( structDef: ExportedStruct, allStructs: [ExportedStruct], + scope: JSGlueVariableScope, printer: CodeFragmentPrinter ) { let lowerPrinter = CodeFragmentPrinter() - let lowerScope = JSGlueVariableScope() + let lowerScope = scope.makeChildScope() let lowerCleanup = CodeFragmentPrinter() lowerCleanup.indent() @@ -2672,10 +3165,11 @@ struct IntrinsicJSFragment: Sendable { private static func generateStructLiftCode( structDef: ExportedStruct, allStructs: [ExportedStruct], + scope: JSGlueVariableScope, printer: CodeFragmentPrinter, attachMethods: Bool = false ) { - let liftScope = JSGlueVariableScope() + let liftScope = scope.makeChildScope() let liftCleanup = CodeFragmentPrinter() var fieldExpressions: [(name: String, expression: String)] = [] @@ -2702,122 +3196,65 @@ struct IntrinsicJSFragment: Sendable { let instanceVar = liftScope.variable("instance") printer.write("const \(instanceVar) = { \(reconstructedFields.joined(separator: ", ")) };") - // Attach instance methods to the struct instance - for method in structDef.methods where !method.effects.isStatic { - let paramList = DefaultValueUtils.formatParameterList(method.parameters) - printer.write( - "\(instanceVar).\(method.name) = function(\(paramList)) {" - ) - printer.indent { - let methodScope = JSGlueVariableScope() - let methodCleanup = CodeFragmentPrinter() - - // Lower the struct instance (this) using the helper's lower function - let structCleanupVar = methodScope.variable("structCleanup") - printer.write( - "const { cleanup: \(structCleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(this);" - ) - - // Lower each parameter and collect forwarding expressions - var paramForwardings: [String] = [] - for param in method.parameters { - let fragment = try! IntrinsicJSFragment.lowerParameter(type: param.type) - let loweredValues = fragment.printCode([param.name], methodScope, printer, methodCleanup) - paramForwardings.append(contentsOf: loweredValues) - } - - // Call the Swift function with all lowered parameters - let callExpr = "instance.exports.\(method.abiName)(\(paramForwardings.joined(separator: ", ")))" - if method.returnType == .void { - printer.write("\(callExpr);") - } else { - printer.write("const ret = \(callExpr);") - } - - // Cleanup - printer.write("if (\(structCleanupVar)) { \(structCleanupVar)(); }") - printer.write(contentsOf: methodCleanup) - - // Lift return value if needed - if method.returnType != .void { - let liftFragment = try! IntrinsicJSFragment.liftReturn(type: method.returnType) - if !liftFragment.parameters.isEmpty { - let lifted = liftFragment.printCode(["ret"], methodScope, printer, methodCleanup) - if let liftedValue = lifted.first { - printer.write("return \(liftedValue);") - } - } - } - } - printer.write("}.bind(\(instanceVar));") - } - - printer.write("return \(instanceVar);") - } else { - printer.write("return { \(reconstructedFields.joined(separator: ", ")) };") - } - } - - private static func structFieldLowerFragment( - field: ExportedProperty, - allStructs: [ExportedStruct] - ) -> IntrinsicJSFragment { - switch field.type { - case .string: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - let bytesVar = scope.variable("bytes") - let idVar = scope.variable("id") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") - printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - return [idVar] - } - ) - case .bool: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(arguments[0]) ? 1 : 0);") - return [] - } - ) - case .int, .uint: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") - return [] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") - return [] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") - return [] - } - ) - case .unsafePointer: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push((\(arguments[0]) | 0));") - return [] + // Attach instance methods to the struct instance + for method in structDef.methods where !method.effects.isStatic { + let paramList = DefaultValueUtils.formatParameterList(method.parameters) + printer.write( + "\(instanceVar).\(method.name) = function(\(paramList)) {" + ) + printer.indent { + let methodScope = scope.makeChildScope() + let methodCleanup = CodeFragmentPrinter() + + let structCleanupVar = methodScope.variable("structCleanup") + printer.write( + "const { cleanup: \(structCleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(this);" + ) + + var paramForwardings: [String] = [] + for param in method.parameters { + let fragment = try! IntrinsicJSFragment.lowerParameter(type: param.type) + let loweredValues = fragment.printCode([param.name], methodScope, printer, methodCleanup) + paramForwardings.append(contentsOf: loweredValues) + } + + let callExpr = "instance.exports.\(method.abiName)(\(paramForwardings.joined(separator: ", ")))" + if method.returnType == .void { + printer.write("\(callExpr);") + } else { + printer.write("const ret = \(callExpr);") + } + + // Cleanup + printer.write("if (\(structCleanupVar)) { \(structCleanupVar)(); }") + printer.write(contentsOf: methodCleanup) + + // Lift return value if needed + if method.returnType != .void { + let liftFragment = try! IntrinsicJSFragment.liftReturn(type: method.returnType) + let liftArgs = liftFragment.parameters.isEmpty ? [] : ["ret"] + let lifted = liftFragment.printCode(liftArgs, methodScope, printer, methodCleanup) + if let liftedValue = lifted.first { + printer.write("return \(liftedValue);") + } + } } - ) + printer.write("}.bind(\(instanceVar));") + } + + printer.write("return \(instanceVar);") + } else { + printer.write("return { \(reconstructedFields.joined(separator: ", ")) };") + } + } + + private static func structFieldLowerFragment( + field: ExportedProperty, + allStructs: [ExportedStruct] + ) -> IntrinsicJSFragment { + switch field.type { + case .jsValue: + preconditionFailure("Struct field of JSValue is not supported yet") case .jsObject: return IntrinsicJSFragment( parameters: ["value"], @@ -2850,13 +3287,13 @@ struct IntrinsicJSFragment: Sendable { return [idVar] } ) - case .optional(let wrappedType): + case .nullable(let wrappedType, let kind): return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in let value = arguments[0] let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(value) != null;") + printer.write("const \(isSomeVar) = \(kind.presenceCheck(value: value));") if case .caseEnum = wrappedType { printer.write("if (\(isSomeVar)) {") @@ -2878,7 +3315,9 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") printer.indent { let bytesVar = scope.variable("bytes") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") + printer.write( + "const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" + ) printer.write( "\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" ) @@ -2971,7 +3410,9 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") printer.indent { let bytesVar = scope.variable("bytes") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") + printer.write( + "const \(bytesVar) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(value));" + ) printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") @@ -3014,7 +3455,6 @@ struct IntrinsicJSFragment: Sendable { cleanup.write("}") return [idVar] } else { - // Handle optional primitive types using helper switch wrappedType { case .int, .uint: pushOptionalPrimitive( @@ -3075,7 +3515,6 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") cleanup.write("if (\(enumCleanupVar)) { \(enumCleanupVar)(); }") default: - // For other types (nested structs, etc.), original logic applies let wrappedFragment = structFieldLowerFragment( field: ExportedProperty( name: field.name, @@ -3085,9 +3524,36 @@ struct IntrinsicJSFragment: Sendable { ), allStructs: allStructs ) + let guardedPrinter = CodeFragmentPrinter() + let guardedCleanup = CodeFragmentPrinter() + _ = wrappedFragment.printCode([value], scope, guardedPrinter, guardedCleanup) + var loweredLines = guardedPrinter.lines + var hoistedCleanupVar: String? + if let first = loweredLines.first { + let trimmed = first.trimmingCharacters(in: .whitespaces) + if trimmed.hasPrefix("const "), + let namePart = trimmed.split(separator: " ").dropFirst().first, + trimmed.contains("= []") + { + hoistedCleanupVar = String(namePart) + loweredLines[0] = "\(hoistedCleanupVar!) = [];" + } + } + if let hoistedName = hoistedCleanupVar { + printer.write("let \(hoistedName);") + } printer.write("if (\(isSomeVar)) {") printer.indent { - _ = wrappedFragment.printCode([value], scope, printer, cleanup) + for line in loweredLines { + printer.write(line) + } + if !guardedCleanup.lines.isEmpty { + cleanup.write("if (\(isSomeVar)) {") + cleanup.indent { + cleanup.write(contentsOf: guardedCleanup) + } + cleanup.write("}") + } } printer.write("}") printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") @@ -3109,83 +3575,6 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .swiftHeapObject: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(value).pointer);") - return [] - } - ) - case .associatedValueEnum(let fullName): - let base = fullName.components(separatedBy: ".").last ?? fullName - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - let caseIdVar = scope.variable("caseId") - let cleanupVar = scope.variable("enumCleanup") - printer.write( - "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") - cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") - return [cleanupVar] - } - ) - case .caseEnum: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") - return [] - } - ) - case .rawValueEnum(_, let rawType): - switch rawType { - case .string: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - let value = arguments[0] - let bytesVar = scope.variable("bytes") - let idVar = scope.variable("id") - printer.write("const \(bytesVar) = textEncoder.encode(\(value));") - printer.write( - "const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - return [idVar] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") - return [] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") - return [] - } - ) - default: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") - return [] - } - ) - } case .void, .swiftProtocol, .namespaceEnum, .closure: // These types should not appear as struct fields - return error fragment return IntrinsicJSFragment( @@ -3195,8 +3584,8 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .array(let elementType): - return try! arrayLower(elementType: elementType) + default: + return try! stackLowerFragment(elementType: field.type) } } @@ -3249,61 +3638,9 @@ struct IntrinsicJSFragment: Sendable { allStructs: [ExportedStruct] ) -> IntrinsicJSFragment { switch field.type { - case .string: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let strVar = scope.variable("string") - printer.write("const \(strVar) = \(JSGlueVariableScope.reservedTmpRetStrings).pop();") - return [strVar] - } - ) - case .bool: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let bVar = scope.variable("bool") - printer.write("const \(bVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop() !== 0;") - return [bVar] - } - ) - case .int, .uint: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let iVar = scope.variable("int") - printer.write("const \(iVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - return [iVar] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let fVar = scope.variable("f32") - printer.write("const \(fVar) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") - return [fVar] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let dVar = scope.variable("f64") - printer.write("const \(dVar) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") - return [dVar] - } - ) - case .unsafePointer: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let pVar = scope.variable("pointer") - printer.write("const \(pVar) = \(JSGlueVariableScope.reservedTmpRetPointers).pop();") - return [pVar] - } - ) - case .optional(let wrappedType): + case .jsValue: + preconditionFailure("Struct field of JSValue is not supported yet") + case .nullable(let wrappedType, let kind): return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -3319,7 +3656,7 @@ struct IntrinsicJSFragment: Sendable { let caseIdVar = scope.variable("enumCaseId") printer.write("const \(caseIdVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") printer.write( - "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" + "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) } else { let wrappedFragment = structFieldLiftFragment( @@ -3341,7 +3678,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(optVar) = null;") + printer.write("\(optVar) = \(kind.absenceLiteral);") } printer.write("}") return [optVar] @@ -3358,65 +3695,6 @@ struct IntrinsicJSFragment: Sendable { return [structVar] } ) - case .caseEnum: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - return [varName] - } - ) - case .rawValueEnum(_, let rawType): - switch rawType { - case .string: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetStrings).pop();") - return [varName] - } - ) - case .float: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") - return [varName] - } - ) - case .double: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") - return [varName] - } - ) - default: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - return [varName] - } - ) - } - case .swiftHeapObject(let className): - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let ptrVar = scope.variable("ptr") - let varName = scope.variable("value") - printer.write("const \(ptrVar) = \(JSGlueVariableScope.reservedTmpRetPointers).pop();") - printer.write("const \(varName) = _exports['\(className)'].__construct(\(ptrVar));") - return [varName] - } - ) case .jsObject: return IntrinsicJSFragment( parameters: [], @@ -3440,18 +3718,6 @@ struct IntrinsicJSFragment: Sendable { return [varName] } ) - case .associatedValueEnum(let fullName): - let base = fullName.components(separatedBy: ".").last ?? fullName - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let varName = scope.variable("value") - printer.write( - "const \(varName) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s));" - ) - return [varName] - } - ) case .void, .swiftProtocol, .namespaceEnum, .closure: // These types should not appear as struct fields return IntrinsicJSFragment( @@ -3461,8 +3727,8 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .array(let elementType): - return try! arrayLift(elementType: elementType) + default: + return try! stackLiftFragment(elementType: field.type) } } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 33cc94479..0d4a78d3e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -126,10 +126,32 @@ public struct UnsafePointerType: Codable, Equatable, Hashable, Sendable { } } +/// JS semantics for optional/nullable types: which value represents "absent". +public enum JSOptionalKind: String, Codable, Equatable, Hashable, Sendable { + case null + case undefined + + /// The JS literal for absence (e.g. in generated glue). + public var absenceLiteral: String { + switch self { + case .null: return "null" + case .undefined: return "undefined" + } + } + + /// JS expression that is true when the value is present. `value` is the variable name. + public func presenceCheck(value: String) -> String { + switch self { + case .null: return "\(value) != null" + case .undefined: return "\(value) !== undefined" + } + } +} + public enum BridgeType: Codable, Equatable, Hashable, Sendable { - case int, uint, float, double, string, bool, jsObject(String?), swiftHeapObject(String), void + case int, uint, float, double, string, bool, jsObject(String?), jsValue, swiftHeapObject(String), void case unsafePointer(UnsafePointerType) - indirect case optional(BridgeType) + indirect case nullable(BridgeType, JSOptionalKind) indirect case array(BridgeType) case caseEnum(String) case rawValueEnum(String, SwiftEnumRawType) @@ -242,7 +264,7 @@ public enum StaticContext: Codable, Equatable, Sendable { case className(String) case structName(String) case enumName(String) - case namespaceEnum + case namespaceEnum(String) } // MARK: - Struct Skeleton @@ -533,13 +555,9 @@ public struct ExportedProperty: Codable, Equatable, Sendable { public func callName(prefix: String? = nil) -> String { if let staticContext = staticContext { switch staticContext { - case .className(let baseName), .enumName(let baseName), .structName(let baseName): + case .className(let baseName), .enumName(let baseName), .structName(let baseName), + .namespaceEnum(let baseName): return "\(baseName).\(name)" - case .namespaceEnum: - if let namespace = namespace, !namespace.isEmpty { - let namespacePath = namespace.joined(separator: ".") - return "\(namespacePath).\(name)" - } } } if let prefix = prefix { @@ -606,6 +624,10 @@ public struct ExportedSkeleton: Codable { self.protocols.append(contentsOf: other.protocols) assert(self.exposeToGlobal == other.exposeToGlobal) } + + public var isEmpty: Bool { + functions.isEmpty && classes.isEmpty && enums.isEmpty && structs.isEmpty && protocols.isEmpty + } } // MARK: - Imported Skeleton @@ -644,9 +666,14 @@ public struct ImportedFunctionSkeleton: Codable { } public func abiName(context: ImportedTypeSkeleton?) -> String { + return abiName(context: context, operation: nil) + } + + public func abiName(context: ImportedTypeSkeleton?, operation: String?) -> String { return ABINameGenerator.generateImportedABIName( baseName: name, - context: context + context: context, + operation: operation ) } } @@ -756,6 +783,8 @@ public struct ImportedTypeSkeleton: Codable { public let from: JSImportFrom? public let constructor: ImportedConstructorSkeleton? public let methods: [ImportedFunctionSkeleton] + /// Static methods available on the JavaScript constructor. + public var staticMethods: [ImportedFunctionSkeleton] public let getters: [ImportedGetterSkeleton] public let setters: [ImportedSetterSkeleton] public let documentation: String? @@ -765,7 +794,8 @@ public struct ImportedTypeSkeleton: Codable { jsName: String? = nil, from: JSImportFrom? = nil, constructor: ImportedConstructorSkeleton? = nil, - methods: [ImportedFunctionSkeleton], + methods: [ImportedFunctionSkeleton] = [], + staticMethods: [ImportedFunctionSkeleton] = [], getters: [ImportedGetterSkeleton] = [], setters: [ImportedSetterSkeleton] = [], documentation: String? = nil @@ -775,6 +805,7 @@ public struct ImportedTypeSkeleton: Codable { self.from = from self.constructor = constructor self.methods = methods + self.staticMethods = staticMethods self.getters = getters self.setters = setters self.documentation = documentation @@ -827,6 +858,10 @@ public struct ImportedFileSkeleton: Codable { try container.encode(globalSetters, forKey: .globalSetters) } } + + public var isEmpty: Bool { + functions.isEmpty && types.isEmpty && globalGetters.isEmpty && globalSetters.isEmpty + } } public struct ImportedModuleSkeleton: Codable { @@ -870,6 +905,8 @@ extension BridgeType { self = .string case "Bool": self = .bool + case "JSValue": + self = .jsValue case "Void": self = .void case "JSObject": @@ -894,12 +931,13 @@ extension BridgeType { case .double: return .f64 case .string: return nil case .jsObject: return .i32 + case .jsValue: return nil case .swiftHeapObject: // UnsafeMutableRawPointer is returned as an i32 pointer return .pointer case .unsafePointer: return .pointer - case .optional(_): + case .nullable: return nil case .caseEnum: return .i32 @@ -924,9 +962,9 @@ extension BridgeType { } } - /// Returns true if this type is optional + /// Returns true if this type is optional (nullable with null or undefined). public var isOptional: Bool { - if case .optional = self { return true } + if case .nullable = self { return true } return false } @@ -944,6 +982,8 @@ extension BridgeType { case .jsObject(let name): let typeName = name ?? "JSObject" return "\(typeName.count)\(typeName)C" + case .jsValue: + return "7JSValueV" case .swiftHeapObject(let name): return "\(name.count)\(name)C" case .unsafePointer(let ptr): @@ -963,8 +1003,9 @@ extension BridgeType { return "\(kindCode)\(p.count)\(p)" } return kindCode - case .optional(let wrapped): - return "Sq\(wrapped.mangleTypeName)" + case .nullable(let wrapped, let kind): + let prefix = kind == .null ? "Sq" : "Su" + return "\(prefix)\(wrapped.mangleTypeName)" case .caseEnum(let name), .rawValueEnum(let name, _), .associatedValueEnum(let name), @@ -991,7 +1032,9 @@ extension BridgeType { /// Side channels are needed when the wrapped type cannot be directly returned via WASM, /// or when we need to distinguish null from absent value for certain primitives. public func usesSideChannelForOptionalReturn() -> Bool { - guard case .optional(let wrappedType) = self else { return false } + guard case .nullable(let wrappedType, _) = self else { + return false + } switch wrappedType { case .string, .int, .float, .double, .jsObject, .swiftProtocol: diff --git a/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift b/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift index dd37fb3bc..92e74e621 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift @@ -148,7 +148,13 @@ import BridgeJSUtilities exposeToGlobal: config.exposeToGlobal ) for inputFile in inputFiles.sorted() { - let content = try String(contentsOf: URL(fileURLWithPath: inputFile), encoding: .utf8) + let inputURL = URL(fileURLWithPath: inputFile) + // Skip directories (e.g. .docc catalogs included in target.sourceFiles) + var isDirectory: ObjCBool = false + if FileManager.default.fileExists(atPath: inputFile, isDirectory: &isDirectory), isDirectory.boolValue { + continue + } + let content = try String(contentsOf: inputURL, encoding: .utf8) if hasBridgeJSSkipComment(content) { continue } diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/package.json b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/package.json index d6b34558d..de3af1ab8 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/package.json +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/package.json @@ -5,5 +5,8 @@ }, "bin": { "ts2swift": "./bin/ts2swift.js" + }, + "scripts": { + "test": "vitest run" } } diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js index 645be1f5a..766cd0432 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js @@ -76,13 +76,80 @@ function printUsage() { console.error('Usage: ts2swift -p [--global ]... [-o output.swift]'); } +/** + * Run ts2swift for a single input file (programmatic API, no process I/O). + * @param {string} filePath - Path to the .d.ts file + * @param {{ tsconfigPath: string, logLevel?: string, globalFiles?: string[] }} options + * @returns {string} Generated Swift source + * @throws {Error} on parse/type-check errors (diagnostics are included in the message) + */ +export function run(filePath, options) { + const { tsconfigPath, logLevel = 'info', globalFiles: globalFilesOpt = [] } = options; + const globalFiles = Array.isArray(globalFilesOpt) ? globalFilesOpt : (globalFilesOpt ? [globalFilesOpt] : []); + + const diagnosticEngine = new DiagnosticEngine(logLevel); + + const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); + const configParseResult = ts.parseJsonConfigFileContent( + configFile.config, + ts.sys, + path.dirname(path.resolve(tsconfigPath)) + ); + + if (configParseResult.errors.length > 0) { + const message = ts.formatDiagnosticsWithColorAndContext(configParseResult.errors, { + getCanonicalFileName: (fileName) => fileName, + getNewLine: () => ts.sys.newLine, + getCurrentDirectory: () => ts.sys.getCurrentDirectory(), + }); + throw new Error(`TypeScript config/parse errors:\n${message}`); + } + + const program = TypeProcessor.createProgram([filePath, ...globalFiles], configParseResult.options); + const diagnostics = program.getSemanticDiagnostics(); + if (diagnostics.length > 0) { + const message = ts.formatDiagnosticsWithColorAndContext(diagnostics, { + getCanonicalFileName: (fileName) => fileName, + getNewLine: () => ts.sys.newLine, + getCurrentDirectory: () => ts.sys.getCurrentDirectory(), + }); + throw new Error(`TypeScript semantic errors:\n${message}`); + } + + const prelude = [ + "// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,", + "// DO NOT EDIT.", + "//", + "// To update this file, just rebuild your project or run", + "// `swift package bridge-js`.", + "", + "@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit", + "", + "", + ].join("\n"); + + /** @type {string[]} */ + const bodies = []; + const globalFileSet = new Set(globalFiles); + for (const inputPath of [filePath, ...globalFiles]) { + const processor = new TypeProcessor(program.getTypeChecker(), diagnosticEngine, { + defaultImportFromGlobal: globalFileSet.has(inputPath), + }); + const result = processor.processTypeDeclarations(program, inputPath); + const body = result.content.trim(); + if (body.length > 0) bodies.push(body); + } + + const hasAny = bodies.length > 0; + return hasAny ? prelude + bodies.join("\n\n") + "\n" : ""; +} + /** * Main function to run the CLI * @param {string[]} args - Command-line arguments * @returns {void} */ export function main(args) { - // Parse command line arguments const options = parseArgs({ args, options: { @@ -118,64 +185,24 @@ export function main(args) { } const filePath = options.positionals[0]; - const diagnosticEngine = new DiagnosticEngine(options.values["log-level"] || "info"); - - diagnosticEngine.print("verbose", `Processing ${filePath}...`); - - // Create TypeScript program and process declarations - const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); - const configParseResult = ts.parseJsonConfigFileContent( - configFile.config, - ts.sys, - path.dirname(path.resolve(tsconfigPath)) - ); - - if (configParseResult.errors.length > 0) { - diagnosticEngine.tsDiagnose(configParseResult.errors); - process.exit(1); - } - + const logLevel = options.values["log-level"] || "info"; /** @type {string[]} */ const globalFiles = Array.isArray(options.values.global) ? options.values.global : (options.values.global ? [options.values.global] : []); - const program = TypeProcessor.createProgram([filePath, ...globalFiles], configParseResult.options); - const diagnostics = program.getSemanticDiagnostics(); - if (diagnostics.length > 0) { - diagnosticEngine.tsDiagnose(diagnostics); - process.exit(1); - } - - const prelude = [ - "// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,", - "// DO NOT EDIT.", - "//", - "// To update this file, just rebuild your project or run", - "// `swift package bridge-js`.", - "", - "@_spi(Experimental) import JavaScriptKit", - "", - "", - ].join("\n"); + const diagnosticEngine = new DiagnosticEngine(logLevel); + diagnosticEngine.print("verbose", `Processing ${filePath}...`); - /** @type {string[]} */ - const bodies = []; - const globalFileSet = new Set(globalFiles); - for (const inputPath of [filePath, ...globalFiles]) { - const processor = new TypeProcessor(program.getTypeChecker(), diagnosticEngine, { - defaultImportFromGlobal: globalFileSet.has(inputPath), - }); - const result = processor.processTypeDeclarations(program, inputPath); - const body = result.content.trim(); - if (body.length > 0) bodies.push(body); + let swiftOutput; + try { + swiftOutput = run(filePath, { tsconfigPath, logLevel, globalFiles }); + } catch (err) { + console.error(err.message); + process.exit(1); } - - const hasAny = bodies.length > 0; - const swiftOutput = hasAny ? prelude + bodies.join("\n\n") + "\n" : ""; - if (options.values.output) { - if (hasAny) { + if (swiftOutput.length > 0) { fs.mkdirSync(path.dirname(options.values.output), { recursive: true }); fs.writeFileSync(options.values.output, swiftOutput); } diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index e48510466..ef446af0f 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -27,7 +27,11 @@ export class TypeProcessor { static createProgram(filePaths, options) { const host = ts.createCompilerHost(options); const roots = Array.isArray(filePaths) ? filePaths : [filePaths]; - return ts.createProgram(roots, options, host); + return ts.createProgram(roots, { + ...options, + noCheck: true, + skipLibCheck: true, + }, host); } /** @@ -399,7 +403,7 @@ export class TypeProcessor { this.swiftLines.push(` case ${this.renderIdentifier(name)} = "${raw.replaceAll("\"", "\\\\\"")}"`); } this.swiftLines.push("}"); - this.swiftLines.push(`extension ${swiftEnumName}: _BridgedSwiftEnumNoPayload {}`); + this.swiftLines.push(`extension ${swiftEnumName}: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}`); this.swiftLines.push(""); return; } @@ -410,7 +414,7 @@ export class TypeProcessor { this.swiftLines.push(` case ${this.renderIdentifier(name)} = ${raw}`); } this.swiftLines.push("}"); - this.swiftLines.push(`extension ${swiftEnumName}: _BridgedSwiftEnumNoPayload {}`); + this.swiftLines.push(`extension ${swiftEnumName}: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {}`); this.swiftLines.push(""); return; } @@ -659,6 +663,15 @@ export class TypeProcessor { * @private */ visitType(type, node) { + if (this.checker.isArrayType(type)) { + const typeArgs = this.checker.getTypeArguments(type); + if (typeArgs && typeArgs.length > 0) { + const elementType = this.visitType(typeArgs[0], node); + return `[${elementType}]`; + } + return "[JSObject]"; + } + // Treat A and A as the same type if (isTypeReference(type)) { type = type.target; @@ -672,14 +685,38 @@ export class TypeProcessor { * @returns {string} */ const convert = (type) => { + // Handle nullable/undefined unions (e.g. T | null, T | undefined) + const isUnionType = (type.flags & ts.TypeFlags.Union) !== 0; + if (isUnionType) { + /** @type {ts.UnionType} */ + // @ts-ignore + const unionType = type; + const unionTypes = unionType.types; + const hasNull = unionTypes.some(t => (t.flags & ts.TypeFlags.Null) !== 0); + const hasUndefined = unionTypes.some(t => (t.flags & ts.TypeFlags.Undefined) !== 0); + const nonNullableTypes = unionTypes.filter( + t => (t.flags & ts.TypeFlags.Null) === 0 && (t.flags & ts.TypeFlags.Undefined) === 0 + ); + if (nonNullableTypes.length === 1 && (hasNull || hasUndefined)) { + const wrapped = this.visitType(nonNullableTypes[0], node); + if (hasNull && hasUndefined) { + return "JSObject"; + } + if (hasNull) { + return `Optional<${wrapped}>`; + } + return `JSUndefinedOr<${wrapped}>`; + } + } + /** @type {Record} */ const typeMap = { "number": "Double", "string": "String", "boolean": "Bool", "void": "Void", - "any": "JSObject", - "unknown": "JSObject", + "any": "JSValue", + "unknown": "JSValue", "null": "Void", "undefined": "Void", "bigint": "Int", @@ -688,19 +725,18 @@ export class TypeProcessor { "never": "Void", "Promise": "JSPromise", }; - const typeString = type.getSymbol()?.name ?? this.checker.typeToString(type); + const symbol = type.getSymbol() ?? type.aliasSymbol; + const typeString = symbol?.name ?? this.checker.typeToString(type); if (typeMap[typeString]) { return typeMap[typeString]; } - - const symbol = type.getSymbol() ?? type.aliasSymbol; if (symbol && (symbol.flags & ts.SymbolFlags.Enum) !== 0) { const typeName = symbol.name; this.seenTypes.set(type, node); return this.renderTypeIdentifier(typeName); } - if (this.checker.isArrayType(type) || this.checker.isTupleType(type) || type.getCallSignatures().length > 0) { + if (this.checker.isTupleType(type) || type.getCallSignatures().length > 0) { return "JSObject"; } // "a" | "b" -> string @@ -817,8 +853,12 @@ export class TypeProcessor { const returnType = this.visitType(signature.getReturnType(), node); const effects = this.renderEffects({ isAsync: false }); const swiftMethodName = this.renderIdentifier(swiftName); + const isStatic = node.modifiers?.some( + (modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword + ) ?? false; + const staticKeyword = isStatic ? "static " : ""; - this.swiftLines.push(` ${annotation} func ${swiftMethodName}(${params}) ${effects} -> ${returnType}`); + this.swiftLines.push(` ${annotation} ${staticKeyword}func ${swiftMethodName}(${params}) ${effects} -> ${returnType}`); } /** @@ -870,7 +910,7 @@ export class TypeProcessor { if (effects?.isAsync) { parts.push("async"); } - parts.push("throws (JSException)"); + parts.push("throws(JSException)"); return parts.join(" "); } diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap new file mode 100644 index 000000000..6fdb79f78 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -0,0 +1,374 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`ts2swift > snapshots Swift output for ArrayParameter.d.ts > ArrayParameter 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func processNumbers(_ values: [Double]) throws(JSException) -> Void + +@JSFunction func getNumbers() throws(JSException) -> [Double] + +@JSFunction func transformNumbers(_ values: [Double]) throws(JSException) -> [Double] + +@JSFunction func processStrings(_ values: [String]) throws(JSException) -> [String] + +@JSFunction func processBooleans(_ values: [Bool]) throws(JSException) -> [Bool] + +@JSFunction func processArraySyntax(_ values: [Double]) throws(JSException) -> [Double] +" +`; + +exports[`ts2swift > snapshots Swift output for Async.d.ts > Async 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func asyncReturnVoid() throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripInt(_ v: Double) throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripString(_ v: String) throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripBool(_ v: Bool) throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripFloat(_ v: Double) throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise + +@JSFunction func asyncRoundTripJSObject(_ v: JSValue) throws(JSException) -> JSPromise +" +`; + +exports[`ts2swift > snapshots Swift output for Interface.d.ts > Interface 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func returnAnimatable() throws(JSException) -> Animatable + +@JSClass struct Animatable { + @JSFunction func animate(_ keyframes: JSValue, _ options: JSValue) throws(JSException) -> JSValue + @JSFunction func getAnimations(_ options: JSValue) throws(JSException) -> JSValue +} +" +`; + +exports[`ts2swift > snapshots Swift output for InvalidPropertyNames.d.ts > InvalidPropertyNames 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func createArrayBuffer() throws(JSException) -> ArrayBufferLike + +@JSClass struct ArrayBufferLike { + @JSGetter var byteLength: Double + @JSFunction func slice(_ begin: Double, _ end: Double) throws(JSException) -> ArrayBufferLike +} + +@JSFunction func createWeirdObject() throws(JSException) -> WeirdNaming + +@JSClass struct WeirdNaming { + @JSGetter var normalProperty: String + @JSSetter func setNormalProperty(_ value: String) throws(JSException) + @JSGetter(jsName: "property-with-dashes") var property_with_dashes: Double + @JSSetter(jsName: "property-with-dashes") func setProperty_with_dashes(_ value: Double) throws(JSException) + @JSGetter(jsName: "123invalidStart") var _123invalidStart: Bool + @JSSetter(jsName: "123invalidStart") func set_123invalidStart(_ value: Bool) throws(JSException) + @JSGetter(jsName: "property with spaces") var property_with_spaces: String + @JSSetter(jsName: "property with spaces") func setProperty_with_spaces(_ value: String) throws(JSException) + @JSGetter(jsName: "@specialChar") var _specialChar: Double + @JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws(JSException) + @JSGetter var constructor: String + @JSSetter func setConstructor(_ value: String) throws(JSException) + @JSGetter var \`for\`: String + @JSSetter func setFor(_ value: String) throws(JSException) + @JSGetter var \`Any\`: String + @JSSetter(jsName: "Any") func setAny(_ value: String) throws(JSException) + @JSFunction func \`as\`() throws(JSException) -> Void + @JSFunction func \`try\`() throws(JSException) -> Void +} + +@JSClass(jsName: "$Weird") struct _Weird { + @JSFunction init() throws(JSException) + @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> Void +} + +@JSFunction func createWeirdClass() throws(JSException) -> _Weird +" +`; + +exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > MultipleImportedTypes 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func createDatabaseConnection(_ config: JSValue) throws(JSException) -> DatabaseConnection + +@JSClass struct DatabaseConnection { + @JSFunction func connect(_ url: String) throws(JSException) -> Void + @JSFunction func execute(_ query: String) throws(JSException) -> JSValue + @JSGetter var isConnected: Bool + @JSGetter var connectionTimeout: Double + @JSSetter func setConnectionTimeout(_ value: Double) throws(JSException) +} + +@JSFunction func createLogger(_ level: String) throws(JSException) -> Logger + +@JSClass struct Logger { + @JSFunction func log(_ message: String) throws(JSException) -> Void + @JSFunction func error(_ message: String, _ error: JSValue) throws(JSException) -> Void + @JSGetter var level: String +} + +@JSFunction func getConfigManager() throws(JSException) -> ConfigManager + +@JSClass struct ConfigManager { + @JSFunction func get(_ key: String) throws(JSException) -> JSValue + @JSFunction func set(_ key: String, _ value: JSValue) throws(JSException) -> Void + @JSGetter var configPath: String +} +" +`; + +exports[`ts2swift > snapshots Swift output for ObjectLikeTypes.d.ts > ObjectLikeTypes 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func acceptObject(_ v: JSObject) throws(JSException) -> Void +" +`; + +exports[`ts2swift > snapshots Swift output for OptionalNullUndefined.d.ts > OptionalNullUndefined 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func roundTripNumberNull(_ value: Optional) throws(JSException) -> Optional + +@JSFunction func roundTripNumberUndefined(_ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr + +@JSFunction func roundTripStringNull(_ value: Optional) throws(JSException) -> Optional + +@JSFunction func roundTripStringUndefined(_ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr + +@JSFunction func roundTripBooleanNull(_ value: JSObject) throws(JSException) -> JSObject + +@JSFunction func roundTripBooleanUndefined(_ value: JSObject) throws(JSException) -> JSObject + +@JSFunction func optionalNumberParamNull(_ x: Double, _ maybe: Optional) throws(JSException) -> Double + +@JSFunction func optionalNumberParamUndefined(_ x: Double, _ maybe: JSUndefinedOr) throws(JSException) -> Double + +@JSFunction func roundTripMyInterfaceNull(_ value: Optional) throws(JSException) -> Optional + +@JSClass struct MyInterface { +} + +@JSFunction func roundTripMyInterfaceUndefined(_ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr + +@JSClass struct WithOptionalFields { + @JSGetter var valueOrNull: Optional + @JSSetter func setValueOrNull(_ value: Optional) throws(JSException) + @JSGetter var valueOrUndefined: JSUndefinedOr + @JSSetter func setValueOrUndefined(_ value: JSUndefinedOr) throws(JSException) +} +" +`; + +exports[`ts2swift > snapshots Swift output for PrimitiveParameters.d.ts > PrimitiveParameters 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func check(_ a: Double, _ b: Bool) throws(JSException) -> Void +" +`; + +exports[`ts2swift > snapshots Swift output for PrimitiveReturn.d.ts > PrimitiveReturn 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func checkNumber() throws(JSException) -> Double + +@JSFunction func checkBoolean() throws(JSException) -> Bool +" +`; + +exports[`ts2swift > snapshots Swift output for ReExportFrom.d.ts > ReExportFrom 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func jsRoundTripNumber(_ v: Double) throws(JSException) -> Double + +@JSClass struct JsGreeter { + @JSFunction init(_ name: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String +} +" +`; + +exports[`ts2swift > snapshots Swift output for StringEnum.d.ts > StringEnum 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +enum FeatureFlag: String { + case foo = "foo" + case bar = "bar" +} +extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} + +@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void + +@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag +" +`; + +exports[`ts2swift > snapshots Swift output for StringParameter.d.ts > StringParameter 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func checkString(_ a: String) throws(JSException) -> Void + +@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws(JSException) -> Void +" +`; + +exports[`ts2swift > snapshots Swift output for StringReturn.d.ts > StringReturn 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func checkString() throws(JSException) -> String +" +`; + +exports[`ts2swift > snapshots Swift output for TS2SkeletonLike.d.ts > TS2SkeletonLike 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func createTS2Skeleton() throws(JSException) -> TypeScriptProcessor + +@JSClass struct TypeScriptProcessor { + @JSFunction func convert(_ ts: String) throws(JSException) -> String + @JSFunction func validate(_ ts: String) throws(JSException) -> Bool + @JSGetter var version: String +} + +@JSFunction func createCodeGenerator(_ format: String) throws(JSException) -> CodeGenerator + +@JSClass struct CodeGenerator { + @JSFunction func generate(_ input: JSValue) throws(JSException) -> String + @JSGetter var outputFormat: String +} +" +`; + +exports[`ts2swift > snapshots Swift output for TypeAlias.d.ts > TypeAlias 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func checkSimple(_ a: Double) throws(JSException) -> Void +" +`; + +exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScriptClass 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSClass struct Greeter { + @JSGetter var name: String + @JSSetter func setName(_ value: String) throws(JSException) + @JSGetter var age: Double + @JSFunction init(_ name: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String + @JSFunction func changeName(_ name: String) throws(JSException) -> Void + @JSFunction static func staticMethod(_ p1: Double, _ p2: String) throws(JSException) -> String +} +" +`; + +exports[`ts2swift > snapshots Swift output for VoidParameterVoidReturn.d.ts > VoidParameterVoidReturn 1`] = ` +"// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// \`swift package bridge-js\`. + +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit + +@JSFunction func check() throws(JSException) -> Void +" +`; diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts new file mode 100644 index 000000000..b5a099388 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts @@ -0,0 +1,17 @@ +// Array as parameter +export function processNumbers(values: number[]): void; + +// Array as return value +export function getNumbers(): number[]; + +// Array as both parameter and return value +export function transformNumbers(values: number[]): number[]; + +// String arrays +export function processStrings(values: string[]): string[]; + +// Boolean arrays +export function processBooleans(values: boolean[]): boolean[]; + +// Using Array syntax +export function processArraySyntax(values: Array): Array; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Async.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Async.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Async.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Async.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Interface.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Interface.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Interface.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Interface.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/InvalidPropertyNames.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/InvalidPropertyNames.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/InvalidPropertyNames.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/InvalidPropertyNames.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MultipleImportedTypes.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/MultipleImportedTypes.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MultipleImportedTypes.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/MultipleImportedTypes.d.ts diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ObjectLikeTypes.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ObjectLikeTypes.d.ts new file mode 100644 index 000000000..d605048cd --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ObjectLikeTypes.d.ts @@ -0,0 +1 @@ +export function acceptObject(v: object): void; diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/OptionalNullUndefined.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/OptionalNullUndefined.d.ts new file mode 100644 index 000000000..8b64528d9 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/OptionalNullUndefined.d.ts @@ -0,0 +1,20 @@ +export function roundTripNumberNull(value: number | null): number | null; +export function roundTripNumberUndefined(value: number | undefined): number | undefined; + +export function roundTripStringNull(value: string | null): string | null; +export function roundTripStringUndefined(value: string | undefined): string | undefined; + +export function roundTripBooleanNull(value: boolean | null): boolean | null; +export function roundTripBooleanUndefined(value: boolean | undefined): boolean | undefined; + +export function optionalNumberParamNull(x: number, maybe: number | null): number; +export function optionalNumberParamUndefined(x: number, maybe: number | undefined): number; + +export interface MyInterface {} +export function roundTripMyInterfaceNull(value: MyInterface | null): MyInterface | null; +export function roundTripMyInterfaceUndefined(value: MyInterface | undefined): MyInterface | undefined; + +export class WithOptionalFields { + valueOrNull: MyInterface | null; + valueOrUndefined: MyInterface | undefined; +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/PrimitiveParameters.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/PrimitiveParameters.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveReturn.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/PrimitiveReturn.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveReturn.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/PrimitiveReturn.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ReExportFrom.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ReExportFrom.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ReExportFrom.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ReExportFrom.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringEnum.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringEnum.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringEnum.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringEnum.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringParameter.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringParameter.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringReturn.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/StringReturn.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Support/ReExportTarget.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Support/ReExportTarget.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Support/ReExportTarget.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/Support/ReExportTarget.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TS2SkeletonLike.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TS2SkeletonLike.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TS2SkeletonLike.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TS2SkeletonLike.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeAlias.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeAlias.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeAlias.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeAlias.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeScriptClass.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts similarity index 73% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeScriptClass.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts index 074772f24..0745de1f9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeScriptClass.d.ts +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts @@ -4,4 +4,6 @@ export class Greeter { constructor(name: string); greet(): string; changeName(name: string): void; + + static staticMethod(p1: number, p2: string): string; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/VoidParameterVoidReturn.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/VoidParameterVoidReturn.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/tsconfig.json b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/tsconfig.json similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/tsconfig.json rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/tsconfig.json diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/ts2swift.test.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/ts2swift.test.js new file mode 100644 index 000000000..a65386924 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/ts2swift.test.js @@ -0,0 +1,41 @@ +// @ts-check +import { describe, it, expect } from 'vitest'; +import { readdirSync } from 'fs'; +import { fileURLToPath } from 'url'; +import path from 'path'; +import { run } from '../src/cli.js'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +/** Path to BridgeJSToolTests/Inputs/TypeScript (.d.ts fixtures and tsconfig). */ +const inputsDir = path.resolve(__dirname, 'fixtures'); +const tsconfigPath = path.join(inputsDir, 'tsconfig.json'); + +function runTs2Swift(dtsPath) { + return run(dtsPath, { tsconfigPath, logLevel: 'error' }); +} + +function collectDtsInputs() { + const entries = readdirSync(inputsDir, { withFileTypes: true }); + return entries + .filter((e) => e.isFile() && e.name.endsWith('.d.ts')) + .map((e) => e.name) + .sort(); +} + +describe('ts2swift', () => { + const dtsFiles = collectDtsInputs(); + if (dtsFiles.length === 0) { + it.skip('no .d.ts fixtures found in BridgeJSToolTests/Inputs', () => {}); + return; + } + + for (const dtsFile of dtsFiles) { + it(`snapshots Swift output for ${dtsFile}`, () => { + const dtsPath = path.join(inputsDir, dtsFile); + const swiftOutput = runTs2Swift(dtsPath); + const name = dtsFile.replace(/\.d\.ts$/, ''); + expect(swiftOutput).toMatchSnapshot(name); + }); + } +}); diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/vitest.config.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/vitest.config.js new file mode 100644 index 000000000..d5d33a7e1 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/vitest.config.js @@ -0,0 +1,9 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + snapshotFormat: { + escapeString: false, + }, + }, +}); diff --git a/Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSGetterMacroTests.swift b/Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSGetterMacroTests.swift index 2796c1014..6e47475b1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSGetterMacroTests.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSMacrosTests/JSGetterMacroTests.swift @@ -270,7 +270,7 @@ import BridgeJSMacros ) } - #if canImport(SwiftSyntax601) + #if canImport(SwiftSyntax602) // https://github.com/swiftlang/swift-syntax/pull/2722 @Test func variableWithTrailingComment() { TestSupport.assertMacroExpansion( diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift new file mode 100644 index 000000000..9754fbced --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift @@ -0,0 +1,187 @@ +import Foundation +import SwiftSyntax +import SwiftParser +import Testing + +@testable import BridgeJSCore +@testable import BridgeJSSkeleton + +@Suite struct BridgeJSCodegenTests { + static let inputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent( + "Inputs" + ).appendingPathComponent("MacroSwift") + static let multifileInputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() + .appendingPathComponent("Inputs").appendingPathComponent("MacroSwift").appendingPathComponent("Multifile") + + private func snapshotCodegen( + skeleton: BridgeJSSkeleton, + name: String, + filePath: String = #filePath, + function: String = #function, + sourceLocation: Testing.SourceLocation = #_sourceLocation + ) throws { + var swiftParts: [String] = [] + if let closureSupport = try ClosureCodegen().renderSupport(for: skeleton) { + swiftParts.append(closureSupport) + } + if let exported = skeleton.exported { + let exportSwift = ExportSwift( + progress: .silent, + moduleName: skeleton.moduleName, + skeleton: exported + ) + if let s = try exportSwift.finalize() { + swiftParts.append(s) + } + } + if let imported = skeleton.imported { + let importTS = ImportTS(progress: .silent, moduleName: skeleton.moduleName, skeleton: imported) + if let s = try importTS.finalize() { + swiftParts.append(s) + } + } + let combinedSwift = + swiftParts + .map { $0.trimmingCharacters(in: .newlines) } + .filter { !$0.isEmpty } + .joined(separator: "\n\n") + try assertSnapshot( + name: name, + filePath: filePath, + function: function, + sourceLocation: sourceLocation, + input: combinedSwift.data(using: String.Encoding.utf8)!, + fileExtension: "swift" + ) + let encoder = JSONEncoder() + encoder.outputFormatting = [.prettyPrinted, .sortedKeys] + let skeletonData = try encoder.encode(skeleton) + try assertSnapshot( + name: name, + filePath: filePath, + function: function, + sourceLocation: sourceLocation, + input: skeletonData, + fileExtension: "json" + ) + } + + static func collectInputs() -> [String] { + let fileManager = FileManager.default + let inputs = try! fileManager.contentsOfDirectory(atPath: Self.inputsDirectory.path) + return inputs.filter { $0.hasSuffix(".swift") }.sorted() + } + + @Test(arguments: collectInputs()) + func codegenSnapshot(input: String) throws { + let url = Self.inputsDirectory.appendingPathComponent(input) + let name = url.deletingPathExtension().lastPathComponent + let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + swiftAPI.addSourceFile(sourceFile, inputFilePath: input) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: name) + } + + @Test(arguments: [ + "Namespaces.swift", + "StaticFunctions.swift", + "StaticProperties.swift", + "EnumNamespace.swift", + ]) + func codegenSnapshotWithGlobal(input: String) throws { + let url = Self.inputsDirectory.appendingPathComponent(input) + let name = url.deletingPathExtension().lastPathComponent + let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: true) + swiftAPI.addSourceFile(sourceFile, inputFilePath: input) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: name + ".Global") + } + + @Test + func codegenCrossFileTypeResolution() throws { + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + let classBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassB.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: classBURL, encoding: .utf8)), + inputFilePath: "CrossFileClassB.swift" + ) + let classAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassA.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: classAURL, encoding: .utf8)), + inputFilePath: "CrossFileClassA.swift" + ) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: "CrossFileTypeResolution") + } + + @Test + func codegenCrossFileTypeResolutionReverseOrder() throws { + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + let classAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassA.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: classAURL, encoding: .utf8)), + inputFilePath: "CrossFileClassA.swift" + ) + let classBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassB.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: classBURL, encoding: .utf8)), + inputFilePath: "CrossFileClassB.swift" + ) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: "CrossFileTypeResolution.ReverseOrder") + } + + @Test + func codegenCrossFileFunctionTypes() throws { + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + let functionBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionB.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: functionBURL, encoding: .utf8)), + inputFilePath: "CrossFileFunctionB.swift" + ) + let functionAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionA.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: functionAURL, encoding: .utf8)), + inputFilePath: "CrossFileFunctionA.swift" + ) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: "CrossFileFunctionTypes") + } + + @Test + func codegenCrossFileFunctionTypesReverseOrder() throws { + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + let functionAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionA.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: functionAURL, encoding: .utf8)), + inputFilePath: "CrossFileFunctionA.swift" + ) + let functionBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionB.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: functionBURL, encoding: .utf8)), + inputFilePath: "CrossFileFunctionB.swift" + ) + let skeleton = try swiftAPI.finalize() + try snapshotCodegen(skeleton: skeleton, name: "CrossFileFunctionTypes.ReverseOrder") + } + + @Test + func codegenSkipsEmptySkeletons() throws { + let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) + let importedURL = Self.multifileInputsDirectory.appendingPathComponent("ImportedFunctions.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: importedURL, encoding: .utf8)), + inputFilePath: "ImportedFunctions.swift" + ) + let exportedOnlyURL = Self.multifileInputsDirectory.appendingPathComponent("ExportedOnly.swift") + swiftAPI.addSourceFile( + Parser.parse(source: try String(contentsOf: exportedOnlyURL, encoding: .utf8)), + inputFilePath: "ExportedOnly.swift" + ) + let skeleton = try swiftAPI.finalize() + #expect(skeleton.exported == nil, "Empty exported skeleton should be omitted") + try snapshotCodegen(skeleton: skeleton, name: "CrossFileSkipsEmptySkeletons") + } +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift index 16de8617e..711b04512 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSLinkTests.swift @@ -4,7 +4,6 @@ import SwiftParser import Testing @testable import BridgeJSLink @testable import BridgeJSCore -@testable import TS2Swift @testable import BridgeJSSkeleton @Suite struct BridgeJSLinkTests { @@ -36,10 +35,7 @@ import Testing static let inputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent( "Inputs" - ) - - static let importMacroInputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() - .appendingPathComponent("ImportMacroInputs") + ).appendingPathComponent("MacroSwift") static func collectInputs(extension: String) -> [String] { let fileManager = FileManager.default @@ -47,56 +43,9 @@ import Testing return inputs.filter { $0.hasSuffix(`extension`) } } - static func collectImportMacroInputs() -> [String] { - let fileManager = FileManager.default - let inputs = try! fileManager.contentsOfDirectory(atPath: Self.importMacroInputsDirectory.path) - return inputs.filter { $0.hasSuffix(".swift") } - } - @Test(arguments: collectInputs(extension: ".swift")) - func snapshotExport(input: String) throws { + func snapshot(input: String) throws { let url = Self.inputsDirectory.appendingPathComponent(input) - let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - swiftAPI.addSourceFile(sourceFile, inputFilePath: input) - let name = url.deletingPathExtension().lastPathComponent - - let outputSkeleton = try swiftAPI.finalize() - let bridgeJSLink: BridgeJSLink = BridgeJSLink( - skeletons: [outputSkeleton], - sharedMemory: false - ) - try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".Export") - } - - @Test(arguments: collectInputs(extension: ".d.ts")) - func snapshotImport(input: String) throws { - let url = Self.inputsDirectory.appendingPathComponent(input) - let name = url.deletingPathExtension().deletingPathExtension().lastPathComponent - let tsconfigPath = url.deletingLastPathComponent().appendingPathComponent("tsconfig.json") - - let nodePath = try #require(which("node")) - let swiftSource = try invokeTS2Swift( - dtsFile: url.path, - tsconfigPath: tsconfigPath.path, - nodePath: nodePath, - progress: .silent - ) - - let sourceFile = Parser.parse(source: swiftSource) - let importSwift = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - importSwift.addSourceFile(sourceFile, inputFilePath: "\(name).Macros.swift") - let skeleton = try importSwift.finalize() - let bridgeJSLink = BridgeJSLink( - skeletons: [skeleton], - sharedMemory: false - ) - try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".Import") - } - - @Test(arguments: collectImportMacroInputs()) - func snapshotImportMacroInput(input: String) throws { - let url = Self.importMacroInputsDirectory.appendingPathComponent(input) let name = url.deletingPathExtension().lastPathComponent let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) @@ -108,7 +57,7 @@ import Testing encoder.outputFormatting = [.prettyPrinted, .sortedKeys] let unifiedData = try encoder.encode(importResult) try bridgeJSLink.addSkeletonFile(data: unifiedData) - try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".ImportMacros") + try snapshot(bridgeJSLink: bridgeJSLink, name: name) } @Test(arguments: [ @@ -130,7 +79,7 @@ import Testing ], sharedMemory: false ) - try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".Global.Export") + try snapshot(bridgeJSLink: bridgeJSLink, name: name + ".Global") } @Test @@ -154,6 +103,6 @@ import Testing ], sharedMemory: false ) - try snapshot(bridgeJSLink: bridgeJSLink, name: "MixedModules.Export") + try snapshot(bridgeJSLink: bridgeJSLink, name: "MixedModules") } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ExportSwiftTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/ExportSwiftTests.swift deleted file mode 100644 index fb31ac837..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ExportSwiftTests.swift +++ /dev/null @@ -1,158 +0,0 @@ -import Foundation -import SwiftSyntax -import SwiftParser -import Testing - -@testable import BridgeJSCore -@testable import BridgeJSSkeleton - -@Suite struct ExportSwiftTests { - private func snapshot( - skeleton: BridgeJSSkeleton, - name: String? = nil, - filePath: String = #filePath, - function: String = #function, - sourceLocation: Testing.SourceLocation = #_sourceLocation - ) throws { - guard let exported = skeleton.exported else { return } - let exportSwift = ExportSwift( - progress: .silent, - moduleName: skeleton.moduleName, - skeleton: exported - ) - let closureSupport = try ClosureCodegen().renderSupport(for: skeleton) - let exportResult = try #require(try exportSwift.finalize()) - let outputSwift = ([closureSupport, exportResult] as [String?]) - .compactMap { $0?.trimmingCharacters(in: .newlines) } - .filter { !$0.isEmpty } - .joined(separator: "\n\n") - try assertSnapshot( - name: name, - filePath: filePath, - function: function, - sourceLocation: sourceLocation, - input: outputSwift.data(using: .utf8)!, - fileExtension: "swift" - ) - let encoder = JSONEncoder() - encoder.outputFormatting = [.prettyPrinted, .sortedKeys] - let outputSkeletonData = try encoder.encode(exported) - try assertSnapshot( - name: name, - filePath: filePath, - function: function, - sourceLocation: sourceLocation, - input: outputSkeletonData, - fileExtension: "json" - ) - } - - static let inputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent( - "Inputs" - ) - - static let multifileInputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() - .appendingPathComponent( - "MultifileInputs" - ) - - static func collectInputs() -> [String] { - let fileManager = FileManager.default - let inputs = try! fileManager.contentsOfDirectory(atPath: Self.inputsDirectory.path) - return inputs.filter { $0.hasSuffix(".swift") } - } - - @Test(arguments: collectInputs()) - func snapshot(input: String) throws { - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - let url = Self.inputsDirectory.appendingPathComponent(input) - let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) - swiftAPI.addSourceFile(sourceFile, inputFilePath: input) - let name = url.deletingPathExtension().lastPathComponent - try snapshot(skeleton: swiftAPI.finalize(), name: name) - } - - @Test(arguments: [ - "Namespaces.swift", - "StaticFunctions.swift", - "StaticProperties.swift", - "EnumNamespace.swift", - ]) - func snapshotWithGlobal(input: String) throws { - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: true) - let url = Self.inputsDirectory.appendingPathComponent(input) - let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) - swiftAPI.addSourceFile(sourceFile, inputFilePath: input) - let name = url.deletingPathExtension().lastPathComponent - try snapshot(skeleton: swiftAPI.finalize(), name: name + ".Global") - } - - @Test - func snapshotCrossFileTypeResolution() throws { - // Test that types defined in one file can be referenced from another file - // This tests the fix for cross-file type resolution in BridgeJS - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - - // Add ClassB first, then ClassA (which references ClassB) - let classBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassB.swift") - let classBSourceFile = Parser.parse(source: try String(contentsOf: classBURL, encoding: .utf8)) - swiftAPI.addSourceFile(classBSourceFile, inputFilePath: "CrossFileClassB.swift") - - let classAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassA.swift") - let classASourceFile = Parser.parse(source: try String(contentsOf: classAURL, encoding: .utf8)) - swiftAPI.addSourceFile(classASourceFile, inputFilePath: "CrossFileClassA.swift") - - try snapshot(skeleton: swiftAPI.finalize(), name: "CrossFileTypeResolution") - } - - @Test - func snapshotCrossFileTypeResolutionReverseOrder() throws { - // Test that types can be resolved regardless of the order files are added - // Add ClassA first (which references ClassB), then ClassB - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - - let classAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassA.swift") - let classASourceFile = Parser.parse(source: try String(contentsOf: classAURL, encoding: .utf8)) - swiftAPI.addSourceFile(classASourceFile, inputFilePath: "CrossFileClassA.swift") - - let classBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileClassB.swift") - let classBSourceFile = Parser.parse(source: try String(contentsOf: classBURL, encoding: .utf8)) - swiftAPI.addSourceFile(classBSourceFile, inputFilePath: "CrossFileClassB.swift") - - try snapshot(skeleton: swiftAPI.finalize(), name: "CrossFileTypeResolution.ReverseOrder") - } - - @Test - func snapshotCrossFileFunctionTypes() throws { - // Test that functions and methods can use cross-file types as parameters and return types - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - - // Add FunctionB first, then FunctionA (which references FunctionB in methods and functions) - let functionBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionB.swift") - let functionBSourceFile = Parser.parse(source: try String(contentsOf: functionBURL, encoding: .utf8)) - swiftAPI.addSourceFile(functionBSourceFile, inputFilePath: "CrossFileFunctionB.swift") - - let functionAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionA.swift") - let functionASourceFile = Parser.parse(source: try String(contentsOf: functionAURL, encoding: .utf8)) - swiftAPI.addSourceFile(functionASourceFile, inputFilePath: "CrossFileFunctionA.swift") - - try snapshot(skeleton: swiftAPI.finalize(), name: "CrossFileFunctionTypes") - } - - @Test - func snapshotCrossFileFunctionTypesReverseOrder() throws { - // Test that function types can be resolved regardless of the order files are added - let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false) - - // Add FunctionA first (which references FunctionB), then FunctionB - let functionAURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionA.swift") - let functionASourceFile = Parser.parse(source: try String(contentsOf: functionAURL, encoding: .utf8)) - swiftAPI.addSourceFile(functionASourceFile, inputFilePath: "CrossFileFunctionA.swift") - - let functionBURL = Self.multifileInputsDirectory.appendingPathComponent("CrossFileFunctionB.swift") - let functionBSourceFile = Parser.parse(source: try String(contentsOf: functionBURL, encoding: .utf8)) - swiftAPI.addSourceFile(functionBSourceFile, inputFilePath: "CrossFileFunctionB.swift") - - try snapshot(skeleton: swiftAPI.finalize(), name: "CrossFileFunctionTypes.ReverseOrder") - } -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportTSTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportTSTests.swift deleted file mode 100644 index 89c7dd11d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportTSTests.swift +++ /dev/null @@ -1,101 +0,0 @@ -import Testing -import Foundation -import SwiftParser -@testable import BridgeJSCore -@testable import TS2Swift -@testable import BridgeJSSkeleton - -@Suite struct ImportTSTests { - static let inputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent( - "Inputs" - ) - static let importMacroInputsDirectory = URL(fileURLWithPath: #filePath).deletingLastPathComponent() - .appendingPathComponent("ImportMacroInputs") - - static func collectInputs() -> [String] { - let fileManager = FileManager.default - let inputs = try! fileManager.contentsOfDirectory(atPath: Self.inputsDirectory.path) - return inputs.filter { $0.hasSuffix(".d.ts") } - } - - static func collectImportMacroInputs() -> [String] { - let fileManager = FileManager.default - let inputs = try! fileManager.contentsOfDirectory(atPath: Self.importMacroInputsDirectory.path) - return inputs.filter { $0.hasSuffix(".swift") } - } - - @Test(arguments: collectInputs()) - func snapshot(input: String) throws { - let url = Self.inputsDirectory.appendingPathComponent(input) - let name = url.deletingPathExtension().deletingPathExtension().deletingPathExtension().lastPathComponent - let nodePath = try #require(which("node")) - let tsconfigPath = url.deletingLastPathComponent().appendingPathComponent("tsconfig.json") - - let swiftSource = try invokeTS2Swift( - dtsFile: url.path, - tsconfigPath: tsconfigPath.path, - nodePath: nodePath, - progress: .silent - ) - try assertSnapshot( - name: name + ".Macros", - filePath: #filePath, - function: #function, - input: swiftSource.data(using: .utf8)!, - fileExtension: "swift" - ) - - let sourceFile = Parser.parse(source: swiftSource) - let importSwift = SwiftToSkeleton(progress: .silent, moduleName: "Check", exposeToGlobal: false) - importSwift.addSourceFile(sourceFile, inputFilePath: "\(name).Macros.swift") - let skeleton = try importSwift.finalize() - - guard let imported = skeleton.imported else { return } - - let importTS = ImportTS(progress: .silent, moduleName: "Check", skeleton: imported) - let importResult = try #require(try importTS.finalize()) - let closureSupport = try ClosureCodegen().renderSupport( - for: BridgeJSSkeleton(moduleName: "Check", imported: imported) - ) - let outputSwift = ([closureSupport, importResult] as [String?]) - .compactMap { $0?.trimmingCharacters(in: .newlines) } - .filter { !$0.isEmpty } - .joined(separator: "\n\n") - try assertSnapshot( - name: name, - filePath: #filePath, - function: #function, - input: outputSwift.data(using: .utf8)!, - fileExtension: "swift" - ) - } - - @Test(arguments: collectImportMacroInputs()) - func snapshotImportMacroInput(input: String) throws { - let url = Self.importMacroInputsDirectory.appendingPathComponent(input) - let name = url.deletingPathExtension().lastPathComponent - - let sourceFile = Parser.parse(source: try String(contentsOf: url, encoding: .utf8)) - let importSwift = SwiftToSkeleton(progress: .silent, moduleName: "Check", exposeToGlobal: false) - importSwift.addSourceFile(sourceFile, inputFilePath: "\(name).swift") - let skeleton = try importSwift.finalize() - - guard let imported = skeleton.imported else { return } - let importTS = ImportTS(progress: .silent, moduleName: "Check", skeleton: imported) - let importResult = try #require(try importTS.finalize()) - let closureSupport = try ClosureCodegen().renderSupport( - for: BridgeJSSkeleton(moduleName: "Check", imported: imported) - ) - let outputSwift = ([closureSupport, importResult] as [String?]) - .compactMap { $0?.trimmingCharacters(in: .newlines) } - .filter { !$0.isEmpty } - .joined(separator: "\n\n") - try assertSnapshot( - name: name + ".ImportMacros", - filePath: #filePath, - function: #function, - input: outputSwift.data(using: .utf8)!, - fileExtension: "swift" - ) - } -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayParameter.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayParameter.d.ts deleted file mode 100644 index 59674e071..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayParameter.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function checkArray(a: number[]): void; -export function checkArrayWithLength(a: number[], b: number): void; -export function checkArray(a: Array): void; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ImportedTypeInExportedInterface.swift deleted file mode 100644 index 9e3524284..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ImportedTypeInExportedInterface.swift +++ /dev/null @@ -1,7 +0,0 @@ -@JSClass class Foo { - @JSFunction init() throws(JSException) -} - -@JS func makeFoo() throws(JSException) -> Foo { - return try Foo() -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift similarity index 69% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift index 8454b7520..0cea90512 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift @@ -54,3 +54,16 @@ @JS func processItemArray(_ items: [Item]) -> [Item] @JS func processNestedItemArray(_ items: [[Item]]) -> [[Item]] + +@JS func processJSObjectArray(_ objects: [JSObject]) -> [JSObject] +@JS func processOptionalJSObjectArray(_ objects: [JSObject?]) -> [JSObject?] +@JS func processNestedJSObjectArray(_ objects: [[JSObject]]) -> [[JSObject]] + +@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void +@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void + +@JSFunction func importProcessNumbers(_ values: [Double]) throws(JSException) -> Void +@JSFunction func importGetNumbers() throws(JSException) -> [Double] +@JSFunction func importTransformNumbers(_ values: [Double]) throws(JSException) -> [Double] +@JSFunction func importProcessStrings(_ values: [String]) throws(JSException) -> [String] +@JSFunction func importProcessBooleans(_ values: [Bool]) throws(JSException) -> [Bool] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Async.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Async.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Async.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Async.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/DefaultParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DefaultParameters.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/DefaultParameters.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DefaultParameters.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift similarity index 52% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumAssociatedValue.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift index efb6cd1b1..a0e6cbfeb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumAssociatedValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift @@ -55,3 +55,66 @@ enum APIOptionalResult { } @JS func roundTripOptionalAPIOptionalResult(result: APIOptionalResult?) -> APIOptionalResult? @JS func compareAPIResults(result1: APIOptionalResult?, result2: APIOptionalResult?) -> APIOptionalResult? + +@JS enum Precision: Float { + case rough = 0.1 + case fine = 0.001 +} + +@JS enum CardinalDirection { + case north + case south + case east + case west +} + +@JS +enum TypedPayloadResult { + case precision(Precision) + case direction(CardinalDirection) + case optPrecision(Precision?) + case optDirection(CardinalDirection?) + case empty +} + +@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult +@JS func roundTripOptionalTypedPayloadResult(_ result: TypedPayloadResult?) -> TypedPayloadResult? + +@JS struct Point { + var x: Double + var y: Double +} + +@JS class User { + var name: String + + init(name: String) { + self.name = name + } +} + +@JS +enum AllTypesResult { + case structPayload(Point) + case classPayload(User) + case jsObjectPayload(JSObject) + case nestedEnum(APIResult) + case arrayPayload([Int]) + case empty +} + +@JS func roundTripAllTypesResult(_ result: AllTypesResult) -> AllTypesResult +@JS func roundTripOptionalAllTypesResult(_ result: AllTypesResult?) -> AllTypesResult? + +@JS +enum OptionalAllTypesResult { + case optStruct(Point?) + case optClass(User?) + case optJSObject(JSObject?) + case optNestedEnum(APIResult?) + case optArray([Int]?) + case empty +} + +@JS func roundTripOptionalPayloadResult(_ result: OptionalAllTypesResult) -> OptionalAllTypesResult +@JS func roundTripOptionalPayloadResultOpt(_ result: OptionalAllTypesResult?) -> OptionalAllTypesResult? diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumCase.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumCase.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumCase.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumCase.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumNamespace.swift similarity index 77% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumNamespace.swift index 26a4e9c3a..dbf044834 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumNamespace.swift @@ -53,4 +53,17 @@ enum Internal { } } -// TODO: Add namespace enum with static functions when supported +@JS(namespace: "Services.Graph") +enum GraphOperations { + @JS static func createGraph(rootId: Int) -> Int { + return rootId * 10 + } + + @JS static func nodeCount(graphId: Int) -> Int { + return graphId + } + + @JS static func validate(graphId: Int) throws(JSException) -> Bool { + return graphId > 0 + } +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumRawType.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumRawType.swift similarity index 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumRawType.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumRawType.swift index 13b502eac..6e18c913c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumRawType.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumRawType.swift @@ -124,3 +124,13 @@ @JS func processTheme(_ theme: Theme) -> HttpStatus @JS func convertPriority(_ status: HttpStatus) -> Priority @JS func validateSession(_ session: SessionId) -> Theme + +enum FeatureFlag: String { + case foo = "foo" + case bar = "bar" +} +extension FeatureFlag: _BridgedSwiftEnumNoPayload {} + +@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void + +@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/GlobalGetter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GlobalGetter.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/GlobalGetter.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GlobalGetter.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/GlobalThisImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GlobalThisImports.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/GlobalThisImports.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/GlobalThisImports.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportArray.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportArray.swift new file mode 100644 index 000000000..cd9142a26 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportArray.swift @@ -0,0 +1,2 @@ +@JSFunction func roundtrip(_ items: [Int]) throws(JSException) -> [Int] +@JSFunction func logStrings(_ items: [String]) throws(JSException) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift new file mode 100644 index 000000000..db167c5a9 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift @@ -0,0 +1,17 @@ +@JSClass class Foo { + @JSFunction init() throws(JSException) +} + +@JS func makeFoo() throws(JSException) -> Foo { + return try Foo() +} + +@JS func processFooArray(_ foos: [Foo]) -> [Foo] +@JS func processOptionalFooArray(_ foos: [Foo?]) -> [Foo?] + +@JS struct FooContainer { + var foo: Foo + var optionalFoo: Foo? +} + +@JS func roundtripFooContainer(_ container: FooContainer) -> FooContainer diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/InvalidPropertyNames.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/InvalidPropertyNames.swift new file mode 100644 index 000000000..ea5755dec --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/InvalidPropertyNames.swift @@ -0,0 +1,29 @@ +@JSFunction func createWeirdObject() throws(JSException) -> WeirdNaming + +@JSClass struct WeirdNaming { + @JSGetter var normalProperty: String + @JSSetter func setNormalProperty(_ value: String) throws(JSException) + @JSGetter(jsName: "property-with-dashes") var property_with_dashes: Double + @JSSetter(jsName: "property-with-dashes") func setProperty_with_dashes(_ value: Double) throws(JSException) + @JSGetter(jsName: "123invalidStart") var _123invalidStart: Bool + @JSSetter(jsName: "123invalidStart") func set_123invalidStart(_ value: Bool) throws(JSException) + @JSGetter(jsName: "property with spaces") var property_with_spaces: String + @JSSetter(jsName: "property with spaces") func setProperty_with_spaces(_ value: String) throws(JSException) + @JSGetter(jsName: "@specialChar") var _specialChar: Double + @JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws(JSException) + @JSGetter var constructor: String + @JSSetter func setConstructor(_ value: String) throws(JSException) + @JSGetter var `for`: String + @JSSetter func setFor(_ value: String) throws(JSException) + @JSGetter var `Any`: String + @JSSetter(jsName: "Any") func setAny(_ value: String) throws(JSException) + @JSFunction func `as`() throws(JSException) -> Void + @JSFunction func `try`() throws(JSException) -> Void +} + +@JSClass(jsName: "$Weird") struct _Weird { + @JSFunction init() throws(JSException) + @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> Void +} + +@JSFunction func createWeirdClass() throws(JSException) -> _Weird diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClass.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClass.swift new file mode 100644 index 000000000..6459f5354 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClass.swift @@ -0,0 +1,15 @@ +@JSClass struct Greeter { + @JSGetter var name: String + @JSSetter func setName(_ value: String) throws(JSException) + @JSGetter var age: Double + @JSFunction init(_ name: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String + @JSFunction func changeName(_ name: String) throws(JSException) -> Void +} + +@JSFunction func returnAnimatable() throws(JSException) -> Animatable + +@JSClass struct Animatable { + @JSFunction func animate(_ keyframes: JSObject, _ options: JSObject) throws(JSException) -> JSObject + @JSFunction func getAnimations(_ options: JSObject) throws(JSException) -> JSObject +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift new file mode 100644 index 000000000..c64952565 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift @@ -0,0 +1,12 @@ +@JSClass struct StaticBox { + @JSFunction static func create(_ value: Double) throws(JSException) -> StaticBox + @JSFunction func value() throws(JSException) -> Double + @JSFunction static func value() throws(JSException) -> Double + @JSFunction static func makeDefault() throws(JSException) -> StaticBox + @JSFunction(jsName: "with-dashes") static func dashed() throws(JSException) -> StaticBox +} + +@JSClass struct WithCtor { + @JSFunction init(_ value: Double) throws(JSException) + @JSFunction static func create(_ value: Double) throws(JSException) -> WithCtor +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift new file mode 100644 index 000000000..2a34f5f2b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift @@ -0,0 +1,41 @@ +@JS func roundTripJSValue(_ value: JSValue) -> JSValue { + return value +} + +@JS func roundTripOptionalJSValue(_ value: JSValue?) -> JSValue? { + return value +} + +@JS func roundTripJSValueArray(_ values: [JSValue]) -> [JSValue] { + return values +} + +@JS func roundTripOptionalJSValueArray(_ values: [JSValue]?) -> [JSValue]? { + return values +} + +@JS class JSValueHolder { + @JS var value: JSValue + @JS var optionalValue: JSValue? + + @JS init(value: JSValue, optionalValue: JSValue?) { + self.value = value + self.optionalValue = optionalValue + } + + @JS func update(value: JSValue, optionalValue: JSValue?) { + self.value = value + self.optionalValue = optionalValue + } + + @JS func echo(value: JSValue) -> JSValue { + return value + } + + @JS func echoOptional(_ value: JSValue?) -> JSValue? { + return value + } +} + +@JSFunction func jsEchoJSValue(_ value: JSValue) throws(JSException) -> JSValue +@JSFunction func jsEchoJSValueArray(_ values: [JSValue]) throws(JSException) -> [JSValue] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MixedGlobal.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/MixedGlobal.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MixedGlobal.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/MixedGlobal.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MixedPrivate.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/MixedPrivate.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MixedPrivate.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/MixedPrivate.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileClassA.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileClassA.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileClassA.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileClassA.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileClassB.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileClassB.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileClassB.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileClassB.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileFunctionA.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileFunctionA.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileFunctionA.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileFunctionA.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileFunctionB.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileFunctionB.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/MultifileInputs/CrossFileFunctionB.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/CrossFileFunctionB.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ExportedOnly.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ExportedOnly.swift new file mode 100644 index 000000000..d7887d2bd --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ExportedOnly.swift @@ -0,0 +1,3 @@ +struct ExportedOnly { + let value: Int = 0 +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ImportedFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ImportedFunctions.swift new file mode 100644 index 000000000..451424777 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ImportedFunctions.swift @@ -0,0 +1 @@ +@JSFunction func fetchNumber() throws(JSException) -> Int diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Namespaces.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Namespaces.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Namespaces.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Namespaces.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift new file mode 100644 index 000000000..57d994519 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift @@ -0,0 +1,128 @@ +@JS class Greeter { + @JS var name: String? + + @JS init(name: String?) { + self.name = name + } + + @JS func greet() -> String { + return "Hello, " + (self.name ?? "stranger") + "!" + } + + @JS func changeName(name: String?) { + self.name = name + } +} + +@JS +func roundTripOptionalClass(value: Greeter?) -> Greeter? { + return value +} + +@JS +class OptionalPropertyHolder { + @JS var optionalName: String? = nil + @JS var optionalAge: Int? = nil + @JS var optionalGreeter: Greeter? = nil + + @JS init() {} +} + +@JS func testOptionalPropertyRoundtrip(_ holder: OptionalPropertyHolder?) -> OptionalPropertyHolder? + +@JS +func roundTripString(name: String?) -> String? { + return name +} + +@JS +func roundTripInt(value: Int?) -> Int? { + return value +} + +@JS +func roundTripBool(flag: Bool?) -> Bool? { + return flag +} + +@JS +func roundTripFloat(number: Float?) -> Float? { + return number +} + +@JS +func roundTripDouble(precision: Double?) -> Double? { + return precision +} + +@JS func roundTripSyntax(name: Optional) -> Optional { + return name +} + +@JS func roundTripMixSyntax(name: String?) -> Optional { + return name +} + +@JS func roundTripSwiftSyntax(name: Swift.Optional) -> Swift.Optional { + return name +} + +@JS func roundTripMixedSwiftSyntax(name: String?) -> Swift.Optional { + return name +} + +@JS func roundTripWithSpaces(value: Optional) -> Optional { + return value +} + +typealias OptionalAge = Int? + +@JS func roundTripAlias(age: OptionalAge) -> OptionalAge { + return age +} + +typealias OptionalNameAlias = Optional +@JS func roundTripOptionalAlias(name: OptionalNameAlias) -> OptionalNameAlias { + return name +} + +@JS +func testMixedOptionals(firstName: String?, lastName: String?, age: Int?, active: Bool) -> String? { + return nil +} + +@JSClass struct WithOptionalJSClass { + @JSFunction init(valueOrNull: String?, valueOrUndefined: JSUndefinedOr) throws(JSException) + + @JSGetter var stringOrNull: String? + @JSSetter func setStringOrNull(_ value: String?) throws(JSException) + @JSGetter var stringOrUndefined: JSUndefinedOr + @JSSetter func setStringOrUndefined(_ value: JSUndefinedOr) throws(JSException) + @JSFunction func roundTripStringOrNull(value: String?) throws(JSException) -> String? + @JSFunction func roundTripStringOrUndefined( + value: JSUndefinedOr + ) throws(JSException) -> JSUndefinedOr + + @JSGetter var doubleOrNull: Double? + @JSSetter func setDoubleOrNull(_ value: Double?) throws(JSException) + @JSGetter var doubleOrUndefined: JSUndefinedOr + @JSSetter func setDoubleOrUndefined(_ value: JSUndefinedOr) throws(JSException) + @JSFunction func roundTripDoubleOrNull(value: Double?) throws(JSException) -> Double? + @JSFunction func roundTripDoubleOrUndefined( + value: JSUndefinedOr + ) throws(JSException) -> JSUndefinedOr + + @JSGetter var boolOrNull: Bool? + @JSSetter func setBoolOrNull(_ value: Bool?) throws(JSException) + @JSGetter var boolOrUndefined: JSUndefinedOr + @JSSetter func setBoolOrUndefined(_ value: JSUndefinedOr) throws(JSException) + @JSFunction func roundTripBoolOrNull(value: Bool?) throws(JSException) -> Bool? + @JSFunction func roundTripBoolOrUndefined(value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr + + @JSGetter var intOrNull: Int? + @JSSetter func setIntOrNull(_ value: Int?) throws(JSException) + @JSGetter var intOrUndefined: JSUndefinedOr + @JSSetter func setIntOrUndefined(_ value: JSUndefinedOr) throws(JSException) + @JSFunction func roundTripIntOrNull(value: Int?) throws(JSException) -> Int? + @JSFunction func roundTripIntOrUndefined(value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveParameters.swift new file mode 100644 index 000000000..97495d947 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveParameters.swift @@ -0,0 +1,2 @@ +@JS func check(a: Int, b: UInt, c: Float, d: Double, e: Bool) {} +@JSFunction func check(_ a: Double, _ b: Bool) throws(JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveReturn.swift similarity index 65% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveReturn.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveReturn.swift index 144a759ec..d2a65faef 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveReturn.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveReturn.swift @@ -3,3 +3,6 @@ @JS func checkFloat() -> Float { fatalError() } @JS func checkDouble() -> Double { fatalError() } @JS func checkBool() -> Bool { fatalError() } + +@JSFunction func checkNumber() throws(JSException) -> Double +@JSFunction func checkBoolean() throws(JSException) -> Bool diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PropertyTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PropertyTypes.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PropertyTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PropertyTypes.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Protocol.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StaticFunctions.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StaticFunctions.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StaticFunctions.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StaticProperties.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StaticProperties.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StaticProperties.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StaticProperties.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringParameter.swift new file mode 100644 index 000000000..32fc62f32 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringParameter.swift @@ -0,0 +1,5 @@ +@JS func checkString(a: String) {} +@JS func roundtripString(a: String) -> String { return a } + +@JSFunction func checkString(_ a: String) throws(JSException) -> Void +@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws(JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringReturn.swift new file mode 100644 index 000000000..4b5bc088a --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringReturn.swift @@ -0,0 +1,2 @@ +@JS func checkString() -> String { fatalError() } +@JSFunction func checkString() throws(JSException) -> String diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftClass.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClass.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftClass.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClass.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClosure.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftClosure.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClosure.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/SwiftClosureImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClosureImports.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/SwiftClosureImports.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClosureImports.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift similarity index 88% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftStruct.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift index ac316a05a..0d84f4736 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftStruct.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift @@ -53,3 +53,10 @@ @JS static var computedSetting: String { "Config: \(defaultConfig)" } @JS static func update(_ timeout: Double) -> Double } + +@JS struct Container { + var object: JSObject + var optionalObject: JSObject? +} + +@JS func roundtripContainer(_ container: Container) -> Container diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/SwiftStructImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStructImports.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportMacroInputs/SwiftStructImports.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStructImports.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Throws.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Throws.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Throws.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Throws.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/UnsafePointer.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/UnsafePointer.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/UnsafePointer.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/UnsafePointer.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/VoidParameterVoidReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/VoidParameterVoidReturn.swift new file mode 100644 index 000000000..4b9cd0d02 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/VoidParameterVoidReturn.swift @@ -0,0 +1,2 @@ +@JS func check() {} +@JSFunction func check() throws(JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Optionals.swift deleted file mode 100644 index d256a8753..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Optionals.swift +++ /dev/null @@ -1,92 +0,0 @@ -@JS class Greeter { - @JS var name: String? - - @JS init(name: String?) { - self.name = name - } - - @JS func greet() -> String { - return "Hello, " + (self.name ?? "stranger") + "!" - } - - @JS func changeName(name: String?) { - self.name = name - } -} - -@JS -func roundTripOptionalClass(value: Greeter?) -> Greeter? { - return value -} - -@JS -class OptionalPropertyHolder { - @JS var optionalName: String? = nil - @JS var optionalAge: Int? = nil - @JS var optionalGreeter: Greeter? = nil - - @JS init() {} -} - -@JS func testOptionalPropertyRoundtrip(_ holder: OptionalPropertyHolder?) -> OptionalPropertyHolder? - -@JS -func roundTripString(name: String?) -> String? { - return name -} - -@JS -func roundTripInt(value: Int?) -> Int? { - return value -} - -@JS -func roundTripBool(flag: Bool?) -> Bool? { - return flag -} - -@JS -func roundTripFloat(number: Float?) -> Float? { - return number -} - -@JS -func roundTripDouble(precision: Double?) -> Double? { - return precision -} - -@JS func roundTripSyntax(name: Optional) -> Optional { - return name -} - -@JS func roundTripMixSyntax(name: String?) -> Optional { - return name -} - -@JS func roundTripSwiftSyntax(name: Swift.Optional) -> Swift.Optional { - return name -} - -@JS func roundTripMixedSwiftSyntax(name: String?) -> Swift.Optional { - return name -} - -@JS func roundTripWithSpaces(value: Optional) -> Optional { - return value -} - -typealias OptionalAge = Int? - -@JS func roundTripAlias(age: OptionalAge) -> OptionalAge { - return age -} - -typealias OptionalNameAlias = Optional -@JS func roundTripOptionalAlias(name: OptionalNameAlias) -> OptionalNameAlias { - return name -} - -@JS -func testMixedOptionals(firstName: String?, lastName: String?, age: Int?, active: Bool) -> String? { - return nil -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.swift deleted file mode 100644 index a0d4353eb..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.swift +++ /dev/null @@ -1 +0,0 @@ -@JS func check(a: Int, b: UInt, c: Float, d: Double, e: Bool) {} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.swift deleted file mode 100644 index c735c56f7..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.swift +++ /dev/null @@ -1,2 +0,0 @@ -@JS func checkString(a: String) {} -@JS func roundtripString(a: String) -> String { return a } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.swift deleted file mode 100644 index fe070f0db..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.swift +++ /dev/null @@ -1 +0,0 @@ -@JS func checkString() -> String { fatalError() } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.swift deleted file mode 100644 index ba0cf5d23..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.swift +++ /dev/null @@ -1 +0,0 @@ -@JS func check() {} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/TS2SwiftVitestTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/TS2SwiftVitestTests.swift new file mode 100644 index 000000000..bb3d2e0a4 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/TS2SwiftVitestTests.swift @@ -0,0 +1,34 @@ +import Foundation +import Testing + +/// Runs the TS2Swift JavaScript test suite (Vitest) so that `swift test --package-path ./Plugins/BridgeJS` +/// validates both the TypeScript ts2swift output and the Swift codegen. For fast iteration on ts2swift, +/// run `npm test` directly in `Sources/TS2Swift/JavaScript`. +@Suite struct TS2SwiftVitestTests { + @Test + func ts2SwiftVitestSuitePasses() throws { + let testFileURL = URL(fileURLWithPath: #filePath) + let ts2SwiftJSDir = + testFileURL + .deletingLastPathComponent() // BridgeJSToolTests + .deletingLastPathComponent() // Tests + .deletingLastPathComponent() // BridgeJS package root + .appendingPathComponent("Sources") + .appendingPathComponent("TS2Swift") + .appendingPathComponent("JavaScript") + let process = Process() + process.executableURL = URL(fileURLWithPath: "/usr/bin/env") + var arguments = ["npm", "run", "test"] + if ProcessInfo.processInfo.environment["UPDATE_SNAPSHOTS"] != nil { + arguments.append(contentsOf: ["--", "--update"]) + } + process.arguments = arguments + process.currentDirectoryURL = ts2SwiftJSDir + try process.run() + process.waitUntilExit() + #expect( + process.terminationStatus == 0, + "TS2Swift Vitest suite failed (exit code \(process.terminationStatus)). Run `cd Sources/TS2Swift/JavaScript && npm test` for details." + ) + } +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json new file mode 100644 index 000000000..8eab0c059 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json @@ -0,0 +1,1285 @@ +{ + "exported" : { + "classes" : [ + { + "methods" : [ + + ], + "name" : "Item", + "properties" : [ + + ], + "swiftCallName" : "Item" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "Direction", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Direction", + "tsFullPath" : "Direction" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "pending", + "rawValue" : "0" + }, + { + "associatedValues" : [ + + ], + "name" : "active", + "rawValue" : "1" + }, + { + "associatedValues" : [ + + ], + "name" : "completed", + "rawValue" : "2" + } + ], + "emitStyle" : "const", + "name" : "Status", + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Status", + "tsFullPath" : "Status" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_processIntArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processIntArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "abiName" : "bjs_processStringArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processStringArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "abiName" : "bjs_processDoubleArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processDoubleArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "abiName" : "bjs_processBoolArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processBoolArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + }, + { + "abiName" : "bjs_processPointArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processPointArray", + "parameters" : [ + { + "label" : "_", + "name" : "points", + "type" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + } + }, + { + "abiName" : "bjs_processDirectionArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processDirectionArray", + "parameters" : [ + { + "label" : "_", + "name" : "directions", + "type" : { + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } + } + } + }, + { + "abiName" : "bjs_processStatusArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processStatusArray", + "parameters" : [ + { + "label" : "_", + "name" : "statuses", + "type" : { + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Status", + "_1" : "Int" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Status", + "_1" : "Int" + } + } + } + } + }, + { + "abiName" : "bjs_sumIntArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "sumIntArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_findFirstPoint", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "findFirstPoint", + "parameters" : [ + { + "label" : "_", + "name" : "points", + "type" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + } + }, + { + "label" : "matching", + "name" : "matching", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Point" + } + } + }, + { + "abiName" : "bjs_processUnsafeRawPointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processUnsafeRawPointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + } + } + }, + { + "abiName" : "bjs_processUnsafeMutableRawPointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processUnsafeMutableRawPointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + } + } + }, + { + "abiName" : "bjs_processOpaquePointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOpaquePointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalIntArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalIntArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalStringArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalStringArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_processOptionalPointArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalPointArray", + "parameters" : [ + { + "label" : "_", + "name" : "points", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalDirectionArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalDirectionArray", + "parameters" : [ + { + "label" : "_", + "name" : "directions", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalStatusArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalStatusArray", + "parameters" : [ + { + "label" : "_", + "name" : "statuses", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Status", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Status", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processNestedIntArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processNestedIntArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + } + }, + { + "abiName" : "bjs_processNestedStringArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processNestedStringArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + } + }, + { + "abiName" : "bjs_processNestedPointArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processNestedPointArray", + "parameters" : [ + { + "label" : "_", + "name" : "points", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + } + } + } + }, + { + "abiName" : "bjs_processItemArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processItemArray", + "parameters" : [ + { + "label" : "_", + "name" : "items", + "type" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Item" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Item" + } + } + } + } + }, + { + "abiName" : "bjs_processNestedItemArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processNestedItemArray", + "parameters" : [ + { + "label" : "_", + "name" : "items", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Item" + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Item" + } + } + } + } + } + } + }, + { + "abiName" : "bjs_processJSObjectArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processJSObjectArray", + "parameters" : [ + { + "label" : "_", + "name" : "objects", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalJSObjectArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalJSObjectArray", + "parameters" : [ + { + "label" : "_", + "name" : "objects", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_processNestedJSObjectArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processNestedJSObjectArray", + "parameters" : [ + { + "label" : "_", + "name" : "objects", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "Point", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "double" : { + + } + } + } + ], + "swiftCallName" : "Point" + } + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "checkArray", + "parameters" : [ + { + "name" : "a", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "checkArrayWithLength", + "parameters" : [ + { + "name" : "a", + "type" : { + "jsObject" : { + + } + } + }, + { + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "importProcessNumbers", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "importGetNumbers", + "parameters" : [ + + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "name" : "importTransformNumbers", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "name" : "importProcessStrings", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "name" : "importProcessBooleans", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift similarity index 60% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index 711694c9d..023caf21f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -41,19 +41,19 @@ extension Direction: _BridgedSwiftCaseEnum { } } -extension Status: _BridgedSwiftEnumNoPayload { +extension Status: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Point: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { - let y = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let x = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let y = Double.bridgeJSLiftParameter() + let x = Double.bridgeJSLiftParameter() return Point(x: x, y: y) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.x) - _swift_js_push_f64(self.y) + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -93,19 +93,8 @@ fileprivate func _bjs_struct_lift_Point() -> Int32 { @_cdecl("bjs_processIntArray") public func _bjs_processIntArray() -> Void { #if arch(wasm32) - let ret = processIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + let ret = processIntArray(_: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -115,22 +104,8 @@ public func _bjs_processIntArray() -> Void { @_cdecl("bjs_processStringArray") public func _bjs_processStringArray() -> Void { #if arch(wasm32) - let ret = processStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(ret.count)) + let ret = processStringArray(_: [String].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -140,19 +115,8 @@ public func _bjs_processStringArray() -> Void { @_cdecl("bjs_processDoubleArray") public func _bjs_processDoubleArray() -> Void { #if arch(wasm32) - let ret = processDoubleArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_f64(__bjs_elem_ret)} - _swift_js_push_i32(Int32(ret.count)) + let ret = processDoubleArray(_: [Double].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -162,19 +126,8 @@ public func _bjs_processDoubleArray() -> Void { @_cdecl("bjs_processBoolArray") public func _bjs_processBoolArray() -> Void { #if arch(wasm32) - let ret = processBoolArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Bool] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(__bjs_elem_ret ? 1 : 0)} - _swift_js_push_i32(Int32(ret.count)) + let ret = processBoolArray(_: [Bool].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -184,19 +137,8 @@ public func _bjs_processBoolArray() -> Void { @_cdecl("bjs_processPointArray") public func _bjs_processPointArray() -> Void { #if arch(wasm32) - let ret = processPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = processPointArray(_: [Point].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -206,19 +148,8 @@ public func _bjs_processPointArray() -> Void { @_cdecl("bjs_processDirectionArray") public func _bjs_processDirectionArray() -> Void { #if arch(wasm32) - let ret = processDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Direction] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Direction.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret.bridgeJSLowerParameter()))} - _swift_js_push_i32(Int32(ret.count)) + let ret = processDirectionArray(_: [Direction].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -228,19 +159,8 @@ public func _bjs_processDirectionArray() -> Void { @_cdecl("bjs_processStatusArray") public func _bjs_processStatusArray() -> Void { #if arch(wasm32) - let ret = processStatusArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Status] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Status.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret.bridgeJSLowerParameter()))} - _swift_js_push_i32(Int32(ret.count)) + let ret = processStatusArray(_: [Status].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -250,16 +170,7 @@ public func _bjs_processStatusArray() -> Void { @_cdecl("bjs_sumIntArray") public func _bjs_sumIntArray() -> Int32 { #if arch(wasm32) - let ret = sumIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + let ret = sumIntArray(_: [Int].bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -270,16 +181,7 @@ public func _bjs_sumIntArray() -> Int32 { @_cdecl("bjs_findFirstPoint") public func _bjs_findFirstPoint(_ matchingBytes: Int32, _ matchingLength: Int32) -> Void { #if arch(wasm32) - let ret = findFirstPoint(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }(), matching: String.bridgeJSLiftParameter(matchingBytes, matchingLength)) + let ret = findFirstPoint(_: [Point].bridgeJSLiftParameter(), matching: String.bridgeJSLiftParameter(matchingBytes, matchingLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -290,19 +192,8 @@ public func _bjs_findFirstPoint(_ matchingBytes: Int32, _ matchingLength: Int32) @_cdecl("bjs_processUnsafeRawPointerArray") public func _bjs_processUnsafeRawPointerArray() -> Void { #if arch(wasm32) - let ret = processUnsafeRawPointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [UnsafeRawPointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(UnsafeRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = processUnsafeRawPointerArray(_: [UnsafeRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -312,19 +203,8 @@ public func _bjs_processUnsafeRawPointerArray() -> Void { @_cdecl("bjs_processUnsafeMutableRawPointerArray") public func _bjs_processUnsafeMutableRawPointerArray() -> Void { #if arch(wasm32) - let ret = processUnsafeMutableRawPointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [UnsafeMutableRawPointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(UnsafeMutableRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = processUnsafeMutableRawPointerArray(_: [UnsafeMutableRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -334,19 +214,8 @@ public func _bjs_processUnsafeMutableRawPointerArray() -> Void { @_cdecl("bjs_processOpaquePointerArray") public func _bjs_processOpaquePointerArray() -> Void { #if arch(wasm32) - let ret = processOpaquePointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [OpaquePointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(OpaquePointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = processOpaquePointerArray(_: [OpaquePointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -361,7 +230,7 @@ public func _bjs_processOptionalIntArray() -> Void { var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -369,7 +238,7 @@ public func _bjs_processOptionalIntArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_unwrapped_ret_elem))} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -386,7 +255,7 @@ public func _bjs_processOptionalStringArray() -> Void { var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -394,10 +263,7 @@ public func _bjs_processOptionalStringArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - var __bjs_str_ret_elem = __bjs_unwrapped_ret_elem - __bjs_str_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -413,23 +279,12 @@ public func _bjs_processOptionalArray(_ values: Int32) -> Void { if values == 0 { return Optional<[Int]>.none } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }() + return [Int].bridgeJSLiftParameter() } }()) let __bjs_isSome_ret = ret != nil if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") @@ -445,7 +300,7 @@ public func _bjs_processOptionalPointArray() -> Void { var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -470,7 +325,7 @@ public func _bjs_processOptionalDirectionArray() -> Void { var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -478,7 +333,7 @@ public func _bjs_processOptionalDirectionArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(__bjs_unwrapped_ret_elem.bridgeJSLowerParameter())} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -495,7 +350,7 @@ public func _bjs_processOptionalStatusArray() -> Void { var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -503,7 +358,7 @@ public func _bjs_processOptionalStatusArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(__bjs_unwrapped_ret_elem.bridgeJSLowerParameter())} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -520,24 +375,13 @@ public func _bjs_processNestedIntArray() -> Void { var __result: [[Int]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + __result.append([Int].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret_elem))} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -553,27 +397,13 @@ public func _bjs_processNestedStringArray() -> Void { var __result: [[String]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + __result.append([String].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - var __bjs_ret_elem_elem = __bjs_elem_ret_elem - __bjs_ret_elem_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -589,24 +419,13 @@ public func _bjs_processNestedPointArray() -> Void { var __result: [[Point]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Point] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Point.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) + __result.append([Point].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - __bjs_elem_ret_elem.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -617,51 +436,87 @@ public func _bjs_processNestedPointArray() -> Void { @_cdecl("bjs_processItemArray") public func _bjs_processItemArray() -> Void { #if arch(wasm32) - let ret = processItemArray(_: { + let ret = processItemArray(_: [Item].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_processNestedItemArray") +@_cdecl("bjs_processNestedItemArray") +public func _bjs_processNestedItemArray() -> Void { + #if arch(wasm32) + let ret = processNestedItemArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Item] = [] + var __result: [[Item]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Item.bridgeJSLiftParameter(_swift_js_pop_pointer())) + __result.append([Item].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_processNestedItemArray") -@_cdecl("bjs_processNestedItemArray") -public func _bjs_processNestedItemArray() -> Void { +@_expose(wasm, "bjs_processJSObjectArray") +@_cdecl("bjs_processJSObjectArray") +public func _bjs_processJSObjectArray() -> Void { #if arch(wasm32) - let ret = processNestedItemArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Item]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ + let ret = processJSObjectArray(_: [JSObject].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_processOptionalJSObjectArray") +@_cdecl("bjs_processOptionalJSObjectArray") +public func _bjs_processOptionalJSObjectArray() -> Void { + #if arch(wasm32) + let ret = processOptionalJSObjectArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Item] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Item.bridgeJSLiftParameter(_swift_js_pop_pointer())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result - }()) + }()) + for __bjs_elem_ret in ret { + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + _swift_js_push_i32(Int32(ret.count)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_processNestedJSObjectArray") +@_cdecl("bjs_processNestedJSObjectArray") +public func _bjs_processNestedJSObjectArray() -> Void { + #if arch(wasm32) + let ret = processNestedJSObjectArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[JSObject]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([JSObject].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_pointer(__bjs_elem_ret_elem.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -691,4 +546,127 @@ fileprivate func _bjs_Item_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 fileprivate func _bjs_Item_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") } -#endif \ No newline at end of file +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_checkArray") +fileprivate func bjs_checkArray(_ a: Int32) -> Void +#else +fileprivate func bjs_checkArray(_ a: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$checkArray(_ a: JSObject) throws(JSException) -> Void { + let aValue = a.bridgeJSLowerParameter() + bjs_checkArray(aValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_checkArrayWithLength") +fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void +#else +fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void { + let aValue = a.bridgeJSLowerParameter() + let bValue = b.bridgeJSLowerParameter() + bjs_checkArrayWithLength(aValue, bValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importProcessNumbers") +fileprivate func bjs_importProcessNumbers() -> Void +#else +fileprivate func bjs_importProcessNumbers() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importProcessNumbers(_ values: [Double]) throws(JSException) -> Void { + let _ = values.bridgeJSLowerParameter() + bjs_importProcessNumbers() + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importGetNumbers") +fileprivate func bjs_importGetNumbers() -> Void +#else +fileprivate func bjs_importGetNumbers() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importGetNumbers() throws(JSException) -> [Double] { + bjs_importGetNumbers() + if let error = _swift_js_take_exception() { + throw error + } + return [Double].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importTransformNumbers") +fileprivate func bjs_importTransformNumbers() -> Void +#else +fileprivate func bjs_importTransformNumbers() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importTransformNumbers(_ values: [Double]) throws(JSException) -> [Double] { + let _ = values.bridgeJSLowerParameter() + bjs_importTransformNumbers() + if let error = _swift_js_take_exception() { + throw error + } + return [Double].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importProcessStrings") +fileprivate func bjs_importProcessStrings() -> Void +#else +fileprivate func bjs_importProcessStrings() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importProcessStrings(_ values: [String]) throws(JSException) -> [String] { + let _ = values.bridgeJSLowerParameter() + bjs_importProcessStrings() + if let error = _swift_js_take_exception() { + throw error + } + return [String].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importProcessBooleans") +fileprivate func bjs_importProcessBooleans() -> Void +#else +fileprivate func bjs_importProcessBooleans() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importProcessBooleans(_ values: [Bool]) throws(JSException) -> [Bool] { + let _ = values.bridgeJSLowerParameter() + bjs_importProcessBooleans() + if let error = _swift_js_take_exception() { + throw error + } + return [Bool].bridgeJSLiftReturn() +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.json new file mode 100644 index 000000000..a780871ba --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.json @@ -0,0 +1,187 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_asyncReturnVoid", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncReturnVoid", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripInt", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripInt", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripString", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripString", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripBool", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripBool", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripFloat", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripFloat", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "float" : { + + } + } + } + ], + "returnType" : { + "float" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripDouble", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripDouble", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_asyncRoundTripJSObject", + "effects" : { + "isAsync" : true, + "isStatic" : false, + "isThrows" : false + }, + "name" : "asyncRoundTripJSObject", + "parameters" : [ + { + "label" : "_", + "name" : "v", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.json new file mode 100644 index 000000000..9b056b650 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.json @@ -0,0 +1,152 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_FunctionA_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_FunctionA_processB", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processB", + "parameters" : [ + { + "label" : "b", + "name" : "b", + "type" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_FunctionA_createB", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createB", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "name" : "FunctionA", + "properties" : [ + + ], + "swiftCallName" : "FunctionA" + }, + { + "constructor" : { + "abiName" : "bjs_FunctionB_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "FunctionB", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "FunctionB" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_standaloneFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "standaloneFunction", + "parameters" : [ + { + "label" : "b", + "name" : "b", + "type" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.json new file mode 100644 index 000000000..d76a1622d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.json @@ -0,0 +1,152 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_FunctionB_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "FunctionB", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "FunctionB" + }, + { + "constructor" : { + "abiName" : "bjs_FunctionA_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_FunctionA_processB", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processB", + "parameters" : [ + { + "label" : "b", + "name" : "b", + "type" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_FunctionA_createB", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createB", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "name" : "FunctionA", + "properties" : [ + + ], + "swiftCallName" : "FunctionA" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_standaloneFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "standaloneFunction", + "parameters" : [ + { + "label" : "b", + "name" : "b", + "type" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "FunctionB" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.json new file mode 100644 index 000000000..10c079b27 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.json @@ -0,0 +1,25 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "fetchNumber", + "parameters" : [ + + ], + "returnType" : { + "int" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.swift new file mode 100644 index 000000000..21e4e939a --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.swift @@ -0,0 +1,16 @@ +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_fetchNumber") +fileprivate func bjs_fetchNumber() -> Int32 +#else +fileprivate func bjs_fetchNumber() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$fetchNumber() throws(JSException) -> Int { + let ret = bjs_fetchNumber() + if let error = _swift_js_take_exception() { + throw error + } + return Int.bridgeJSLiftReturn(ret) +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json new file mode 100644 index 000000000..59fb8484a --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json @@ -0,0 +1,65 @@ +{ + "exported" : { + "classes" : [ + { + "methods" : [ + + ], + "name" : "ClassA", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "linkedB", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "ClassB" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "ClassA" + }, + { + "constructor" : { + "abiName" : "bjs_ClassB_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "ClassB", + "properties" : [ + + ], + "swiftCallName" : "ClassB" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json new file mode 100644 index 000000000..cc10331a4 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json @@ -0,0 +1,65 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_ClassB_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "ClassB", + "properties" : [ + + ], + "swiftCallName" : "ClassB" + }, + { + "methods" : [ + + ], + "name" : "ClassA", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "linkedB", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "ClassB" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "ClassA" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json new file mode 100644 index 000000000..8c088a35e --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json @@ -0,0 +1,1283 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_DefaultGreeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "DefaultGreeter", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "DefaultGreeter" + }, + { + "constructor" : { + "abiName" : "bjs_EmptyGreeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "EmptyGreeter", + "properties" : [ + + ], + "swiftCallName" : "EmptyGreeter" + }, + { + "constructor" : { + "abiName" : "bjs_ConstructorDefaults_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "defaultValue" : { + "string" : { + "_0" : "Default" + } + }, + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "defaultValue" : { + "int" : { + "_0" : 42 + } + }, + "label" : "count", + "name" : "count", + "type" : { + "int" : { + + } + } + }, + { + "defaultValue" : { + "bool" : { + "_0" : true + } + }, + "label" : "enabled", + "name" : "enabled", + "type" : { + "bool" : { + + } + } + }, + { + "defaultValue" : { + "enumCase" : { + "_0" : "Status", + "_1" : "active" + } + }, + "label" : "status", + "name" : "status", + "type" : { + "caseEnum" : { + "_0" : "Status" + } + } + }, + { + "defaultValue" : { + "null" : { + + } + }, + "label" : "tag", + "name" : "tag", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "ConstructorDefaults", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "count", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "enabled", + "type" : { + "bool" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "status", + "type" : { + "caseEnum" : { + "_0" : "Status" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "tag", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "ConstructorDefaults" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "active" + }, + { + "associatedValues" : [ + + ], + "name" : "inactive" + }, + { + "associatedValues" : [ + + ], + "name" : "pending" + } + ], + "emitStyle" : "const", + "explicitAccessControl" : "public", + "name" : "Status", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Status", + "tsFullPath" : "Status" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_testStringDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testStringDefault", + "parameters" : [ + { + "defaultValue" : { + "string" : { + "_0" : "Hello World" + } + }, + "label" : "message", + "name" : "message", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_testNegativeIntDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testNegativeIntDefault", + "parameters" : [ + { + "defaultValue" : { + "int" : { + "_0" : -42 + } + }, + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_testBoolDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testBoolDefault", + "parameters" : [ + { + "defaultValue" : { + "bool" : { + "_0" : true + } + }, + "label" : "flag", + "name" : "flag", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_testNegativeFloatDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testNegativeFloatDefault", + "parameters" : [ + { + "defaultValue" : { + "float" : { + "_0" : -273.15 + } + }, + "label" : "temp", + "name" : "temp", + "type" : { + "float" : { + + } + } + } + ], + "returnType" : { + "float" : { + + } + } + }, + { + "abiName" : "bjs_testDoubleDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testDoubleDefault", + "parameters" : [ + { + "defaultValue" : { + "double" : { + "_0" : 2.718 + } + }, + "label" : "precision", + "name" : "precision", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_testOptionalDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testOptionalDefault", + "parameters" : [ + { + "defaultValue" : { + "null" : { + + } + }, + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testOptionalStringDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testOptionalStringDefault", + "parameters" : [ + { + "defaultValue" : { + "string" : { + "_0" : "Hi" + } + }, + "label" : "greeting", + "name" : "greeting", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testMultipleDefaults", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testMultipleDefaults", + "parameters" : [ + { + "defaultValue" : { + "string" : { + "_0" : "Default Title" + } + }, + "label" : "title", + "name" : "title", + "type" : { + "string" : { + + } + } + }, + { + "defaultValue" : { + "int" : { + "_0" : 10 + } + }, + "label" : "count", + "name" : "count", + "type" : { + "int" : { + + } + } + }, + { + "defaultValue" : { + "bool" : { + "_0" : false + } + }, + "label" : "enabled", + "name" : "enabled", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_testEnumDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testEnumDefault", + "parameters" : [ + { + "defaultValue" : { + "enumCase" : { + "_0" : "Status", + "_1" : "active" + } + }, + "label" : "status", + "name" : "status", + "type" : { + "caseEnum" : { + "_0" : "Status" + } + } + } + ], + "returnType" : { + "caseEnum" : { + "_0" : "Status" + } + } + }, + { + "abiName" : "bjs_testComplexInit", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testComplexInit", + "parameters" : [ + { + "defaultValue" : { + "objectWithArguments" : { + "_0" : "DefaultGreeter", + "_1" : [ + { + "string" : { + "_0" : "DefaultUser" + } + } + ] + } + }, + "label" : "greeter", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "DefaultGreeter" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "DefaultGreeter" + } + } + }, + { + "abiName" : "bjs_testEmptyInit", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testEmptyInit", + "parameters" : [ + { + "defaultValue" : { + "object" : { + "_0" : "EmptyGreeter" + } + }, + "label" : "greeter", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "EmptyGreeter" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "EmptyGreeter" + } + } + }, + { + "abiName" : "bjs_testOptionalStructDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testOptionalStructDefault", + "parameters" : [ + { + "defaultValue" : { + "null" : { + + } + }, + "label" : "point", + "name" : "point", + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testOptionalStructWithValueDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testOptionalStructWithValueDefault", + "parameters" : [ + { + "defaultValue" : { + "structLiteral" : { + "_0" : "Config", + "_1" : [ + { + "name" : "name", + "value" : { + "string" : { + "_0" : "default" + } + } + }, + { + "name" : "value", + "value" : { + "int" : { + "_0" : 42 + } + } + }, + { + "name" : "enabled", + "value" : { + "bool" : { + "_0" : true + } + } + } + ] + } + }, + "label" : "point", + "name" : "point", + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testIntArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testIntArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 1 + } + }, + { + "int" : { + "_0" : 2 + } + }, + { + "int" : { + "_0" : 3 + } + } + ] + } + }, + "label" : "values", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "abiName" : "bjs_testStringArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testStringArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "string" : { + "_0" : "a" + } + }, + { + "string" : { + "_0" : "b" + } + }, + { + "string" : { + "_0" : "c" + } + } + ] + } + }, + "label" : "names", + "name" : "names", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "abiName" : "bjs_testDoubleArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testDoubleArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "double" : { + "_0" : 1.5 + } + }, + { + "double" : { + "_0" : 2.5 + } + }, + { + "double" : { + "_0" : 3.5 + } + } + ] + } + }, + "label" : "values", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "abiName" : "bjs_testBoolArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testBoolArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "bool" : { + "_0" : true + } + }, + { + "bool" : { + "_0" : false + } + }, + { + "bool" : { + "_0" : true + } + } + ] + } + }, + "label" : "flags", + "name" : "flags", + "type" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + }, + { + "abiName" : "bjs_testEmptyArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testEmptyArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "array" : { + "_0" : [ + + ] + } + }, + "label" : "items", + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "abiName" : "bjs_testMixedWithArrayDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testMixedWithArrayDefault", + "parameters" : [ + { + "defaultValue" : { + "string" : { + "_0" : "test" + } + }, + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 10 + } + }, + { + "int" : { + "_0" : 20 + } + }, + { + "int" : { + "_0" : 30 + } + } + ] + } + }, + "label" : "values", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "defaultValue" : { + "bool" : { + "_0" : true + } + }, + "label" : "enabled", + "name" : "enabled", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "Config", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "value", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "enabled", + "type" : { + "bool" : { + + } + } + } + ], + "swiftCallName" : "Config" + }, + { + "constructor" : { + "abiName" : "bjs_MathOperations_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "defaultValue" : { + "double" : { + "_0" : 0 + } + }, + "label" : "baseValue", + "name" : "baseValue", + "type" : { + "double" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_MathOperations_add", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "add", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "defaultValue" : { + "double" : { + "_0" : 10 + } + }, + "label" : "b", + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_MathOperations_multiply", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "multiply", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_MathOperations_static_subtract", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "subtract", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "defaultValue" : { + "double" : { + "_0" : 5 + } + }, + "label" : "b", + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + }, + "staticContext" : { + "structName" : { + "_0" : "MathOperations" + } + } + } + ], + "name" : "MathOperations", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "baseValue", + "type" : { + "double" : { + + } + } + } + ], + "swiftCallName" : "MathOperations" + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift similarity index 85% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift index 5232bdd53..4c4c69c99 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift @@ -39,19 +39,16 @@ extension Status: _BridgedSwiftCaseEnum { extension Config: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Config { - let enabled = Bool.bridgeJSLiftParameter(_swift_js_pop_i32()) - let value = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let enabled = Bool.bridgeJSLiftParameter() + let value = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return Config(name: name, value: value, enabled: enabled) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.value)) - _swift_js_push_i32(self.enabled ? 1 : 0) + self.name.bridgeJSLowerStackReturn() + self.value.bridgeJSLowerStackReturn() + self.enabled.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -89,12 +86,12 @@ fileprivate func _bjs_struct_lift_Config() -> Int32 { extension MathOperations: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> MathOperations { - let baseValue = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let baseValue = Double.bridgeJSLiftParameter() return MathOperations(baseValue: baseValue) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.baseValue) + self.baseValue.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -321,19 +318,8 @@ public func _bjs_testOptionalStructWithValueDefault(_ point: Int32) -> Void { @_cdecl("bjs_testIntArrayDefault") public func _bjs_testIntArrayDefault() -> Void { #if arch(wasm32) - let ret = testIntArrayDefault(values: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + let ret = testIntArrayDefault(values: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -343,22 +329,8 @@ public func _bjs_testIntArrayDefault() -> Void { @_cdecl("bjs_testStringArrayDefault") public func _bjs_testStringArrayDefault() -> Void { #if arch(wasm32) - let ret = testStringArrayDefault(names: { - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(ret.count)) + let ret = testStringArrayDefault(names: [String].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -368,19 +340,8 @@ public func _bjs_testStringArrayDefault() -> Void { @_cdecl("bjs_testDoubleArrayDefault") public func _bjs_testDoubleArrayDefault() -> Void { #if arch(wasm32) - let ret = testDoubleArrayDefault(values: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_f64(__bjs_elem_ret)} - _swift_js_push_i32(Int32(ret.count)) + let ret = testDoubleArrayDefault(values: [Double].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -390,19 +351,8 @@ public func _bjs_testDoubleArrayDefault() -> Void { @_cdecl("bjs_testBoolArrayDefault") public func _bjs_testBoolArrayDefault() -> Void { #if arch(wasm32) - let ret = testBoolArrayDefault(flags: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Bool] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(__bjs_elem_ret ? 1 : 0)} - _swift_js_push_i32(Int32(ret.count)) + let ret = testBoolArrayDefault(flags: [Bool].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -412,19 +362,8 @@ public func _bjs_testBoolArrayDefault() -> Void { @_cdecl("bjs_testEmptyArrayDefault") public func _bjs_testEmptyArrayDefault() -> Void { #if arch(wasm32) - let ret = testEmptyArrayDefault(items: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(ret.count)) + let ret = testEmptyArrayDefault(items: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -434,16 +373,7 @@ public func _bjs_testEmptyArrayDefault() -> Void { @_cdecl("bjs_testMixedWithArrayDefault") public func _bjs_testMixedWithArrayDefault(_ nameBytes: Int32, _ nameLength: Int32, _ enabled: Int32) -> Void { #if arch(wasm32) - let ret = testMixedWithArrayDefault(name: String.bridgeJSLiftParameter(nameBytes, nameLength), values: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }(), enabled: Bool.bridgeJSLiftParameter(enabled)) + let ret = testMixedWithArrayDefault(name: String.bridgeJSLiftParameter(nameBytes, nameLength), values: [Int].bridgeJSLiftParameter(), enabled: Bool.bridgeJSLiftParameter(enabled)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json new file mode 100644 index 000000000..3c624fa12 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json @@ -0,0 +1,1423 @@ +{ + "exported" : { + "classes" : [ + { + "methods" : [ + + ], + "name" : "User", + "properties" : [ + + ], + "swiftCallName" : "User" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + }, + { + "associatedValues" : [ + { + "type" : { + "bool" : { + + } + } + } + ], + "name" : "flag" + }, + { + "associatedValues" : [ + { + "type" : { + "float" : { + + } + } + } + ], + "name" : "rate" + }, + { + "associatedValues" : [ + { + "type" : { + "double" : { + + } + } + } + ], + "name" : "precise" + }, + { + "associatedValues" : [ + + ], + "name" : "info" + } + ], + "emitStyle" : "const", + "name" : "APIResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIResult", + "tsFullPath" : "APIResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "error" + }, + { + "associatedValues" : [ + { + "type" : { + "bool" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + }, + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "status" + }, + { + "associatedValues" : [ + { + "type" : { + "double" : { + + } + } + }, + { + "type" : { + "double" : { + + } + } + }, + { + "type" : { + "double" : { + + } + } + } + ], + "name" : "coordinates" + }, + { + "associatedValues" : [ + { + "type" : { + "bool" : { + + } + } + }, + { + "type" : { + "bool" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + }, + { + "type" : { + "double" : { + + } + } + }, + { + "type" : { + "double" : { + + } + } + }, + { + "type" : { + "string" : { + + } + } + }, + { + "type" : { + "string" : { + + } + } + }, + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "comprehensive" + }, + { + "associatedValues" : [ + + ], + "name" : "info" + } + ], + "emitStyle" : "const", + "name" : "ComplexResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "ComplexResult", + "tsFullPath" : "ComplexResult" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Utilities", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utilities", + "tsFullPath" : "Utilities" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + }, + { + "associatedValues" : [ + { + "type" : { + "bool" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + }, + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "status" + } + ], + "emitStyle" : "const", + "name" : "Result", + "namespace" : [ + "Utilities" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utilities.Result", + "tsFullPath" : "Utilities.Result" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + }, + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + } + ], + "emitStyle" : "const", + "name" : "NetworkingResult", + "namespace" : [ + "API" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "NetworkingResult", + "tsFullPath" : "API.NetworkingResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "failure" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "status" + } + ], + "emitStyle" : "const", + "name" : "APIOptionalResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIOptionalResult", + "tsFullPath" : "APIOptionalResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "rough", + "rawValue" : "0.1" + }, + { + "associatedValues" : [ + + ], + "name" : "fine", + "rawValue" : "0.001" + } + ], + "emitStyle" : "const", + "name" : "Precision", + "rawType" : "Float", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Precision", + "tsFullPath" : "Precision" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "CardinalDirection", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "CardinalDirection", + "tsFullPath" : "CardinalDirection" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + } + ], + "name" : "precision" + }, + { + "associatedValues" : [ + { + "type" : { + "caseEnum" : { + "_0" : "CardinalDirection" + } + } + } + ], + "name" : "direction" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optPrecision" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "CardinalDirection" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optDirection" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" + } + ], + "emitStyle" : "const", + "name" : "TypedPayloadResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TypedPayloadResult", + "tsFullPath" : "TypedPayloadResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + ], + "name" : "structPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "swiftHeapObject" : { + "_0" : "User" + } + } + } + ], + "name" : "classPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "jsObject" : { + + } + } + } + ], + "name" : "jsObjectPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "name" : "nestedEnum" + }, + { + "associatedValues" : [ + { + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "name" : "arrayPayload" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" + } + ], + "emitStyle" : "const", + "name" : "AllTypesResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "AllTypesResult", + "tsFullPath" : "AllTypesResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Point" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optStruct" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "User" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optClass" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optJSObject" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optNestedEnum" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optArray" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" + } + ], + "emitStyle" : "const", + "name" : "OptionalAllTypesResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "OptionalAllTypesResult", + "tsFullPath" : "OptionalAllTypesResult" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_handle", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handle", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getResult", + "parameters" : [ + + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + }, + { + "abiName" : "bjs_roundtripAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripAPIResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalAPIResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_handleComplex", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handleComplex", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getComplexResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getComplexResult", + "parameters" : [ + + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + } + }, + { + "abiName" : "bjs_roundtripComplexResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripComplexResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalComplexResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalComplexResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalUtilitiesResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalUtilitiesResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "Utilities.Result" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "Utilities.Result" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalNetworkingResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalNetworkingResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "NetworkingResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "NetworkingResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalAPIOptionalResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalAPIOptionalResult", + "parameters" : [ + { + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_compareAPIResults", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "compareAPIResults", + "parameters" : [ + { + "label" : "result1", + "name" : "result1", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" + } + }, + "_1" : "null" + } + } + }, + { + "label" : "result2", + "name" : "result2", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripTypedPayloadResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripTypedPayloadResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalTypedPayloadResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalTypedPayloadResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripAllTypesResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripAllTypesResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalAllTypesResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalAllTypesResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalPayloadResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalPayloadResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalPayloadResultOpt", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalPayloadResultOpt", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + }, + "_1" : "null" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "Point", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "double" : { + + } + } + } + ], + "swiftCallName" : "Point" + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift new file mode 100644 index 000000000..26454a2a7 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift @@ -0,0 +1,998 @@ +extension APIResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { + switch caseId { + case 0: + return .success(String.bridgeJSLiftParameter()) + case 1: + return .failure(Int.bridgeJSLiftParameter()) + case 2: + return .flag(Bool.bridgeJSLiftParameter()) + case 3: + return .rate(Float.bridgeJSLiftParameter()) + case 4: + return .precise(Double.bridgeJSLiftParameter()) + case 5: + return .info + default: + fatalError("Unknown APIResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .failure(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(1) + case .flag(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(2) + case .rate(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(3) + case .precise(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(4) + case .info: + return Int32(5) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) + case .failure(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .flag(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) + case .rate(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) + case .precise(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) + case .info: + _swift_js_push_tag(Int32(5)) + } + } +} + +extension ComplexResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> ComplexResult { + switch caseId { + case 0: + return .success(String.bridgeJSLiftParameter()) + case 1: + return .error(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) + case 2: + return .status(Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) + case 3: + return .coordinates(Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter()) + case 4: + return .comprehensive(Bool.bridgeJSLiftParameter(), Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) + case 5: + return .info + default: + fatalError("Unknown ComplexResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .error(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + return Int32(1) + case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + return Int32(2) + case .coordinates(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + return Int32(3) + case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() + return Int32(4) + case .info: + return Int32(5) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> ComplexResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> ComplexResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) + case .error(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) + case .coordinates(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) + case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) + case .info: + _swift_js_push_tag(Int32(5)) + } + } +} + +extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> Utilities.Result { + switch caseId { + case 0: + return .success(String.bridgeJSLiftParameter()) + case 1: + return .failure(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) + case 2: + return .status(Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) + default: + fatalError("Unknown Utilities.Result case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + return Int32(1) + case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + return Int32(2) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> Utilities.Result { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> Utilities.Result { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) + case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) + } + } +} + +extension NetworkingResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> NetworkingResult { + switch caseId { + case 0: + return .success(String.bridgeJSLiftParameter()) + case 1: + return .failure(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) + default: + fatalError("Unknown NetworkingResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + return Int32(1) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> NetworkingResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> NetworkingResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) + case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + } + } +} + +extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIOptionalResult { + switch caseId { + case 0: + return .success(Optional.bridgeJSLiftParameter()) + case 1: + return .failure(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) + case 2: + return .status(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) + default: + fatalError("Unknown APIOptionalResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(0) + case .failure(let param0, let param1): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + return Int32(1) + case .status(let param0, let param1, let param2): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + let __bjs_isSome_param2 = param2 != nil + if let __bjs_unwrapped_param2 = param2 { + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + return Int32(2) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIOptionalResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIOptionalResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(0)) + case .failure(let param0, let param1): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + _swift_js_push_tag(Int32(1)) + case .status(let param0, let param1, let param2): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + let __bjs_isSome_param2 = param2 != nil + if let __bjs_unwrapped_param2 = param2 { + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + _swift_js_push_tag(Int32(2)) + } + } +} + +extension Precision: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { +} + +extension CardinalDirection: _BridgedSwiftCaseEnum { + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + return bridgeJSRawValue + } + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ value: Int32) -> CardinalDirection { + return bridgeJSLiftParameter(value) + } + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> CardinalDirection { + return CardinalDirection(bridgeJSRawValue: value)! + } + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { + return bridgeJSLowerParameter() + } + + private init?(bridgeJSRawValue: Int32) { + switch bridgeJSRawValue { + case 0: + self = .north + case 1: + self = .south + case 2: + self = .east + case 3: + self = .west + default: + return nil + } + } + + private var bridgeJSRawValue: Int32 { + switch self { + case .north: + return 0 + case .south: + return 1 + case .east: + return 2 + case .west: + return 3 + } + } +} + +extension TypedPayloadResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> TypedPayloadResult { + switch caseId { + case 0: + return .precision(Precision.bridgeJSLiftParameter(_swift_js_pop_f32())) + case 1: + return .direction(CardinalDirection.bridgeJSLiftParameter(_swift_js_pop_i32())) + case 2: + return .optPrecision(Optional.bridgeJSLiftParameter()) + case 3: + return .optDirection(Optional.bridgeJSLiftParameter()) + case 4: + return .empty + default: + fatalError("Unknown TypedPayloadResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .precision(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .direction(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(1) + case .optPrecision(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(2) + case .optDirection(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(3) + case .empty: + return Int32(4) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> TypedPayloadResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> TypedPayloadResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .precision(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) + case .direction(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .optPrecision(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(2)) + case .optDirection(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(3)) + case .empty: + _swift_js_push_tag(Int32(4)) + } + } +} + +extension AllTypesResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> AllTypesResult { + switch caseId { + case 0: + return .structPayload(Point.bridgeJSLiftParameter()) + case 1: + return .classPayload(User.bridgeJSLiftParameter()) + case 2: + return .jsObjectPayload(JSObject.bridgeJSLiftParameter()) + case 3: + return .nestedEnum(APIResult.bridgeJSLiftParameter(_swift_js_pop_i32())) + case 4: + return .arrayPayload([Int].bridgeJSLiftParameter()) + case 5: + return .empty + default: + fatalError("Unknown AllTypesResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .structPayload(let param0): + param0.bridgeJSLowerReturn() + return Int32(0) + case .classPayload(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(1) + case .jsObjectPayload(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(2) + case .nestedEnum(let param0): + param0.bridgeJSLowerReturn() + return Int32(3) + case .arrayPayload(let param0): + param0.bridgeJSLowerReturn() + return Int32(4) + case .empty: + return Int32(5) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> AllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> AllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .structPayload(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(0)) + case .classPayload(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .jsObjectPayload(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) + case .nestedEnum(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(3)) + case .arrayPayload(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(4)) + case .empty: + _swift_js_push_tag(Int32(5)) + } + } +} + +extension OptionalAllTypesResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> OptionalAllTypesResult { + switch caseId { + case 0: + return .optStruct(Optional.bridgeJSLiftParameter()) + case 1: + return .optClass(Optional.bridgeJSLiftParameter()) + case 2: + return .optJSObject(Optional.bridgeJSLiftParameter()) + case 3: + return .optNestedEnum(Optional.bridgeJSLiftParameter()) + case 4: + return .optArray({ + let __isSome = _swift_js_pop_i32() + if __isSome == 0 { + return Optional<[Int]>.none + } else { + return [Int].bridgeJSLiftParameter() + } + }()) + case 5: + return .empty + default: + fatalError("Unknown OptionalAllTypesResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .optStruct(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(0) + case .optClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(1) + case .optJSObject(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(2) + case .optNestedEnum(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(3) + case .optArray(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(4) + case .empty: + return Int32(5) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> OptionalAllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> OptionalAllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .optStruct(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(0)) + case .optClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(1)) + case .optJSObject(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(2)) + case .optNestedEnum(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(3)) + case .optArray(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(4)) + case .empty: + _swift_js_push_tag(Int32(5)) + } + } +} + +extension Point: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { + let y = Double.bridgeJSLiftParameter() + let x = Double.bridgeJSLiftParameter() + return Point(x: x, y: y) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Point())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_Point") +fileprivate func _bjs_struct_lift_Point() -> Int32 +#else +fileprivate func _bjs_struct_lift_Point() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_handle") +@_cdecl("bjs_handle") +public func _bjs_handle(_ result: Int32) -> Void { + #if arch(wasm32) + handle(result: APIResult.bridgeJSLiftParameter(result)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_getResult") +@_cdecl("bjs_getResult") +public func _bjs_getResult() -> Void { + #if arch(wasm32) + let ret = getResult() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundtripAPIResult") +@_cdecl("bjs_roundtripAPIResult") +public func _bjs_roundtripAPIResult(_ result: Int32) -> Void { + #if arch(wasm32) + let ret = roundtripAPIResult(result: APIResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalAPIResult") +@_cdecl("bjs_roundTripOptionalAPIResult") +public func _bjs_roundTripOptionalAPIResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalAPIResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_handleComplex") +@_cdecl("bjs_handleComplex") +public func _bjs_handleComplex(_ result: Int32) -> Void { + #if arch(wasm32) + handleComplex(result: ComplexResult.bridgeJSLiftParameter(result)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_getComplexResult") +@_cdecl("bjs_getComplexResult") +public func _bjs_getComplexResult() -> Void { + #if arch(wasm32) + let ret = getComplexResult() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundtripComplexResult") +@_cdecl("bjs_roundtripComplexResult") +public func _bjs_roundtripComplexResult(_ result: Int32) -> Void { + #if arch(wasm32) + let ret = roundtripComplexResult(_: ComplexResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalComplexResult") +@_cdecl("bjs_roundTripOptionalComplexResult") +public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalComplexResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalUtilitiesResult") +@_cdecl("bjs_roundTripOptionalUtilitiesResult") +public func _bjs_roundTripOptionalUtilitiesResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalUtilitiesResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalNetworkingResult") +@_cdecl("bjs_roundTripOptionalNetworkingResult") +public func _bjs_roundTripOptionalNetworkingResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalNetworkingResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalAPIOptionalResult") +@_cdecl("bjs_roundTripOptionalAPIOptionalResult") +public func _bjs_roundTripOptionalAPIOptionalResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_compareAPIResults") +@_cdecl("bjs_compareAPIResults") +public func _bjs_compareAPIResults(_ result1IsSome: Int32, _ result1CaseId: Int32, _ result2IsSome: Int32, _ result2CaseId: Int32) -> Void { + #if arch(wasm32) + let _tmp_result2 = Optional.bridgeJSLiftParameter(result2IsSome, result2CaseId) + let _tmp_result1 = Optional.bridgeJSLiftParameter(result1IsSome, result1CaseId) + let ret = compareAPIResults(result1: _tmp_result1, result2: _tmp_result2) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripTypedPayloadResult") +@_cdecl("bjs_roundTripTypedPayloadResult") +public func _bjs_roundTripTypedPayloadResult(_ result: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripTypedPayloadResult(_: TypedPayloadResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalTypedPayloadResult") +@_cdecl("bjs_roundTripOptionalTypedPayloadResult") +public func _bjs_roundTripOptionalTypedPayloadResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalTypedPayloadResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripAllTypesResult") +@_cdecl("bjs_roundTripAllTypesResult") +public func _bjs_roundTripAllTypesResult(_ result: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripAllTypesResult(_: AllTypesResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalAllTypesResult") +@_cdecl("bjs_roundTripOptionalAllTypesResult") +public func _bjs_roundTripOptionalAllTypesResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalAllTypesResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalPayloadResult") +@_cdecl("bjs_roundTripOptionalPayloadResult") +public func _bjs_roundTripOptionalPayloadResult(_ result: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalPayloadResult(_: OptionalAllTypesResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalPayloadResultOpt") +@_cdecl("bjs_roundTripOptionalPayloadResultOpt") +public func _bjs_roundTripOptionalPayloadResultOpt(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalPayloadResultOpt(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_User_deinit") +@_cdecl("bjs_User_deinit") +public func _bjs_User_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension User: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_User_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_User_wrap") +fileprivate func _bjs_User_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_User_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json new file mode 100644 index 000000000..ea32ad739 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json @@ -0,0 +1,327 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "Direction", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Direction", + "tsFullPath" : "Direction" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "loading" + }, + { + "associatedValues" : [ + + ], + "name" : "success" + }, + { + "associatedValues" : [ + + ], + "name" : "error" + } + ], + "emitStyle" : "const", + "name" : "Status", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Status", + "tsFullPath" : "Status" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "tsEnum", + "name" : "TSDirection", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TSDirection", + "tsFullPath" : "TSDirection" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "success" + } + ], + "emitStyle" : "const", + "explicitAccessControl" : "public", + "name" : "PublicStatus", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "PublicStatus", + "tsFullPath" : "PublicStatus" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_setDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setDirection", + "parameters" : [ + { + "label" : "_", + "name" : "direction", + "type" : { + "caseEnum" : { + "_0" : "Direction" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getDirection", + "parameters" : [ + + ], + "returnType" : { + "caseEnum" : { + "_0" : "Direction" + } + } + }, + { + "abiName" : "bjs_processDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processDirection", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "caseEnum" : { + "_0" : "Direction" + } + } + } + ], + "returnType" : { + "caseEnum" : { + "_0" : "Status" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalDirection", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setTSDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setTSDirection", + "parameters" : [ + { + "label" : "_", + "name" : "direction", + "type" : { + "caseEnum" : { + "_0" : "TSDirection" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getTSDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTSDirection", + "parameters" : [ + + ], + "returnType" : { + "caseEnum" : { + "_0" : "TSDirection" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalTSDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalTSDirection", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "TSDirection" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "TSDirection" + } + }, + "_1" : "null" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.json new file mode 100644 index 000000000..65b8ba350 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.json @@ -0,0 +1,541 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Converter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_Converter_toString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "toString", + "namespace" : [ + "Utils" + ], + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Converter", + "namespace" : [ + "Utils" + ], + "properties" : [ + + ], + "swiftCallName" : "Utils.Converter" + }, + { + "constructor" : { + "abiName" : "bjs_HTTPServer_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_HTTPServer_call", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "call", + "namespace" : [ + "Networking", + "API" + ], + "parameters" : [ + { + "label" : "_", + "name" : "method", + "type" : { + "caseEnum" : { + "_0" : "Networking.API.Method" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "HTTPServer", + "namespace" : [ + "Networking", + "API" + ], + "properties" : [ + + ], + "swiftCallName" : "Networking.API.HTTPServer" + }, + { + "constructor" : { + "abiName" : "bjs_TestServer_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_TestServer_call", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "call", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "parameters" : [ + { + "label" : "_", + "name" : "method", + "type" : { + "caseEnum" : { + "_0" : "Internal.SupportedMethod" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "TestServer", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "properties" : [ + + ], + "swiftCallName" : "Internal.TestServer" + } + ], + "enums" : [ + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Utils", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils", + "tsFullPath" : "Utils" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Networking", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking", + "tsFullPath" : "Networking" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "API", + "namespace" : [ + "Networking" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking.API", + "tsFullPath" : "Networking.API" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "get" + }, + { + "associatedValues" : [ + + ], + "name" : "post" + }, + { + "associatedValues" : [ + + ], + "name" : "put" + }, + { + "associatedValues" : [ + + ], + "name" : "delete" + } + ], + "emitStyle" : "const", + "name" : "Method", + "namespace" : [ + "Networking", + "API" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking.API.Method", + "tsFullPath" : "Networking.API.Method" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Configuration", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration", + "tsFullPath" : "Configuration" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "debug", + "rawValue" : "debug" + }, + { + "associatedValues" : [ + + ], + "name" : "info", + "rawValue" : "info" + }, + { + "associatedValues" : [ + + ], + "name" : "warning", + "rawValue" : "warning" + }, + { + "associatedValues" : [ + + ], + "name" : "error", + "rawValue" : "error" + } + ], + "emitStyle" : "const", + "name" : "LogLevel", + "namespace" : [ + "Configuration" + ], + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration.LogLevel", + "tsFullPath" : "Configuration.LogLevel" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "http", + "rawValue" : "80" + }, + { + "associatedValues" : [ + + ], + "name" : "https", + "rawValue" : "443" + }, + { + "associatedValues" : [ + + ], + "name" : "development", + "rawValue" : "3000" + } + ], + "emitStyle" : "const", + "name" : "Port", + "namespace" : [ + "Configuration" + ], + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration.Port", + "tsFullPath" : "Configuration.Port" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Internal", + "namespace" : [ + "Networking", + "APIV2" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Internal", + "tsFullPath" : "Networking.APIV2.Internal" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "get" + }, + { + "associatedValues" : [ + + ], + "name" : "post" + } + ], + "emitStyle" : "const", + "name" : "SupportedMethod", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Internal.SupportedMethod", + "tsFullPath" : "Networking.APIV2.Internal.SupportedMethod" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "GraphOperations", + "namespace" : [ + "Services", + "Graph" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_createGraph", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "createGraph", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "rootId", + "name" : "rootId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + }, + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_nodeCount", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "nodeCount", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "graphId", + "name" : "graphId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + }, + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_validate", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : true + }, + "name" : "validate", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "graphId", + "name" : "graphId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "GraphOperations", + "tsFullPath" : "Services.Graph.GraphOperations" + } + ], + "exposeToGlobal" : true, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.swift similarity index 77% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.swift index 9683b5307..b1b5e9c8c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.swift @@ -41,10 +41,10 @@ extension Networking.API.Method: _BridgedSwiftCaseEnum { } } -extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload { +extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Configuration.Port: _BridgedSwiftEnumNoPayload { +extension Configuration.Port: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Internal.SupportedMethod: _BridgedSwiftCaseEnum { @@ -82,6 +82,53 @@ extension Internal.SupportedMethod: _BridgedSwiftCaseEnum { } } +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_createGraph") +@_cdecl("bjs_Services_Graph_GraphOperations_static_createGraph") +public func _bjs_Services_Graph_GraphOperations_static_createGraph(_ rootId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.createGraph(rootId: Int.bridgeJSLiftParameter(rootId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_nodeCount") +@_cdecl("bjs_Services_Graph_GraphOperations_static_nodeCount") +public func _bjs_Services_Graph_GraphOperations_static_nodeCount(_ graphId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.nodeCount(graphId: Int.bridgeJSLiftParameter(graphId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_validate") +@_cdecl("bjs_Services_Graph_GraphOperations_static_validate") +public func _bjs_Services_Graph_GraphOperations_static_validate(_ graphId: Int32) -> Int32 { + #if arch(wasm32) + do { + let ret = try GraphOperations.validate(graphId: Int.bridgeJSLiftParameter(graphId)) + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: String(describing: error)) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_Converter_init") @_cdecl("bjs_Converter_init") public func _bjs_Converter_init() -> UnsafeMutableRawPointer { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.json new file mode 100644 index 000000000..9b800c743 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.json @@ -0,0 +1,541 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Converter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_Converter_toString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "toString", + "namespace" : [ + "Utils" + ], + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Converter", + "namespace" : [ + "Utils" + ], + "properties" : [ + + ], + "swiftCallName" : "Utils.Converter" + }, + { + "constructor" : { + "abiName" : "bjs_HTTPServer_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_HTTPServer_call", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "call", + "namespace" : [ + "Networking", + "API" + ], + "parameters" : [ + { + "label" : "_", + "name" : "method", + "type" : { + "caseEnum" : { + "_0" : "Networking.API.Method" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "HTTPServer", + "namespace" : [ + "Networking", + "API" + ], + "properties" : [ + + ], + "swiftCallName" : "Networking.API.HTTPServer" + }, + { + "constructor" : { + "abiName" : "bjs_TestServer_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_TestServer_call", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "call", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "parameters" : [ + { + "label" : "_", + "name" : "method", + "type" : { + "caseEnum" : { + "_0" : "Internal.SupportedMethod" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "TestServer", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "properties" : [ + + ], + "swiftCallName" : "Internal.TestServer" + } + ], + "enums" : [ + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Utils", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils", + "tsFullPath" : "Utils" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Networking", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking", + "tsFullPath" : "Networking" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "API", + "namespace" : [ + "Networking" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking.API", + "tsFullPath" : "Networking.API" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "get" + }, + { + "associatedValues" : [ + + ], + "name" : "post" + }, + { + "associatedValues" : [ + + ], + "name" : "put" + }, + { + "associatedValues" : [ + + ], + "name" : "delete" + } + ], + "emitStyle" : "const", + "name" : "Method", + "namespace" : [ + "Networking", + "API" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Networking.API.Method", + "tsFullPath" : "Networking.API.Method" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Configuration", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration", + "tsFullPath" : "Configuration" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "debug", + "rawValue" : "debug" + }, + { + "associatedValues" : [ + + ], + "name" : "info", + "rawValue" : "info" + }, + { + "associatedValues" : [ + + ], + "name" : "warning", + "rawValue" : "warning" + }, + { + "associatedValues" : [ + + ], + "name" : "error", + "rawValue" : "error" + } + ], + "emitStyle" : "const", + "name" : "LogLevel", + "namespace" : [ + "Configuration" + ], + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration.LogLevel", + "tsFullPath" : "Configuration.LogLevel" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "http", + "rawValue" : "80" + }, + { + "associatedValues" : [ + + ], + "name" : "https", + "rawValue" : "443" + }, + { + "associatedValues" : [ + + ], + "name" : "development", + "rawValue" : "3000" + } + ], + "emitStyle" : "const", + "name" : "Port", + "namespace" : [ + "Configuration" + ], + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Configuration.Port", + "tsFullPath" : "Configuration.Port" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Internal", + "namespace" : [ + "Networking", + "APIV2" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Internal", + "tsFullPath" : "Networking.APIV2.Internal" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "get" + }, + { + "associatedValues" : [ + + ], + "name" : "post" + } + ], + "emitStyle" : "const", + "name" : "SupportedMethod", + "namespace" : [ + "Networking", + "APIV2", + "Internal" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Internal.SupportedMethod", + "tsFullPath" : "Networking.APIV2.Internal.SupportedMethod" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "GraphOperations", + "namespace" : [ + "Services", + "Graph" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_createGraph", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "createGraph", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "rootId", + "name" : "rootId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + }, + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_nodeCount", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "nodeCount", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "graphId", + "name" : "graphId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + }, + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_validate", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : true + }, + "name" : "validate", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "graphId", + "name" : "graphId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "GraphOperations", + "tsFullPath" : "Services.Graph.GraphOperations" + } + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.swift similarity index 77% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.swift index 9683b5307..b1b5e9c8c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.swift @@ -41,10 +41,10 @@ extension Networking.API.Method: _BridgedSwiftCaseEnum { } } -extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload { +extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Configuration.Port: _BridgedSwiftEnumNoPayload { +extension Configuration.Port: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Internal.SupportedMethod: _BridgedSwiftCaseEnum { @@ -82,6 +82,53 @@ extension Internal.SupportedMethod: _BridgedSwiftCaseEnum { } } +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_createGraph") +@_cdecl("bjs_Services_Graph_GraphOperations_static_createGraph") +public func _bjs_Services_Graph_GraphOperations_static_createGraph(_ rootId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.createGraph(rootId: Int.bridgeJSLiftParameter(rootId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_nodeCount") +@_cdecl("bjs_Services_Graph_GraphOperations_static_nodeCount") +public func _bjs_Services_Graph_GraphOperations_static_nodeCount(_ graphId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.nodeCount(graphId: Int.bridgeJSLiftParameter(graphId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_validate") +@_cdecl("bjs_Services_Graph_GraphOperations_static_validate") +public func _bjs_Services_Graph_GraphOperations_static_validate(_ graphId: Int32) -> Int32 { + #if arch(wasm32) + do { + let ret = try GraphOperations.validate(graphId: Int.bridgeJSLiftParameter(graphId)) + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: String(describing: error)) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_Converter_init") @_cdecl("bjs_Converter_init") public func _bjs_Converter_init() -> UnsafeMutableRawPointer { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json new file mode 100644 index 000000000..ba36405ba --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json @@ -0,0 +1,1567 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "light", + "rawValue" : "light" + }, + { + "associatedValues" : [ + + ], + "name" : "dark", + "rawValue" : "dark" + }, + { + "associatedValues" : [ + + ], + "name" : "auto", + "rawValue" : "auto" + } + ], + "emitStyle" : "const", + "name" : "Theme", + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Theme", + "tsFullPath" : "Theme" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "light", + "rawValue" : "light" + }, + { + "associatedValues" : [ + + ], + "name" : "dark", + "rawValue" : "dark" + }, + { + "associatedValues" : [ + + ], + "name" : "auto", + "rawValue" : "auto" + } + ], + "emitStyle" : "tsEnum", + "name" : "TSTheme", + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TSTheme", + "tsFullPath" : "TSTheme" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "enabled", + "rawValue" : "true" + }, + { + "associatedValues" : [ + + ], + "name" : "disabled", + "rawValue" : "false" + } + ], + "emitStyle" : "const", + "name" : "FeatureFlag", + "rawType" : "Bool", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "FeatureFlag", + "tsFullPath" : "FeatureFlag" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "ok", + "rawValue" : "200" + }, + { + "associatedValues" : [ + + ], + "name" : "notFound", + "rawValue" : "404" + }, + { + "associatedValues" : [ + + ], + "name" : "serverError", + "rawValue" : "500" + } + ], + "emitStyle" : "const", + "name" : "HttpStatus", + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "HttpStatus", + "tsFullPath" : "HttpStatus" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "ok", + "rawValue" : "200" + }, + { + "associatedValues" : [ + + ], + "name" : "notFound", + "rawValue" : "404" + }, + { + "associatedValues" : [ + + ], + "name" : "serverError", + "rawValue" : "500" + } + ], + "emitStyle" : "tsEnum", + "name" : "TSHttpStatus", + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TSHttpStatus", + "tsFullPath" : "TSHttpStatus" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "lowest", + "rawValue" : "-1" + }, + { + "associatedValues" : [ + + ], + "name" : "low", + "rawValue" : "2" + }, + { + "associatedValues" : [ + + ], + "name" : "medium", + "rawValue" : "3" + }, + { + "associatedValues" : [ + + ], + "name" : "high", + "rawValue" : "4" + }, + { + "associatedValues" : [ + + ], + "name" : "highest", + "rawValue" : "5" + } + ], + "emitStyle" : "const", + "name" : "Priority", + "rawType" : "Int32", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Priority", + "tsFullPath" : "Priority" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "tiny", + "rawValue" : "1024" + }, + { + "associatedValues" : [ + + ], + "name" : "small", + "rawValue" : "10240" + }, + { + "associatedValues" : [ + + ], + "name" : "medium", + "rawValue" : "102400" + }, + { + "associatedValues" : [ + + ], + "name" : "large", + "rawValue" : "1048576" + } + ], + "emitStyle" : "const", + "name" : "FileSize", + "rawType" : "Int64", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "FileSize", + "tsFullPath" : "FileSize" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "guest", + "rawValue" : "0" + }, + { + "associatedValues" : [ + + ], + "name" : "user", + "rawValue" : "1000" + }, + { + "associatedValues" : [ + + ], + "name" : "admin", + "rawValue" : "9999" + } + ], + "emitStyle" : "const", + "name" : "UserId", + "rawType" : "UInt", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "UserId", + "tsFullPath" : "UserId" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "invalid", + "rawValue" : "0" + }, + { + "associatedValues" : [ + + ], + "name" : "session", + "rawValue" : "12345" + }, + { + "associatedValues" : [ + + ], + "name" : "refresh", + "rawValue" : "67890" + } + ], + "emitStyle" : "const", + "name" : "TokenId", + "rawType" : "UInt32", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TokenId", + "tsFullPath" : "TokenId" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "none", + "rawValue" : "0" + }, + { + "associatedValues" : [ + + ], + "name" : "active", + "rawValue" : "9876543210" + }, + { + "associatedValues" : [ + + ], + "name" : "expired", + "rawValue" : "1234567890" + } + ], + "emitStyle" : "const", + "name" : "SessionId", + "rawType" : "UInt64", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "SessionId", + "tsFullPath" : "SessionId" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "rough", + "rawValue" : "0.1" + }, + { + "associatedValues" : [ + + ], + "name" : "normal", + "rawValue" : "0.01" + }, + { + "associatedValues" : [ + + ], + "name" : "fine", + "rawValue" : "0.001" + } + ], + "emitStyle" : "const", + "name" : "Precision", + "rawType" : "Float", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Precision", + "tsFullPath" : "Precision" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "quarter", + "rawValue" : "0.25" + }, + { + "associatedValues" : [ + + ], + "name" : "half", + "rawValue" : "0.5" + }, + { + "associatedValues" : [ + + ], + "name" : "golden", + "rawValue" : "1.618" + }, + { + "associatedValues" : [ + + ], + "name" : "pi", + "rawValue" : "3.14159" + } + ], + "emitStyle" : "const", + "name" : "Ratio", + "rawType" : "Double", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Ratio", + "tsFullPath" : "Ratio" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_setTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setTheme", + "parameters" : [ + { + "label" : "_", + "name" : "theme", + "type" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTheme", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalTheme", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setTSTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setTSTheme", + "parameters" : [ + { + "label" : "_", + "name" : "theme", + "type" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getTSTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTSTheme", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalTSTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalTSTheme", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setFeatureFlag", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setFeatureFlag", + "parameters" : [ + { + "label" : "_", + "name" : "flag", + "type" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getFeatureFlag", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getFeatureFlag", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalFeatureFlag", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalFeatureFlag", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setHttpStatus", + "parameters" : [ + { + "label" : "_", + "name" : "status", + "type" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getHttpStatus", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalHttpStatus", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setTSHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setTSHttpStatus", + "parameters" : [ + { + "label" : "_", + "name" : "status", + "type" : { + "rawValueEnum" : { + "_0" : "TSHttpStatus", + "_1" : "Int" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getTSHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTSHttpStatus", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "TSHttpStatus", + "_1" : "Int" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalHttpStatus", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSHttpStatus", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSHttpStatus", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setPriority", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setPriority", + "parameters" : [ + { + "label" : "_", + "name" : "priority", + "type" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int32" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getPriority", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getPriority", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int32" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalPriority", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalPriority", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int32" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int32" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setFileSize", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setFileSize", + "parameters" : [ + { + "label" : "_", + "name" : "size", + "type" : { + "rawValueEnum" : { + "_0" : "FileSize", + "_1" : "Int64" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getFileSize", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getFileSize", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "FileSize", + "_1" : "Int64" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalFileSize", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalFileSize", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FileSize", + "_1" : "Int64" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FileSize", + "_1" : "Int64" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setUserId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setUserId", + "parameters" : [ + { + "label" : "_", + "name" : "id", + "type" : { + "rawValueEnum" : { + "_0" : "UserId", + "_1" : "UInt" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getUserId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getUserId", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "UserId", + "_1" : "UInt" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalUserId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalUserId", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "UserId", + "_1" : "UInt" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "UserId", + "_1" : "UInt" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setTokenId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setTokenId", + "parameters" : [ + { + "label" : "_", + "name" : "token", + "type" : { + "rawValueEnum" : { + "_0" : "TokenId", + "_1" : "UInt32" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getTokenId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTokenId", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "TokenId", + "_1" : "UInt32" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalTokenId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalTokenId", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TokenId", + "_1" : "UInt32" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TokenId", + "_1" : "UInt32" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setSessionId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setSessionId", + "parameters" : [ + { + "label" : "_", + "name" : "session", + "type" : { + "rawValueEnum" : { + "_0" : "SessionId", + "_1" : "UInt64" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getSessionId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getSessionId", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "SessionId", + "_1" : "UInt64" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalSessionId", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalSessionId", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "SessionId", + "_1" : "UInt64" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "SessionId", + "_1" : "UInt64" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setPrecision", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setPrecision", + "parameters" : [ + { + "label" : "_", + "name" : "precision", + "type" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getPrecision", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getPrecision", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalPrecision", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalPrecision", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_setRatio", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setRatio", + "parameters" : [ + { + "label" : "_", + "name" : "ratio", + "type" : { + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_getRatio", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getRatio", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalRatio", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalRatio", + "parameters" : [ + { + "label" : "_", + "name" : "input", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_processTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processTheme", + "parameters" : [ + { + "label" : "_", + "name" : "theme", + "type" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + } + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + }, + { + "abiName" : "bjs_convertPriority", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "convertPriority", + "parameters" : [ + { + "label" : "_", + "name" : "status", + "type" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + } + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int32" + } + } + }, + { + "abiName" : "bjs_validateSession", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "validateSession", + "parameters" : [ + { + "label" : "_", + "name" : "session", + "type" : { + "rawValueEnum" : { + "_0" : "SessionId", + "_1" : "UInt64" + } + } + } + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "takesFeatureFlag", + "parameters" : [ + { + "name" : "flag", + "type" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "returnsFeatureFlag", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift similarity index 84% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift index 12fdeba04..210361b3b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift @@ -1,37 +1,37 @@ -extension Theme: _BridgedSwiftEnumNoPayload { +extension Theme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension TSTheme: _BridgedSwiftEnumNoPayload { +extension TSTheme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension FeatureFlag: _BridgedSwiftEnumNoPayload { +extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension HttpStatus: _BridgedSwiftEnumNoPayload { +extension HttpStatus: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension TSHttpStatus: _BridgedSwiftEnumNoPayload { +extension TSHttpStatus: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Priority: _BridgedSwiftEnumNoPayload { +extension Priority: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension FileSize: _BridgedSwiftEnumNoPayload { +extension FileSize: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension UserId: _BridgedSwiftEnumNoPayload { +extension UserId: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension TokenId: _BridgedSwiftEnumNoPayload { +extension TokenId: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension SessionId: _BridgedSwiftEnumNoPayload { +extension SessionId: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Precision: _BridgedSwiftEnumNoPayload { +extension Precision: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Ratio: _BridgedSwiftEnumNoPayload { +extension Ratio: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } @_expose(wasm, "bjs_setTheme") @@ -100,9 +100,9 @@ public func _bjs_roundTripOptionalTSTheme(_ inputIsSome: Int32, _ inputBytes: In @_expose(wasm, "bjs_setFeatureFlag") @_cdecl("bjs_setFeatureFlag") -public func _bjs_setFeatureFlag(_ flag: Int32) -> Void { +public func _bjs_setFeatureFlag(_ flagBytes: Int32, _ flagLength: Int32) -> Void { #if arch(wasm32) - setFeatureFlag(_: FeatureFlag.bridgeJSLiftParameter(flag)) + setFeatureFlag(_: FeatureFlag.bridgeJSLiftParameter(flagBytes, flagLength)) #else fatalError("Only available on WebAssembly") #endif @@ -110,7 +110,7 @@ public func _bjs_setFeatureFlag(_ flag: Int32) -> Void { @_expose(wasm, "bjs_getFeatureFlag") @_cdecl("bjs_getFeatureFlag") -public func _bjs_getFeatureFlag() -> Int32 { +public func _bjs_getFeatureFlag() -> Void { #if arch(wasm32) let ret = getFeatureFlag() return ret.bridgeJSLowerReturn() @@ -121,9 +121,9 @@ public func _bjs_getFeatureFlag() -> Int32 { @_expose(wasm, "bjs_roundTripOptionalFeatureFlag") @_cdecl("bjs_roundTripOptionalFeatureFlag") -public func _bjs_roundTripOptionalFeatureFlag(_ inputIsSome: Int32, _ inputValue: Int32) -> Void { +public func _bjs_roundTripOptionalFeatureFlag(_ inputIsSome: Int32, _ inputBytes: Int32, _ inputLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalFeatureFlag(_: Optional.bridgeJSLiftParameter(inputIsSome, inputValue)) + let ret = roundTripOptionalFeatureFlag(_: Optional.bridgeJSLiftParameter(inputIsSome, inputBytes, inputLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -449,4 +449,38 @@ public func _bjs_validateSession(_ session: Int32) -> Void { #else fatalError("Only available on WebAssembly") #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_takesFeatureFlag") +fileprivate func bjs_takesFeatureFlag(_ flag: Int32) -> Void +#else +fileprivate func bjs_takesFeatureFlag(_ flag: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void { + let flagValue = flag.bridgeJSLowerParameter() + bjs_takesFeatureFlag(flagValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_returnsFeatureFlag") +fileprivate func bjs_returnsFeatureFlag() -> Int32 +#else +fileprivate func bjs_returnsFeatureFlag() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$returnsFeatureFlag() throws(JSException) -> FeatureFlag { + let ret = bjs_returnsFeatureFlag() + if let error = _swift_js_take_exception() { + throw error + } + return FeatureFlag.bridgeJSLiftReturn(ret) } \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json new file mode 100644 index 000000000..55ac7dd70 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json @@ -0,0 +1,56 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + + ], + "globalGetters" : [ + { + "name" : "console", + "type" : { + "jsObject" : { + "_0" : "JSConsole" + } + } + } + ], + "types" : [ + { + "getters" : [ + + ], + "methods" : [ + { + "name" : "log", + "parameters" : [ + { + "name" : "message", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "JSConsole", + "setters" : [ + + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalGetter.ImportMacros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift similarity index 88% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalGetter.ImportMacros.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift index b5442b09e..da3f1367b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalGetter.ImportMacros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.swift @@ -1,5 +1,5 @@ #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_console_get") +@_extern(wasm, module: "TestModule", name: "bjs_console_get") fileprivate func bjs_console_get() -> Int32 #else fileprivate func bjs_console_get() -> Int32 { @@ -16,7 +16,7 @@ func _$console_get() throws(JSException) -> JSConsole { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_JSConsole_log") +@_extern(wasm, module: "TestModule", name: "bjs_JSConsole_log") fileprivate func bjs_JSConsole_log(_ self: Int32, _ message: Int32) -> Void #else fileprivate func bjs_JSConsole_log(_ self: Int32, _ message: Int32) -> Void { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json new file mode 100644 index 000000000..5e002e34f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json @@ -0,0 +1,114 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "from" : "global", + "jsName" : "parseInt", + "name" : "parseInt", + "parameters" : [ + { + "name" : "string", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + } + ], + "globalGetters" : [ + { + "from" : "global", + "name" : "console", + "type" : { + "jsObject" : { + "_0" : "JSConsole" + } + } + } + ], + "types" : [ + { + "getters" : [ + + ], + "methods" : [ + { + "name" : "log", + "parameters" : [ + { + "name" : "message", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "JSConsole", + "setters" : [ + + ], + "staticMethods" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "url", + "type" : { + "string" : { + + } + } + } + ] + }, + "from" : "global", + "getters" : [ + + ], + "methods" : [ + { + "name" : "close", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "WebSocket", + "setters" : [ + + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalThisImports.ImportMacros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift similarity index 88% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalThisImports.ImportMacros.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift index 503da6189..56353b253 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/GlobalThisImports.ImportMacros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.swift @@ -1,5 +1,5 @@ #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_console_get") +@_extern(wasm, module: "TestModule", name: "bjs_console_get") fileprivate func bjs_console_get() -> Int32 #else fileprivate func bjs_console_get() -> Int32 { @@ -16,7 +16,7 @@ func _$console_get() throws(JSException) -> JSConsole { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_parseInt") +@_extern(wasm, module: "TestModule", name: "bjs_parseInt") fileprivate func bjs_parseInt(_ string: Int32) -> Float64 #else fileprivate func bjs_parseInt(_ string: Int32) -> Float64 { @@ -34,7 +34,7 @@ func _$parseInt(_ string: String) throws(JSException) -> Double { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_JSConsole_log") +@_extern(wasm, module: "TestModule", name: "bjs_JSConsole_log") fileprivate func bjs_JSConsole_log(_ self: Int32, _ message: Int32) -> Void #else fileprivate func bjs_JSConsole_log(_ self: Int32, _ message: Int32) -> Void { @@ -52,7 +52,7 @@ func _$JSConsole_log(_ self: JSObject, _ message: String) throws(JSException) -> } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WebSocket_init") +@_extern(wasm, module: "TestModule", name: "bjs_WebSocket_init") fileprivate func bjs_WebSocket_init(_ url: Int32) -> Int32 #else fileprivate func bjs_WebSocket_init(_ url: Int32) -> Int32 { @@ -61,7 +61,7 @@ fileprivate func bjs_WebSocket_init(_ url: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WebSocket_close") +@_extern(wasm, module: "TestModule", name: "bjs_WebSocket_close") fileprivate func bjs_WebSocket_close(_ self: Int32) -> Void #else fileprivate func bjs_WebSocket_close(_ self: Int32) -> Void { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.json new file mode 100644 index 000000000..b884e0cb9 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.json @@ -0,0 +1,62 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "roundtrip", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "logStrings", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift new file mode 100644 index 000000000..33b987c76 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift @@ -0,0 +1,34 @@ +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_roundtrip") +fileprivate func bjs_roundtrip() -> Void +#else +fileprivate func bjs_roundtrip() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$roundtrip(_ items: [Int]) throws(JSException) -> [Int] { + let _ = items.bridgeJSLowerParameter() + bjs_roundtrip() + if let error = _swift_js_take_exception() { + throw error + } + return [Int].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_logStrings") +fileprivate func bjs_logStrings() -> Void +#else +fileprivate func bjs_logStrings() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$logStrings(_ items: [String]) throws(JSException) -> Void { + let _ = items.bridgeJSLowerParameter() + bjs_logStrings() + if let error = _swift_js_take_exception() { + throw error + } +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json new file mode 100644 index 000000000..f57e77d21 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json @@ -0,0 +1,202 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_makeFoo", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "makeFoo", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "Foo" + } + } + }, + { + "abiName" : "bjs_processFooArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processFooArray", + "parameters" : [ + { + "label" : "_", + "name" : "foos", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + }, + { + "abiName" : "bjs_processOptionalFooArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalFooArray", + "parameters" : [ + { + "label" : "_", + "name" : "foos", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" + } + } + } + } + }, + { + "abiName" : "bjs_roundtripFooContainer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripFooContainer", + "parameters" : [ + { + "label" : "_", + "name" : "container", + "type" : { + "swiftStruct" : { + "_0" : "FooContainer" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "FooContainer" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "FooContainer", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "foo", + "type" : { + "jsObject" : { + "_0" : "Foo" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalFoo", + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "FooContainer" + } + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + + ] + }, + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "Foo", + "setters" : [ + + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift new file mode 100644 index 000000000..6d9bee080 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift @@ -0,0 +1,152 @@ +extension FooContainer: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> FooContainer { + let optionalFoo = Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + } + let foo = Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter()) + return FooContainer(foo: foo, optionalFoo: optionalFoo) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.foo.jsObject.bridgeJSLowerStackReturn() + let __bjs_isSome_optionalFoo = self.optionalFoo != nil + if let __bjs_unwrapped_optionalFoo = self.optionalFoo { + __bjs_unwrapped_optionalFoo.jsObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_optionalFoo ? 1 : 0) + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_FooContainer())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_FooContainer") +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_FooContainer") +fileprivate func _bjs_struct_lift_FooContainer() -> Int32 +#else +fileprivate func _bjs_struct_lift_FooContainer() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_makeFoo") +@_cdecl("bjs_makeFoo") +public func _bjs_makeFoo() -> Int32 { + #if arch(wasm32) + do { + let ret = try makeFoo() + return ret.bridgeJSLowerReturn() + } catch let error { + if let error = error.thrownValue.object { + withExtendedLifetime(error) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } else { + let jsError = JSError(message: String(describing: error)) + withExtendedLifetime(jsError.jsObject) { + _swift_js_throw(Int32(bitPattern: $0.id)) + } + } + return 0 + } + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_processFooArray") +@_cdecl("bjs_processFooArray") +public func _bjs_processFooArray() -> Void { + #if arch(wasm32) + let ret = processFooArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Foo] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append(Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter())) + } + __result.reverse() + return __result + }()) + ret.map { + $0.jsObject + } .bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_processOptionalFooArray") +@_cdecl("bjs_processOptionalFooArray") +public func _bjs_processOptionalFooArray() -> Void { + #if arch(wasm32) + let ret = processOptionalFooArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append(Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + }) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.jsObject.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + _swift_js_push_i32(Int32(ret.count)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundtripFooContainer") +@_cdecl("bjs_roundtripFooContainer") +public func _bjs_roundtripFooContainer() -> Void { + #if arch(wasm32) + let ret = roundtripFooContainer(_: FooContainer.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Foo_init") +fileprivate func bjs_Foo_init() -> Int32 +#else +fileprivate func bjs_Foo_init() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$Foo_init() throws(JSException) -> JSObject { + let ret = bjs_Foo_init() + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json new file mode 100644 index 000000000..935f7a7f2 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json @@ -0,0 +1,246 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "createWeirdObject", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "WeirdNaming" + } + } + }, + { + "name" : "createWeirdClass", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "_Weird" + } + } + } + ], + "types" : [ + { + "getters" : [ + { + "name" : "normalProperty", + "type" : { + "string" : { + + } + } + }, + { + "jsName" : "property-with-dashes", + "name" : "property_with_dashes", + "type" : { + "double" : { + + } + } + }, + { + "jsName" : "123invalidStart", + "name" : "_123invalidStart", + "type" : { + "bool" : { + + } + } + }, + { + "jsName" : "property with spaces", + "name" : "property_with_spaces", + "type" : { + "string" : { + + } + } + }, + { + "jsName" : "@specialChar", + "name" : "_specialChar", + "type" : { + "double" : { + + } + } + }, + { + "name" : "constructor", + "type" : { + "string" : { + + } + } + }, + { + "name" : "for", + "type" : { + "string" : { + + } + } + }, + { + "name" : "Any", + "type" : { + "string" : { + + } + } + } + ], + "methods" : [ + { + "name" : "as", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "try", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "WeirdNaming", + "setters" : [ + { + "functionName" : "normalProperty_set", + "name" : "normalProperty", + "type" : { + "string" : { + + } + } + }, + { + "functionName" : "property_with_dashes_set", + "jsName" : "property-with-dashes", + "name" : "property_with_dashes", + "type" : { + "double" : { + + } + } + }, + { + "functionName" : "_123invalidStart_set", + "jsName" : "123invalidStart", + "name" : "_123invalidStart", + "type" : { + "bool" : { + + } + } + }, + { + "functionName" : "property_with_spaces_set", + "jsName" : "property with spaces", + "name" : "property_with_spaces", + "type" : { + "string" : { + + } + } + }, + { + "functionName" : "_specialChar_set", + "jsName" : "@specialChar", + "name" : "_specialChar", + "type" : { + "double" : { + + } + } + }, + { + "functionName" : "constructor_set", + "name" : "constructor", + "type" : { + "string" : { + + } + } + }, + { + "functionName" : "for_set", + "name" : "for", + "type" : { + "string" : { + + } + } + }, + { + "functionName" : "any_set", + "jsName" : "Any", + "name" : "any", + "type" : { + "string" : { + + } + } + } + ], + "staticMethods" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + + ] + }, + "getters" : [ + + ], + "jsName" : "$Weird", + "methods" : [ + { + "jsName" : "method-with-dashes", + "name" : "method_with_dashes", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "_Weird", + "setters" : [ + + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift similarity index 77% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift index 0ef52d4d7..86e72bb53 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.swift @@ -1,22 +1,5 @@ #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createArrayBuffer") -fileprivate func bjs_createArrayBuffer() -> Int32 -#else -fileprivate func bjs_createArrayBuffer() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$createArrayBuffer() throws(JSException) -> ArrayBufferLike { - let ret = bjs_createArrayBuffer() - if let error = _swift_js_take_exception() { - throw error - } - return ArrayBufferLike.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createWeirdObject") +@_extern(wasm, module: "TestModule", name: "bjs_createWeirdObject") fileprivate func bjs_createWeirdObject() -> Int32 #else fileprivate func bjs_createWeirdObject() -> Int32 { @@ -33,7 +16,7 @@ func _$createWeirdObject() throws(JSException) -> WeirdNaming { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createWeirdClass") +@_extern(wasm, module: "TestModule", name: "bjs_createWeirdClass") fileprivate func bjs_createWeirdClass() -> Int32 #else fileprivate func bjs_createWeirdClass() -> Int32 { @@ -50,45 +33,7 @@ func _$createWeirdClass() throws(JSException) -> _Weird { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_ArrayBufferLike_byteLength_get") -fileprivate func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64 -#else -fileprivate func bjs_ArrayBufferLike_byteLength_get(_ self: Int32) -> Float64 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_ArrayBufferLike_slice") -fileprivate func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32 -#else -fileprivate func bjs_ArrayBufferLike_slice(_ self: Int32, _ begin: Float64, _ end: Float64) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$ArrayBufferLike_byteLength_get(_ self: JSObject) throws(JSException) -> Double { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_ArrayBufferLike_byteLength_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return Double.bridgeJSLiftReturn(ret) -} - -func _$ArrayBufferLike_slice(_ self: JSObject, _ begin: Double, _ end: Double) throws(JSException) -> ArrayBufferLike { - let selfValue = self.bridgeJSLowerParameter() - let beginValue = begin.bridgeJSLowerParameter() - let endValue = end.bridgeJSLowerParameter() - let ret = bjs_ArrayBufferLike_slice(selfValue, beginValue, endValue) - if let error = _swift_js_take_exception() { - throw error - } - return ArrayBufferLike.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_normalProperty_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_normalProperty_get") fileprivate func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32 { @@ -97,7 +42,7 @@ fileprivate func bjs_WeirdNaming_normalProperty_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_property_with_dashes_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_property_with_dashes_get") fileprivate func bjs_WeirdNaming_property_with_dashes_get(_ self: Int32) -> Float64 #else fileprivate func bjs_WeirdNaming_property_with_dashes_get(_ self: Int32) -> Float64 { @@ -106,7 +51,7 @@ fileprivate func bjs_WeirdNaming_property_with_dashes_get(_ self: Int32) -> Floa #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming__123invalidStart_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming__123invalidStart_get") fileprivate func bjs_WeirdNaming__123invalidStart_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming__123invalidStart_get(_ self: Int32) -> Int32 { @@ -115,7 +60,7 @@ fileprivate func bjs_WeirdNaming__123invalidStart_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_property_with_spaces_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_property_with_spaces_get") fileprivate func bjs_WeirdNaming_property_with_spaces_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming_property_with_spaces_get(_ self: Int32) -> Int32 { @@ -124,7 +69,7 @@ fileprivate func bjs_WeirdNaming_property_with_spaces_get(_ self: Int32) -> Int3 #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming__specialChar_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming__specialChar_get") fileprivate func bjs_WeirdNaming__specialChar_get(_ self: Int32) -> Float64 #else fileprivate func bjs_WeirdNaming__specialChar_get(_ self: Int32) -> Float64 { @@ -133,7 +78,7 @@ fileprivate func bjs_WeirdNaming__specialChar_get(_ self: Int32) -> Float64 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_constructor_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_constructor_get") fileprivate func bjs_WeirdNaming_constructor_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming_constructor_get(_ self: Int32) -> Int32 { @@ -142,7 +87,7 @@ fileprivate func bjs_WeirdNaming_constructor_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_for_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_for_get") fileprivate func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32 { @@ -151,7 +96,7 @@ fileprivate func bjs_WeirdNaming_for_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_Any_get") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_Any_get") fileprivate func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32 #else fileprivate func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32 { @@ -160,7 +105,7 @@ fileprivate func bjs_WeirdNaming_Any_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_normalProperty_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_normalProperty_set") fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -169,7 +114,7 @@ fileprivate func bjs_WeirdNaming_normalProperty_set(_ self: Int32, _ newValue: I #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_property_with_dashes_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_property_with_dashes_set") fileprivate func bjs_WeirdNaming_property_with_dashes_set(_ self: Int32, _ newValue: Float64) -> Void #else fileprivate func bjs_WeirdNaming_property_with_dashes_set(_ self: Int32, _ newValue: Float64) -> Void { @@ -178,7 +123,7 @@ fileprivate func bjs_WeirdNaming_property_with_dashes_set(_ self: Int32, _ newVa #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming__123invalidStart_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming__123invalidStart_set") fileprivate func bjs_WeirdNaming__123invalidStart_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming__123invalidStart_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -187,7 +132,7 @@ fileprivate func bjs_WeirdNaming__123invalidStart_set(_ self: Int32, _ newValue: #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_property_with_spaces_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_property_with_spaces_set") fileprivate func bjs_WeirdNaming_property_with_spaces_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming_property_with_spaces_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -196,7 +141,7 @@ fileprivate func bjs_WeirdNaming_property_with_spaces_set(_ self: Int32, _ newVa #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming__specialChar_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming__specialChar_set") fileprivate func bjs_WeirdNaming__specialChar_set(_ self: Int32, _ newValue: Float64) -> Void #else fileprivate func bjs_WeirdNaming__specialChar_set(_ self: Int32, _ newValue: Float64) -> Void { @@ -205,7 +150,7 @@ fileprivate func bjs_WeirdNaming__specialChar_set(_ self: Int32, _ newValue: Flo #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_constructor_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_constructor_set") fileprivate func bjs_WeirdNaming_constructor_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming_constructor_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -214,7 +159,7 @@ fileprivate func bjs_WeirdNaming_constructor_set(_ self: Int32, _ newValue: Int3 #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_for_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_for_set") fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -223,7 +168,7 @@ fileprivate func bjs_WeirdNaming_for_set(_ self: Int32, _ newValue: Int32) -> Vo #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_any_set") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_any_set") fileprivate func bjs_WeirdNaming_any_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_WeirdNaming_any_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -232,7 +177,7 @@ fileprivate func bjs_WeirdNaming_any_set(_ self: Int32, _ newValue: Int32) -> Vo #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_as") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_as") fileprivate func bjs_WeirdNaming_as(_ self: Int32) -> Void #else fileprivate func bjs_WeirdNaming_as(_ self: Int32) -> Void { @@ -241,7 +186,7 @@ fileprivate func bjs_WeirdNaming_as(_ self: Int32) -> Void { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_WeirdNaming_try") +@_extern(wasm, module: "TestModule", name: "bjs_WeirdNaming_try") fileprivate func bjs_WeirdNaming_try(_ self: Int32) -> Void #else fileprivate func bjs_WeirdNaming_try(_ self: Int32) -> Void { @@ -410,7 +355,7 @@ func _$WeirdNaming_try(_ self: JSObject) throws(JSException) -> Void { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs__Weird_init") +@_extern(wasm, module: "TestModule", name: "bjs__Weird_init") fileprivate func bjs__Weird_init() -> Int32 #else fileprivate func bjs__Weird_init() -> Int32 { @@ -419,7 +364,7 @@ fileprivate func bjs__Weird_init() -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs__Weird_method_with_dashes") +@_extern(wasm, module: "TestModule", name: "bjs__Weird_method_with_dashes") fileprivate func bjs__Weird_method_with_dashes(_ self: Int32) -> Void #else fileprivate func bjs__Weird_method_with_dashes(_ self: Int32) -> Void { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json new file mode 100644 index 000000000..689e86150 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json @@ -0,0 +1,160 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "returnAnimatable", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "Animatable" + } + } + } + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "getters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "name" : "age", + "type" : { + "double" : { + + } + } + } + ], + "methods" : [ + { + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "name" : "changeName", + "parameters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "Greeter", + "setters" : [ + { + "functionName" : "name_set", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "staticMethods" : [ + + ] + }, + { + "getters" : [ + + ], + "methods" : [ + { + "name" : "animate", + "parameters" : [ + { + "name" : "keyframes", + "type" : { + "jsObject" : { + + } + } + }, + { + "name" : "options", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + + } + } + }, + { + "name" : "getAnimations", + "parameters" : [ + { + "name" : "options", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + + } + } + } + ], + "name" : "Animatable", + "setters" : [ + + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift similarity index 55% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift index 67c778975..09e828fba 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.swift @@ -1,5 +1,22 @@ #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_init") +@_extern(wasm, module: "TestModule", name: "bjs_returnAnimatable") +fileprivate func bjs_returnAnimatable() -> Int32 +#else +fileprivate func bjs_returnAnimatable() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$returnAnimatable() throws(JSException) -> Animatable { + let ret = bjs_returnAnimatable() + if let error = _swift_js_take_exception() { + throw error + } + return Animatable.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_init") fileprivate func bjs_Greeter_init(_ name: Int32) -> Int32 #else fileprivate func bjs_Greeter_init(_ name: Int32) -> Int32 { @@ -8,7 +25,7 @@ fileprivate func bjs_Greeter_init(_ name: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_name_get") +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_name_get") fileprivate func bjs_Greeter_name_get(_ self: Int32) -> Int32 #else fileprivate func bjs_Greeter_name_get(_ self: Int32) -> Int32 { @@ -17,7 +34,7 @@ fileprivate func bjs_Greeter_name_get(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_age_get") +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_age_get") fileprivate func bjs_Greeter_age_get(_ self: Int32) -> Float64 #else fileprivate func bjs_Greeter_age_get(_ self: Int32) -> Float64 { @@ -26,7 +43,7 @@ fileprivate func bjs_Greeter_age_get(_ self: Int32) -> Float64 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_name_set") +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_name_set") fileprivate func bjs_Greeter_name_set(_ self: Int32, _ newValue: Int32) -> Void #else fileprivate func bjs_Greeter_name_set(_ self: Int32, _ newValue: Int32) -> Void { @@ -35,7 +52,7 @@ fileprivate func bjs_Greeter_name_set(_ self: Int32, _ newValue: Int32) -> Void #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_greet") +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_greet") fileprivate func bjs_Greeter_greet(_ self: Int32) -> Int32 #else fileprivate func bjs_Greeter_greet(_ self: Int32) -> Int32 { @@ -44,7 +61,7 @@ fileprivate func bjs_Greeter_greet(_ self: Int32) -> Int32 { #endif #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Greeter_changeName") +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_changeName") fileprivate func bjs_Greeter_changeName(_ self: Int32, _ name: Int32) -> Void #else fileprivate func bjs_Greeter_changeName(_ self: Int32, _ name: Int32) -> Void { @@ -104,4 +121,43 @@ func _$Greeter_changeName(_ self: JSObject, _ name: String) throws(JSException) if let error = _swift_js_take_exception() { throw error } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Animatable_animate") +fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 +#else +fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Animatable_getAnimations") +fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 +#else +fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$Animatable_animate(_ self: JSObject, _ keyframes: JSObject, _ options: JSObject) throws(JSException) -> JSObject { + let selfValue = self.bridgeJSLowerParameter() + let keyframesValue = keyframes.bridgeJSLowerParameter() + let optionsValue = options.bridgeJSLowerParameter() + let ret = bjs_Animatable_animate(selfValue, keyframesValue, optionsValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$Animatable_getAnimations(_ self: JSObject, _ options: JSObject) throws(JSException) -> JSObject { + let selfValue = self.bridgeJSLowerParameter() + let optionsValue = options.bridgeJSLowerParameter() + let ret = bjs_Animatable_getAnimations(selfValue, optionsValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) } \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json new file mode 100644 index 000000000..a8b64558f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -0,0 +1,134 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + + ], + "types" : [ + { + "getters" : [ + + ], + "methods" : [ + { + "name" : "value", + "parameters" : [ + + ], + "returnType" : { + "double" : { + + } + } + } + ], + "name" : "StaticBox", + "setters" : [ + + ], + "staticMethods" : [ + { + "name" : "create", + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + }, + { + "name" : "value", + "parameters" : [ + + ], + "returnType" : { + "double" : { + + } + } + }, + { + "name" : "makeDefault", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + }, + { + "jsName" : "with-dashes", + "name" : "dashed", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + } + ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ] + }, + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "WithCtor", + "setters" : [ + + ], + "staticMethods" : [ + { + "name" : "create", + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "WithCtor" + } + } + } + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift new file mode 100644 index 000000000..5e297f929 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift @@ -0,0 +1,122 @@ +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_create_static") +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 +#else +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_value_static") +fileprivate func bjs_StaticBox_value_static() -> Float64 +#else +fileprivate func bjs_StaticBox_value_static() -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_makeDefault_static") +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 +#else +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_dashed_static") +fileprivate func bjs_StaticBox_dashed_static() -> Int32 +#else +fileprivate func bjs_StaticBox_dashed_static() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_value") +fileprivate func bjs_StaticBox_value(_ self: Int32) -> Float64 +#else +fileprivate func bjs_StaticBox_value(_ self: Int32) -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$StaticBox_create(_ value: Double) throws(JSException) -> StaticBox { + let valueValue = value.bridgeJSLowerParameter() + let ret = bjs_StaticBox_create_static(valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return StaticBox.bridgeJSLiftReturn(ret) +} + +func _$StaticBox_value() throws(JSException) -> Double { + let ret = bjs_StaticBox_value_static() + if let error = _swift_js_take_exception() { + throw error + } + return Double.bridgeJSLiftReturn(ret) +} + +func _$StaticBox_makeDefault() throws(JSException) -> StaticBox { + let ret = bjs_StaticBox_makeDefault_static() + if let error = _swift_js_take_exception() { + throw error + } + return StaticBox.bridgeJSLiftReturn(ret) +} + +func _$StaticBox_dashed() throws(JSException) -> StaticBox { + let ret = bjs_StaticBox_dashed_static() + if let error = _swift_js_take_exception() { + throw error + } + return StaticBox.bridgeJSLiftReturn(ret) +} + +func _$StaticBox_value(_ self: JSObject) throws(JSException) -> Double { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_StaticBox_value(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return Double.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithCtor_init") +fileprivate func bjs_WithCtor_init(_ value: Float64) -> Int32 +#else +fileprivate func bjs_WithCtor_init(_ value: Float64) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithCtor_create_static") +fileprivate func bjs_WithCtor_create_static(_ value: Float64) -> Int32 +#else +fileprivate func bjs_WithCtor_create_static(_ value: Float64) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$WithCtor_init(_ value: Double) throws(JSException) -> JSObject { + let valueValue = value.bridgeJSLowerParameter() + let ret = bjs_WithCtor_init(valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$WithCtor_create(_ value: Double) throws(JSException) -> WithCtor { + let valueValue = value.bridgeJSLowerParameter() + let ret = bjs_WithCtor_create_static(valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return WithCtor.bridgeJSLiftReturn(ret) +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json new file mode 100644 index 000000000..5bd83be27 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json @@ -0,0 +1,375 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_JSValueHolder_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "jsValue" : { + + } + } + }, + { + "label" : "optionalValue", + "name" : "optionalValue", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_JSValueHolder_update", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "update", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "jsValue" : { + + } + } + }, + { + "label" : "optionalValue", + "name" : "optionalValue", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_JSValueHolder_echo", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "echo", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + + } + } + }, + { + "abiName" : "bjs_JSValueHolder_echoOptional", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "echoOptional", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "JSValueHolder", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "value", + "type" : { + "jsValue" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalValue", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "JSValueHolder" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_roundTripJSValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSValue", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + + } + } + }, + { + "abiName" : "bjs_roundTripOptionalJSValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalJSValue", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripJSValueArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSValueArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + }, + { + "abiName" : "bjs_roundTripOptionalJSValueArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalJSValueArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "jsEchoJSValue", + "parameters" : [ + { + "name" : "value", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + + } + } + }, + { + "name" : "jsEchoJSValueArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift new file mode 100644 index 000000000..f3550129c --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift @@ -0,0 +1,198 @@ +@_expose(wasm, "bjs_roundTripJSValue") +@_cdecl("bjs_roundTripJSValue") +public func _bjs_roundTripJSValue(_ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripJSValue(_: JSValue.bridgeJSLiftParameter(valueKind, valuePayload1, valuePayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalJSValue") +@_cdecl("bjs_roundTripOptionalJSValue") +public func _bjs_roundTripOptionalJSValue(_ valueIsSome: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalJSValue(_: Optional.bridgeJSLiftParameter(valueIsSome, valueKind, valuePayload1, valuePayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripJSValueArray") +@_cdecl("bjs_roundTripJSValueArray") +public func _bjs_roundTripJSValueArray() -> Void { + #if arch(wasm32) + let ret = roundTripJSValueArray(_: [JSValue].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalJSValueArray") +@_cdecl("bjs_roundTripOptionalJSValueArray") +public func _bjs_roundTripOptionalJSValueArray(_ values: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalJSValueArray(_: { + if values == 0 { + return Optional<[JSValue]>.none + } else { + return [JSValue].bridgeJSLiftParameter() + } + }()) + let __bjs_isSome_ret = ret != nil + if let __bjs_unwrapped_ret = ret { + __bjs_unwrapped_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_init") +@_cdecl("bjs_JSValueHolder_init") +public func _bjs_JSValueHolder_init(_ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64, _ optionalValueIsSome: Int32, _ optionalValueKind: Int32, _ optionalValuePayload1: Int32, _ optionalValuePayload2: Float64) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = JSValueHolder(value: JSValue.bridgeJSLiftParameter(valueKind, valuePayload1, valuePayload2), optionalValue: Optional.bridgeJSLiftParameter(optionalValueIsSome, optionalValueKind, optionalValuePayload1, optionalValuePayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_update") +@_cdecl("bjs_JSValueHolder_update") +public func _bjs_JSValueHolder_update(_ _self: UnsafeMutableRawPointer, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64, _ optionalValueIsSome: Int32, _ optionalValueKind: Int32, _ optionalValuePayload1: Int32, _ optionalValuePayload2: Float64) -> Void { + #if arch(wasm32) + JSValueHolder.bridgeJSLiftParameter(_self).update(value: JSValue.bridgeJSLiftParameter(valueKind, valuePayload1, valuePayload2), optionalValue: Optional.bridgeJSLiftParameter(optionalValueIsSome, optionalValueKind, optionalValuePayload1, optionalValuePayload2)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_echo") +@_cdecl("bjs_JSValueHolder_echo") +public func _bjs_JSValueHolder_echo(_ _self: UnsafeMutableRawPointer, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + let ret = JSValueHolder.bridgeJSLiftParameter(_self).echo(value: JSValue.bridgeJSLiftParameter(valueKind, valuePayload1, valuePayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_echoOptional") +@_cdecl("bjs_JSValueHolder_echoOptional") +public func _bjs_JSValueHolder_echoOptional(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + let ret = JSValueHolder.bridgeJSLiftParameter(_self).echoOptional(_: Optional.bridgeJSLiftParameter(valueIsSome, valueKind, valuePayload1, valuePayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_value_get") +@_cdecl("bjs_JSValueHolder_value_get") +public func _bjs_JSValueHolder_value_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = JSValueHolder.bridgeJSLiftParameter(_self).value + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_value_set") +@_cdecl("bjs_JSValueHolder_value_set") +public func _bjs_JSValueHolder_value_set(_ _self: UnsafeMutableRawPointer, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + JSValueHolder.bridgeJSLiftParameter(_self).value = JSValue.bridgeJSLiftParameter(valueKind, valuePayload1, valuePayload2) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_optionalValue_get") +@_cdecl("bjs_JSValueHolder_optionalValue_get") +public func _bjs_JSValueHolder_optionalValue_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = JSValueHolder.bridgeJSLiftParameter(_self).optionalValue + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_optionalValue_set") +@_cdecl("bjs_JSValueHolder_optionalValue_set") +public func _bjs_JSValueHolder_optionalValue_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + #if arch(wasm32) + JSValueHolder.bridgeJSLiftParameter(_self).optionalValue = Optional.bridgeJSLiftParameter(valueIsSome, valueKind, valuePayload1, valuePayload2) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_JSValueHolder_deinit") +@_cdecl("bjs_JSValueHolder_deinit") +public func _bjs_JSValueHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension JSValueHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_JSValueHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_JSValueHolder_wrap") +fileprivate func _bjs_JSValueHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_JSValueHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_jsEchoJSValue") +fileprivate func bjs_jsEchoJSValue(_ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void +#else +fileprivate func bjs_jsEchoJSValue(_ valueKind: Int32, _ valuePayload1: Int32, _ valuePayload2: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsEchoJSValue(_ value: JSValue) throws(JSException) -> JSValue { + let (valueKind, valuePayload1, valuePayload2) = value.bridgeJSLowerParameter() + bjs_jsEchoJSValue(valueKind, valuePayload1, valuePayload2) + if let error = _swift_js_take_exception() { + throw error + } + return JSValue.bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_jsEchoJSValueArray") +fileprivate func bjs_jsEchoJSValueArray() -> Void +#else +fileprivate func bjs_jsEchoJSValueArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsEchoJSValueArray(_ values: [JSValue]) throws(JSException) -> [JSValue] { + let _ = values.bridgeJSLowerParameter() + bjs_jsEchoJSValueArray() + if let error = _swift_js_take_exception() { + throw error + } + return [JSValue].bridgeJSLiftReturn() +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.json new file mode 100644 index 000000000..1241c232d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.json @@ -0,0 +1,79 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_GlobalClass_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_GlobalClass_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "GlobalClass", + "namespace" : [ + "GlobalAPI" + ], + "properties" : [ + + ], + "swiftCallName" : "GlobalClass" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_GlobalAPI_globalFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "globalFunction", + "namespace" : [ + "GlobalAPI" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.json new file mode 100644 index 000000000..96e188fd2 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.json @@ -0,0 +1,79 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_PrivateClass_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_PrivateClass_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "PrivateClass", + "namespace" : [ + "PrivateAPI" + ], + "properties" : [ + + ], + "swiftCallName" : "PrivateClass" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_PrivateAPI_privateFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "privateFunction", + "namespace" : [ + "PrivateAPI" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.json new file mode 100644 index 000000000..a87bffa6b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.json @@ -0,0 +1,185 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Greeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Greeter_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Greeter", + "namespace" : [ + "__Swift", + "Foundation" + ], + "properties" : [ + + ], + "swiftCallName" : "Greeter" + }, + { + "constructor" : { + "abiName" : "bjs_Converter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_Converter_toString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "toString", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Converter", + "namespace" : [ + "Utils", + "Converters" + ], + "properties" : [ + + ], + "swiftCallName" : "Converter" + }, + { + "methods" : [ + { + "abiName" : "bjs_UUID_uuidString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "uuidString", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "UUID", + "namespace" : [ + "__Swift", + "Foundation" + ], + "properties" : [ + + ], + "swiftCallName" : "UUID" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : true, + "functions" : [ + { + "abiName" : "bjs_plainFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "plainFunction", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_MyModule_Utils_namespacedFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "namespacedFunction", + "namespace" : [ + "MyModule", + "Utils" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.json new file mode 100644 index 000000000..766d93a5d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.json @@ -0,0 +1,185 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Greeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Greeter_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Greeter", + "namespace" : [ + "__Swift", + "Foundation" + ], + "properties" : [ + + ], + "swiftCallName" : "Greeter" + }, + { + "constructor" : { + "abiName" : "bjs_Converter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_Converter_toString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "toString", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Converter", + "namespace" : [ + "Utils", + "Converters" + ], + "properties" : [ + + ], + "swiftCallName" : "Converter" + }, + { + "methods" : [ + { + "abiName" : "bjs_UUID_uuidString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "uuidString", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "UUID", + "namespace" : [ + "__Swift", + "Foundation" + ], + "properties" : [ + + ], + "swiftCallName" : "UUID" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_plainFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "plainFunction", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_MyModule_Utils_namespacedFunction", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "namespacedFunction", + "namespace" : [ + "MyModule", + "Utils" + ], + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json new file mode 100644 index 000000000..9c99bb8c4 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json @@ -0,0 +1,1233 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Greeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Greeter_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_Greeter_changeName", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "changeName", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "Greeter", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Greeter" + }, + { + "constructor" : { + "abiName" : "bjs_OptionalPropertyHolder_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "OptionalPropertyHolder", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalName", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalAge", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalGreeter", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "OptionalPropertyHolder" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_roundTripOptionalClass", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalClass", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testOptionalPropertyRoundtrip", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testOptionalPropertyRoundtrip", + "parameters" : [ + { + "label" : "_", + "name" : "holder", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "OptionalPropertyHolder" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "OptionalPropertyHolder" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripString", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripInt", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripInt", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripBool", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripBool", + "parameters" : [ + { + "label" : "flag", + "name" : "flag", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripFloat", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripFloat", + "parameters" : [ + { + "label" : "number", + "name" : "number", + "type" : { + "nullable" : { + "_0" : { + "float" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "float" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripDouble", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripDouble", + "parameters" : [ + { + "label" : "precision", + "name" : "precision", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripSyntax", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripSyntax", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripMixSyntax", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripMixSyntax", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripSwiftSyntax", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripSwiftSyntax", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripMixedSwiftSyntax", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripMixedSwiftSyntax", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripWithSpaces", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripWithSpaces", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripAlias", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripAlias", + "parameters" : [ + { + "label" : "age", + "name" : "age", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalAlias", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalAlias", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_testMixedOptionals", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testMixedOptionals", + "parameters" : [ + { + "label" : "firstName", + "name" : "firstName", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "label" : "lastName", + "name" : "lastName", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "label" : "age", + "name" : "age", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "label" : "active", + "name" : "active", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "valueOrNull", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "valueOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + } + ] + }, + "getters" : [ + { + "name" : "stringOrNull", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "stringOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "doubleOrNull", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "doubleOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "boolOrNull", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "boolOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "intOrNull", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "intOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "methods" : [ + { + "name" : "roundTripStringOrNull", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "roundTripStringOrUndefined", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "roundTripDoubleOrNull", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "roundTripDoubleOrUndefined", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "roundTripBoolOrNull", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "roundTripBoolOrUndefined", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "roundTripIntOrNull", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "roundTripIntOrUndefined", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "name" : "WithOptionalJSClass", + "setters" : [ + { + "functionName" : "stringOrNull_set", + "name" : "stringOrNull", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "functionName" : "stringOrUndefined_set", + "name" : "stringOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "functionName" : "doubleOrNull_set", + "name" : "doubleOrNull", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + }, + { + "functionName" : "doubleOrUndefined_set", + "name" : "doubleOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "functionName" : "boolOrNull_set", + "name" : "boolOrNull", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "functionName" : "boolOrUndefined_set", + "name" : "boolOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "functionName" : "intOrNull_set", + "name" : "intOrNull", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "functionName" : "intOrUndefined_set", + "name" : "intOrUndefined", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "staticMethods" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift new file mode 100644 index 000000000..471d38a6c --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift @@ -0,0 +1,800 @@ +@_expose(wasm, "bjs_roundTripOptionalClass") +@_cdecl("bjs_roundTripOptionalClass") +public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalClass(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_testOptionalPropertyRoundtrip") +@_cdecl("bjs_testOptionalPropertyRoundtrip") +public func _bjs_testOptionalPropertyRoundtrip(_ holderIsSome: Int32, _ holderValue: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = testOptionalPropertyRoundtrip(_: Optional.bridgeJSLiftParameter(holderIsSome, holderValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripString") +@_cdecl("bjs_roundTripString") +public func _bjs_roundTripString(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripInt") +@_cdecl("bjs_roundTripInt") +public func _bjs_roundTripInt(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripBool") +@_cdecl("bjs_roundTripBool") +public func _bjs_roundTripBool(_ flagIsSome: Int32, _ flagValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripFloat") +@_cdecl("bjs_roundTripFloat") +public func _bjs_roundTripFloat(_ numberIsSome: Int32, _ numberValue: Float32) -> Void { + #if arch(wasm32) + let ret = roundTripFloat(number: Optional.bridgeJSLiftParameter(numberIsSome, numberValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripDouble") +@_cdecl("bjs_roundTripDouble") +public func _bjs_roundTripDouble(_ precisionIsSome: Int32, _ precisionValue: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripDouble(precision: Optional.bridgeJSLiftParameter(precisionIsSome, precisionValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripSyntax") +@_cdecl("bjs_roundTripSyntax") +public func _bjs_roundTripSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripMixSyntax") +@_cdecl("bjs_roundTripMixSyntax") +public func _bjs_roundTripMixSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripMixSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripSwiftSyntax") +@_cdecl("bjs_roundTripSwiftSyntax") +public func _bjs_roundTripSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripMixedSwiftSyntax") +@_cdecl("bjs_roundTripMixedSwiftSyntax") +public func _bjs_roundTripMixedSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripMixedSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripWithSpaces") +@_cdecl("bjs_roundTripWithSpaces") +public func _bjs_roundTripWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripWithSpaces(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripAlias") +@_cdecl("bjs_roundTripAlias") +public func _bjs_roundTripAlias(_ ageIsSome: Int32, _ ageValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalAlias") +@_cdecl("bjs_roundTripOptionalAlias") +public func _bjs_roundTripOptionalAlias(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalAlias(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_testMixedOptionals") +@_cdecl("bjs_testMixedOptionals") +public func _bjs_testMixedOptionals(_ firstNameIsSome: Int32, _ firstNameBytes: Int32, _ firstNameLength: Int32, _ lastNameIsSome: Int32, _ lastNameBytes: Int32, _ lastNameLength: Int32, _ ageIsSome: Int32, _ ageValue: Int32, _ active: Int32) -> Void { + #if arch(wasm32) + let ret = testMixedOptionals(firstName: Optional.bridgeJSLiftParameter(firstNameIsSome, firstNameBytes, firstNameLength), lastName: Optional.bridgeJSLiftParameter(lastNameIsSome, lastNameBytes, lastNameLength), age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue), active: Bool.bridgeJSLiftParameter(active)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_init") +@_cdecl("bjs_Greeter_init") +public func _bjs_Greeter_init(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = Greeter(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_greet") +@_cdecl("bjs_Greeter_greet") +public func _bjs_Greeter_greet(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = Greeter.bridgeJSLiftParameter(_self).greet() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_changeName") +@_cdecl("bjs_Greeter_changeName") +public func _bjs_Greeter_changeName(_ _self: UnsafeMutableRawPointer, _ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + Greeter.bridgeJSLiftParameter(_self).changeName(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_name_get") +@_cdecl("bjs_Greeter_name_get") +public func _bjs_Greeter_name_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = Greeter.bridgeJSLiftParameter(_self).name + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_name_set") +@_cdecl("bjs_Greeter_name_set") +public func _bjs_Greeter_name_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + Greeter.bridgeJSLiftParameter(_self).name = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Greeter_deinit") +@_cdecl("bjs_Greeter_deinit") +public func _bjs_Greeter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension Greeter: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_Greeter_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Greeter_wrap") +fileprivate func _bjs_Greeter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_Greeter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_OptionalPropertyHolder_init") +@_cdecl("bjs_OptionalPropertyHolder_init") +public func _bjs_OptionalPropertyHolder_init() -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = OptionalPropertyHolder() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalName_get") +public func _bjs_OptionalPropertyHolder_optionalName_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalName_set") +public func _bjs_OptionalPropertyHolder_optionalName_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalAge_get") +public func _bjs_OptionalPropertyHolder_optionalAge_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalAge_set") +public func _bjs_OptionalPropertyHolder_optionalAge_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_get") +public func _bjs_OptionalPropertyHolder_optionalGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_set") +public func _bjs_OptionalPropertyHolder_optionalGreeter_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_deinit") +@_cdecl("bjs_OptionalPropertyHolder_deinit") +public func _bjs_OptionalPropertyHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension OptionalPropertyHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalPropertyHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_OptionalPropertyHolder_wrap") +fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_init") +fileprivate func bjs_WithOptionalJSClass_init(_ valueOrNullIsSome: Int32, _ valueOrNullValue: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedValue: Int32) -> Int32 +#else +fileprivate func bjs_WithOptionalJSClass_init(_ valueOrNullIsSome: Int32, _ valueOrNullValue: Int32, _ valueOrUndefinedIsSome: Int32, _ valueOrUndefinedValue: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrNull_get") +fileprivate func bjs_WithOptionalJSClass_stringOrNull_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_stringOrNull_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrUndefined_get") +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_doubleOrNull_get") +fileprivate func bjs_WithOptionalJSClass_doubleOrNull_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_doubleOrNull_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_doubleOrUndefined_get") +fileprivate func bjs_WithOptionalJSClass_doubleOrUndefined_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_doubleOrUndefined_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_boolOrNull_get") +fileprivate func bjs_WithOptionalJSClass_boolOrNull_get(_ self: Int32) -> Int32 +#else +fileprivate func bjs_WithOptionalJSClass_boolOrNull_get(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_boolOrUndefined_get") +fileprivate func bjs_WithOptionalJSClass_boolOrUndefined_get(_ self: Int32) -> Int32 +#else +fileprivate func bjs_WithOptionalJSClass_boolOrUndefined_get(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_intOrNull_get") +fileprivate func bjs_WithOptionalJSClass_intOrNull_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_intOrNull_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_intOrUndefined_get") +fileprivate func bjs_WithOptionalJSClass_intOrUndefined_get(_ self: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_intOrUndefined_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrNull_set") +fileprivate func bjs_WithOptionalJSClass_stringOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_stringOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_stringOrUndefined_set") +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_stringOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_doubleOrNull_set") +fileprivate func bjs_WithOptionalJSClass_doubleOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Float64) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_doubleOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_doubleOrUndefined_set") +fileprivate func bjs_WithOptionalJSClass_doubleOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Float64) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_doubleOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_boolOrNull_set") +fileprivate func bjs_WithOptionalJSClass_boolOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_boolOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_boolOrUndefined_set") +fileprivate func bjs_WithOptionalJSClass_boolOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_boolOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_intOrNull_set") +fileprivate func bjs_WithOptionalJSClass_intOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_intOrNull_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_intOrUndefined_set") +fileprivate func bjs_WithOptionalJSClass_intOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_intOrUndefined_set(_ self: Int32, _ newValueIsSome: Int32, _ newValueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripStringOrNull") +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripStringOrUndefined") +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripStringOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripDoubleOrNull") +fileprivate func bjs_WithOptionalJSClass_roundTripDoubleOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Float64) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripDoubleOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripDoubleOrUndefined") +fileprivate func bjs_WithOptionalJSClass_roundTripDoubleOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Float64) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripDoubleOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripBoolOrNull") +fileprivate func bjs_WithOptionalJSClass_roundTripBoolOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Int32 +#else +fileprivate func bjs_WithOptionalJSClass_roundTripBoolOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripBoolOrUndefined") +fileprivate func bjs_WithOptionalJSClass_roundTripBoolOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Int32 +#else +fileprivate func bjs_WithOptionalJSClass_roundTripBoolOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripIntOrNull") +fileprivate func bjs_WithOptionalJSClass_roundTripIntOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripIntOrNull(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_WithOptionalJSClass_roundTripIntOrUndefined") +fileprivate func bjs_WithOptionalJSClass_roundTripIntOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_WithOptionalJSClass_roundTripIntOrUndefined(_ self: Int32, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$WithOptionalJSClass_init(_ valueOrNull: Optional, _ valueOrUndefined: JSUndefinedOr) throws(JSException) -> JSObject { + let (valueOrNullIsSome, valueOrNullValue) = valueOrNull.bridgeJSLowerParameter() + let (valueOrUndefinedIsSome, valueOrUndefinedValue) = valueOrUndefined.bridgeJSLowerParameter() + let ret = bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullValue, valueOrUndefinedIsSome, valueOrUndefinedValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$WithOptionalJSClass_stringOrNull_get(_ self: JSObject) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_stringOrNull_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_stringOrUndefined_get(_ self: JSObject) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_stringOrUndefined_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_doubleOrNull_get(_ self: JSObject) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_doubleOrNull_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_doubleOrUndefined_get(_ self: JSObject) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_doubleOrUndefined_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_boolOrNull_get(_ self: JSObject) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_WithOptionalJSClass_boolOrNull_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturn(ret) +} + +func _$WithOptionalJSClass_boolOrUndefined_get(_ self: JSObject) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_WithOptionalJSClass_boolOrUndefined_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturn(ret) +} + +func _$WithOptionalJSClass_intOrNull_get(_ self: JSObject) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_intOrNull_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_intOrUndefined_get(_ self: JSObject) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_intOrUndefined_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_stringOrNull_set(_ self: JSObject, _ newValue: Optional) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_stringOrNull_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_stringOrUndefined_set(_ self: JSObject, _ newValue: JSUndefinedOr) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_stringOrUndefined_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_doubleOrNull_set(_ self: JSObject, _ newValue: Optional) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_doubleOrNull_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_doubleOrUndefined_set(_ self: JSObject, _ newValue: JSUndefinedOr) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_doubleOrUndefined_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_boolOrNull_set(_ self: JSObject, _ newValue: Optional) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_boolOrNull_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_boolOrUndefined_set(_ self: JSObject, _ newValue: JSUndefinedOr) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_boolOrUndefined_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_intOrNull_set(_ self: JSObject, _ newValue: Optional) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_intOrNull_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_intOrUndefined_set(_ self: JSObject, _ newValue: JSUndefinedOr) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let (newValueIsSome, newValueValue) = newValue.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_intOrUndefined_set(selfValue, newValueIsSome, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$WithOptionalJSClass_roundTripStringOrNull(_ self: JSObject, _ value: Optional) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripStringOrNull(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_roundTripStringOrUndefined(_ self: JSObject, _ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripStringOrUndefined(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_roundTripDoubleOrNull(_ self: JSObject, _ value: Optional) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripDoubleOrNull(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_roundTripDoubleOrUndefined(_ self: JSObject, _ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripDoubleOrUndefined(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_roundTripBoolOrNull(_ self: JSObject, _ value: Optional) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + let ret = bjs_WithOptionalJSClass_roundTripBoolOrNull(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturn(ret) +} + +func _$WithOptionalJSClass_roundTripBoolOrUndefined(_ self: JSObject, _ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + let ret = bjs_WithOptionalJSClass_roundTripBoolOrUndefined(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturn(ret) +} + +func _$WithOptionalJSClass_roundTripIntOrNull(_ self: JSObject, _ value: Optional) throws(JSException) -> Optional { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripIntOrNull(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +func _$WithOptionalJSClass_roundTripIntOrUndefined(_ self: JSObject, _ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let selfValue = self.bridgeJSLowerParameter() + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_WithOptionalJSClass_roundTripIntOrUndefined(selfValue, valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.json new file mode 100644 index 000000000..8b586dbe0 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.json @@ -0,0 +1,118 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_check", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "check", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "int" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "uint" : { + + } + } + }, + { + "label" : "c", + "name" : "c", + "type" : { + "float" : { + + } + } + }, + { + "label" : "d", + "name" : "d", + "type" : { + "double" : { + + } + } + }, + { + "label" : "e", + "name" : "e", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "check", + "parameters" : [ + { + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "name" : "b", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.swift new file mode 100644 index 000000000..763cf8ca4 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.swift @@ -0,0 +1,27 @@ +@_expose(wasm, "bjs_check") +@_cdecl("bjs_check") +public func _bjs_check(_ a: Int32, _ b: Int32, _ c: Float32, _ d: Float64, _ e: Int32) -> Void { + #if arch(wasm32) + check(a: Int.bridgeJSLiftParameter(a), b: UInt.bridgeJSLiftParameter(b), c: Float.bridgeJSLiftParameter(c), d: Double.bridgeJSLiftParameter(d), e: Bool.bridgeJSLiftParameter(e)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_check") +fileprivate func bjs_check(_ a: Float64, _ b: Int32) -> Void +#else +fileprivate func bjs_check(_ a: Float64, _ b: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$check(_ a: Double, _ b: Bool) throws(JSException) -> Void { + let aValue = a.bridgeJSLowerParameter() + let bValue = b.bridgeJSLowerParameter() + bjs_check(aValue, bValue) + if let error = _swift_js_take_exception() { + throw error + } +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.json new file mode 100644 index 000000000..aae09ea49 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.json @@ -0,0 +1,138 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_checkInt", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkInt", + "parameters" : [ + + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_checkUInt", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkUInt", + "parameters" : [ + + ], + "returnType" : { + "uint" : { + + } + } + }, + { + "abiName" : "bjs_checkFloat", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkFloat", + "parameters" : [ + + ], + "returnType" : { + "float" : { + + } + } + }, + { + "abiName" : "bjs_checkDouble", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkDouble", + "parameters" : [ + + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_checkBool", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkBool", + "parameters" : [ + + ], + "returnType" : { + "bool" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "checkNumber", + "parameters" : [ + + ], + "returnType" : { + "double" : { + + } + } + }, + { + "name" : "checkBoolean", + "parameters" : [ + + ], + "returnType" : { + "bool" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.swift similarity index 59% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.swift index 74ee7b1c3..3bbb2809b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.swift @@ -51,4 +51,38 @@ public func _bjs_checkBool() -> Int32 { #else fatalError("Only available on WebAssembly") #endif +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_checkNumber") +fileprivate func bjs_checkNumber() -> Float64 +#else +fileprivate func bjs_checkNumber() -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$checkNumber() throws(JSException) -> Double { + let ret = bjs_checkNumber() + if let error = _swift_js_take_exception() { + throw error + } + return Double.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_checkBoolean") +fileprivate func bjs_checkBoolean() -> Int32 +#else +fileprivate func bjs_checkBoolean() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$checkBoolean() throws(JSException) -> Bool { + let ret = bjs_checkBoolean() + if let error = _swift_js_take_exception() { + throw error + } + return Bool.bridgeJSLiftReturn(ret) } \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.json new file mode 100644 index 000000000..1c71b2b8f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.json @@ -0,0 +1,363 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_PropertyHolder_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "intValue", + "name" : "intValue", + "type" : { + "int" : { + + } + } + }, + { + "label" : "floatValue", + "name" : "floatValue", + "type" : { + "float" : { + + } + } + }, + { + "label" : "doubleValue", + "name" : "doubleValue", + "type" : { + "double" : { + + } + } + }, + { + "label" : "boolValue", + "name" : "boolValue", + "type" : { + "bool" : { + + } + } + }, + { + "label" : "stringValue", + "name" : "stringValue", + "type" : { + "string" : { + + } + } + }, + { + "label" : "jsObject", + "name" : "jsObject", + "type" : { + "jsObject" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_PropertyHolder_getAllValues", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getAllValues", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "PropertyHolder", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "intValue", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "floatValue", + "type" : { + "float" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "doubleValue", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "boolValue", + "type" : { + "bool" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "stringValue", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "readonlyInt", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "readonlyFloat", + "type" : { + "float" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "readonlyDouble", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "readonlyBool", + "type" : { + "bool" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "readonlyString", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "jsObject", + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "sibling", + "type" : { + "swiftHeapObject" : { + "_0" : "PropertyHolder" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "lazyValue", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "computedReadonly", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "computedReadWrite", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "observedProperty", + "type" : { + "int" : { + + } + } + } + ], + "swiftCallName" : "PropertyHolder" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_createPropertyHolder", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createPropertyHolder", + "parameters" : [ + { + "label" : "intValue", + "name" : "intValue", + "type" : { + "int" : { + + } + } + }, + { + "label" : "floatValue", + "name" : "floatValue", + "type" : { + "float" : { + + } + } + }, + { + "label" : "doubleValue", + "name" : "doubleValue", + "type" : { + "double" : { + + } + } + }, + { + "label" : "boolValue", + "name" : "boolValue", + "type" : { + "bool" : { + + } + } + }, + { + "label" : "stringValue", + "name" : "stringValue", + "type" : { + "string" : { + + } + } + }, + { + "label" : "jsObject", + "name" : "jsObject", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "PropertyHolder" + } + } + }, + { + "abiName" : "bjs_testPropertyHolder", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testPropertyHolder", + "parameters" : [ + { + "label" : "holder", + "name" : "holder", + "type" : { + "swiftHeapObject" : { + "_0" : "PropertyHolder" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json new file mode 100644 index 000000000..e9f5264cd --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -0,0 +1,909 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Helper_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Helper_increment", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "increment", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "Helper", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "swiftCallName" : "Helper" + }, + { + "constructor" : { + "abiName" : "bjs_MyViewController_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "delegate", + "name" : "delegate", + "type" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_MyViewController_triggerEvent", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "triggerEvent", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewController_updateValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "updateValue", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewController_updateCount", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "updateCount", + "parameters" : [ + { + "label" : "_", + "name" : "count", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_MyViewController_updateLabel", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "updateLabel", + "parameters" : [ + { + "label" : "_", + "name" : "prefix", + "type" : { + "string" : { + + } + } + }, + { + "label" : "_", + "name" : "suffix", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewController_checkEvenCount", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkEvenCount", + "parameters" : [ + + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_MyViewController_sendHelper", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "sendHelper", + "parameters" : [ + { + "label" : "_", + "name" : "helper", + "type" : { + "swiftHeapObject" : { + "_0" : "Helper" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "MyViewController", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "delegate", + "type" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "secondDelegate", + "type" : { + "nullable" : { + "_0" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "MyViewController" + }, + { + "constructor" : { + "abiName" : "bjs_DelegateManager_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "delegates", + "name" : "delegates", + "type" : { + "array" : { + "_0" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_DelegateManager_notifyAll", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "notifyAll", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "DelegateManager", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "delegates", + "type" : { + "array" : { + "_0" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + } + } + } + ], + "swiftCallName" : "DelegateManager" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "Direction", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Direction", + "tsFullPath" : "Direction" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "test", + "rawValue" : "test" + }, + { + "associatedValues" : [ + + ], + "name" : "test2", + "rawValue" : "test2" + } + ], + "emitStyle" : "const", + "name" : "ExampleEnum", + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "ExampleEnum", + "tsFullPath" : "ExampleEnum" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + } + ], + "emitStyle" : "const", + "name" : "Result", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Result", + "tsFullPath" : "Result" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "low", + "rawValue" : "-1" + }, + { + "associatedValues" : [ + + ], + "name" : "medium", + "rawValue" : "0" + }, + { + "associatedValues" : [ + + ], + "name" : "high", + "rawValue" : "1" + } + ], + "emitStyle" : "const", + "name" : "Priority", + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Priority", + "tsFullPath" : "Priority" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_processDelegates", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processDelegates", + "parameters" : [ + { + "label" : "_", + "name" : "delegates", + "type" : { + "array" : { + "_0" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "swiftProtocol" : { + "_0" : "MyViewControllerDelegate" + } + } + } + } + } + ], + "protocols" : [ + { + "methods" : [ + { + "abiName" : "bjs_MyViewControllerDelegate_onSomethingHappened", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onSomethingHappened", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_onValueChanged", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onValueChanged", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_onCountUpdated", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onCountUpdated", + "parameters" : [ + { + "label" : "count", + "name" : "count", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_onLabelUpdated", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onLabelUpdated", + "parameters" : [ + { + "label" : "_", + "name" : "prefix", + "type" : { + "string" : { + + } + } + }, + { + "label" : "_", + "name" : "suffix", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_isCountEven", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "isCountEven", + "parameters" : [ + + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_onHelperUpdated", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onHelperUpdated", + "parameters" : [ + { + "label" : "_", + "name" : "helper", + "type" : { + "swiftHeapObject" : { + "_0" : "Helper" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_createHelper", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createHelper", + "parameters" : [ + + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "Helper" + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_onOptionalHelperUpdated", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "onOptionalHelperUpdated", + "parameters" : [ + { + "label" : "_", + "name" : "helper", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Helper" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_createOptionalHelper", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createOptionalHelper", + "parameters" : [ + + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Helper" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_createEnum", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createEnum", + "parameters" : [ + + ], + "returnType" : { + "rawValueEnum" : { + "_0" : "ExampleEnum", + "_1" : "String" + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_handleResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handleResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "Result" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_MyViewControllerDelegate_getResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getResult", + "parameters" : [ + + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "Result" + } + } + } + ], + "name" : "MyViewControllerDelegate", + "properties" : [ + { + "isReadonly" : false, + "name" : "eventCount", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "name" : "delegateName", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "name" : "optionalName", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "optionalRawEnum", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "ExampleEnum", + "_1" : "String" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "rawStringEnum", + "type" : { + "rawValueEnum" : { + "_0" : "ExampleEnum", + "_1" : "String" + } + } + }, + { + "isReadonly" : false, + "name" : "result", + "type" : { + "associatedValueEnum" : { + "_0" : "Result" + } + } + }, + { + "isReadonly" : false, + "name" : "optionalResult", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "Result" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "direction", + "type" : { + "caseEnum" : { + "_0" : "Direction" + } + } + }, + { + "isReadonly" : false, + "name" : "directionOptional", + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "priority", + "type" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int" + } + } + }, + { + "isReadonly" : false, + "name" : "priorityOptional", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Priority", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + } + ] + } + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift similarity index 92% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index 0558e2a1f..3536b53cb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -359,16 +359,16 @@ extension Direction: _BridgedSwiftCaseEnum { } } -extension ExampleEnum: _BridgedSwiftEnumNoPayload { +extension ExampleEnum: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Result: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> Result { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) default: fatalError("Unknown Result case ID: \(caseId)") } @@ -379,13 +379,10 @@ extension Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) } } @@ -403,38 +400,26 @@ extension Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) } } } -extension Priority: _BridgedSwiftEnumNoPayload { +extension Priority: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } @_expose(wasm, "bjs_processDelegates") @_cdecl("bjs_processDelegates") public func _bjs_processDelegates() -> Void { #if arch(wasm32) - let ret = processDelegates(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [AnyMyViewControllerDelegate] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(AnyMyViewControllerDelegate.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32((__bjs_elem_ret as! AnyMyViewControllerDelegate).bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = processDelegates(_: [AnyMyViewControllerDelegate].bridgeJSLiftParameter()) + ret.map { + $0 as! AnyMyViewControllerDelegate + } .bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -653,16 +638,7 @@ fileprivate func _bjs_MyViewController_wrap(_ pointer: UnsafeMutableRawPointer) @_cdecl("bjs_DelegateManager_init") public func _bjs_DelegateManager_init() -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = DelegateManager(delegates: { - let __count = Int(_swift_js_pop_i32()) - var __result: [AnyMyViewControllerDelegate] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(AnyMyViewControllerDelegate.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + let ret = DelegateManager(delegates: [AnyMyViewControllerDelegate].bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -684,9 +660,9 @@ public func _bjs_DelegateManager_notifyAll(_ _self: UnsafeMutableRawPointer) -> public func _bjs_DelegateManager_delegates_get(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) let ret = DelegateManager.bridgeJSLiftParameter(_self).delegates - for __bjs_elem_ret in ret { - _swift_js_push_i32((__bjs_elem_ret as! AnyMyViewControllerDelegate).bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + ret.map { + $0 as! AnyMyViewControllerDelegate + } .bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -696,16 +672,7 @@ public func _bjs_DelegateManager_delegates_get(_ _self: UnsafeMutableRawPointer) @_cdecl("bjs_DelegateManager_delegates_set") public func _bjs_DelegateManager_delegates_set(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - DelegateManager.bridgeJSLiftParameter(_self).delegates = { - let __count = Int(_swift_js_pop_i32()) - var __result: [AnyMyViewControllerDelegate] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(AnyMyViewControllerDelegate.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }() + DelegateManager.bridgeJSLiftParameter(_self).delegates = [AnyMyViewControllerDelegate].bridgeJSLiftParameter() #else fatalError("Only available on WebAssembly") #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.json new file mode 100644 index 000000000..b0eac3313 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.json @@ -0,0 +1,339 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_MathUtils_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_MathUtils_static_subtract", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "subtract", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "int" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "className" : { + "_0" : "MathUtils" + } + } + }, + { + "abiName" : "bjs_MathUtils_static_add", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "add", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "int" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "className" : { + "_0" : "MathUtils" + } + } + }, + { + "abiName" : "bjs_MathUtils_multiply", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "multiply", + "parameters" : [ + { + "label" : "x", + "name" : "x", + "type" : { + "int" : { + + } + } + }, + { + "label" : "y", + "name" : "y", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + } + } + ], + "name" : "MathUtils", + "properties" : [ + + ], + "swiftCallName" : "MathUtils" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "scientific" + }, + { + "associatedValues" : [ + + ], + "name" : "basic" + } + ], + "emitStyle" : "const", + "name" : "Calculator", + "staticMethods" : [ + { + "abiName" : "bjs_Calculator_static_square", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "square", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "enumName" : { + "_0" : "Calculator" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Calculator", + "tsFullPath" : "Calculator" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + } + ], + "emitStyle" : "const", + "name" : "APIResult", + "staticMethods" : [ + { + "abiName" : "bjs_APIResult_static_roundtrip", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "roundtrip", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "staticContext" : { + "enumName" : { + "_0" : "APIResult" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIResult", + "tsFullPath" : "APIResult" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Utils", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils", + "tsFullPath" : "Utils" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "String", + "namespace" : [ + "Utils" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Utils_String_static_uppercase", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "uppercase", + "namespace" : [ + "Utils", + "String" + ], + "parameters" : [ + { + "label" : "_", + "name" : "text", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "Utils.String" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils.String", + "tsFullPath" : "Utils.String" + } + ], + "exposeToGlobal" : true, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift similarity index 90% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift index 378eff8bb..3e5b40def 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift @@ -48,9 +48,9 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) default: fatalError("Unknown APIResult case ID: \(caseId)") } @@ -61,13 +61,10 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) } } @@ -85,14 +82,11 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.json new file mode 100644 index 000000000..e4ec22855 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.json @@ -0,0 +1,339 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_MathUtils_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + { + "abiName" : "bjs_MathUtils_static_subtract", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "subtract", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "int" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "className" : { + "_0" : "MathUtils" + } + } + }, + { + "abiName" : "bjs_MathUtils_static_add", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "add", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "int" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "className" : { + "_0" : "MathUtils" + } + } + }, + { + "abiName" : "bjs_MathUtils_multiply", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "multiply", + "parameters" : [ + { + "label" : "x", + "name" : "x", + "type" : { + "int" : { + + } + } + }, + { + "label" : "y", + "name" : "y", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + } + } + ], + "name" : "MathUtils", + "properties" : [ + + ], + "swiftCallName" : "MathUtils" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "scientific" + }, + { + "associatedValues" : [ + + ], + "name" : "basic" + } + ], + "emitStyle" : "const", + "name" : "Calculator", + "staticMethods" : [ + { + "abiName" : "bjs_Calculator_static_square", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "square", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "enumName" : { + "_0" : "Calculator" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Calculator", + "tsFullPath" : "Calculator" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + } + ], + "emitStyle" : "const", + "name" : "APIResult", + "staticMethods" : [ + { + "abiName" : "bjs_APIResult_static_roundtrip", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "roundtrip", + "parameters" : [ + { + "label" : "value", + "name" : "value", + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "returnType" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "staticContext" : { + "enumName" : { + "_0" : "APIResult" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIResult", + "tsFullPath" : "APIResult" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Utils", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils", + "tsFullPath" : "Utils" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "String", + "namespace" : [ + "Utils" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Utils_String_static_uppercase", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "uppercase", + "namespace" : [ + "Utils", + "String" + ], + "parameters" : [ + { + "label" : "_", + "name" : "text", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "Utils.String" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils.String", + "tsFullPath" : "Utils.String" + } + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift similarity index 90% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift index 378eff8bb..3e5b40def 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift @@ -48,9 +48,9 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) default: fatalError("Unknown APIResult case ID: \(caseId)") } @@ -61,13 +61,10 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) } } @@ -85,14 +82,11 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json new file mode 100644 index 000000000..bb9e48091 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json @@ -0,0 +1,343 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_PropertyClass_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "PropertyClass", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : true, + "name" : "staticConstant", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "staticVariable", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "jsObjectProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "classVariable", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "computedProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "readOnlyComputed", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "optionalProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "PropertyClass" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "value1" + }, + { + "associatedValues" : [ + + ], + "name" : "value2" + } + ], + "emitStyle" : "const", + "name" : "PropertyEnum", + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "enumProperty", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "enumConstant", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "computedEnum", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "PropertyEnum", + "tsFullPath" : "PropertyEnum" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "PropertyNamespace", + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "namespaceProperty", + "namespace" : [ + "PropertyNamespace" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "namespaceConstant", + "namespace" : [ + "PropertyNamespace" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace" + } + }, + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "PropertyNamespace", + "tsFullPath" : "PropertyNamespace" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Nested", + "namespace" : [ + "PropertyNamespace" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "nestedProperty", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "nestedConstant", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "nestedDouble", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "double" : { + + } + } + } + ], + "swiftCallName" : "PropertyNamespace.Nested", + "tsFullPath" : "PropertyNamespace.Nested" + } + ], + "exposeToGlobal" : true, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json new file mode 100644 index 000000000..d385e3887 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json @@ -0,0 +1,343 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_PropertyClass_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + + ] + }, + "methods" : [ + + ], + "name" : "PropertyClass", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : true, + "name" : "staticConstant", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "staticVariable", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "jsObjectProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "classVariable", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "computedProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "readOnlyComputed", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "optionalProperty", + "staticContext" : { + "className" : { + "_0" : "PropertyClass" + } + }, + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "PropertyClass" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "value1" + }, + { + "associatedValues" : [ + + ], + "name" : "value2" + } + ], + "emitStyle" : "const", + "name" : "PropertyEnum", + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "enumProperty", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "enumConstant", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "computedEnum", + "staticContext" : { + "enumName" : { + "_0" : "PropertyEnum" + } + }, + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "PropertyEnum", + "tsFullPath" : "PropertyEnum" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "PropertyNamespace", + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "namespaceProperty", + "namespace" : [ + "PropertyNamespace" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "namespaceConstant", + "namespace" : [ + "PropertyNamespace" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace" + } + }, + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "PropertyNamespace", + "tsFullPath" : "PropertyNamespace" + }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "Nested", + "namespace" : [ + "PropertyNamespace" + ], + "staticMethods" : [ + + ], + "staticProperties" : [ + { + "isReadonly" : false, + "isStatic" : true, + "name" : "nestedProperty", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "nestedConstant", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "nestedDouble", + "namespace" : [ + "PropertyNamespace", + "Nested" + ], + "staticContext" : { + "namespaceEnum" : { + "_0" : "PropertyNamespace.Nested" + } + }, + "type" : { + "double" : { + + } + } + } + ], + "swiftCallName" : "PropertyNamespace.Nested", + "tsFullPath" : "PropertyNamespace.Nested" + } + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.json new file mode 100644 index 000000000..b0aa8c35b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.json @@ -0,0 +1,125 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_checkString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkString", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_roundtripString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripString", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "checkString", + "parameters" : [ + { + "name" : "a", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "name" : "checkStringWithLength", + "parameters" : [ + { + "name" : "a", + "type" : { + "string" : { + + } + } + }, + { + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift similarity index 54% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift index 694c44e06..e9e3c2d89 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.swift @@ -1,5 +1,26 @@ +@_expose(wasm, "bjs_checkString") +@_cdecl("bjs_checkString") +public func _bjs_checkString(_ aBytes: Int32, _ aLength: Int32) -> Void { + #if arch(wasm32) + checkString(a: String.bridgeJSLiftParameter(aBytes, aLength)) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundtripString") +@_cdecl("bjs_roundtripString") +public func _bjs_roundtripString(_ aBytes: Int32, _ aLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundtripString(a: String.bridgeJSLiftParameter(aBytes, aLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkString") +@_extern(wasm, module: "TestModule", name: "bjs_checkString") fileprivate func bjs_checkString(_ a: Int32) -> Void #else fileprivate func bjs_checkString(_ a: Int32) -> Void { @@ -16,7 +37,7 @@ func _$checkString(_ a: String) throws(JSException) -> Void { } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkStringWithLength") +@_extern(wasm, module: "TestModule", name: "bjs_checkStringWithLength") fileprivate func bjs_checkStringWithLength(_ a: Int32, _ b: Float64) -> Void #else fileprivate func bjs_checkStringWithLength(_ a: Int32, _ b: Float64) -> Void { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.json new file mode 100644 index 000000000..3f9271592 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.json @@ -0,0 +1,59 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_checkString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "checkString", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "checkString", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.swift similarity index 53% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.swift index bde90ea74..9de24ef73 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.swift @@ -1,5 +1,16 @@ +@_expose(wasm, "bjs_checkString") +@_cdecl("bjs_checkString") +public func _bjs_checkString() -> Void { + #if arch(wasm32) + let ret = checkString() + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkString") +@_extern(wasm, module: "TestModule", name: "bjs_checkString") fileprivate func bjs_checkString() -> Int32 #else fileprivate func bjs_checkString() -> Int32 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.json new file mode 100644 index 000000000..9fe717651 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.json @@ -0,0 +1,145 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Greeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Greeter_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_Greeter_changeName", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "changeName", + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "Greeter", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "Greeter" + }, + { + "explicitAccessControl" : "public", + "methods" : [ + + ], + "name" : "PublicGreeter", + "properties" : [ + + ], + "swiftCallName" : "PublicGreeter" + }, + { + "explicitAccessControl" : "package", + "methods" : [ + + ], + "name" : "PackageGreeter", + "properties" : [ + + ], + "swiftCallName" : "PackageGreeter" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_takeGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeGreeter", + "parameters" : [ + { + "label" : "greeter", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json new file mode 100644 index 000000000..d71726828 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json @@ -0,0 +1,1087 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Person_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "explicitAccessControl" : "public", + "methods" : [ + + ], + "name" : "Person", + "properties" : [ + + ], + "swiftCallName" : "Person" + }, + { + "constructor" : { + "abiName" : "bjs_TestProcessor_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "transform", + "name" : "transform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSS_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_TestProcessor_getTransform", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getTransform", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSS_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_processWithCustom", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processWithCustom", + "parameters" : [ + { + "label" : "_", + "name" : "text", + "type" : { + "string" : { + + } + } + }, + { + "label" : "customTransform", + "name" : "customTransform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSS_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_printTogether", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "printTogether", + "parameters" : [ + { + "label" : "person", + "name" : "person", + "type" : { + "swiftHeapObject" : { + "_0" : "Person" + } + } + }, + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "label" : "ratio", + "name" : "ratio", + "type" : { + "double" : { + + } + } + }, + { + "label" : "customTransform", + "name" : "customTransform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq6PersonCSqSSSqSd_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Person" + } + }, + "_1" : "null" + } + }, + { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + }, + { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_roundtrip", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtrip", + "parameters" : [ + { + "label" : "_", + "name" : "personClosure", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule6PersonC_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "swiftHeapObject" : { + "_0" : "Person" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule6PersonC_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "swiftHeapObject" : { + "_0" : "Person" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_roundtripOptional", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripOptional", + "parameters" : [ + { + "label" : "_", + "name" : "personClosure", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq6PersonC_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Person" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq6PersonC_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Person" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_processDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processDirection", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule9DirectionO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "caseEnum" : { + "_0" : "Direction" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_processTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processTheme", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule5ThemeO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_processHttpStatus", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processHttpStatus", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule10HttpStatusO_Si", + "moduleName" : "TestModule", + "parameters" : [ + { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + ], + "returnType" : { + "int" : { + + } + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_processAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processAPIResult", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule9APIResultO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_makeDirectionChecker", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeDirectionChecker", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule9DirectionO_Sb", + "moduleName" : "TestModule", + "parameters" : [ + { + "caseEnum" : { + "_0" : "Direction" + } + } + ], + "returnType" : { + "bool" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_makeThemeValidator", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeThemeValidator", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule5ThemeO_Sb", + "moduleName" : "TestModule", + "parameters" : [ + { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + ], + "returnType" : { + "bool" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_makeStatusCodeExtractor", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeStatusCodeExtractor", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule10HttpStatusO_Si", + "moduleName" : "TestModule", + "parameters" : [ + { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } + ], + "returnType" : { + "int" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_makeAPIResultHandler", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeAPIResultHandler", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModule9APIResultO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_TestProcessor_processOptionalDirection", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalDirection", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq9DirectionO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_processOptionalTheme", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalTheme", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq5ThemeO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_processOptionalAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalAPIResult", + "parameters" : [ + { + "label" : "_", + "name" : "callback", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq9APIResultO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_TestProcessor_makeOptionalDirectionFormatter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeOptionalDirectionFormatter", + "parameters" : [ + + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSq9DirectionO_SS", + "moduleName" : "TestModule", + "parameters" : [ + { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "string" : { + + } + } + } + } + } + } + ], + "name" : "TestProcessor", + "properties" : [ + + ], + "swiftCallName" : "TestProcessor" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "Direction", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Direction", + "tsFullPath" : "Direction" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "light", + "rawValue" : "light" + }, + { + "associatedValues" : [ + + ], + "name" : "dark", + "rawValue" : "dark" + }, + { + "associatedValues" : [ + + ], + "name" : "auto", + "rawValue" : "auto" + } + ], + "emitStyle" : "const", + "name" : "Theme", + "rawType" : "String", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Theme", + "tsFullPath" : "Theme" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "ok", + "rawValue" : "200" + }, + { + "associatedValues" : [ + + ], + "name" : "notFound", + "rawValue" : "404" + }, + { + "associatedValues" : [ + + ], + "name" : "serverError", + "rawValue" : "500" + }, + { + "associatedValues" : [ + + ], + "name" : "unknown", + "rawValue" : "-1" + } + ], + "emitStyle" : "const", + "name" : "HttpStatus", + "rawType" : "Int", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "HttpStatus", + "tsFullPath" : "HttpStatus" + }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "string" : { + + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "int" : { + + } + } + } + ], + "name" : "failure" + }, + { + "associatedValues" : [ + { + "type" : { + "bool" : { + + } + } + } + ], + "name" : "flag" + }, + { + "associatedValues" : [ + { + "type" : { + "float" : { + + } + } + } + ], + "name" : "rate" + }, + { + "associatedValues" : [ + { + "type" : { + "double" : { + + } + } + } + ], + "name" : "precise" + }, + { + "associatedValues" : [ + + ], + "name" : "info" + } + ], + "emitStyle" : "const", + "name" : "APIResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIResult", + "tsFullPath" : "APIResult" + } + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift similarity index 97% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift index 415aa54f6..94351dbdf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift @@ -667,25 +667,25 @@ extension Direction: _BridgedSwiftCaseEnum { } } -extension Theme: _BridgedSwiftEnumNoPayload { +extension Theme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension HttpStatus: _BridgedSwiftEnumNoPayload { +extension HttpStatus: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension APIResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) case 2: - return .flag(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .flag(Bool.bridgeJSLiftParameter()) case 3: - return .rate(Float.bridgeJSLiftParameter(_swift_js_pop_f32())) + return .rate(Float.bridgeJSLiftParameter()) case 4: - return .precise(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + return .precise(Double.bridgeJSLiftParameter()) case 5: return .info default: @@ -698,22 +698,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) case .flag(let param0): - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() return Int32(2) case .rate(let param0): - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() return Int32(3) case .precise(let param0): - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() return Int32(4) case .info: return Int32(5) @@ -733,23 +730,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) case .flag(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) case .rate(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) case .precise(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) case .info: _swift_js_push_tag(Int32(5)) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json new file mode 100644 index 000000000..9e0e0a491 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json @@ -0,0 +1,92 @@ +{ + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "applyInt", + "parameters" : [ + { + "name" : "value", + "type" : { + "int" : { + + } + } + }, + { + "name" : "transform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSi_Si", + "moduleName" : "TestModule", + "parameters" : [ + { + "int" : { + + } + } + ], + "returnType" : { + "int" : { + + } + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "name" : "makeAdder", + "parameters" : [ + { + "name" : "base", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "10TestModuleSi_Si", + "moduleName" : "TestModule", + "parameters" : [ + { + "int" : { + + } + } + ], + "returnType" : { + "int" : { + + } + } + } + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftClosureImports.ImportMacros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift similarity index 62% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftClosureImports.ImportMacros.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift index 9e0959157..c833a54d1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftClosureImports.ImportMacros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.swift @@ -1,22 +1,22 @@ #if arch(wasm32) -@_extern(wasm, module: "bjs", name: "invoke_js_callback_Check_5CheckSi_Si") -fileprivate func invoke_js_callback_Check_5CheckSi_Si(_ callback: Int32, _ param0: Int32) -> Int32 +@_extern(wasm, module: "bjs", name: "invoke_js_callback_TestModule_10TestModuleSi_Si") +fileprivate func invoke_js_callback_TestModule_10TestModuleSi_Si(_ callback: Int32, _ param0: Int32) -> Int32 #else -fileprivate func invoke_js_callback_Check_5CheckSi_Si(_ callback: Int32, _ param0: Int32) -> Int32 { +fileprivate func invoke_js_callback_TestModule_10TestModuleSi_Si(_ callback: Int32, _ param0: Int32) -> Int32 { fatalError("Only available on WebAssembly") } #endif -private final class _BJS_ClosureBox_5CheckSi_Si: _BridgedSwiftClosureBox { +private final class _BJS_ClosureBox_10TestModuleSi_Si: _BridgedSwiftClosureBox { let closure: (Int) -> Int init(_ closure: @escaping (Int) -> Int) { self.closure = closure } } -private enum _BJS_Closure_5CheckSi_Si { +private enum _BJS_Closure_10TestModuleSi_Si { static func bridgeJSLower(_ closure: @escaping (Int) -> Int) -> UnsafeMutableRawPointer { - let box = _BJS_ClosureBox_5CheckSi_Si(closure) + let box = _BJS_ClosureBox_10TestModuleSi_Si(closure) return Unmanaged.passRetained(box).toOpaque() } static func bridgeJSLift(_ callbackId: Int32) -> (Int) -> Int { @@ -25,7 +25,7 @@ private enum _BJS_Closure_5CheckSi_Si { #if arch(wasm32) let callbackValue = callback.bridgeJSLowerParameter() let param0Value = param0.bridgeJSLowerParameter() - let ret = invoke_js_callback_Check_5CheckSi_Si(callbackValue, param0Value) + let ret = invoke_js_callback_TestModule_10TestModuleSi_Si(callbackValue, param0Value) return Int.bridgeJSLiftReturn(ret) #else fatalError("Only available on WebAssembly") @@ -34,11 +34,11 @@ private enum _BJS_Closure_5CheckSi_Si { } } -@_expose(wasm, "invoke_swift_closure_Check_5CheckSi_Si") -@_cdecl("invoke_swift_closure_Check_5CheckSi_Si") -public func _invoke_swift_closure_Check_5CheckSi_Si(_ boxPtr: UnsafeMutableRawPointer, _ param0: Int32) -> Int32 { +@_expose(wasm, "invoke_swift_closure_TestModule_10TestModuleSi_Si") +@_cdecl("invoke_swift_closure_TestModule_10TestModuleSi_Si") +public func _invoke_swift_closure_TestModule_10TestModuleSi_Si(_ boxPtr: UnsafeMutableRawPointer, _ param0: Int32) -> Int32 { #if arch(wasm32) - let box = Unmanaged<_BJS_ClosureBox_5CheckSi_Si>.fromOpaque(boxPtr).takeUnretainedValue() + let box = Unmanaged<_BJS_ClosureBox_10TestModuleSi_Si>.fromOpaque(boxPtr).takeUnretainedValue() let result = box.closure(Int.bridgeJSLiftParameter(param0)) return result.bridgeJSLowerReturn() #else @@ -47,7 +47,7 @@ public func _invoke_swift_closure_Check_5CheckSi_Si(_ boxPtr: UnsafeMutableRawPo } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_applyInt") +@_extern(wasm, module: "TestModule", name: "bjs_applyInt") fileprivate func bjs_applyInt(_ value: Int32, _ transform: UnsafeMutableRawPointer) -> Int32 #else fileprivate func bjs_applyInt(_ value: Int32, _ transform: UnsafeMutableRawPointer) -> Int32 { @@ -57,7 +57,7 @@ fileprivate func bjs_applyInt(_ value: Int32, _ transform: UnsafeMutableRawPoint func _$applyInt(_ value: Int, _ transform: @escaping (Int) -> Int) throws(JSException) -> Int { let valueValue = value.bridgeJSLowerParameter() - let transformPointer = _BJS_Closure_5CheckSi_Si.bridgeJSLower(transform) + let transformPointer = _BJS_Closure_10TestModuleSi_Si.bridgeJSLower(transform) let ret = bjs_applyInt(valueValue, transformPointer) if let error = _swift_js_take_exception() { throw error @@ -66,7 +66,7 @@ func _$applyInt(_ value: Int, _ transform: @escaping (Int) -> Int) throws(JSExce } #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_makeAdder") +@_extern(wasm, module: "TestModule", name: "bjs_makeAdder") fileprivate func bjs_makeAdder(_ base: Int32) -> Int32 #else fileprivate func bjs_makeAdder(_ base: Int32) -> Int32 { @@ -80,5 +80,5 @@ func _$makeAdder(_ base: Int) throws(JSException) -> (Int) -> Int { if let error = _swift_js_take_exception() { throw error } - return _BJS_Closure_5CheckSi_Si.bridgeJSLift(ret) + return _BJS_Closure_10TestModuleSi_Si.bridgeJSLift(ret) } \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json new file mode 100644 index 000000000..00c6af5cb --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json @@ -0,0 +1,589 @@ +{ + "exported" : { + "classes" : [ + { + "constructor" : { + "abiName" : "bjs_Greeter_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "name", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_Greeter_greet", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "Greeter", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "Greeter" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "rough", + "rawValue" : "0.1" + }, + { + "associatedValues" : [ + + ], + "name" : "fine", + "rawValue" : "0.001" + } + ], + "emitStyle" : "const", + "name" : "Precision", + "rawType" : "Float", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Precision", + "tsFullPath" : "Precision" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_roundtrip", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtrip", + "parameters" : [ + { + "label" : "_", + "name" : "session", + "type" : { + "swiftStruct" : { + "_0" : "Person" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Person" + } + } + }, + { + "abiName" : "bjs_roundtripContainer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundtripContainer", + "parameters" : [ + { + "label" : "_", + "name" : "container", + "type" : { + "swiftStruct" : { + "_0" : "Container" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Container" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "constructor" : { + "abiName" : "bjs_DataPoint_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "x", + "name" : "x", + "type" : { + "double" : { + + } + } + }, + { + "label" : "y", + "name" : "y", + "type" : { + "double" : { + + } + } + }, + { + "label" : "label", + "name" : "label", + "type" : { + "string" : { + + } + } + }, + { + "label" : "optCount", + "name" : "optCount", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "label" : "optFlag", + "name" : "optFlag", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "DataPoint", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "label", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optCount", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optFlag", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "DataPoint" + }, + { + "methods" : [ + + ], + "name" : "Address", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "street", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "city", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "zipCode", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Address" + }, + { + "methods" : [ + + ], + "name" : "Person", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "age", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "address", + "type" : { + "swiftStruct" : { + "_0" : "Address" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "email", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Person" + }, + { + "methods" : [ + + ], + "name" : "Session", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "id", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "owner", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + ], + "swiftCallName" : "Session" + }, + { + "methods" : [ + + ], + "name" : "Measurement", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "value", + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "precision", + "type" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalPrecision", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Measurement" + }, + { + "methods" : [ + { + "abiName" : "bjs_ConfigStruct_static_update", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "update", + "parameters" : [ + { + "label" : "_", + "name" : "timeout", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + }, + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + } + } + ], + "name" : "ConfigStruct", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : true, + "name" : "maxRetries", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + }, + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "defaultConfig", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + }, + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "isStatic" : true, + "name" : "timeout", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + }, + "type" : { + "double" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : true, + "name" : "computedSetting", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + }, + "type" : { + "string" : { + + } + } + } + ], + "swiftCallName" : "ConfigStruct" + }, + { + "methods" : [ + + ], + "name" : "Container", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "object", + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalObject", + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Container" + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift similarity index 79% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift index af4428979..ca2467249 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift @@ -1,31 +1,28 @@ -extension Precision: _BridgedSwiftEnumNoPayload { +extension Precision: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension DataPoint: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> DataPoint { - let optFlag = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let optCount = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let label = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let y = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let x = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let optFlag = Optional.bridgeJSLiftParameter() + let optCount = Optional.bridgeJSLiftParameter() + let label = String.bridgeJSLiftParameter() + let y = Double.bridgeJSLiftParameter() + let x = Double.bridgeJSLiftParameter() return DataPoint(x: x, y: y, label: label, optCount: optCount, optFlag: optFlag) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.x) - _swift_js_push_f64(self.y) - var __bjs_label = self.label - __bjs_label.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() + self.label.bridgeJSLowerStackReturn() let __bjs_isSome_optCount = self.optCount != nil if let __bjs_unwrapped_optCount = self.optCount { - _swift_js_push_i32(Int32(__bjs_unwrapped_optCount)) + __bjs_unwrapped_optCount.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optCount ? 1 : 0) let __bjs_isSome_optFlag = self.optFlag != nil if let __bjs_unwrapped_optFlag = self.optFlag { - _swift_js_push_i32(__bjs_unwrapped_optFlag ? 1 : 0) + __bjs_unwrapped_optFlag.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optFlag ? 1 : 0) } @@ -76,24 +73,18 @@ public func _bjs_DataPoint_init(_ x: Float64, _ y: Float64, _ labelBytes: Int32, extension Address: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Address { - let zipCode = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let city = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let street = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let zipCode = Optional.bridgeJSLiftParameter() + let city = String.bridgeJSLiftParameter() + let street = String.bridgeJSLiftParameter() return Address(street: street, city: city, zipCode: zipCode) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_street = self.street - __bjs_street.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_city = self.city - __bjs_city.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.street.bridgeJSLowerStackReturn() + self.city.bridgeJSLowerStackReturn() let __bjs_isSome_zipCode = self.zipCode != nil if let __bjs_unwrapped_zipCode = self.zipCode { - _swift_js_push_i32(Int32(__bjs_unwrapped_zipCode)) + __bjs_unwrapped_zipCode.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_zipCode ? 1 : 0) } @@ -133,26 +124,20 @@ fileprivate func _bjs_struct_lift_Address() -> Int32 { extension Person: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Person { - let email = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32()) + let email = Optional.bridgeJSLiftParameter() let address = Address.bridgeJSLiftParameter() - let age = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let age = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return Person(name: name, age: age, address: address, email: email) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.age)) + self.name.bridgeJSLowerStackReturn() + self.age.bridgeJSLowerStackReturn() self.address.bridgeJSLowerReturn() let __bjs_isSome_email = self.email != nil if let __bjs_unwrapped_email = self.email { - var __bjs_str_email = __bjs_unwrapped_email - __bjs_str_email.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_email.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_email ? 1 : 0) } @@ -192,14 +177,14 @@ fileprivate func _bjs_struct_lift_Person() -> Int32 { extension Session: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Session { - let owner = Greeter.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let owner = Greeter.bridgeJSLiftParameter() + let id = Int.bridgeJSLiftParameter() return Session(id: id, owner: owner) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) - _swift_js_push_pointer(self.owner.bridgeJSLowerReturn()) + self.id.bridgeJSLowerStackReturn() + self.owner.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -237,18 +222,18 @@ fileprivate func _bjs_struct_lift_Session() -> Int32 { extension Measurement: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Measurement { - let optionalPrecision = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f32()) + let optionalPrecision = Optional.bridgeJSLiftParameter() let precision = Precision.bridgeJSLiftParameter(_swift_js_pop_f32()) - let value = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let value = Double.bridgeJSLiftParameter() return Measurement(value: value, precision: precision, optionalPrecision: optionalPrecision) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.value) - _swift_js_push_f32(self.precision.bridgeJSLowerParameter()) + self.value.bridgeJSLowerStackReturn() + self.precision.bridgeJSLowerStackReturn() let __bjs_isSome_optionalPrecision = self.optionalPrecision != nil if let __bjs_unwrapped_optionalPrecision = self.optionalPrecision { - _swift_js_push_f32(__bjs_unwrapped_optionalPrecision.bridgeJSLowerParameter()) + __bjs_unwrapped_optionalPrecision.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optionalPrecision ? 1 : 0) } @@ -403,6 +388,55 @@ public func _bjs_ConfigStruct_static_update(_ timeout: Float64) -> Float64 { #endif } +extension Container: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Container { + let optionalObject = Optional.bridgeJSLiftParameter() + let object = JSObject.bridgeJSLiftParameter() + return Container(object: object, optionalObject: optionalObject) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.object.bridgeJSLowerStackReturn() + let __bjs_isSome_optionalObject = self.optionalObject != nil + if let __bjs_unwrapped_optionalObject = self.optionalObject { + __bjs_unwrapped_optionalObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_optionalObject ? 1 : 0) + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_Container(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Container())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Container") +fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_Container") +fileprivate func _bjs_struct_lift_Container() -> Int32 +#else +fileprivate func _bjs_struct_lift_Container() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + @_expose(wasm, "bjs_roundtrip") @_cdecl("bjs_roundtrip") public func _bjs_roundtrip() -> Void { @@ -414,6 +448,17 @@ public func _bjs_roundtrip() -> Void { #endif } +@_expose(wasm, "bjs_roundtripContainer") +@_cdecl("bjs_roundtripContainer") +public func _bjs_roundtripContainer() -> Void { + #if arch(wasm32) + let ret = roundtripContainer(_: Container.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_Greeter_init") @_cdecl("bjs_Greeter_init") public func _bjs_Greeter_init(_ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.json new file mode 100644 index 000000000..50af441a9 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.json @@ -0,0 +1,94 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "Point", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "int" : { + + } + } + } + ], + "swiftCallName" : "Point" + } + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "translate", + "parameters" : [ + { + "name" : "point", + "type" : { + "swiftStruct" : { + "_0" : "Point" + } + } + }, + { + "name" : "dx", + "type" : { + "int" : { + + } + } + }, + { + "name" : "dy", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Point" + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift new file mode 100644 index 000000000..187f3369a --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift @@ -0,0 +1,64 @@ +extension Point: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { + let y = Int.bridgeJSLiftParameter() + let x = Int.bridgeJSLiftParameter() + return Point(x: x, y: y) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Point())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_Point") +fileprivate func _bjs_struct_lift_Point() -> Int32 +#else +fileprivate func _bjs_struct_lift_Point() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_translate") +fileprivate func bjs_translate(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 +#else +fileprivate func bjs_translate(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$translate(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException) -> Point { + let pointObjectId = point.bridgeJSLowerParameter() + let dxValue = dx.bridgeJSLowerParameter() + let dyValue = dy.bridgeJSLowerParameter() + let ret = bjs_translate(pointObjectId, dxValue, dyValue) + if let error = _swift_js_take_exception() { + throw error + } + return Point.bridgeJSLiftReturn(ret) +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.json new file mode 100644 index 000000000..02796479f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.json @@ -0,0 +1,37 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_throwsSomething", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "throwsSomething", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.swift diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.json new file mode 100644 index 000000000..1eb9e47ec --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.json @@ -0,0 +1,416 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_takeUnsafeRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeUnsafeRawPointer", + "parameters" : [ + { + "label" : "_", + "name" : "p", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_takeUnsafeMutableRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeUnsafeMutableRawPointer", + "parameters" : [ + { + "label" : "_", + "name" : "p", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_takeOpaquePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeOpaquePointer", + "parameters" : [ + { + "label" : "_", + "name" : "p", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_takeUnsafePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeUnsafePointer", + "parameters" : [ + { + "label" : "_", + "name" : "p", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_takeUnsafeMutablePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "takeUnsafeMutablePointer", + "parameters" : [ + { + "label" : "_", + "name" : "p", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_returnUnsafeRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "returnUnsafeRawPointer", + "parameters" : [ + + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + }, + { + "abiName" : "bjs_returnUnsafeMutableRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "returnUnsafeMutableRawPointer", + "parameters" : [ + + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "abiName" : "bjs_returnOpaquePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "returnOpaquePointer", + "parameters" : [ + + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + }, + { + "abiName" : "bjs_returnUnsafePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "returnUnsafePointer", + "parameters" : [ + + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "abiName" : "bjs_returnUnsafeMutablePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "returnUnsafeMutablePointer", + "parameters" : [ + + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "abiName" : "bjs_roundTripPointerFields", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripPointerFields", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "swiftStruct" : { + "_0" : "PointerFields" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "PointerFields" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + { + "constructor" : { + "abiName" : "bjs_PointerFields_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "raw", + "name" : "raw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + }, + { + "label" : "mutRaw", + "name" : "mutRaw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "label" : "opaque", + "name" : "opaque", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + }, + { + "label" : "ptr", + "name" : "ptr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "label" : "mutPtr", + "name" : "mutPtr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "PointerFields", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "raw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "mutRaw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "opaque", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "ptr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "mutPtr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + ], + "swiftCallName" : "PointerFields" + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift similarity index 90% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift index 4c368908b..752cc6bc3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift @@ -1,19 +1,19 @@ extension PointerFields: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> PointerFields { - let mutPtr = UnsafeMutablePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let ptr = UnsafePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let opaque = OpaquePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let mutRaw = UnsafeMutableRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let raw = UnsafeRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) + let mutPtr = UnsafeMutablePointer.bridgeJSLiftParameter() + let ptr = UnsafePointer.bridgeJSLiftParameter() + let opaque = OpaquePointer.bridgeJSLiftParameter() + let mutRaw = UnsafeMutableRawPointer.bridgeJSLiftParameter() + let raw = UnsafeRawPointer.bridgeJSLiftParameter() return PointerFields(raw: raw, mutRaw: mutRaw, opaque: opaque, ptr: ptr, mutPtr: mutPtr) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_pointer(self.raw.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.mutRaw.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.opaque.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.ptr.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.mutPtr.bridgeJSLowerReturn()) + self.raw.bridgeJSLowerStackReturn() + self.mutRaw.bridgeJSLowerStackReturn() + self.opaque.bridgeJSLowerStackReturn() + self.ptr.bridgeJSLowerStackReturn() + self.mutPtr.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.json new file mode 100644 index 000000000..14da32841 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.json @@ -0,0 +1,59 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_check", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "check", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "check", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.swift similarity index 54% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.swift index 2a2622ce0..3fa9619f8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.swift @@ -1,5 +1,15 @@ +@_expose(wasm, "bjs_check") +@_cdecl("bjs_check") +public func _bjs_check() -> Void { + #if arch(wasm32) + check() + #else + fatalError("Only available on WebAssembly") + #endif +} + #if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_check") +@_extern(wasm, module: "TestModule", name: "bjs_check") fileprivate func bjs_check() -> Void #else fileprivate func bjs_check() -> Void { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.d.ts deleted file mode 100644 index 2a6771ca7..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { -} -export type Imports = { - checkArray(a: any): void; - checkArrayWithLength(a: any, b: number): void; - checkArray(a: any): void; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.js deleted file mode 100644 index 8add18b9f..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.js +++ /dev/null @@ -1,245 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_checkArray"] = function bjs_checkArray(a) { - try { - imports.checkArray(swift.memory.getObject(a)); - } catch (error) { - setException(error); - } - } - TestModule["bjs_checkArrayWithLength"] = function bjs_checkArrayWithLength(a, b) { - try { - imports.checkArrayWithLength(swift.memory.getObject(a), b); - } catch (error) { - setException(error); - } - } - TestModule["bjs_checkArray"] = function bjs_checkArray(a) { - try { - imports.checkArray(swift.memory.getObject(a)); - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts similarity index 84% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts index 988626f3e..8dc76156b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts @@ -62,10 +62,20 @@ export type Exports = { processNestedPointArray(points: Point[][]): Point[][]; processItemArray(items: Item[]): Item[]; processNestedItemArray(items: Item[][]): Item[][]; + processJSObjectArray(objects: any[]): any[]; + processOptionalJSObjectArray(objects: (any | null)[]): (any | null)[]; + processNestedJSObjectArray(objects: any[][]): any[][]; Direction: DirectionObject Status: StatusObject } export type Imports = { + checkArray(a: any): void; + checkArrayWithLength(a: any, b: number): void; + importProcessNumbers(values: number[]): void; + importGetNumbers(): number[]; + importTransformNumbers(values: number[]): number[]; + importProcessStrings(values: string[]): string[]; + importProcessBooleans(values: boolean[]): boolean[]; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js similarity index 79% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 7388f4150..6cca17cf6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -44,7 +44,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createPointHelpers = () => { @@ -69,6 +69,7 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); bjs["swift_js_return_string"] = function(ptr, len) { const bytes = new Uint8Array(memory.buffer, ptr, len); tmpRetString = textDecoder.decode(bytes); @@ -97,7 +98,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -247,6 +248,110 @@ export async function createInstantiator(options, swift) { const obj = Item.__construct(pointer); return swift.memory.retain(obj); }; + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_checkArray"] = function bjs_checkArray(a) { + try { + imports.checkArray(swift.memory.getObject(a)); + } catch (error) { + setException(error); + } + } + TestModule["bjs_checkArrayWithLength"] = function bjs_checkArrayWithLength(a, b) { + try { + imports.checkArrayWithLength(swift.memory.getObject(a), b); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importProcessNumbers"] = function bjs_importProcessNumbers() { + try { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const f64 = tmpRetF64s.pop(); + arrayResult.push(f64); + } + arrayResult.reverse(); + imports.importProcessNumbers(arrayResult); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importGetNumbers"] = function bjs_importGetNumbers() { + try { + let ret = imports.importGetNumbers(); + const arrayCleanups = []; + for (const elem of ret) { + tmpParamF64s.push(elem); + } + tmpParamInts.push(ret.length); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importTransformNumbers"] = function bjs_importTransformNumbers() { + try { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const f64 = tmpRetF64s.pop(); + arrayResult.push(f64); + } + arrayResult.reverse(); + let ret = imports.importTransformNumbers(arrayResult); + const arrayCleanups = []; + for (const elem of ret) { + tmpParamF64s.push(elem); + } + tmpParamInts.push(ret.length); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importProcessStrings"] = function bjs_importProcessStrings() { + try { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const string = tmpRetStrings.pop(); + arrayResult.push(string); + } + arrayResult.reverse(); + let ret = imports.importProcessStrings(arrayResult); + const arrayCleanups = []; + for (const elem of ret) { + const bytes = textEncoder.encode(elem); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + } + tmpParamInts.push(ret.length); + } catch (error) { + setException(error); + } + } + TestModule["bjs_importProcessBooleans"] = function bjs_importProcessBooleans() { + try { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const bool = tmpRetInts.pop() !== 0; + arrayResult.push(bool); + } + arrayResult.reverse(); + let ret = imports.importProcessBooleans(arrayResult); + const arrayCleanups = []; + for (const elem of ret) { + tmpParamInts.push(elem ? 1 : 0); + } + tmpParamInts.push(ret.length); + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { instance = i; @@ -272,7 +377,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -282,11 +387,11 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Item_deinit, Item.prototype); } - + } const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Point = PointHelpers; - + const exports = { Item, processIntArray: function bjs_processIntArray(values) { @@ -366,9 +471,9 @@ export async function createInstantiator(options, swift) { processPointArray: function bjs_processPointArray(points) { const arrayCleanups = []; for (const elem of points) { - const { cleanup: cleanup } = structHelpers.Point.lower(elem); + const { cleanup: structCleanup } = structHelpers.Point.lower(elem); arrayCleanups.push(() => { - if (cleanup) { cleanup(); } + if (structCleanup) { structCleanup(); } }); } tmpParamInts.push(points.length); @@ -430,9 +535,9 @@ export async function createInstantiator(options, swift) { findFirstPoint: function bjs_findFirstPoint(points, matching) { const arrayCleanups = []; for (const elem of points) { - const { cleanup: cleanup } = structHelpers.Point.lower(elem); + const { cleanup: structCleanup } = structHelpers.Point.lower(elem); arrayCleanups.push(() => { - if (cleanup) { cleanup(); } + if (structCleanup) { structCleanup(); } }); } tmpParamInts.push(points.length); @@ -594,8 +699,8 @@ export async function createInstantiator(options, swift) { for (const elem of points) { const isSome = elem != null ? 1 : 0; if (isSome) { - const { cleanup: cleanup } = structHelpers.Point.lower(elem); - arrayCleanups.push(() => { if (cleanup) { cleanup(); } }); + const { cleanup: structCleanup } = structHelpers.Point.lower(elem); + arrayCleanups.push(() => { if (structCleanup) { structCleanup(); } }); } else { } tmpParamInts.push(isSome); @@ -750,9 +855,9 @@ export async function createInstantiator(options, swift) { for (const elem of points) { const arrayCleanups1 = []; for (const elem1 of elem) { - const { cleanup: cleanup } = structHelpers.Point.lower(elem1); + const { cleanup: structCleanup } = structHelpers.Point.lower(elem1); arrayCleanups1.push(() => { - if (cleanup) { cleanup(); } + if (structCleanup) { structCleanup(); } }); } tmpParamInts.push(elem.length); @@ -789,7 +894,7 @@ export async function createInstantiator(options, swift) { const arrayResult = []; for (let i = 0; i < arrayLen; i++) { const ptr = tmpRetPointers.pop(); - const obj = Item.__construct(ptr); + const obj = _exports['Item'].__construct(ptr); arrayResult.push(obj); } arrayResult.reverse(); @@ -817,7 +922,93 @@ export async function createInstantiator(options, swift) { const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { const ptr = tmpRetPointers.pop(); - const obj = Item.__construct(ptr); + const obj = _exports['Item'].__construct(ptr); + arrayResult1.push(obj); + } + arrayResult1.reverse(); + arrayResult.push(arrayResult1); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + processJSObjectArray: function bjs_processJSObjectArray(objects) { + const arrayCleanups = []; + for (const elem of objects) { + const objId = swift.memory.retain(elem); + tmpParamInts.push(objId); + } + tmpParamInts.push(objects.length); + instance.exports.bjs_processJSObjectArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const objId1 = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId1); + swift.memory.release(objId1); + arrayResult.push(obj); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + processOptionalJSObjectArray: function bjs_processOptionalJSObjectArray(objects) { + const arrayCleanups = []; + for (const elem of objects) { + const isSome = elem != null ? 1 : 0; + if (isSome) { + const objId = swift.memory.retain(elem); + tmpParamInts.push(objId); + } else { + tmpParamInts.push(0); + } + tmpParamInts.push(isSome); + } + tmpParamInts.push(objects.length); + instance.exports.bjs_processOptionalJSObjectArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const isSome1 = tmpRetInts.pop(); + let optValue; + if (isSome1 === 0) { + optValue = null; + } else { + const objId1 = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId1); + swift.memory.release(objId1); + optValue = obj; + } + arrayResult.push(optValue); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + processNestedJSObjectArray: function bjs_processNestedJSObjectArray(objects) { + const arrayCleanups = []; + for (const elem of objects) { + const arrayCleanups1 = []; + for (const elem1 of elem) { + const objId = swift.memory.retain(elem1); + tmpParamInts.push(objId); + } + tmpParamInts.push(elem.length); + arrayCleanups.push(() => { + for (const cleanup of arrayCleanups1) { cleanup(); } + }); + } + tmpParamInts.push(objects.length); + instance.exports.bjs_processNestedJSObjectArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const arrayLen1 = tmpRetInts.pop(); + const arrayResult1 = []; + for (let i1 = 0; i1 < arrayLen1; i1++) { + const objId1 = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId1); + swift.memory.release(objId1); arrayResult1.push(obj); } arrayResult1.reverse(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.d.ts deleted file mode 100644 index dea0bd186..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { -} -export type Imports = { - asyncReturnVoid(): JSPromise; - asyncRoundTripInt(v: number): JSPromise; - asyncRoundTripString(v: string): JSPromise; - asyncRoundTripBool(v: boolean): JSPromise; - asyncRoundTripFloat(v: number): JSPromise; - asyncRoundTripDouble(v: number): JSPromise; - asyncRoundTripJSObject(v: any): JSPromise; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 4015b6261..0aa9148c1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 978272568..754c47b0a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -24,7 +24,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -37,7 +37,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createConfigHelpers = () => { @@ -123,7 +123,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -317,7 +317,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -327,7 +327,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_DefaultGreeter_deinit, DefaultGreeter.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -352,7 +352,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_EmptyGreeter_deinit, EmptyGreeter.prototype); } - + constructor() { const ret = instance.exports.bjs_EmptyGreeter_init(); return EmptyGreeter.__construct(ret); @@ -362,7 +362,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_ConstructorDefaults_deinit, ConstructorDefaults.prototype); } - + constructor(name = "Default", count = 42, enabled = true, status = StatusValues.Active, tag = null) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -433,10 +433,10 @@ export async function createInstantiator(options, swift) { } const ConfigHelpers = __bjs_createConfigHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Config = ConfigHelpers; - + const MathOperationsHelpers = __bjs_createMathOperationsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.MathOperations = MathOperationsHelpers; - + const exports = { DefaultGreeter, EmptyGreeter, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js deleted file mode 100644 index 2d8dbc0ca..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js +++ /dev/null @@ -1,877 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export const APIResultValues = { - Tag: { - Success: 0, - Failure: 1, - Flag: 2, - Rate: 3, - Precise: 4, - Info: 5, - }, -}; - -const __bjs_createAPIResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case APIResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: APIResultValues.Tag.Success, cleanup }; - } - case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; - } - case APIResultValues.Tag.Flag: { - tmpParamInts.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Flag, cleanup }; - } - case APIResultValues.Tag.Rate: { - tmpParamF32s.push(Math.fround(value.param0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Rate, cleanup }; - } - case APIResultValues.Tag.Precise: { - tmpParamF64s.push(value.param0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Precise, cleanup }; - } - case APIResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Info, cleanup }; - } - default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: APIResultValues.Tag.Success, param0: string }; - } - case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Failure, param0: int }; - } - case APIResultValues.Tag.Flag: { - const bool = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Flag, param0: bool }; - } - case APIResultValues.Tag.Rate: { - const f32 = tmpRetF32s.pop(); - return { tag: APIResultValues.Tag.Rate, param0: f32 }; - } - case APIResultValues.Tag.Precise: { - const f64 = tmpRetF64s.pop(); - return { tag: APIResultValues.Tag.Precise, param0: f64 }; - } - case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; - default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; -export const ComplexResultValues = { - Tag: { - Success: 0, - Error: 1, - Status: 2, - Coordinates: 3, - Comprehensive: 4, - Info: 5, - }, -}; - -const __bjs_createComplexResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case ComplexResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ComplexResultValues.Tag.Success, cleanup }; - } - case ComplexResultValues.Tag.Error: { - tmpParamInts.push((value.param1 | 0)); - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ComplexResultValues.Tag.Error, cleanup }; - } - case ComplexResultValues.Tag.Status: { - const bytes = textEncoder.encode(value.param2); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - tmpParamInts.push((value.param1 | 0)); - tmpParamInts.push(value.param0 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ComplexResultValues.Tag.Status, cleanup }; - } - case ComplexResultValues.Tag.Coordinates: { - tmpParamF64s.push(value.param2); - tmpParamF64s.push(value.param1); - tmpParamF64s.push(value.param0); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Coordinates, cleanup }; - } - case ComplexResultValues.Tag.Comprehensive: { - const bytes = textEncoder.encode(value.param8); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const bytes1 = textEncoder.encode(value.param7); - const id1 = swift.memory.retain(bytes1); - tmpParamInts.push(bytes1.length); - tmpParamInts.push(id1); - const bytes2 = textEncoder.encode(value.param6); - const id2 = swift.memory.retain(bytes2); - tmpParamInts.push(bytes2.length); - tmpParamInts.push(id2); - tmpParamF64s.push(value.param5); - tmpParamF64s.push(value.param4); - tmpParamInts.push((value.param3 | 0)); - tmpParamInts.push((value.param2 | 0)); - tmpParamInts.push(value.param1 ? 1 : 0); - tmpParamInts.push(value.param0 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - swift.memory.release(id1); - swift.memory.release(id2); - }; - return { caseId: ComplexResultValues.Tag.Comprehensive, cleanup }; - } - case ComplexResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Info, cleanup }; - } - default: throw new Error("Unknown ComplexResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case ComplexResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: ComplexResultValues.Tag.Success, param0: string }; - } - case ComplexResultValues.Tag.Error: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); - return { tag: ComplexResultValues.Tag.Error, param0: string, param1: int }; - } - case ComplexResultValues.Tag.Status: { - const string = tmpRetStrings.pop(); - const int = tmpRetInts.pop(); - const bool = tmpRetInts.pop(); - return { tag: ComplexResultValues.Tag.Status, param0: bool, param1: int, param2: string }; - } - case ComplexResultValues.Tag.Coordinates: { - const f64 = tmpRetF64s.pop(); - const f641 = tmpRetF64s.pop(); - const f642 = tmpRetF64s.pop(); - return { tag: ComplexResultValues.Tag.Coordinates, param0: f642, param1: f641, param2: f64 }; - } - case ComplexResultValues.Tag.Comprehensive: { - const string = tmpRetStrings.pop(); - const string1 = tmpRetStrings.pop(); - const string2 = tmpRetStrings.pop(); - const f64 = tmpRetF64s.pop(); - const f641 = tmpRetF64s.pop(); - const int = tmpRetInts.pop(); - const int1 = tmpRetInts.pop(); - const bool = tmpRetInts.pop(); - const bool1 = tmpRetInts.pop(); - return { tag: ComplexResultValues.Tag.Comprehensive, param0: bool1, param1: bool, param2: int1, param3: int, param4: f641, param5: f64, param6: string2, param7: string1, param8: string }; - } - case ComplexResultValues.Tag.Info: return { tag: ComplexResultValues.Tag.Info }; - default: throw new Error("Unknown ComplexResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; -export const ResultValues = { - Tag: { - Success: 0, - Failure: 1, - Status: 2, - }, -}; - -const __bjs_createResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case ResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ResultValues.Tag.Success, cleanup }; - } - case ResultValues.Tag.Failure: { - tmpParamInts.push((value.param1 | 0)); - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ResultValues.Tag.Failure, cleanup }; - } - case ResultValues.Tag.Status: { - const bytes = textEncoder.encode(value.param2); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - tmpParamInts.push((value.param1 | 0)); - tmpParamInts.push(value.param0 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ResultValues.Tag.Status, cleanup }; - } - default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case ResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: ResultValues.Tag.Success, param0: string }; - } - case ResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); - return { tag: ResultValues.Tag.Failure, param0: string, param1: int }; - } - case ResultValues.Tag.Status: { - const string = tmpRetStrings.pop(); - const int = tmpRetInts.pop(); - const bool = tmpRetInts.pop(); - return { tag: ResultValues.Tag.Status, param0: bool, param1: int, param2: string }; - } - default: throw new Error("Unknown ResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; -export const NetworkingResultValues = { - Tag: { - Success: 0, - Failure: 1, - }, -}; - -const __bjs_createNetworkingResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case NetworkingResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: NetworkingResultValues.Tag.Success, cleanup }; - } - case NetworkingResultValues.Tag.Failure: { - tmpParamInts.push((value.param1 | 0)); - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: NetworkingResultValues.Tag.Failure, cleanup }; - } - default: throw new Error("Unknown NetworkingResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case NetworkingResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: NetworkingResultValues.Tag.Success, param0: string }; - } - case NetworkingResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); - return { tag: NetworkingResultValues.Tag.Failure, param0: string, param1: int }; - } - default: throw new Error("Unknown NetworkingResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; -export const APIOptionalResultValues = { - Tag: { - Success: 0, - Failure: 1, - Status: 2, - }, -}; - -const __bjs_createAPIOptionalResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case APIOptionalResultValues.Tag.Success: { - const isSome = value.param0 != null; - let id; - if (isSome) { - let bytes = textEncoder.encode(value.param0); - id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - } else { - tmpParamInts.push(0); - tmpParamInts.push(0); - } - tmpParamInts.push(isSome ? 1 : 0); - const cleanup = () => { - if(id) { - swift.memory.release(id); - } - }; - return { caseId: APIOptionalResultValues.Tag.Success, cleanup }; - } - case APIOptionalResultValues.Tag.Failure: { - const isSome = value.param1 != null; - tmpParamInts.push(isSome ? (value.param1 ? 1 : 0) : 0); - tmpParamInts.push(isSome ? 1 : 0); - const isSome1 = value.param0 != null; - tmpParamInts.push(isSome1 ? (value.param0 | 0) : 0); - tmpParamInts.push(isSome1 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIOptionalResultValues.Tag.Failure, cleanup }; - } - case APIOptionalResultValues.Tag.Status: { - const isSome = value.param2 != null; - let id; - if (isSome) { - let bytes = textEncoder.encode(value.param2); - id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - } else { - tmpParamInts.push(0); - tmpParamInts.push(0); - } - tmpParamInts.push(isSome ? 1 : 0); - const isSome1 = value.param1 != null; - tmpParamInts.push(isSome1 ? (value.param1 | 0) : 0); - tmpParamInts.push(isSome1 ? 1 : 0); - const isSome2 = value.param0 != null; - tmpParamInts.push(isSome2 ? (value.param0 ? 1 : 0) : 0); - tmpParamInts.push(isSome2 ? 1 : 0); - const cleanup = () => { - if(id) { - swift.memory.release(id); - } - }; - return { caseId: APIOptionalResultValues.Tag.Status, cleanup }; - } - default: throw new Error("Unknown APIOptionalResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case APIOptionalResultValues.Tag.Success: { - const isSome = tmpRetInts.pop(); - let optional; - if (isSome) { - const string = tmpRetStrings.pop(); - optional = string; - } else { - optional = null; - } - return { tag: APIOptionalResultValues.Tag.Success, param0: optional }; - } - case APIOptionalResultValues.Tag.Failure: { - const isSome = tmpRetInts.pop(); - let optional; - if (isSome) { - const bool = tmpRetInts.pop(); - optional = bool; - } else { - optional = null; - } - const isSome1 = tmpRetInts.pop(); - let optional1; - if (isSome1) { - const int = tmpRetInts.pop(); - optional1 = int; - } else { - optional1 = null; - } - return { tag: APIOptionalResultValues.Tag.Failure, param0: optional1, param1: optional }; - } - case APIOptionalResultValues.Tag.Status: { - const isSome = tmpRetInts.pop(); - let optional; - if (isSome) { - const string = tmpRetStrings.pop(); - optional = string; - } else { - optional = null; - } - const isSome1 = tmpRetInts.pop(); - let optional1; - if (isSome1) { - const int = tmpRetInts.pop(); - optional1 = int; - } else { - optional1 = null; - } - const isSome2 = tmpRetInts.pop(); - let optional2; - if (isSome2) { - const bool = tmpRetInts.pop(); - optional2 = bool; - } else { - optional2 = null; - } - return { tag: APIOptionalResultValues.Tag.Status, param0: optional2, param1: optional1, param2: optional }; - } - default: throw new Error("Unknown APIOptionalResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.APIResult = APIResultHelpers; - - const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.ComplexResult = ComplexResultHelpers; - - const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.Result = ResultHelpers; - - const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.NetworkingResult = NetworkingResultHelpers; - - const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.APIOptionalResult = APIOptionalResultHelpers; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - handle: function bjs_handle(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); - instance.exports.bjs_handle(resultCaseId); - if (resultCleanup) { resultCleanup(); } - }, - getResult: function bjs_getResult() { - instance.exports.bjs_getResult(); - const ret = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - return ret; - }, - roundtripAPIResult: function bjs_roundtripAPIResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); - instance.exports.bjs_roundtripAPIResult(resultCaseId); - const ret = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - if (resultCleanup) { resultCleanup(); } - return ret; - }, - roundTripOptionalAPIResult: function bjs_roundTripOptionalAPIResult(result) { - const isSome = result != null; - let resultCaseId, resultCleanup; - if (isSome) { - const enumResult = enumHelpers.APIResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; - } - instance.exports.bjs_roundTripOptionalAPIResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (resultCleanup) { resultCleanup(); } - return optResult; - }, - handleComplex: function bjs_handleComplex(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); - instance.exports.bjs_handleComplex(resultCaseId); - if (resultCleanup) { resultCleanup(); } - }, - getComplexResult: function bjs_getComplexResult() { - instance.exports.bjs_getComplexResult(); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - return ret; - }, - roundtripComplexResult: function bjs_roundtripComplexResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); - instance.exports.bjs_roundtripComplexResult(resultCaseId); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - if (resultCleanup) { resultCleanup(); } - return ret; - }, - roundTripOptionalComplexResult: function bjs_roundTripOptionalComplexResult(result) { - const isSome = result != null; - let resultCaseId, resultCleanup; - if (isSome) { - const enumResult = enumHelpers.ComplexResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; - } - instance.exports.bjs_roundTripOptionalComplexResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.ComplexResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (resultCleanup) { resultCleanup(); } - return optResult; - }, - roundTripOptionalUtilitiesResult: function bjs_roundTripOptionalUtilitiesResult(result) { - const isSome = result != null; - let resultCaseId, resultCleanup; - if (isSome) { - const enumResult = enumHelpers.Result.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; - } - instance.exports.bjs_roundTripOptionalUtilitiesResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.Result.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (resultCleanup) { resultCleanup(); } - return optResult; - }, - roundTripOptionalNetworkingResult: function bjs_roundTripOptionalNetworkingResult(result) { - const isSome = result != null; - let resultCaseId, resultCleanup; - if (isSome) { - const enumResult = enumHelpers.NetworkingResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; - } - instance.exports.bjs_roundTripOptionalNetworkingResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.NetworkingResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (resultCleanup) { resultCleanup(); } - return optResult; - }, - roundTripOptionalAPIOptionalResult: function bjs_roundTripOptionalAPIOptionalResult(result) { - const isSome = result != null; - let resultCaseId, resultCleanup; - if (isSome) { - const enumResult = enumHelpers.APIOptionalResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; - } - instance.exports.bjs_roundTripOptionalAPIOptionalResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.APIOptionalResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (resultCleanup) { resultCleanup(); } - return optResult; - }, - compareAPIResults: function bjs_compareAPIResults(result1, result2) { - const isSome = result1 != null; - let result1CaseId, result1Cleanup; - if (isSome) { - const enumResult = enumHelpers.APIOptionalResult.lower(result1); - result1CaseId = enumResult.caseId; - result1Cleanup = enumResult.cleanup; - } - const isSome1 = result2 != null; - let result2CaseId, result2Cleanup; - if (isSome1) { - const enumResult1 = enumHelpers.APIOptionalResult.lower(result2); - result2CaseId = enumResult1.caseId; - result2Cleanup = enumResult1.cleanup; - } - instance.exports.bjs_compareAPIResults(+isSome, isSome ? result1CaseId : 0, +isSome1, isSome1 ? result2CaseId : 0); - const isNull = (tmpRetTag === -1); - let optResult; - if (isNull) { - optResult = null; - } else { - optResult = enumHelpers.APIOptionalResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); - } - if (result1Cleanup) { result1Cleanup(); } - if (result2Cleanup) { result2Cleanup(); } - return optResult; - }, - APIResult: APIResultValues, - ComplexResult: ComplexResultValues, - APIOptionalResult: APIOptionalResultValues, - API: { - NetworkingResult: NetworkingResultValues, - }, - Utilities: { - Result: ResultValues, - }, - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts similarity index 53% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts index 20962c388..9ab117011 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts @@ -43,6 +43,65 @@ export const APIOptionalResultValues: { export type APIOptionalResultTag = { tag: typeof APIOptionalResultValues.Tag.Success; param0: string | null } | { tag: typeof APIOptionalResultValues.Tag.Failure; param0: number | null; param1: boolean | null } | { tag: typeof APIOptionalResultValues.Tag.Status; param0: boolean | null; param1: number | null; param2: string | null } +export const PrecisionValues: { + readonly Rough: 0.1; + readonly Fine: 0.001; +}; +export type PrecisionTag = typeof PrecisionValues[keyof typeof PrecisionValues]; + +export const CardinalDirectionValues: { + readonly North: 0; + readonly South: 1; + readonly East: 2; + readonly West: 3; +}; +export type CardinalDirectionTag = typeof CardinalDirectionValues[keyof typeof CardinalDirectionValues]; + +export const TypedPayloadResultValues: { + readonly Tag: { + readonly Precision: 0; + readonly Direction: 1; + readonly OptPrecision: 2; + readonly OptDirection: 3; + readonly Empty: 4; + }; +}; + +export type TypedPayloadResultTag = + { tag: typeof TypedPayloadResultValues.Tag.Precision; param0: PrecisionTag } | { tag: typeof TypedPayloadResultValues.Tag.Direction; param0: CardinalDirectionTag } | { tag: typeof TypedPayloadResultValues.Tag.OptPrecision; param0: PrecisionTag | null } | { tag: typeof TypedPayloadResultValues.Tag.OptDirection; param0: CardinalDirectionTag | null } | { tag: typeof TypedPayloadResultValues.Tag.Empty } + +export const AllTypesResultValues: { + readonly Tag: { + readonly StructPayload: 0; + readonly ClassPayload: 1; + readonly JsObjectPayload: 2; + readonly NestedEnum: 3; + readonly ArrayPayload: 4; + readonly Empty: 5; + }; +}; + +export type AllTypesResultTag = + { tag: typeof AllTypesResultValues.Tag.StructPayload; param0: PointTag } | { tag: typeof AllTypesResultValues.Tag.ClassPayload; param0: User } | { tag: typeof AllTypesResultValues.Tag.JsObjectPayload; param0: any } | { tag: typeof AllTypesResultValues.Tag.NestedEnum; param0: APIResultTag } | { tag: typeof AllTypesResultValues.Tag.ArrayPayload; param0: number[] } | { tag: typeof AllTypesResultValues.Tag.Empty } + +export const OptionalAllTypesResultValues: { + readonly Tag: { + readonly OptStruct: 0; + readonly OptClass: 1; + readonly OptJSObject: 2; + readonly OptNestedEnum: 3; + readonly OptArray: 4; + readonly Empty: 5; + }; +}; + +export type OptionalAllTypesResultTag = + { tag: typeof OptionalAllTypesResultValues.Tag.OptStruct; param0: PointTag | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptClass; param0: User | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptJSObject; param0: any | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptNestedEnum; param0: APIResultTag | null } | { tag: typeof OptionalAllTypesResultValues.Tag.OptArray; param0: number[] | null } | { tag: typeof OptionalAllTypesResultValues.Tag.Empty } + +export interface Point { + x: number; + y: number; +} export type APIResultObject = typeof APIResultValues; export type ComplexResultObject = typeof ComplexResultValues; @@ -53,6 +112,16 @@ export type NetworkingResultObject = typeof API.NetworkingResultValues; export type APIOptionalResultObject = typeof APIOptionalResultValues; +export type PrecisionObject = typeof PrecisionValues; + +export type CardinalDirectionObject = typeof CardinalDirectionValues; + +export type TypedPayloadResultObject = typeof TypedPayloadResultValues; + +export type AllTypesResultObject = typeof AllTypesResultValues; + +export type OptionalAllTypesResultObject = typeof OptionalAllTypesResultValues; + export namespace API { const NetworkingResultValues: { readonly Tag: { @@ -74,7 +143,18 @@ export namespace Utilities { type ResultTag = { tag: typeof ResultValues.Tag.Success; param0: string } | { tag: typeof ResultValues.Tag.Failure; param0: string; param1: number } | { tag: typeof ResultValues.Tag.Status; param0: boolean; param1: number; param2: string } } +/// Represents a Swift heap object like a class instance or an actor instance. +export interface SwiftHeapObject { + /// Release the heap object. + /// + /// Note: Calling this method will release the heap object and it will no longer be accessible. + release(): void; +} +export interface User extends SwiftHeapObject { +} export type Exports = { + User: { + } handle(result: APIResultTag): void; getResult(): APIResultTag; roundtripAPIResult(result: APIResultTag): APIResultTag; @@ -87,9 +167,20 @@ export type Exports = { roundTripOptionalNetworkingResult(result: API.NetworkingResultTag | null): API.NetworkingResultTag | null; roundTripOptionalAPIOptionalResult(result: APIOptionalResultTag | null): APIOptionalResultTag | null; compareAPIResults(result1: APIOptionalResultTag | null, result2: APIOptionalResultTag | null): APIOptionalResultTag | null; + roundTripTypedPayloadResult(result: TypedPayloadResultTag): TypedPayloadResultTag; + roundTripOptionalTypedPayloadResult(result: TypedPayloadResultTag | null): TypedPayloadResultTag | null; + roundTripAllTypesResult(result: AllTypesResultTag): AllTypesResultTag; + roundTripOptionalAllTypesResult(result: AllTypesResultTag | null): AllTypesResultTag | null; + roundTripOptionalPayloadResult(result: OptionalAllTypesResultTag): OptionalAllTypesResultTag; + roundTripOptionalPayloadResultOpt(result: OptionalAllTypesResultTag | null): OptionalAllTypesResultTag | null; APIResult: APIResultObject ComplexResult: ComplexResultObject APIOptionalResult: APIOptionalResultObject + Precision: PrecisionObject + CardinalDirection: CardinalDirectionObject + TypedPayloadResult: TypedPayloadResultObject + AllTypesResult: AllTypesResultObject + OptionalAllTypesResult: OptionalAllTypesResultObject API: { NetworkingResult: NetworkingResultObject }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js new file mode 100644 index 000000000..123ba56fa --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -0,0 +1,1397 @@ +// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// `swift package bridge-js`. + +export const APIResultValues = { + Tag: { + Success: 0, + Failure: 1, + Flag: 2, + Rate: 3, + Precise: 4, + Info: 5, + }, +}; +export const ComplexResultValues = { + Tag: { + Success: 0, + Error: 1, + Status: 2, + Coordinates: 3, + Comprehensive: 4, + Info: 5, + }, +}; +export const ResultValues = { + Tag: { + Success: 0, + Failure: 1, + Status: 2, + }, +}; +export const NetworkingResultValues = { + Tag: { + Success: 0, + Failure: 1, + }, +}; +export const APIOptionalResultValues = { + Tag: { + Success: 0, + Failure: 1, + Status: 2, + }, +}; +export const PrecisionValues = { + Rough: 0.1, + Fine: 0.001, +}; + +export const CardinalDirectionValues = { + North: 0, + South: 1, + East: 2, + West: 3, +}; + +export const TypedPayloadResultValues = { + Tag: { + Precision: 0, + Direction: 1, + OptPrecision: 2, + OptDirection: 3, + Empty: 4, + }, +}; +export const AllTypesResultValues = { + Tag: { + StructPayload: 0, + ClassPayload: 1, + JsObjectPayload: 2, + NestedEnum: 3, + ArrayPayload: 4, + Empty: 5, + }, +}; +export const OptionalAllTypesResultValues = { + Tag: { + OptStruct: 0, + OptClass: 1, + OptJSObject: 2, + OptNestedEnum: 3, + OptArray: 4, + Empty: 5, + }, +}; +export async function createInstantiator(options, swift) { + let instance; + let memory; + let setException; + const textDecoder = new TextDecoder("utf-8"); + const textEncoder = new TextEncoder("utf-8"); + let tmpRetString; + let tmpRetBytes; + let tmpRetException; + let tmpRetOptionalBool; + let tmpRetOptionalInt; + let tmpRetOptionalFloat; + let tmpRetOptionalDouble; + let tmpRetOptionalHeapObject; + let tmpRetTag = []; + let tmpRetStrings = []; + let tmpRetInts = []; + let tmpRetF32s = []; + let tmpRetF64s = []; + let tmpParamInts = []; + let tmpParamF32s = []; + let tmpParamF64s = []; + let tmpRetPointers = []; + let tmpParamPointers = []; + let tmpStructCleanups = []; + const enumHelpers = {}; + const structHelpers = {}; + + let _exports = null; + let bjs = null; + const __bjs_createPointHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + lower: (value) => { + tmpParamF64s.push(value.x); + tmpParamF64s.push(value.y); + return { cleanup: undefined }; + }, + lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + const f64 = tmpRetF64s.pop(); + const f641 = tmpRetF64s.pop(); + return { x: f641, y: f64 }; + } + }); + }; + const __bjs_createAPIResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case APIResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: APIResultValues.Tag.Success, cleanup }; + } + case APIResultValues.Tag.Failure: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Failure, cleanup }; + } + case APIResultValues.Tag.Flag: { + tmpParamInts.push(value.param0 ? 1 : 0); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Flag, cleanup }; + } + case APIResultValues.Tag.Rate: { + tmpParamF32s.push(Math.fround(value.param0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Rate, cleanup }; + } + case APIResultValues.Tag.Precise: { + tmpParamF64s.push(value.param0); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Precise, cleanup }; + } + case APIResultValues.Tag.Info: { + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Info, cleanup }; + } + default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case APIResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: APIResultValues.Tag.Success, param0: string }; + } + case APIResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + return { tag: APIResultValues.Tag.Failure, param0: int }; + } + case APIResultValues.Tag.Flag: { + const bool = tmpRetInts.pop() !== 0; + return { tag: APIResultValues.Tag.Flag, param0: bool }; + } + case APIResultValues.Tag.Rate: { + const f32 = tmpRetF32s.pop(); + return { tag: APIResultValues.Tag.Rate, param0: f32 }; + } + case APIResultValues.Tag.Precise: { + const f64 = tmpRetF64s.pop(); + return { tag: APIResultValues.Tag.Precise, param0: f64 }; + } + case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; + default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createComplexResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case ComplexResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ComplexResultValues.Tag.Success, cleanup }; + } + case ComplexResultValues.Tag.Error: { + tmpParamInts.push((value.param1 | 0)); + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ComplexResultValues.Tag.Error, cleanup }; + } + case ComplexResultValues.Tag.Status: { + const bytes = textEncoder.encode(value.param2); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + tmpParamInts.push((value.param1 | 0)); + tmpParamInts.push(value.param0 ? 1 : 0); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ComplexResultValues.Tag.Status, cleanup }; + } + case ComplexResultValues.Tag.Coordinates: { + tmpParamF64s.push(value.param2); + tmpParamF64s.push(value.param1); + tmpParamF64s.push(value.param0); + const cleanup = undefined; + return { caseId: ComplexResultValues.Tag.Coordinates, cleanup }; + } + case ComplexResultValues.Tag.Comprehensive: { + const bytes = textEncoder.encode(value.param8); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const bytes1 = textEncoder.encode(value.param7); + const id1 = swift.memory.retain(bytes1); + tmpParamInts.push(bytes1.length); + tmpParamInts.push(id1); + const bytes2 = textEncoder.encode(value.param6); + const id2 = swift.memory.retain(bytes2); + tmpParamInts.push(bytes2.length); + tmpParamInts.push(id2); + tmpParamF64s.push(value.param5); + tmpParamF64s.push(value.param4); + tmpParamInts.push((value.param3 | 0)); + tmpParamInts.push((value.param2 | 0)); + tmpParamInts.push(value.param1 ? 1 : 0); + tmpParamInts.push(value.param0 ? 1 : 0); + const cleanup = () => { + swift.memory.release(id); + swift.memory.release(id1); + swift.memory.release(id2); + }; + return { caseId: ComplexResultValues.Tag.Comprehensive, cleanup }; + } + case ComplexResultValues.Tag.Info: { + const cleanup = undefined; + return { caseId: ComplexResultValues.Tag.Info, cleanup }; + } + default: throw new Error("Unknown ComplexResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case ComplexResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: ComplexResultValues.Tag.Success, param0: string }; + } + case ComplexResultValues.Tag.Error: { + const int = tmpRetInts.pop(); + const string = tmpRetStrings.pop(); + return { tag: ComplexResultValues.Tag.Error, param0: string, param1: int }; + } + case ComplexResultValues.Tag.Status: { + const string = tmpRetStrings.pop(); + const int = tmpRetInts.pop(); + const bool = tmpRetInts.pop() !== 0; + return { tag: ComplexResultValues.Tag.Status, param0: bool, param1: int, param2: string }; + } + case ComplexResultValues.Tag.Coordinates: { + const f64 = tmpRetF64s.pop(); + const f641 = tmpRetF64s.pop(); + const f642 = tmpRetF64s.pop(); + return { tag: ComplexResultValues.Tag.Coordinates, param0: f642, param1: f641, param2: f64 }; + } + case ComplexResultValues.Tag.Comprehensive: { + const string = tmpRetStrings.pop(); + const string1 = tmpRetStrings.pop(); + const string2 = tmpRetStrings.pop(); + const f64 = tmpRetF64s.pop(); + const f641 = tmpRetF64s.pop(); + const int = tmpRetInts.pop(); + const int1 = tmpRetInts.pop(); + const bool = tmpRetInts.pop() !== 0; + const bool1 = tmpRetInts.pop() !== 0; + return { tag: ComplexResultValues.Tag.Comprehensive, param0: bool1, param1: bool, param2: int1, param3: int, param4: f641, param5: f64, param6: string2, param7: string1, param8: string }; + } + case ComplexResultValues.Tag.Info: return { tag: ComplexResultValues.Tag.Info }; + default: throw new Error("Unknown ComplexResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case ResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ResultValues.Tag.Success, cleanup }; + } + case ResultValues.Tag.Failure: { + tmpParamInts.push((value.param1 | 0)); + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ResultValues.Tag.Failure, cleanup }; + } + case ResultValues.Tag.Status: { + const bytes = textEncoder.encode(value.param2); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + tmpParamInts.push((value.param1 | 0)); + tmpParamInts.push(value.param0 ? 1 : 0); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ResultValues.Tag.Status, cleanup }; + } + default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case ResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: ResultValues.Tag.Success, param0: string }; + } + case ResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + const string = tmpRetStrings.pop(); + return { tag: ResultValues.Tag.Failure, param0: string, param1: int }; + } + case ResultValues.Tag.Status: { + const string = tmpRetStrings.pop(); + const int = tmpRetInts.pop(); + const bool = tmpRetInts.pop() !== 0; + return { tag: ResultValues.Tag.Status, param0: bool, param1: int, param2: string }; + } + default: throw new Error("Unknown ResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createNetworkingResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case NetworkingResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: NetworkingResultValues.Tag.Success, cleanup }; + } + case NetworkingResultValues.Tag.Failure: { + tmpParamInts.push((value.param1 | 0)); + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: NetworkingResultValues.Tag.Failure, cleanup }; + } + default: throw new Error("Unknown NetworkingResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case NetworkingResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: NetworkingResultValues.Tag.Success, param0: string }; + } + case NetworkingResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + const string = tmpRetStrings.pop(); + return { tag: NetworkingResultValues.Tag.Failure, param0: string, param1: int }; + } + default: throw new Error("Unknown NetworkingResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createAPIOptionalResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case APIOptionalResultValues.Tag.Success: { + const isSome = value.param0 != null; + let id; + if (isSome) { + let bytes = textEncoder.encode(value.param0); + id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + } else { + tmpParamInts.push(0); + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if(id) { + swift.memory.release(id); + } + }; + return { caseId: APIOptionalResultValues.Tag.Success, cleanup }; + } + case APIOptionalResultValues.Tag.Failure: { + const isSome = value.param1 != null; + tmpParamInts.push(isSome ? (value.param1 ? 1 : 0) : 0); + tmpParamInts.push(isSome ? 1 : 0); + const isSome1 = value.param0 != null; + tmpParamInts.push(isSome1 ? (value.param0 | 0) : 0); + tmpParamInts.push(isSome1 ? 1 : 0); + const cleanup = undefined; + return { caseId: APIOptionalResultValues.Tag.Failure, cleanup }; + } + case APIOptionalResultValues.Tag.Status: { + const isSome = value.param2 != null; + let id; + if (isSome) { + let bytes = textEncoder.encode(value.param2); + id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + } else { + tmpParamInts.push(0); + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const isSome1 = value.param1 != null; + tmpParamInts.push(isSome1 ? (value.param1 | 0) : 0); + tmpParamInts.push(isSome1 ? 1 : 0); + const isSome2 = value.param0 != null; + tmpParamInts.push(isSome2 ? (value.param0 ? 1 : 0) : 0); + tmpParamInts.push(isSome2 ? 1 : 0); + const cleanup = () => { + if(id) { + swift.memory.release(id); + } + }; + return { caseId: APIOptionalResultValues.Tag.Status, cleanup }; + } + default: throw new Error("Unknown APIOptionalResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case APIOptionalResultValues.Tag.Success: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const string = tmpRetStrings.pop(); + optional = string; + } else { + optional = null; + } + return { tag: APIOptionalResultValues.Tag.Success, param0: optional }; + } + case APIOptionalResultValues.Tag.Failure: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const bool = tmpRetInts.pop() !== 0; + optional = bool; + } else { + optional = null; + } + const isSome1 = tmpRetInts.pop(); + let optional1; + if (isSome1) { + const int = tmpRetInts.pop(); + optional1 = int; + } else { + optional1 = null; + } + return { tag: APIOptionalResultValues.Tag.Failure, param0: optional1, param1: optional }; + } + case APIOptionalResultValues.Tag.Status: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const string = tmpRetStrings.pop(); + optional = string; + } else { + optional = null; + } + const isSome1 = tmpRetInts.pop(); + let optional1; + if (isSome1) { + const int = tmpRetInts.pop(); + optional1 = int; + } else { + optional1 = null; + } + const isSome2 = tmpRetInts.pop(); + let optional2; + if (isSome2) { + const bool = tmpRetInts.pop() !== 0; + optional2 = bool; + } else { + optional2 = null; + } + return { tag: APIOptionalResultValues.Tag.Status, param0: optional2, param1: optional1, param2: optional }; + } + default: throw new Error("Unknown APIOptionalResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createTypedPayloadResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case TypedPayloadResultValues.Tag.Precision: { + tmpParamF32s.push(Math.fround(value.param0)); + const cleanup = undefined; + return { caseId: TypedPayloadResultValues.Tag.Precision, cleanup }; + } + case TypedPayloadResultValues.Tag.Direction: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: TypedPayloadResultValues.Tag.Direction, cleanup }; + } + case TypedPayloadResultValues.Tag.OptPrecision: { + const isSome = value.param0 != null; + tmpParamF32s.push(isSome ? Math.fround(value.param0) : 0.0); + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = undefined; + return { caseId: TypedPayloadResultValues.Tag.OptPrecision, cleanup }; + } + case TypedPayloadResultValues.Tag.OptDirection: { + const isSome = value.param0 != null; + tmpParamInts.push(isSome ? (value.param0 | 0) : 0); + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = undefined; + return { caseId: TypedPayloadResultValues.Tag.OptDirection, cleanup }; + } + case TypedPayloadResultValues.Tag.Empty: { + const cleanup = undefined; + return { caseId: TypedPayloadResultValues.Tag.Empty, cleanup }; + } + default: throw new Error("Unknown TypedPayloadResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case TypedPayloadResultValues.Tag.Precision: { + const rawValue = tmpRetF32s.pop(); + return { tag: TypedPayloadResultValues.Tag.Precision, param0: rawValue }; + } + case TypedPayloadResultValues.Tag.Direction: { + const caseId = tmpRetInts.pop(); + return { tag: TypedPayloadResultValues.Tag.Direction, param0: caseId }; + } + case TypedPayloadResultValues.Tag.OptPrecision: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const rawValue = tmpRetF32s.pop(); + optional = rawValue; + } else { + optional = null; + } + return { tag: TypedPayloadResultValues.Tag.OptPrecision, param0: optional }; + } + case TypedPayloadResultValues.Tag.OptDirection: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const caseId = tmpRetInts.pop(); + optional = caseId; + } else { + optional = null; + } + return { tag: TypedPayloadResultValues.Tag.OptDirection, param0: optional }; + } + case TypedPayloadResultValues.Tag.Empty: return { tag: TypedPayloadResultValues.Tag.Empty }; + default: throw new Error("Unknown TypedPayloadResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createAllTypesResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case AllTypesResultValues.Tag.StructPayload: { + const { cleanup: structCleanup } = structHelpers.Point.lower(value.param0); + const cleanup = () => { + if (structCleanup) { structCleanup(); } + }; + return { caseId: AllTypesResultValues.Tag.StructPayload, cleanup }; + } + case AllTypesResultValues.Tag.ClassPayload: { + tmpParamPointers.push(value.param0.pointer); + const cleanup = undefined; + return { caseId: AllTypesResultValues.Tag.ClassPayload, cleanup }; + } + case AllTypesResultValues.Tag.JsObjectPayload: { + const objId = swift.memory.retain(value.param0); + tmpParamInts.push(objId); + const cleanup = undefined; + return { caseId: AllTypesResultValues.Tag.JsObjectPayload, cleanup }; + } + case AllTypesResultValues.Tag.NestedEnum: { + const { caseId: caseId, cleanup: enumCleanup } = enumHelpers.APIResult.lower(value.param0); + tmpParamInts.push(caseId); + const cleanup = () => { + if (enumCleanup) { enumCleanup(); } + }; + return { caseId: AllTypesResultValues.Tag.NestedEnum, cleanup }; + } + case AllTypesResultValues.Tag.ArrayPayload: { + const arrayCleanups = []; + for (const elem of value.param0) { + tmpParamInts.push((elem | 0)); + } + tmpParamInts.push(value.param0.length); + const cleanup = () => { + for (const cleanup of arrayCleanups) { cleanup(); } + }; + return { caseId: AllTypesResultValues.Tag.ArrayPayload, cleanup }; + } + case AllTypesResultValues.Tag.Empty: { + const cleanup = undefined; + return { caseId: AllTypesResultValues.Tag.Empty, cleanup }; + } + default: throw new Error("Unknown AllTypesResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case AllTypesResultValues.Tag.StructPayload: { + const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return { tag: AllTypesResultValues.Tag.StructPayload, param0: struct }; + } + case AllTypesResultValues.Tag.ClassPayload: { + const ptr = tmpRetPointers.pop(); + const obj = _exports['User'].__construct(ptr); + return { tag: AllTypesResultValues.Tag.ClassPayload, param0: obj }; + } + case AllTypesResultValues.Tag.JsObjectPayload: { + const objId = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId); + swift.memory.release(objId); + return { tag: AllTypesResultValues.Tag.JsObjectPayload, param0: obj }; + } + case AllTypesResultValues.Tag.NestedEnum: { + const enumValue = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return { tag: AllTypesResultValues.Tag.NestedEnum, param0: enumValue }; + } + case AllTypesResultValues.Tag.ArrayPayload: { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const int = tmpRetInts.pop(); + arrayResult.push(int); + } + arrayResult.reverse(); + return { tag: AllTypesResultValues.Tag.ArrayPayload, param0: arrayResult }; + } + case AllTypesResultValues.Tag.Empty: return { tag: AllTypesResultValues.Tag.Empty }; + default: throw new Error("Unknown AllTypesResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + const __bjs_createOptionalAllTypesResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case OptionalAllTypesResultValues.Tag.OptStruct: { + const isSome = value.param0 != null; + let nestedCleanup; + if (isSome) { + const structResult = structHelpers.Point.lower(value.param0); + nestedCleanup = structResult.cleanup; + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if (nestedCleanup) { nestedCleanup(); } + }; + return { caseId: OptionalAllTypesResultValues.Tag.OptStruct, cleanup }; + } + case OptionalAllTypesResultValues.Tag.OptClass: { + const isSome = value.param0 != null; + if (isSome) { + tmpParamPointers.push(value.param0.pointer); + } else { + tmpParamPointers.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = undefined; + return { caseId: OptionalAllTypesResultValues.Tag.OptClass, cleanup }; + } + case OptionalAllTypesResultValues.Tag.OptJSObject: { + const isSome = value.param0 != null; + let id; + if (isSome) { + id = swift.memory.retain(value.param0); + tmpParamInts.push(id); + } else { + id = undefined; + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = undefined; + return { caseId: OptionalAllTypesResultValues.Tag.OptJSObject, cleanup }; + } + case OptionalAllTypesResultValues.Tag.OptNestedEnum: { + const isSome = value.param0 != null; + let enumCaseId, enumCleanup; + if (isSome) { + const enumResult = enumHelpers.APIResult.lower(value.param0); + enumCaseId = enumResult.caseId; + enumCleanup = enumResult.cleanup; + tmpParamInts.push(enumCaseId); + } else { + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if (enumCleanup) { enumCleanup(); } + }; + return { caseId: OptionalAllTypesResultValues.Tag.OptNestedEnum, cleanup }; + } + case OptionalAllTypesResultValues.Tag.OptArray: { + const isSome = value.param0 != null; + let arrCleanup; + if (isSome) { + const arrayCleanups = []; + for (const elem of value.param0) { + tmpParamInts.push((elem | 0)); + } + tmpParamInts.push(value.param0.length); + arrCleanup = () => { + for (const cleanup of arrayCleanups) { cleanup(); } + }; + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if (arrCleanup) { arrCleanup(); } + }; + return { caseId: OptionalAllTypesResultValues.Tag.OptArray, cleanup }; + } + case OptionalAllTypesResultValues.Tag.Empty: { + const cleanup = undefined; + return { caseId: OptionalAllTypesResultValues.Tag.Empty, cleanup }; + } + default: throw new Error("Unknown OptionalAllTypesResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case OptionalAllTypesResultValues.Tag.OptStruct: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optional = struct; + } else { + optional = null; + } + return { tag: OptionalAllTypesResultValues.Tag.OptStruct, param0: optional }; + } + case OptionalAllTypesResultValues.Tag.OptClass: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const ptr = tmpRetPointers.pop(); + const obj = _exports['User'].__construct(ptr); + optional = obj; + } else { + optional = null; + } + return { tag: OptionalAllTypesResultValues.Tag.OptClass, param0: optional }; + } + case OptionalAllTypesResultValues.Tag.OptJSObject: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const objId = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId); + swift.memory.release(objId); + optional = obj; + } else { + optional = null; + } + return { tag: OptionalAllTypesResultValues.Tag.OptJSObject, param0: optional }; + } + case OptionalAllTypesResultValues.Tag.OptNestedEnum: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const caseId = tmpRetInts.pop(); + optional = enumHelpers.APIResult.lift(caseId, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } else { + optional = null; + } + return { tag: OptionalAllTypesResultValues.Tag.OptNestedEnum, param0: optional }; + } + case OptionalAllTypesResultValues.Tag.OptArray: { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const int = tmpRetInts.pop(); + arrayResult.push(int); + } + arrayResult.reverse(); + optional = arrayResult; + } else { + optional = null; + } + return { tag: OptionalAllTypesResultValues.Tag.OptArray, param0: optional }; + } + case OptionalAllTypesResultValues.Tag.Empty: return { tag: OptionalAllTypesResultValues.Tag.Empty }; + default: throw new Error("Unknown OptionalAllTypesResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; + + return { + /** + * @param {WebAssembly.Imports} importObject + */ + addImports: (importObject, importsContext) => { + bjs = {}; + importObject["bjs"] = bjs; + bjs["swift_js_return_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + tmpRetString = textDecoder.decode(bytes); + } + bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { + const source = swift.memory.getObject(sourceId); + const bytes = new Uint8Array(memory.buffer, bytesPtr); + bytes.set(source); + } + bjs["swift_js_make_js_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + return swift.memory.retain(textDecoder.decode(bytes)); + } + bjs["swift_js_init_memory_with_result"] = function(ptr, len) { + const target = new Uint8Array(memory.buffer, ptr, len); + target.set(tmpRetBytes); + tmpRetBytes = undefined; + } + bjs["swift_js_throw"] = function(id) { + tmpRetException = swift.memory.retainByRef(id); + } + bjs["swift_js_retain"] = function(id) { + return swift.memory.retainByRef(id); + } + bjs["swift_js_release"] = function(id) { + swift.memory.release(id); + } + bjs["swift_js_push_tag"] = function(tag) { + tmpRetTag.push(tag); + } + bjs["swift_js_push_i32"] = function(v) { + tmpRetInts.push(v | 0); + } + bjs["swift_js_push_f32"] = function(v) { + tmpRetF32s.push(Math.fround(v)); + } + bjs["swift_js_push_f64"] = function(v) { + tmpRetF64s.push(v); + } + bjs["swift_js_push_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + const value = textDecoder.decode(bytes); + tmpRetStrings.push(value); + } + bjs["swift_js_pop_i32"] = function() { + return tmpParamInts.pop(); + } + bjs["swift_js_pop_f32"] = function() { + return tmpParamF32s.pop(); + } + bjs["swift_js_pop_f64"] = function() { + return tmpParamF64s.pop(); + } + bjs["swift_js_push_pointer"] = function(pointer) { + tmpRetPointers.push(pointer); + } + bjs["swift_js_pop_pointer"] = function() { + return tmpParamPointers.pop(); + } + bjs["swift_js_struct_cleanup"] = function(cleanupId) { + if (cleanupId === 0) { return; } + const index = (cleanupId | 0) - 1; + const cleanup = tmpStructCleanups[index]; + tmpStructCleanups[index] = null; + if (cleanup) { cleanup(); } + while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { + tmpStructCleanups.pop(); + } + } + bjs["swift_js_struct_lower_Point"] = function(objectId) { + const { cleanup: cleanup } = structHelpers.Point.lower(swift.memory.getObject(objectId)); + if (cleanup) { + return tmpStructCleanups.push(cleanup); + } + return 0; + } + bjs["swift_js_struct_lift_Point"] = function() { + const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return swift.memory.retain(value); + } + bjs["swift_js_return_optional_bool"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalBool = null; + } else { + tmpRetOptionalBool = value !== 0; + } + } + bjs["swift_js_return_optional_int"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalInt = null; + } else { + tmpRetOptionalInt = value | 0; + } + } + bjs["swift_js_return_optional_float"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalFloat = null; + } else { + tmpRetOptionalFloat = Math.fround(value); + } + } + bjs["swift_js_return_optional_double"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalDouble = null; + } else { + tmpRetOptionalDouble = value; + } + } + bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + if (isSome === 0) { + tmpRetString = null; + } else { + const bytes = new Uint8Array(memory.buffer, ptr, len); + tmpRetString = textDecoder.decode(bytes); + } + } + bjs["swift_js_return_optional_object"] = function(isSome, objectId) { + if (isSome === 0) { + tmpRetString = null; + } else { + tmpRetString = swift.memory.getObject(objectId); + } + } + bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { + if (isSome === 0) { + tmpRetOptionalHeapObject = null; + } else { + tmpRetOptionalHeapObject = pointer; + } + } + bjs["swift_js_get_optional_int_presence"] = function() { + return tmpRetOptionalInt != null ? 1 : 0; + } + bjs["swift_js_get_optional_int_value"] = function() { + const value = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; + return value; + } + bjs["swift_js_get_optional_string"] = function() { + const str = tmpRetString; + tmpRetString = undefined; + if (str == null) { + return -1; + } else { + const bytes = textEncoder.encode(str); + tmpRetBytes = bytes; + return bytes.length; + } + } + bjs["swift_js_get_optional_float_presence"] = function() { + return tmpRetOptionalFloat != null ? 1 : 0; + } + bjs["swift_js_get_optional_float_value"] = function() { + const value = tmpRetOptionalFloat; + tmpRetOptionalFloat = undefined; + return value; + } + bjs["swift_js_get_optional_double_presence"] = function() { + return tmpRetOptionalDouble != null ? 1 : 0; + } + bjs["swift_js_get_optional_double_value"] = function() { + const value = tmpRetOptionalDouble; + tmpRetOptionalDouble = undefined; + return value; + } + bjs["swift_js_get_optional_heap_object_pointer"] = function() { + const pointer = tmpRetOptionalHeapObject; + tmpRetOptionalHeapObject = undefined; + return pointer || 0; + } + // Wrapper functions for module: TestModule + if (!importObject["TestModule"]) { + importObject["TestModule"] = {}; + } + importObject["TestModule"]["bjs_User_wrap"] = function(pointer) { + const obj = User.__construct(pointer); + return swift.memory.retain(obj); + }; + }, + setInstance: (i) => { + instance = i; + memory = instance.exports.memory; + + setException = (error) => { + instance.exports._swift_js_exception.value = swift.memory.retain(error) + } + }, + /** @param {WebAssembly.Instance} instance */ + createExports: (instance) => { + const js = swift.memory.heap; + /// Represents a Swift heap object like a class instance or an actor instance. + class SwiftHeapObject { + static __wrap(pointer, deinit, prototype) { + const obj = Object.create(prototype); + obj.pointer = pointer; + obj.hasReleased = false; + obj.deinit = deinit; + obj.registry = new FinalizationRegistry((pointer) => { + deinit(pointer); + }); + obj.registry.register(this, obj.pointer); + return obj; + } + + release() { + this.registry.unregister(this); + this.deinit(this.pointer); + } + } + class User extends SwiftHeapObject { + static __construct(ptr) { + return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_User_deinit, User.prototype); + } + + } + const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + structHelpers.Point = PointHelpers; + + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.APIResult = APIResultHelpers; + + const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.ComplexResult = ComplexResultHelpers; + + const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.Result = ResultHelpers; + + const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.NetworkingResult = NetworkingResultHelpers; + + const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.APIOptionalResult = APIOptionalResultHelpers; + + const TypedPayloadResultHelpers = __bjs_createTypedPayloadResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.TypedPayloadResult = TypedPayloadResultHelpers; + + const AllTypesResultHelpers = __bjs_createAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.AllTypesResult = AllTypesResultHelpers; + + const OptionalAllTypesResultHelpers = __bjs_createOptionalAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.OptionalAllTypesResult = OptionalAllTypesResultHelpers; + + const exports = { + User, + handle: function bjs_handle(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); + instance.exports.bjs_handle(resultCaseId); + if (resultCleanup) { resultCleanup(); } + }, + getResult: function bjs_getResult() { + instance.exports.bjs_getResult(); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return ret; + }, + roundtripAPIResult: function bjs_roundtripAPIResult(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); + instance.exports.bjs_roundtripAPIResult(resultCaseId); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (resultCleanup) { resultCleanup(); } + return ret; + }, + roundTripOptionalAPIResult: function bjs_roundTripOptionalAPIResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.APIResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalAPIResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.APIResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + handleComplex: function bjs_handleComplex(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); + instance.exports.bjs_handleComplex(resultCaseId); + if (resultCleanup) { resultCleanup(); } + }, + getComplexResult: function bjs_getComplexResult() { + instance.exports.bjs_getComplexResult(); + const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return ret; + }, + roundtripComplexResult: function bjs_roundtripComplexResult(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); + instance.exports.bjs_roundtripComplexResult(resultCaseId); + const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (resultCleanup) { resultCleanup(); } + return ret; + }, + roundTripOptionalComplexResult: function bjs_roundTripOptionalComplexResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.ComplexResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalComplexResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.ComplexResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + roundTripOptionalUtilitiesResult: function bjs_roundTripOptionalUtilitiesResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.Result.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalUtilitiesResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.Result.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + roundTripOptionalNetworkingResult: function bjs_roundTripOptionalNetworkingResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.NetworkingResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalNetworkingResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.NetworkingResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + roundTripOptionalAPIOptionalResult: function bjs_roundTripOptionalAPIOptionalResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.APIOptionalResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalAPIOptionalResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.APIOptionalResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + compareAPIResults: function bjs_compareAPIResults(result1, result2) { + const isSome = result1 != null; + let result1CaseId, result1Cleanup; + if (isSome) { + const enumResult = enumHelpers.APIOptionalResult.lower(result1); + result1CaseId = enumResult.caseId; + result1Cleanup = enumResult.cleanup; + } + const isSome1 = result2 != null; + let result2CaseId, result2Cleanup; + if (isSome1) { + const enumResult1 = enumHelpers.APIOptionalResult.lower(result2); + result2CaseId = enumResult1.caseId; + result2Cleanup = enumResult1.cleanup; + } + instance.exports.bjs_compareAPIResults(+isSome, isSome ? result1CaseId : 0, +isSome1, isSome1 ? result2CaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.APIOptionalResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (result1Cleanup) { result1Cleanup(); } + if (result2Cleanup) { result2Cleanup(); } + return optResult; + }, + roundTripTypedPayloadResult: function bjs_roundTripTypedPayloadResult(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.TypedPayloadResult.lower(result); + instance.exports.bjs_roundTripTypedPayloadResult(resultCaseId); + const ret = enumHelpers.TypedPayloadResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (resultCleanup) { resultCleanup(); } + return ret; + }, + roundTripOptionalTypedPayloadResult: function bjs_roundTripOptionalTypedPayloadResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.TypedPayloadResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalTypedPayloadResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.TypedPayloadResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + roundTripAllTypesResult: function bjs_roundTripAllTypesResult(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.AllTypesResult.lower(result); + instance.exports.bjs_roundTripAllTypesResult(resultCaseId); + const ret = enumHelpers.AllTypesResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (resultCleanup) { resultCleanup(); } + return ret; + }, + roundTripOptionalAllTypesResult: function bjs_roundTripOptionalAllTypesResult(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.AllTypesResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalAllTypesResult(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.AllTypesResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + roundTripOptionalPayloadResult: function bjs_roundTripOptionalPayloadResult(result) { + const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.OptionalAllTypesResult.lower(result); + instance.exports.bjs_roundTripOptionalPayloadResult(resultCaseId); + const ret = enumHelpers.OptionalAllTypesResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (resultCleanup) { resultCleanup(); } + return ret; + }, + roundTripOptionalPayloadResultOpt: function bjs_roundTripOptionalPayloadResultOpt(result) { + const isSome = result != null; + let resultCaseId, resultCleanup; + if (isSome) { + const enumResult = enumHelpers.OptionalAllTypesResult.lower(result); + resultCaseId = enumResult.caseId; + resultCleanup = enumResult.cleanup; + } + instance.exports.bjs_roundTripOptionalPayloadResultOpt(+isSome, isSome ? resultCaseId : 0); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); + let optResult; + if (isNull) { + optResult = null; + } else { + optResult = enumHelpers.OptionalAllTypesResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + } + if (resultCleanup) { resultCleanup(); } + return optResult; + }, + APIResult: APIResultValues, + ComplexResult: ComplexResultValues, + APIOptionalResult: APIOptionalResultValues, + Precision: PrecisionValues, + CardinalDirection: CardinalDirectionValues, + TypedPayloadResult: TypedPayloadResultValues, + AllTypesResult: AllTypesResultValues, + OptionalAllTypesResult: OptionalAllTypesResultValues, + API: { + NetworkingResult: NetworkingResultValues, + }, + Utilities: { + Result: ResultValues, + }, + }; + _exports = exports; + return exports; + }, + } +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 89a0f0897..9ca596a6e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -42,7 +42,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -55,7 +55,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -94,7 +94,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts similarity index 87% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts index 4261ca3bb..f1dc0a926 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts @@ -58,6 +58,15 @@ declare global { } } } + namespace Services { + namespace Graph { + namespace GraphOperations { + createGraph(rootId: number): number; + nodeCount(graphId: number): number; + validate(graphId: number): boolean; + } + } + } namespace Utils { class Converter { constructor(); @@ -103,6 +112,15 @@ export type Exports = { }, }, }, + Services: { + Graph: { + GraphOperations: { + createGraph(rootId: number): number; + nodeCount(graphId: number): number; + validate(graphId: number): boolean; + }, + }, + }, Utils: { Converter: { new(): Converter; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js similarity index 86% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index 77c327e8d..a7a2c4b98 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -62,7 +62,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -75,7 +75,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -114,7 +114,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -286,7 +286,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -296,7 +296,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype); } - + constructor() { const ret = instance.exports.bjs_Converter_init(); return Converter.__construct(ret); @@ -312,7 +312,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_HTTPServer_deinit, HTTPServer.prototype); } - + constructor() { const ret = instance.exports.bjs_HTTPServer_init(); return HTTPServer.__construct(ret); @@ -325,7 +325,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestServer_deinit, TestServer.prototype); } - + constructor() { const ret = instance.exports.bjs_TestServer_init(); return TestServer.__construct(ret); @@ -349,6 +349,15 @@ export async function createInstantiator(options, swift) { if (typeof globalThis.Networking.APIV2.Internal === 'undefined') { globalThis.Networking.APIV2.Internal = {}; } + if (typeof globalThis.Services === 'undefined') { + globalThis.Services = {}; + } + if (typeof globalThis.Services.Graph === 'undefined') { + globalThis.Services.Graph = {}; + } + if (typeof globalThis.Services.Graph.GraphOperations === 'undefined') { + globalThis.Services.Graph.GraphOperations = {}; + } if (typeof globalThis.Utils === 'undefined') { globalThis.Utils = {}; } @@ -369,6 +378,30 @@ export async function createInstantiator(options, swift) { }, }, }, + Services: { + Graph: { + GraphOperations: { + createGraph: function bjs_Services_Graph_GraphOperations_static_createGraph(rootId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_createGraph(rootId); + return ret; + }, + nodeCount: function bjs_Services_Graph_GraphOperations_static_nodeCount(graphId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_nodeCount(graphId); + return ret; + }, + validate: function bjs_Services_Graph_GraphOperations_static_validate(graphId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_validate(graphId); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + return ret !== 0; + }, + }, + }, + }, Utils: { Converter, }, @@ -377,6 +410,9 @@ export async function createInstantiator(options, swift) { globalThis.Utils.Converter = exports.Utils.Converter; globalThis.Networking.API.HTTPServer = exports.Networking.API.HTTPServer; globalThis.Networking.APIV2.Internal.TestServer = exports.Networking.APIV2.Internal.TestServer; + globalThis.Services.Graph.GraphOperations.createGraph = exports.Services.Graph.GraphOperations.createGraph; + globalThis.Services.Graph.GraphOperations.nodeCount = exports.Services.Graph.GraphOperations.nodeCount; + globalThis.Services.Graph.GraphOperations.validate = exports.Services.Graph.GraphOperations.validate; return exports; }, } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.d.ts similarity index 92% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.d.ts index b8b92d14e..a6934d6e7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.d.ts @@ -84,6 +84,15 @@ export type Exports = { }, }, }, + Services: { + Graph: { + GraphOperations: { + createGraph(rootId: number): number; + nodeCount(graphId: number): number; + validate(graphId: number): boolean; + }, + }, + }, Utils: { Converter: { new(): Converter; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js similarity index 89% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index b01148873..b195b6945 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -43,7 +43,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -56,7 +56,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -95,7 +95,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -277,7 +277,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype); } - + constructor() { const ret = instance.exports.bjs_Converter_init(); return Converter.__construct(ret); @@ -293,7 +293,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_HTTPServer_deinit, HTTPServer.prototype); } - + constructor() { const ret = instance.exports.bjs_HTTPServer_init(); return HTTPServer.__construct(ret); @@ -306,7 +306,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestServer_deinit, TestServer.prototype); } - + constructor() { const ret = instance.exports.bjs_TestServer_init(); return TestServer.__construct(ret); @@ -332,6 +332,30 @@ export async function createInstantiator(options, swift) { }, }, }, + Services: { + Graph: { + GraphOperations: { + createGraph: function bjs_Services_Graph_GraphOperations_static_createGraph(rootId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_createGraph(rootId); + return ret; + }, + nodeCount: function bjs_Services_Graph_GraphOperations_static_nodeCount(graphId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_nodeCount(graphId); + return ret; + }, + validate: function bjs_Services_Graph_GraphOperations_static_validate(graphId) { + const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_validate(graphId); + if (tmpRetException) { + const error = swift.memory.getObject(tmpRetException); + swift.memory.release(tmpRetException); + tmpRetException = undefined; + throw error; + } + return ret !== 0; + }, + }, + }, + }, Utils: { Converter, }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.d.ts similarity index 98% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.d.ts index d321b99fb..170d7f07d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.d.ts @@ -161,6 +161,8 @@ export type Exports = { Ratio: RatioObject } export type Imports = { + takesFeatureFlag(flag: FeatureFlagTag): void; + returnsFeatureFlag(): FeatureFlagTag; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js similarity index 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index c1865adfc..c906f27ff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -93,7 +93,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -106,7 +106,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -117,6 +117,7 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); bjs["swift_js_return_string"] = function(ptr, len) { const bytes = new Uint8Array(memory.buffer, ptr, len); tmpRetString = textDecoder.decode(bytes); @@ -145,7 +146,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -276,6 +277,25 @@ export async function createInstantiator(options, swift) { tmpRetOptionalHeapObject = undefined; return pointer || 0; } + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_takesFeatureFlag"] = function bjs_takesFeatureFlag(flag) { + try { + const flagObject = swift.memory.getObject(flag); + swift.memory.release(flag); + imports.takesFeatureFlag(flagObject); + } catch (error) { + setException(error); + } + } + TestModule["bjs_returnsFeatureFlag"] = function bjs_returnsFeatureFlag() { + try { + let ret = imports.returnsFeatureFlag(); + tmpRetBytes = textEncoder.encode(ret); + return tmpRetBytes.length; + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { instance = i; @@ -344,17 +364,30 @@ export async function createInstantiator(options, swift) { return optResult; }, setFeatureFlag: function bjs_setFeatureFlag(flag) { - instance.exports.bjs_setFeatureFlag(flag); + const flagBytes = textEncoder.encode(flag); + const flagId = swift.memory.retain(flagBytes); + instance.exports.bjs_setFeatureFlag(flagId, flagBytes.length); + swift.memory.release(flagId); }, getFeatureFlag: function bjs_getFeatureFlag() { - const ret = instance.exports.bjs_getFeatureFlag(); - return ret !== 0; + instance.exports.bjs_getFeatureFlag(); + const ret = tmpRetString; + tmpRetString = undefined; + return ret; }, roundTripOptionalFeatureFlag: function bjs_roundTripOptionalFeatureFlag(input) { const isSome = input != null; - instance.exports.bjs_roundTripOptionalFeatureFlag(+isSome, isSome ? input : 0); - const optResult = tmpRetOptionalBool; - tmpRetOptionalBool = undefined; + let inputId, inputBytes; + if (isSome) { + inputBytes = textEncoder.encode(input); + inputId = swift.memory.retain(inputBytes); + } + instance.exports.bjs_roundTripOptionalFeatureFlag(+isSome, isSome ? inputId : 0, isSome ? inputBytes.length : 0); + const optResult = tmpRetString; + tmpRetString = undefined; + if (inputId != undefined) { + swift.memory.release(inputId); + } return optResult; }, setHttpStatus: function bjs_setHttpStatus(status) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index b3b809476..ac6170b08 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 35a3d76ec..dc2220715 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts similarity index 86% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts index 5442ebfa2..5d1e2c4dc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts @@ -7,7 +7,8 @@ export type Exports = { } export type Imports = { - check(a: number, b: boolean): void; + roundtrip(items: number[]): number[]; + logStrings(items: string[]): void; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js similarity index 88% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index e3263af05..daa601aed 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -203,22 +203,37 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_checkNumber"] = function bjs_checkNumber() { + TestModule["bjs_roundtrip"] = function bjs_roundtrip() { try { - let ret = imports.checkNumber(); - return ret; + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const int = tmpRetInts.pop(); + arrayResult.push(int); + } + arrayResult.reverse(); + let ret = imports.roundtrip(arrayResult); + const arrayCleanups = []; + for (const elem of ret) { + tmpParamInts.push((elem | 0)); + } + tmpParamInts.push(ret.length); } catch (error) { setException(error); - return 0 } } - TestModule["bjs_checkBoolean"] = function bjs_checkBoolean() { + TestModule["bjs_logStrings"] = function bjs_logStrings() { try { - let ret = imports.checkBoolean(); - return ret ? 1 : 0; + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const string = tmpRetStrings.pop(); + arrayResult.push(string); + } + arrayResult.reverse(); + imports.logStrings(arrayResult); } catch (error) { setException(error); - return 0 } } }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts similarity index 70% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts index 654b4bc04..22b4e6a1c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts @@ -4,10 +4,17 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. +export interface FooContainer { + foo: Foo; + optionalFoo: Foo | null; +} export interface Foo { } export type Exports = { makeFoo(): Foo; + processFooArray(foos: Foo[]): Foo[]; + processOptionalFooArray(foos: (Foo | null)[]): (Foo | null)[]; + roundtripFooContainer(container: FooContainer): FooContainer; } export type Imports = { Foo: { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js similarity index 59% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 094c2241d..efcbbe2d6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,9 +31,73 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; + const __bjs_createFooContainerHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + lower: (value) => { + let id; + if (value.foo != null) { + id = swift.memory.retain(value.foo); + } else { + id = undefined; + } + tmpParamInts.push(id !== undefined ? id : 0); + const isSome = value.optionalFoo != null; + let id1; + if (isSome) { + id1 = swift.memory.retain(value.optionalFoo); + tmpParamInts.push(id1); + } else { + id1 = undefined; + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if(id !== undefined && id !== 0) { + try { + swift.memory.getObject(id); + swift.memory.release(id); + } catch(e) {} + } + if(id1 !== undefined && id1 !== 0) { + try { + swift.memory.getObject(id1); + swift.memory.release(id1); + } catch(e) {} + } + }; + return { cleanup }; + }, + lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const objectId = tmpRetInts.pop(); + let value; + if (objectId !== 0) { + value = swift.memory.getObject(objectId); + swift.memory.release(objectId); + } else { + value = null; + } + optional = value; + } else { + optional = null; + } + const objectId1 = tmpRetInts.pop(); + let value1; + if (objectId1 !== 0) { + value1 = swift.memory.getObject(objectId1); + swift.memory.release(objectId1); + } else { + value1 = null; + } + return { foo: value1, optionalFoo: optional }; + } + }); + }; return { /** @@ -71,7 +135,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -112,6 +176,17 @@ export async function createInstantiator(options, swift) { tmpStructCleanups.pop(); } } + bjs["swift_js_struct_lower_FooContainer"] = function(objectId) { + const { cleanup: cleanup } = structHelpers.FooContainer.lower(swift.memory.getObject(objectId)); + if (cleanup) { + return tmpStructCleanups.push(cleanup); + } + return 0; + } + bjs["swift_js_struct_lift_FooContainer"] = function() { + const value = structHelpers.FooContainer.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return swift.memory.retain(value); + } bjs["swift_js_return_optional_bool"] = function(isSome, value) { if (isSome === 0) { tmpRetOptionalBool = null; @@ -223,6 +298,9 @@ export async function createInstantiator(options, swift) { /** @param {WebAssembly.Instance} instance */ createExports: (instance) => { const js = swift.memory.heap; + const FooContainerHelpers = __bjs_createFooContainerHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + structHelpers.FooContainer = FooContainerHelpers; + const exports = { makeFoo: function bjs_makeFoo() { const ret = instance.exports.bjs_makeFoo(); @@ -236,6 +314,66 @@ export async function createInstantiator(options, swift) { } return ret1; }, + processFooArray: function bjs_processFooArray(foos) { + const arrayCleanups = []; + for (const elem of foos) { + const objId = swift.memory.retain(elem); + tmpParamInts.push(objId); + } + tmpParamInts.push(foos.length); + instance.exports.bjs_processFooArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const objId1 = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId1); + swift.memory.release(objId1); + arrayResult.push(obj); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + processOptionalFooArray: function bjs_processOptionalFooArray(foos) { + const arrayCleanups = []; + for (const elem of foos) { + const isSome = elem != null ? 1 : 0; + if (isSome) { + const objId = swift.memory.retain(elem); + tmpParamInts.push(objId); + } else { + tmpParamInts.push(0); + } + tmpParamInts.push(isSome); + } + tmpParamInts.push(foos.length); + instance.exports.bjs_processOptionalFooArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const isSome1 = tmpRetInts.pop(); + let optValue; + if (isSome1 === 0) { + optValue = null; + } else { + const objId1 = tmpRetInts.pop(); + const obj = swift.memory.getObject(objId1); + swift.memory.release(objId1); + optValue = obj; + } + arrayResult.push(optValue); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + roundtripFooContainer: function bjs_roundtripFooContainer(container) { + const { cleanup: cleanup } = structHelpers.FooContainer.lower(container); + instance.exports.bjs_roundtripFooContainer(); + const structValue = structHelpers.FooContainer.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (cleanup) { cleanup(); } + return structValue; + }, }; _exports = exports; return exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.d.ts deleted file mode 100644 index ccd371b71..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export interface Animatable { - animate(keyframes: any, options: any): any; - getAnimations(options: any): any; -} -export type Exports = { -} -export type Imports = { - returnAnimatable(): Animatable; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.js deleted file mode 100644 index 1d25a2954..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.js +++ /dev/null @@ -1,251 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_returnAnimatable"] = function bjs_returnAnimatable() { - try { - let ret = imports.returnAnimatable(); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_Animatable_animate"] = function bjs_Animatable_animate(self, keyframes, options) { - try { - let ret = swift.memory.getObject(self).animate(swift.memory.getObject(keyframes), swift.memory.getObject(options)); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_Animatable_getAnimations"] = function bjs_Animatable_getAnimations(self, options) { - try { - let ret = swift.memory.getObject(self).getAnimations(swift.memory.getObject(options)); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.d.ts similarity index 85% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.d.ts index 2efd24317..ac0e05a91 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.d.ts @@ -4,10 +4,6 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -export interface ArrayBufferLike { - slice(begin: number, end: number): ArrayBufferLike; - readonly byteLength: number; -} export interface WeirdNaming { as(): void; try(): void; @@ -26,7 +22,6 @@ export interface _Weird { export type Exports = { } export type Imports = { - createArrayBuffer(): ArrayBufferLike; createWeirdObject(): WeirdNaming; createWeirdClass(): _Weird; _Weird: { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js similarity index 93% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index 833436226..d64ff7e96 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -203,15 +203,6 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_createArrayBuffer"] = function bjs_createArrayBuffer() { - try { - let ret = imports.createArrayBuffer(); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } TestModule["bjs_createWeirdObject"] = function bjs_createWeirdObject() { try { let ret = imports.createWeirdObject(); @@ -230,24 +221,6 @@ export async function createInstantiator(options, swift) { return 0 } } - TestModule["bjs_ArrayBufferLike_byteLength_get"] = function bjs_ArrayBufferLike_byteLength_get(self) { - try { - let ret = swift.memory.getObject(self).byteLength; - return ret; - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_ArrayBufferLike_slice"] = function bjs_ArrayBufferLike_slice(self, begin, end) { - try { - let ret = swift.memory.getObject(self).slice(begin, end); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } TestModule["bjs_WeirdNaming_normalProperty_get"] = function bjs_WeirdNaming_normalProperty_get(self) { try { let ret = swift.memory.getObject(self).normalProperty; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.d.ts similarity index 81% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.d.ts index 24d3d8fac..aaf227cf7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.d.ts @@ -10,9 +10,14 @@ export interface Greeter { name: string; readonly age: number; } +export interface Animatable { + animate(keyframes: any, options: any): any; + getAnimations(options: any): any; +} export type Exports = { } export type Imports = { + returnAnimatable(): Animatable; Greeter: { new(name: string): Greeter; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js similarity index 89% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index d83919051..096e3a345 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -203,6 +203,15 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_returnAnimatable"] = function bjs_returnAnimatable() { + try { + let ret = imports.returnAnimatable(); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } TestModule["bjs_Greeter_init"] = function bjs_Greeter_init(name) { try { const nameObject = swift.memory.getObject(name); @@ -258,6 +267,24 @@ export async function createInstantiator(options, swift) { setException(error); } } + TestModule["bjs_Animatable_animate"] = function bjs_Animatable_animate(self, keyframes, options) { + try { + let ret = swift.memory.getObject(self).animate(swift.memory.getObject(keyframes), swift.memory.getObject(options)); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_Animatable_getAnimations"] = function bjs_Animatable_getAnimations(self, options) { + try { + let ret = swift.memory.getObject(self).getAnimations(swift.memory.getObject(options)); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } }, setInstance: (i) => { instance = i; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts similarity index 60% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts index db6d2be05..3b2b5de99 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts @@ -4,15 +4,23 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -export interface JsGreeter { - greet(): string; +export interface StaticBox { + value(): number; +} +export interface WithCtor { } export type Exports = { } export type Imports = { - jsRoundTripNumber(v: number): number; - JsGreeter: { - new(name: string): JsGreeter; + StaticBox: { + create(value: number): StaticBox; + value(): number; + makeDefault(): StaticBox; + "with-dashes"(): StaticBox; + } + WithCtor: { + new(value: number): WithCtor; + create(value: number): WithCtor; } } export function createInstantiator(options: { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js similarity index 87% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 981cecbe5..cacaa87a3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -203,65 +203,62 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_asyncReturnVoid"] = function bjs_asyncReturnVoid() { + TestModule["bjs_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { try { - let ret = imports.asyncReturnVoid(); + let ret = imports.StaticBox.create(value); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripInt"] = function bjs_asyncRoundTripInt(v) { + TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { try { - let ret = imports.asyncRoundTripInt(v); - return swift.memory.retain(ret); + let ret = imports.StaticBox.value(); + return ret; } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(v) { + TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { try { - const vObject = swift.memory.getObject(v); - swift.memory.release(v); - let ret = imports.asyncRoundTripString(vObject); + let ret = imports.StaticBox.makeDefault(); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripBool"] = function bjs_asyncRoundTripBool(v) { + TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { try { - let ret = imports.asyncRoundTripBool(v !== 0); + let ret = imports.StaticBox["with-dashes"](); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripFloat"] = function bjs_asyncRoundTripFloat(v) { + TestModule["bjs_StaticBox_value"] = function bjs_StaticBox_value(self) { try { - let ret = imports.asyncRoundTripFloat(v); - return swift.memory.retain(ret); + let ret = swift.memory.getObject(self).value(); + return ret; } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripDouble"] = function bjs_asyncRoundTripDouble(v) { + TestModule["bjs_WithCtor_init"] = function bjs_WithCtor_init(value) { try { - let ret = imports.asyncRoundTripDouble(v); - return swift.memory.retain(ret); + return swift.memory.retain(new imports.WithCtor(value)); } catch (error) { setException(error); return 0 } } - TestModule["bjs_asyncRoundTripJSObject"] = function bjs_asyncRoundTripJSObject(v) { + TestModule["bjs_WithCtor_create_static"] = function bjs_WithCtor_create_static(value) { try { - let ret = imports.asyncRoundTripJSObject(swift.memory.getObject(v)); + let ret = imports.WithCtor.create(value); return swift.memory.retain(ret); } catch (error) { setException(error); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts new file mode 100644 index 000000000..f4c13c610 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts @@ -0,0 +1,40 @@ +// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// `swift package bridge-js`. + +/// Represents a Swift heap object like a class instance or an actor instance. +export interface SwiftHeapObject { + /// Release the heap object. + /// + /// Note: Calling this method will release the heap object and it will no longer be accessible. + release(): void; +} +export interface JSValueHolder extends SwiftHeapObject { + update(value: any, optionalValue: any | null): void; + echo(value: any): any; + echoOptional(value: any | null): any | null; + value: any; + optionalValue: any | null; +} +export type Exports = { + JSValueHolder: { + new(value: any, optionalValue: any | null): JSValueHolder; + } + roundTripJSValue(value: any): any; + roundTripOptionalJSValue(value: any | null): any | null; + roundTripJSValueArray(values: any[]): any[]; + roundTripOptionalJSValueArray(values: any[] | null): any[] | null; +} +export type Imports = { + jsEchoJSValue(value: any): any; + jsEchoJSValueArray(values: any[]): any[]; +} +export function createInstantiator(options: { + imports: Imports; +}, swift: any): Promise<{ + addImports: (importObject: WebAssembly.Imports) => void; + setInstance: (instance: WebAssembly.Instance) => void; + createExports: (instance: WebAssembly.Instance) => Exports; +}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js new file mode 100644 index 000000000..f5c360bb0 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -0,0 +1,539 @@ +// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, +// DO NOT EDIT. +// +// To update this file, just rebuild your project or run +// `swift package bridge-js`. + +export async function createInstantiator(options, swift) { + let instance; + let memory; + let setException; + const textDecoder = new TextDecoder("utf-8"); + const textEncoder = new TextEncoder("utf-8"); + let tmpRetString; + let tmpRetBytes; + let tmpRetException; + let tmpRetOptionalBool; + let tmpRetOptionalInt; + let tmpRetOptionalFloat; + let tmpRetOptionalDouble; + let tmpRetOptionalHeapObject; + let tmpRetTag = []; + let tmpRetStrings = []; + let tmpRetInts = []; + let tmpRetF32s = []; + let tmpRetF64s = []; + let tmpParamInts = []; + let tmpParamF32s = []; + let tmpParamF64s = []; + let tmpRetPointers = []; + let tmpParamPointers = []; + let tmpStructCleanups = []; + const enumHelpers = {}; + const structHelpers = {}; + + let _exports = null; + let bjs = null; + function __bjs_jsValueLower(value) { + let kind; + let payload1; + let payload2; + if (value === null) { + kind = 4; + payload1 = 0; + payload2 = 0; + } else { + switch (typeof value) { + case "boolean": + kind = 0; + payload1 = value ? 1 : 0; + payload2 = 0; + break; + case "number": + kind = 2; + payload1 = 0; + payload2 = value; + break; + case "string": + kind = 1; + payload1 = swift.memory.retain(value); + payload2 = 0; + break; + case "undefined": + kind = 5; + payload1 = 0; + payload2 = 0; + break; + case "object": + kind = 3; + payload1 = swift.memory.retain(value); + payload2 = 0; + break; + case "function": + kind = 3; + payload1 = swift.memory.retain(value); + payload2 = 0; + break; + case "symbol": + kind = 7; + payload1 = swift.memory.retain(value); + payload2 = 0; + break; + case "bigint": + kind = 8; + payload1 = swift.memory.retain(value); + payload2 = 0; + break; + default: + throw new TypeError("Unsupported JSValue type"); + } + } + return [kind, payload1, payload2]; + } + function __bjs_jsValueLift(kind, payload1, payload2) { + let jsValue; + switch (kind) { + case 0: + jsValue = payload1 !== 0; + break; + case 1: + jsValue = swift.memory.getObject(payload1); + break; + case 2: + jsValue = payload2; + break; + case 3: + jsValue = swift.memory.getObject(payload1); + break; + case 4: + jsValue = null; + break; + case 5: + jsValue = undefined; + break; + case 7: + jsValue = swift.memory.getObject(payload1); + break; + case 8: + jsValue = swift.memory.getObject(payload1); + break; + default: + throw new TypeError("Unsupported JSValue kind " + kind); + } + return jsValue; + } + + + return { + /** + * @param {WebAssembly.Imports} importObject + */ + addImports: (importObject, importsContext) => { + bjs = {}; + importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); + bjs["swift_js_return_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + tmpRetString = textDecoder.decode(bytes); + } + bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { + const source = swift.memory.getObject(sourceId); + const bytes = new Uint8Array(memory.buffer, bytesPtr); + bytes.set(source); + } + bjs["swift_js_make_js_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + return swift.memory.retain(textDecoder.decode(bytes)); + } + bjs["swift_js_init_memory_with_result"] = function(ptr, len) { + const target = new Uint8Array(memory.buffer, ptr, len); + target.set(tmpRetBytes); + tmpRetBytes = undefined; + } + bjs["swift_js_throw"] = function(id) { + tmpRetException = swift.memory.retainByRef(id); + } + bjs["swift_js_retain"] = function(id) { + return swift.memory.retainByRef(id); + } + bjs["swift_js_release"] = function(id) { + swift.memory.release(id); + } + bjs["swift_js_push_tag"] = function(tag) { + tmpRetTag.push(tag); + } + bjs["swift_js_push_i32"] = function(v) { + tmpRetInts.push(v | 0); + } + bjs["swift_js_push_f32"] = function(v) { + tmpRetF32s.push(Math.fround(v)); + } + bjs["swift_js_push_f64"] = function(v) { + tmpRetF64s.push(v); + } + bjs["swift_js_push_string"] = function(ptr, len) { + const bytes = new Uint8Array(memory.buffer, ptr, len); + const value = textDecoder.decode(bytes); + tmpRetStrings.push(value); + } + bjs["swift_js_pop_i32"] = function() { + return tmpParamInts.pop(); + } + bjs["swift_js_pop_f32"] = function() { + return tmpParamF32s.pop(); + } + bjs["swift_js_pop_f64"] = function() { + return tmpParamF64s.pop(); + } + bjs["swift_js_push_pointer"] = function(pointer) { + tmpRetPointers.push(pointer); + } + bjs["swift_js_pop_pointer"] = function() { + return tmpParamPointers.pop(); + } + bjs["swift_js_struct_cleanup"] = function(cleanupId) { + if (cleanupId === 0) { return; } + const index = (cleanupId | 0) - 1; + const cleanup = tmpStructCleanups[index]; + tmpStructCleanups[index] = null; + if (cleanup) { cleanup(); } + while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { + tmpStructCleanups.pop(); + } + } + bjs["swift_js_return_optional_bool"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalBool = null; + } else { + tmpRetOptionalBool = value !== 0; + } + } + bjs["swift_js_return_optional_int"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalInt = null; + } else { + tmpRetOptionalInt = value | 0; + } + } + bjs["swift_js_return_optional_float"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalFloat = null; + } else { + tmpRetOptionalFloat = Math.fround(value); + } + } + bjs["swift_js_return_optional_double"] = function(isSome, value) { + if (isSome === 0) { + tmpRetOptionalDouble = null; + } else { + tmpRetOptionalDouble = value; + } + } + bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { + if (isSome === 0) { + tmpRetString = null; + } else { + const bytes = new Uint8Array(memory.buffer, ptr, len); + tmpRetString = textDecoder.decode(bytes); + } + } + bjs["swift_js_return_optional_object"] = function(isSome, objectId) { + if (isSome === 0) { + tmpRetString = null; + } else { + tmpRetString = swift.memory.getObject(objectId); + } + } + bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { + if (isSome === 0) { + tmpRetOptionalHeapObject = null; + } else { + tmpRetOptionalHeapObject = pointer; + } + } + bjs["swift_js_get_optional_int_presence"] = function() { + return tmpRetOptionalInt != null ? 1 : 0; + } + bjs["swift_js_get_optional_int_value"] = function() { + const value = tmpRetOptionalInt; + tmpRetOptionalInt = undefined; + return value; + } + bjs["swift_js_get_optional_string"] = function() { + const str = tmpRetString; + tmpRetString = undefined; + if (str == null) { + return -1; + } else { + const bytes = textEncoder.encode(str); + tmpRetBytes = bytes; + return bytes.length; + } + } + bjs["swift_js_get_optional_float_presence"] = function() { + return tmpRetOptionalFloat != null ? 1 : 0; + } + bjs["swift_js_get_optional_float_value"] = function() { + const value = tmpRetOptionalFloat; + tmpRetOptionalFloat = undefined; + return value; + } + bjs["swift_js_get_optional_double_presence"] = function() { + return tmpRetOptionalDouble != null ? 1 : 0; + } + bjs["swift_js_get_optional_double_value"] = function() { + const value = tmpRetOptionalDouble; + tmpRetOptionalDouble = undefined; + return value; + } + bjs["swift_js_get_optional_heap_object_pointer"] = function() { + const pointer = tmpRetOptionalHeapObject; + tmpRetOptionalHeapObject = undefined; + return pointer || 0; + } + // Wrapper functions for module: TestModule + if (!importObject["TestModule"]) { + importObject["TestModule"] = {}; + } + importObject["TestModule"]["bjs_JSValueHolder_wrap"] = function(pointer) { + const obj = JSValueHolder.__construct(pointer); + return swift.memory.retain(obj); + }; + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_jsEchoJSValue"] = function bjs_jsEchoJSValue(valueKind, valuePayload1, valuePayload2) { + try { + const jsValue = __bjs_jsValueLift(valueKind, valuePayload1, valuePayload2); + let ret = imports.jsEchoJSValue(jsValue); + const [retKind, retPayload1, retPayload2] = __bjs_jsValueLower(ret); + tmpParamInts.push(retKind); + tmpParamInts.push(retPayload1); + tmpParamF64s.push(retPayload2); + } catch (error) { + setException(error); + } + } + TestModule["bjs_jsEchoJSValueArray"] = function bjs_jsEchoJSValueArray() { + try { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + arrayResult.push(jsValue); + } + arrayResult.reverse(); + let ret = imports.jsEchoJSValueArray(arrayResult); + const arrayCleanups = []; + for (const elem of ret) { + const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); + tmpParamInts.push(elemKind); + tmpParamInts.push(elemPayload1); + tmpParamF64s.push(elemPayload2); + } + tmpParamInts.push(ret.length); + } catch (error) { + setException(error); + } + } + }, + setInstance: (i) => { + instance = i; + memory = instance.exports.memory; + + setException = (error) => { + instance.exports._swift_js_exception.value = swift.memory.retain(error) + } + }, + /** @param {WebAssembly.Instance} instance */ + createExports: (instance) => { + const js = swift.memory.heap; + /// Represents a Swift heap object like a class instance or an actor instance. + class SwiftHeapObject { + static __wrap(pointer, deinit, prototype) { + const obj = Object.create(prototype); + obj.pointer = pointer; + obj.hasReleased = false; + obj.deinit = deinit; + obj.registry = new FinalizationRegistry((pointer) => { + deinit(pointer); + }); + obj.registry.register(this, obj.pointer); + return obj; + } + + release() { + this.registry.unregister(this); + this.deinit(this.pointer); + } + } + class JSValueHolder extends SwiftHeapObject { + static __construct(ptr) { + return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_JSValueHolder_deinit, JSValueHolder.prototype); + } + + constructor(value, optionalValue) { + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + const isSome = optionalValue != null; + const [optionalValueKind, optionalValuePayload1, optionalValuePayload2] = __bjs_jsValueLower(optionalValue); + const ret = instance.exports.bjs_JSValueHolder_init(valueKind, valuePayload1, valuePayload2, +isSome, optionalValueKind, optionalValuePayload1, optionalValuePayload2); + return JSValueHolder.__construct(ret); + } + update(value, optionalValue) { + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + const isSome = optionalValue != null; + const [optionalValueKind, optionalValuePayload1, optionalValuePayload2] = __bjs_jsValueLower(optionalValue); + instance.exports.bjs_JSValueHolder_update(this.pointer, valueKind, valuePayload1, valuePayload2, +isSome, optionalValueKind, optionalValuePayload1, optionalValuePayload2); + } + echo(value) { + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_JSValueHolder_echo(this.pointer, valueKind, valuePayload1, valuePayload2); + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + return jsValue; + } + echoOptional(value) { + const isSome = value != null; + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_JSValueHolder_echoOptional(this.pointer, +isSome, valueKind, valuePayload1, valuePayload2); + const isSome1 = tmpRetInts.pop(); + let optResult; + if (isSome1) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + optResult = jsValue; + } else { + optResult = null; + } + return optResult; + } + get value() { + instance.exports.bjs_JSValueHolder_value_get(this.pointer); + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + return jsValue; + } + set value(value) { + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_JSValueHolder_value_set(this.pointer, valueKind, valuePayload1, valuePayload2); + } + get optionalValue() { + instance.exports.bjs_JSValueHolder_optionalValue_get(this.pointer); + const isSome = tmpRetInts.pop(); + let optResult; + if (isSome) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + optResult = jsValue; + } else { + optResult = null; + } + return optResult; + } + set optionalValue(value) { + const isSome = value != null; + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_JSValueHolder_optionalValue_set(this.pointer, +isSome, valueKind, valuePayload1, valuePayload2); + } + } + const exports = { + JSValueHolder, + roundTripJSValue: function bjs_roundTripJSValue(value) { + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_roundTripJSValue(valueKind, valuePayload1, valuePayload2); + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + return jsValue; + }, + roundTripOptionalJSValue: function bjs_roundTripOptionalJSValue(value) { + const isSome = value != null; + const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); + instance.exports.bjs_roundTripOptionalJSValue(+isSome, valueKind, valuePayload1, valuePayload2); + const isSome1 = tmpRetInts.pop(); + let optResult; + if (isSome1) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + optResult = jsValue; + } else { + optResult = null; + } + return optResult; + }, + roundTripJSValueArray: function bjs_roundTripJSValueArray(values) { + const arrayCleanups = []; + for (const elem of values) { + const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); + tmpParamInts.push(elemKind); + tmpParamInts.push(elemPayload1); + tmpParamF64s.push(elemPayload2); + } + tmpParamInts.push(values.length); + instance.exports.bjs_roundTripJSValueArray(); + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + arrayResult.push(jsValue); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, + roundTripOptionalJSValueArray: function bjs_roundTripOptionalJSValueArray(values) { + const isSome = values != null; + const valuesCleanups = []; + if (isSome) { + const arrayCleanups = []; + for (const elem of values) { + const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); + tmpParamInts.push(elemKind); + tmpParamInts.push(elemPayload1); + tmpParamF64s.push(elemPayload2); + } + tmpParamInts.push(values.length); + valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); + } + instance.exports.bjs_roundTripOptionalJSValueArray(+isSome); + const isSome1 = tmpRetInts.pop(); + let optResult; + if (isSome1) { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i = 0; i < arrayLen; i++) { + const jsValuePayload2 = tmpRetF64s.pop(); + const jsValuePayload1 = tmpRetInts.pop(); + const jsValueKind = tmpRetInts.pop(); + const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); + arrayResult.push(jsValue); + } + arrayResult.reverse(); + optResult = arrayResult; + } else { + optResult = null; + } + for (const cleanup of valuesCleanups) { cleanup(); } + return optResult; + }, + }; + _exports = exports; + return exports; + }, + } +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index f079de1da..4ac3b11b7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -234,7 +234,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -244,7 +244,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_GlobalClass_deinit, GlobalClass.prototype); } - + constructor() { const ret = instance.exports.bjs_GlobalClass_init(); return GlobalClass.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 2c43b91e8..9eb55f30b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -242,7 +242,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -252,7 +252,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_GlobalClass_deinit, GlobalClass.prototype); } - + constructor() { const ret = instance.exports.bjs_GlobalClass_init(); return GlobalClass.__construct(ret); @@ -268,7 +268,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PrivateClass_deinit, PrivateClass.prototype); } - + constructor() { const ret = instance.exports.bjs_PrivateClass_init(); return PrivateClass.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 4b8ce8a66..e81a95669 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -234,7 +234,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -244,7 +244,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PrivateClass_deinit, PrivateClass.prototype); } - + constructor() { const ret = instance.exports.bjs_PrivateClass_init(); return PrivateClass.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.d.ts deleted file mode 100644 index 83fe3c141..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export interface DatabaseConnection { - connect(url: string): void; - execute(query: string): any; - readonly isConnected: boolean; - connectionTimeout: number; -} -export interface Logger { - log(message: string): void; - error(message: string, error: any): void; - readonly level: string; -} -export interface ConfigManager { - get(key: string): any; - set(key: string, value: any): void; - readonly configPath: string; -} -export type Exports = { -} -export type Imports = { - createDatabaseConnection(config: any): DatabaseConnection; - createLogger(level: string): Logger; - getConfigManager(): ConfigManager; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.js deleted file mode 100644 index f8cfd7366..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.js +++ /dev/null @@ -1,354 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_createDatabaseConnection"] = function bjs_createDatabaseConnection(config) { - try { - let ret = imports.createDatabaseConnection(swift.memory.getObject(config)); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_createLogger"] = function bjs_createLogger(level) { - try { - const levelObject = swift.memory.getObject(level); - swift.memory.release(level); - let ret = imports.createLogger(levelObject); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_getConfigManager"] = function bjs_getConfigManager() { - try { - let ret = imports.getConfigManager(); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_DatabaseConnection_isConnected_get"] = function bjs_DatabaseConnection_isConnected_get(self) { - try { - let ret = swift.memory.getObject(self).isConnected; - return ret ? 1 : 0; - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_DatabaseConnection_connectionTimeout_get"] = function bjs_DatabaseConnection_connectionTimeout_get(self) { - try { - let ret = swift.memory.getObject(self).connectionTimeout; - return ret; - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_DatabaseConnection_connectionTimeout_set"] = function bjs_DatabaseConnection_connectionTimeout_set(self, newValue) { - try { - swift.memory.getObject(self).connectionTimeout = newValue; - } catch (error) { - setException(error); - } - } - TestModule["bjs_DatabaseConnection_connect"] = function bjs_DatabaseConnection_connect(self, url) { - try { - const urlObject = swift.memory.getObject(url); - swift.memory.release(url); - swift.memory.getObject(self).connect(urlObject); - } catch (error) { - setException(error); - } - } - TestModule["bjs_DatabaseConnection_execute"] = function bjs_DatabaseConnection_execute(self, query) { - try { - const queryObject = swift.memory.getObject(query); - swift.memory.release(query); - let ret = swift.memory.getObject(self).execute(queryObject); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_Logger_level_get"] = function bjs_Logger_level_get(self) { - try { - let ret = swift.memory.getObject(self).level; - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - TestModule["bjs_Logger_log"] = function bjs_Logger_log(self, message) { - try { - const messageObject = swift.memory.getObject(message); - swift.memory.release(message); - swift.memory.getObject(self).log(messageObject); - } catch (error) { - setException(error); - } - } - TestModule["bjs_Logger_error"] = function bjs_Logger_error(self, message, error) { - try { - const messageObject = swift.memory.getObject(message); - swift.memory.release(message); - swift.memory.getObject(self).error(messageObject, swift.memory.getObject(error)); - } catch (error) { - setException(error); - } - } - TestModule["bjs_ConfigManager_configPath_get"] = function bjs_ConfigManager_configPath_get(self) { - try { - let ret = swift.memory.getObject(self).configPath; - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - TestModule["bjs_ConfigManager_get"] = function bjs_ConfigManager_get(self, key) { - try { - const keyObject = swift.memory.getObject(key); - swift.memory.release(key); - let ret = swift.memory.getObject(self).get(keyObject); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_ConfigManager_set"] = function bjs_ConfigManager_set(self, key, value) { - try { - const keyObject = swift.memory.getObject(key); - swift.memory.release(key); - swift.memory.getObject(self).set(keyObject, swift.memory.getObject(value)); - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index 671868eab..c8d0b935e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -242,7 +242,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -252,7 +252,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -271,7 +271,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype); } - + constructor() { const ret = instance.exports.bjs_Converter_init(); return Converter.__construct(ret); @@ -287,7 +287,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_UUID_deinit, UUID.prototype); } - + uuidString() { instance.exports.bjs_UUID_uuidString(this.pointer); const ret = tmpRetString; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index ae7bf7451..bb2c93649 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -242,7 +242,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -252,7 +252,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -271,7 +271,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Converter_deinit, Converter.prototype); } - + constructor() { const ret = instance.exports.bjs_Converter_init(); return Converter.__construct(ret); @@ -287,7 +287,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_UUID_deinit, UUID.prototype); } - + uuidString() { instance.exports.bjs_UUID_uuidString(this.pointer); const ret = tmpRetString; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.d.ts similarity index 68% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.d.ts index 5f63e9db5..b1a67ccde 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.d.ts @@ -21,6 +21,24 @@ export interface OptionalPropertyHolder extends SwiftHeapObject { optionalAge: number | null; optionalGreeter: Greeter | null; } +export interface WithOptionalJSClass { + roundTripStringOrNull(value: string | null): string | null; + roundTripStringOrUndefined(value: string | undefined): string | undefined; + roundTripDoubleOrNull(value: number | null): number | null; + roundTripDoubleOrUndefined(value: number | undefined): number | undefined; + roundTripBoolOrNull(value: boolean | null): boolean | null; + roundTripBoolOrUndefined(value: boolean | undefined): boolean | undefined; + roundTripIntOrNull(value: number | null): number | null; + roundTripIntOrUndefined(value: number | undefined): number | undefined; + stringOrNull: string | null; + stringOrUndefined: string | undefined; + doubleOrNull: number | null; + doubleOrUndefined: number | undefined; + boolOrNull: boolean | null; + boolOrUndefined: boolean | undefined; + intOrNull: number | null; + intOrUndefined: number | undefined; +} export type Exports = { Greeter: { new(name: string | null): Greeter; @@ -45,6 +63,9 @@ export type Exports = { testMixedOptionals(firstName: string | null, lastName: string | null, age: number | null, active: boolean): string | null; } export type Imports = { + WithOptionalJSClass: { + new(valueOrNull: string | null, valueOrUndefined: string | undefined): WithOptionalJSClass; + } } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js similarity index 63% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 2c08e3d9f..0d45b2169 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -42,6 +42,7 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); bjs["swift_js_return_string"] = function(ptr, len) { const bytes = new Uint8Array(memory.buffer, ptr, len); tmpRetString = textDecoder.decode(bytes); @@ -70,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -213,6 +214,261 @@ export async function createInstantiator(options, swift) { const obj = OptionalPropertyHolder.__construct(pointer); return swift.memory.retain(obj); }; + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_WithOptionalJSClass_init"] = function bjs_WithOptionalJSClass_init(valueOrNullIsSome, valueOrNullWrappedValue, valueOrUndefinedIsSome, valueOrUndefinedWrappedValue) { + try { + let obj; + if (valueOrNullIsSome) { + obj = swift.memory.getObject(valueOrNullWrappedValue); + swift.memory.release(valueOrNullWrappedValue); + } + let obj1; + if (valueOrUndefinedIsSome) { + obj1 = swift.memory.getObject(valueOrUndefinedWrappedValue); + swift.memory.release(valueOrUndefinedWrappedValue); + } + return swift.memory.retain(new imports.WithOptionalJSClass(valueOrNullIsSome ? obj : null, valueOrUndefinedIsSome ? obj1 : undefined)); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_WithOptionalJSClass_stringOrNull_get"] = function bjs_WithOptionalJSClass_stringOrNull_get(self) { + try { + let ret = swift.memory.getObject(self).stringOrNull; + const isSome = ret != null; + if (isSome) { + tmpRetString = ret; + } else { + tmpRetString = null; + } + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_stringOrUndefined_get"] = function bjs_WithOptionalJSClass_stringOrUndefined_get(self) { + try { + let ret = swift.memory.getObject(self).stringOrUndefined; + const isSome = ret !== undefined; + if (isSome) { + tmpRetString = ret; + } else { + tmpRetString = null; + } + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_doubleOrNull_get"] = function bjs_WithOptionalJSClass_doubleOrNull_get(self) { + try { + let ret = swift.memory.getObject(self).doubleOrNull; + const isSome = ret != null; + bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_doubleOrUndefined_get"] = function bjs_WithOptionalJSClass_doubleOrUndefined_get(self) { + try { + let ret = swift.memory.getObject(self).doubleOrUndefined; + const isSome = ret !== undefined; + bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_boolOrNull_get"] = function bjs_WithOptionalJSClass_boolOrNull_get(self) { + try { + let ret = swift.memory.getObject(self).boolOrNull; + const isSome = ret != null; + bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_boolOrUndefined_get"] = function bjs_WithOptionalJSClass_boolOrUndefined_get(self) { + try { + let ret = swift.memory.getObject(self).boolOrUndefined; + const isSome = ret !== undefined; + bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_intOrNull_get"] = function bjs_WithOptionalJSClass_intOrNull_get(self) { + try { + let ret = swift.memory.getObject(self).intOrNull; + const isSome = ret != null; + bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_intOrUndefined_get"] = function bjs_WithOptionalJSClass_intOrUndefined_get(self) { + try { + let ret = swift.memory.getObject(self).intOrUndefined; + const isSome = ret !== undefined; + bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_stringOrNull_set"] = function bjs_WithOptionalJSClass_stringOrNull_set(self, newValueIsSome, newValueWrappedValue) { + try { + let obj; + if (newValueIsSome) { + obj = swift.memory.getObject(newValueWrappedValue); + swift.memory.release(newValueWrappedValue); + } + swift.memory.getObject(self).stringOrNull = newValueIsSome ? obj : null; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_stringOrUndefined_set"] = function bjs_WithOptionalJSClass_stringOrUndefined_set(self, newValueIsSome, newValueWrappedValue) { + try { + let obj; + if (newValueIsSome) { + obj = swift.memory.getObject(newValueWrappedValue); + swift.memory.release(newValueWrappedValue); + } + swift.memory.getObject(self).stringOrUndefined = newValueIsSome ? obj : undefined; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_doubleOrNull_set"] = function bjs_WithOptionalJSClass_doubleOrNull_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).doubleOrNull = newValueIsSome ? newValueWrappedValue : null; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_doubleOrUndefined_set"] = function bjs_WithOptionalJSClass_doubleOrUndefined_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).doubleOrUndefined = newValueIsSome ? newValueWrappedValue : undefined; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_boolOrNull_set"] = function bjs_WithOptionalJSClass_boolOrNull_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).boolOrNull = newValueIsSome ? newValueWrappedValue !== 0 : null; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_boolOrUndefined_set"] = function bjs_WithOptionalJSClass_boolOrUndefined_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).boolOrUndefined = newValueIsSome ? newValueWrappedValue !== 0 : undefined; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_intOrNull_set"] = function bjs_WithOptionalJSClass_intOrNull_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).intOrNull = newValueIsSome ? newValueWrappedValue : null; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_intOrUndefined_set"] = function bjs_WithOptionalJSClass_intOrUndefined_set(self, newValueIsSome, newValueWrappedValue) { + try { + swift.memory.getObject(self).intOrUndefined = newValueIsSome ? newValueWrappedValue : undefined; + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripStringOrNull"] = function bjs_WithOptionalJSClass_roundTripStringOrNull(self, valueIsSome, valueWrappedValue) { + try { + let obj; + if (valueIsSome) { + obj = swift.memory.getObject(valueWrappedValue); + swift.memory.release(valueWrappedValue); + } + let ret = swift.memory.getObject(self).roundTripStringOrNull(valueIsSome ? obj : null); + const isSome = ret != null; + if (isSome) { + tmpRetString = ret; + } else { + tmpRetString = null; + } + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripStringOrUndefined"] = function bjs_WithOptionalJSClass_roundTripStringOrUndefined(self, valueIsSome, valueWrappedValue) { + try { + let obj; + if (valueIsSome) { + obj = swift.memory.getObject(valueWrappedValue); + swift.memory.release(valueWrappedValue); + } + let ret = swift.memory.getObject(self).roundTripStringOrUndefined(valueIsSome ? obj : undefined); + const isSome = ret !== undefined; + if (isSome) { + tmpRetString = ret; + } else { + tmpRetString = null; + } + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripDoubleOrNull"] = function bjs_WithOptionalJSClass_roundTripDoubleOrNull(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripDoubleOrNull(valueIsSome ? valueWrappedValue : null); + const isSome = ret != null; + bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripDoubleOrUndefined"] = function bjs_WithOptionalJSClass_roundTripDoubleOrUndefined(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripDoubleOrUndefined(valueIsSome ? valueWrappedValue : undefined); + const isSome = ret !== undefined; + bjs["swift_js_return_optional_double"](isSome ? 1 : 0, isSome ? ret : 0.0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripBoolOrNull"] = function bjs_WithOptionalJSClass_roundTripBoolOrNull(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripBoolOrNull(valueIsSome ? valueWrappedValue !== 0 : null); + const isSome = ret != null; + bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripBoolOrUndefined"] = function bjs_WithOptionalJSClass_roundTripBoolOrUndefined(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripBoolOrUndefined(valueIsSome ? valueWrappedValue !== 0 : undefined); + const isSome = ret !== undefined; + bjs["swift_js_return_optional_bool"](isSome ? 1 : 0, isSome ? (ret ? 1 : 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripIntOrNull"] = function bjs_WithOptionalJSClass_roundTripIntOrNull(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripIntOrNull(valueIsSome ? valueWrappedValue : null); + const isSome = ret != null; + bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0); + } catch (error) { + setException(error); + } + } + TestModule["bjs_WithOptionalJSClass_roundTripIntOrUndefined"] = function bjs_WithOptionalJSClass_roundTripIntOrUndefined(self, valueIsSome, valueWrappedValue) { + try { + let ret = swift.memory.getObject(self).roundTripIntOrUndefined(valueIsSome ? valueWrappedValue : undefined); + const isSome = ret !== undefined; + bjs["swift_js_return_optional_int"](isSome ? 1 : 0, isSome ? (ret | 0) : 0); + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { instance = i; @@ -238,7 +494,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -248,7 +504,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype); } - + constructor(name) { const isSome = name != null; let nameId, nameBytes; @@ -303,7 +559,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_OptionalPropertyHolder_deinit, OptionalPropertyHolder.prototype); } - + constructor() { const ret = instance.exports.bjs_OptionalPropertyHolder_init(); return OptionalPropertyHolder.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.js deleted file mode 100644 index 0a92510f7..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.js +++ /dev/null @@ -1,225 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - check: function bjs_check(a, b, c, d, e) { - instance.exports.bjs_check(a, b, c, d, e); - }, - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.d.ts similarity index 93% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.d.ts index 9bf0e1e35..961f97635 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.d.ts @@ -8,6 +8,7 @@ export type Exports = { check(a: number, b: number, c: number, d: number, e: boolean): void; } export type Imports = { + check(a: number, b: boolean): void; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js similarity index 97% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index fe6c3ae04..2d754a5c3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -223,6 +223,9 @@ export async function createInstantiator(options, swift) { createExports: (instance) => { const js = swift.memory.heap; const exports = { + check: function bjs_check(a, b, c, d, e) { + instance.exports.bjs_check(a, b, c, d, e); + }, }; _exports = exports; return exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.d.ts deleted file mode 100644 index ad63bd7d0..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { -} -export type Imports = { - checkNumber(): number; - checkBoolean(): boolean; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.d.ts similarity index 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.d.ts index c726e1f5a..77e269d16 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.d.ts @@ -12,6 +12,8 @@ export type Exports = { checkBool(): boolean; } export type Imports = { + checkNumber(): number; + checkBoolean(): boolean; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js similarity index 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index 836a82f21..f348869b2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -42,6 +42,7 @@ export async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { bjs = {}; importObject["bjs"] = bjs; + const imports = options.getImports(importsContext); bjs["swift_js_return_string"] = function(ptr, len) { const bytes = new Uint8Array(memory.buffer, ptr, len); tmpRetString = textDecoder.decode(bytes); @@ -70,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -201,6 +202,25 @@ export async function createInstantiator(options, swift) { tmpRetOptionalHeapObject = undefined; return pointer || 0; } + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_checkNumber"] = function bjs_checkNumber() { + try { + let ret = imports.checkNumber(); + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_checkBoolean"] = function bjs_checkBoolean() { + try { + let ret = imports.checkBoolean(); + return ret ? 1 : 0; + } catch (error) { + setException(error); + return 0 + } + } }, setInstance: (i) => { instance = i; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index fc13a471a..7be6cd924 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -234,7 +234,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -244,7 +244,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PropertyHolder_deinit, PropertyHolder.prototype); } - + constructor(intValue, floatValue, doubleValue, boolValue, stringValue, jsObject) { const stringValueBytes = textEncoder.encode(stringValue); const stringValueId = swift.memory.retain(stringValueBytes); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js similarity index 93% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 24c02750f..7c20130b3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -22,46 +22,6 @@ export const ResultValues = { Failure: 1, }, }; - -const __bjs_createResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case ResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: ResultValues.Tag.Success, cleanup }; - } - case ResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Failure, cleanup }; - } - default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case ResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: ResultValues.Tag.Success, param0: string }; - } - case ResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - return { tag: ResultValues.Tag.Failure, param0: int }; - } - default: throw new Error("Unknown ResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; export const PriorityValues = { Low: -1, Medium: 0, @@ -82,7 +42,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -95,9 +55,48 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; + const __bjs_createResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case ResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: ResultValues.Tag.Success, cleanup }; + } + case ResultValues.Tag.Failure: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: ResultValues.Tag.Failure, cleanup }; + } + default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case ResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: ResultValues.Tag.Success, param0: string }; + } + case ResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + return { tag: ResultValues.Tag.Failure, param0: int }; + } + default: throw new Error("Unknown ResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; return { /** @@ -134,7 +133,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -376,7 +375,7 @@ export async function createInstantiator(options, swift) { } TestModule["bjs_MyViewControllerDelegate_result_set"] = function bjs_MyViewControllerDelegate_result_set(self, value) { try { - const enumValue = enumHelpers.Result.lift(value, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const enumValue = enumHelpers.Result.lift(value, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); swift.memory.getObject(self).result = enumValue; } catch (error) { setException(error); @@ -400,7 +399,7 @@ export async function createInstantiator(options, swift) { try { let enumValue; if (valueIsSome) { - enumValue = enumHelpers.Result.lift(valueWrappedValue, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + enumValue = enumHelpers.Result.lift(valueWrappedValue, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } swift.memory.getObject(self).optionalResult = valueIsSome ? enumValue : null; } catch (error) { @@ -557,7 +556,7 @@ export async function createInstantiator(options, swift) { } TestModule["bjs_MyViewControllerDelegate_handleResult"] = function bjs_MyViewControllerDelegate_handleResult(self, result) { try { - const enumValue = enumHelpers.Result.lift(result, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const enumValue = enumHelpers.Result.lift(result, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); swift.memory.getObject(self).handleResult(enumValue); } catch (error) { setException(error); @@ -577,9 +576,6 @@ export async function createInstantiator(options, swift) { instance = i; memory = instance.exports.memory; - const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.Result = ResultHelpers; - setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) } @@ -600,7 +596,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -610,7 +606,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Helper_deinit, Helper.prototype); } - + constructor(value) { const ret = instance.exports.bjs_Helper_init(value); return Helper.__construct(ret); @@ -630,7 +626,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_MyViewController_deinit, MyViewController.prototype); } - + constructor(delegate) { const ret = instance.exports.bjs_MyViewController_init(swift.memory.retain(delegate)); return MyViewController.__construct(ret); @@ -688,7 +684,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_DelegateManager_deinit, DelegateManager.prototype); } - + constructor(delegates) { const arrayCleanups = []; for (const elem of delegates) { @@ -727,6 +723,9 @@ export async function createInstantiator(options, swift) { for (const cleanup of arrayCleanups) { cleanup(); } } } + const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.Result = ResultHelpers; + const exports = { Helper, MyViewController, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.js deleted file mode 100644 index 94e22ffc4..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.js +++ /dev/null @@ -1,252 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_jsRoundTripNumber"] = function bjs_jsRoundTripNumber(v) { - try { - let ret = imports.jsRoundTripNumber(v); - return ret; - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_JsGreeter_init"] = function bjs_JsGreeter_init(name) { - try { - const nameObject = swift.memory.getObject(name); - swift.memory.release(name); - return swift.memory.retain(new imports.JsGreeter(nameObject)); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_JsGreeter_greet"] = function bjs_JsGreeter_greet(self) { - try { - let ret = swift.memory.getObject(self).greet(); - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js similarity index 85% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index e7bebfe6c..391c7167e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -15,46 +15,6 @@ export const APIResultValues = { Failure: 1, }, }; - -const __bjs_createAPIResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case APIResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: APIResultValues.Tag.Success, cleanup }; - } - case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; - } - default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: APIResultValues.Tag.Success, param0: string }; - } - case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Failure, param0: int }; - } - default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; export async function createInstantiator(options, swift) { let instance; let memory; @@ -69,7 +29,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -82,9 +42,48 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; + const __bjs_createAPIResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case APIResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: APIResultValues.Tag.Success, cleanup }; + } + case APIResultValues.Tag.Failure: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Failure, cleanup }; + } + default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case APIResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: APIResultValues.Tag.Success, param0: string }; + } + case APIResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + return { tag: APIResultValues.Tag.Failure, param0: int }; + } + default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; return { /** @@ -121,7 +120,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -265,9 +264,6 @@ export async function createInstantiator(options, swift) { instance = i; memory = instance.exports.memory; - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.APIResult = APIResultHelpers; - setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) } @@ -288,7 +284,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -298,7 +294,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_MathUtils_deinit, MathUtils.prototype); } - + constructor() { const ret = instance.exports.bjs_MathUtils_init(); return MathUtils.__construct(ret); @@ -316,6 +312,9 @@ export async function createInstantiator(options, swift) { return ret; } } + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.APIResult = APIResultHelpers; + if (typeof globalThis.Utils === 'undefined') { globalThis.Utils = {}; } @@ -336,7 +335,7 @@ export async function createInstantiator(options, swift) { roundtrip: function(value) { const { caseId: valueCaseId, cleanup: valueCleanup } = enumHelpers.APIResult.lower(value); instance.exports.bjs_APIResult_static_roundtrip(valueCaseId); - const ret = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); if (valueCleanup) { valueCleanup(); } return ret; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js similarity index 84% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index 8b5a54315..b38668c57 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -15,46 +15,6 @@ export const APIResultValues = { Failure: 1, }, }; - -const __bjs_createAPIResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case APIResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: APIResultValues.Tag.Success, cleanup }; - } - case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; - } - default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: APIResultValues.Tag.Success, param0: string }; - } - case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Failure, param0: int }; - } - default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; export async function createInstantiator(options, swift) { let instance; let memory; @@ -69,7 +29,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -82,9 +42,48 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; + const __bjs_createAPIResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case APIResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: APIResultValues.Tag.Success, cleanup }; + } + case APIResultValues.Tag.Failure: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Failure, cleanup }; + } + default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case APIResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: APIResultValues.Tag.Success, param0: string }; + } + case APIResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + return { tag: APIResultValues.Tag.Failure, param0: int }; + } + default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; return { /** @@ -121,7 +120,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -265,9 +264,6 @@ export async function createInstantiator(options, swift) { instance = i; memory = instance.exports.memory; - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.APIResult = APIResultHelpers; - setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) } @@ -288,7 +284,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -298,7 +294,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_MathUtils_deinit, MathUtils.prototype); } - + constructor() { const ret = instance.exports.bjs_MathUtils_init(); return MathUtils.__construct(ret); @@ -316,6 +312,9 @@ export async function createInstantiator(options, swift) { return ret; } } + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.APIResult = APIResultHelpers; + const exports = { MathUtils, Calculator: { @@ -330,7 +329,7 @@ export async function createInstantiator(options, swift) { roundtrip: function(value) { const { caseId: valueCaseId, cleanup: valueCleanup } = enumHelpers.APIResult.lower(value); instance.exports.bjs_APIResult_static_roundtrip(valueCaseId); - const ret = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); if (valueCleanup) { valueCleanup(); } return ret; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index 9806fc631..293ae4f7d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -23,7 +23,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -75,7 +75,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -239,7 +239,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -249,7 +249,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PropertyClass_deinit, PropertyClass.prototype); } - + constructor() { const ret = instance.exports.bjs_PropertyClass_init(); return PropertyClass.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index ee127ed07..27e3df464 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -23,7 +23,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -75,7 +75,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -239,7 +239,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -249,7 +249,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PropertyClass_deinit, PropertyClass.prototype); } - + constructor() { const ret = instance.exports.bjs_PropertyClass_init(); return PropertyClass.__construct(ret); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.d.ts deleted file mode 100644 index bb9f163cc..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { -} -export type Imports = { - takesFeatureFlag(flag: FeatureFlagTag): void; - returnsFeatureFlag(): FeatureFlagTag; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.js deleted file mode 100644 index 373b433b6..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.js +++ /dev/null @@ -1,242 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_takesFeatureFlag"] = function bjs_takesFeatureFlag(flag) { - try { - const flagObject = swift.memory.getObject(flag); - swift.memory.release(flag); - imports.takesFeatureFlag(flagObject); - } catch (error) { - setException(error); - } - } - TestModule["bjs_returnsFeatureFlag"] = function bjs_returnsFeatureFlag() { - try { - let ret = imports.returnsFeatureFlag(); - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.d.ts deleted file mode 100644 index 229436712..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { - checkString(a: string): void; - roundtripString(a: string): string; -} -export type Imports = { -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.js deleted file mode 100644 index 021adcba3..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.js +++ /dev/null @@ -1,237 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - checkString: function bjs_checkString(a) { - const aBytes = textEncoder.encode(a); - const aId = swift.memory.retain(aBytes); - instance.exports.bjs_checkString(aId, aBytes.length); - swift.memory.release(aId); - }, - roundtripString: function bjs_roundtripString(a) { - const aBytes = textEncoder.encode(a); - const aId = swift.memory.retain(aBytes); - instance.exports.bjs_roundtripString(aId, aBytes.length); - const ret = tmpRetString; - tmpRetString = undefined; - swift.memory.release(aId); - return ret; - }, - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.d.ts similarity index 89% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.d.ts index 09fd7b638..5e45162a1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.d.ts @@ -5,6 +5,8 @@ // `swift package bridge-js`. export type Exports = { + checkString(a: string): void; + roundtripString(a: string): string; } export type Imports = { checkString(a: string): void; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js similarity index 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index 718f776c7..e57c5153d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -234,6 +234,21 @@ export async function createInstantiator(options, swift) { createExports: (instance) => { const js = swift.memory.heap; const exports = { + checkString: function bjs_checkString(a) { + const aBytes = textEncoder.encode(a); + const aId = swift.memory.retain(aBytes); + instance.exports.bjs_checkString(aId, aBytes.length); + swift.memory.release(aId); + }, + roundtripString: function bjs_roundtripString(a) { + const aBytes = textEncoder.encode(a); + const aId = swift.memory.retain(aBytes); + instance.exports.bjs_roundtripString(aId, aBytes.length); + const ret = tmpRetString; + tmpRetString = undefined; + swift.memory.release(aId); + return ret; + }, }; _exports = exports; return exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.d.ts deleted file mode 100644 index c6a9f65a4..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { - checkString(): string; -} -export type Imports = { -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.js deleted file mode 100644 index 479b313dd..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.js +++ /dev/null @@ -1,228 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - checkString: function bjs_checkString() { - instance.exports.bjs_checkString(); - const ret = tmpRetString; - tmpRetString = undefined; - return ret; - }, - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts similarity index 95% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts index cb7783667..b43ff062c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts @@ -5,6 +5,7 @@ // `swift package bridge-js`. export type Exports = { + checkString(): string; } export type Imports = { checkString(): string; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js similarity index 96% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index bb5278068..74d140236 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -225,6 +225,12 @@ export async function createInstantiator(options, swift) { createExports: (instance) => { const js = swift.memory.heap; const exports = { + checkString: function bjs_checkString() { + instance.exports.bjs_checkString(); + const ret = tmpRetString; + tmpRetString = undefined; + return ret; + }, }; _exports = exports; return exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index d04cd6507..27398d2a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -242,7 +242,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -252,7 +252,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -289,13 +289,13 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PublicGreeter_deinit, PublicGreeter.prototype); } - + } class PackageGreeter extends SwiftHeapObject { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_PackageGreeter_deinit, PackageGreeter.prototype); } - + } const exports = { Greeter, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js similarity index 90% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 40378d042..ff5af72f9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -34,78 +34,6 @@ export const APIResultValues = { Info: 5, }, }; - -const __bjs_createAPIResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift) => ({ - lower: (value) => { - const enumTag = value.tag; - switch (enumTag) { - case APIResultValues.Tag.Success: { - const bytes = textEncoder.encode(value.param0); - const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - const cleanup = () => { - swift.memory.release(id); - }; - return { caseId: APIResultValues.Tag.Success, cleanup }; - } - case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; - } - case APIResultValues.Tag.Flag: { - tmpParamInts.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Flag, cleanup }; - } - case APIResultValues.Tag.Rate: { - tmpParamF32s.push(Math.fround(value.param0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Rate, cleanup }; - } - case APIResultValues.Tag.Precise: { - tmpParamF64s.push(value.param0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Precise, cleanup }; - } - case APIResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Info, cleanup }; - } - default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); - } - }, - lift: (tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s) => { - const tag = tmpRetTag | 0; - switch (tag) { - case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); - return { tag: APIResultValues.Tag.Success, param0: string }; - } - case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Failure, param0: int }; - } - case APIResultValues.Tag.Flag: { - const bool = tmpRetInts.pop(); - return { tag: APIResultValues.Tag.Flag, param0: bool }; - } - case APIResultValues.Tag.Rate: { - const f32 = tmpRetF32s.pop(); - return { tag: APIResultValues.Tag.Rate, param0: f32 }; - } - case APIResultValues.Tag.Precise: { - const f64 = tmpRetF64s.pop(); - return { tag: APIResultValues.Tag.Precise, param0: f64 }; - } - case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; - default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); - } - } - }); -}; export async function createInstantiator(options, swift) { let instance; let memory; @@ -120,7 +48,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -133,9 +61,80 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; + const __bjs_createAPIResultValuesHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + lower: (value) => { + const enumTag = value.tag; + switch (enumTag) { + case APIResultValues.Tag.Success: { + const bytes = textEncoder.encode(value.param0); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + const cleanup = () => { + swift.memory.release(id); + }; + return { caseId: APIResultValues.Tag.Success, cleanup }; + } + case APIResultValues.Tag.Failure: { + tmpParamInts.push((value.param0 | 0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Failure, cleanup }; + } + case APIResultValues.Tag.Flag: { + tmpParamInts.push(value.param0 ? 1 : 0); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Flag, cleanup }; + } + case APIResultValues.Tag.Rate: { + tmpParamF32s.push(Math.fround(value.param0)); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Rate, cleanup }; + } + case APIResultValues.Tag.Precise: { + tmpParamF64s.push(value.param0); + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Precise, cleanup }; + } + case APIResultValues.Tag.Info: { + const cleanup = undefined; + return { caseId: APIResultValues.Tag.Info, cleanup }; + } + default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); + } + }, + lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + tag = tag | 0; + switch (tag) { + case APIResultValues.Tag.Success: { + const string = tmpRetStrings.pop(); + return { tag: APIResultValues.Tag.Success, param0: string }; + } + case APIResultValues.Tag.Failure: { + const int = tmpRetInts.pop(); + return { tag: APIResultValues.Tag.Failure, param0: int }; + } + case APIResultValues.Tag.Flag: { + const bool = tmpRetInts.pop() !== 0; + return { tag: APIResultValues.Tag.Flag, param0: bool }; + } + case APIResultValues.Tag.Rate: { + const f32 = tmpRetF32s.pop(); + return { tag: APIResultValues.Tag.Rate, param0: f32 }; + } + case APIResultValues.Tag.Precise: { + const f64 = tmpRetF64s.pop(); + return { tag: APIResultValues.Tag.Precise, param0: f64 }; + } + case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; + default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); + } + } + }); + }; return { /** @@ -172,7 +171,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -303,7 +302,7 @@ export async function createInstantiator(options, swift) { tmpRetOptionalHeapObject = undefined; return pointer || 0; } - + bjs["invoke_js_callback_TestModule_10TestModule10HttpStatusO_Si"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -315,7 +314,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule10HttpStatusO_Si"] = function(closurePtr) { return function(param0) { try { @@ -326,7 +325,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule5ThemeO_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -345,7 +344,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule5ThemeO_SS"] = function(closurePtr) { return function(param0) { try { @@ -361,7 +360,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule5ThemeO_Sb"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -375,7 +374,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule5ThemeO_Sb"] = function(closurePtr) { return function(param0) { try { @@ -388,7 +387,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule6PersonC_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -405,7 +404,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule6PersonC_SS"] = function(closurePtr) { return function(param0) { try { @@ -419,11 +418,11 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule9APIResultO_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); - let param0 = enumHelpers.APIResult.lift(param0Id, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + let param0 = enumHelpers.APIResult.lift(param0Id, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); const result = callback(param0); if (typeof result !== "string") { throw new TypeError("Callback must return a string"); @@ -436,7 +435,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9APIResultO_SS"] = function(closurePtr) { return function(param0) { try { @@ -451,7 +450,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule9DirectionO_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -468,7 +467,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9DirectionO_SS"] = function(closurePtr) { return function(param0) { try { @@ -482,7 +481,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule9DirectionO_Sb"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -494,7 +493,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9DirectionO_Sb"] = function(closurePtr) { return function(param0) { try { @@ -505,7 +504,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSS_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -524,7 +523,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSS_SS"] = function(closurePtr) { return function(param0) { try { @@ -540,7 +539,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq5ThemeO_SS"] = function(callbackId, param0IsSome, param0Value) { try { const callback = swift.memory.getObject(callbackId); @@ -564,7 +563,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq5ThemeO_SS"] = function(closurePtr) { return function(param0) { try { @@ -584,7 +583,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq6PersonCSqSSSqSd_SS"] = function(callbackId, param0IsSome, param0Value, param1IsSome, param1Value, param2IsSome, param2Value) { try { const callback = swift.memory.getObject(callbackId); @@ -620,7 +619,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq6PersonCSqSSSqSd_SS"] = function(closurePtr) { return function(param0, param1, param2) { try { @@ -642,7 +641,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq6PersonC_SS"] = function(callbackId, param0IsSome, param0Value) { try { const callback = swift.memory.getObject(callbackId); @@ -664,7 +663,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq6PersonC_SS"] = function(closurePtr) { return function(param0) { try { @@ -679,13 +678,13 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq9APIResultO_SS"] = function(callbackId, param0IsSome, param0Value) { try { const callback = swift.memory.getObject(callbackId); let param0; if (param0IsSome) { - param0 = enumHelpers.APIResult.lift(param0Value, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + param0 = enumHelpers.APIResult.lift(param0Value, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } else { param0 = null; } @@ -701,7 +700,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq9APIResultO_SS"] = function(closurePtr) { return function(param0) { try { @@ -722,7 +721,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq9DirectionO_SS"] = function(callbackId, param0IsSome, param0Value) { try { const callback = swift.memory.getObject(callbackId); @@ -744,7 +743,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq9DirectionO_SS"] = function(closurePtr) { return function(param0) { try { @@ -776,9 +775,6 @@ export async function createInstantiator(options, swift) { instance = i; memory = instance.exports.memory; - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); - enumHelpers.APIResult = APIResultHelpers; - setException = (error) => { instance.exports._swift_js_exception.value = swift.memory.retain(error) } @@ -799,7 +795,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -809,7 +805,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Person_deinit, Person.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -822,7 +818,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_TestProcessor_deinit, TestProcessor.prototype); } - + constructor(transform) { const callbackId = swift.memory.retain(transform); const ret = instance.exports.bjs_TestProcessor_init(callbackId); @@ -930,6 +926,9 @@ export async function createInstantiator(options, swift) { return bjs["lower_closure_TestModule_10TestModuleSq9DirectionO_SS"](ret); } } + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + enumHelpers.APIResult = APIResultHelpers; + const exports = { Person, TestProcessor, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 9ab218df1..52e12ef7c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -202,7 +202,7 @@ export async function createInstantiator(options, swift) { tmpRetOptionalHeapObject = undefined; return pointer || 0; } - + bjs["invoke_js_callback_TestModule_10TestModuleSi_Si"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -214,7 +214,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSi_Si"] = function(closurePtr) { return function(param0) { try { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.d.ts similarity index 93% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.d.ts index 7769ebcbe..4a61a26e3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.d.ts @@ -39,6 +39,10 @@ export interface Measurement { } export interface ConfigStruct { } +export interface Container { + object: any; + optionalObject: any | null; +} export type PrecisionObject = typeof PrecisionValues; /// Represents a Swift heap object like a class instance or an actor instance. @@ -57,6 +61,7 @@ export type Exports = { new(name: string): Greeter; } roundtrip(session: Person): Person; + roundtripContainer(container: Container): Container; Precision: PrecisionObject DataPoint: { init(x: number, y: number, label: string, optCount: number | null, optFlag: boolean | null): DataPoint; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js similarity index 86% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index a3d60d0bd..adbe18856 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -23,7 +23,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createDataPointHelpers = () => { @@ -183,9 +183,9 @@ export async function createInstantiator(options, swift) { }, lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { const ptr = tmpRetPointers.pop(); - const value = _exports['Greeter'].__construct(ptr); + const obj = _exports['Greeter'].__construct(ptr); const int = tmpRetInts.pop(); - return { id: int, owner: value }; + return { id: int, owner: obj }; } }); }; @@ -207,14 +207,14 @@ export async function createInstantiator(options, swift) { const isSome = tmpRetInts.pop(); let optional; if (isSome) { - const value = tmpRetF32s.pop(); - optional = value; + const rawValue = tmpRetF32s.pop(); + optional = rawValue; } else { optional = null; } - const value1 = tmpRetF32s.pop(); + const rawValue1 = tmpRetF32s.pop(); const f64 = tmpRetF64s.pop(); - return { value: f64, precision: value1, optionalPrecision: optional }; + return { value: f64, precision: rawValue1, optionalPrecision: optional }; } }); }; @@ -228,6 +228,70 @@ export async function createInstantiator(options, swift) { } }); }; + const __bjs_createContainerHelpers = () => { + return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + lower: (value) => { + let id; + if (value.object != null) { + id = swift.memory.retain(value.object); + } else { + id = undefined; + } + tmpParamInts.push(id !== undefined ? id : 0); + const isSome = value.optionalObject != null; + let id1; + if (isSome) { + id1 = swift.memory.retain(value.optionalObject); + tmpParamInts.push(id1); + } else { + id1 = undefined; + tmpParamInts.push(0); + } + tmpParamInts.push(isSome ? 1 : 0); + const cleanup = () => { + if(id !== undefined && id !== 0) { + try { + swift.memory.getObject(id); + swift.memory.release(id); + } catch(e) {} + } + if(id1 !== undefined && id1 !== 0) { + try { + swift.memory.getObject(id1); + swift.memory.release(id1); + } catch(e) {} + } + }; + return { cleanup }; + }, + lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + const isSome = tmpRetInts.pop(); + let optional; + if (isSome) { + const objectId = tmpRetInts.pop(); + let value; + if (objectId !== 0) { + value = swift.memory.getObject(objectId); + swift.memory.release(objectId); + } else { + value = null; + } + optional = value; + } else { + optional = null; + } + const objectId1 = tmpRetInts.pop(); + let value1; + if (objectId1 !== 0) { + value1 = swift.memory.getObject(objectId1); + swift.memory.release(objectId1); + } else { + value1 = null; + } + return { object: value1, optionalObject: optional }; + } + }); + }; return { /** @@ -264,7 +328,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -371,6 +435,17 @@ export async function createInstantiator(options, swift) { const value = structHelpers.ConfigStruct.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); return swift.memory.retain(value); } + bjs["swift_js_struct_lower_Container"] = function(objectId) { + const { cleanup: cleanup } = structHelpers.Container.lower(swift.memory.getObject(objectId)); + if (cleanup) { + return tmpStructCleanups.push(cleanup); + } + return 0; + } + bjs["swift_js_struct_lift_Container"] = function() { + const value = structHelpers.Container.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + return swift.memory.retain(value); + } bjs["swift_js_return_optional_bool"] = function(isSome, value) { if (isSome === 0) { tmpRetOptionalBool = null; @@ -494,7 +569,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -504,7 +579,7 @@ export async function createInstantiator(options, swift) { static __construct(ptr) { return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Greeter_deinit, Greeter.prototype); } - + constructor(name) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); @@ -533,22 +608,25 @@ export async function createInstantiator(options, swift) { } const DataPointHelpers = __bjs_createDataPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.DataPoint = DataPointHelpers; - + const AddressHelpers = __bjs_createAddressHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Address = AddressHelpers; - + const PersonHelpers = __bjs_createPersonHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Person = PersonHelpers; - + const SessionHelpers = __bjs_createSessionHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Session = SessionHelpers; - + const MeasurementHelpers = __bjs_createMeasurementHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Measurement = MeasurementHelpers; - + const ConfigStructHelpers = __bjs_createConfigStructHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.ConfigStruct = ConfigStructHelpers; - + + const ContainerHelpers = __bjs_createContainerHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + structHelpers.Container = ContainerHelpers; + const exports = { Greeter, roundtrip: function bjs_roundtrip(session) { @@ -558,6 +636,13 @@ export async function createInstantiator(options, swift) { if (cleanup) { cleanup(); } return structValue; }, + roundtripContainer: function bjs_roundtripContainer(container) { + const { cleanup: cleanup } = structHelpers.Container.lower(container); + instance.exports.bjs_roundtripContainer(); + const structValue = structHelpers.Container.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + if (cleanup) { cleanup(); } + return structValue; + }, Precision: PrecisionValues, DataPoint: { init: function(x, y, label, optCount, optFlag) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index f4e7e61e9..8f90491df 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createPointHelpers = () => { @@ -85,7 +85,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -252,7 +252,7 @@ export async function createInstantiator(options, swift) { const js = swift.memory.heap; const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.Point = PointHelpers; - + const exports = { }; _exports = exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.d.ts deleted file mode 100644 index 26d56fb6c..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export interface TypeScriptProcessor { - convert(ts: string): string; - validate(ts: string): boolean; - readonly version: string; -} -export interface CodeGenerator { - generate(input: any): string; - readonly outputFormat: string; -} -export type Exports = { -} -export type Imports = { - createTS2Skeleton(): TypeScriptProcessor; - createCodeGenerator(format: string): CodeGenerator; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.js deleted file mode 100644 index 45c273115..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.js +++ /dev/null @@ -1,293 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_createTS2Skeleton"] = function bjs_createTS2Skeleton() { - try { - let ret = imports.createTS2Skeleton(); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_createCodeGenerator"] = function bjs_createCodeGenerator(format) { - try { - const formatObject = swift.memory.getObject(format); - swift.memory.release(format); - let ret = imports.createCodeGenerator(formatObject); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_TypeScriptProcessor_version_get"] = function bjs_TypeScriptProcessor_version_get(self) { - try { - let ret = swift.memory.getObject(self).version; - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - TestModule["bjs_TypeScriptProcessor_convert"] = function bjs_TypeScriptProcessor_convert(self, ts) { - try { - const tsObject = swift.memory.getObject(ts); - swift.memory.release(ts); - let ret = swift.memory.getObject(self).convert(tsObject); - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - TestModule["bjs_TypeScriptProcessor_validate"] = function bjs_TypeScriptProcessor_validate(self, ts) { - try { - const tsObject = swift.memory.getObject(ts); - swift.memory.release(ts); - let ret = swift.memory.getObject(self).validate(tsObject); - return ret ? 1 : 0; - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_CodeGenerator_outputFormat_get"] = function bjs_CodeGenerator_outputFormat_get(self) { - try { - let ret = swift.memory.getObject(self).outputFormat; - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - TestModule["bjs_CodeGenerator_generate"] = function bjs_CodeGenerator_generate(self, input) { - try { - let ret = swift.memory.getObject(self).generate(swift.memory.getObject(input)); - tmpRetBytes = textEncoder.encode(ret); - return tmpRetBytes.length; - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 5a492295a..2e2f8bf6a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.d.ts deleted file mode 100644 index da5dfb076..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { -} -export type Imports = { - checkSimple(a: number): void; -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.js deleted file mode 100644 index 406d7f0f3..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.js +++ /dev/null @@ -1,231 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - const imports = options.getImports(importsContext); - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_checkSimple"] = function bjs_checkSimple(a) { - try { - imports.checkSimple(a); - } catch (error) { - setException(error); - } - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js similarity index 99% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 2ac28b7e9..bbeeffa0d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createPointerFieldsHelpers = () => { @@ -90,7 +90,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -246,7 +246,7 @@ export async function createInstantiator(options, swift) { const js = swift.memory.heap; const PointerFieldsHelpers = __bjs_createPointerFieldsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); structHelpers.PointerFields = PointerFieldsHelpers; - + const exports = { takeUnsafeRawPointer: function bjs_takeUnsafeRawPointer(p) { instance.exports.bjs_takeUnsafeRawPointer(p); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.d.ts deleted file mode 100644 index be85a00fd..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export type Exports = { - check(): void; -} -export type Imports = { -} -export function createInstantiator(options: { - imports: Imports; -}, swift: any): Promise<{ - addImports: (importObject: WebAssembly.Imports) => void; - setInstance: (instance: WebAssembly.Instance) => void; - createExports: (instance: WebAssembly.Instance) => Exports; -}>; \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.js deleted file mode 100644 index 8a2fabca9..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.js +++ /dev/null @@ -1,225 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -export async function createInstantiator(options, swift) { - let instance; - let memory; - let setException; - const textDecoder = new TextDecoder("utf-8"); - const textEncoder = new TextEncoder("utf-8"); - let tmpRetString; - let tmpRetBytes; - let tmpRetException; - let tmpRetOptionalBool; - let tmpRetOptionalInt; - let tmpRetOptionalFloat; - let tmpRetOptionalDouble; - let tmpRetOptionalHeapObject; - let tmpRetTag; - let tmpRetStrings = []; - let tmpRetInts = []; - let tmpRetF32s = []; - let tmpRetF64s = []; - let tmpParamInts = []; - let tmpParamF32s = []; - let tmpParamF64s = []; - let tmpRetPointers = []; - let tmpParamPointers = []; - let tmpStructCleanups = []; - const enumHelpers = {}; - const structHelpers = {}; - - let _exports = null; - let bjs = null; - - return { - /** - * @param {WebAssembly.Imports} importObject - */ - addImports: (importObject, importsContext) => { - bjs = {}; - importObject["bjs"] = bjs; - bjs["swift_js_return_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { - const source = swift.memory.getObject(sourceId); - const bytes = new Uint8Array(memory.buffer, bytesPtr); - bytes.set(source); - } - bjs["swift_js_make_js_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - return swift.memory.retain(textDecoder.decode(bytes)); - } - bjs["swift_js_init_memory_with_result"] = function(ptr, len) { - const target = new Uint8Array(memory.buffer, ptr, len); - target.set(tmpRetBytes); - tmpRetBytes = undefined; - } - bjs["swift_js_throw"] = function(id) { - tmpRetException = swift.memory.retainByRef(id); - } - bjs["swift_js_retain"] = function(id) { - return swift.memory.retainByRef(id); - } - bjs["swift_js_release"] = function(id) { - swift.memory.release(id); - } - bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; - } - bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); - } - bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); - } - bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); - } - bjs["swift_js_push_string"] = function(ptr, len) { - const bytes = new Uint8Array(memory.buffer, ptr, len); - const value = textDecoder.decode(bytes); - tmpRetStrings.push(value); - } - bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); - } - bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); - } - bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); - } - bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); - } - bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); - } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } - bjs["swift_js_return_optional_bool"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalBool = null; - } else { - tmpRetOptionalBool = value !== 0; - } - } - bjs["swift_js_return_optional_int"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalInt = null; - } else { - tmpRetOptionalInt = value | 0; - } - } - bjs["swift_js_return_optional_float"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalFloat = null; - } else { - tmpRetOptionalFloat = Math.fround(value); - } - } - bjs["swift_js_return_optional_double"] = function(isSome, value) { - if (isSome === 0) { - tmpRetOptionalDouble = null; - } else { - tmpRetOptionalDouble = value; - } - } - bjs["swift_js_return_optional_string"] = function(isSome, ptr, len) { - if (isSome === 0) { - tmpRetString = null; - } else { - const bytes = new Uint8Array(memory.buffer, ptr, len); - tmpRetString = textDecoder.decode(bytes); - } - } - bjs["swift_js_return_optional_object"] = function(isSome, objectId) { - if (isSome === 0) { - tmpRetString = null; - } else { - tmpRetString = swift.memory.getObject(objectId); - } - } - bjs["swift_js_return_optional_heap_object"] = function(isSome, pointer) { - if (isSome === 0) { - tmpRetOptionalHeapObject = null; - } else { - tmpRetOptionalHeapObject = pointer; - } - } - bjs["swift_js_get_optional_int_presence"] = function() { - return tmpRetOptionalInt != null ? 1 : 0; - } - bjs["swift_js_get_optional_int_value"] = function() { - const value = tmpRetOptionalInt; - tmpRetOptionalInt = undefined; - return value; - } - bjs["swift_js_get_optional_string"] = function() { - const str = tmpRetString; - tmpRetString = undefined; - if (str == null) { - return -1; - } else { - const bytes = textEncoder.encode(str); - tmpRetBytes = bytes; - return bytes.length; - } - } - bjs["swift_js_get_optional_float_presence"] = function() { - return tmpRetOptionalFloat != null ? 1 : 0; - } - bjs["swift_js_get_optional_float_value"] = function() { - const value = tmpRetOptionalFloat; - tmpRetOptionalFloat = undefined; - return value; - } - bjs["swift_js_get_optional_double_presence"] = function() { - return tmpRetOptionalDouble != null ? 1 : 0; - } - bjs["swift_js_get_optional_double_value"] = function() { - const value = tmpRetOptionalDouble; - tmpRetOptionalDouble = undefined; - return value; - } - bjs["swift_js_get_optional_heap_object_pointer"] = function() { - const pointer = tmpRetOptionalHeapObject; - tmpRetOptionalHeapObject = undefined; - return pointer || 0; - } - }, - setInstance: (i) => { - instance = i; - memory = instance.exports.memory; - - setException = (error) => { - instance.exports._swift_js_exception.value = swift.memory.retain(error) - } - }, - /** @param {WebAssembly.Instance} instance */ - createExports: (instance) => { - const js = swift.memory.heap; - const exports = { - check: function bjs_check() { - instance.exports.bjs_check(); - }, - }; - _exports = exports; - return exports; - }, - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.d.ts similarity index 96% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.d.ts index 8cd1e806e..7acba67a0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.d.ts @@ -5,6 +5,7 @@ // `swift package bridge-js`. export type Exports = { + check(): void; } export type Imports = { check(): void; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js similarity index 98% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 2944bcf5a..45374093b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -18,7 +18,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -71,7 +71,7 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag = tag; + tmpRetTag.push(tag); } bjs["swift_js_push_i32"] = function(v) { tmpRetInts.push(v | 0); @@ -223,6 +223,9 @@ export async function createInstantiator(options, swift) { createExports: (instance) => { const js = swift.memory.heap; const exports = { + check: function bjs_check() { + instance.exports.bjs_check(); + }, }; _exports = exports; return exports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.json deleted file mode 100644 index c796433dd..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.json +++ /dev/null @@ -1,983 +0,0 @@ -{ - "classes" : [ - { - "methods" : [ - - ], - "name" : "Item", - "properties" : [ - - ], - "swiftCallName" : "Item" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" - }, - { - "associatedValues" : [ - - ], - "name" : "south" - }, - { - "associatedValues" : [ - - ], - "name" : "east" - }, - { - "associatedValues" : [ - - ], - "name" : "west" - } - ], - "emitStyle" : "const", - "name" : "Direction", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Direction", - "tsFullPath" : "Direction" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "pending", - "rawValue" : "0" - }, - { - "associatedValues" : [ - - ], - "name" : "active", - "rawValue" : "1" - }, - { - "associatedValues" : [ - - ], - "name" : "completed", - "rawValue" : "2" - } - ], - "emitStyle" : "const", - "name" : "Status", - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Status", - "tsFullPath" : "Status" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_processIntArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processIntArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "abiName" : "bjs_processStringArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processStringArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_processDoubleArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processDoubleArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - }, - { - "abiName" : "bjs_processBoolArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processBoolArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - }, - { - "abiName" : "bjs_processPointArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processPointArray", - "parameters" : [ - { - "label" : "_", - "name" : "points", - "type" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - }, - { - "abiName" : "bjs_processDirectionArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processDirectionArray", - "parameters" : [ - { - "label" : "_", - "name" : "directions", - "type" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - }, - { - "abiName" : "bjs_processStatusArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processStatusArray", - "parameters" : [ - { - "label" : "_", - "name" : "statuses", - "type" : { - "array" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Status", - "_1" : "Int" - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Status", - "_1" : "Int" - } - } - } - } - }, - { - "abiName" : "bjs_sumIntArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "sumIntArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_findFirstPoint", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "findFirstPoint", - "parameters" : [ - { - "label" : "_", - "name" : "points", - "type" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - }, - { - "label" : "matching", - "name" : "matching", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "swiftStruct" : { - "_0" : "Point" - } - } - }, - { - "abiName" : "bjs_processUnsafeRawPointerArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processUnsafeRawPointerArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - } - } - }, - { - "abiName" : "bjs_processUnsafeMutableRawPointerArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processUnsafeMutableRawPointerArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - } - } - }, - { - "abiName" : "bjs_processOpaquePointerArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOpaquePointerArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalIntArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalIntArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalStringArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalStringArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "optional" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalPointArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalPointArray", - "parameters" : [ - { - "label" : "_", - "name" : "points", - "type" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalDirectionArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalDirectionArray", - "parameters" : [ - { - "label" : "_", - "name" : "directions", - "type" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processOptionalStatusArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalStatusArray", - "parameters" : [ - { - "label" : "_", - "name" : "statuses", - "type" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Status", - "_1" : "Int" - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Status", - "_1" : "Int" - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processNestedIntArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processNestedIntArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processNestedStringArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processNestedStringArray", - "parameters" : [ - { - "label" : "_", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processNestedPointArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processNestedPointArray", - "parameters" : [ - { - "label" : "_", - "name" : "points", - "type" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "Point" - } - } - } - } - } - } - }, - { - "abiName" : "bjs_processItemArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processItemArray", - "parameters" : [ - { - "label" : "_", - "name" : "items", - "type" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Item" - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Item" - } - } - } - } - }, - { - "abiName" : "bjs_processNestedItemArray", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processNestedItemArray", - "parameters" : [ - { - "label" : "_", - "name" : "items", - "type" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Item" - } - } - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Item" - } - } - } - } - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - { - "methods" : [ - - ], - "name" : "Point", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "x", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "y", - "type" : { - "double" : { - - } - } - } - ], - "swiftCallName" : "Point" - } - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.json deleted file mode 100644 index 77c5b3678..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.json +++ /dev/null @@ -1,184 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_asyncReturnVoid", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncReturnVoid", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripInt", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripInt", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripString", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripString", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripBool", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripBool", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripFloat", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripFloat", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "float" : { - - } - } - } - ], - "returnType" : { - "float" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripDouble", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripDouble", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - } - }, - { - "abiName" : "bjs_asyncRoundTripJSObject", - "effects" : { - "isAsync" : true, - "isStatic" : false, - "isThrows" : false - }, - "name" : "asyncRoundTripJSObject", - "parameters" : [ - { - "label" : "_", - "name" : "v", - "type" : { - "jsObject" : { - - } - } - } - ], - "returnType" : { - "jsObject" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.json deleted file mode 100644 index 97def2060..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.json +++ /dev/null @@ -1,149 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_FunctionA_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_FunctionA_processB", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processB", - "parameters" : [ - { - "label" : "b", - "name" : "b", - "type" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_FunctionA_createB", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createB", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "name" : "FunctionA", - "properties" : [ - - ], - "swiftCallName" : "FunctionA" - }, - { - "constructor" : { - "abiName" : "bjs_FunctionB_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "FunctionB", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "FunctionB" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_standaloneFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "standaloneFunction", - "parameters" : [ - { - "label" : "b", - "name" : "b", - "type" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.json deleted file mode 100644 index acfa4c9ef..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.json +++ /dev/null @@ -1,149 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_FunctionB_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "FunctionB", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "FunctionB" - }, - { - "constructor" : { - "abiName" : "bjs_FunctionA_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_FunctionA_processB", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processB", - "parameters" : [ - { - "label" : "b", - "name" : "b", - "type" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_FunctionA_createB", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createB", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "name" : "FunctionA", - "properties" : [ - - ], - "swiftCallName" : "FunctionA" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_standaloneFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "standaloneFunction", - "parameters" : [ - { - "label" : "b", - "name" : "b", - "type" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "FunctionB" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.json deleted file mode 100644 index de5fb19b0..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "classes" : [ - { - "methods" : [ - - ], - "name" : "ClassA", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "linkedB", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "ClassB" - } - } - } - } - } - ], - "swiftCallName" : "ClassA" - }, - { - "constructor" : { - "abiName" : "bjs_ClassB_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "ClassB", - "properties" : [ - - ], - "swiftCallName" : "ClassB" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.json deleted file mode 100644 index 53a5f858c..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_ClassB_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "ClassB", - "properties" : [ - - ], - "swiftCallName" : "ClassB" - }, - { - "methods" : [ - - ], - "name" : "ClassA", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "linkedB", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "ClassB" - } - } - } - } - } - ], - "swiftCallName" : "ClassA" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.json deleted file mode 100644 index f2e6a4e2e..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.json +++ /dev/null @@ -1,1270 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_DefaultGreeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "DefaultGreeter", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "DefaultGreeter" - }, - { - "constructor" : { - "abiName" : "bjs_EmptyGreeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "EmptyGreeter", - "properties" : [ - - ], - "swiftCallName" : "EmptyGreeter" - }, - { - "constructor" : { - "abiName" : "bjs_ConstructorDefaults_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "defaultValue" : { - "string" : { - "_0" : "Default" - } - }, - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "defaultValue" : { - "int" : { - "_0" : 42 - } - }, - "label" : "count", - "name" : "count", - "type" : { - "int" : { - - } - } - }, - { - "defaultValue" : { - "bool" : { - "_0" : true - } - }, - "label" : "enabled", - "name" : "enabled", - "type" : { - "bool" : { - - } - } - }, - { - "defaultValue" : { - "enumCase" : { - "_0" : "Status", - "_1" : "active" - } - }, - "label" : "status", - "name" : "status", - "type" : { - "caseEnum" : { - "_0" : "Status" - } - } - }, - { - "defaultValue" : { - "null" : { - - } - }, - "label" : "tag", - "name" : "tag", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "ConstructorDefaults", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "count", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "enabled", - "type" : { - "bool" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "status", - "type" : { - "caseEnum" : { - "_0" : "Status" - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "tag", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "swiftCallName" : "ConstructorDefaults" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "active" - }, - { - "associatedValues" : [ - - ], - "name" : "inactive" - }, - { - "associatedValues" : [ - - ], - "name" : "pending" - } - ], - "emitStyle" : "const", - "explicitAccessControl" : "public", - "name" : "Status", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Status", - "tsFullPath" : "Status" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_testStringDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testStringDefault", - "parameters" : [ - { - "defaultValue" : { - "string" : { - "_0" : "Hello World" - } - }, - "label" : "message", - "name" : "message", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_testNegativeIntDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testNegativeIntDefault", - "parameters" : [ - { - "defaultValue" : { - "int" : { - "_0" : -42 - } - }, - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_testBoolDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testBoolDefault", - "parameters" : [ - { - "defaultValue" : { - "bool" : { - "_0" : true - } - }, - "label" : "flag", - "name" : "flag", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_testNegativeFloatDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testNegativeFloatDefault", - "parameters" : [ - { - "defaultValue" : { - "float" : { - "_0" : -273.15 - } - }, - "label" : "temp", - "name" : "temp", - "type" : { - "float" : { - - } - } - } - ], - "returnType" : { - "float" : { - - } - } - }, - { - "abiName" : "bjs_testDoubleDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testDoubleDefault", - "parameters" : [ - { - "defaultValue" : { - "double" : { - "_0" : 2.718 - } - }, - "label" : "precision", - "name" : "precision", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - } - }, - { - "abiName" : "bjs_testOptionalDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testOptionalDefault", - "parameters" : [ - { - "defaultValue" : { - "null" : { - - } - }, - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testOptionalStringDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testOptionalStringDefault", - "parameters" : [ - { - "defaultValue" : { - "string" : { - "_0" : "Hi" - } - }, - "label" : "greeting", - "name" : "greeting", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testMultipleDefaults", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testMultipleDefaults", - "parameters" : [ - { - "defaultValue" : { - "string" : { - "_0" : "Default Title" - } - }, - "label" : "title", - "name" : "title", - "type" : { - "string" : { - - } - } - }, - { - "defaultValue" : { - "int" : { - "_0" : 10 - } - }, - "label" : "count", - "name" : "count", - "type" : { - "int" : { - - } - } - }, - { - "defaultValue" : { - "bool" : { - "_0" : false - } - }, - "label" : "enabled", - "name" : "enabled", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_testEnumDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testEnumDefault", - "parameters" : [ - { - "defaultValue" : { - "enumCase" : { - "_0" : "Status", - "_1" : "active" - } - }, - "label" : "status", - "name" : "status", - "type" : { - "caseEnum" : { - "_0" : "Status" - } - } - } - ], - "returnType" : { - "caseEnum" : { - "_0" : "Status" - } - } - }, - { - "abiName" : "bjs_testComplexInit", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testComplexInit", - "parameters" : [ - { - "defaultValue" : { - "objectWithArguments" : { - "_0" : "DefaultGreeter", - "_1" : [ - { - "string" : { - "_0" : "DefaultUser" - } - } - ] - } - }, - "label" : "greeter", - "name" : "greeter", - "type" : { - "swiftHeapObject" : { - "_0" : "DefaultGreeter" - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "DefaultGreeter" - } - } - }, - { - "abiName" : "bjs_testEmptyInit", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testEmptyInit", - "parameters" : [ - { - "defaultValue" : { - "object" : { - "_0" : "EmptyGreeter" - } - }, - "label" : "greeter", - "name" : "greeter", - "type" : { - "swiftHeapObject" : { - "_0" : "EmptyGreeter" - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "EmptyGreeter" - } - } - }, - { - "abiName" : "bjs_testOptionalStructDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testOptionalStructDefault", - "parameters" : [ - { - "defaultValue" : { - "null" : { - - } - }, - "label" : "point", - "name" : "point", - "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Config" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Config" - } - } - } - } - }, - { - "abiName" : "bjs_testOptionalStructWithValueDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testOptionalStructWithValueDefault", - "parameters" : [ - { - "defaultValue" : { - "structLiteral" : { - "_0" : "Config", - "_1" : [ - { - "name" : "name", - "value" : { - "string" : { - "_0" : "default" - } - } - }, - { - "name" : "value", - "value" : { - "int" : { - "_0" : 42 - } - } - }, - { - "name" : "enabled", - "value" : { - "bool" : { - "_0" : true - } - } - } - ] - } - }, - "label" : "point", - "name" : "point", - "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Config" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Config" - } - } - } - } - }, - { - "abiName" : "bjs_testIntArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testIntArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "int" : { - "_0" : 1 - } - }, - { - "int" : { - "_0" : 2 - } - }, - { - "int" : { - "_0" : 3 - } - } - ] - } - }, - "label" : "values", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testStringArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testStringArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "string" : { - "_0" : "a" - } - }, - { - "string" : { - "_0" : "b" - } - }, - { - "string" : { - "_0" : "c" - } - } - ] - } - }, - "label" : "names", - "name" : "names", - "type" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testDoubleArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testDoubleArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "double" : { - "_0" : 1.5 - } - }, - { - "double" : { - "_0" : 2.5 - } - }, - { - "double" : { - "_0" : 3.5 - } - } - ] - } - }, - "label" : "values", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "double" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testBoolArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testBoolArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "bool" : { - "_0" : true - } - }, - { - "bool" : { - "_0" : false - } - }, - { - "bool" : { - "_0" : true - } - } - ] - } - }, - "label" : "flags", - "name" : "flags", - "type" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "bool" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testEmptyArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testEmptyArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "array" : { - "_0" : [ - - ] - } - }, - "label" : "items", - "name" : "items", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testMixedWithArrayDefault", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testMixedWithArrayDefault", - "parameters" : [ - { - "defaultValue" : { - "string" : { - "_0" : "test" - } - }, - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "int" : { - "_0" : 10 - } - }, - { - "int" : { - "_0" : 20 - } - }, - { - "int" : { - "_0" : 30 - } - } - ] - } - }, - "label" : "values", - "name" : "values", - "type" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "defaultValue" : { - "bool" : { - "_0" : true - } - }, - "label" : "enabled", - "name" : "enabled", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - { - "methods" : [ - - ], - "name" : "Config", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "value", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "enabled", - "type" : { - "bool" : { - - } - } - } - ], - "swiftCallName" : "Config" - }, - { - "constructor" : { - "abiName" : "bjs_MathOperations_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "defaultValue" : { - "double" : { - "_0" : 0 - } - }, - "label" : "baseValue", - "name" : "baseValue", - "type" : { - "double" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_MathOperations_add", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "add", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "defaultValue" : { - "double" : { - "_0" : 10 - } - }, - "label" : "b", - "name" : "b", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - } - }, - { - "abiName" : "bjs_MathOperations_multiply", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "multiply", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - } - }, - { - "abiName" : "bjs_MathOperations_static_subtract", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "subtract", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "defaultValue" : { - "double" : { - "_0" : 5 - } - }, - "label" : "b", - "name" : "b", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - }, - "staticContext" : { - "structName" : { - "_0" : "MathOperations" - } - } - } - ], - "name" : "MathOperations", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "baseValue", - "type" : { - "double" : { - - } - } - } - ], - "swiftCallName" : "MathOperations" - } - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.json deleted file mode 100644 index ab7fbfd9d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.json +++ /dev/null @@ -1,844 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - }, - { - "associatedValues" : [ - { - "type" : { - "bool" : { - - } - } - } - ], - "name" : "flag" - }, - { - "associatedValues" : [ - { - "type" : { - "float" : { - - } - } - } - ], - "name" : "rate" - }, - { - "associatedValues" : [ - { - "type" : { - "double" : { - - } - } - } - ], - "name" : "precise" - }, - { - "associatedValues" : [ - - ], - "name" : "info" - } - ], - "emitStyle" : "const", - "name" : "APIResult", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "APIResult", - "tsFullPath" : "APIResult" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "error" - }, - { - "associatedValues" : [ - { - "type" : { - "bool" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - }, - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "status" - }, - { - "associatedValues" : [ - { - "type" : { - "double" : { - - } - } - }, - { - "type" : { - "double" : { - - } - } - }, - { - "type" : { - "double" : { - - } - } - } - ], - "name" : "coordinates" - }, - { - "associatedValues" : [ - { - "type" : { - "bool" : { - - } - } - }, - { - "type" : { - "bool" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - }, - { - "type" : { - "double" : { - - } - } - }, - { - "type" : { - "double" : { - - } - } - }, - { - "type" : { - "string" : { - - } - } - }, - { - "type" : { - "string" : { - - } - } - }, - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "comprehensive" - }, - { - "associatedValues" : [ - - ], - "name" : "info" - } - ], - "emitStyle" : "const", - "name" : "ComplexResult", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "ComplexResult", - "tsFullPath" : "ComplexResult" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Utilities", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utilities", - "tsFullPath" : "Utilities" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - }, - { - "associatedValues" : [ - { - "type" : { - "bool" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - }, - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "status" - } - ], - "emitStyle" : "const", - "name" : "Result", - "namespace" : [ - "Utilities" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utilities.Result", - "tsFullPath" : "Utilities.Result" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - }, - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - } - ], - "emitStyle" : "const", - "name" : "NetworkingResult", - "namespace" : [ - "API" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "NetworkingResult", - "tsFullPath" : "API.NetworkingResult" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "name" : "failure" - }, - { - "associatedValues" : [ - { - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - }, - { - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "name" : "status" - } - ], - "emitStyle" : "const", - "name" : "APIOptionalResult", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "APIOptionalResult", - "tsFullPath" : "APIOptionalResult" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_handle", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "handle", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getResult", - "parameters" : [ - - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - }, - { - "abiName" : "bjs_roundtripAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtripAPIResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalAPIResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - } - }, - { - "abiName" : "bjs_handleComplex", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "handleComplex", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getComplexResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getComplexResult", - "parameters" : [ - - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - }, - { - "abiName" : "bjs_roundtripComplexResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtripComplexResult", - "parameters" : [ - { - "label" : "_", - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - } - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalComplexResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalComplexResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } - } - } - }, - { - "abiName" : "bjs_roundTripOptionalUtilitiesResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalUtilitiesResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "Utilities.Result" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "Utilities.Result" - } - } - } - } - }, - { - "abiName" : "bjs_roundTripOptionalNetworkingResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalNetworkingResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "NetworkingResult" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "NetworkingResult" - } - } - } - } - }, - { - "abiName" : "bjs_roundTripOptionalAPIOptionalResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalAPIOptionalResult", - "parameters" : [ - { - "label" : "result", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } - } - } - }, - { - "abiName" : "bjs_compareAPIResults", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "compareAPIResults", - "parameters" : [ - { - "label" : "result1", - "name" : "result1", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } - } - } - }, - { - "label" : "result2", - "name" : "result2", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift deleted file mode 100644 index e35da2f77..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift +++ /dev/null @@ -1,614 +0,0 @@ -extension APIResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { - switch caseId { - case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - case 2: - return .flag(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) - case 3: - return .rate(Float.bridgeJSLiftParameter(_swift_js_pop_f32())) - case 4: - return .precise(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - case 5: - return .info - default: - fatalError("Unknown APIResult case ID: \(caseId)") - } - } - - // MARK: Protocol Export - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - switch self { - case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(0) - case .failure(let param0): - _swift_js_push_i32(Int32(param0)) - return Int32(1) - case .flag(let param0): - _swift_js_push_i32(param0 ? 1 : 0) - return Int32(2) - case .rate(let param0): - _swift_js_push_f32(param0) - return Int32(3) - case .precise(let param0): - _swift_js_push_f64(param0) - return Int32(4) - case .info: - return Int32(5) - } - } - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - switch self { - case .success(let param0): - _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .failure(let param0): - _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) - case .flag(let param0): - _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) - case .rate(let param0): - _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) - case .precise(let param0): - _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) - case .info: - _swift_js_push_tag(Int32(5)) - } - } -} - -extension ComplexResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> ComplexResult { - switch caseId { - case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 1: - return .error(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - case 2: - return .status(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 3: - return .coordinates(Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - case 4: - return .comprehensive(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 5: - return .info - default: - fatalError("Unknown ComplexResult case ID: \(caseId)") - } - } - - // MARK: Protocol Export - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - switch self { - case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(0) - case .error(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - return Int32(1) - case .status(let param0, let param1, let param2): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(2) - case .coordinates(let param0, let param1, let param2): - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) - return Int32(3) - case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(4) - case .info: - return Int32(5) - } - } - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> ComplexResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> ComplexResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - switch self { - case .success(let param0): - _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .error(let param0, let param1): - _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .coordinates(let param0, let param1, let param2): - _swift_js_push_tag(Int32(3)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) - case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): - _swift_js_push_tag(Int32(4)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .info: - _swift_js_push_tag(Int32(5)) - } - } -} - -extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> Utilities.Result { - switch caseId { - case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 1: - return .failure(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - case 2: - return .status(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - default: - fatalError("Unknown Utilities.Result case ID: \(caseId)") - } - } - - // MARK: Protocol Export - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - switch self { - case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(0) - case .failure(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - return Int32(1) - case .status(let param0, let param1, let param2): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(2) - } - } - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> Utilities.Result { - return _bridgeJSLiftFromCaseId(caseId) - } - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> Utilities.Result { - return _bridgeJSLiftFromCaseId(caseId) - } - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - switch self { - case .success(let param0): - _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - } -} - -extension NetworkingResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> NetworkingResult { - switch caseId { - case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 1: - return .failure(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - default: - fatalError("Unknown NetworkingResult case ID: \(caseId)") - } - } - - // MARK: Protocol Export - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - switch self { - case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - return Int32(0) - case .failure(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - return Int32(1) - } - } - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> NetworkingResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> NetworkingResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - switch self { - case .success(let param0): - _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) - } - } -} - -extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIOptionalResult { - switch caseId { - case 0: - return .success(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) - case 1: - return .failure(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - case 2: - return .status(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) - default: - fatalError("Unknown APIOptionalResult case ID: \(caseId)") - } - } - - // MARK: Protocol Export - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - switch self { - case .success(let param0): - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - var __bjs_str_param0 = __bjs_unwrapped_param0 - __bjs_str_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - return Int32(0) - case .failure(let param0, let param1): - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param0)) - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(__bjs_unwrapped_param1 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - return Int32(1) - case .status(let param0, let param1, let param2): - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param1)) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - let __bjs_isSome_param2 = param2 != nil - if let __bjs_unwrapped_param2 = param2 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) - return Int32(2) - } - } - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIOptionalResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIOptionalResult { - return _bridgeJSLiftFromCaseId(caseId) - } - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - switch self { - case .success(let param0): - _swift_js_push_tag(Int32(0)) - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - var __bjs_str_param0 = __bjs_unwrapped_param0 - __bjs_str_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param0)) - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(__bjs_unwrapped_param1 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param1)) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - let __bjs_isSome_param2 = param2 != nil - if let __bjs_unwrapped_param2 = param2 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) - } - } -} - -@_expose(wasm, "bjs_handle") -@_cdecl("bjs_handle") -public func _bjs_handle(_ result: Int32) -> Void { - #if arch(wasm32) - handle(result: APIResult.bridgeJSLiftParameter(result)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_getResult") -@_cdecl("bjs_getResult") -public func _bjs_getResult() -> Void { - #if arch(wasm32) - let ret = getResult() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundtripAPIResult") -@_cdecl("bjs_roundtripAPIResult") -public func _bjs_roundtripAPIResult(_ result: Int32) -> Void { - #if arch(wasm32) - let ret = roundtripAPIResult(result: APIResult.bridgeJSLiftParameter(result)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalAPIResult") -@_cdecl("bjs_roundTripOptionalAPIResult") -public func _bjs_roundTripOptionalAPIResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalAPIResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_handleComplex") -@_cdecl("bjs_handleComplex") -public func _bjs_handleComplex(_ result: Int32) -> Void { - #if arch(wasm32) - handleComplex(result: ComplexResult.bridgeJSLiftParameter(result)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_getComplexResult") -@_cdecl("bjs_getComplexResult") -public func _bjs_getComplexResult() -> Void { - #if arch(wasm32) - let ret = getComplexResult() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundtripComplexResult") -@_cdecl("bjs_roundtripComplexResult") -public func _bjs_roundtripComplexResult(_ result: Int32) -> Void { - #if arch(wasm32) - let ret = roundtripComplexResult(_: ComplexResult.bridgeJSLiftParameter(result)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalComplexResult") -@_cdecl("bjs_roundTripOptionalComplexResult") -public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalComplexResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalUtilitiesResult") -@_cdecl("bjs_roundTripOptionalUtilitiesResult") -public func _bjs_roundTripOptionalUtilitiesResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalUtilitiesResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalNetworkingResult") -@_cdecl("bjs_roundTripOptionalNetworkingResult") -public func _bjs_roundTripOptionalNetworkingResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalNetworkingResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalAPIOptionalResult") -@_cdecl("bjs_roundTripOptionalAPIOptionalResult") -public func _bjs_roundTripOptionalAPIOptionalResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_compareAPIResults") -@_cdecl("bjs_compareAPIResults") -public func _bjs_compareAPIResults(_ result1IsSome: Int32, _ result1CaseId: Int32, _ result2IsSome: Int32, _ result2CaseId: Int32) -> Void { - #if arch(wasm32) - let _tmp_result2 = Optional.bridgeJSLiftParameter(result2IsSome, result2CaseId) - let _tmp_result1 = Optional.bridgeJSLiftParameter(result1IsSome, result1CaseId) - let ret = compareAPIResults(result1: _tmp_result1, result2: _tmp_result2) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.json deleted file mode 100644 index ca6fabceb..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.json +++ /dev/null @@ -1,320 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" - }, - { - "associatedValues" : [ - - ], - "name" : "south" - }, - { - "associatedValues" : [ - - ], - "name" : "east" - }, - { - "associatedValues" : [ - - ], - "name" : "west" - } - ], - "emitStyle" : "const", - "name" : "Direction", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Direction", - "tsFullPath" : "Direction" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "loading" - }, - { - "associatedValues" : [ - - ], - "name" : "success" - }, - { - "associatedValues" : [ - - ], - "name" : "error" - } - ], - "emitStyle" : "const", - "name" : "Status", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Status", - "tsFullPath" : "Status" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" - }, - { - "associatedValues" : [ - - ], - "name" : "south" - }, - { - "associatedValues" : [ - - ], - "name" : "east" - }, - { - "associatedValues" : [ - - ], - "name" : "west" - } - ], - "emitStyle" : "tsEnum", - "name" : "TSDirection", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "TSDirection", - "tsFullPath" : "TSDirection" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "success" - } - ], - "emitStyle" : "const", - "explicitAccessControl" : "public", - "name" : "PublicStatus", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "PublicStatus", - "tsFullPath" : "PublicStatus" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_setDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setDirection", - "parameters" : [ - { - "label" : "_", - "name" : "direction", - "type" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getDirection", - "parameters" : [ - - ], - "returnType" : { - "caseEnum" : { - "_0" : "Direction" - } - } - }, - { - "abiName" : "bjs_processDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processDirection", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - ], - "returnType" : { - "caseEnum" : { - "_0" : "Status" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalDirection", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - }, - { - "abiName" : "bjs_setTSDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setTSDirection", - "parameters" : [ - { - "label" : "_", - "name" : "direction", - "type" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getTSDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTSDirection", - "parameters" : [ - - ], - "returnType" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalTSDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalTSDirection", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json deleted file mode 100644 index 42a084c44..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json +++ /dev/null @@ -1,415 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Converter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_Converter_toString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "toString", - "namespace" : [ - "Utils" - ], - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Converter", - "namespace" : [ - "Utils" - ], - "properties" : [ - - ], - "swiftCallName" : "Utils.Converter" - }, - { - "constructor" : { - "abiName" : "bjs_HTTPServer_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_HTTPServer_call", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "call", - "namespace" : [ - "Networking", - "API" - ], - "parameters" : [ - { - "label" : "_", - "name" : "method", - "type" : { - "caseEnum" : { - "_0" : "Networking.API.Method" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "HTTPServer", - "namespace" : [ - "Networking", - "API" - ], - "properties" : [ - - ], - "swiftCallName" : "Networking.API.HTTPServer" - }, - { - "constructor" : { - "abiName" : "bjs_TestServer_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_TestServer_call", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "call", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "parameters" : [ - { - "label" : "_", - "name" : "method", - "type" : { - "caseEnum" : { - "_0" : "Internal.SupportedMethod" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "TestServer", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "properties" : [ - - ], - "swiftCallName" : "Internal.TestServer" - } - ], - "enums" : [ - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Utils", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils", - "tsFullPath" : "Utils" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Networking", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking", - "tsFullPath" : "Networking" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "API", - "namespace" : [ - "Networking" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking.API", - "tsFullPath" : "Networking.API" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "get" - }, - { - "associatedValues" : [ - - ], - "name" : "post" - }, - { - "associatedValues" : [ - - ], - "name" : "put" - }, - { - "associatedValues" : [ - - ], - "name" : "delete" - } - ], - "emitStyle" : "const", - "name" : "Method", - "namespace" : [ - "Networking", - "API" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking.API.Method", - "tsFullPath" : "Networking.API.Method" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Configuration", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration", - "tsFullPath" : "Configuration" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "debug", - "rawValue" : "debug" - }, - { - "associatedValues" : [ - - ], - "name" : "info", - "rawValue" : "info" - }, - { - "associatedValues" : [ - - ], - "name" : "warning", - "rawValue" : "warning" - }, - { - "associatedValues" : [ - - ], - "name" : "error", - "rawValue" : "error" - } - ], - "emitStyle" : "const", - "name" : "LogLevel", - "namespace" : [ - "Configuration" - ], - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration.LogLevel", - "tsFullPath" : "Configuration.LogLevel" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "http", - "rawValue" : "80" - }, - { - "associatedValues" : [ - - ], - "name" : "https", - "rawValue" : "443" - }, - { - "associatedValues" : [ - - ], - "name" : "development", - "rawValue" : "3000" - } - ], - "emitStyle" : "const", - "name" : "Port", - "namespace" : [ - "Configuration" - ], - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration.Port", - "tsFullPath" : "Configuration.Port" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Internal", - "namespace" : [ - "Networking", - "APIV2" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Internal", - "tsFullPath" : "Networking.APIV2.Internal" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "get" - }, - { - "associatedValues" : [ - - ], - "name" : "post" - } - ], - "emitStyle" : "const", - "name" : "SupportedMethod", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Internal.SupportedMethod", - "tsFullPath" : "Networking.APIV2.Internal.SupportedMethod" - } - ], - "exposeToGlobal" : true, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json deleted file mode 100644 index 23bb06429..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json +++ /dev/null @@ -1,415 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Converter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_Converter_toString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "toString", - "namespace" : [ - "Utils" - ], - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Converter", - "namespace" : [ - "Utils" - ], - "properties" : [ - - ], - "swiftCallName" : "Utils.Converter" - }, - { - "constructor" : { - "abiName" : "bjs_HTTPServer_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_HTTPServer_call", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "call", - "namespace" : [ - "Networking", - "API" - ], - "parameters" : [ - { - "label" : "_", - "name" : "method", - "type" : { - "caseEnum" : { - "_0" : "Networking.API.Method" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "HTTPServer", - "namespace" : [ - "Networking", - "API" - ], - "properties" : [ - - ], - "swiftCallName" : "Networking.API.HTTPServer" - }, - { - "constructor" : { - "abiName" : "bjs_TestServer_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_TestServer_call", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "call", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "parameters" : [ - { - "label" : "_", - "name" : "method", - "type" : { - "caseEnum" : { - "_0" : "Internal.SupportedMethod" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "TestServer", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "properties" : [ - - ], - "swiftCallName" : "Internal.TestServer" - } - ], - "enums" : [ - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Utils", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils", - "tsFullPath" : "Utils" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Networking", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking", - "tsFullPath" : "Networking" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "API", - "namespace" : [ - "Networking" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking.API", - "tsFullPath" : "Networking.API" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "get" - }, - { - "associatedValues" : [ - - ], - "name" : "post" - }, - { - "associatedValues" : [ - - ], - "name" : "put" - }, - { - "associatedValues" : [ - - ], - "name" : "delete" - } - ], - "emitStyle" : "const", - "name" : "Method", - "namespace" : [ - "Networking", - "API" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Networking.API.Method", - "tsFullPath" : "Networking.API.Method" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Configuration", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration", - "tsFullPath" : "Configuration" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "debug", - "rawValue" : "debug" - }, - { - "associatedValues" : [ - - ], - "name" : "info", - "rawValue" : "info" - }, - { - "associatedValues" : [ - - ], - "name" : "warning", - "rawValue" : "warning" - }, - { - "associatedValues" : [ - - ], - "name" : "error", - "rawValue" : "error" - } - ], - "emitStyle" : "const", - "name" : "LogLevel", - "namespace" : [ - "Configuration" - ], - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration.LogLevel", - "tsFullPath" : "Configuration.LogLevel" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "http", - "rawValue" : "80" - }, - { - "associatedValues" : [ - - ], - "name" : "https", - "rawValue" : "443" - }, - { - "associatedValues" : [ - - ], - "name" : "development", - "rawValue" : "3000" - } - ], - "emitStyle" : "const", - "name" : "Port", - "namespace" : [ - "Configuration" - ], - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Configuration.Port", - "tsFullPath" : "Configuration.Port" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Internal", - "namespace" : [ - "Networking", - "APIV2" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Internal", - "tsFullPath" : "Networking.APIV2.Internal" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "get" - }, - { - "associatedValues" : [ - - ], - "name" : "post" - } - ], - "emitStyle" : "const", - "name" : "SupportedMethod", - "namespace" : [ - "Networking", - "APIV2", - "Internal" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Internal.SupportedMethod", - "tsFullPath" : "Networking.APIV2.Internal.SupportedMethod" - } - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.json deleted file mode 100644 index 078772ff2..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.json +++ /dev/null @@ -1,1498 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "light", - "rawValue" : "light" - }, - { - "associatedValues" : [ - - ], - "name" : "dark", - "rawValue" : "dark" - }, - { - "associatedValues" : [ - - ], - "name" : "auto", - "rawValue" : "auto" - } - ], - "emitStyle" : "const", - "name" : "Theme", - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Theme", - "tsFullPath" : "Theme" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "light", - "rawValue" : "light" - }, - { - "associatedValues" : [ - - ], - "name" : "dark", - "rawValue" : "dark" - }, - { - "associatedValues" : [ - - ], - "name" : "auto", - "rawValue" : "auto" - } - ], - "emitStyle" : "tsEnum", - "name" : "TSTheme", - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "TSTheme", - "tsFullPath" : "TSTheme" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "enabled", - "rawValue" : "true" - }, - { - "associatedValues" : [ - - ], - "name" : "disabled", - "rawValue" : "false" - } - ], - "emitStyle" : "const", - "name" : "FeatureFlag", - "rawType" : "Bool", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "FeatureFlag", - "tsFullPath" : "FeatureFlag" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "ok", - "rawValue" : "200" - }, - { - "associatedValues" : [ - - ], - "name" : "notFound", - "rawValue" : "404" - }, - { - "associatedValues" : [ - - ], - "name" : "serverError", - "rawValue" : "500" - } - ], - "emitStyle" : "const", - "name" : "HttpStatus", - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "HttpStatus", - "tsFullPath" : "HttpStatus" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "ok", - "rawValue" : "200" - }, - { - "associatedValues" : [ - - ], - "name" : "notFound", - "rawValue" : "404" - }, - { - "associatedValues" : [ - - ], - "name" : "serverError", - "rawValue" : "500" - } - ], - "emitStyle" : "tsEnum", - "name" : "TSHttpStatus", - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "TSHttpStatus", - "tsFullPath" : "TSHttpStatus" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "lowest", - "rawValue" : "-1" - }, - { - "associatedValues" : [ - - ], - "name" : "low", - "rawValue" : "2" - }, - { - "associatedValues" : [ - - ], - "name" : "medium", - "rawValue" : "3" - }, - { - "associatedValues" : [ - - ], - "name" : "high", - "rawValue" : "4" - }, - { - "associatedValues" : [ - - ], - "name" : "highest", - "rawValue" : "5" - } - ], - "emitStyle" : "const", - "name" : "Priority", - "rawType" : "Int32", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Priority", - "tsFullPath" : "Priority" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "tiny", - "rawValue" : "1024" - }, - { - "associatedValues" : [ - - ], - "name" : "small", - "rawValue" : "10240" - }, - { - "associatedValues" : [ - - ], - "name" : "medium", - "rawValue" : "102400" - }, - { - "associatedValues" : [ - - ], - "name" : "large", - "rawValue" : "1048576" - } - ], - "emitStyle" : "const", - "name" : "FileSize", - "rawType" : "Int64", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "FileSize", - "tsFullPath" : "FileSize" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "guest", - "rawValue" : "0" - }, - { - "associatedValues" : [ - - ], - "name" : "user", - "rawValue" : "1000" - }, - { - "associatedValues" : [ - - ], - "name" : "admin", - "rawValue" : "9999" - } - ], - "emitStyle" : "const", - "name" : "UserId", - "rawType" : "UInt", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "UserId", - "tsFullPath" : "UserId" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "invalid", - "rawValue" : "0" - }, - { - "associatedValues" : [ - - ], - "name" : "session", - "rawValue" : "12345" - }, - { - "associatedValues" : [ - - ], - "name" : "refresh", - "rawValue" : "67890" - } - ], - "emitStyle" : "const", - "name" : "TokenId", - "rawType" : "UInt32", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "TokenId", - "tsFullPath" : "TokenId" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "none", - "rawValue" : "0" - }, - { - "associatedValues" : [ - - ], - "name" : "active", - "rawValue" : "9876543210" - }, - { - "associatedValues" : [ - - ], - "name" : "expired", - "rawValue" : "1234567890" - } - ], - "emitStyle" : "const", - "name" : "SessionId", - "rawType" : "UInt64", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "SessionId", - "tsFullPath" : "SessionId" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "rough", - "rawValue" : "0.1" - }, - { - "associatedValues" : [ - - ], - "name" : "normal", - "rawValue" : "0.01" - }, - { - "associatedValues" : [ - - ], - "name" : "fine", - "rawValue" : "0.001" - } - ], - "emitStyle" : "const", - "name" : "Precision", - "rawType" : "Float", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Precision", - "tsFullPath" : "Precision" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "quarter", - "rawValue" : "0.25" - }, - { - "associatedValues" : [ - - ], - "name" : "half", - "rawValue" : "0.5" - }, - { - "associatedValues" : [ - - ], - "name" : "golden", - "rawValue" : "1.618" - }, - { - "associatedValues" : [ - - ], - "name" : "pi", - "rawValue" : "3.14159" - } - ], - "emitStyle" : "const", - "name" : "Ratio", - "rawType" : "Double", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Ratio", - "tsFullPath" : "Ratio" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_setTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setTheme", - "parameters" : [ - { - "label" : "_", - "name" : "theme", - "type" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTheme", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalTheme", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - } - }, - { - "abiName" : "bjs_setTSTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setTSTheme", - "parameters" : [ - { - "label" : "_", - "name" : "theme", - "type" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getTSTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTSTheme", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalTSTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalTSTheme", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } - } - } - }, - { - "abiName" : "bjs_setFeatureFlag", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setFeatureFlag", - "parameters" : [ - { - "label" : "_", - "name" : "flag", - "type" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "Bool" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getFeatureFlag", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getFeatureFlag", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "Bool" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalFeatureFlag", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalFeatureFlag", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "Bool" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "Bool" - } - } - } - } - }, - { - "abiName" : "bjs_setHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setHttpStatus", - "parameters" : [ - { - "label" : "_", - "name" : "status", - "type" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getHttpStatus", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalHttpStatus", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - } - } - }, - { - "abiName" : "bjs_setTSHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setTSHttpStatus", - "parameters" : [ - { - "label" : "_", - "name" : "status", - "type" : { - "rawValueEnum" : { - "_0" : "TSHttpStatus", - "_1" : "Int" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getTSHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTSHttpStatus", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "TSHttpStatus", - "_1" : "Int" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalHttpStatus", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSHttpStatus", - "_1" : "Int" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSHttpStatus", - "_1" : "Int" - } - } - } - } - }, - { - "abiName" : "bjs_setPriority", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setPriority", - "parameters" : [ - { - "label" : "_", - "name" : "priority", - "type" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int32" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getPriority", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getPriority", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int32" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalPriority", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalPriority", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int32" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int32" - } - } - } - } - }, - { - "abiName" : "bjs_setFileSize", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setFileSize", - "parameters" : [ - { - "label" : "_", - "name" : "size", - "type" : { - "rawValueEnum" : { - "_0" : "FileSize", - "_1" : "Int64" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getFileSize", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getFileSize", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "FileSize", - "_1" : "Int64" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalFileSize", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalFileSize", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "FileSize", - "_1" : "Int64" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "FileSize", - "_1" : "Int64" - } - } - } - } - }, - { - "abiName" : "bjs_setUserId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setUserId", - "parameters" : [ - { - "label" : "_", - "name" : "id", - "type" : { - "rawValueEnum" : { - "_0" : "UserId", - "_1" : "UInt" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getUserId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getUserId", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "UserId", - "_1" : "UInt" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalUserId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalUserId", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "UserId", - "_1" : "UInt" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "UserId", - "_1" : "UInt" - } - } - } - } - }, - { - "abiName" : "bjs_setTokenId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setTokenId", - "parameters" : [ - { - "label" : "_", - "name" : "token", - "type" : { - "rawValueEnum" : { - "_0" : "TokenId", - "_1" : "UInt32" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getTokenId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTokenId", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "TokenId", - "_1" : "UInt32" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalTokenId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalTokenId", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TokenId", - "_1" : "UInt32" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TokenId", - "_1" : "UInt32" - } - } - } - } - }, - { - "abiName" : "bjs_setSessionId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setSessionId", - "parameters" : [ - { - "label" : "_", - "name" : "session", - "type" : { - "rawValueEnum" : { - "_0" : "SessionId", - "_1" : "UInt64" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getSessionId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getSessionId", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "SessionId", - "_1" : "UInt64" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalSessionId", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalSessionId", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "SessionId", - "_1" : "UInt64" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "SessionId", - "_1" : "UInt64" - } - } - } - } - }, - { - "abiName" : "bjs_setPrecision", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setPrecision", - "parameters" : [ - { - "label" : "_", - "name" : "precision", - "type" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getPrecision", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getPrecision", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalPrecision", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalPrecision", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - } - } - }, - { - "abiName" : "bjs_setRatio", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setRatio", - "parameters" : [ - { - "label" : "_", - "name" : "ratio", - "type" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_getRatio", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getRatio", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalRatio", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalRatio", - "parameters" : [ - { - "label" : "_", - "name" : "input", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" - } - } - } - } - }, - { - "abiName" : "bjs_processTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processTheme", - "parameters" : [ - { - "label" : "_", - "name" : "theme", - "type" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - }, - { - "abiName" : "bjs_convertPriority", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "convertPriority", - "parameters" : [ - { - "label" : "_", - "name" : "status", - "type" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - } - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int32" - } - } - }, - { - "abiName" : "bjs_validateSession", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "validateSession", - "parameters" : [ - { - "label" : "_", - "name" : "session", - "type" : { - "rawValueEnum" : { - "_0" : "SessionId", - "_1" : "UInt64" - } - } - } - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.json deleted file mode 100644 index 6ee073ca8..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_makeFoo", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : true - }, - "name" : "makeFoo", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "Foo" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift deleted file mode 100644 index 0bebd4e73..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift +++ /dev/null @@ -1,24 +0,0 @@ -@_expose(wasm, "bjs_makeFoo") -@_cdecl("bjs_makeFoo") -public func _bjs_makeFoo() -> Int32 { - #if arch(wasm32) - do { - let ret = try makeFoo() - return ret.bridgeJSLowerReturn() - } catch let error { - if let error = error.thrownValue.object { - withExtendedLifetime(error) { - _swift_js_throw(Int32(bitPattern: $0.id)) - } - } else { - let jsError = JSError(message: String(describing: error)) - withExtendedLifetime(jsError.jsObject) { - _swift_js_throw(Int32(bitPattern: $0.id)) - } - } - return 0 - } - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.json deleted file mode 100644 index 5409a400e..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_GlobalClass_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_GlobalClass_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "GlobalClass", - "namespace" : [ - "GlobalAPI" - ], - "properties" : [ - - ], - "swiftCallName" : "GlobalClass" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_GlobalAPI_globalFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "globalFunction", - "namespace" : [ - "GlobalAPI" - ], - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.json deleted file mode 100644 index bc58d985e..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_PrivateClass_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_PrivateClass_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "PrivateClass", - "namespace" : [ - "PrivateAPI" - ], - "properties" : [ - - ], - "swiftCallName" : "PrivateClass" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_PrivateAPI_privateFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "privateFunction", - "namespace" : [ - "PrivateAPI" - ], - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.json deleted file mode 100644 index eb11e983f..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.json +++ /dev/null @@ -1,182 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Greeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Greeter_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Greeter", - "namespace" : [ - "__Swift", - "Foundation" - ], - "properties" : [ - - ], - "swiftCallName" : "Greeter" - }, - { - "constructor" : { - "abiName" : "bjs_Converter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_Converter_toString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "toString", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Converter", - "namespace" : [ - "Utils", - "Converters" - ], - "properties" : [ - - ], - "swiftCallName" : "Converter" - }, - { - "methods" : [ - { - "abiName" : "bjs_UUID_uuidString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "uuidString", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "UUID", - "namespace" : [ - "__Swift", - "Foundation" - ], - "properties" : [ - - ], - "swiftCallName" : "UUID" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : true, - "functions" : [ - { - "abiName" : "bjs_plainFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "plainFunction", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_MyModule_Utils_namespacedFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "namespacedFunction", - "namespace" : [ - "MyModule", - "Utils" - ], - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.json deleted file mode 100644 index 914b7b894..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.json +++ /dev/null @@ -1,182 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Greeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Greeter_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Greeter", - "namespace" : [ - "__Swift", - "Foundation" - ], - "properties" : [ - - ], - "swiftCallName" : "Greeter" - }, - { - "constructor" : { - "abiName" : "bjs_Converter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_Converter_toString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "toString", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Converter", - "namespace" : [ - "Utils", - "Converters" - ], - "properties" : [ - - ], - "swiftCallName" : "Converter" - }, - { - "methods" : [ - { - "abiName" : "bjs_UUID_uuidString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "uuidString", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "UUID", - "namespace" : [ - "__Swift", - "Foundation" - ], - "properties" : [ - - ], - "swiftCallName" : "UUID" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_plainFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "plainFunction", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_MyModule_Utils_namespacedFunction", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "namespacedFunction", - "namespace" : [ - "MyModule", - "Utils" - ], - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.json deleted file mode 100644 index b3a4fc2c0..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.json +++ /dev/null @@ -1,699 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Greeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Greeter_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_Greeter_changeName", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "changeName", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "Greeter", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "swiftCallName" : "Greeter" - }, - { - "constructor" : { - "abiName" : "bjs_OptionalPropertyHolder_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "OptionalPropertyHolder", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalAge", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalGreeter", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - } - } - ], - "swiftCallName" : "OptionalPropertyHolder" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_roundTripOptionalClass", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalClass", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - } - }, - { - "abiName" : "bjs_testOptionalPropertyRoundtrip", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testOptionalPropertyRoundtrip", - "parameters" : [ - { - "label" : "_", - "name" : "holder", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "OptionalPropertyHolder" - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "OptionalPropertyHolder" - } - } - } - } - }, - { - "abiName" : "bjs_roundTripString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripString", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripInt", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripInt", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripBool", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripBool", - "parameters" : [ - { - "label" : "flag", - "name" : "flag", - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripFloat", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripFloat", - "parameters" : [ - { - "label" : "number", - "name" : "number", - "type" : { - "optional" : { - "_0" : { - "float" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "float" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripDouble", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripDouble", - "parameters" : [ - { - "label" : "precision", - "name" : "precision", - "type" : { - "optional" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "double" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripSyntax", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripSyntax", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripMixSyntax", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripMixSyntax", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripSwiftSyntax", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripSwiftSyntax", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripMixedSwiftSyntax", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripMixedSwiftSyntax", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripWithSpaces", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripWithSpaces", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "optional" : { - "_0" : { - "double" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "double" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripAlias", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripAlias", - "parameters" : [ - { - "label" : "age", - "name" : "age", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "abiName" : "bjs_roundTripOptionalAlias", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalAlias", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "abiName" : "bjs_testMixedOptionals", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testMixedOptionals", - "parameters" : [ - { - "label" : "firstName", - "name" : "firstName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "label" : "lastName", - "name" : "lastName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "label" : "age", - "name" : "age", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "label" : "active", - "name" : "active", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.swift deleted file mode 100644 index 88195f37d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.swift +++ /dev/null @@ -1,341 +0,0 @@ -@_expose(wasm, "bjs_roundTripOptionalClass") -@_cdecl("bjs_roundTripOptionalClass") -public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalClass(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_testOptionalPropertyRoundtrip") -@_cdecl("bjs_testOptionalPropertyRoundtrip") -public func _bjs_testOptionalPropertyRoundtrip(_ holderIsSome: Int32, _ holderValue: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = testOptionalPropertyRoundtrip(_: Optional.bridgeJSLiftParameter(holderIsSome, holderValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripString") -@_cdecl("bjs_roundTripString") -public func _bjs_roundTripString(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripInt") -@_cdecl("bjs_roundTripInt") -public func _bjs_roundTripInt(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripBool") -@_cdecl("bjs_roundTripBool") -public func _bjs_roundTripBool(_ flagIsSome: Int32, _ flagValue: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripFloat") -@_cdecl("bjs_roundTripFloat") -public func _bjs_roundTripFloat(_ numberIsSome: Int32, _ numberValue: Float32) -> Void { - #if arch(wasm32) - let ret = roundTripFloat(number: Optional.bridgeJSLiftParameter(numberIsSome, numberValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripDouble") -@_cdecl("bjs_roundTripDouble") -public func _bjs_roundTripDouble(_ precisionIsSome: Int32, _ precisionValue: Float64) -> Void { - #if arch(wasm32) - let ret = roundTripDouble(precision: Optional.bridgeJSLiftParameter(precisionIsSome, precisionValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripSyntax") -@_cdecl("bjs_roundTripSyntax") -public func _bjs_roundTripSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripMixSyntax") -@_cdecl("bjs_roundTripMixSyntax") -public func _bjs_roundTripMixSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripMixSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripSwiftSyntax") -@_cdecl("bjs_roundTripSwiftSyntax") -public func _bjs_roundTripSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripMixedSwiftSyntax") -@_cdecl("bjs_roundTripMixedSwiftSyntax") -public func _bjs_roundTripMixedSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripMixedSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripWithSpaces") -@_cdecl("bjs_roundTripWithSpaces") -public func _bjs_roundTripWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { - #if arch(wasm32) - let ret = roundTripWithSpaces(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripAlias") -@_cdecl("bjs_roundTripAlias") -public func _bjs_roundTripAlias(_ ageIsSome: Int32, _ ageValue: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalAlias") -@_cdecl("bjs_roundTripOptionalAlias") -public func _bjs_roundTripOptionalAlias(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalAlias(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_testMixedOptionals") -@_cdecl("bjs_testMixedOptionals") -public func _bjs_testMixedOptionals(_ firstNameIsSome: Int32, _ firstNameBytes: Int32, _ firstNameLength: Int32, _ lastNameIsSome: Int32, _ lastNameBytes: Int32, _ lastNameLength: Int32, _ ageIsSome: Int32, _ ageValue: Int32, _ active: Int32) -> Void { - #if arch(wasm32) - let ret = testMixedOptionals(firstName: Optional.bridgeJSLiftParameter(firstNameIsSome, firstNameBytes, firstNameLength), lastName: Optional.bridgeJSLiftParameter(lastNameIsSome, lastNameBytes, lastNameLength), age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue), active: Bool.bridgeJSLiftParameter(active)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_init") -@_cdecl("bjs_Greeter_init") -public func _bjs_Greeter_init(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = Greeter(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_greet") -@_cdecl("bjs_Greeter_greet") -public func _bjs_Greeter_greet(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = Greeter.bridgeJSLiftParameter(_self).greet() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_changeName") -@_cdecl("bjs_Greeter_changeName") -public func _bjs_Greeter_changeName(_ _self: UnsafeMutableRawPointer, _ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { - #if arch(wasm32) - Greeter.bridgeJSLiftParameter(_self).changeName(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_name_get") -@_cdecl("bjs_Greeter_name_get") -public func _bjs_Greeter_name_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = Greeter.bridgeJSLiftParameter(_self).name - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_name_set") -@_cdecl("bjs_Greeter_name_set") -public func _bjs_Greeter_name_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - #if arch(wasm32) - Greeter.bridgeJSLiftParameter(_self).name = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Greeter_deinit") -@_cdecl("bjs_Greeter_deinit") -public func _bjs_Greeter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension Greeter: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_Greeter_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_Greeter_wrap") -fileprivate func _bjs_Greeter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_Greeter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -@_expose(wasm, "bjs_OptionalPropertyHolder_init") -@_cdecl("bjs_OptionalPropertyHolder_init") -public func _bjs_OptionalPropertyHolder_init() -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = OptionalPropertyHolder() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalName_get") -public func _bjs_OptionalPropertyHolder_optionalName_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalName_set") -public func _bjs_OptionalPropertyHolder_optionalName_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalAge_get") -public func _bjs_OptionalPropertyHolder_optionalAge_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalAge_set") -public func _bjs_OptionalPropertyHolder_optionalAge_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_get") -public func _bjs_OptionalPropertyHolder_optionalGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_set") -public func _bjs_OptionalPropertyHolder_optionalGreeter_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_deinit") -@_cdecl("bjs_OptionalPropertyHolder_deinit") -public func _bjs_OptionalPropertyHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension OptionalPropertyHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalPropertyHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_OptionalPropertyHolder_wrap") -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.json deleted file mode 100644 index 3b45bf30f..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_check", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "check", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "int" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "uint" : { - - } - } - }, - { - "label" : "c", - "name" : "c", - "type" : { - "float" : { - - } - } - }, - { - "label" : "d", - "name" : "d", - "type" : { - "double" : { - - } - } - }, - { - "label" : "e", - "name" : "e", - "type" : { - "bool" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.swift deleted file mode 100644 index f91e1e213..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.swift +++ /dev/null @@ -1,9 +0,0 @@ -@_expose(wasm, "bjs_check") -@_cdecl("bjs_check") -public func _bjs_check(_ a: Int32, _ b: Int32, _ c: Float32, _ d: Float64, _ e: Int32) -> Void { - #if arch(wasm32) - check(a: Int.bridgeJSLiftParameter(a), b: UInt.bridgeJSLiftParameter(b), c: Float.bridgeJSLiftParameter(c), d: Double.bridgeJSLiftParameter(d), e: Bool.bridgeJSLiftParameter(e)) - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.json deleted file mode 100644 index d70b0c9b5..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.json +++ /dev/null @@ -1,102 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_checkInt", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkInt", - "parameters" : [ - - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_checkUInt", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkUInt", - "parameters" : [ - - ], - "returnType" : { - "uint" : { - - } - } - }, - { - "abiName" : "bjs_checkFloat", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkFloat", - "parameters" : [ - - ], - "returnType" : { - "float" : { - - } - } - }, - { - "abiName" : "bjs_checkDouble", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkDouble", - "parameters" : [ - - ], - "returnType" : { - "double" : { - - } - } - }, - { - "abiName" : "bjs_checkBool", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkBool", - "parameters" : [ - - ], - "returnType" : { - "bool" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.json deleted file mode 100644 index 43d05d9fa..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.json +++ /dev/null @@ -1,360 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_PropertyHolder_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "intValue", - "name" : "intValue", - "type" : { - "int" : { - - } - } - }, - { - "label" : "floatValue", - "name" : "floatValue", - "type" : { - "float" : { - - } - } - }, - { - "label" : "doubleValue", - "name" : "doubleValue", - "type" : { - "double" : { - - } - } - }, - { - "label" : "boolValue", - "name" : "boolValue", - "type" : { - "bool" : { - - } - } - }, - { - "label" : "stringValue", - "name" : "stringValue", - "type" : { - "string" : { - - } - } - }, - { - "label" : "jsObject", - "name" : "jsObject", - "type" : { - "jsObject" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_PropertyHolder_getAllValues", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getAllValues", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "PropertyHolder", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "intValue", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "floatValue", - "type" : { - "float" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "doubleValue", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "boolValue", - "type" : { - "bool" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "stringValue", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "readonlyInt", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "readonlyFloat", - "type" : { - "float" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "readonlyDouble", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "readonlyBool", - "type" : { - "bool" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "readonlyString", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "jsObject", - "type" : { - "jsObject" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "sibling", - "type" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "lazyValue", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "computedReadonly", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "computedReadWrite", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "observedProperty", - "type" : { - "int" : { - - } - } - } - ], - "swiftCallName" : "PropertyHolder" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_createPropertyHolder", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createPropertyHolder", - "parameters" : [ - { - "label" : "intValue", - "name" : "intValue", - "type" : { - "int" : { - - } - } - }, - { - "label" : "floatValue", - "name" : "floatValue", - "type" : { - "float" : { - - } - } - }, - { - "label" : "doubleValue", - "name" : "doubleValue", - "type" : { - "double" : { - - } - } - }, - { - "label" : "boolValue", - "name" : "boolValue", - "type" : { - "bool" : { - - } - } - }, - { - "label" : "stringValue", - "name" : "stringValue", - "type" : { - "string" : { - - } - } - }, - { - "label" : "jsObject", - "name" : "jsObject", - "type" : { - "jsObject" : { - - } - } - } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" - } - } - }, - { - "abiName" : "bjs_testPropertyHolder", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testPropertyHolder", - "parameters" : [ - { - "label" : "holder", - "name" : "holder", - "type" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.json deleted file mode 100644 index eb8f2426a..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.json +++ /dev/null @@ -1,898 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Helper_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Helper_increment", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "increment", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "Helper", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "swiftCallName" : "Helper" - }, - { - "constructor" : { - "abiName" : "bjs_MyViewController_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "delegate", - "name" : "delegate", - "type" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_MyViewController_triggerEvent", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "triggerEvent", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewController_updateValue", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "updateValue", - "parameters" : [ - { - "label" : "_", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewController_updateCount", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "updateCount", - "parameters" : [ - { - "label" : "_", - "name" : "count", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_MyViewController_updateLabel", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "updateLabel", - "parameters" : [ - { - "label" : "_", - "name" : "prefix", - "type" : { - "string" : { - - } - } - }, - { - "label" : "_", - "name" : "suffix", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewController_checkEvenCount", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkEvenCount", - "parameters" : [ - - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_MyViewController_sendHelper", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "sendHelper", - "parameters" : [ - { - "label" : "_", - "name" : "helper", - "type" : { - "swiftHeapObject" : { - "_0" : "Helper" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "MyViewController", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "delegate", - "type" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "secondDelegate", - "type" : { - "optional" : { - "_0" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - } - } - ], - "swiftCallName" : "MyViewController" - }, - { - "constructor" : { - "abiName" : "bjs_DelegateManager_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "delegates", - "name" : "delegates", - "type" : { - "array" : { - "_0" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_DelegateManager_notifyAll", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "notifyAll", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "DelegateManager", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "delegates", - "type" : { - "array" : { - "_0" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - } - } - ], - "swiftCallName" : "DelegateManager" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" - }, - { - "associatedValues" : [ - - ], - "name" : "south" - }, - { - "associatedValues" : [ - - ], - "name" : "east" - }, - { - "associatedValues" : [ - - ], - "name" : "west" - } - ], - "emitStyle" : "const", - "name" : "Direction", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Direction", - "tsFullPath" : "Direction" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "test", - "rawValue" : "test" - }, - { - "associatedValues" : [ - - ], - "name" : "test2", - "rawValue" : "test2" - } - ], - "emitStyle" : "const", - "name" : "ExampleEnum", - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "ExampleEnum", - "tsFullPath" : "ExampleEnum" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - } - ], - "emitStyle" : "const", - "name" : "Result", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Result", - "tsFullPath" : "Result" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "low", - "rawValue" : "-1" - }, - { - "associatedValues" : [ - - ], - "name" : "medium", - "rawValue" : "0" - }, - { - "associatedValues" : [ - - ], - "name" : "high", - "rawValue" : "1" - } - ], - "emitStyle" : "const", - "name" : "Priority", - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Priority", - "tsFullPath" : "Priority" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_processDelegates", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processDelegates", - "parameters" : [ - { - "label" : "_", - "name" : "delegates", - "type" : { - "array" : { - "_0" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - } - } - ], - "returnType" : { - "array" : { - "_0" : { - "swiftProtocol" : { - "_0" : "MyViewControllerDelegate" - } - } - } - } - } - ], - "protocols" : [ - { - "methods" : [ - { - "abiName" : "bjs_MyViewControllerDelegate_onSomethingHappened", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onSomethingHappened", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_onValueChanged", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onValueChanged", - "parameters" : [ - { - "label" : "_", - "name" : "value", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_onCountUpdated", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onCountUpdated", - "parameters" : [ - { - "label" : "count", - "name" : "count", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_onLabelUpdated", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onLabelUpdated", - "parameters" : [ - { - "label" : "_", - "name" : "prefix", - "type" : { - "string" : { - - } - } - }, - { - "label" : "_", - "name" : "suffix", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_isCountEven", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "isCountEven", - "parameters" : [ - - ], - "returnType" : { - "bool" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_onHelperUpdated", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onHelperUpdated", - "parameters" : [ - { - "label" : "_", - "name" : "helper", - "type" : { - "swiftHeapObject" : { - "_0" : "Helper" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_createHelper", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createHelper", - "parameters" : [ - - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "Helper" - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_onOptionalHelperUpdated", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "onOptionalHelperUpdated", - "parameters" : [ - { - "label" : "_", - "name" : "helper", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Helper" - } - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_createOptionalHelper", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createOptionalHelper", - "parameters" : [ - - ], - "returnType" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Helper" - } - } - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_createEnum", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createEnum", - "parameters" : [ - - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "ExampleEnum", - "_1" : "String" - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_handleResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "handleResult", - "parameters" : [ - { - "label" : "_", - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "Result" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_MyViewControllerDelegate_getResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getResult", - "parameters" : [ - - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "Result" - } - } - } - ], - "name" : "MyViewControllerDelegate", - "properties" : [ - { - "isReadonly" : false, - "name" : "eventCount", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "name" : "delegateName", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "name" : "optionalName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "isReadonly" : false, - "name" : "optionalRawEnum", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "ExampleEnum", - "_1" : "String" - } - } - } - } - }, - { - "isReadonly" : false, - "name" : "rawStringEnum", - "type" : { - "rawValueEnum" : { - "_0" : "ExampleEnum", - "_1" : "String" - } - } - }, - { - "isReadonly" : false, - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "Result" - } - } - }, - { - "isReadonly" : false, - "name" : "optionalResult", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "Result" - } - } - } - } - }, - { - "isReadonly" : false, - "name" : "direction", - "type" : { - "caseEnum" : { - "_0" : "Direction" - } - } - }, - { - "isReadonly" : false, - "name" : "directionOptional", - "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - }, - { - "isReadonly" : false, - "name" : "priority", - "type" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int" - } - } - }, - { - "isReadonly" : false, - "name" : "priorityOptional", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Priority", - "_1" : "Int" - } - } - } - } - } - ] - } - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json deleted file mode 100644 index 3b6937c30..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json +++ /dev/null @@ -1,336 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_MathUtils_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_MathUtils_static_subtract", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "subtract", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "int" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "className" : { - "_0" : "MathUtils" - } - } - }, - { - "abiName" : "bjs_MathUtils_static_add", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "add", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "int" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "className" : { - "_0" : "MathUtils" - } - } - }, - { - "abiName" : "bjs_MathUtils_multiply", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "multiply", - "parameters" : [ - { - "label" : "x", - "name" : "x", - "type" : { - "int" : { - - } - } - }, - { - "label" : "y", - "name" : "y", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - } - } - ], - "name" : "MathUtils", - "properties" : [ - - ], - "swiftCallName" : "MathUtils" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "scientific" - }, - { - "associatedValues" : [ - - ], - "name" : "basic" - } - ], - "emitStyle" : "const", - "name" : "Calculator", - "staticMethods" : [ - { - "abiName" : "bjs_Calculator_static_square", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "square", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "enumName" : { - "_0" : "Calculator" - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Calculator", - "tsFullPath" : "Calculator" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - } - ], - "emitStyle" : "const", - "name" : "APIResult", - "staticMethods" : [ - { - "abiName" : "bjs_APIResult_static_roundtrip", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "roundtrip", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "staticContext" : { - "enumName" : { - "_0" : "APIResult" - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "APIResult", - "tsFullPath" : "APIResult" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Utils", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils", - "tsFullPath" : "Utils" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "String", - "namespace" : [ - "Utils" - ], - "staticMethods" : [ - { - "abiName" : "bjs_Utils_String_static_uppercase", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "uppercase", - "namespace" : [ - "Utils", - "String" - ], - "parameters" : [ - { - "label" : "_", - "name" : "text", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - }, - "staticContext" : { - "namespaceEnum" : { - - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils.String", - "tsFullPath" : "Utils.String" - } - ], - "exposeToGlobal" : true, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json deleted file mode 100644 index 652465dff..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json +++ /dev/null @@ -1,336 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_MathUtils_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - { - "abiName" : "bjs_MathUtils_static_subtract", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "subtract", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "int" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "className" : { - "_0" : "MathUtils" - } - } - }, - { - "abiName" : "bjs_MathUtils_static_add", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "add", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "int" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "className" : { - "_0" : "MathUtils" - } - } - }, - { - "abiName" : "bjs_MathUtils_multiply", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "multiply", - "parameters" : [ - { - "label" : "x", - "name" : "x", - "type" : { - "int" : { - - } - } - }, - { - "label" : "y", - "name" : "y", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - } - } - ], - "name" : "MathUtils", - "properties" : [ - - ], - "swiftCallName" : "MathUtils" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "scientific" - }, - { - "associatedValues" : [ - - ], - "name" : "basic" - } - ], - "emitStyle" : "const", - "name" : "Calculator", - "staticMethods" : [ - { - "abiName" : "bjs_Calculator_static_square", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "square", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "int" : { - - } - } - } - ], - "returnType" : { - "int" : { - - } - }, - "staticContext" : { - "enumName" : { - "_0" : "Calculator" - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Calculator", - "tsFullPath" : "Calculator" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - } - ], - "emitStyle" : "const", - "name" : "APIResult", - "staticMethods" : [ - { - "abiName" : "bjs_APIResult_static_roundtrip", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "roundtrip", - "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - ], - "returnType" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "staticContext" : { - "enumName" : { - "_0" : "APIResult" - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "APIResult", - "tsFullPath" : "APIResult" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Utils", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils", - "tsFullPath" : "Utils" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "String", - "namespace" : [ - "Utils" - ], - "staticMethods" : [ - { - "abiName" : "bjs_Utils_String_static_uppercase", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "uppercase", - "namespace" : [ - "Utils", - "String" - ], - "parameters" : [ - { - "label" : "_", - "name" : "text", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - }, - "staticContext" : { - "namespaceEnum" : { - - } - } - } - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Utils.String", - "tsFullPath" : "Utils.String" - } - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json deleted file mode 100644 index 4ec19f83c..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json +++ /dev/null @@ -1,339 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_PropertyClass_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "PropertyClass", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : true, - "name" : "staticConstant", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "staticVariable", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "jsObjectProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "jsObject" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "classVariable", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "computedProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "readOnlyComputed", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "optionalProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "swiftCallName" : "PropertyClass" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "value1" - }, - { - "associatedValues" : [ - - ], - "name" : "value2" - } - ], - "emitStyle" : "const", - "name" : "PropertyEnum", - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "enumProperty", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "enumConstant", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "computedEnum", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "PropertyEnum", - "tsFullPath" : "PropertyEnum" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "PropertyNamespace", - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "namespaceProperty", - "namespace" : [ - "PropertyNamespace" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "namespaceConstant", - "namespace" : [ - "PropertyNamespace" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "PropertyNamespace", - "tsFullPath" : "PropertyNamespace" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Nested", - "namespace" : [ - "PropertyNamespace" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "nestedProperty", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "nestedConstant", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "nestedDouble", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "double" : { - - } - } - } - ], - "swiftCallName" : "PropertyNamespace.Nested", - "tsFullPath" : "PropertyNamespace.Nested" - } - ], - "exposeToGlobal" : true, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json deleted file mode 100644 index 0e8b2de22..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json +++ /dev/null @@ -1,339 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_PropertyClass_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - - ] - }, - "methods" : [ - - ], - "name" : "PropertyClass", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : true, - "name" : "staticConstant", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "staticVariable", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "jsObjectProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "jsObject" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "classVariable", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "computedProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "readOnlyComputed", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "optionalProperty", - "staticContext" : { - "className" : { - "_0" : "PropertyClass" - } - }, - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "swiftCallName" : "PropertyClass" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "value1" - }, - { - "associatedValues" : [ - - ], - "name" : "value2" - } - ], - "emitStyle" : "const", - "name" : "PropertyEnum", - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "enumProperty", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "enumConstant", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "computedEnum", - "staticContext" : { - "enumName" : { - "_0" : "PropertyEnum" - } - }, - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "PropertyEnum", - "tsFullPath" : "PropertyEnum" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "PropertyNamespace", - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "namespaceProperty", - "namespace" : [ - "PropertyNamespace" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "namespaceConstant", - "namespace" : [ - "PropertyNamespace" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "PropertyNamespace", - "tsFullPath" : "PropertyNamespace" - }, - { - "cases" : [ - - ], - "emitStyle" : "const", - "name" : "Nested", - "namespace" : [ - "PropertyNamespace" - ], - "staticMethods" : [ - - ], - "staticProperties" : [ - { - "isReadonly" : false, - "isStatic" : true, - "name" : "nestedProperty", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "nestedConstant", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "nestedDouble", - "namespace" : [ - "PropertyNamespace", - "Nested" - ], - "staticContext" : { - "namespaceEnum" : { - - } - }, - "type" : { - "double" : { - - } - } - } - ], - "swiftCallName" : "PropertyNamespace.Nested", - "tsFullPath" : "PropertyNamespace.Nested" - } - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.json deleted file mode 100644 index 9116fd482..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_checkString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkString", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_roundtripString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtripString", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.swift deleted file mode 100644 index d980f5bc6..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.swift +++ /dev/null @@ -1,20 +0,0 @@ -@_expose(wasm, "bjs_checkString") -@_cdecl("bjs_checkString") -public func _bjs_checkString(_ aBytes: Int32, _ aLength: Int32) -> Void { - #if arch(wasm32) - checkString(a: String.bridgeJSLiftParameter(aBytes, aLength)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundtripString") -@_cdecl("bjs_roundtripString") -public func _bjs_roundtripString(_ aBytes: Int32, _ aLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundtripString(a: String.bridgeJSLiftParameter(aBytes, aLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.json deleted file mode 100644 index 01f9ca4b7..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_checkString", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "checkString", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.swift deleted file mode 100644 index 1c260ec55..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.swift +++ /dev/null @@ -1,10 +0,0 @@ -@_expose(wasm, "bjs_checkString") -@_cdecl("bjs_checkString") -public func _bjs_checkString() -> Void { - #if arch(wasm32) - let ret = checkString() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.json deleted file mode 100644 index b8f908c2d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.json +++ /dev/null @@ -1,142 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Greeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Greeter_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_Greeter_changeName", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "changeName", - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "name" : "Greeter", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "Greeter" - }, - { - "explicitAccessControl" : "public", - "methods" : [ - - ], - "name" : "PublicGreeter", - "properties" : [ - - ], - "swiftCallName" : "PublicGreeter" - }, - { - "explicitAccessControl" : "package", - "methods" : [ - - ], - "name" : "PackageGreeter", - "properties" : [ - - ], - "swiftCallName" : "PackageGreeter" - } - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_takeGreeter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeGreeter", - "parameters" : [ - { - "label" : "greeter", - "name" : "greeter", - "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - ], - "returnType" : { - "void" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.json deleted file mode 100644 index 27627407b..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.json +++ /dev/null @@ -1,1075 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Person_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "explicitAccessControl" : "public", - "methods" : [ - - ], - "name" : "Person", - "properties" : [ - - ], - "swiftCallName" : "Person" - }, - { - "constructor" : { - "abiName" : "bjs_TestProcessor_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "transform", - "name" : "transform", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSS_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "string" : { - - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_TestProcessor_getTransform", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getTransform", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSS_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "string" : { - - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_processWithCustom", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processWithCustom", - "parameters" : [ - { - "label" : "_", - "name" : "text", - "type" : { - "string" : { - - } - } - }, - { - "label" : "customTransform", - "name" : "customTransform", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSS_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "string" : { - - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_printTogether", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "printTogether", - "parameters" : [ - { - "label" : "person", - "name" : "person", - "type" : { - "swiftHeapObject" : { - "_0" : "Person" - } - } - }, - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "label" : "ratio", - "name" : "ratio", - "type" : { - "double" : { - - } - } - }, - { - "label" : "customTransform", - "name" : "customTransform", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq6PersonCSqSSSqSd_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Person" - } - } - } - }, - { - "optional" : { - "_0" : { - "string" : { - - } - } - } - }, - { - "optional" : { - "_0" : { - "double" : { - - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_roundtrip", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtrip", - "parameters" : [ - { - "label" : "_", - "name" : "personClosure", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule6PersonC_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "swiftHeapObject" : { - "_0" : "Person" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule6PersonC_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "swiftHeapObject" : { - "_0" : "Person" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_roundtripOptional", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtripOptional", - "parameters" : [ - { - "label" : "_", - "name" : "personClosure", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq6PersonC_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Person" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq6PersonC_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Person" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_processDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processDirection", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule9DirectionO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "caseEnum" : { - "_0" : "Direction" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_processTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processTheme", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule5ThemeO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_processHttpStatus", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processHttpStatus", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule10HttpStatusO_Si", - "moduleName" : "TestModule", - "parameters" : [ - { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - ], - "returnType" : { - "int" : { - - } - } - } - } - } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_processAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processAPIResult", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule9APIResultO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_makeDirectionChecker", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "makeDirectionChecker", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule9DirectionO_Sb", - "moduleName" : "TestModule", - "parameters" : [ - { - "caseEnum" : { - "_0" : "Direction" - } - } - ], - "returnType" : { - "bool" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_makeThemeValidator", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "makeThemeValidator", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule5ThemeO_Sb", - "moduleName" : "TestModule", - "parameters" : [ - { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - ], - "returnType" : { - "bool" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_makeStatusCodeExtractor", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "makeStatusCodeExtractor", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule10HttpStatusO_Si", - "moduleName" : "TestModule", - "parameters" : [ - { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } - ], - "returnType" : { - "int" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_makeAPIResultHandler", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "makeAPIResultHandler", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModule9APIResultO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - }, - { - "abiName" : "bjs_TestProcessor_processOptionalDirection", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalDirection", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq9DirectionO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_processOptionalTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalTheme", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq5ThemeO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_processOptionalAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalAPIResult", - "parameters" : [ - { - "label" : "_", - "name" : "callback", - "type" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq9APIResultO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - }, - { - "abiName" : "bjs_TestProcessor_makeOptionalDirectionFormatter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "makeOptionalDirectionFormatter", - "parameters" : [ - - ], - "returnType" : { - "closure" : { - "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "10TestModuleSq9DirectionO_SS", - "moduleName" : "TestModule", - "parameters" : [ - { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } - } - ], - "returnType" : { - "string" : { - - } - } - } - } - } - } - ], - "name" : "TestProcessor", - "properties" : [ - - ], - "swiftCallName" : "TestProcessor" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" - }, - { - "associatedValues" : [ - - ], - "name" : "south" - }, - { - "associatedValues" : [ - - ], - "name" : "east" - }, - { - "associatedValues" : [ - - ], - "name" : "west" - } - ], - "emitStyle" : "const", - "name" : "Direction", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Direction", - "tsFullPath" : "Direction" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "light", - "rawValue" : "light" - }, - { - "associatedValues" : [ - - ], - "name" : "dark", - "rawValue" : "dark" - }, - { - "associatedValues" : [ - - ], - "name" : "auto", - "rawValue" : "auto" - } - ], - "emitStyle" : "const", - "name" : "Theme", - "rawType" : "String", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Theme", - "tsFullPath" : "Theme" - }, - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "ok", - "rawValue" : "200" - }, - { - "associatedValues" : [ - - ], - "name" : "notFound", - "rawValue" : "404" - }, - { - "associatedValues" : [ - - ], - "name" : "serverError", - "rawValue" : "500" - }, - { - "associatedValues" : [ - - ], - "name" : "unknown", - "rawValue" : "-1" - } - ], - "emitStyle" : "const", - "name" : "HttpStatus", - "rawType" : "Int", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "HttpStatus", - "tsFullPath" : "HttpStatus" - }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "string" : { - - } - } - } - ], - "name" : "success" - }, - { - "associatedValues" : [ - { - "type" : { - "int" : { - - } - } - } - ], - "name" : "failure" - }, - { - "associatedValues" : [ - { - "type" : { - "bool" : { - - } - } - } - ], - "name" : "flag" - }, - { - "associatedValues" : [ - { - "type" : { - "float" : { - - } - } - } - ], - "name" : "rate" - }, - { - "associatedValues" : [ - { - "type" : { - "double" : { - - } - } - } - ], - "name" : "precise" - }, - { - "associatedValues" : [ - - ], - "name" : "info" - } - ], - "emitStyle" : "const", - "name" : "APIResult", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "APIResult", - "tsFullPath" : "APIResult" - } - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.json deleted file mode 100644 index ca8f7c625..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.json +++ /dev/null @@ -1,520 +0,0 @@ -{ - "classes" : [ - { - "constructor" : { - "abiName" : "bjs_Greeter_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "string" : { - - } - } - } - ] - }, - "methods" : [ - { - "abiName" : "bjs_Greeter_greet", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "greet", - "parameters" : [ - - ], - "returnType" : { - "string" : { - - } - } - } - ], - "name" : "Greeter", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "Greeter" - } - ], - "enums" : [ - { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "rough", - "rawValue" : "0.1" - }, - { - "associatedValues" : [ - - ], - "name" : "fine", - "rawValue" : "0.001" - } - ], - "emitStyle" : "const", - "name" : "Precision", - "rawType" : "Float", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Precision", - "tsFullPath" : "Precision" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_roundtrip", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundtrip", - "parameters" : [ - { - "label" : "_", - "name" : "session", - "type" : { - "swiftStruct" : { - "_0" : "Person" - } - } - } - ], - "returnType" : { - "swiftStruct" : { - "_0" : "Person" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - { - "constructor" : { - "abiName" : "bjs_DataPoint_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "x", - "name" : "x", - "type" : { - "double" : { - - } - } - }, - { - "label" : "y", - "name" : "y", - "type" : { - "double" : { - - } - } - }, - { - "label" : "label", - "name" : "label", - "type" : { - "string" : { - - } - } - }, - { - "label" : "optCount", - "name" : "optCount", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "label" : "optFlag", - "name" : "optFlag", - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "DataPoint", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "x", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "y", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "label", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "optCount", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "optFlag", - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ], - "swiftCallName" : "DataPoint" - }, - { - "methods" : [ - - ], - "name" : "Address", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "street", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "city", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "zipCode", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - } - ], - "swiftCallName" : "Address" - }, - { - "methods" : [ - - ], - "name" : "Person", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "age", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "address", - "type" : { - "swiftStruct" : { - "_0" : "Address" - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "email", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ], - "swiftCallName" : "Person" - }, - { - "methods" : [ - - ], - "name" : "Session", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "id", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "owner", - "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - ], - "swiftCallName" : "Session" - }, - { - "methods" : [ - - ], - "name" : "Measurement", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "value", - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "precision", - "type" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "optionalPrecision", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - } - } - } - ], - "swiftCallName" : "Measurement" - }, - { - "methods" : [ - { - "abiName" : "bjs_ConfigStruct_static_update", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "update", - "parameters" : [ - { - "label" : "_", - "name" : "timeout", - "type" : { - "double" : { - - } - } - } - ], - "returnType" : { - "double" : { - - } - }, - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" - } - } - } - ], - "name" : "ConfigStruct", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : true, - "name" : "maxRetries", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" - } - }, - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "defaultConfig", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" - } - }, - "type" : { - "string" : { - - } - } - }, - { - "isReadonly" : false, - "isStatic" : true, - "name" : "timeout", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" - } - }, - "type" : { - "double" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : true, - "name" : "computedSetting", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" - } - }, - "type" : { - "string" : { - - } - } - } - ], - "swiftCallName" : "ConfigStruct" - } - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.json deleted file mode 100644 index ad47cbf0b..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_throwsSomething", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : true - }, - "name" : "throwsSomething", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.json deleted file mode 100644 index f38cd9440..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.json +++ /dev/null @@ -1,413 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_takeUnsafeRawPointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeUnsafeRawPointer", - "parameters" : [ - { - "label" : "_", - "name" : "p", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_takeUnsafeMutableRawPointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeUnsafeMutableRawPointer", - "parameters" : [ - { - "label" : "_", - "name" : "p", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_takeOpaquePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeOpaquePointer", - "parameters" : [ - { - "label" : "_", - "name" : "p", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_takeUnsafePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeUnsafePointer", - "parameters" : [ - { - "label" : "_", - "name" : "p", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_takeUnsafeMutablePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "takeUnsafeMutablePointer", - "parameters" : [ - { - "label" : "_", - "name" : "p", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } - } - ], - "returnType" : { - "void" : { - - } - } - }, - { - "abiName" : "bjs_returnUnsafeRawPointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "returnUnsafeRawPointer", - "parameters" : [ - - ], - "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - }, - { - "abiName" : "bjs_returnUnsafeMutableRawPointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "returnUnsafeMutableRawPointer", - "parameters" : [ - - ], - "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - }, - { - "abiName" : "bjs_returnOpaquePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "returnOpaquePointer", - "parameters" : [ - - ], - "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - }, - { - "abiName" : "bjs_returnUnsafePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "returnUnsafePointer", - "parameters" : [ - - ], - "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } - } - } - }, - { - "abiName" : "bjs_returnUnsafeMutablePointer", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "returnUnsafeMutablePointer", - "parameters" : [ - - ], - "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } - }, - { - "abiName" : "bjs_roundTripPointerFields", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripPointerFields", - "parameters" : [ - { - "label" : "_", - "name" : "value", - "type" : { - "swiftStruct" : { - "_0" : "PointerFields" - } - } - } - ], - "returnType" : { - "swiftStruct" : { - "_0" : "PointerFields" - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - { - "constructor" : { - "abiName" : "bjs_PointerFields_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "raw", - "name" : "raw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - }, - { - "label" : "mutRaw", - "name" : "mutRaw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - }, - { - "label" : "opaque", - "name" : "opaque", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - }, - { - "label" : "ptr", - "name" : "ptr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } - } - } - }, - { - "label" : "mutPtr", - "name" : "mutPtr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "PointerFields", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "raw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "mutRaw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "opaque", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "ptr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "mutPtr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } - } - ], - "swiftCallName" : "PointerFields" - } - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.json deleted file mode 100644 index b6b9c7bcb..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_check", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "check", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } - } - ], - "protocols" : [ - - ], - "structs" : [ - - ] -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.swift deleted file mode 100644 index d5bc03b15..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.swift +++ /dev/null @@ -1,9 +0,0 @@ -@_expose(wasm, "bjs_check") -@_cdecl("bjs_check") -public func _bjs_check() -> Void { - #if arch(wasm32) - check() - #else - fatalError("Only available on WebAssembly") - #endif -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift deleted file mode 100644 index cf1118df0..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift +++ /dev/null @@ -1,13 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void - -@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws (JSException) -> Void - -@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.swift deleted file mode 100644 index 4e2cec8dc..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.swift +++ /dev/null @@ -1,51 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkArray") -fileprivate func bjs_checkArray(_ a: Int32) -> Void -#else -fileprivate func bjs_checkArray(_ a: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkArray(_ a: JSObject) throws(JSException) -> Void { - let aValue = a.bridgeJSLowerParameter() - bjs_checkArray(aValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkArrayWithLength") -fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void -#else -fileprivate func bjs_checkArrayWithLength(_ a: Int32, _ b: Float64) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void { - let aValue = a.bridgeJSLowerParameter() - let bValue = b.bridgeJSLowerParameter() - bjs_checkArrayWithLength(aValue, bValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkArray") -fileprivate func bjs_checkArray(_ a: Int32) -> Void -#else -fileprivate func bjs_checkArray(_ a: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkArray(_ a: JSObject) throws(JSException) -> Void { - let aValue = a.bridgeJSLowerParameter() - bjs_checkArray(aValue) - if let error = _swift_js_take_exception() { - throw error - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift deleted file mode 100644 index dd0377377..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift +++ /dev/null @@ -1,21 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func asyncReturnVoid() throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripInt(_ v: Double) throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripString(_ v: String) throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripBool(_ v: Bool) throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripFloat(_ v: Double) throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripDouble(_ v: Double) throws (JSException) -> JSPromise - -@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws (JSException) -> JSPromise diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.swift deleted file mode 100644 index 1cc954b0d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.swift +++ /dev/null @@ -1,124 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncReturnVoid") -fileprivate func bjs_asyncReturnVoid() -> Int32 -#else -fileprivate func bjs_asyncReturnVoid() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncReturnVoid() throws(JSException) -> JSPromise { - let ret = bjs_asyncReturnVoid() - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripInt") -fileprivate func bjs_asyncRoundTripInt(_ v: Float64) -> Int32 -#else -fileprivate func bjs_asyncRoundTripInt(_ v: Float64) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripInt(_ v: Double) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripInt(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripString") -fileprivate func bjs_asyncRoundTripString(_ v: Int32) -> Int32 -#else -fileprivate func bjs_asyncRoundTripString(_ v: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripString(_ v: String) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripString(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripBool") -fileprivate func bjs_asyncRoundTripBool(_ v: Int32) -> Int32 -#else -fileprivate func bjs_asyncRoundTripBool(_ v: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripBool(_ v: Bool) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripBool(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripFloat") -fileprivate func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32 -#else -fileprivate func bjs_asyncRoundTripFloat(_ v: Float64) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripFloat(_ v: Double) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripFloat(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripDouble") -fileprivate func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32 -#else -fileprivate func bjs_asyncRoundTripDouble(_ v: Float64) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripDouble(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_asyncRoundTripJSObject") -fileprivate func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32 -#else -fileprivate func bjs_asyncRoundTripJSObject(_ v: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$asyncRoundTripJSObject(_ v: JSObject) throws(JSException) -> JSPromise { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_asyncRoundTripJSObject(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSPromise.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift deleted file mode 100644 index 5d13234ca..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift +++ /dev/null @@ -1,14 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func returnAnimatable() throws (JSException) -> Animatable - -@JSClass struct Animatable { - @JSFunction func animate(_ keyframes: JSObject, _ options: JSObject) throws (JSException) -> JSObject - @JSFunction func getAnimations(_ options: JSObject) throws (JSException) -> JSObject -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.swift deleted file mode 100644 index fd16bd0d8..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.swift +++ /dev/null @@ -1,55 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_returnAnimatable") -fileprivate func bjs_returnAnimatable() -> Int32 -#else -fileprivate func bjs_returnAnimatable() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$returnAnimatable() throws(JSException) -> Animatable { - let ret = bjs_returnAnimatable() - if let error = _swift_js_take_exception() { - throw error - } - return Animatable.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Animatable_animate") -fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 -#else -fileprivate func bjs_Animatable_animate(_ self: Int32, _ keyframes: Int32, _ options: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Animatable_getAnimations") -fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 -#else -fileprivate func bjs_Animatable_getAnimations(_ self: Int32, _ options: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$Animatable_animate(_ self: JSObject, _ keyframes: JSObject, _ options: JSObject) throws(JSException) -> JSObject { - let selfValue = self.bridgeJSLowerParameter() - let keyframesValue = keyframes.bridgeJSLowerParameter() - let optionsValue = options.bridgeJSLowerParameter() - let ret = bjs_Animatable_animate(selfValue, keyframesValue, optionsValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSObject.bridgeJSLiftReturn(ret) -} - -func _$Animatable_getAnimations(_ self: JSObject, _ options: JSObject) throws(JSException) -> JSObject { - let selfValue = self.bridgeJSLowerParameter() - let optionsValue = options.bridgeJSLowerParameter() - let ret = bjs_Animatable_getAnimations(selfValue, optionsValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSObject.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift deleted file mode 100644 index 43d6a3eb9..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift +++ /dev/null @@ -1,44 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func createArrayBuffer() throws (JSException) -> ArrayBufferLike - -@JSClass struct ArrayBufferLike { - @JSGetter var byteLength: Double - @JSFunction func slice(_ begin: Double, _ end: Double) throws (JSException) -> ArrayBufferLike -} - -@JSFunction func createWeirdObject() throws (JSException) -> WeirdNaming - -@JSClass struct WeirdNaming { - @JSGetter var normalProperty: String - @JSSetter func setNormalProperty(_ value: String) throws (JSException) - @JSGetter(jsName: "property-with-dashes") var property_with_dashes: Double - @JSSetter(jsName: "property-with-dashes") func setProperty_with_dashes(_ value: Double) throws (JSException) - @JSGetter(jsName: "123invalidStart") var _123invalidStart: Bool - @JSSetter(jsName: "123invalidStart") func set_123invalidStart(_ value: Bool) throws (JSException) - @JSGetter(jsName: "property with spaces") var property_with_spaces: String - @JSSetter(jsName: "property with spaces") func setProperty_with_spaces(_ value: String) throws (JSException) - @JSGetter(jsName: "@specialChar") var _specialChar: Double - @JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws (JSException) - @JSGetter var constructor: String - @JSSetter func setConstructor(_ value: String) throws (JSException) - @JSGetter var `for`: String - @JSSetter func setFor(_ value: String) throws (JSException) - @JSGetter var `Any`: String - @JSSetter(jsName: "Any") func setAny(_ value: String) throws (JSException) - @JSFunction func `as`() throws (JSException) -> Void - @JSFunction func `try`() throws (JSException) -> Void -} - -@JSClass(jsName: "$Weird") struct _Weird { - @JSFunction init() throws (JSException) - @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws (JSException) -> Void -} - -@JSFunction func createWeirdClass() throws (JSException) -> _Weird diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift deleted file mode 100644 index 47efcbc84..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift +++ /dev/null @@ -1,33 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func createDatabaseConnection(_ config: JSObject) throws (JSException) -> DatabaseConnection - -@JSClass struct DatabaseConnection { - @JSFunction func connect(_ url: String) throws (JSException) -> Void - @JSFunction func execute(_ query: String) throws (JSException) -> JSObject - @JSGetter var isConnected: Bool - @JSGetter var connectionTimeout: Double - @JSSetter func setConnectionTimeout(_ value: Double) throws (JSException) -} - -@JSFunction func createLogger(_ level: String) throws (JSException) -> Logger - -@JSClass struct Logger { - @JSFunction func log(_ message: String) throws (JSException) -> Void - @JSFunction func error(_ message: String, _ error: JSObject) throws (JSException) -> Void - @JSGetter var level: String -} - -@JSFunction func getConfigManager() throws (JSException) -> ConfigManager - -@JSClass struct ConfigManager { - @JSFunction func get(_ key: String) throws (JSException) -> JSObject - @JSFunction func set(_ key: String, _ value: JSObject) throws (JSException) -> Void - @JSGetter var configPath: String -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.swift deleted file mode 100644 index 1c1418af8..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.swift +++ /dev/null @@ -1,254 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createDatabaseConnection") -fileprivate func bjs_createDatabaseConnection(_ config: Int32) -> Int32 -#else -fileprivate func bjs_createDatabaseConnection(_ config: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$createDatabaseConnection(_ config: JSObject) throws(JSException) -> DatabaseConnection { - let configValue = config.bridgeJSLowerParameter() - let ret = bjs_createDatabaseConnection(configValue) - if let error = _swift_js_take_exception() { - throw error - } - return DatabaseConnection.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createLogger") -fileprivate func bjs_createLogger(_ level: Int32) -> Int32 -#else -fileprivate func bjs_createLogger(_ level: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$createLogger(_ level: String) throws(JSException) -> Logger { - let levelValue = level.bridgeJSLowerParameter() - let ret = bjs_createLogger(levelValue) - if let error = _swift_js_take_exception() { - throw error - } - return Logger.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_getConfigManager") -fileprivate func bjs_getConfigManager() -> Int32 -#else -fileprivate func bjs_getConfigManager() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$getConfigManager() throws(JSException) -> ConfigManager { - let ret = bjs_getConfigManager() - if let error = _swift_js_take_exception() { - throw error - } - return ConfigManager.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_DatabaseConnection_isConnected_get") -fileprivate func bjs_DatabaseConnection_isConnected_get(_ self: Int32) -> Int32 -#else -fileprivate func bjs_DatabaseConnection_isConnected_get(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_DatabaseConnection_connectionTimeout_get") -fileprivate func bjs_DatabaseConnection_connectionTimeout_get(_ self: Int32) -> Float64 -#else -fileprivate func bjs_DatabaseConnection_connectionTimeout_get(_ self: Int32) -> Float64 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_DatabaseConnection_connectionTimeout_set") -fileprivate func bjs_DatabaseConnection_connectionTimeout_set(_ self: Int32, _ newValue: Float64) -> Void -#else -fileprivate func bjs_DatabaseConnection_connectionTimeout_set(_ self: Int32, _ newValue: Float64) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_DatabaseConnection_connect") -fileprivate func bjs_DatabaseConnection_connect(_ self: Int32, _ url: Int32) -> Void -#else -fileprivate func bjs_DatabaseConnection_connect(_ self: Int32, _ url: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_DatabaseConnection_execute") -fileprivate func bjs_DatabaseConnection_execute(_ self: Int32, _ query: Int32) -> Int32 -#else -fileprivate func bjs_DatabaseConnection_execute(_ self: Int32, _ query: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$DatabaseConnection_isConnected_get(_ self: JSObject) throws(JSException) -> Bool { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_DatabaseConnection_isConnected_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return Bool.bridgeJSLiftReturn(ret) -} - -func _$DatabaseConnection_connectionTimeout_get(_ self: JSObject) throws(JSException) -> Double { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_DatabaseConnection_connectionTimeout_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return Double.bridgeJSLiftReturn(ret) -} - -func _$DatabaseConnection_connectionTimeout_set(_ self: JSObject, _ newValue: Double) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let newValueValue = newValue.bridgeJSLowerParameter() - bjs_DatabaseConnection_connectionTimeout_set(selfValue, newValueValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -func _$DatabaseConnection_connect(_ self: JSObject, _ url: String) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let urlValue = url.bridgeJSLowerParameter() - bjs_DatabaseConnection_connect(selfValue, urlValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -func _$DatabaseConnection_execute(_ self: JSObject, _ query: String) throws(JSException) -> JSObject { - let selfValue = self.bridgeJSLowerParameter() - let queryValue = query.bridgeJSLowerParameter() - let ret = bjs_DatabaseConnection_execute(selfValue, queryValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSObject.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Logger_level_get") -fileprivate func bjs_Logger_level_get(_ self: Int32) -> Int32 -#else -fileprivate func bjs_Logger_level_get(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Logger_log") -fileprivate func bjs_Logger_log(_ self: Int32, _ message: Int32) -> Void -#else -fileprivate func bjs_Logger_log(_ self: Int32, _ message: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_Logger_error") -fileprivate func bjs_Logger_error(_ self: Int32, _ message: Int32, _ error: Int32) -> Void -#else -fileprivate func bjs_Logger_error(_ self: Int32, _ message: Int32, _ error: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$Logger_level_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_Logger_level_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$Logger_log(_ self: JSObject, _ message: String) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let messageValue = message.bridgeJSLowerParameter() - bjs_Logger_log(selfValue, messageValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -func _$Logger_error(_ self: JSObject, _ message: String, _ error: JSObject) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let messageValue = message.bridgeJSLowerParameter() - let errorValue = error.bridgeJSLowerParameter() - bjs_Logger_error(selfValue, messageValue, errorValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_ConfigManager_configPath_get") -fileprivate func bjs_ConfigManager_configPath_get(_ self: Int32) -> Int32 -#else -fileprivate func bjs_ConfigManager_configPath_get(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_ConfigManager_get") -fileprivate func bjs_ConfigManager_get(_ self: Int32, _ key: Int32) -> Int32 -#else -fileprivate func bjs_ConfigManager_get(_ self: Int32, _ key: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_ConfigManager_set") -fileprivate func bjs_ConfigManager_set(_ self: Int32, _ key: Int32, _ value: Int32) -> Void -#else -fileprivate func bjs_ConfigManager_set(_ self: Int32, _ key: Int32, _ value: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$ConfigManager_configPath_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_ConfigManager_configPath_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$ConfigManager_get(_ self: JSObject, _ key: String) throws(JSException) -> JSObject { - let selfValue = self.bridgeJSLowerParameter() - let keyValue = key.bridgeJSLowerParameter() - let ret = bjs_ConfigManager_get(selfValue, keyValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSObject.bridgeJSLiftReturn(ret) -} - -func _$ConfigManager_set(_ self: JSObject, _ key: String, _ value: JSObject) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let keyValue = key.bridgeJSLowerParameter() - let valueValue = value.bridgeJSLowerParameter() - bjs_ConfigManager_set(selfValue, keyValue, valueValue) - if let error = _swift_js_take_exception() { - throw error - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift deleted file mode 100644 index eea42f30d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift +++ /dev/null @@ -1,9 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func check(_ a: Double, _ b: Bool) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.swift deleted file mode 100644 index 6d59ca52f..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.swift +++ /dev/null @@ -1,17 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_check") -fileprivate func bjs_check(_ a: Float64, _ b: Int32) -> Void -#else -fileprivate func bjs_check(_ a: Float64, _ b: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$check(_ a: Double, _ b: Bool) throws(JSException) -> Void { - let aValue = a.bridgeJSLowerParameter() - let bValue = b.bridgeJSLowerParameter() - bjs_check(aValue, bValue) - if let error = _swift_js_take_exception() { - throw error - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift deleted file mode 100644 index 15867131d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift +++ /dev/null @@ -1,11 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func checkNumber() throws (JSException) -> Double - -@JSFunction func checkBoolean() throws (JSException) -> Bool diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.swift deleted file mode 100644 index 17f536ba5..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.swift +++ /dev/null @@ -1,33 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkNumber") -fileprivate func bjs_checkNumber() -> Float64 -#else -fileprivate func bjs_checkNumber() -> Float64 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkNumber() throws(JSException) -> Double { - let ret = bjs_checkNumber() - if let error = _swift_js_take_exception() { - throw error - } - return Double.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkBoolean") -fileprivate func bjs_checkBoolean() -> Int32 -#else -fileprivate func bjs_checkBoolean() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkBoolean() throws(JSException) -> Bool { - let ret = bjs_checkBoolean() - if let error = _swift_js_take_exception() { - throw error - } - return Bool.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift deleted file mode 100644 index 0c0dfb362..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift +++ /dev/null @@ -1,14 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func jsRoundTripNumber(_ v: Double) throws (JSException) -> Double - -@JSClass struct JsGreeter { - @JSFunction init(_ name: String) throws (JSException) - @JSFunction func greet() throws (JSException) -> String -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.swift deleted file mode 100644 index 01c2b1e6e..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.swift +++ /dev/null @@ -1,53 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_jsRoundTripNumber") -fileprivate func bjs_jsRoundTripNumber(_ v: Float64) -> Float64 -#else -fileprivate func bjs_jsRoundTripNumber(_ v: Float64) -> Float64 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$jsRoundTripNumber(_ v: Double) throws(JSException) -> Double { - let vValue = v.bridgeJSLowerParameter() - let ret = bjs_jsRoundTripNumber(vValue) - if let error = _swift_js_take_exception() { - throw error - } - return Double.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_JsGreeter_init") -fileprivate func bjs_JsGreeter_init(_ name: Int32) -> Int32 -#else -fileprivate func bjs_JsGreeter_init(_ name: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_JsGreeter_greet") -fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 -#else -fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$JsGreeter_init(_ name: String) throws(JSException) -> JSObject { - let nameValue = name.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_init(nameValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSObject.bridgeJSLiftReturn(ret) -} - -func _$JsGreeter_greet(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_greet(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift deleted file mode 100644 index b0049af28..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift +++ /dev/null @@ -1,17 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -enum FeatureFlag: String { - case foo = "foo" - case bar = "bar" -} -extension FeatureFlag: _BridgedSwiftEnumNoPayload {} - -@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> Void - -@JSFunction func returnsFeatureFlag() throws (JSException) -> FeatureFlag diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.swift deleted file mode 100644 index 3059865ac..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.swift +++ /dev/null @@ -1,33 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_takesFeatureFlag") -fileprivate func bjs_takesFeatureFlag(_ flag: Int32) -> Void -#else -fileprivate func bjs_takesFeatureFlag(_ flag: Int32) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void { - let flagValue = flag.bridgeJSLowerParameter() - bjs_takesFeatureFlag(flagValue) - if let error = _swift_js_take_exception() { - throw error - } -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_returnsFeatureFlag") -fileprivate func bjs_returnsFeatureFlag() -> Int32 -#else -fileprivate func bjs_returnsFeatureFlag() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$returnsFeatureFlag() throws(JSException) -> FeatureFlag { - let ret = bjs_returnsFeatureFlag() - if let error = _swift_js_take_exception() { - throw error - } - return FeatureFlag.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift deleted file mode 100644 index 38fe0dd2b..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift +++ /dev/null @@ -1,11 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func checkString(_ a: String) throws (JSException) -> Void - -@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift deleted file mode 100644 index 60aae03c4..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift +++ /dev/null @@ -1,9 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func checkString() throws (JSException) -> String diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftStructImports.ImportMacros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftStructImports.ImportMacros.swift deleted file mode 100644 index 54470e5de..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftStructImports.ImportMacros.swift +++ /dev/null @@ -1,19 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_translate") -fileprivate func bjs_translate(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 -#else -fileprivate func bjs_translate(_ point: Int32, _ dx: Int32, _ dy: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$translate(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException) -> Point { - let pointObjectId = point.bridgeJSLowerParameter() - let dxValue = dx.bridgeJSLowerParameter() - let dyValue = dy.bridgeJSLowerParameter() - let ret = bjs_translate(pointObjectId, dxValue, dyValue) - if let error = _swift_js_take_exception() { - throw error - } - return Point.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift deleted file mode 100644 index e0d6c9d24..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift +++ /dev/null @@ -1,22 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func createTS2Skeleton() throws (JSException) -> TypeScriptProcessor - -@JSClass struct TypeScriptProcessor { - @JSFunction func convert(_ ts: String) throws (JSException) -> String - @JSFunction func validate(_ ts: String) throws (JSException) -> Bool - @JSGetter var version: String -} - -@JSFunction func createCodeGenerator(_ format: String) throws (JSException) -> CodeGenerator - -@JSClass struct CodeGenerator { - @JSFunction func generate(_ input: JSObject) throws (JSException) -> String - @JSGetter var outputFormat: String -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.swift deleted file mode 100644 index 54d3b9156..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.swift +++ /dev/null @@ -1,127 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createTS2Skeleton") -fileprivate func bjs_createTS2Skeleton() -> Int32 -#else -fileprivate func bjs_createTS2Skeleton() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$createTS2Skeleton() throws(JSException) -> TypeScriptProcessor { - let ret = bjs_createTS2Skeleton() - if let error = _swift_js_take_exception() { - throw error - } - return TypeScriptProcessor.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_createCodeGenerator") -fileprivate func bjs_createCodeGenerator(_ format: Int32) -> Int32 -#else -fileprivate func bjs_createCodeGenerator(_ format: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$createCodeGenerator(_ format: String) throws(JSException) -> CodeGenerator { - let formatValue = format.bridgeJSLowerParameter() - let ret = bjs_createCodeGenerator(formatValue) - if let error = _swift_js_take_exception() { - throw error - } - return CodeGenerator.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_TypeScriptProcessor_version_get") -fileprivate func bjs_TypeScriptProcessor_version_get(_ self: Int32) -> Int32 -#else -fileprivate func bjs_TypeScriptProcessor_version_get(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_TypeScriptProcessor_convert") -fileprivate func bjs_TypeScriptProcessor_convert(_ self: Int32, _ ts: Int32) -> Int32 -#else -fileprivate func bjs_TypeScriptProcessor_convert(_ self: Int32, _ ts: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_TypeScriptProcessor_validate") -fileprivate func bjs_TypeScriptProcessor_validate(_ self: Int32, _ ts: Int32) -> Int32 -#else -fileprivate func bjs_TypeScriptProcessor_validate(_ self: Int32, _ ts: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$TypeScriptProcessor_version_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_TypeScriptProcessor_version_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$TypeScriptProcessor_convert(_ self: JSObject, _ ts: String) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let tsValue = ts.bridgeJSLowerParameter() - let ret = bjs_TypeScriptProcessor_convert(selfValue, tsValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$TypeScriptProcessor_validate(_ self: JSObject, _ ts: String) throws(JSException) -> Bool { - let selfValue = self.bridgeJSLowerParameter() - let tsValue = ts.bridgeJSLowerParameter() - let ret = bjs_TypeScriptProcessor_validate(selfValue, tsValue) - if let error = _swift_js_take_exception() { - throw error - } - return Bool.bridgeJSLiftReturn(ret) -} - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_CodeGenerator_outputFormat_get") -fileprivate func bjs_CodeGenerator_outputFormat_get(_ self: Int32) -> Int32 -#else -fileprivate func bjs_CodeGenerator_outputFormat_get(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_CodeGenerator_generate") -fileprivate func bjs_CodeGenerator_generate(_ self: Int32, _ input: Int32) -> Int32 -#else -fileprivate func bjs_CodeGenerator_generate(_ self: Int32, _ input: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$CodeGenerator_outputFormat_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_CodeGenerator_outputFormat_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$CodeGenerator_generate(_ self: JSObject, _ input: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let inputValue = input.bridgeJSLowerParameter() - let ret = bjs_CodeGenerator_generate(selfValue, inputValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift deleted file mode 100644 index 62b2b4663..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift +++ /dev/null @@ -1,9 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func checkSimple(_ a: Double) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.swift deleted file mode 100644 index 0b5d0c40d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.swift +++ /dev/null @@ -1,16 +0,0 @@ -#if arch(wasm32) -@_extern(wasm, module: "Check", name: "bjs_checkSimple") -fileprivate func bjs_checkSimple(_ a: Float64) -> Void -#else -fileprivate func bjs_checkSimple(_ a: Float64) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$checkSimple(_ a: Double) throws(JSException) -> Void { - let aValue = a.bridgeJSLowerParameter() - bjs_checkSimple(aValue) - if let error = _swift_js_take_exception() { - throw error - } -} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift deleted file mode 100644 index 1fbf3376d..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift +++ /dev/null @@ -1,16 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSClass struct Greeter { - @JSGetter var name: String - @JSSetter func setName(_ value: String) throws (JSException) - @JSGetter var age: Double - @JSFunction init(_ name: String) throws (JSException) - @JSFunction func greet() throws (JSException) -> String - @JSFunction func changeName(_ name: String) throws (JSException) -> Void -} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift deleted file mode 100644 index b3a7fc6f6..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift +++ /dev/null @@ -1,9 +0,0 @@ -// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, -// DO NOT EDIT. -// -// To update this file, just rebuild your project or run -// `swift package bridge-js`. - -@_spi(Experimental) import JavaScriptKit - -@JSFunction func check() throws (JSException) -> Void diff --git a/Plugins/PackageToJS/Templates/instantiate.js b/Plugins/PackageToJS/Templates/instantiate.js index 54a7212c6..c17d78841 100644 --- a/Plugins/PackageToJS/Templates/instantiate.js +++ b/Plugins/PackageToJS/Templates/instantiate.js @@ -62,6 +62,9 @@ async function createInstantiator(options, swift) { swift_js_get_optional_double_presence: unexpectedBjsCall, swift_js_get_optional_double_value: unexpectedBjsCall, swift_js_get_optional_heap_object_pointer: unexpectedBjsCall, + swift_js_push_pointer: unexpectedBjsCall, + swift_js_pop_pointer: unexpectedBjsCall, + swift_js_struct_cleanup: unexpectedBjsCall, } }, /** @param {WebAssembly.Instance} instance */ diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 1e7893c82..1c8592724 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -64,6 +64,8 @@ import _CJavaScriptKit // // MARK: ExportSwift // @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ ...) -> <#Self#> { // } +// @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> <#Self#> { +// } // @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> <#WasmCoreType#> { // } // } @@ -75,7 +77,10 @@ import _CJavaScriptKit // - `func bridgeJSLowerParameter()`: lower the given higher-level parameter to a WebAssembly core type // - `func bridgeJSLiftReturn(_ ...) -> <#TargetType#>`: lift the given Wasm core type return value to a higher-level type // - `func bridgeJSLiftParameter(_ ...) -> <#TargetType#>`: lift the given Wasm core type parameters to a higher-level type +// - `func bridgeJSLiftParameter() -> <#TargetType#>`: no-arg overload that pops parameters from the param stack internally. +// Note: Pop order must match Swift's left-to-right argument evaluation order. // - `func bridgeJSLowerReturn() -> <#WasmCoreType#>`: lower the given higher-level return value to a Wasm core type +// - `func bridgeJSLowerStackReturn()`: push the value onto the return stack (used by _BridgedSwiftStackType for array elements) // // Optional types (ExportSwift only) additionally define: // - `func bridgeJSLowerParameterWithRetain()`: lower optional heap object with ownership transfer for escaping closures @@ -94,7 +99,21 @@ public protocol _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { consuming func bridgeJSLowerReturn() -> WasmCoreType } -extension Bool: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +public protocol _BridgedSwiftStackType { + associatedtype StackLiftResult = Self + static func bridgeJSLiftParameter() -> StackLiftResult + consuming func bridgeJSLowerStackReturn() +} + +/// Types that bridge with the same (isSome, value) ABI as Optional. +/// Used by JSUndefinedOr so all bridge methods delegate to Optional. +public protocol _BridgedAsOptional { + associatedtype Wrapped + var optionalRepresentation: Wrapped? { get } + init(optional: Wrapped?) +} + +extension Bool: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { self ? 1 : 0 @@ -106,12 +125,18 @@ extension Bool: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> Bool { value == 1 } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Bool { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { self ? 1 : 0 } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(self ? 1 : 0) + } } -extension Int: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +extension Int: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { Int32(self) @@ -123,12 +148,18 @@ extension Int: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> Int { Int(value) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Int { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { Int32(self) } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(Int32(self)) + } } -extension UInt: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +extension UInt: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { Int32(bitPattern: UInt32(self)) @@ -140,12 +171,54 @@ extension UInt: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> UInt { UInt(UInt32(bitPattern: value)) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UInt { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { Int32(bitPattern: UInt32(self)) } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(Int32(bitPattern: UInt32(self))) + } +} + +extension Int32: _BridgedSwiftStackType { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Int32 { + _swift_js_pop_i32() + } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(self) + } +} + +extension Int64: _BridgedSwiftStackType { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Int64 { + Int64(_swift_js_pop_i32()) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(Int32(self)) + } +} + +extension UInt32: _BridgedSwiftStackType { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UInt32 { + UInt32(bitPattern: _swift_js_pop_i32()) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(Int32(bitPattern: self)) + } } -extension Float: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +extension UInt64: _BridgedSwiftStackType { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UInt64 { + UInt64(UInt32(bitPattern: _swift_js_pop_i32())) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(Int32(bitPattern: UInt32(self))) + } +} + +extension Float: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Float32 { Float32(self) @@ -157,12 +230,18 @@ extension Float: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Float32) -> Float { Float(value) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Float { + bridgeJSLiftParameter(_swift_js_pop_f32()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Float32 { Float32(self) } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_f32(Float32(self)) + } } -extension Double: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +extension Double: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Float64 { Float64(self) @@ -174,12 +253,20 @@ extension Double: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Float64) -> Double { Double(value) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Double { + bridgeJSLiftParameter(_swift_js_pop_f64()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Float64 { Float64(self) } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_f64(Float64(self)) + } } -extension String { +extension String: _BridgedSwiftStackType { + public typealias StackLiftResult = String + // MARK: ImportTS @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> Int32 { @@ -210,14 +297,30 @@ extension String { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> String { + let bytes = _swift_js_pop_i32() + let count = _swift_js_pop_i32() + return bridgeJSLiftParameter(bytes, count) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { return self.withUTF8 { ptr in _swift_js_return_string(ptr.baseAddress, Int32(ptr.count)) } } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + self.withUTF8 { ptr in + _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) + } + } } -extension JSObject { +extension JSObject: _BridgedSwiftStackType { + // JSObject is a non-final class, so we must explicitly specify the associated type + // rather than relying on the default `Self` (which Swift requires for covariant returns). + public typealias StackLiftResult = JSObject + // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { @@ -233,15 +336,109 @@ extension JSObject { JSObject(id: JavaScriptObjectRef(bitPattern: id)) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> JSObject { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Int32 { return _swift_js_retain(Int32(bitPattern: self.id)) } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(bridgeJSLowerReturn()) + } +} + +extension JSValue: _BridgedSwiftStackType { + public typealias StackLiftResult = JSValue + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (kind: Int32, payload1: Int32, payload2: Double) { + return withRawJSValue { raw in + ( + kind: Int32(raw.kind.rawValue), + payload1: Int32(bitPattern: raw.payload1), + payload2: raw.payload2 + ) + } + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn( + _ kind: Int32, + _ payload1: Int32, + _ payload2: Double + ) -> JSValue { + return bridgeJSLiftParameter(kind, payload1, payload2) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter( + _ kind: Int32, + _ payload1: Int32, + _ payload2: Double + ) -> JSValue { + let retainedPayload1: Int32 + if let kindEnum = JavaScriptValueKind(rawValue: UInt32(kind)) { + switch kindEnum { + case .string, .object, .symbol, .bigInt: + retainedPayload1 = _swift_js_retain(payload1) + default: + retainedPayload1 = payload1 + } + } else { + retainedPayload1 = payload1 + } + + guard let kindEnum = JavaScriptValueKind(rawValue: UInt32(kind)) else { + fatalError("Invalid JSValue kind: \(kind)") + } + let rawValue = RawJSValue( + kind: kindEnum, + payload1: JavaScriptPayload1(UInt32(bitPattern: retainedPayload1)), + payload2: payload2 + ) + return rawValue.jsValue + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> JSValue { + let payload2 = _swift_js_pop_f64() + let payload1 = _swift_js_pop_i32() + let kind = _swift_js_pop_i32() + return bridgeJSLiftParameter(kind, payload1, payload2) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn() -> JSValue { + let payload2 = _swift_js_pop_f64() + let payload1 = _swift_js_pop_i32() + let kind = _swift_js_pop_i32() + return bridgeJSLiftParameter(kind, payload1, payload2) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + let lowered = bridgeJSLowerParameter() + let retainedPayload1: Int32 + if let kind = JavaScriptValueKind(rawValue: UInt32(lowered.kind)) { + switch kind { + case .string, .object, .symbol, .bigInt: + retainedPayload1 = _swift_js_retain(lowered.payload1) + default: + retainedPayload1 = lowered.payload1 + } + } else { + retainedPayload1 = lowered.payload1 + } + _swift_js_push_i32(lowered.kind) + _swift_js_push_i32(retainedPayload1) + _swift_js_push_f64(lowered.payload2) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + bridgeJSLowerReturn() + } } /// A protocol that Swift heap objects exposed to JavaScript via `@JS class` must conform to. /// /// The conformance is automatically synthesized by the BridgeJS code generator. -public protocol _BridgedSwiftHeapObject: AnyObject {} +public protocol _BridgedSwiftHeapObject: AnyObject, _BridgedSwiftStackType {} /// Define the lowering/lifting for `_BridgedSwiftHeapObject` extension _BridgedSwiftHeapObject { @@ -260,10 +457,16 @@ extension _BridgedSwiftHeapObject { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ pointer: UnsafeMutableRawPointer) -> Self { Unmanaged.fromOpaque(pointer).takeUnretainedValue() } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { // Perform a manual retain on the object, which will be balanced by a release called via FinalizationRegistry return Unmanaged.passRetained(self).toOpaque() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(Unmanaged.passRetained(self).toOpaque()) + } } // MARK: Closure Box Protocol @@ -289,17 +492,25 @@ extension _JSBridgedClass { /// A protocol that Swift protocol wrappers exposed from JavaScript must conform to. /// /// The conformance is automatically synthesized by the BridgeJS code generator. -public protocol _BridgedSwiftProtocolWrapper { +public protocol _BridgedSwiftProtocolWrapper: _BridgedSwiftStackType { var jsObject: JSObject { get } static func bridgeJSLiftParameter(_ value: Int32) -> Self } extension _BridgedSwiftProtocolWrapper { // MARK: ExportSwift + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Int32 { jsObject.bridgeJSLowerReturn() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(jsObject.bridgeJSLowerReturn()) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> Int32 { jsObject.bridgeJSLowerParameter() } @@ -310,10 +521,29 @@ extension _BridgedSwiftProtocolWrapper { /// The conformance is automatically synthesized by the BridgeJS code generator. public protocol _BridgedSwiftEnumNoPayload {} +/// A protocol for raw value enums that enables automatic stack operations. +/// +/// Conforming to this protocol provides default implementations of `_BridgedSwiftStackType` +/// methods by delegating to the raw value's stack operations. The raw value type must itself +/// conform to `_BridgedSwiftStackType`. +/// +/// The conformance is automatically synthesized by the BridgeJS code generator. +public protocol _BridgedSwiftRawValueEnum: _BridgedSwiftStackType, RawRepresentable +where RawValue: _BridgedSwiftStackType, RawValue.StackLiftResult == RawValue {} + +extension _BridgedSwiftRawValueEnum { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(rawValue: RawValue.bridgeJSLiftParameter())! + } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + rawValue.bridgeJSLowerStackReturn() + } +} + /// A protocol that Swift case enum types (enums without raw values or associated values) conform to. /// /// The conformance is automatically synthesized by the BridgeJS code generator. -public protocol _BridgedSwiftCaseEnum { +public protocol _BridgedSwiftCaseEnum: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) consuming func bridgeJSLowerParameter() -> Int32 @_spi(BridgeJS) static func bridgeJSLiftReturn(_ value: Int32) -> Self @@ -323,10 +553,20 @@ public protocol _BridgedSwiftCaseEnum { @_spi(BridgeJS) consuming func bridgeJSLowerReturn() -> Int32 } +extension _BridgedSwiftCaseEnum { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_i32(bridgeJSLowerReturn()) + } +} + /// A protocol that Swift associated value enum types conform to. /// /// The conformance is automatically synthesized by the BridgeJS code generator. -public protocol _BridgedSwiftAssociatedValueEnum: _BridgedSwiftTypeLoweredIntoVoidType { +public protocol _BridgedSwiftAssociatedValueEnum: _BridgedSwiftTypeLoweredIntoVoidType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) consuming func bridgeJSLowerParameter() -> Int32 @_spi(BridgeJS) static func bridgeJSLiftReturn(_ caseId: Int32) -> Self @@ -336,10 +576,20 @@ public protocol _BridgedSwiftAssociatedValueEnum: _BridgedSwiftTypeLoweredIntoVo @_spi(BridgeJS) consuming func bridgeJSLowerReturn() -> Void } +extension _BridgedSwiftAssociatedValueEnum { + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + bridgeJSLowerReturn() + } +} + /// A protocol that Swift struct types conform to. /// /// The conformance is automatically synthesized by the BridgeJS code generator. -public protocol _BridgedSwiftStruct: _BridgedSwiftTypeLoweredIntoVoidType { +public protocol _BridgedSwiftStruct: _BridgedSwiftTypeLoweredIntoVoidType, _BridgedSwiftStackType { // MARK: ExportSwift @_spi(BridgeJS) static func bridgeJSLiftParameter() -> Self @_spi(BridgeJS) consuming func bridgeJSLowerReturn() -> Void @@ -359,6 +609,10 @@ extension _BridgedSwiftStruct { let jsObject = JSObject.bridgeJSLiftReturn(objectId) return Self(unsafelyCopying: jsObject) } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + bridgeJSLowerReturn() + } } extension _BridgedSwiftEnumNoPayload where Self: RawRepresentable, RawValue == String { @@ -685,16 +939,20 @@ func _swift_js_return_optional_double(_ isSome: Int32, _ value: Float64) { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_pop_pointer") -@_spi(BridgeJS) public func _swift_js_pop_pointer() -> UnsafeMutableRawPointer +private func _swift_js_pop_pointer_extern() -> UnsafeMutableRawPointer #else -@_spi(BridgeJS) public func _swift_js_pop_pointer() -> UnsafeMutableRawPointer { +private func _swift_js_pop_pointer_extern() -> UnsafeMutableRawPointer { _onlyAvailableOnWasm() } #endif +@_spi(BridgeJS) @inline(never) public func _swift_js_pop_pointer() -> UnsafeMutableRawPointer { + _swift_js_pop_pointer_extern() +} + // MARK: - UnsafePointer family -extension UnsafeMutableRawPointer { +extension UnsafeMutableRawPointer: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> UnsafeMutableRawPointer { self } @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn( @@ -713,10 +971,16 @@ extension UnsafeMutableRawPointer { { pointer } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UnsafeMutableRawPointer { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { self } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(self) + } } -extension UnsafeRawPointer { +extension UnsafeRawPointer: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> UnsafeMutableRawPointer { UnsafeMutableRawPointer(mutating: self) @@ -737,12 +1001,18 @@ extension UnsafeRawPointer { { UnsafeRawPointer(pointer) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UnsafeRawPointer { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { bridgeJSLowerParameter() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(UnsafeMutableRawPointer(mutating: self)) + } } -extension OpaquePointer { +extension OpaquePointer: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> UnsafeMutableRawPointer { UnsafeMutableRawPointer(mutating: UnsafeRawPointer(self)) @@ -763,12 +1033,18 @@ extension OpaquePointer { { OpaquePointer(UnsafeRawPointer(pointer)) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> OpaquePointer { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { bridgeJSLowerParameter() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(UnsafeMutableRawPointer(mutating: UnsafeRawPointer(self))) + } } -extension UnsafePointer { +extension UnsafePointer: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> UnsafeMutableRawPointer { UnsafeMutableRawPointer(mutating: UnsafeRawPointer(self)) @@ -789,12 +1065,18 @@ extension UnsafePointer { { UnsafeRawPointer(pointer).assumingMemoryBound(to: Pointee.self) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UnsafePointer { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { bridgeJSLowerParameter() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(bridgeJSLowerParameter()) + } } -extension UnsafeMutablePointer { +extension UnsafeMutablePointer: _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> UnsafeMutableRawPointer { UnsafeMutableRawPointer(self) @@ -815,17 +1097,18 @@ extension UnsafeMutablePointer { { pointer.assumingMemoryBound(to: Pointee.self) } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UnsafeMutablePointer { + bridgeJSLiftParameter(_swift_js_pop_pointer()) + } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> UnsafeMutableRawPointer { bridgeJSLowerParameter() } + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + _swift_js_push_pointer(bridgeJSLowerParameter()) + } } extension Optional where Wrapped == Bool { - // MARK: ImportTS - - @available(*, unavailable, message: "Optional Bool type is not supported to be passed to imported JS functions") - @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> Void {} - // MARK: ExportSwift @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> ( @@ -847,6 +1130,12 @@ extension Optional where Wrapped == Bool { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Bool? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ value: Int32) -> Bool? { switch value { case -1: @@ -871,11 +1160,6 @@ extension Optional where Wrapped == Bool { } extension Optional where Wrapped == Int { - // MARK: ImportTS - - @available(*, unavailable, message: "Optional Int type is not supported to be passed to imported JS functions") - @_spi(BridgeJS) public func bridgeJSLowerParameter() -> Void {} - // MARK: ExportSwift @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> ( @@ -897,6 +1181,12 @@ extension Optional where Wrapped == Int { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Int? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Int? { let isSome = _swift_js_get_optional_int_presence() if isSome == 0 { @@ -917,14 +1207,7 @@ extension Optional where Wrapped == Int { } extension Optional where Wrapped == UInt { - // MARK: ImportTS - - @available(*, unavailable, message: "Optional UInt type is not supported to be passed to imported JS functions") - @_spi(BridgeJS) public func bridgeJSLowerParameter() -> Void {} - - // MARK: ExportSwift - - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameterWithPresence() -> ( + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> ( isSome: Int32, value: Int32 ) { switch consume self { @@ -943,6 +1226,12 @@ extension Optional where Wrapped == UInt { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> UInt? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> UInt? { let isSome = _swift_js_get_optional_int_presence() if isSome == 0 { @@ -984,6 +1273,13 @@ extension Optional where Wrapped == String { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> String? { + let isSome = _swift_js_pop_i32() + let bytes = _swift_js_pop_i32() + let count = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, bytes, count) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> String? { let length = _swift_js_get_optional_string() if length < 0 { @@ -1026,6 +1322,12 @@ extension Optional where Wrapped == JSObject { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> JSObject? { + let isSome = _swift_js_pop_i32() + let objectId = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, objectId) + } + @_spi(BridgeJS) public func bridgeJSLowerReturn() -> Void { switch self { case .none: @@ -1037,6 +1339,105 @@ extension Optional where Wrapped == JSObject { } } +extension Optional where Wrapped == JSValue { + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> ( + isSome: Int32, kind: Int32, payload1: Int32, payload2: Double + ) { + switch consume self { + case .none: + return (isSome: 0, kind: 0, payload1: 0, payload2: 0) + case .some(let wrapped): + let lowered = wrapped.bridgeJSLowerParameter() + return ( + isSome: 1, + kind: lowered.kind, + payload1: lowered.payload1, + payload2: lowered.payload2 + ) + } + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter( + _ isSome: Int32, + _ kind: Int32, + _ payload1: Int32, + _ payload2: Double + ) -> JSValue? { + if isSome == 0 { + return nil + } else { + return JSValue.bridgeJSLiftParameter(kind, payload1, payload2) + } + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> JSValue? { + let isSome = _swift_js_pop_i32() + if isSome == 0 { + return nil + } + let payload2 = _swift_js_pop_f64() + let payload1 = _swift_js_pop_i32() + let kind = _swift_js_pop_i32() + return JSValue.bridgeJSLiftParameter(kind, payload1, payload2) + } + + @_spi(BridgeJS) public func bridgeJSLowerReturn() -> Void { + switch self { + case .none: + _swift_js_push_i32(0) + case .some(let value): + value.bridgeJSLowerReturn() + _swift_js_push_i32(1) + } + } +} + +extension Optional where Wrapped == [JSValue] { + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch consume self { + case .none: + return 0 + case .some(let array): + array.bridgeJSLowerReturn() + return 1 + } + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32) -> [JSValue]? { + if isSome == 0 { + return nil + } + return [JSValue].bridgeJSLiftParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> [JSValue]? { + let isSome = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn() -> [JSValue]? { + let isSome = _swift_js_pop_i32() + if isSome == 0 { + return nil + } + return [JSValue].bridgeJSLiftReturn() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + switch consume self { + case .none: + _swift_js_push_i32(0) + case .some(let array): + array.bridgeJSLowerReturn() + _swift_js_push_i32(1) + } + } +} + extension Optional where Wrapped: _BridgedSwiftProtocolWrapper { // MARK: ExportSwift @@ -1053,7 +1454,7 @@ extension Optional where Wrapped: _BridgedSwiftProtocolWrapper { case .none: _swift_js_return_optional_object(0, 0) case .some(let wrapper): - let retainedId = wrapper.bridgeJSLowerReturn() + let retainedId: Int32 = wrapper.bridgeJSLowerReturn() _swift_js_return_optional_object(1, retainedId) } } @@ -1121,6 +1522,12 @@ extension Optional where Wrapped: _BridgedSwiftHeapObject { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let pointer = _swift_js_pop_pointer() + return bridgeJSLiftParameter(isSome, pointer) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Wrapped? { let pointer = _swift_js_get_optional_heap_object_pointer() if pointer == UnsafeMutableRawPointer(bitPattern: 0) { @@ -1135,7 +1542,7 @@ extension Optional where Wrapped: _BridgedSwiftHeapObject { case .none: _swift_js_return_optional_heap_object(0, nil) case .some(let value): - let retainedPointer = value.bridgeJSLowerReturn() + let retainedPointer: UnsafeMutableRawPointer = value.bridgeJSLowerReturn() _swift_js_return_optional_heap_object(1, retainedPointer) } } @@ -1162,6 +1569,12 @@ extension Optional where Wrapped == Float { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Float? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_f32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Float? { let isSome = _swift_js_get_optional_float_presence() if isSome == 0 { @@ -1204,6 +1617,12 @@ extension Optional where Wrapped == Double { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Double? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_f64() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Double? { let isSome = _swift_js_get_optional_double_presence() if isSome == 0 { @@ -1244,6 +1663,12 @@ extension Optional where Wrapped: _BridgedSwiftCaseEnum { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ value: Int32) -> Wrapped? { if value == -1 { return nil @@ -1303,6 +1728,13 @@ extension Optional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepres return optionalRawValue.flatMap { Wrapped(rawValue: $0) } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let bytes = _swift_js_pop_i32() + let count = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, bytes, count) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Wrapped? { let length = _swift_js_get_optional_string() if length < 0 { @@ -1335,6 +1767,12 @@ extension Optional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepres return optionalRawValue.flatMap { Wrapped(rawValue: $0) } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Wrapped? { let isSome = _swift_js_get_optional_int_presence() if isSome == 0 { @@ -1359,6 +1797,12 @@ extension Optional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepres return optionalRawValue.flatMap { Wrapped(rawValue: $0) } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { let optionalRawValue: Bool? = self?.rawValue optionalRawValue.bridgeJSLowerReturn() @@ -1384,6 +1828,12 @@ extension Optional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepres return optionalRawValue.flatMap { Wrapped(rawValue: $0) } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_f32() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Wrapped? { let isSome = _swift_js_get_optional_float_presence() if isSome == 0 { @@ -1419,6 +1869,12 @@ extension Optional where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepres return optionalRawValue.flatMap { Wrapped(rawValue: $0) } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let wrappedValue = _swift_js_pop_f64() + return bridgeJSLiftParameter(isSome, wrappedValue) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Wrapped? { let isSome = _swift_js_get_optional_double_presence() if isSome == 0 { @@ -1457,6 +1913,12 @@ extension Optional where Wrapped: _BridgedSwiftAssociatedValueEnum { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + let caseId = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome, caseId) + } + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ caseId: Int32) -> Wrapped? { if caseId == -1 { return nil @@ -1488,6 +1950,11 @@ extension Optional where Wrapped: _BridgedSwiftStruct { } } + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Wrapped? { + let isSome = _swift_js_pop_i32() + return bridgeJSLiftParameter(isSome) + } + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { switch consume self { case .none: @@ -1498,3 +1965,413 @@ extension Optional where Wrapped: _BridgedSwiftStruct { } } } + +// MARK: - _BridgedAsOptional (JSUndefinedOr) delegating to Optional + +extension _BridgedAsOptional where Wrapped == Bool { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ value: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftReturn(value)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == Int { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == UInt { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == String { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter( + _ isSome: Int32, + _ bytes: Int32, + _ count: Int32 + ) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, bytes, count)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == JSObject { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ objectId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, objectId)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftProtocolWrapper { + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ objectId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, objectId)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftHeapObject { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, pointer: UnsafeMutableRawPointer) + { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameterWithRetain() -> ( + isSome: Int32, pointer: UnsafeMutableRawPointer + ) { + optionalRepresentation.bridgeJSLowerParameterWithRetain() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter( + _ isSome: Int32, + _ pointer: UnsafeMutableRawPointer + ) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, pointer)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == Float { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Float32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Float32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped == Double { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Float64) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Float64) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftCaseEnum { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ caseId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, caseId)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ caseId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftReturn(caseId)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftTypeLoweredIntoVoidType { + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional +where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == String { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter( + _ isSome: Int32, + _ bytes: Int32, + _ count: Int32 + ) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, bytes, count)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional +where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == Int { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional +where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == Bool { + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional +where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == Float { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Float32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Float32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional +where Wrapped: _BridgedSwiftEnumNoPayload, Wrapped: RawRepresentable, Wrapped.RawValue == Double { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, value: Float64) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ wrappedValue: Float64) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, wrappedValue)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturnFromSideChannel() -> Self { + Self(optional: Optional.bridgeJSLiftReturnFromSideChannel()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftAssociatedValueEnum { + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> (isSome: Int32, caseId: Int32) { + optionalRepresentation.bridgeJSLowerParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32, _ caseId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome, caseId)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn(_ caseId: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftReturn(caseId)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftStruct { + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32) -> Self { + Self(optional: Optional.bridgeJSLiftParameter(isSome)) + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> Self { + Self(optional: Optional.bridgeJSLiftParameter()) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +// MARK: - Array Support + +extension Array: _BridgedSwiftStackType where Element: _BridgedSwiftStackType, Element.StackLiftResult == Element { + public typealias StackLiftResult = [Element] + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> [Element] { + let count = Int(_swift_js_pop_i32()) + var result: [Element] = [] + result.reserveCapacity(count) + for _ in 0.. [Element] { + bridgeJSLiftParameter() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + bridgeJSLowerReturn() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() { + let array = self + for elem in array { + elem.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(Int32(array.count)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() { + bridgeJSLowerReturn() + } +} diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Array.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Array.md index fed56618f..53d008068 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Array.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Array.md @@ -119,6 +119,8 @@ const result = exports.processNumbers(original); | Struct arrays: `[MyStruct]` | ✅ | | Class arrays: `[MyClass]` | ✅ | | Enum arrays (case, raw value, associated value) | ✅ | +| `JSObject` arrays: `[JSObject]` | ✅ | +| `@JSClass struct` arrays: `[Foo]` | ✅ | | Nested arrays: `[[Int]]` | ✅ | | Optional arrays: `[Int]?` | ✅ | | Arrays of optionals: `[Int?]` | ✅ | diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Enum.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Enum.md index 3dda2b9c5..6fb3afeda 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Enum.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Enum.md @@ -509,8 +509,9 @@ This differs from classes, which use reference semantics and share state across | Static functions | ✅ | | Static properties | ✅ | | Associated values: `String`, `Int`, `Bool`, `Float`, `Double` | ✅ | -| Associated values: Custom classes/structs | ❌ | -| Associated values: Other enums | ❌ | -| Associated values: Arrays/Collections | ❌ | -| Associated values: Optionals | ❌ | +| Associated values: Custom classes/structs | ✅ | +| Associated values: Other enums (case, raw value, and associated value) | ✅ | +| Associated values: `JSObject` | ✅ | +| Associated values: Arrays | ✅ | +| Associated values: Optionals of all supported types | ✅ | | Generics | ❌ | diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Struct.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Struct.md index 236b822ab..10babd9b6 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Struct.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Struct.md @@ -160,6 +160,8 @@ This differs from classes, which use reference semantics and share state across | Stored fields with supported types | ✅ | | Optional fields | ✅ | | Nested structs | ✅ | +| `JSObject` fields | ✅ | +| `@JSClass struct` fields | ✅ | | Instance methods | ✅ | | Static methods | ✅ | | Static properties | ✅ | diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Supported-Types.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Supported-Types.md index 668fe21b5..c872c0dda 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Supported-Types.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Supported-Types.md @@ -9,7 +9,7 @@ Use this page as a quick reference for how common TypeScript types appear in Swi | `number` | `Double` | | `string` | `String` | | `boolean` | `Bool` | -| TODO | `Array` | +| `T[]` | `[T]` | | TODO | `Dictionary` | | `T \| undefined` | TODO | | `T \| null` | `Optional` | diff --git a/Sources/JavaScriptKit/JSUndefinedOr.swift b/Sources/JavaScriptKit/JSUndefinedOr.swift new file mode 100644 index 000000000..82e218105 --- /dev/null +++ b/Sources/JavaScriptKit/JSUndefinedOr.swift @@ -0,0 +1,45 @@ +@frozen public enum JSUndefinedOr { + case undefined + case value(Wrapped) + + /// Convenience accessor for the undefined case. + public static var undefinedValue: Self { .undefined } + + @inlinable + public init(optional: Wrapped?) { + self = optional.map(Self.value) ?? .undefined + } + + @inlinable + public var optionalRepresentation: Wrapped? { + switch self { + case .undefined: + return nil + case .value(let wrapped): + return wrapped + } + } +} + +extension JSUndefinedOr: ConstructibleFromJSValue where Wrapped: ConstructibleFromJSValue { + public static func construct(from value: JSValue) -> Self? { + if value.isUndefined { return .undefined } + guard let wrapped = Wrapped.construct(from: value) else { return nil } + return .value(wrapped) + } +} + +extension JSUndefinedOr: ConvertibleToJSValue where Wrapped: ConvertibleToJSValue { + public var jsValue: JSValue { + switch self { + case .undefined: + return .undefined + case .value(let wrapped): + return wrapped.jsValue + } + } +} + +// MARK: - BridgeJS (via _BridgedAsOptional in BridgeJSIntrinsics) + +extension JSUndefinedOr: _BridgedAsOptional {} diff --git a/Tests/BridgeJSGlobalTests/Generated/BridgeJS.swift b/Tests/BridgeJSGlobalTests/Generated/BridgeJS.swift index aaa5f1b8a..03fe0983a 100644 --- a/Tests/BridgeJSGlobalTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSGlobalTests/Generated/BridgeJS.swift @@ -50,10 +50,10 @@ extension GlobalNetworking.API.CallMethod: _BridgedSwiftCaseEnum { } } -extension GlobalConfiguration.PublicLogLevel: _BridgedSwiftEnumNoPayload { +extension GlobalConfiguration.PublicLogLevel: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension GlobalConfiguration.AvailablePort: _BridgedSwiftEnumNoPayload { +extension GlobalConfiguration.AvailablePort: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Internal.SupportedServerMethod: _BridgedSwiftCaseEnum { diff --git a/Tests/BridgeJSGlobalTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSGlobalTests/Generated/JavaScript/BridgeJS.json index 8b91ea964..e7bcf59b6 100644 --- a/Tests/BridgeJSGlobalTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSGlobalTests/Generated/JavaScript/BridgeJS.json @@ -406,7 +406,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "GlobalStaticPropertyNamespace" } }, "type" : { @@ -424,7 +424,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "GlobalStaticPropertyNamespace" } }, "type" : { @@ -460,7 +460,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "GlobalStaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -479,7 +479,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "GlobalStaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -498,7 +498,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "GlobalStaticPropertyNamespace.NestedProperties" } }, "type" : { diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 2aee862c6..74817d82b 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -52,6 +52,22 @@ func runJsWorks() -> Void return v } +@JS func roundTripJSValue(v: JSValue) -> JSValue { + return v +} + +@JS func roundTripOptionalJSValue(v: JSValue?) -> JSValue? { + return v +} + +@JS func roundTripJSValueArray(v: [JSValue]) -> [JSValue] { + return v +} + +@JS func roundTripOptionalJSValueArray(v: [JSValue]?) -> [JSValue]? { + return v +} + @JSClass struct Foo { @JSGetter var value: String @JSFunction init(_ value: String) throws(JSException) @@ -295,6 +311,16 @@ struct TestError: Error { return String(value) } } + + @JS enum StringUtils { + @JS static func uppercase(_ text: String) -> String { + return text.uppercased() + } + + @JS static func lowercase(_ text: String) -> String { + return text.lowercased() + } + } } @JS enum Networking { @@ -497,128 +523,31 @@ enum ComplexResult { return result } -// MARK: - Optionals - -@JS func roundTripOptionalString(name: String?) -> String? { - return name -} - -@JS func roundTripOptionalInt(value: Int?) -> Int? { - return value -} - -@JS func roundTripOptionalBool(flag: Bool?) -> Bool? { - return flag -} - -@JS func roundTripOptionalFloat(number: Float?) -> Float? { - return number -} - -@JS func roundTripOptionalDouble(precision: Double?) -> Double? { - return precision -} - -@JS func roundTripOptionalSyntax(name: Optional) -> Optional { - return name -} - -@JS func roundTripOptionalMixSyntax(name: String?) -> Optional { - return name -} - -@JS func roundTripOptionalSwiftSyntax(name: Swift.Optional) -> Swift.Optional { - return name -} - -@JS func roundTripOptionalWithSpaces(value: Optional) -> Optional { - return value -} - -typealias OptionalAge = Int? -@JS func roundTripOptionalTypeAlias(age: OptionalAge) -> OptionalAge { - return age -} - -@JS func roundTripOptionalStatus(value: Status?) -> Status? { - return value -} - -@JS func roundTripOptionalTheme(value: Theme?) -> Theme? { - return value -} - -@JS func roundTripOptionalHttpStatus(value: HttpStatus?) -> HttpStatus? { - return value -} - -@JS func roundTripOptionalTSDirection(value: TSDirection?) -> TSDirection? { - return value -} - -@JS func roundTripOptionalTSTheme(value: TSTheme?) -> TSTheme? { - return value -} - -@JS func roundTripOptionalNetworkingAPIMethod(_ method: Networking.API.Method?) -> Networking.API.Method? { - return method -} - -@JS func roundTripOptionalAPIResult(value: APIResult?) -> APIResult? { - return value -} - -@JS func compareAPIResults(_ r1: APIResult?, _ r2: APIResult?) -> String { - let r1Str: String - switch r1 { - case .none: r1Str = "nil" - case .some(.success(let msg)): r1Str = "success:\(msg)" - case .some(.failure(let code)): r1Str = "failure:\(code)" - case .some(.info): r1Str = "info" - case .some(.flag(let b)): r1Str = "flag:\(b)" - case .some(.rate(let r)): r1Str = "rate:\(r)" - case .some(.precise(let p)): r1Str = "precise:\(p)" - } - - let r2Str: String - switch r2 { - case .none: r2Str = "nil" - case .some(.success(let msg)): r2Str = "success:\(msg)" - case .some(.failure(let code)): r2Str = "failure:\(code)" - case .some(.info): r2Str = "info" - case .some(.flag(let b)): r2Str = "flag:\(b)" - case .some(.rate(let r)): r2Str = "rate:\(r)" - case .some(.precise(let p)): r2Str = "precise:\(p)" - } - - return "r1:\(r1Str),r2:\(r2Str)" +@JS +enum AllTypesResult { + case structPayload(Address) + case classPayload(Greeter) + case jsObjectPayload(JSObject) + case nestedEnum(APIResult) + case arrayPayload([Int]) + case jsClassPayload(Foo) + case empty } -@JS func roundTripOptionalComplexResult(_ result: ComplexResult?) -> ComplexResult? { - return result +@JS func roundTripAllTypesResult(_ result: AllTypesResult) -> AllTypesResult { + result } -@JS func roundTripOptionalClass(value: Greeter?) -> Greeter? { - return value +@JS enum TypedPayloadResult { + case precision(Precision) + case direction(Direction) + case optPrecision(Precision?) + case optDirection(Direction?) + case empty } -@JS class OptionalPropertyHolder { - @JS var optionalName: String? - @JS var optionalAge: Int? = nil - @JS var optionalGreeter: Greeter? = nil - @JS init(optionalName: String?) { - self.optionalName = optionalName - } -} - -@JS -enum APIOptionalResult { - case success(String?) - case failure(Int?, Bool?) - case status(Bool?, Int?, String?) -} -@JS func roundTripOptionalAPIOptionalResult(result: APIOptionalResult?) -> APIOptionalResult? { - return result +@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult { + result } // MARK: - Property Tests @@ -788,6 +717,17 @@ enum APIOptionalResult { } } +@JS(namespace: "Services.Graph") +enum GraphOperations { + @JS static func createGraph(rootId: Int) -> Int { + return rootId * 10 + } + + @JS static func nodeCount(graphId: Int) -> Int { + return graphId + } +} + // MARK: - Default Parameters @JS func testStringDefault(message: String = "Hello World") -> String { @@ -1407,6 +1347,12 @@ enum APIOptionalResult { @JS func roundTripOpaquePointerArray(_ values: [OpaquePointer]) -> [OpaquePointer] { return values } +@JS func roundTripUnsafePointerArray(_ values: [UnsafePointer]) -> [UnsafePointer] { + return values +} +@JS func roundTripUnsafeMutablePointerArray(_ values: [UnsafeMutablePointer]) -> [UnsafeMutablePointer] { + return values +} @JS func consumeDataProcessorArrayType(_ processors: [DataProcessor]) -> Int { return processors.count @@ -1416,6 +1362,22 @@ enum APIOptionalResult { return processors } +@JS func roundTripJSObjectArray(_ objects: [JSObject]) -> [JSObject] { + return objects +} + +@JS func roundTripOptionalJSObjectArray(_ objects: [JSObject?]) -> [JSObject?] { + return objects +} + +@JS func roundTripFooArray(_ foos: [Foo]) -> [Foo] { + return foos +} + +@JS func roundTripOptionalFooArray(_ foos: [Foo?]) -> [Foo?] { + return foos +} + class ExportAPITests: XCTestCase { func testAll() { var hasDeinitGreeter = false diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index b0b24137a..9f500f4a4 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -4,62 +4,87 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -@_spi(Experimental) import JavaScriptKit +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func jsRoundTripVoid() throws (JSException) -> Void +@JSFunction func jsRoundTripVoid() throws(JSException) -> Void -@JSFunction func jsRoundTripNumber(_ v: Double) throws (JSException) -> Double +@JSFunction func jsRoundTripNumber(_ v: Double) throws(JSException) -> Double -@JSFunction func jsRoundTripBool(_ v: Bool) throws (JSException) -> Bool +@JSFunction func jsRoundTripBool(_ v: Bool) throws(JSException) -> Bool -@JSFunction func jsRoundTripString(_ v: String) throws (JSException) -> String +@JSFunction func jsRoundTripString(_ v: String) throws(JSException) -> String -@JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws (JSException) -> Void +@JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue -@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws (JSException) -> Double +@JSFunction func jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] -@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws (JSException) -> Bool +@JSFunction func jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> -@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws (JSException) -> String +@JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void + +@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double + +@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws(JSException) -> Bool + +@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws(JSException) -> String enum FeatureFlag: String { case foo = "foo" case bar = "bar" } -extension FeatureFlag: _BridgedSwiftEnumNoPayload {} +extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} -@JSFunction func jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> FeatureFlag +@JSFunction func jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> FeatureFlag @JSClass struct JsGreeter { @JSGetter var name: String - @JSSetter func setName(_ value: String) throws (JSException) + @JSSetter func setName(_ value: String) throws(JSException) @JSGetter var `prefix`: String - @JSFunction init(_ name: String, _ `prefix`: String) throws (JSException) - @JSFunction func greet() throws (JSException) -> String - @JSFunction func changeName(_ name: String) throws (JSException) -> Void + @JSFunction init(_ name: String, _ `prefix`: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String + @JSFunction func changeName(_ name: String) throws(JSException) -> Void } -@JSFunction func runAsyncWorks() throws (JSException) -> JSPromise +@JSFunction func runAsyncWorks() throws(JSException) -> JSPromise -@JSFunction(jsName: "$jsWeirdFunction") func _jsWeirdFunction() throws (JSException) -> Double +@JSFunction(jsName: "$jsWeirdFunction") func _jsWeirdFunction() throws(JSException) -> Double @JSClass(jsName: "$WeirdClass") struct _WeirdClass { - @JSFunction init() throws (JSException) - @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws (JSException) -> String + @JSFunction init() throws(JSException) + @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> String +} + +@JSClass struct StaticBox { + @JSFunction init(_ value: Double) throws(JSException) + @JSFunction func value() throws(JSException) -> Double + @JSFunction static func create(_ value: Double) throws(JSException) -> StaticBox + @JSFunction static func value() throws(JSException) -> Double + @JSFunction static func makeDefault() throws(JSException) -> StaticBox + @JSFunction(jsName: "with-dashes") static func with_dashes() throws(JSException) -> StaticBox } -@JSFunction(from: .global) func parseInt(_ string: String) throws (JSException) -> Double +@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 { @JSGetter var name: String - @JSSetter func setName(_ value: String) throws (JSException) + @JSSetter func setName(_ value: String) throws(JSException) @JSGetter var age: Double - @JSSetter func setAge(_ value: Double) throws (JSException) + @JSSetter func setAge(_ value: Double) throws(JSException) @JSGetter var isCat: Bool - @JSSetter func setIsCat(_ value: Bool) throws (JSException) - @JSFunction init(_ name: String, _ age: Double, _ isCat: Bool) throws (JSException) - @JSFunction func bark() throws (JSException) -> String - @JSFunction func getIsCat() throws (JSException) -> Bool + @JSSetter func setIsCat(_ value: Bool) throws(JSException) + @JSFunction init(_ name: String, _ age: Double, _ isCat: Bool) throws(JSException) + @JSFunction func bark() throws(JSException) -> String + @JSFunction func getIsCat() throws(JSException) -> Bool } -@JSGetter(from: .global) var globalObject1: JSObject +@JSGetter(from: .global) var globalObject1: JSValue diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 35a53805d..194ed04b3 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -679,6 +679,54 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7 #endif } +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC") +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC(_ callback: Int32, _ param0IsSome: Int32, _ param0Pointer: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer +#else +fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC(_ callback: Int32, _ param0IsSome: Int32, _ param0Pointer: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + fatalError("Only available on WebAssembly") +} +#endif + +private final class _BJS_ClosureBox_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC: _BridgedSwiftClosureBox { + let closure: (Optional) -> Optional + init(_ closure: @escaping (Optional) -> Optional) { + self.closure = closure + } +} + +private enum _BJS_Closure_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC { + static func bridgeJSLower(_ closure: @escaping (Optional) -> Optional) -> UnsafeMutableRawPointer { + let box = _BJS_ClosureBox_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC(closure) + return Unmanaged.passRetained(box).toOpaque() + } + static func bridgeJSLift(_ callbackId: Int32) -> (Optional) -> Optional { + let callback = JSObject.bridgeJSLiftParameter(callbackId) + return { [callback] param0 in + #if arch(wasm32) + let callbackValue = callback.bridgeJSLowerParameter() + let (param0IsSome, param0Pointer) = param0.bridgeJSLowerParameter() + let ret = invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC(callbackValue, param0IsSome, param0Pointer) + return Optional.bridgeJSLiftReturn(ret) + #else + fatalError("Only available on WebAssembly") + #endif + } + } +} + +@_expose(wasm, "invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC") +@_cdecl("invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC") +public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC(_ boxPtr: UnsafeMutableRawPointer, _ param0IsSome: Int32, _ param0Value: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let box = Unmanaged<_BJS_ClosureBox_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC>.fromOpaque(boxPtr).takeUnretainedValue() + let result = box.closure(Optional.bridgeJSLiftParameter(param0IsSome, param0Value)) + return result.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + #if arch(wasm32) @_extern(wasm, module: "bjs", name: "invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq9APIResultO_SS") fileprivate func invoke_js_callback_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsSq9APIResultO_SS(_ callback: Int32, _ param0IsSome: Int32, _ param0CaseId: Int32) -> Int32 @@ -1292,16 +1340,16 @@ extension Status: _BridgedSwiftCaseEnum { } } -extension Theme: _BridgedSwiftEnumNoPayload { +extension Theme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension HttpStatus: _BridgedSwiftEnumNoPayload { +extension HttpStatus: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Precision: _BridgedSwiftEnumNoPayload { +extension Precision: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Ratio: _BridgedSwiftEnumNoPayload { +extension Ratio: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension TSDirection: _BridgedSwiftCaseEnum { @@ -1347,7 +1395,29 @@ extension TSDirection: _BridgedSwiftCaseEnum { } } -extension TSTheme: _BridgedSwiftEnumNoPayload { +extension TSTheme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { +} + +@_expose(wasm, "bjs_Utils_StringUtils_static_uppercase") +@_cdecl("bjs_Utils_StringUtils_static_uppercase") +public func _bjs_Utils_StringUtils_static_uppercase(_ textBytes: Int32, _ textLength: Int32) -> Void { + #if arch(wasm32) + let ret = Utils.StringUtils.uppercase(_: String.bridgeJSLiftParameter(textBytes, textLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Utils_StringUtils_static_lowercase") +@_cdecl("bjs_Utils_StringUtils_static_lowercase") +public func _bjs_Utils_StringUtils_static_lowercase(_ textBytes: Int32, _ textLength: Int32) -> Void { + #if arch(wasm32) + let ret = Utils.StringUtils.lowercase(_: String.bridgeJSLiftParameter(textBytes, textLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif } extension Networking.API.Method: _BridgedSwiftCaseEnum { @@ -1393,10 +1463,10 @@ extension Networking.API.Method: _BridgedSwiftCaseEnum { } } -extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload { +extension Configuration.LogLevel: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } -extension Configuration.Port: _BridgedSwiftEnumNoPayload { +extension Configuration.Port: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } extension Internal.SupportedMethod: _BridgedSwiftCaseEnum { @@ -1438,15 +1508,15 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(Int.bridgeJSLiftParameter()) case 2: - return .flag(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .flag(Bool.bridgeJSLiftParameter()) case 3: - return .rate(Float.bridgeJSLiftParameter(_swift_js_pop_f32())) + return .rate(Float.bridgeJSLiftParameter()) case 4: - return .precise(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + return .precise(Double.bridgeJSLiftParameter()) case 5: return .info default: @@ -1459,22 +1529,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0): - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() return Int32(1) case .flag(let param0): - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() return Int32(2) case .rate(let param0): - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() return Int32(3) case .precise(let param0): - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() return Int32(4) case .info: return Int32(5) @@ -1494,23 +1561,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) case .flag(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) case .rate(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) case .precise(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) case .info: _swift_js_push_tag(Int32(5)) } @@ -1521,17 +1585,17 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> ComplexResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .error(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .error(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) case 2: - return .location(Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .location(Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 3: - return .status(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .status(Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 4: - return .coordinates(Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + return .coordinates(Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter()) case 5: - return .comprehensive(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), Double.bridgeJSLiftParameter(_swift_js_pop_f64()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .comprehensive(Bool.bridgeJSLiftParameter(), Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), Double.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) case 6: return .info default: @@ -1544,58 +1608,37 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .error(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() return Int32(1) case .location(let param0, let param1, let param2): - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(2) case .status(let param0, let param1, let param2): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(3) case .coordinates(let param0, let param1, let param2): - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(4) case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() return Int32(5) case .info: return Int32(6) @@ -1615,59 +1658,38 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .error(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) case .location(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(3)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .coordinates(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) case .comprehensive(let param0, let param1, let param2, let param3, let param4, let param5, let param6, let param7, let param8): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(5)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(param1 ? 1 : 0) - _swift_js_push_i32(Int32(param2)) - _swift_js_push_i32(Int32(param3)) - _swift_js_push_f64(param4) - _swift_js_push_f64(param5) - var __bjs_param6 = param6 - __bjs_param6.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param7 = param7 - __bjs_param7.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_param8 = param8 - __bjs_param8.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .info: _swift_js_push_tag(Int32(6)) } @@ -1678,11 +1700,11 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> Utilities.Result { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) case 2: - return .status(Bool.bridgeJSLiftParameter(_swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32()), String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .status(Bool.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter(), String.bridgeJSLiftParameter()) default: fatalError("Unknown Utilities.Result case ID: \(caseId)") } @@ -1693,25 +1715,16 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() return Int32(1) case .status(let param0, let param1, let param2): - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() return Int32(2) } } @@ -1729,26 +1742,17 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) case .status(let param0, let param1, let param2): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) - _swift_js_push_i32(Int32(param1)) - var __bjs_param2 = param2 - __bjs_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } } } } @@ -1757,9 +1761,9 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> API.NetworkingResult { switch caseId { case 0: - return .success(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .success(String.bridgeJSLiftParameter()) case 1: - return .failure(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + return .failure(String.bridgeJSLiftParameter(), Int.bridgeJSLiftParameter()) default: fatalError("Unknown API.NetworkingResult case ID: \(caseId)") } @@ -1770,17 +1774,11 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { case .success(let param0): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + param0.bridgeJSLowerStackReturn() return Int32(0) case .failure(let param0, let param1): - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() return Int32(1) } } @@ -1798,33 +1796,35 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } case .failure(let param0, let param1): + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - var __bjs_param0 = param0 - __bjs_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(param1)) } } } -extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIOptionalResult { +extension AllTypesResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> AllTypesResult { switch caseId { case 0: - return .success(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) + return .structPayload(Address.bridgeJSLiftParameter()) case 1: - return .failure(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + return .classPayload(Greeter.bridgeJSLiftParameter()) case 2: - return .status(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()), Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) + return .jsObjectPayload(JSObject.bridgeJSLiftParameter()) + case 3: + return .nestedEnum(APIResult.bridgeJSLiftParameter(_swift_js_pop_i32())) + case 4: + return .arrayPayload([Int].bridgeJSLiftParameter()) + case 5: + return .jsClassPayload(Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter())) + case 6: + return .empty default: - fatalError("Unknown APIOptionalResult case ID: \(caseId)") + fatalError("Unknown AllTypesResult case ID: \(caseId)") } } @@ -1832,105 +1832,146 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { switch self { - case .success(let param0): - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - var __bjs_str_param0 = __bjs_unwrapped_param0 - __bjs_str_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + case .structPayload(let param0): + param0.bridgeJSLowerReturn() return Int32(0) - case .failure(let param0, let param1): + case .classPayload(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(1) + case .jsObjectPayload(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(2) + case .nestedEnum(let param0): + param0.bridgeJSLowerReturn() + return Int32(3) + case .arrayPayload(let param0): + param0.bridgeJSLowerReturn() + return Int32(4) + case .jsClassPayload(let param0): + param0.jsObject.bridgeJSLowerStackReturn() + return Int32(5) + case .empty: + return Int32(6) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> AllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> AllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .structPayload(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(0)) + case .classPayload(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + case .jsObjectPayload(let param0): + param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) + case .nestedEnum(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(3)) + case .arrayPayload(let param0): + param0.bridgeJSLowerReturn() + _swift_js_push_tag(Int32(4)) + case .jsClassPayload(let param0): + param0.jsObject.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(5)) + case .empty: + _swift_js_push_tag(Int32(6)) + } + } +} + +extension TypedPayloadResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> TypedPayloadResult { + switch caseId { + case 0: + return .precision(Precision.bridgeJSLiftParameter(_swift_js_pop_f32())) + case 1: + return .direction(Direction.bridgeJSLiftParameter(_swift_js_pop_i32())) + case 2: + return .optPrecision(Optional.bridgeJSLiftParameter()) + case 3: + return .optDirection(Optional.bridgeJSLiftParameter()) + case 4: + return .empty + default: + fatalError("Unknown TypedPayloadResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .precision(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(0) + case .direction(let param0): + param0.bridgeJSLowerStackReturn() + return Int32(1) + case .optPrecision(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param0)) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(__bjs_unwrapped_param1 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - return Int32(1) - case .status(let param0, let param1, let param2): + return Int32(2) + case .optDirection(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0 ? 1 : 0) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param1)) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - let __bjs_isSome_param2 = param2 != nil - if let __bjs_unwrapped_param2 = param2 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) - return Int32(2) + return Int32(3) + case .empty: + return Int32(4) } } - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIOptionalResult { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> TypedPayloadResult { return _bridgeJSLiftFromCaseId(caseId) } // MARK: ExportSwift - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIOptionalResult { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> TypedPayloadResult { return _bridgeJSLiftFromCaseId(caseId) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { - case .success(let param0): + case .precision(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(0)) - let __bjs_isSome_param0 = param0 != nil - if let __bjs_unwrapped_param0 = param0 { - var __bjs_str_param0 = __bjs_unwrapped_param0 - __bjs_str_param0.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - case .failure(let param0, let param1): + case .direction(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) + case .optPrecision(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param0)) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(__bjs_unwrapped_param1 ? 1 : 0) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - case .status(let param0, let param1, let param2): _swift_js_push_tag(Int32(2)) + case .optDirection(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0 ? 1 : 0) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) - let __bjs_isSome_param1 = param1 != nil - if let __bjs_unwrapped_param1 = param1 { - _swift_js_push_i32(Int32(__bjs_unwrapped_param1)) - } - _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) - let __bjs_isSome_param2 = param2 != nil - if let __bjs_unwrapped_param2 = param2 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - } - _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + _swift_js_push_tag(Int32(3)) + case .empty: + _swift_js_push_tag(Int32(4)) } } } @@ -1992,6 +2033,28 @@ public func _bjs_StaticUtils_Nested_static_roundtrip(_ valueBytes: Int32, _ valu #endif } +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_createGraph") +@_cdecl("bjs_Services_Graph_GraphOperations_static_createGraph") +public func _bjs_Services_Graph_GraphOperations_static_createGraph(_ rootId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.createGraph(rootId: Int.bridgeJSLiftParameter(rootId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Services_Graph_GraphOperations_static_nodeCount") +@_cdecl("bjs_Services_Graph_GraphOperations_static_nodeCount") +public func _bjs_Services_Graph_GraphOperations_static_nodeCount(_ graphId: Int32) -> Int32 { + #if arch(wasm32) + let ret = GraphOperations.nodeCount(graphId: Int.bridgeJSLiftParameter(graphId)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + extension StaticPropertyEnum: _BridgedSwiftCaseEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { return bridgeJSRawValue @@ -2218,37 +2281,288 @@ public func _bjs_StaticPropertyNamespace_NestedProperties_static_nestedDouble_se #endif } -extension Point: _BridgedSwiftStruct { - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { - let y = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let x = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - return Point(x: x, y: y) +extension OptionalAllTypesResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> OptionalAllTypesResult { + switch caseId { + case 0: + return .optStruct(Optional
.bridgeJSLiftParameter()) + case 1: + return .optClass(Optional.bridgeJSLiftParameter()) + case 2: + return .optJSObject(Optional.bridgeJSLiftParameter()) + case 3: + return .optNestedEnum(Optional.bridgeJSLiftParameter()) + case 4: + return .optArray({ + let __isSome = _swift_js_pop_i32() + if __isSome == 0 { + return Optional<[Int]>.none + } else { + return [Int].bridgeJSLiftParameter() + } + }()) + case 5: + return .optJsClass(Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + }) + case 6: + return .empty + default: + fatalError("Unknown OptionalAllTypesResult case ID: \(caseId)") + } } - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.x)) - _swift_js_push_i32(Int32(self.y)) - } + // MARK: Protocol Export - init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .optStruct(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(0) + case .optClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(1) + case .optJSObject(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(2) + case .optNestedEnum(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(3) + case .optArray(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(4) + case .optJsClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.jsObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(5) + case .empty: + return Int32(6) } - self = Self.bridgeJSLiftParameter() } - func toJSObject() -> JSObject { - let __bjs_self = self - __bjs_self.bridgeJSLowerReturn() - return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Point())) + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> OptionalAllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) } -} -#if arch(wasm32) -@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 -#else + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> OptionalAllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .optStruct(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(0)) + case .optClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(1)) + case .optJSObject(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(2)) + case .optNestedEnum(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(3)) + case .optArray(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(4)) + case .optJsClass(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.jsObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(5)) + case .empty: + _swift_js_push_tag(Int32(6)) + } + } +} + +extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIOptionalResult { + switch caseId { + case 0: + return .success(Optional.bridgeJSLiftParameter()) + case 1: + return .failure(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) + case 2: + return .status(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) + default: + fatalError("Unknown APIOptionalResult case ID: \(caseId)") + } + } + + // MARK: Protocol Export + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + switch self { + case .success(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + return Int32(0) + case .failure(let param0, let param1): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + return Int32(1) + case .status(let param0, let param1, let param2): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + let __bjs_isSome_param2 = param2 != nil + if let __bjs_unwrapped_param2 = param2 { + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + return Int32(2) + } + } + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> APIOptionalResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + // MARK: ExportSwift + + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> APIOptionalResult { + return _bridgeJSLiftFromCaseId(caseId) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + switch self { + case .success(let param0): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + _swift_js_push_tag(Int32(0)) + case .failure(let param0, let param1): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + _swift_js_push_tag(Int32(1)) + case .status(let param0, let param1, let param2): + let __bjs_isSome_param0 = param0 != nil + if let __bjs_unwrapped_param0 = param0 { + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param0 ? 1 : 0) + let __bjs_isSome_param1 = param1 != nil + if let __bjs_unwrapped_param1 = param1 { + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param1 ? 1 : 0) + let __bjs_isSome_param2 = param2 != nil + if let __bjs_unwrapped_param2 = param2 { + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + _swift_js_push_tag(Int32(2)) + } + } +} + +extension Point: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Point { + let y = Int.bridgeJSLiftParameter() + let x = Int.bridgeJSLiftParameter() + return Point(x: x, y: y) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_Point())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +#else fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { fatalError("Only available on WebAssembly") } @@ -2265,20 +2579,20 @@ fileprivate func _bjs_struct_lift_Point() -> Int32 { extension PointerFields: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> PointerFields { - let mutPtr = UnsafeMutablePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let ptr = UnsafePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let opaque = OpaquePointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let mutRaw = UnsafeMutableRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) - let raw = UnsafeRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer()) + let mutPtr = UnsafeMutablePointer.bridgeJSLiftParameter() + let ptr = UnsafePointer.bridgeJSLiftParameter() + let opaque = OpaquePointer.bridgeJSLiftParameter() + let mutRaw = UnsafeMutableRawPointer.bridgeJSLiftParameter() + let raw = UnsafeRawPointer.bridgeJSLiftParameter() return PointerFields(raw: raw, mutRaw: mutRaw, opaque: opaque, ptr: ptr, mutPtr: mutPtr) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_pointer(self.raw.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.mutRaw.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.opaque.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.ptr.bridgeJSLowerReturn()) - _swift_js_push_pointer(self.mutPtr.bridgeJSLowerReturn()) + self.raw.bridgeJSLowerStackReturn() + self.mutRaw.bridgeJSLowerStackReturn() + self.opaque.bridgeJSLowerStackReturn() + self.ptr.bridgeJSLowerStackReturn() + self.mutPtr.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -2327,29 +2641,26 @@ public func _bjs_PointerFields_init(_ raw: UnsafeMutableRawPointer, _ mutRaw: Un extension DataPoint: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> DataPoint { - let optFlag = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let optCount = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let label = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let y = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) - let x = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let optFlag = Optional.bridgeJSLiftParameter() + let optCount = Optional.bridgeJSLiftParameter() + let label = String.bridgeJSLiftParameter() + let y = Double.bridgeJSLiftParameter() + let x = Double.bridgeJSLiftParameter() return DataPoint(x: x, y: y, label: label, optCount: optCount, optFlag: optFlag) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.x) - _swift_js_push_f64(self.y) - var __bjs_label = self.label - __bjs_label.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() + self.label.bridgeJSLowerStackReturn() let __bjs_isSome_optCount = self.optCount != nil if let __bjs_unwrapped_optCount = self.optCount { - _swift_js_push_i32(Int32(__bjs_unwrapped_optCount)) + __bjs_unwrapped_optCount.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optCount ? 1 : 0) let __bjs_isSome_optFlag = self.optFlag != nil if let __bjs_unwrapped_optFlag = self.optFlag { - _swift_js_push_i32(__bjs_unwrapped_optFlag ? 1 : 0) + __bjs_unwrapped_optFlag.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optFlag ? 1 : 0) } @@ -2400,24 +2711,18 @@ public func _bjs_DataPoint_init(_ x: Float64, _ y: Float64, _ labelBytes: Int32, extension Address: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Address { - let zipCode = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let city = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let street = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let zipCode = Optional.bridgeJSLiftParameter() + let city = String.bridgeJSLiftParameter() + let street = String.bridgeJSLiftParameter() return Address(street: street, city: city, zipCode: zipCode) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_street = self.street - __bjs_street.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - var __bjs_city = self.city - __bjs_city.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.street.bridgeJSLowerStackReturn() + self.city.bridgeJSLowerStackReturn() let __bjs_isSome_zipCode = self.zipCode != nil if let __bjs_unwrapped_zipCode = self.zipCode { - _swift_js_push_i32(Int32(__bjs_unwrapped_zipCode)) + __bjs_unwrapped_zipCode.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_zipCode ? 1 : 0) } @@ -2457,27 +2762,21 @@ fileprivate func _bjs_struct_lift_Address() -> Int32 { extension Contact: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Contact { - let secondaryAddress = Optional
.bridgeJSLiftParameter(_swift_js_pop_i32()) - let email = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32()) + let secondaryAddress = Optional
.bridgeJSLiftParameter() + let email = Optional.bridgeJSLiftParameter() let address = Address.bridgeJSLiftParameter() - let age = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let age = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return Contact(name: name, age: age, address: address, email: email, secondaryAddress: secondaryAddress) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.age)) + self.name.bridgeJSLowerStackReturn() + self.age.bridgeJSLowerStackReturn() self.address.bridgeJSLowerReturn() let __bjs_isSome_email = self.email != nil if let __bjs_unwrapped_email = self.email { - var __bjs_str_email = __bjs_unwrapped_email - __bjs_str_email.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_email.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_email ? 1 : 0) let __bjs_isSome_secondaryAddress = self.secondaryAddress != nil @@ -2523,31 +2822,25 @@ fileprivate func _bjs_struct_lift_Contact() -> Int32 { extension Config: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> Config { let status = Status.bridgeJSLiftParameter(_swift_js_pop_i32()) - let direction = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let theme = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let direction = Optional.bridgeJSLiftParameter() + let theme = Optional.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return Config(name: name, theme: theme, direction: direction, status: status) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + self.name.bridgeJSLowerStackReturn() let __bjs_isSome_theme = self.theme != nil if let __bjs_unwrapped_theme = self.theme { - var __bjs_str_theme = __bjs_unwrapped_theme.rawValue - __bjs_str_theme.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_theme.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_theme ? 1 : 0) let __bjs_isSome_direction = self.direction != nil if let __bjs_unwrapped_direction = self.direction { - _swift_js_push_i32(__bjs_unwrapped_direction.bridgeJSLowerParameter()) + __bjs_unwrapped_direction.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_direction ? 1 : 0) - _swift_js_push_i32(Int32(self.status.bridgeJSLowerParameter())) + self.status.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -2585,16 +2878,16 @@ fileprivate func _bjs_struct_lift_Config() -> Int32 { extension SessionData: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> SessionData { - let owner = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_pointer()) - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let owner = Optional.bridgeJSLiftParameter() + let id = Int.bridgeJSLiftParameter() return SessionData(id: id, owner: owner) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) + self.id.bridgeJSLowerStackReturn() let __bjs_isSome_owner = self.owner != nil if let __bjs_unwrapped_owner = self.owner { - _swift_js_push_pointer(__bjs_unwrapped_owner.bridgeJSLowerReturn()) + __bjs_unwrapped_owner.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_owner ? 1 : 0) } @@ -2634,19 +2927,19 @@ fileprivate func _bjs_struct_lift_SessionData() -> Int32 { extension ValidationReport: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> ValidationReport { - let outcome = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let status = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let outcome = Optional.bridgeJSLiftParameter() + let status = Optional.bridgeJSLiftParameter() let result = APIResult.bridgeJSLiftParameter(_swift_js_pop_i32()) - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let id = Int.bridgeJSLiftParameter() return ValidationReport(id: id, result: result, status: status, outcome: outcome) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) + self.id.bridgeJSLowerStackReturn() self.result.bridgeJSLowerReturn() let __bjs_isSome_status = self.status != nil if let __bjs_unwrapped_status = self.status { - _swift_js_push_i32(__bjs_unwrapped_status.bridgeJSLowerParameter()) + __bjs_unwrapped_status.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_status ? 1 : 0) let __bjs_isSome_outcome = self.outcome != nil @@ -2691,31 +2984,25 @@ fileprivate func _bjs_struct_lift_ValidationReport() -> Int32 { extension AdvancedConfig: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> AdvancedConfig { - let overrideDefaults = Optional.bridgeJSLiftParameter(_swift_js_pop_i32()) + let overrideDefaults = Optional.bridgeJSLiftParameter() let defaults = ConfigStruct.bridgeJSLiftParameter() - let location = Optional.bridgeJSLiftParameter(_swift_js_pop_i32()) - let metadata = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let result = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let location = Optional.bridgeJSLiftParameter() + let metadata = Optional.bridgeJSLiftParameter() + let result = Optional.bridgeJSLiftParameter() let status = Status.bridgeJSLiftParameter(_swift_js_pop_i32()) let theme = Theme.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let enabled = Bool.bridgeJSLiftParameter(_swift_js_pop_i32()) - let title = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let enabled = Bool.bridgeJSLiftParameter() + let title = String.bridgeJSLiftParameter() + let id = Int.bridgeJSLiftParameter() return AdvancedConfig(id: id, title: title, enabled: enabled, theme: theme, status: status, result: result, metadata: metadata, location: location, defaults: defaults, overrideDefaults: overrideDefaults) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) - var __bjs_title = self.title - __bjs_title.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(self.enabled ? 1 : 0) - var __bjs_theme = self.theme.rawValue - __bjs_theme.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.status.bridgeJSLowerParameter())) + self.id.bridgeJSLowerStackReturn() + self.title.bridgeJSLowerStackReturn() + self.enabled.bridgeJSLowerStackReturn() + self.theme.bridgeJSLowerStackReturn() + self.status.bridgeJSLowerStackReturn() let __bjs_isSome_result = self.result != nil if let __bjs_unwrapped_result = self.result { _swift_js_push_i32(__bjs_unwrapped_result.bridgeJSLowerParameter()) @@ -2723,7 +3010,7 @@ extension AdvancedConfig: _BridgedSwiftStruct { _swift_js_push_i32(__bjs_isSome_result ? 1 : 0) let __bjs_isSome_metadata = self.metadata != nil if let __bjs_unwrapped_metadata = self.metadata { - _swift_js_push_i32(__bjs_unwrapped_metadata.bridgeJSLowerReturn()) + __bjs_unwrapped_metadata.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_metadata ? 1 : 0) let __bjs_isSome_location = self.location != nil @@ -2774,24 +3061,24 @@ fileprivate func _bjs_struct_lift_AdvancedConfig() -> Int32 { extension MeasurementConfig: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> MeasurementConfig { - let optionalRatio = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f64()) - let optionalPrecision = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_f32()) + let optionalRatio = Optional.bridgeJSLiftParameter() + let optionalPrecision = Optional.bridgeJSLiftParameter() let ratio = Ratio.bridgeJSLiftParameter(_swift_js_pop_f64()) let precision = Precision.bridgeJSLiftParameter(_swift_js_pop_f32()) return MeasurementConfig(precision: precision, ratio: ratio, optionalPrecision: optionalPrecision, optionalRatio: optionalRatio) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f32(self.precision.bridgeJSLowerParameter()) - _swift_js_push_f64(self.ratio.bridgeJSLowerParameter()) + self.precision.bridgeJSLowerStackReturn() + self.ratio.bridgeJSLowerStackReturn() let __bjs_isSome_optionalPrecision = self.optionalPrecision != nil if let __bjs_unwrapped_optionalPrecision = self.optionalPrecision { - _swift_js_push_f32(__bjs_unwrapped_optionalPrecision.bridgeJSLowerParameter()) + __bjs_unwrapped_optionalPrecision.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optionalPrecision ? 1 : 0) let __bjs_isSome_optionalRatio = self.optionalRatio != nil if let __bjs_unwrapped_optionalRatio = self.optionalRatio { - _swift_js_push_f64(__bjs_unwrapped_optionalRatio.bridgeJSLowerParameter()) + __bjs_unwrapped_optionalRatio.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_optionalRatio ? 1 : 0) } @@ -2831,12 +3118,12 @@ fileprivate func _bjs_struct_lift_MeasurementConfig() -> Int32 { extension MathOperations: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> MathOperations { - let baseValue = Double.bridgeJSLiftParameter(_swift_js_pop_f64()) + let baseValue = Double.bridgeJSLiftParameter() return MathOperations(baseValue: baseValue) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_f64(self.baseValue) + self.baseValue.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -2918,19 +3205,16 @@ public func _bjs_MathOperations_static_subtract(_ a: Float64, _ b: Float64) -> F extension CopyableCart: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> CopyableCart { - let note = Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32()) - let x = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let note = Optional.bridgeJSLiftParameter() + let x = Int.bridgeJSLiftParameter() return CopyableCart(x: x, note: note) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.x)) + self.x.bridgeJSLowerStackReturn() let __bjs_isSome_note = self.note != nil if let __bjs_unwrapped_note = self.note { - var __bjs_str_note = __bjs_unwrapped_note - __bjs_str_note.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_note.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_note ? 1 : 0) } @@ -2981,17 +3265,14 @@ public func _bjs_CopyableCart_static_fromJSObject(_ object: Int32) -> Void { extension CopyableCartItem: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> CopyableCartItem { - let quantity = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let sku = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let quantity = Int.bridgeJSLiftParameter() + let sku = String.bridgeJSLiftParameter() return CopyableCartItem(sku: sku, quantity: quantity) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_sku = self.sku - __bjs_sku.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.quantity)) + self.sku.bridgeJSLowerStackReturn() + self.quantity.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -3029,14 +3310,14 @@ fileprivate func _bjs_struct_lift_CopyableCartItem() -> Int32 { extension CopyableNestedCart: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> CopyableNestedCart { - let shippingAddress = Optional
.bridgeJSLiftParameter(_swift_js_pop_i32()) + let shippingAddress = Optional
.bridgeJSLiftParameter() let item = CopyableCartItem.bridgeJSLiftParameter() - let id = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) + let id = Int.bridgeJSLiftParameter() return CopyableNestedCart(id: id, item: item, shippingAddress: shippingAddress) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.id)) + self.id.bridgeJSLowerStackReturn() self.item.bridgeJSLowerReturn() let __bjs_isSome_shippingAddress = self.shippingAddress != nil if let __bjs_unwrapped_shippingAddress = self.shippingAddress { @@ -3091,17 +3372,14 @@ public func _bjs_CopyableNestedCart_static_fromJSObject(_ object: Int32) -> Void extension ConfigStruct: _BridgedSwiftStruct { @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> ConfigStruct { - let value = Int.bridgeJSLiftParameter(_swift_js_pop_i32()) - let name = String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32()) + let value = Int.bridgeJSLiftParameter() + let name = String.bridgeJSLiftParameter() return ConfigStruct(name: name, value: value) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - var __bjs_name = self.name - __bjs_name.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } - _swift_js_push_i32(Int32(self.value)) + self.name.bridgeJSLowerStackReturn() + self.value.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -3201,78 +3479,256 @@ public func _bjs_ConfigStruct_static_computedSetting_get() -> Void { #endif } -@_expose(wasm, "bjs_roundTripVoid") -@_cdecl("bjs_roundTripVoid") -public func _bjs_roundTripVoid() -> Void { - #if arch(wasm32) - roundTripVoid() - #else - fatalError("Only available on WebAssembly") - #endif -} +extension JSObjectContainer: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> JSObjectContainer { + let optionalObject = Optional.bridgeJSLiftParameter() + let object = JSObject.bridgeJSLiftParameter() + return JSObjectContainer(object: object, optionalObject: optionalObject) + } -@_expose(wasm, "bjs_roundTripInt") -@_cdecl("bjs_roundTripInt") -public func _bjs_roundTripInt(_ v: Int32) -> Int32 { - #if arch(wasm32) - let ret = roundTripInt(v: Int.bridgeJSLiftParameter(v)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.object.bridgeJSLowerStackReturn() + let __bjs_isSome_optionalObject = self.optionalObject != nil + if let __bjs_unwrapped_optionalObject = self.optionalObject { + __bjs_unwrapped_optionalObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_optionalObject ? 1 : 0) + } -@_expose(wasm, "bjs_roundTripUInt") -@_cdecl("bjs_roundTripUInt") -public func _bjs_roundTripUInt(_ v: Int32) -> Int32 { - #if arch(wasm32) - let ret = roundTripUInt(v: UInt.bridgeJSLiftParameter(v)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_JSObjectContainer(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } -@_expose(wasm, "bjs_roundTripFloat") -@_cdecl("bjs_roundTripFloat") -public func _bjs_roundTripFloat(_ v: Float32) -> Float32 { - #if arch(wasm32) - let ret = roundTripFloat(v: Float.bridgeJSLiftParameter(v)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_JSObjectContainer())) + } } -@_expose(wasm, "bjs_roundTripDouble") -@_cdecl("bjs_roundTripDouble") -public func _bjs_roundTripDouble(_ v: Float64) -> Float64 { - #if arch(wasm32) - let ret = roundTripDouble(v: Double.bridgeJSLiftParameter(v)) - return ret.bridgeJSLowerReturn() - #else +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_JSObjectContainer") +fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Int32 { fatalError("Only available on WebAssembly") - #endif } +#endif -@_expose(wasm, "bjs_roundTripBool") -@_cdecl("bjs_roundTripBool") -public func _bjs_roundTripBool(_ v: Int32) -> Int32 { - #if arch(wasm32) - let ret = roundTripBool(v: Bool.bridgeJSLiftParameter(v)) - return ret.bridgeJSLowerReturn() - #else +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_JSObjectContainer") +fileprivate func _bjs_struct_lift_JSObjectContainer() -> Int32 +#else +fileprivate func _bjs_struct_lift_JSObjectContainer() -> Int32 { fatalError("Only available on WebAssembly") - #endif } +#endif -@_expose(wasm, "bjs_roundTripString") -@_cdecl("bjs_roundTripString") -public func _bjs_roundTripString(_ vBytes: Int32, _ vLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripString(v: String.bridgeJSLiftParameter(vBytes, vLength)) - return ret.bridgeJSLowerReturn() - #else +extension FooContainer: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> FooContainer { + let optionalFoo = Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + } + let foo = Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter()) + return FooContainer(foo: foo, optionalFoo: optionalFoo) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.foo.jsObject.bridgeJSLowerStackReturn() + let __bjs_isSome_optionalFoo = self.optionalFoo != nil + if let __bjs_unwrapped_optionalFoo = self.optionalFoo { + __bjs_unwrapped_optionalFoo.jsObject.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(__bjs_isSome_optionalFoo ? 1 : 0) + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_FooContainer())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_FooContainer") +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_FooContainer") +fileprivate func _bjs_struct_lift_FooContainer() -> Int32 +#else +fileprivate func _bjs_struct_lift_FooContainer() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +extension ArrayMembers: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> ArrayMembers { + let optStrings = { + let __isSome = _swift_js_pop_i32() + if __isSome == 0 { + return Optional<[String]>.none + } else { + return [String].bridgeJSLiftParameter() + } + }() + let ints = [Int].bridgeJSLiftParameter() + return ArrayMembers(ints: ints, optStrings: optStrings) + } + + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { + self.ints.bridgeJSLowerReturn() + let __bjs_isSome_optStrings = self.optStrings != nil + if let __bjs_unwrapped_optStrings = self.optStrings { + __bjs_unwrapped_optStrings.bridgeJSLowerReturn() + } + _swift_js_push_i32(__bjs_isSome_optStrings ? 1 : 0) + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_ArrayMembers(jsObject.bridgeJSLowerParameter()) + defer { + _swift_js_struct_cleanup(__bjs_cleanupId) + } + self = Self.bridgeJSLiftParameter() + } + + func toJSObject() -> JSObject { + let __bjs_self = self + __bjs_self.bridgeJSLowerReturn() + return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_ArrayMembers())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ArrayMembers") +fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_ArrayMembers") +fileprivate func _bjs_struct_lift_ArrayMembers() -> Int32 +#else +fileprivate func _bjs_struct_lift_ArrayMembers() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_ArrayMembers_sumValues") +@_cdecl("bjs_ArrayMembers_sumValues") +public func _bjs_ArrayMembers_sumValues() -> Int32 { + #if arch(wasm32) + let ret = ArrayMembers.bridgeJSLiftParameter().sumValues(_: [Int].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_ArrayMembers_firstString") +@_cdecl("bjs_ArrayMembers_firstString") +public func _bjs_ArrayMembers_firstString() -> Void { + #if arch(wasm32) + let ret = ArrayMembers.bridgeJSLiftParameter().firstString(_: [String].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripVoid") +@_cdecl("bjs_roundTripVoid") +public func _bjs_roundTripVoid() -> Void { + #if arch(wasm32) + roundTripVoid() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripInt") +@_cdecl("bjs_roundTripInt") +public func _bjs_roundTripInt(_ v: Int32) -> Int32 { + #if arch(wasm32) + let ret = roundTripInt(v: Int.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripUInt") +@_cdecl("bjs_roundTripUInt") +public func _bjs_roundTripUInt(_ v: Int32) -> Int32 { + #if arch(wasm32) + let ret = roundTripUInt(v: UInt.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripFloat") +@_cdecl("bjs_roundTripFloat") +public func _bjs_roundTripFloat(_ v: Float32) -> Float32 { + #if arch(wasm32) + let ret = roundTripFloat(v: Float.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripDouble") +@_cdecl("bjs_roundTripDouble") +public func _bjs_roundTripDouble(_ v: Float64) -> Float64 { + #if arch(wasm32) + let ret = roundTripDouble(v: Double.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripBool") +@_cdecl("bjs_roundTripBool") +public func _bjs_roundTripBool(_ v: Int32) -> Int32 { + #if arch(wasm32) + let ret = roundTripBool(v: Bool.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripString") +@_cdecl("bjs_roundTripString") +public func _bjs_roundTripString(_ vBytes: Int32, _ vLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripString(v: String.bridgeJSLiftParameter(vBytes, vLength)) + return ret.bridgeJSLowerReturn() + #else fatalError("Only available on WebAssembly") #endif } @@ -3354,6 +3810,59 @@ public func _bjs_roundTripJSObject(_ v: Int32) -> Int32 { #endif } +@_expose(wasm, "bjs_roundTripJSValue") +@_cdecl("bjs_roundTripJSValue") +public func _bjs_roundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripJSValue(v: JSValue.bridgeJSLiftParameter(vKind, vPayload1, vPayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalJSValue") +@_cdecl("bjs_roundTripOptionalJSValue") +public func _bjs_roundTripOptionalJSValue(_ vIsSome: Int32, _ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalJSValue(v: Optional.bridgeJSLiftParameter(vIsSome, vKind, vPayload1, vPayload2)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripJSValueArray") +@_cdecl("bjs_roundTripJSValueArray") +public func _bjs_roundTripJSValueArray() -> Void { + #if arch(wasm32) + let ret = roundTripJSValueArray(v: [JSValue].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalJSValueArray") +@_cdecl("bjs_roundTripOptionalJSValueArray") +public func _bjs_roundTripOptionalJSValueArray(_ v: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalJSValueArray(v: { + if v == 0 { + return Optional<[JSValue]>.none + } else { + return [JSValue].bridgeJSLiftParameter() + } + }()) + let __bjs_isSome_ret = ret != nil + if let __bjs_unwrapped_ret = ret { + __bjs_unwrapped_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_makeImportedFoo") @_cdecl("bjs_makeImportedFoo") public func _bjs_makeImportedFoo(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { @@ -4176,683 +4685,624 @@ public func _bjs_roundtripAPINetworkingResult(_ result: Int32) -> Void { #endif } -@_expose(wasm, "bjs_roundTripOptionalString") -@_cdecl("bjs_roundTripOptionalString") -public func _bjs_roundTripOptionalString(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripAllTypesResult") +@_cdecl("bjs_roundTripAllTypesResult") +public func _bjs_roundTripAllTypesResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + let ret = roundTripAllTypesResult(_: AllTypesResult.bridgeJSLiftParameter(result)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalInt") -@_cdecl("bjs_roundTripOptionalInt") -public func _bjs_roundTripOptionalInt(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { +@_expose(wasm, "bjs_roundTripTypedPayloadResult") +@_cdecl("bjs_roundTripTypedPayloadResult") +public func _bjs_roundTripTypedPayloadResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = roundTripTypedPayloadResult(_: TypedPayloadResult.bridgeJSLiftParameter(result)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalBool") -@_cdecl("bjs_roundTripOptionalBool") -public func _bjs_roundTripOptionalBool(_ flagIsSome: Int32, _ flagValue: Int32) -> Void { +@_expose(wasm, "bjs_createPropertyHolder") +@_cdecl("bjs_createPropertyHolder") +public func _bjs_createPropertyHolder(_ intValue: Int32, _ floatValue: Float32, _ doubleValue: Float64, _ boolValue: Int32, _ stringValueBytes: Int32, _ stringValueLength: Int32, _ jsObject: Int32) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = roundTripOptionalBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) + let ret = createPropertyHolder(intValue: Int.bridgeJSLiftParameter(intValue), floatValue: Float.bridgeJSLiftParameter(floatValue), doubleValue: Double.bridgeJSLiftParameter(doubleValue), boolValue: Bool.bridgeJSLiftParameter(boolValue), stringValue: String.bridgeJSLiftParameter(stringValueBytes, stringValueLength), jsObject: JSObject.bridgeJSLiftParameter(jsObject)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalFloat") -@_cdecl("bjs_roundTripOptionalFloat") -public func _bjs_roundTripOptionalFloat(_ numberIsSome: Int32, _ numberValue: Float32) -> Void { +@_expose(wasm, "bjs_testPropertyHolder") +@_cdecl("bjs_testPropertyHolder") +public func _bjs_testPropertyHolder(_ holder: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = roundTripOptionalFloat(number: Optional.bridgeJSLiftParameter(numberIsSome, numberValue)) + let ret = testPropertyHolder(holder: PropertyHolder.bridgeJSLiftParameter(holder)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalDouble") -@_cdecl("bjs_roundTripOptionalDouble") -public func _bjs_roundTripOptionalDouble(_ precisionIsSome: Int32, _ precisionValue: Float64) -> Void { +@_expose(wasm, "bjs_resetObserverCounts") +@_cdecl("bjs_resetObserverCounts") +public func _bjs_resetObserverCounts() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDouble(precision: Optional.bridgeJSLiftParameter(precisionIsSome, precisionValue)) - return ret.bridgeJSLowerReturn() + resetObserverCounts() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalSyntax") -@_cdecl("bjs_roundTripOptionalSyntax") -public func _bjs_roundTripOptionalSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_getObserverStats") +@_cdecl("bjs_getObserverStats") +public func _bjs_getObserverStats() -> Void { #if arch(wasm32) - let ret = roundTripOptionalSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + let ret = getObserverStats() return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalMixSyntax") -@_cdecl("bjs_roundTripOptionalMixSyntax") -public func _bjs_roundTripOptionalMixSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_testStringDefault") +@_cdecl("bjs_testStringDefault") +public func _bjs_testStringDefault(_ messageBytes: Int32, _ messageLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalMixSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + let ret = testStringDefault(message: String.bridgeJSLiftParameter(messageBytes, messageLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalSwiftSyntax") -@_cdecl("bjs_roundTripOptionalSwiftSyntax") -public func _bjs_roundTripOptionalSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_testIntDefault") +@_cdecl("bjs_testIntDefault") +public func _bjs_testIntDefault(_ count: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + let ret = testIntDefault(count: Int.bridgeJSLiftParameter(count)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalWithSpaces") -@_cdecl("bjs_roundTripOptionalWithSpaces") -public func _bjs_roundTripOptionalWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { +@_expose(wasm, "bjs_testBoolDefault") +@_cdecl("bjs_testBoolDefault") +public func _bjs_testBoolDefault(_ flag: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalWithSpaces(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = testBoolDefault(flag: Bool.bridgeJSLiftParameter(flag)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalTypeAlias") -@_cdecl("bjs_roundTripOptionalTypeAlias") -public func _bjs_roundTripOptionalTypeAlias(_ ageIsSome: Int32, _ ageValue: Int32) -> Void { +@_expose(wasm, "bjs_testOptionalDefault") +@_cdecl("bjs_testOptionalDefault") +public func _bjs_testOptionalDefault(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalTypeAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) + let ret = testOptionalDefault(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStatus") -@_cdecl("bjs_roundTripOptionalStatus") -public func _bjs_roundTripOptionalStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalTheme") -@_cdecl("bjs_roundTripOptionalTheme") -public func _bjs_roundTripOptionalTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalHttpStatus") -@_cdecl("bjs_roundTripOptionalHttpStatus") -public func _bjs_roundTripOptionalHttpStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { - #if arch(wasm32) - let ret = roundTripOptionalHttpStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_roundTripOptionalTSDirection") -@_cdecl("bjs_roundTripOptionalTSDirection") -public func _bjs_roundTripOptionalTSDirection(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { +@_expose(wasm, "bjs_testMultipleDefaults") +@_cdecl("bjs_testMultipleDefaults") +public func _bjs_testMultipleDefaults(_ titleBytes: Int32, _ titleLength: Int32, _ count: Int32, _ enabled: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalTSDirection(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = testMultipleDefaults(title: String.bridgeJSLiftParameter(titleBytes, titleLength), count: Int.bridgeJSLiftParameter(count), enabled: Bool.bridgeJSLiftParameter(enabled)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalTSTheme") -@_cdecl("bjs_roundTripOptionalTSTheme") -public func _bjs_roundTripOptionalTSTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { +@_expose(wasm, "bjs_testSimpleEnumDefault") +@_cdecl("bjs_testSimpleEnumDefault") +public func _bjs_testSimpleEnumDefault(_ status: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalTSTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + let ret = testSimpleEnumDefault(status: Status.bridgeJSLiftParameter(status)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalNetworkingAPIMethod") -@_cdecl("bjs_roundTripOptionalNetworkingAPIMethod") -public func _bjs_roundTripOptionalNetworkingAPIMethod(_ methodIsSome: Int32, _ methodValue: Int32) -> Void { +@_expose(wasm, "bjs_testDirectionDefault") +@_cdecl("bjs_testDirectionDefault") +public func _bjs_testDirectionDefault(_ direction: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalNetworkingAPIMethod(_: Optional.bridgeJSLiftParameter(methodIsSome, methodValue)) + let ret = testDirectionDefault(direction: Direction.bridgeJSLiftParameter(direction)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalAPIResult") -@_cdecl("bjs_roundTripOptionalAPIResult") -public func _bjs_roundTripOptionalAPIResult(_ valueIsSome: Int32, _ valueCaseId: Int32) -> Void { +@_expose(wasm, "bjs_testRawStringEnumDefault") +@_cdecl("bjs_testRawStringEnumDefault") +public func _bjs_testRawStringEnumDefault(_ themeBytes: Int32, _ themeLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalAPIResult(value: Optional.bridgeJSLiftParameter(valueIsSome, valueCaseId)) + let ret = testRawStringEnumDefault(theme: Theme.bridgeJSLiftParameter(themeBytes, themeLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_compareAPIResults") -@_cdecl("bjs_compareAPIResults") -public func _bjs_compareAPIResults(_ r1IsSome: Int32, _ r1CaseId: Int32, _ r2IsSome: Int32, _ r2CaseId: Int32) -> Void { +@_expose(wasm, "bjs_testComplexInit") +@_cdecl("bjs_testComplexInit") +public func _bjs_testComplexInit(_ greeter: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let _tmp_r2 = Optional.bridgeJSLiftParameter(r2IsSome, r2CaseId) - let _tmp_r1 = Optional.bridgeJSLiftParameter(r1IsSome, r1CaseId) - let ret = compareAPIResults(_: _tmp_r1, _: _tmp_r2) + let ret = testComplexInit(greeter: Greeter.bridgeJSLiftParameter(greeter)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalComplexResult") -@_cdecl("bjs_roundTripOptionalComplexResult") -public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { +@_expose(wasm, "bjs_testEmptyInit") +@_cdecl("bjs_testEmptyInit") +public func _bjs_testEmptyInit(_ object: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = roundTripOptionalComplexResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + let ret = testEmptyInit(_: StaticPropertyHolder.bridgeJSLiftParameter(object)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalClass") -@_cdecl("bjs_roundTripOptionalClass") -public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_arrayWithDefault") +@_cdecl("bjs_arrayWithDefault") +public func _bjs_arrayWithDefault() -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalClass(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = arrayWithDefault(_: [Int].bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalAPIOptionalResult") -@_cdecl("bjs_roundTripOptionalAPIOptionalResult") -public func _bjs_roundTripOptionalAPIOptionalResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { +@_expose(wasm, "bjs_arrayWithOptionalDefault") +@_cdecl("bjs_arrayWithOptionalDefault") +public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + let ret = arrayWithOptionalDefault(_: { + if values == 0 { + return Optional<[Int]>.none + } else { + return [Int].bridgeJSLiftParameter() + } + }()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_createPropertyHolder") -@_cdecl("bjs_createPropertyHolder") -public func _bjs_createPropertyHolder(_ intValue: Int32, _ floatValue: Float32, _ doubleValue: Float64, _ boolValue: Int32, _ stringValueBytes: Int32, _ stringValueLength: Int32, _ jsObject: Int32) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_arrayMixedDefaults") +@_cdecl("bjs_arrayMixedDefaults") +public func _bjs_arrayMixedDefaults(_ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { #if arch(wasm32) - let ret = createPropertyHolder(intValue: Int.bridgeJSLiftParameter(intValue), floatValue: Float.bridgeJSLiftParameter(floatValue), doubleValue: Double.bridgeJSLiftParameter(doubleValue), boolValue: Bool.bridgeJSLiftParameter(boolValue), stringValue: String.bridgeJSLiftParameter(stringValueBytes, stringValueLength), jsObject: JSObject.bridgeJSLiftParameter(jsObject)) + let ret = arrayMixedDefaults(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength), values: [Int].bridgeJSLiftParameter(), suffix: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testPropertyHolder") -@_cdecl("bjs_testPropertyHolder") -public func _bjs_testPropertyHolder(_ holder: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_formatName") +@_cdecl("bjs_formatName") +public func _bjs_formatName(_ nameBytes: Int32, _ nameLength: Int32, _ transform: Int32) -> Void { #if arch(wasm32) - let ret = testPropertyHolder(holder: PropertyHolder.bridgeJSLiftParameter(holder)) + let ret = formatName(_: String.bridgeJSLiftParameter(nameBytes, nameLength), transform: _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLift(transform)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_resetObserverCounts") -@_cdecl("bjs_resetObserverCounts") -public func _bjs_resetObserverCounts() -> Void { +@_expose(wasm, "bjs_makeFormatter") +@_cdecl("bjs_makeFormatter") +public func _bjs_makeFormatter(_ prefixBytes: Int32, _ prefixLength: Int32) -> UnsafeMutableRawPointer { #if arch(wasm32) - resetObserverCounts() + let ret = makeFormatter(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength)) + return _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLower(ret) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_getObserverStats") -@_cdecl("bjs_getObserverStats") -public func _bjs_getObserverStats() -> Void { +@_expose(wasm, "bjs_makeAdder") +@_cdecl("bjs_makeAdder") +public func _bjs_makeAdder(_ base: Int32) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = getObserverStats() - return ret.bridgeJSLowerReturn() + let ret = makeAdder(base: Int.bridgeJSLiftParameter(base)) + return _BJS_Closure_20BridgeJSRuntimeTestsSi_Si.bridgeJSLower(ret) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testStringDefault") -@_cdecl("bjs_testStringDefault") -public func _bjs_testStringDefault(_ messageBytes: Int32, _ messageLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripIntArray") +@_cdecl("bjs_roundTripIntArray") +public func _bjs_roundTripIntArray() -> Void { #if arch(wasm32) - let ret = testStringDefault(message: String.bridgeJSLiftParameter(messageBytes, messageLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripIntArray(_: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testIntDefault") -@_cdecl("bjs_testIntDefault") -public func _bjs_testIntDefault(_ count: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripStringArray") +@_cdecl("bjs_roundTripStringArray") +public func _bjs_roundTripStringArray() -> Void { #if arch(wasm32) - let ret = testIntDefault(count: Int.bridgeJSLiftParameter(count)) - return ret.bridgeJSLowerReturn() + let ret = roundTripStringArray(_: [String].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testBoolDefault") -@_cdecl("bjs_testBoolDefault") -public func _bjs_testBoolDefault(_ flag: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripDoubleArray") +@_cdecl("bjs_roundTripDoubleArray") +public func _bjs_roundTripDoubleArray() -> Void { #if arch(wasm32) - let ret = testBoolDefault(flag: Bool.bridgeJSLiftParameter(flag)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDoubleArray(_: [Double].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testOptionalDefault") -@_cdecl("bjs_testOptionalDefault") -public func _bjs_testOptionalDefault(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripBoolArray") +@_cdecl("bjs_roundTripBoolArray") +public func _bjs_roundTripBoolArray() -> Void { #if arch(wasm32) - let ret = testOptionalDefault(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripBoolArray(_: [Bool].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testMultipleDefaults") -@_cdecl("bjs_testMultipleDefaults") -public func _bjs_testMultipleDefaults(_ titleBytes: Int32, _ titleLength: Int32, _ count: Int32, _ enabled: Int32) -> Void { +@_expose(wasm, "bjs_roundTripDirectionArray") +@_cdecl("bjs_roundTripDirectionArray") +public func _bjs_roundTripDirectionArray() -> Void { #if arch(wasm32) - let ret = testMultipleDefaults(title: String.bridgeJSLiftParameter(titleBytes, titleLength), count: Int.bridgeJSLiftParameter(count), enabled: Bool.bridgeJSLiftParameter(enabled)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDirectionArray(_: [Direction].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testSimpleEnumDefault") -@_cdecl("bjs_testSimpleEnumDefault") -public func _bjs_testSimpleEnumDefault(_ status: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripStatusArray") +@_cdecl("bjs_roundTripStatusArray") +public func _bjs_roundTripStatusArray() -> Void { #if arch(wasm32) - let ret = testSimpleEnumDefault(status: Status.bridgeJSLiftParameter(status)) - return ret.bridgeJSLowerReturn() + let ret = roundTripStatusArray(_: [Status].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testDirectionDefault") -@_cdecl("bjs_testDirectionDefault") -public func _bjs_testDirectionDefault(_ direction: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripThemeArray") +@_cdecl("bjs_roundTripThemeArray") +public func _bjs_roundTripThemeArray() -> Void { #if arch(wasm32) - let ret = testDirectionDefault(direction: Direction.bridgeJSLiftParameter(direction)) - return ret.bridgeJSLowerReturn() + let ret = roundTripThemeArray(_: [Theme].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testRawStringEnumDefault") -@_cdecl("bjs_testRawStringEnumDefault") -public func _bjs_testRawStringEnumDefault(_ themeBytes: Int32, _ themeLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripHttpStatusArray") +@_cdecl("bjs_roundTripHttpStatusArray") +public func _bjs_roundTripHttpStatusArray() -> Void { #if arch(wasm32) - let ret = testRawStringEnumDefault(theme: Theme.bridgeJSLiftParameter(themeBytes, themeLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripHttpStatusArray(_: [HttpStatus].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testComplexInit") -@_cdecl("bjs_testComplexInit") -public func _bjs_testComplexInit(_ greeter: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_roundTripDataPointArray") +@_cdecl("bjs_roundTripDataPointArray") +public func _bjs_roundTripDataPointArray() -> Void { #if arch(wasm32) - let ret = testComplexInit(greeter: Greeter.bridgeJSLiftParameter(greeter)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDataPointArray(_: [DataPoint].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testEmptyInit") -@_cdecl("bjs_testEmptyInit") -public func _bjs_testEmptyInit(_ object: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_roundTripGreeterArray") +@_cdecl("bjs_roundTripGreeterArray") +public func _bjs_roundTripGreeterArray() -> Void { #if arch(wasm32) - let ret = testEmptyInit(_: StaticPropertyHolder.bridgeJSLiftParameter(object)) - return ret.bridgeJSLowerReturn() + let ret = roundTripGreeterArray(_: [Greeter].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_arrayWithDefault") -@_cdecl("bjs_arrayWithDefault") -public func _bjs_arrayWithDefault() -> Int32 { +@_expose(wasm, "bjs_roundTripOptionalIntArray") +@_cdecl("bjs_roundTripOptionalIntArray") +public func _bjs_roundTripOptionalIntArray() -> Void { #if arch(wasm32) - let ret = arrayWithDefault(_: { + let ret = roundTripOptionalIntArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result }()) - return ret.bridgeJSLowerReturn() + for __bjs_elem_ret in ret { + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_arrayWithOptionalDefault") -@_cdecl("bjs_arrayWithOptionalDefault") -public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripOptionalStringArray") +@_cdecl("bjs_roundTripOptionalStringArray") +public func _bjs_roundTripOptionalStringArray() -> Void { #if arch(wasm32) - let ret = arrayWithOptionalDefault(_: { - if values == 0 { - return Optional<[Int]>.none - } else { - return { + let ret = roundTripOptionalStringArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result - }() - } }()) - return ret.bridgeJSLowerReturn() + for __bjs_elem_ret in ret { + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_arrayMixedDefaults") -@_cdecl("bjs_arrayMixedDefaults") -public func _bjs_arrayMixedDefaults(_ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalDataPointArray") +@_cdecl("bjs_roundTripOptionalDataPointArray") +public func _bjs_roundTripOptionalDataPointArray() -> Void { #if arch(wasm32) - let ret = arrayMixedDefaults(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength), values: { + let ret = roundTripOptionalDataPointArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result - }(), suffix: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_formatName") -@_cdecl("bjs_formatName") -public func _bjs_formatName(_ nameBytes: Int32, _ nameLength: Int32, _ transform: Int32) -> Void { - #if arch(wasm32) - let ret = formatName(_: String.bridgeJSLiftParameter(nameBytes, nameLength), transform: _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLift(transform)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_makeFormatter") -@_cdecl("bjs_makeFormatter") -public func _bjs_makeFormatter(_ prefixBytes: Int32, _ prefixLength: Int32) -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = makeFormatter(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength)) - return _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLower(ret) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_makeAdder") -@_cdecl("bjs_makeAdder") -public func _bjs_makeAdder(_ base: Int32) -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = makeAdder(base: Int.bridgeJSLiftParameter(base)) - return _BJS_Closure_20BridgeJSRuntimeTestsSi_Si.bridgeJSLower(ret) + }()) + for __bjs_elem_ret in ret { + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripIntArray") -@_cdecl("bjs_roundTripIntArray") -public func _bjs_roundTripIntArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalDirectionArray") +@_cdecl("bjs_roundTripOptionalDirectionArray") +public func _bjs_roundTripOptionalDirectionArray() -> Void { #if arch(wasm32) - let ret = roundTripIntArray(_: { + let ret = roundTripOptionalDirectionArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripStringArray") -@_cdecl("bjs_roundTripStringArray") -public func _bjs_roundTripStringArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalStatusArray") +@_cdecl("bjs_roundTripOptionalStatusArray") +public func _bjs_roundTripOptionalStatusArray() -> Void { #if arch(wasm32) - let ret = roundTripStringArray(_: { + let ret = roundTripOptionalStatusArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} + let __bjs_isSome_ret_elem = __bjs_elem_ret != nil + if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} + _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDoubleArray") -@_cdecl("bjs_roundTripDoubleArray") -public func _bjs_roundTripDoubleArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalIntArrayType") +@_cdecl("bjs_roundTripOptionalIntArrayType") +public func _bjs_roundTripOptionalIntArrayType(_ values: Int32) -> Void { #if arch(wasm32) - let ret = roundTripDoubleArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) + let ret = roundTripOptionalIntArrayType(_: { + if values == 0 { + return Optional<[Int]>.none + } else { + return [Int].bridgeJSLiftParameter() } - __result.reverse() - return __result }()) - for __bjs_elem_ret in ret { - _swift_js_push_f64(__bjs_elem_ret)} - _swift_js_push_i32(Int32(ret.count)) + let __bjs_isSome_ret = ret != nil + if let __bjs_unwrapped_ret = ret { + __bjs_unwrapped_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripBoolArray") -@_cdecl("bjs_roundTripBoolArray") -public func _bjs_roundTripBoolArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalStringArrayType") +@_cdecl("bjs_roundTripOptionalStringArrayType") +public func _bjs_roundTripOptionalStringArrayType(_ values: Int32) -> Void { #if arch(wasm32) - let ret = roundTripBoolArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Bool] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) + let ret = roundTripOptionalStringArrayType(_: { + if values == 0 { + return Optional<[String]>.none + } else { + return [String].bridgeJSLiftParameter() } - __result.reverse() - return __result }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(__bjs_elem_ret ? 1 : 0)} - _swift_js_push_i32(Int32(ret.count)) + let __bjs_isSome_ret = ret != nil + if let __bjs_unwrapped_ret = ret { + __bjs_unwrapped_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDirectionArray") -@_cdecl("bjs_roundTripDirectionArray") -public func _bjs_roundTripDirectionArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalGreeterArrayType") +@_cdecl("bjs_roundTripOptionalGreeterArrayType") +public func _bjs_roundTripOptionalGreeterArrayType(_ greeters: Int32) -> Void { #if arch(wasm32) - let ret = roundTripDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Direction] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Direction.bridgeJSLiftParameter(_swift_js_pop_i32())) + let ret = roundTripOptionalGreeterArrayType(_: { + if greeters == 0 { + return Optional<[Greeter]>.none + } else { + return [Greeter].bridgeJSLiftParameter() } - __result.reverse() - return __result }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret.bridgeJSLowerParameter()))} - _swift_js_push_i32(Int32(ret.count)) + let __bjs_isSome_ret = ret != nil + if let __bjs_unwrapped_ret = ret { + __bjs_unwrapped_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripStatusArray") -@_cdecl("bjs_roundTripStatusArray") -public func _bjs_roundTripStatusArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedIntArray") +@_cdecl("bjs_roundTripNestedIntArray") +public func _bjs_roundTripNestedIntArray() -> Void { #if arch(wasm32) - let ret = roundTripStatusArray(_: { + let ret = roundTripNestedIntArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Status] = [] + var __result: [[Int]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Status.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append([Int].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret.bridgeJSLowerParameter()))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripThemeArray") -@_cdecl("bjs_roundTripThemeArray") -public func _bjs_roundTripThemeArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedStringArray") +@_cdecl("bjs_roundTripNestedStringArray") +public func _bjs_roundTripNestedStringArray() -> Void { #if arch(wasm32) - let ret = roundTripThemeArray(_: { + let ret = roundTripNestedStringArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Theme] = [] + var __result: [[String]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Theme.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append([String].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - var __bjs_ret_elem = __bjs_elem_ret.rawValue - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripHttpStatusArray") -@_cdecl("bjs_roundTripHttpStatusArray") -public func _bjs_roundTripHttpStatusArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedDoubleArray") +@_cdecl("bjs_roundTripNestedDoubleArray") +public func _bjs_roundTripNestedDoubleArray() -> Void { #if arch(wasm32) - let ret = roundTripHttpStatusArray(_: { + let ret = roundTripNestedDoubleArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [HttpStatus] = [] + var __result: [[Double]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(HttpStatus.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append([Double].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - _swift_js_push_i32(Int32(__bjs_elem_ret.bridgeJSLowerParameter()))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDataPointArray") -@_cdecl("bjs_roundTripDataPointArray") -public func _bjs_roundTripDataPointArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedBoolArray") +@_cdecl("bjs_roundTripNestedBoolArray") +public func _bjs_roundTripNestedBoolArray() -> Void { #if arch(wasm32) - let ret = roundTripDataPointArray(_: { + let ret = roundTripNestedBoolArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [DataPoint] = [] + var __result: [[Bool]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(DataPoint.bridgeJSLiftParameter()) + __result.append([Bool].bridgeJSLiftParameter()) } __result.reverse() return __result @@ -4865,91 +5315,172 @@ public func _bjs_roundTripDataPointArray() -> Void { #endif } -@_expose(wasm, "bjs_roundTripGreeterArray") -@_cdecl("bjs_roundTripGreeterArray") -public func _bjs_roundTripGreeterArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedDataPointArray") +@_cdecl("bjs_roundTripNestedDataPointArray") +public func _bjs_roundTripNestedDataPointArray() -> Void { #if arch(wasm32) - let ret = roundTripGreeterArray(_: { + let ret = roundTripNestedDataPointArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Greeter] = [] + var __result: [[DataPoint]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Greeter.bridgeJSLiftParameter(_swift_js_pop_pointer())) + __result.append([DataPoint].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalIntArray") -@_cdecl("bjs_roundTripOptionalIntArray") -public func _bjs_roundTripOptionalIntArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedDirectionArray") +@_cdecl("bjs_roundTripNestedDirectionArray") +public func _bjs_roundTripNestedDirectionArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalIntArray(_: { + let ret = roundTripNestedDirectionArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] + var __result: [[Direction]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append([Direction].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - let __bjs_isSome_ret_elem = __bjs_elem_ret != nil - if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_unwrapped_ret_elem))} - _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStringArray") -@_cdecl("bjs_roundTripOptionalStringArray") -public func _bjs_roundTripOptionalStringArray() -> Void { +@_expose(wasm, "bjs_roundTripNestedGreeterArray") +@_cdecl("bjs_roundTripNestedGreeterArray") +public func _bjs_roundTripNestedGreeterArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStringArray(_: { + let ret = roundTripNestedGreeterArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] + var __result: [[Greeter]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append([Greeter].bridgeJSLiftParameter()) } __result.reverse() return __result }()) for __bjs_elem_ret in ret { - let __bjs_isSome_ret_elem = __bjs_elem_ret != nil - if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - var __bjs_str_ret_elem = __bjs_unwrapped_ret_elem - __bjs_str_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalDataPointArray") -@_cdecl("bjs_roundTripOptionalDataPointArray") -public func _bjs_roundTripOptionalDataPointArray() -> Void { +@_expose(wasm, "bjs_roundTripUnsafeRawPointerArray") +@_cdecl("bjs_roundTripUnsafeRawPointerArray") +public func _bjs_roundTripUnsafeRawPointerArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDataPointArray(_: { + let ret = roundTripUnsafeRawPointerArray(_: [UnsafeRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripUnsafeMutableRawPointerArray") +@_cdecl("bjs_roundTripUnsafeMutableRawPointerArray") +public func _bjs_roundTripUnsafeMutableRawPointerArray() -> Void { + #if arch(wasm32) + let ret = roundTripUnsafeMutableRawPointerArray(_: [UnsafeMutableRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOpaquePointerArray") +@_cdecl("bjs_roundTripOpaquePointerArray") +public func _bjs_roundTripOpaquePointerArray() -> Void { + #if arch(wasm32) + let ret = roundTripOpaquePointerArray(_: [OpaquePointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripUnsafePointerArray") +@_cdecl("bjs_roundTripUnsafePointerArray") +public func _bjs_roundTripUnsafePointerArray() -> Void { + #if arch(wasm32) + let ret = roundTripUnsafePointerArray(_: [UnsafePointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripUnsafeMutablePointerArray") +@_cdecl("bjs_roundTripUnsafeMutablePointerArray") +public func _bjs_roundTripUnsafeMutablePointerArray() -> Void { + #if arch(wasm32) + let ret = roundTripUnsafeMutablePointerArray(_: [UnsafeMutablePointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_consumeDataProcessorArrayType") +@_cdecl("bjs_consumeDataProcessorArrayType") +public func _bjs_consumeDataProcessorArrayType() -> Int32 { + #if arch(wasm32) + let ret = consumeDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripDataProcessorArrayType") +@_cdecl("bjs_roundTripDataProcessorArrayType") +public func _bjs_roundTripDataProcessorArrayType() -> Void { + #if arch(wasm32) + let ret = roundTripDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + ret.map { + $0 as! AnyDataProcessor + } .bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripJSObjectArray") +@_cdecl("bjs_roundTripJSObjectArray") +public func _bjs_roundTripJSObjectArray() -> Void { + #if arch(wasm32) + let ret = roundTripJSObjectArray(_: [JSObject].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalJSObjectArray") +@_cdecl("bjs_roundTripOptionalJSObjectArray") +public func _bjs_roundTripOptionalJSObjectArray() -> Void { + #if arch(wasm32) + let ret = roundTripOptionalJSObjectArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -4957,7 +5488,7 @@ public func _bjs_roundTripOptionalDataPointArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - __bjs_unwrapped_ret_elem.bridgeJSLowerReturn()} + __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -4965,41 +5496,40 @@ public func _bjs_roundTripOptionalDataPointArray() -> Void { #endif } -@_expose(wasm, "bjs_roundTripOptionalDirectionArray") -@_cdecl("bjs_roundTripOptionalDirectionArray") -public func _bjs_roundTripOptionalDirectionArray() -> Void { +@_expose(wasm, "bjs_roundTripFooArray") +@_cdecl("bjs_roundTripFooArray") +public func _bjs_roundTripFooArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDirectionArray(_: { + let ret = roundTripFooArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] + var __result: [Foo] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter())) } __result.reverse() return __result }()) - for __bjs_elem_ret in ret { - let __bjs_isSome_ret_elem = __bjs_elem_ret != nil - if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(__bjs_unwrapped_ret_elem.bridgeJSLowerParameter())} - _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} - _swift_js_push_i32(Int32(ret.count)) + ret.map { + $0.jsObject + } .bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStatusArray") -@_cdecl("bjs_roundTripOptionalStatusArray") -public func _bjs_roundTripOptionalStatusArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalFooArray") +@_cdecl("bjs_roundTripOptionalFooArray") +public func _bjs_roundTripOptionalFooArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStatusArray(_: { + let ret = roundTripOptionalFooArray(_: { let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] + var __result: [Optional] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append(Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) + __result.append(Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + }) } __result.reverse() return __result @@ -5007,7 +5537,7 @@ public func _bjs_roundTripOptionalStatusArray() -> Void { for __bjs_elem_ret in ret { let __bjs_isSome_ret_elem = __bjs_elem_ret != nil if let __bjs_unwrapped_ret_elem = __bjs_elem_ret { - _swift_js_push_i32(__bjs_unwrapped_ret_elem.bridgeJSLowerParameter())} + __bjs_unwrapped_ret_elem.jsObject.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -5015,439 +5545,311 @@ public func _bjs_roundTripOptionalStatusArray() -> Void { #endif } -@_expose(wasm, "bjs_roundTripOptionalIntArrayType") -@_cdecl("bjs_roundTripOptionalIntArrayType") -public func _bjs_roundTripOptionalIntArrayType(_ values: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalString") +@_cdecl("bjs_roundTripOptionalString") +public func _bjs_roundTripOptionalString(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalIntArrayType(_: { - if values == 0 { - return Optional<[Int]>.none - } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }() - } - }()) - let __bjs_isSome_ret = ret != nil - if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret))} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} - _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) + let ret = roundTripOptionalString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStringArrayType") -@_cdecl("bjs_roundTripOptionalStringArrayType") -public func _bjs_roundTripOptionalStringArrayType(_ values: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalInt") +@_cdecl("bjs_roundTripOptionalInt") +public func _bjs_roundTripOptionalInt(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalStringArrayType(_: { - if values == 0 { - return Optional<[String]>.none - } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }() - } - }()) - let __bjs_isSome_ret = ret != nil - if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - var __bjs_ret_elem = __bjs_elem_ret - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} - _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) + let ret = roundTripOptionalInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalGreeterArrayType") -@_cdecl("bjs_roundTripOptionalGreeterArrayType") -public func _bjs_roundTripOptionalGreeterArrayType(_ greeters: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalBool") +@_cdecl("bjs_roundTripOptionalBool") +public func _bjs_roundTripOptionalBool(_ flagIsSome: Int32, _ flagValue: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalGreeterArrayType(_: { - if greeters == 0 { - return Optional<[Greeter]>.none - } else { - return { - let __count = Int(_swift_js_pop_i32()) - var __result: [Greeter] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Greeter.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }() - } - }()) - let __bjs_isSome_ret = ret != nil - if let __bjs_unwrapped_ret = ret { - for __bjs_elem_ret in __bjs_unwrapped_ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(__bjs_unwrapped_ret.count))} - _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) + let ret = roundTripOptionalBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedIntArray") -@_cdecl("bjs_roundTripNestedIntArray") -public func _bjs_roundTripNestedIntArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalFloat") +@_cdecl("bjs_roundTripOptionalFloat") +public func _bjs_roundTripOptionalFloat(_ numberIsSome: Int32, _ numberValue: Float32) -> Void { #if arch(wasm32) - let ret = roundTripNestedIntArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Int]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Int] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Int.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret_elem))} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalFloat(number: Optional.bridgeJSLiftParameter(numberIsSome, numberValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalDouble") +@_cdecl("bjs_roundTripOptionalDouble") +public func _bjs_roundTripOptionalDouble(_ precisionIsSome: Int32, _ precisionValue: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalDouble(precision: Optional.bridgeJSLiftParameter(precisionIsSome, precisionValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalSyntax") +@_cdecl("bjs_roundTripOptionalSyntax") +public func _bjs_roundTripOptionalSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalMixSyntax") +@_cdecl("bjs_roundTripOptionalMixSyntax") +public func _bjs_roundTripOptionalMixSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalMixSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalSwiftSyntax") +@_cdecl("bjs_roundTripOptionalSwiftSyntax") +public func _bjs_roundTripOptionalSwiftSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalWithSpaces") +@_cdecl("bjs_roundTripOptionalWithSpaces") +public func _bjs_roundTripOptionalWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalWithSpaces(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalTypeAlias") +@_cdecl("bjs_roundTripOptionalTypeAlias") +public func _bjs_roundTripOptionalTypeAlias(_ ageIsSome: Int32, _ ageValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalTypeAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalStatus") +@_cdecl("bjs_roundTripOptionalStatus") +public func _bjs_roundTripOptionalStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalTheme") +@_cdecl("bjs_roundTripOptionalTheme") +public func _bjs_roundTripOptionalTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalHttpStatus") +@_cdecl("bjs_roundTripOptionalHttpStatus") +public func _bjs_roundTripOptionalHttpStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalHttpStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalTSDirection") +@_cdecl("bjs_roundTripOptionalTSDirection") +public func _bjs_roundTripOptionalTSDirection(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalTSDirection(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalTSTheme") +@_cdecl("bjs_roundTripOptionalTSTheme") +public func _bjs_roundTripOptionalTSTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalTSTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalNetworkingAPIMethod") +@_cdecl("bjs_roundTripOptionalNetworkingAPIMethod") +public func _bjs_roundTripOptionalNetworkingAPIMethod(_ methodIsSome: Int32, _ methodValue: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalNetworkingAPIMethod(_: Optional.bridgeJSLiftParameter(methodIsSome, methodValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalAPIResult") +@_cdecl("bjs_roundTripOptionalAPIResult") +public func _bjs_roundTripOptionalAPIResult(_ valueIsSome: Int32, _ valueCaseId: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalAPIResult(value: Optional.bridgeJSLiftParameter(valueIsSome, valueCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedStringArray") -@_cdecl("bjs_roundTripNestedStringArray") -public func _bjs_roundTripNestedStringArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalTypedPayloadResult") +@_cdecl("bjs_roundTripOptionalTypedPayloadResult") +public func _bjs_roundTripOptionalTypedPayloadResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedStringArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[String]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [String] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(String.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - var __bjs_ret_elem_elem = __bjs_elem_ret_elem - __bjs_ret_elem_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalTypedPayloadResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedDoubleArray") -@_cdecl("bjs_roundTripNestedDoubleArray") -public func _bjs_roundTripNestedDoubleArray() -> Void { +@_expose(wasm, "bjs_compareAPIResults") +@_cdecl("bjs_compareAPIResults") +public func _bjs_compareAPIResults(_ r1IsSome: Int32, _ r1CaseId: Int32, _ r2IsSome: Int32, _ r2CaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedDoubleArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Double]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Double] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Double.bridgeJSLiftParameter(_swift_js_pop_f64())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_f64(__bjs_elem_ret_elem)} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let _tmp_r2 = Optional.bridgeJSLiftParameter(r2IsSome, r2CaseId) + let _tmp_r1 = Optional.bridgeJSLiftParameter(r1IsSome, r1CaseId) + let ret = compareAPIResults(_: _tmp_r1, _: _tmp_r2) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedBoolArray") -@_cdecl("bjs_roundTripNestedBoolArray") -public func _bjs_roundTripNestedBoolArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalComplexResult") +@_cdecl("bjs_roundTripOptionalComplexResult") +public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedBoolArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Bool]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Bool] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Bool.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(__bjs_elem_ret_elem ? 1 : 0)} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalComplexResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedDataPointArray") -@_cdecl("bjs_roundTripNestedDataPointArray") -public func _bjs_roundTripNestedDataPointArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalAllTypesResult") +@_cdecl("bjs_roundTripOptionalAllTypesResult") +public func _bjs_roundTripOptionalAllTypesResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedDataPointArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[DataPoint]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [DataPoint] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(DataPoint.bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - __bjs_elem_ret_elem.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalAllTypesResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedDirectionArray") -@_cdecl("bjs_roundTripNestedDirectionArray") -public func _bjs_roundTripNestedDirectionArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalPayloadResult") +@_cdecl("bjs_roundTripOptionalPayloadResult") +public func _bjs_roundTripOptionalPayloadResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Direction]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Direction] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Direction.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_i32(Int32(__bjs_elem_ret_elem.bridgeJSLowerParameter()))} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalPayloadResult(_: OptionalAllTypesResult.bridgeJSLiftParameter(result)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripNestedGreeterArray") -@_cdecl("bjs_roundTripNestedGreeterArray") -public func _bjs_roundTripNestedGreeterArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalPayloadResultOpt") +@_cdecl("bjs_roundTripOptionalPayloadResultOpt") +public func _bjs_roundTripOptionalPayloadResultOpt(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripNestedGreeterArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [[Greeter]] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Greeter] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Greeter.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - for __bjs_elem_ret_elem in __bjs_elem_ret { - _swift_js_push_pointer(__bjs_elem_ret_elem.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(__bjs_elem_ret.count))} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalPayloadResultOpt(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripUnsafeRawPointerArray") -@_cdecl("bjs_roundTripUnsafeRawPointerArray") -public func _bjs_roundTripUnsafeRawPointerArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalClass") +@_cdecl("bjs_roundTripOptionalClass") +public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = roundTripUnsafeRawPointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [UnsafeRawPointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(UnsafeRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalClass(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripUnsafeMutableRawPointerArray") -@_cdecl("bjs_roundTripUnsafeMutableRawPointerArray") -public func _bjs_roundTripUnsafeMutableRawPointerArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalGreeter") +@_cdecl("bjs_roundTripOptionalGreeter") +public func _bjs_roundTripOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = roundTripUnsafeMutableRawPointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [UnsafeMutableRawPointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(UnsafeMutableRawPointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOpaquePointerArray") -@_cdecl("bjs_roundTripOpaquePointerArray") -public func _bjs_roundTripOpaquePointerArray() -> Void { +@_expose(wasm, "bjs_applyOptionalGreeter") +@_cdecl("bjs_applyOptionalGreeter") +public func _bjs_applyOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer, _ transform: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOpaquePointerArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [OpaquePointer] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(OpaquePointer.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = applyOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue), _: _BJS_Closure_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC.bridgeJSLift(transform)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_consumeDataProcessorArrayType") -@_cdecl("bjs_consumeDataProcessorArrayType") -public func _bjs_consumeDataProcessorArrayType() -> Int32 { +@_expose(wasm, "bjs_makeOptionalHolder") +@_cdecl("bjs_makeOptionalHolder") +public func _bjs_makeOptionalHolder(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsSome: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = consumeDataProcessorArrayType(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [AnyDataProcessor] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(AnyDataProcessor.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) + let ret = makeOptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsSome, undefinedNumberValue)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDataProcessorArrayType") -@_cdecl("bjs_roundTripDataProcessorArrayType") -public func _bjs_roundTripDataProcessorArrayType() -> Void { +@_expose(wasm, "bjs_roundTripOptionalAPIOptionalResult") +@_cdecl("bjs_roundTripOptionalAPIOptionalResult") +public func _bjs_roundTripOptionalAPIOptionalResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripDataProcessorArrayType(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [AnyDataProcessor] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(AnyDataProcessor.bridgeJSLiftParameter(_swift_js_pop_i32())) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - _swift_js_push_i32((__bjs_elem_ret as! AnyDataProcessor).bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -5567,31 +5969,90 @@ public func _bjs_roundTripAdvancedConfig() -> Void { @_cdecl("bjs_roundTripMeasurementConfig") public func _bjs_roundTripMeasurementConfig() -> Void { #if arch(wasm32) - let ret = roundTripMeasurementConfig(_: MeasurementConfig.bridgeJSLiftParameter()) + let ret = roundTripMeasurementConfig(_: MeasurementConfig.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_updateValidationReport") +@_cdecl("bjs_updateValidationReport") +public func _bjs_updateValidationReport(_ newResultIsSome: Int32, _ newResultCaseId: Int32) -> Void { + #if arch(wasm32) + let _tmp_report = ValidationReport.bridgeJSLiftParameter() + let _tmp_newResult = Optional.bridgeJSLiftParameter(newResultIsSome, newResultCaseId) + let ret = updateValidationReport(_: _tmp_newResult, _: _tmp_report) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_testContainerWithStruct") +@_cdecl("bjs_testContainerWithStruct") +public func _bjs_testContainerWithStruct() -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = testContainerWithStruct(_: DataPoint.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripJSObjectContainer") +@_cdecl("bjs_roundTripJSObjectContainer") +public func _bjs_roundTripJSObjectContainer() -> Void { + #if arch(wasm32) + let ret = roundTripJSObjectContainer(_: JSObjectContainer.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripFooContainer") +@_cdecl("bjs_roundTripFooContainer") +public func _bjs_roundTripFooContainer() -> Void { + #if arch(wasm32) + let ret = roundTripFooContainer(_: FooContainer.bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripArrayMembers") +@_cdecl("bjs_roundTripArrayMembers") +public func _bjs_roundTripArrayMembers() -> Void { + #if arch(wasm32) + let ret = roundTripArrayMembers(_: ArrayMembers.bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_updateValidationReport") -@_cdecl("bjs_updateValidationReport") -public func _bjs_updateValidationReport(_ newResultIsSome: Int32, _ newResultCaseId: Int32) -> Void { +@_expose(wasm, "bjs_arrayMembersSum") +@_cdecl("bjs_arrayMembersSum") +public func _bjs_arrayMembersSum() -> Int32 { #if arch(wasm32) - let _tmp_report = ValidationReport.bridgeJSLiftParameter() - let _tmp_newResult = Optional.bridgeJSLiftParameter(newResultIsSome, newResultCaseId) - let ret = updateValidationReport(_: _tmp_newResult, _: _tmp_report) + let _tmp_values = [Int].bridgeJSLiftParameter() + let _tmp_value = ArrayMembers.bridgeJSLiftParameter() + let ret = arrayMembersSum(_: _tmp_value, _: _tmp_values) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_testContainerWithStruct") -@_cdecl("bjs_testContainerWithStruct") -public func _bjs_testContainerWithStruct() -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_arrayMembersFirst") +@_cdecl("bjs_arrayMembersFirst") +public func _bjs_arrayMembersFirst() -> Void { #if arch(wasm32) - let ret = testContainerWithStruct(_: DataPoint.bridgeJSLiftParameter()) + let _tmp_values = [String].bridgeJSLiftParameter() + let _tmp_value = ArrayMembers.bridgeJSLiftParameter() + let ret = arrayMembersFirst(_: _tmp_value, _: _tmp_values) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -5992,105 +6453,6 @@ fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int } #endif -@_expose(wasm, "bjs_OptionalPropertyHolder_init") -@_cdecl("bjs_OptionalPropertyHolder_init") -public func _bjs_OptionalPropertyHolder_init(_ optionalNameIsSome: Int32, _ optionalNameBytes: Int32, _ optionalNameLength: Int32) -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = OptionalPropertyHolder(optionalName: Optional.bridgeJSLiftParameter(optionalNameIsSome, optionalNameBytes, optionalNameLength)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalName_get") -public func _bjs_OptionalPropertyHolder_optionalName_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalName_set") -public func _bjs_OptionalPropertyHolder_optionalName_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalAge_get") -public func _bjs_OptionalPropertyHolder_optionalAge_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalAge_set") -public func _bjs_OptionalPropertyHolder_optionalAge_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_get") -public func _bjs_OptionalPropertyHolder_optionalGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_set") -@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_set") -public func _bjs_OptionalPropertyHolder_optionalGreeter_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_OptionalPropertyHolder_deinit") -@_cdecl("bjs_OptionalPropertyHolder_deinit") -public func _bjs_OptionalPropertyHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension OptionalPropertyHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalPropertyHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalPropertyHolder_wrap") -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - @_expose(wasm, "bjs_SimplePropertyHolder_init") @_cdecl("bjs_SimplePropertyHolder_init") public func _bjs_SimplePropertyHolder_init(_ value: Int32) -> UnsafeMutableRawPointer { @@ -7775,45 +8137,222 @@ public func _bjs_TextProcessor_processOptionalTheme(_ _self: UnsafeMutableRawPoi @_cdecl("bjs_TextProcessor_processOptionalAPIResult") public func _bjs_TextProcessor_processOptionalAPIResult(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { #if arch(wasm32) - let ret = TextProcessor.bridgeJSLiftParameter(_self).processOptionalAPIResult(_: _BJS_Closure_20BridgeJSRuntimeTestsSq9APIResultO_SS.bridgeJSLift(callback)) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processOptionalAPIResult(_: _BJS_Closure_20BridgeJSRuntimeTestsSq9APIResultO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeOptionalDirectionFormatter") +@_cdecl("bjs_TextProcessor_makeOptionalDirectionFormatter") +public func _bjs_TextProcessor_makeOptionalDirectionFormatter(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalDirectionFormatter() + return _BJS_Closure_20BridgeJSRuntimeTestsSq9DirectionO_SS.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_deinit") +@_cdecl("bjs_TextProcessor_deinit") +public func _bjs_TextProcessor_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension TextProcessor: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_TextProcessor_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_TextProcessor_wrap") +fileprivate func _bjs_TextProcessor_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_TextProcessor_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_OptionalHolder_init") +@_cdecl("bjs_OptionalHolder_init") +public func _bjs_OptionalHolder_init(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsSome: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = OptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsSome, undefinedNumberValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalHolder_nullableGreeter_get") +@_cdecl("bjs_OptionalHolder_nullableGreeter_get") +public func _bjs_OptionalHolder_nullableGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalHolder.bridgeJSLiftParameter(_self).nullableGreeter + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalHolder_nullableGreeter_set") +@_cdecl("bjs_OptionalHolder_nullableGreeter_set") +public func _bjs_OptionalHolder_nullableGreeter_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + OptionalHolder.bridgeJSLiftParameter(_self).nullableGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalHolder_undefinedNumber_get") +@_cdecl("bjs_OptionalHolder_undefinedNumber_get") +public func _bjs_OptionalHolder_undefinedNumber_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalHolder_undefinedNumber_set") +@_cdecl("bjs_OptionalHolder_undefinedNumber_set") +public func _bjs_OptionalHolder_undefinedNumber_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Float64) -> Void { + #if arch(wasm32) + OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber = JSUndefinedOr.bridgeJSLiftParameter(valueIsSome, valueValue) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalHolder_deinit") +@_cdecl("bjs_OptionalHolder_deinit") +public func _bjs_OptionalHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension OptionalHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalHolder_wrap") +fileprivate func _bjs_OptionalHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_OptionalHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_OptionalPropertyHolder_init") +@_cdecl("bjs_OptionalPropertyHolder_init") +public func _bjs_OptionalPropertyHolder_init(_ optionalNameIsSome: Int32, _ optionalNameBytes: Int32, _ optionalNameLength: Int32) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = OptionalPropertyHolder(optionalName: Optional.bridgeJSLiftParameter(optionalNameIsSome, optionalNameBytes, optionalNameLength)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalName_get") +public func _bjs_OptionalPropertyHolder_optionalName_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalName_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalName_set") +public func _bjs_OptionalPropertyHolder_optionalName_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: Int32) -> Void { + #if arch(wasm32) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalAge_get") +public func _bjs_OptionalPropertyHolder_optionalAge_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalAge_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalAge_set") +public func _bjs_OptionalPropertyHolder_optionalAge_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Int32) -> Void { + #if arch(wasm32) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_get") +@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_get") +public func _bjs_OptionalPropertyHolder_optionalGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeOptionalDirectionFormatter") -@_cdecl("bjs_TextProcessor_makeOptionalDirectionFormatter") -public func _bjs_TextProcessor_makeOptionalDirectionFormatter(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_set") +@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_set") +public func _bjs_OptionalPropertyHolder_optionalGreeter_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalDirectionFormatter() - return _BJS_Closure_20BridgeJSRuntimeTestsSq9DirectionO_SS.bridgeJSLower(ret) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_deinit") -@_cdecl("bjs_TextProcessor_deinit") -public func _bjs_TextProcessor_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_OptionalPropertyHolder_deinit") +@_cdecl("bjs_OptionalPropertyHolder_deinit") +public func _bjs_OptionalPropertyHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() + Unmanaged.fromOpaque(pointer).release() #else fatalError("Only available on WebAssembly") #endif } -extension TextProcessor: ConvertibleToJSValue, _BridgedSwiftHeapObject { +extension OptionalPropertyHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_TextProcessor_wrap(Unmanaged.passRetained(self).toOpaque())))) + return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalPropertyHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) } } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_TextProcessor_wrap") -fileprivate func _bjs_TextProcessor_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalPropertyHolder_wrap") +fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 #else -fileprivate func _bjs_TextProcessor_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { +fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") } #endif @@ -7936,19 +8475,19 @@ func _$Foo_value_get(_ self: JSObject) throws(JSException) -> String { #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_globalObject1_get") -fileprivate func bjs_globalObject1_get() -> Int32 +fileprivate func bjs_globalObject1_get() -> Void #else -fileprivate func bjs_globalObject1_get() -> Int32 { +fileprivate func bjs_globalObject1_get() -> Void { fatalError("Only available on WebAssembly") } #endif -func _$globalObject1_get() throws(JSException) -> JSObject { - let ret = bjs_globalObject1_get() +func _$globalObject1_get() throws(JSException) -> JSValue { + bjs_globalObject1_get() if let error = _swift_js_take_exception() { throw error } - return JSObject.bridgeJSLiftReturn(ret) + return JSValue.bridgeJSLiftReturn() } #if arch(wasm32) @@ -8021,6 +8560,60 @@ func _$jsRoundTripString(_ v: String) throws(JSException) -> String { return String.bridgeJSLiftReturn(ret) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripJSValue") +fileprivate func bjs_jsRoundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void +#else +fileprivate func bjs_jsRoundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue { + let (vKind, vPayload1, vPayload2) = v.bridgeJSLowerParameter() + bjs_jsRoundTripJSValue(vKind, vPayload1, vPayload2) + if let error = _swift_js_take_exception() { + throw error + } + return JSValue.bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripJSValueArray") +fileprivate func bjs_jsRoundTripJSValueArray() -> Void +#else +fileprivate func bjs_jsRoundTripJSValueArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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(_ v: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalJSValueArray(_ v: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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(_ shouldThrow: Int32) -> Void @@ -8144,6 +8737,95 @@ func _$_jsWeirdFunction() throws(JSException) -> Double { return Double.bridgeJSLiftReturn(ret) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripNumberArray") +fileprivate func bjs_jsRoundTripNumberArray() -> Void +#else +fileprivate func bjs_jsRoundTripNumberArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Void +#else +fileprivate func bjs_jsRoundTripStringArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Void +#else +fileprivate func bjs_jsRoundTripBoolArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Float64 +#else +fileprivate func bjs_jsSumNumberArray() -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Void +#else +fileprivate func bjs_jsCreateNumberArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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(_ string: Int32) -> Float64 @@ -8193,117 +8875,222 @@ fileprivate func bjs_JsGreeter_prefix_get(_ self: Int32) -> Int32 { @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_name_set") fileprivate func bjs_JsGreeter_name_set(_ self: Int32, _ newValue: Int32) -> Void #else -fileprivate func bjs_JsGreeter_name_set(_ self: Int32, _ newValue: Int32) -> Void { +fileprivate func bjs_JsGreeter_name_set(_ self: Int32, _ newValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_greet") +fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 +#else +fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_changeName") +fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ name: Int32) -> Void +#else +fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ name: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$JsGreeter_init(_ name: String, _ prefix: String) throws(JSException) -> JSObject { + let nameValue = name.bridgeJSLowerParameter() + let prefixValue = prefix.bridgeJSLowerParameter() + let ret = bjs_JsGreeter_init(nameValue, prefixValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$JsGreeter_name_get(_ self: JSObject) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_JsGreeter_name_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + +func _$JsGreeter_prefix_get(_ self: JSObject) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_JsGreeter_prefix_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + +func _$JsGreeter_name_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let newValueValue = newValue.bridgeJSLowerParameter() + bjs_JsGreeter_name_set(selfValue, newValueValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$JsGreeter_greet(_ self: JSObject) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs_JsGreeter_greet(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + +func _$JsGreeter_changeName(_ self: JSObject, _ name: String) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let nameValue = name.bridgeJSLowerParameter() + bjs_JsGreeter_changeName(selfValue, nameValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs__WeirdClass_init") +fileprivate func bjs__WeirdClass_init() -> Int32 +#else +fileprivate func bjs__WeirdClass_init() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs__WeirdClass_method_with_dashes") +fileprivate func bjs__WeirdClass_method_with_dashes(_ self: Int32) -> Int32 +#else +fileprivate func bjs__WeirdClass_method_with_dashes(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$_WeirdClass_init() throws(JSException) -> JSObject { + let ret = bjs__WeirdClass_init() + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$_WeirdClass_method_with_dashes(_ self: JSObject) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let ret = bjs__WeirdClass_method_with_dashes(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_init") +fileprivate func bjs_StaticBox_init(_ value: Float64) -> Int32 +#else +fileprivate func bjs_StaticBox_init(_ value: Float64) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_create_static") +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 +#else +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_value_static") +fileprivate func bjs_StaticBox_value_static() -> Float64 +#else +fileprivate func bjs_StaticBox_value_static() -> Float64 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_makeDefault_static") +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 +#else +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 { fatalError("Only available on WebAssembly") } #endif #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_greet") -fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_with_dashes_static") +fileprivate func bjs_StaticBox_with_dashes_static() -> Int32 #else -fileprivate func bjs_JsGreeter_greet(_ self: Int32) -> Int32 { +fileprivate func bjs_StaticBox_with_dashes_static() -> Int32 { fatalError("Only available on WebAssembly") } #endif #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_JsGreeter_changeName") -fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ name: Int32) -> Void +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_StaticBox_value") +fileprivate func bjs_StaticBox_value(_ self: Int32) -> Float64 #else -fileprivate func bjs_JsGreeter_changeName(_ self: Int32, _ name: Int32) -> Void { +fileprivate func bjs_StaticBox_value(_ self: Int32) -> Float64 { fatalError("Only available on WebAssembly") } #endif -func _$JsGreeter_init(_ name: String, _ prefix: String) throws(JSException) -> JSObject { - let nameValue = name.bridgeJSLowerParameter() - let prefixValue = prefix.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_init(nameValue, prefixValue) +func _$StaticBox_init(_ value: Double) throws(JSException) -> JSObject { + let valueValue = value.bridgeJSLowerParameter() + let ret = bjs_StaticBox_init(valueValue) if let error = _swift_js_take_exception() { throw error } return JSObject.bridgeJSLiftReturn(ret) } -func _$JsGreeter_name_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_name_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$JsGreeter_prefix_get(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_prefix_get(selfValue) - if let error = _swift_js_take_exception() { - throw error - } - return String.bridgeJSLiftReturn(ret) -} - -func _$JsGreeter_name_set(_ self: JSObject, _ newValue: String) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let newValueValue = newValue.bridgeJSLowerParameter() - bjs_JsGreeter_name_set(selfValue, newValueValue) +func _$StaticBox_create(_ value: Double) throws(JSException) -> StaticBox { + let valueValue = value.bridgeJSLowerParameter() + let ret = bjs_StaticBox_create_static(valueValue) if let error = _swift_js_take_exception() { throw error } + return StaticBox.bridgeJSLiftReturn(ret) } -func _$JsGreeter_greet(_ self: JSObject) throws(JSException) -> String { - let selfValue = self.bridgeJSLowerParameter() - let ret = bjs_JsGreeter_greet(selfValue) +func _$StaticBox_value() throws(JSException) -> Double { + let ret = bjs_StaticBox_value_static() if let error = _swift_js_take_exception() { throw error } - return String.bridgeJSLiftReturn(ret) + return Double.bridgeJSLiftReturn(ret) } -func _$JsGreeter_changeName(_ self: JSObject, _ name: String) throws(JSException) -> Void { - let selfValue = self.bridgeJSLowerParameter() - let nameValue = name.bridgeJSLowerParameter() - bjs_JsGreeter_changeName(selfValue, nameValue) +func _$StaticBox_makeDefault() throws(JSException) -> StaticBox { + let ret = bjs_StaticBox_makeDefault_static() if let error = _swift_js_take_exception() { throw error } + return StaticBox.bridgeJSLiftReturn(ret) } -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs__WeirdClass_init") -fileprivate func bjs__WeirdClass_init() -> Int32 -#else -fileprivate func bjs__WeirdClass_init() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs__WeirdClass_method_with_dashes") -fileprivate func bjs__WeirdClass_method_with_dashes(_ self: Int32) -> Int32 -#else -fileprivate func bjs__WeirdClass_method_with_dashes(_ self: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -func _$_WeirdClass_init() throws(JSException) -> JSObject { - let ret = bjs__WeirdClass_init() +func _$StaticBox_with_dashes() throws(JSException) -> StaticBox { + let ret = bjs_StaticBox_with_dashes_static() if let error = _swift_js_take_exception() { throw error } - return JSObject.bridgeJSLiftReturn(ret) + return StaticBox.bridgeJSLiftReturn(ret) } -func _$_WeirdClass_method_with_dashes(_ self: JSObject) throws(JSException) -> String { +func _$StaticBox_value(_ self: JSObject) throws(JSException) -> Double { let selfValue = self.bridgeJSLowerParameter() - let ret = bjs__WeirdClass_method_with_dashes(selfValue) + let ret = bjs_StaticBox_value(selfValue) if let error = _swift_js_take_exception() { throw error } - return String.bridgeJSLiftReturn(ret) + return Double.bridgeJSLiftReturn(ret) } #if arch(wasm32) @@ -8470,6 +9257,209 @@ func _$Animal_getIsCat(_ self: JSObject) throws(JSException) -> Bool { return Bool.bridgeJSLiftReturn(ret) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripIntArray") +fileprivate func bjs_jsRoundTripIntArray() -> Void +#else +fileprivate func bjs_jsRoundTripIntArray() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Int32 +#else +fileprivate func bjs_jsArrayLength() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +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() -> Int32 +#else +fileprivate func bjs_makeArrayHost() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$makeArrayHost(_ numbers: [Int], _ labels: [String]) throws(JSException) -> ArrayHost { + let _ = labels.bridgeJSLowerParameter() + let _ = numbers.bridgeJSLowerParameter() + let ret = bjs_makeArrayHost() + if let error = _swift_js_take_exception() { + throw error + } + return ArrayHost.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_init") +fileprivate func bjs_ArrayHost_init() -> Int32 +#else +fileprivate func bjs_ArrayHost_init() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_numbers_get") +fileprivate func bjs_ArrayHost_numbers_get(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_numbers_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_labels_get") +fileprivate func bjs_ArrayHost_labels_get(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_labels_get(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_numbers_set") +fileprivate func bjs_ArrayHost_numbers_set(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_numbers_set(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_labels_set") +fileprivate func bjs_ArrayHost_labels_set(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_labels_set(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_concatNumbers") +fileprivate func bjs_ArrayHost_concatNumbers(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_concatNumbers(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_concatLabels") +fileprivate func bjs_ArrayHost_concatLabels(_ self: Int32) -> Void +#else +fileprivate func bjs_ArrayHost_concatLabels(_ self: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_ArrayHost_firstLabel") +fileprivate func bjs_ArrayHost_firstLabel(_ self: Int32) -> Int32 +#else +fileprivate func bjs_ArrayHost_firstLabel(_ self: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +func _$ArrayHost_init(_ numbers: [Int], _ labels: [String]) throws(JSException) -> JSObject { + let _ = labels.bridgeJSLowerParameter() + let _ = numbers.bridgeJSLowerParameter() + let ret = bjs_ArrayHost_init() + if let error = _swift_js_take_exception() { + throw error + } + return JSObject.bridgeJSLiftReturn(ret) +} + +func _$ArrayHost_numbers_get(_ self: JSObject) throws(JSException) -> [Int] { + let selfValue = self.bridgeJSLowerParameter() + bjs_ArrayHost_numbers_get(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return [Int].bridgeJSLiftReturn() +} + +func _$ArrayHost_labels_get(_ self: JSObject) throws(JSException) -> [String] { + let selfValue = self.bridgeJSLowerParameter() + bjs_ArrayHost_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 { + let selfValue = self.bridgeJSLowerParameter() + let _ = newValue.bridgeJSLowerParameter() + bjs_ArrayHost_numbers_set(selfValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$ArrayHost_labels_set(_ self: JSObject, _ newValue: [String]) throws(JSException) -> Void { + let selfValue = self.bridgeJSLowerParameter() + let _ = newValue.bridgeJSLowerParameter() + bjs_ArrayHost_labels_set(selfValue) + if let error = _swift_js_take_exception() { + throw error + } +} + +func _$ArrayHost_concatNumbers(_ self: JSObject, _ values: [Int]) throws(JSException) -> [Int] { + let selfValue = self.bridgeJSLowerParameter() + let _ = values.bridgeJSLowerParameter() + bjs_ArrayHost_concatNumbers(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return [Int].bridgeJSLiftReturn() +} + +func _$ArrayHost_concatLabels(_ self: JSObject, _ values: [String]) throws(JSException) -> [String] { + let selfValue = self.bridgeJSLowerParameter() + let _ = values.bridgeJSLowerParameter() + bjs_ArrayHost_concatLabels(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return [String].bridgeJSLiftReturn() +} + +func _$ArrayHost_firstLabel(_ self: JSObject, _ values: [String]) throws(JSException) -> String { + let selfValue = self.bridgeJSLowerParameter() + let _ = values.bridgeJSLowerParameter() + let ret = bjs_ArrayHost_firstLabel(selfValue) + if let error = _swift_js_take_exception() { + throw error + } + return String.bridgeJSLiftReturn(ret) +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsApplyInt") fileprivate func bjs_jsApplyInt(_ value: Int32, _ transform: UnsafeMutableRawPointer) -> Int32 @@ -8581,4 +9571,92 @@ func _$jsTranslatePoint(_ point: Point, _ dx: Int, _ dy: Int) throws(JSException throw error } return Point.bridgeJSLiftReturn(ret) +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_runJsOptionalSupportTests") +fileprivate func bjs_runJsOptionalSupportTests() -> Void +#else +fileprivate func bjs_runJsOptionalSupportTests() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$runJsOptionalSupportTests() throws(JSException) -> Void { + bjs_runJsOptionalSupportTests() + if let error = _swift_js_take_exception() { + throw error + } +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberNull") +fileprivate func bjs_jsRoundTripOptionalNumberNull(_ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalNumberNull(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalNumberNull(_ value: Optional) throws(JSException) -> Optional { + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalNumberNull(valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberUndefined") +fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ valueIsSome: Int32, _ valueValue: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalNumberUndefined(_ value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let (valueIsSome, valueValue) = value.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalNumberUndefined(valueIsSome, valueValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalStringNull") +fileprivate func bjs_jsRoundTripOptionalStringNull(_ nameIsSome: Int32, _ nameValue: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalStringNull(_ nameIsSome: Int32, _ nameValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalStringNull(_ name: Optional) throws(JSException) -> Optional { + let (nameIsSome, nameValue) = name.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalStringNull(nameIsSome, nameValue) + if let error = _swift_js_take_exception() { + throw error + } + return Optional.bridgeJSLiftReturnFromSideChannel() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalStringUndefined") +fileprivate func bjs_jsRoundTripOptionalStringUndefined(_ nameIsSome: Int32, _ nameValue: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalStringUndefined(_ nameIsSome: Int32, _ nameValue: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalStringUndefined(_ name: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let (nameIsSome, nameValue) = name.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalStringUndefined(nameIsSome, nameValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() } \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index c79139ea4..10ca73fe8 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -525,80 +525,6 @@ ], "swiftCallName" : "Internal.TestServer" }, - { - "constructor" : { - "abiName" : "bjs_OptionalPropertyHolder_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "optionalName", - "name" : "optionalName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "OptionalPropertyHolder", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalName", - "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalAge", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "optionalGreeter", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - } - } - ], - "swiftCallName" : "OptionalPropertyHolder" - }, { "constructor" : { "abiName" : "bjs_SimplePropertyHolder_init", @@ -1057,12 +983,13 @@ "label" : "tag", "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1134,12 +1061,13 @@ "isStatic" : false, "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1293,12 +1221,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -1312,12 +1241,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1499,12 +1429,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1537,12 +1468,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -1559,12 +1491,13 @@ "label" : "_", "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1587,12 +1520,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1609,12 +1543,13 @@ "label" : "_", "name" : "count", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1637,12 +1572,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -1659,12 +1595,13 @@ "label" : "_", "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -1687,13 +1624,14 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -1710,13 +1648,14 @@ "label" : "_", "name" : "theme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } } @@ -1739,13 +1678,14 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -1762,13 +1702,14 @@ "label" : "_", "name" : "status", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } } @@ -1791,12 +1732,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -1813,12 +1755,13 @@ "label" : "_", "name" : "apiResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -1847,12 +1790,13 @@ "isStatic" : false, "name" : "backupProcessor", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftProtocol" : { "_0" : "DataProcessor" } - } + }, + "_1" : "null" } } } @@ -2037,12 +1981,13 @@ "label" : "_", "name" : "greeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -2065,12 +2010,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -2087,12 +2033,13 @@ "label" : "_", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -2115,12 +2062,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -2152,12 +2100,13 @@ "isStatic" : false, "name" : "optionalTag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -2166,12 +2115,13 @@ "isStatic" : false, "name" : "optionalCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -2180,12 +2130,13 @@ "isStatic" : false, "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -2194,13 +2145,14 @@ "isStatic" : false, "name" : "optionalTheme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -2209,13 +2161,14 @@ "isStatic" : false, "name" : "httpStatus", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -2224,12 +2177,13 @@ "isStatic" : false, "name" : "apiResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -2248,12 +2202,13 @@ "isStatic" : false, "name" : "optionalHelper", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -2439,12 +2394,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } ], @@ -2485,12 +2441,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } ], @@ -2531,12 +2488,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } ], @@ -2576,12 +2534,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } ], @@ -2616,12 +2575,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -2957,12 +2917,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], @@ -3003,13 +2964,14 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } ], @@ -3050,12 +3012,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } ], @@ -3095,12 +3058,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], @@ -3122,7 +3086,7 @@ }, { "constructor" : { - "abiName" : "bjs_Container_init", + "abiName" : "bjs_OptionalHolder_init", "effects" : { "isAsync" : false, "isStatic" : false, @@ -3130,24 +3094,30 @@ }, "parameters" : [ { - "label" : "location", - "name" : "location", + "label" : "nullableGreeter", + "name" : "nullableGreeter", "type" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } }, { - "label" : "config", - "name" : "config", + "label" : "undefinedNumber", + "name" : "undefinedNumber", "type" : { - "optional" : { + "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "Config" + "double" : { + } - } + }, + "_1" : "undefined" } } } @@ -3156,84 +3126,235 @@ "methods" : [ ], - "name" : "Container", + "name" : "OptionalHolder", "properties" : [ { "isReadonly" : false, "isStatic" : false, - "name" : "location", + "name" : "nullableGreeter", "type" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } }, { "isReadonly" : false, "isStatic" : false, - "name" : "config", + "name" : "undefinedNumber", "type" : { - "optional" : { + "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "Config" + "double" : { + } - } + }, + "_1" : "undefined" } } } ], - "swiftCallName" : "Container" - } - ], - "enums" : [ + "swiftCallName" : "OptionalHolder" + }, { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "north" + "constructor" : { + "abiName" : "bjs_OptionalPropertyHolder_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false }, + "parameters" : [ + { + "label" : "optionalName", + "name" : "optionalName", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "OptionalPropertyHolder", + "properties" : [ { - "associatedValues" : [ + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalName", + "type" : { + "nullable" : { + "_0" : { + "string" : { - ], - "name" : "south" + } + }, + "_1" : "null" + } + } }, { - "associatedValues" : [ + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalAge", + "type" : { + "nullable" : { + "_0" : { + "int" : { - ], - "name" : "east" + } + }, + "_1" : "null" + } + } }, { - "associatedValues" : [ - - ], - "name" : "west" + "isReadonly" : false, + "isStatic" : false, + "name" : "optionalGreeter", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } } ], - "emitStyle" : "const", - "name" : "Direction", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "Direction", - "tsFullPath" : "Direction" + "swiftCallName" : "OptionalPropertyHolder" }, { - "cases" : [ - { - "associatedValues" : [ - - ], - "name" : "loading" - }, - { + "constructor" : { + "abiName" : "bjs_Container_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "location", + "name" : "location", + "type" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + }, + { + "label" : "config", + "name" : "config", + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "Container", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "location", + "type" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "config", + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Config" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "Container" + } + ], + "enums" : [ + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "north" + }, + { + "associatedValues" : [ + + ], + "name" : "south" + }, + { + "associatedValues" : [ + + ], + "name" : "east" + }, + { + "associatedValues" : [ + + ], + "name" : "west" + } + ], + "emitStyle" : "const", + "name" : "Direction", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Direction", + "tsFullPath" : "Direction" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "loading" + }, + { "associatedValues" : [ ], @@ -3500,6 +3621,91 @@ { "cases" : [ + ], + "emitStyle" : "const", + "name" : "StringUtils", + "namespace" : [ + "Utils" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Utils_StringUtils_static_uppercase", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "uppercase", + "namespace" : [ + "Utils", + "StringUtils" + ], + "parameters" : [ + { + "label" : "_", + "name" : "text", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "Utils.StringUtils" + } + } + }, + { + "abiName" : "bjs_Utils_StringUtils_static_lowercase", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "lowercase", + "namespace" : [ + "Utils", + "StringUtils" + ], + "parameters" : [ + { + "label" : "_", + "name" : "text", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "Utils.StringUtils" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "Utils.StringUtils", + "tsFullPath" : "Utils.StringUtils" + }, + { + "cases" : [ + ], "emitStyle" : "const", "name" : "Networking", @@ -4157,61 +4363,55 @@ "associatedValues" : [ { "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "swiftStruct" : { + "_0" : "Address" } } } ], - "name" : "success" + "name" : "structPayload" }, { "associatedValues" : [ { "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } + "swiftHeapObject" : { + "_0" : "Greeter" } } - }, + } + ], + "name" : "classPayload" + }, + { + "associatedValues" : [ { "type" : { - "optional" : { - "_0" : { - "bool" : { + "jsObject" : { - } - } } } } ], - "name" : "failure" + "name" : "jsObjectPayload" }, { "associatedValues" : [ { "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } + "associatedValueEnum" : { + "_0" : "APIResult" } } - }, + } + ], + "name" : "nestedEnum" + }, + { + "associatedValues" : [ { "type" : { - "optional" : { + "array" : { "_0" : { "int" : { @@ -4219,44 +4419,131 @@ } } } - }, + } + ], + "name" : "arrayPayload" + }, + { + "associatedValues" : [ { "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "jsObject" : { + "_0" : "Foo" } } } ], - "name" : "status" + "name" : "jsClassPayload" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" } ], "emitStyle" : "const", - "name" : "APIOptionalResult", + "name" : "AllTypesResult", "staticMethods" : [ ], "staticProperties" : [ ], - "swiftCallName" : "APIOptionalResult", - "tsFullPath" : "APIOptionalResult" + "swiftCallName" : "AllTypesResult", + "tsFullPath" : "AllTypesResult" }, { "cases" : [ { "associatedValues" : [ - + { + "type" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + } ], - "name" : "scientific" + "name" : "precision" }, { "associatedValues" : [ - + { + "type" : { + "caseEnum" : { + "_0" : "Direction" + } + } + } + ], + "name" : "direction" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optPrecision" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optDirection" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" + } + ], + "emitStyle" : "const", + "name" : "TypedPayloadResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "TypedPayloadResult", + "tsFullPath" : "TypedPayloadResult" + }, + { + "cases" : [ + { + "associatedValues" : [ + + ], + "name" : "scientific" + }, + { + "associatedValues" : [ + ], "name" : "basic" } @@ -4356,7 +4643,7 @@ }, "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticUtils.Nested" } } } @@ -4367,6 +4654,94 @@ "swiftCallName" : "StaticUtils.Nested", "tsFullPath" : "StaticUtils.Nested" }, + { + "cases" : [ + + ], + "emitStyle" : "const", + "name" : "GraphOperations", + "namespace" : [ + "Services", + "Graph" + ], + "staticMethods" : [ + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_createGraph", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "createGraph", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "rootId", + "name" : "rootId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + }, + { + "abiName" : "bjs_Services_Graph_GraphOperations_static_nodeCount", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "nodeCount", + "namespace" : [ + "Services", + "Graph", + "GraphOperations" + ], + "parameters" : [ + { + "label" : "graphId", + "name" : "graphId", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + }, + "staticContext" : { + "namespaceEnum" : { + "_0" : "GraphOperations" + } + } + } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "GraphOperations", + "tsFullPath" : "Services.Graph.GraphOperations" + }, { "cases" : [ { @@ -4501,7 +4876,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace" } }, "type" : { @@ -4519,7 +4894,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace" } }, "type" : { @@ -4555,7 +4930,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -4574,7 +4949,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -4593,7 +4968,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -4605,55 +4980,282 @@ ], "swiftCallName" : "StaticPropertyNamespace.NestedProperties", "tsFullPath" : "StaticPropertyNamespace.NestedProperties" - } - ], - "exposeToGlobal" : false, - "functions" : [ - { - "abiName" : "bjs_roundTripVoid", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripVoid", - "parameters" : [ - - ], - "returnType" : { - "void" : { - - } - } }, { - "abiName" : "bjs_roundTripInt", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripInt", - "parameters" : [ + "cases" : [ { - "label" : "v", - "name" : "v", - "type" : { - "int" : { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "Address" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optStruct" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optClass" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + } + }, + "_1" : "null" + } + } } - } + ], + "name" : "optJSObject" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optNestedEnum" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optArray" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "optJsClass" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" } ], - "returnType" : { - "int" : { + "emitStyle" : "const", + "name" : "OptionalAllTypesResult", + "staticMethods" : [ - } - } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "OptionalAllTypesResult", + "tsFullPath" : "OptionalAllTypesResult" }, { - "abiName" : "bjs_roundTripUInt", - "effects" : { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "success" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "failure" + }, + { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "status" + } + ], + "emitStyle" : "const", + "name" : "APIOptionalResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "APIOptionalResult", + "tsFullPath" : "APIOptionalResult" + } + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_roundTripVoid", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripVoid", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_roundTripInt", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripInt", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_roundTripUInt", + "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false @@ -4975,6 +5577,142 @@ } } }, + { + "abiName" : "bjs_roundTripJSValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSValue", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + + } + } + }, + { + "abiName" : "bjs_roundTripOptionalJSValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalJSValue", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "jsValue" : { + + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripJSValueArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSValueArray", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + }, + { + "abiName" : "bjs_roundTripOptionalJSValueArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalJSValueArray", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + }, { "abiName" : "bjs_makeImportedFoo", "effects" : { @@ -6597,602 +7335,572 @@ } }, { - "abiName" : "bjs_roundTripOptionalString", + "abiName" : "bjs_roundTripAllTypesResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalString", + "name" : "roundTripAllTypesResult", "parameters" : [ { - "label" : "name", - "name" : "name", + "label" : "_", + "name" : "result", "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "associatedValueEnum" : { + "_0" : "AllTypesResult" } } } ], "returnType" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "associatedValueEnum" : { + "_0" : "AllTypesResult" } } }, { - "abiName" : "bjs_roundTripOptionalInt", + "abiName" : "bjs_roundTripTypedPayloadResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalInt", + "name" : "roundTripTypedPayloadResult", "parameters" : [ { - "label" : "value", - "name" : "value", + "label" : "_", + "name" : "result", "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" } } } ], "returnType" : { - "optional" : { - "_0" : { - "int" : { - - } - } + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" } } }, { - "abiName" : "bjs_roundTripOptionalBool", + "abiName" : "bjs_createPropertyHolder", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalBool", + "name" : "createPropertyHolder", "parameters" : [ { - "label" : "flag", - "name" : "flag", + "label" : "intValue", + "name" : "intValue", "type" : { - "optional" : { - "_0" : { - "bool" : { + "int" : { - } - } } } - } - ], - "returnType" : { - "optional" : { - "_0" : { + }, + { + "label" : "floatValue", + "name" : "floatValue", + "type" : { + "float" : { + + } + } + }, + { + "label" : "doubleValue", + "name" : "doubleValue", + "type" : { + "double" : { + + } + } + }, + { + "label" : "boolValue", + "name" : "boolValue", + "type" : { "bool" : { } } - } - } - }, - { - "abiName" : "bjs_roundTripOptionalFloat", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalFloat", - "parameters" : [ + }, { - "label" : "number", - "name" : "number", + "label" : "stringValue", + "name" : "stringValue", "type" : { - "optional" : { - "_0" : { - "float" : { + "string" : { - } - } } } - } - ], - "returnType" : { - "optional" : { - "_0" : { - "float" : { + }, + { + "label" : "jsObject", + "name" : "jsObject", + "type" : { + "jsObject" : { } } } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "PropertyHolder" + } } }, { - "abiName" : "bjs_roundTripOptionalDouble", + "abiName" : "bjs_testPropertyHolder", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalDouble", + "name" : "testPropertyHolder", "parameters" : [ { - "label" : "precision", - "name" : "precision", + "label" : "holder", + "name" : "holder", "type" : { - "optional" : { - "_0" : { - "double" : { - - } - } + "swiftHeapObject" : { + "_0" : "PropertyHolder" } } } ], "returnType" : { - "optional" : { - "_0" : { - "double" : { + "string" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalSyntax", + "abiName" : "bjs_resetObserverCounts", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalSyntax", + "name" : "resetObserverCounts", "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - } - } - } - } - } ], "returnType" : { - "optional" : { - "_0" : { - "string" : { + "void" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalMixSyntax", + "abiName" : "bjs_getObserverStats", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalMixSyntax", + "name" : "getObserverStats", "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "optional" : { - "_0" : { - "string" : { - } - } - } - } - } ], "returnType" : { - "optional" : { - "_0" : { - "string" : { + "string" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalSwiftSyntax", + "abiName" : "bjs_testStringDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalSwiftSyntax", + "name" : "testStringDefault", "parameters" : [ { - "label" : "name", - "name" : "name", + "defaultValue" : { + "string" : { + "_0" : "Hello World" + } + }, + "label" : "message", + "name" : "message", "type" : { - "optional" : { - "_0" : { - "string" : { + "string" : { - } - } } } } ], "returnType" : { - "optional" : { - "_0" : { - "string" : { + "string" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalWithSpaces", + "abiName" : "bjs_testIntDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalWithSpaces", + "name" : "testIntDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "int" : { + "_0" : 42 + } + }, + "label" : "count", + "name" : "count", "type" : { - "optional" : { - "_0" : { - "double" : { + "int" : { - } - } } } } ], "returnType" : { - "optional" : { - "_0" : { - "double" : { + "int" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalTypeAlias", + "abiName" : "bjs_testBoolDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTypeAlias", + "name" : "testBoolDefault", "parameters" : [ { - "label" : "age", - "name" : "age", + "defaultValue" : { + "bool" : { + "_0" : true + } + }, + "label" : "flag", + "name" : "flag", "type" : { - "optional" : { - "_0" : { - "int" : { + "bool" : { - } - } } } } ], "returnType" : { - "optional" : { - "_0" : { - "int" : { + "bool" : { - } - } } } }, { - "abiName" : "bjs_roundTripOptionalStatus", + "abiName" : "bjs_testOptionalDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStatus", + "name" : "testOptionalDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "null" : { + + } + }, + "label" : "name", + "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalTheme", + "abiName" : "bjs_testMultipleDefaults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTheme", + "name" : "testMultipleDefaults", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "string" : { + "_0" : "Default Title" + } + }, + "label" : "title", + "name" : "title", "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } + "string" : { + + } + } + }, + { + "defaultValue" : { + "int" : { + "_0" : -10 + } + }, + "label" : "count", + "name" : "count", + "type" : { + "int" : { + + } + } + }, + { + "defaultValue" : { + "bool" : { + "_0" : false + } + }, + "label" : "enabled", + "name" : "enabled", + "type" : { + "bool" : { + } } } ], "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } + "string" : { + } } }, { - "abiName" : "bjs_roundTripOptionalHttpStatus", + "abiName" : "bjs_testSimpleEnumDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalHttpStatus", + "name" : "testSimpleEnumDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "enumCase" : { + "_0" : "Status", + "_1" : "success" + } + }, + "label" : "status", + "name" : "status", "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } + "caseEnum" : { + "_0" : "Status" } } } ], "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" - } - } + "caseEnum" : { + "_0" : "Status" } } }, { - "abiName" : "bjs_roundTripOptionalTSDirection", + "abiName" : "bjs_testDirectionDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTSDirection", + "name" : "testDirectionDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "enumCase" : { + "_0" : "Direction", + "_1" : "north" + } + }, + "label" : "direction", + "name" : "direction", "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } + "caseEnum" : { + "_0" : "Direction" } } } ], "returnType" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" - } - } + "caseEnum" : { + "_0" : "Direction" } } }, { - "abiName" : "bjs_roundTripOptionalTSTheme", + "abiName" : "bjs_testRawStringEnumDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTSTheme", + "name" : "testRawStringEnumDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "enumCase" : { + "_0" : "Theme", + "_1" : "light" + } + }, + "label" : "theme", + "name" : "theme", "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } } ], "returnType" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - } + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } }, { - "abiName" : "bjs_roundTripOptionalNetworkingAPIMethod", + "abiName" : "bjs_testComplexInit", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalNetworkingAPIMethod", + "name" : "testComplexInit", "parameters" : [ { - "label" : "_", - "name" : "method", - "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Networking.API.Method" + "defaultValue" : { + "objectWithArguments" : { + "_0" : "Greeter", + "_1" : [ + { + "string" : { + "_0" : "DefaultGreeter" + } } - } + ] + } + }, + "label" : "greeter", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" } } } ], "returnType" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Networking.API.Method" - } - } + "string" : { + } } }, { - "abiName" : "bjs_roundTripOptionalAPIResult", + "abiName" : "bjs_testEmptyInit", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalAPIResult", + "name" : "testEmptyInit", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "object" : { + "_0" : "StaticPropertyHolder" + } + }, + "label" : "_", + "name" : "object", "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } + "swiftHeapObject" : { + "_0" : "StaticPropertyHolder" } } } ], "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } + "swiftHeapObject" : { + "_0" : "StaticPropertyHolder" } } }, { - "abiName" : "bjs_compareAPIResults", + "abiName" : "bjs_arrayWithDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "compareAPIResults", + "name" : "arrayWithDefault", "parameters" : [ { - "label" : "_", - "name" : "r1", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 1 + } + }, + { + "int" : { + "_0" : 2 + } + }, + { + "int" : { + "_0" : 3 + } } - } + ] } - } - }, - { + }, "label" : "_", - "name" : "r2", + "name" : "values", "type" : { - "optional" : { + "array" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "int" : { + } } } @@ -7200,94 +7908,162 @@ } ], "returnType" : { - "string" : { + "int" : { } } }, { - "abiName" : "bjs_roundTripOptionalComplexResult", + "abiName" : "bjs_arrayWithOptionalDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalComplexResult", + "name" : "arrayWithOptionalDefault", "parameters" : [ { - "label" : "_", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" + "defaultValue" : { + "null" : { + + } + }, + "label" : "_", + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - } + "int" : { + } } }, { - "abiName" : "bjs_roundTripOptionalClass", + "abiName" : "bjs_arrayMixedDefaults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalClass", + "name" : "arrayMixedDefaults", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "string" : { + "_0" : "Sum" + } + }, + "label" : "prefix", + "name" : "prefix", + "type" : { + "string" : { + + } + } + }, + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 10 + } + }, + { + "int" : { + "_0" : 20 + } + } + ] + } + }, + "label" : "values", + "name" : "values", "type" : { - "optional" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "int" : { + } } } } + }, + { + "defaultValue" : { + "string" : { + "_0" : "!" + } + }, + "label" : "suffix", + "name" : "suffix", + "type" : { + "string" : { + + } + } } ], "returnType" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "string" : { + } } }, { - "abiName" : "bjs_roundTripOptionalAPIOptionalResult", + "abiName" : "bjs_formatName", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalAPIOptionalResult", + "name" : "formatName", "parameters" : [ { - "label" : "result", - "name" : "result", + "label" : "_", + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "label" : "transform", + "name" : "transform", "type" : { - "optional" : { + "closure" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSS_SS", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } } } } @@ -7295,256 +8071,311 @@ } ], "returnType" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" - } - } + "string" : { + } } }, { - "abiName" : "bjs_createPropertyHolder", + "abiName" : "bjs_makeFormatter", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "createPropertyHolder", + "name" : "makeFormatter", "parameters" : [ { - "label" : "intValue", - "name" : "intValue", + "label" : "prefix", + "name" : "prefix", "type" : { - "int" : { + "string" : { } } - }, - { - "label" : "floatValue", - "name" : "floatValue", - "type" : { - "float" : { + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSS_SS", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "string" : { - } - } - }, - { - "label" : "doubleValue", - "name" : "doubleValue", - "type" : { - "double" : { + } + } + ], + "returnType" : { + "string" : { + } } } - }, + } + } + }, + { + "abiName" : "bjs_makeAdder", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeAdder", + "parameters" : [ { - "label" : "boolValue", - "name" : "boolValue", + "label" : "base", + "name" : "base", "type" : { - "bool" : { + "int" : { } } - }, - { - "label" : "stringValue", - "name" : "stringValue", - "type" : { - "string" : { + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSi_Si", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "int" : { - } - } - }, - { - "label" : "jsObject", - "name" : "jsObject", - "type" : { - "jsObject" : { + } + } + ], + "returnType" : { + "int" : { + } } } } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" - } } }, { - "abiName" : "bjs_testPropertyHolder", + "abiName" : "bjs_roundTripIntArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testPropertyHolder", + "name" : "roundTripIntArray", "parameters" : [ { - "label" : "holder", - "name" : "holder", + "label" : "_", + "name" : "values", "type" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" + "array" : { + "_0" : { + "int" : { + + } + } } } } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "int" : { + } + } } } }, { - "abiName" : "bjs_resetObserverCounts", + "abiName" : "bjs_roundTripStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "resetObserverCounts", + "name" : "roundTripStringArray", "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + } + } + } + } + } ], "returnType" : { - "void" : { + "array" : { + "_0" : { + "string" : { + } + } } } }, { - "abiName" : "bjs_getObserverStats", + "abiName" : "bjs_roundTripDoubleArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "getObserverStats", + "name" : "roundTripDoubleArray", "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + } + } + } + } + } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "double" : { + } + } } } }, { - "abiName" : "bjs_testStringDefault", + "abiName" : "bjs_roundTripBoolArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testStringDefault", + "name" : "roundTripBoolArray", "parameters" : [ { - "defaultValue" : { - "string" : { - "_0" : "Hello World" - } - }, - "label" : "message", - "name" : "message", + "label" : "_", + "name" : "values", "type" : { - "string" : { + "array" : { + "_0" : { + "bool" : { + } + } } } } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "bool" : { + } + } } } }, { - "abiName" : "bjs_testIntDefault", + "abiName" : "bjs_roundTripDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testIntDefault", + "name" : "roundTripDirectionArray", "parameters" : [ { - "defaultValue" : { - "int" : { - "_0" : 42 - } - }, - "label" : "count", - "name" : "count", + "label" : "_", + "name" : "values", "type" : { - "int" : { - + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } } } } ], "returnType" : { - "int" : { - + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } } } }, { - "abiName" : "bjs_testBoolDefault", + "abiName" : "bjs_roundTripStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testBoolDefault", + "name" : "roundTripStatusArray", "parameters" : [ { - "defaultValue" : { - "bool" : { - "_0" : true - } - }, - "label" : "flag", - "name" : "flag", + "label" : "_", + "name" : "values", "type" : { - "bool" : { - + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + } } } } ], "returnType" : { - "bool" : { - + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + } } } }, { - "abiName" : "bjs_testOptionalDefault", + "abiName" : "bjs_roundTripThemeArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testOptionalDefault", + "name" : "roundTripThemeArray", "parameters" : [ { - "defaultValue" : { - "null" : { - - } - }, - "label" : "name", - "name" : "name", + "label" : "_", + "name" : "values", "type" : { - "optional" : { + "array" : { "_0" : { - "string" : { - + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } } @@ -7552,273 +8383,268 @@ } ], "returnType" : { - "optional" : { + "array" : { "_0" : { - "string" : { - + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } } } }, { - "abiName" : "bjs_testMultipleDefaults", + "abiName" : "bjs_roundTripHttpStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testMultipleDefaults", + "name" : "roundTripHttpStatusArray", "parameters" : [ { - "defaultValue" : { - "string" : { - "_0" : "Default Title" - } - }, - "label" : "title", - "name" : "title", - "type" : { - "string" : { - - } - } - }, - { - "defaultValue" : { - "int" : { - "_0" : -10 - } - }, - "label" : "count", - "name" : "count", - "type" : { - "int" : { - - } - } - }, - { - "defaultValue" : { - "bool" : { - "_0" : false - } - }, - "label" : "enabled", - "name" : "enabled", + "label" : "_", + "name" : "values", "type" : { - "bool" : { - + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } } } } ], "returnType" : { - "string" : { - + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } } } }, { - "abiName" : "bjs_testSimpleEnumDefault", + "abiName" : "bjs_roundTripDataPointArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testSimpleEnumDefault", + "name" : "roundTripDataPointArray", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Status", - "_1" : "success" - } - }, - "label" : "status", - "name" : "status", + "label" : "_", + "name" : "points", "type" : { - "caseEnum" : { - "_0" : "Status" + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } } ], "returnType" : { - "caseEnum" : { - "_0" : "Status" + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } }, { - "abiName" : "bjs_testDirectionDefault", + "abiName" : "bjs_roundTripGreeterArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testDirectionDefault", + "name" : "roundTripGreeterArray", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Direction", - "_1" : "north" - } - }, - "label" : "direction", - "name" : "direction", + "label" : "_", + "name" : "greeters", "type" : { - "caseEnum" : { - "_0" : "Direction" - } - } - } + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + } ], "returnType" : { - "caseEnum" : { - "_0" : "Direction" + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } } } }, { - "abiName" : "bjs_testRawStringEnumDefault", + "abiName" : "bjs_roundTripOptionalIntArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testRawStringEnumDefault", + "name" : "roundTripOptionalIntArray", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Theme", - "_1" : "light" - } - }, - "label" : "theme", - "name" : "theme", + "label" : "_", + "name" : "values", "type" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testComplexInit", + "abiName" : "bjs_roundTripOptionalStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testComplexInit", + "name" : "roundTripOptionalStringArray", "parameters" : [ { - "defaultValue" : { - "objectWithArguments" : { - "_0" : "Greeter", - "_1" : [ - { - "string" : { - "_0" : "DefaultGreeter" - } - } - ] - } - }, - "label" : "greeter", - "name" : "greeter", + "label" : "_", + "name" : "values", "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testEmptyInit", + "abiName" : "bjs_roundTripOptionalDataPointArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testEmptyInit", + "name" : "roundTripOptionalDataPointArray", "parameters" : [ { - "defaultValue" : { - "object" : { - "_0" : "StaticPropertyHolder" - } - }, "label" : "_", - "name" : "object", + "name" : "points", "type" : { - "swiftHeapObject" : { - "_0" : "StaticPropertyHolder" + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "swiftHeapObject" : { - "_0" : "StaticPropertyHolder" + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_arrayWithDefault", + "abiName" : "bjs_roundTripOptionalDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayWithDefault", + "name" : "roundTripOptionalDirectionArray", "parameters" : [ { - "defaultValue" : { - "array" : { - "_0" : [ - { - "int" : { - "_0" : 1 - } - }, - { - "int" : { - "_0" : 2 - } - }, - { - "int" : { - "_0" : 3 - } - } - ] - } - }, "label" : "_", - "name" : "values", + "name" : "directions", "type" : { "array" : { "_0" : { - "int" : { - + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" } } } @@ -7826,37 +8652,42 @@ } ], "returnType" : { - "int" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_arrayWithOptionalDefault", + "abiName" : "bjs_roundTripOptionalStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayWithOptionalDefault", + "name" : "roundTripOptionalStatusArray", "parameters" : [ { - "defaultValue" : { - "null" : { - - } - }, "label" : "_", - "name" : "values", + "name" : "statuses", "type" : { - "optional" : { + "array" : { "_0" : { - "array" : { + "nullable" : { "_0" : { - "int" : { - + "caseEnum" : { + "_0" : "Status" } - } + }, + "_1" : "null" } } } @@ -7864,54 +8695,51 @@ } ], "returnType" : { - "int" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_arrayMixedDefaults", + "abiName" : "bjs_roundTripOptionalIntArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayMixedDefaults", + "name" : "roundTripOptionalIntArrayType", "parameters" : [ { - "defaultValue" : { - "string" : { - "_0" : "Sum" - } - }, - "label" : "prefix", - "name" : "prefix", + "label" : "_", + "name" : "values", "type" : { - "string" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { - } - } - }, - { - "defaultValue" : { - "array" : { - "_0" : [ - { - "int" : { - "_0" : 10 - } - }, - { - "int" : { - "_0" : 20 + } } } - ] + }, + "_1" : "null" } - }, - "label" : "values", - "name" : "values", - "type" : { + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { "array" : { "_0" : { "int" : { @@ -7919,172 +8747,146 @@ } } } - } - }, - { - "defaultValue" : { - "string" : { - "_0" : "!" - } }, - "label" : "suffix", - "name" : "suffix", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - + "_1" : "null" } } }, { - "abiName" : "bjs_formatName", + "abiName" : "bjs_roundTripOptionalStringArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "formatName", + "name" : "roundTripOptionalStringArrayType", "parameters" : [ { "label" : "_", - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "label" : "transform", - "name" : "transform", + "name" : "values", "type" : { - "closure" : { + "nullable" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSS_SS", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { + "array" : { + "_0" : { "string" : { } } - ], - "returnType" : { - "string" : { - - } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "string" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + } + } + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_makeFormatter", + "abiName" : "bjs_roundTripOptionalGreeterArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "makeFormatter", + "name" : "roundTripOptionalGreeterArrayType", "parameters" : [ { - "label" : "prefix", - "name" : "prefix", + "label" : "_", + "name" : "greeters", "type" : { - "string" : { - + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + }, + "_1" : "null" } } } ], "returnType" : { - "closure" : { + "nullable" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSS_SS", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { - "string" : { - + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" } } - ], - "returnType" : { - "string" : { - - } } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_makeAdder", + "abiName" : "bjs_roundTripNestedIntArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "makeAdder", + "name" : "roundTripNestedIntArray", "parameters" : [ { - "label" : "base", - "name" : "base", + "label" : "_", + "name" : "values", "type" : { - "int" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + } + } + } + } } } } ], "returnType" : { - "closure" : { + "array" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSi_Si", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { + "array" : { + "_0" : { "int" : { } } - ], - "returnType" : { - "int" : { - - } } } } } }, { - "abiName" : "bjs_roundTripIntArray", + "abiName" : "bjs_roundTripNestedStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripIntArray", + "name" : "roundTripNestedStringArray", "parameters" : [ { "label" : "_", @@ -8092,8 +8894,12 @@ "type" : { "array" : { "_0" : { - "int" : { + "array" : { + "_0" : { + "string" : { + } + } } } } @@ -8103,21 +8909,25 @@ "returnType" : { "array" : { "_0" : { - "int" : { + "array" : { + "_0" : { + "string" : { + } + } } } } } }, { - "abiName" : "bjs_roundTripStringArray", + "abiName" : "bjs_roundTripNestedDoubleArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripStringArray", + "name" : "roundTripNestedDoubleArray", "parameters" : [ { "label" : "_", @@ -8125,8 +8935,12 @@ "type" : { "array" : { "_0" : { - "string" : { + "array" : { + "_0" : { + "double" : { + } + } } } } @@ -8136,21 +8950,25 @@ "returnType" : { "array" : { "_0" : { - "string" : { + "array" : { + "_0" : { + "double" : { + } + } } } } } }, { - "abiName" : "bjs_roundTripDoubleArray", + "abiName" : "bjs_roundTripNestedBoolArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDoubleArray", + "name" : "roundTripNestedBoolArray", "parameters" : [ { "label" : "_", @@ -8158,8 +8976,12 @@ "type" : { "array" : { "_0" : { - "double" : { + "array" : { + "_0" : { + "bool" : { + } + } } } } @@ -8169,30 +8991,38 @@ "returnType" : { "array" : { "_0" : { - "double" : { + "array" : { + "_0" : { + "bool" : { + } + } } } } } }, { - "abiName" : "bjs_roundTripBoolArray", + "abiName" : "bjs_roundTripNestedDataPointArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripBoolArray", + "name" : "roundTripNestedDataPointArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "points", "type" : { "array" : { "_0" : { - "bool" : { - + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } } @@ -8202,30 +9032,38 @@ "returnType" : { "array" : { "_0" : { - "bool" : { - + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } } } }, { - "abiName" : "bjs_roundTripDirectionArray", + "abiName" : "bjs_roundTripNestedDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDirectionArray", + "name" : "roundTripNestedDirectionArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "directions", "type" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } } } } @@ -8235,30 +9073,38 @@ "returnType" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + } } } } } }, { - "abiName" : "bjs_roundTripStatusArray", + "abiName" : "bjs_roundTripNestedGreeterArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripStatusArray", + "name" : "roundTripNestedGreeterArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "greeters", "type" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } } } } @@ -8268,21 +9114,25 @@ "returnType" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } } } } } }, { - "abiName" : "bjs_roundTripThemeArray", + "abiName" : "bjs_roundTripUnsafeRawPointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripThemeArray", + "name" : "roundTripUnsafeRawPointerArray", "parameters" : [ { "label" : "_", @@ -8290,9 +9140,10 @@ "type" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } } } } @@ -8302,22 +9153,23 @@ "returnType" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } } } } } }, { - "abiName" : "bjs_roundTripHttpStatusArray", + "abiName" : "bjs_roundTripUnsafeMutableRawPointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripHttpStatusArray", + "name" : "roundTripUnsafeMutableRawPointerArray", "parameters" : [ { "label" : "_", @@ -8325,9 +9177,10 @@ "type" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } } } } @@ -8337,31 +9190,34 @@ "returnType" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } } } } } }, { - "abiName" : "bjs_roundTripDataPointArray", + "abiName" : "bjs_roundTripOpaquePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDataPointArray", + "name" : "roundTripOpaquePointerArray", "parameters" : [ { "label" : "_", - "name" : "points", + "name" : "values", "type" : { "array" : { "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } } } } @@ -8371,30 +9227,35 @@ "returnType" : { "array" : { "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } } } } } }, { - "abiName" : "bjs_roundTripGreeterArray", + "abiName" : "bjs_roundTripUnsafePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripGreeterArray", + "name" : "roundTripUnsafePointerArray", "parameters" : [ { "label" : "_", - "name" : "greeters", + "name" : "values", "type" : { "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } } } } @@ -8404,21 +9265,24 @@ "returnType" : { "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } } } } } }, { - "abiName" : "bjs_roundTripOptionalIntArray", + "abiName" : "bjs_roundTripUnsafeMutablePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalIntArray", + "name" : "roundTripUnsafeMutablePointerArray", "parameters" : [ { "label" : "_", @@ -8426,11 +9290,10 @@ "type" : { "array" : { "_0" : { - "optional" : { + "unsafePointer" : { "_0" : { - "int" : { - - } + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" } } } @@ -8441,11 +9304,10 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "unsafePointer" : { "_0" : { - "int" : { - - } + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" } } } @@ -8453,26 +9315,22 @@ } }, { - "abiName" : "bjs_roundTripOptionalStringArray", + "abiName" : "bjs_consumeDataProcessorArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStringArray", + "name" : "consumeDataProcessorArrayType", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "processors", "type" : { "array" : { "_0" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "swiftProtocol" : { + "_0" : "DataProcessor" } } } @@ -8480,40 +9338,28 @@ } ], "returnType" : { - "array" : { - "_0" : { - "optional" : { - "_0" : { - "string" : { + "int" : { - } - } - } - } } } }, { - "abiName" : "bjs_roundTripOptionalDataPointArray", + "abiName" : "bjs_roundTripDataProcessorArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalDataPointArray", + "name" : "roundTripDataProcessorArrayType", "parameters" : [ { "label" : "_", - "name" : "points", + "name" : "processors", "type" : { "array" : { "_0" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "swiftProtocol" : { + "_0" : "DataProcessor" } } } @@ -8523,38 +9369,30 @@ "returnType" : { "array" : { "_0" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "swiftProtocol" : { + "_0" : "DataProcessor" } } } } }, { - "abiName" : "bjs_roundTripOptionalDirectionArray", + "abiName" : "bjs_roundTripJSObjectArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalDirectionArray", + "name" : "roundTripJSObjectArray", "parameters" : [ { "label" : "_", - "name" : "directions", + "name" : "objects", "type" : { "array" : { "_0" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "jsObject" : { + } } } @@ -8564,38 +9402,35 @@ "returnType" : { "array" : { "_0" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "jsObject" : { + } } } } }, { - "abiName" : "bjs_roundTripOptionalStatusArray", + "abiName" : "bjs_roundTripOptionalJSObjectArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStatusArray", + "name" : "roundTripOptionalJSObjectArray", "parameters" : [ { "label" : "_", - "name" : "statuses", + "name" : "objects", "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "jsObject" : { + } - } + }, + "_1" : "null" } } } @@ -8605,38 +9440,35 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "jsObject" : { + } - } + }, + "_1" : "null" } } } } }, { - "abiName" : "bjs_roundTripOptionalIntArrayType", + "abiName" : "bjs_roundTripFooArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalIntArrayType", + "name" : "roundTripFooArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "foos", "type" : { - "optional" : { + "array" : { "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } + "jsObject" : { + "_0" : "Foo" } } } @@ -8644,40 +9476,37 @@ } ], "returnType" : { - "optional" : { + "array" : { "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } + "jsObject" : { + "_0" : "Foo" } } } } }, { - "abiName" : "bjs_roundTripOptionalStringArrayType", + "abiName" : "bjs_roundTripOptionalFooArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStringArrayType", + "name" : "roundTripOptionalFooArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "foos", "type" : { - "optional" : { + "array" : { "_0" : { - "array" : { + "nullable" : { "_0" : { - "string" : { - + "jsObject" : { + "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -8685,1298 +9514,2470 @@ } ], "returnType" : { - "optional" : { + "array" : { "_0" : { - "array" : { + "nullable" : { "_0" : { - "string" : { - + "jsObject" : { + "_0" : "Foo" } - } + }, + "_1" : "null" } } } } }, { - "abiName" : "bjs_roundTripOptionalGreeterArrayType", + "abiName" : "bjs_roundTripOptionalString", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalGreeterArrayType", + "name" : "roundTripOptionalString", "parameters" : [ { - "label" : "_", - "name" : "greeters", + "label" : "name", + "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedIntArray", + "abiName" : "bjs_roundTripOptionalInt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedIntArray", + "name" : "roundTripOptionalInt", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "int" : { + "int" : { - } - } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "int" : { + "int" : { - } - } } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedStringArray", + "abiName" : "bjs_roundTripOptionalBool", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedStringArray", + "name" : "roundTripOptionalBool", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "flag", + "name" : "flag", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { + "bool" : { - } - } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { + "bool" : { - } - } } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDoubleArray", + "abiName" : "bjs_roundTripOptionalFloat", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDoubleArray", + "name" : "roundTripOptionalFloat", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "number", + "name" : "number", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "double" : { + "float" : { - } - } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "double" : { + "float" : { - } - } } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedBoolArray", + "abiName" : "bjs_roundTripOptionalDouble", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedBoolArray", + "name" : "roundTripOptionalDouble", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "precision", + "name" : "precision", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "bool" : { + "double" : { - } - } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "bool" : { + "double" : { - } - } } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDataPointArray", + "abiName" : "bjs_roundTripOptionalSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDataPointArray", + "name" : "roundTripOptionalSyntax", "parameters" : [ { - "label" : "_", - "name" : "points", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDirectionArray", + "abiName" : "bjs_roundTripOptionalMixSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDirectionArray", + "name" : "roundTripOptionalMixSyntax", "parameters" : [ { - "label" : "_", - "name" : "directions", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedGreeterArray", + "abiName" : "bjs_roundTripOptionalSwiftSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedGreeterArray", + "name" : "roundTripOptionalSwiftSyntax", "parameters" : [ { - "label" : "_", - "name" : "greeters", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafeRawPointerArray", + "abiName" : "bjs_roundTripOptionalWithSpaces", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeRawPointerArray", + "name" : "roundTripOptionalWithSpaces", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "double" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "double" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafeMutableRawPointerArray", + "abiName" : "bjs_roundTripOptionalTypeAlias", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeMutableRawPointerArray", + "name" : "roundTripOptionalTypeAlias", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "age", + "name" : "age", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "int" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "int" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOpaquePointerArray", + "abiName" : "bjs_roundTripOptionalStatus", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOpaquePointerArray", + "name" : "roundTripOptionalStatus", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } + "caseEnum" : { + "_0" : "Status" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } + "caseEnum" : { + "_0" : "Status" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_consumeDataProcessorArrayType", + "abiName" : "bjs_roundTripOptionalTheme", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "consumeDataProcessorArrayType", + "name" : "roundTripOptionalTheme", "parameters" : [ { - "label" : "_", - "name" : "processors", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "int" : { - + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripDataProcessorArrayType", + "abiName" : "bjs_roundTripOptionalHttpStatus", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDataProcessorArrayType", + "name" : "roundTripOptionalHttpStatus", "parameters" : [ { - "label" : "_", - "name" : "processors", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripPointerFields", + "abiName" : "bjs_roundTripOptionalTSDirection", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripPointerFields", + "name" : "roundTripOptionalTSDirection", "parameters" : [ { - "label" : "_", + "label" : "value", "name" : "value", "type" : { - "swiftStruct" : { - "_0" : "PointerFields" + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "TSDirection" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "PointerFields" + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "TSDirection" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_testStructDefault", + "abiName" : "bjs_roundTripOptionalTSTheme", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testStructDefault", + "name" : "roundTripOptionalTSTheme", "parameters" : [ { - "defaultValue" : { - "structLiteral" : { - "_0" : "DataPoint", - "_1" : [ - { - "name" : "x", - "value" : { - "float" : { - "_0" : 1 - } - } - }, - { - "name" : "y", - "value" : { - "float" : { - "_0" : 2 - } - } - }, - { - "name" : "label", - "value" : { - "string" : { - "_0" : "default" - } - } - }, - { - "name" : "optCount", - "value" : { - "null" : { - - } - } - }, - { - "name" : "optFlag", - "value" : { - "null" : { - - } - } - } - ] - } - }, - "label" : "point", - "name" : "point", + "label" : "value", + "name" : "value", "type" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + }, + "_1" : "null" } } } ], "returnType" : { - "string" : { - + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_cartToJSObject", + "abiName" : "bjs_roundTripOptionalNetworkingAPIMethod", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "cartToJSObject", + "name" : "roundTripOptionalNetworkingAPIMethod", "parameters" : [ { "label" : "_", - "name" : "cart", + "name" : "method", "type" : { - "swiftStruct" : { - "_0" : "CopyableCart" + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Networking.API.Method" + } + }, + "_1" : "null" } } } ], "returnType" : { - "jsObject" : { - + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Networking.API.Method" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_nestedCartToJSObject", + "abiName" : "bjs_roundTripOptionalAPIResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "nestedCartToJSObject", + "name" : "roundTripOptionalAPIResult", "parameters" : [ { - "label" : "_", - "name" : "cart", + "label" : "value", + "name" : "value", "type" : { - "swiftStruct" : { - "_0" : "CopyableNestedCart" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "jsObject" : { - + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripDataPoint", + "abiName" : "bjs_roundTripOptionalTypedPayloadResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDataPoint", + "name" : "roundTripOptionalTypedPayloadResult", "parameters" : [ { "label" : "_", - "name" : "data", + "name" : "result", "type" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripContact", + "abiName" : "bjs_compareAPIResults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripContact", + "name" : "compareAPIResults", "parameters" : [ { "label" : "_", - "name" : "contact", + "name" : "r1", "type" : { - "swiftStruct" : { - "_0" : "Contact" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + }, + { + "label" : "_", + "name" : "r2", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "Contact" + "string" : { + } } }, { - "abiName" : "bjs_roundTripConfig", + "abiName" : "bjs_roundTripOptionalComplexResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripConfig", + "name" : "roundTripOptionalComplexResult", "parameters" : [ { "label" : "_", - "name" : "config", + "name" : "result", "type" : { - "swiftStruct" : { - "_0" : "Config" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "Config" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "ComplexResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripSessionData", + "abiName" : "bjs_roundTripOptionalAllTypesResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripSessionData", + "name" : "roundTripOptionalAllTypesResult", "parameters" : [ { "label" : "_", - "name" : "session", + "name" : "result", "type" : { - "swiftStruct" : { - "_0" : "SessionData" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "SessionData" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "AllTypesResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripValidationReport", + "abiName" : "bjs_roundTripOptionalPayloadResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripValidationReport", + "name" : "roundTripOptionalPayloadResult", "parameters" : [ { "label" : "_", - "name" : "report", + "name" : "result", "type" : { - "swiftStruct" : { - "_0" : "ValidationReport" + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "ValidationReport" + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" } } }, { - "abiName" : "bjs_roundTripAdvancedConfig", + "abiName" : "bjs_roundTripOptionalPayloadResultOpt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripAdvancedConfig", + "name" : "roundTripOptionalPayloadResultOpt", "parameters" : [ { "label" : "_", - "name" : "config", + "name" : "result", "type" : { - "swiftStruct" : { - "_0" : "AdvancedConfig" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "AdvancedConfig" + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripMeasurementConfig", + "abiName" : "bjs_roundTripOptionalClass", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripMeasurementConfig", + "name" : "roundTripOptionalClass", "parameters" : [ { - "label" : "_", - "name" : "config", + "label" : "value", + "name" : "value", "type" : { - "swiftStruct" : { - "_0" : "MeasurementConfig" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "MeasurementConfig" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_updateValidationReport", + "abiName" : "bjs_roundTripOptionalGreeter", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "updateValidationReport", + "name" : "roundTripOptionalGreeter", "parameters" : [ { "label" : "_", - "name" : "newResult", + "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "swiftHeapObject" : { + "_0" : "Greeter" } - } - } - } - }, - { - "label" : "_", - "name" : "report", - "type" : { - "swiftStruct" : { - "_0" : "ValidationReport" + }, + "_1" : "null" } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "ValidationReport" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_testContainerWithStruct", + "abiName" : "bjs_applyOptionalGreeter", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testContainerWithStruct", + "name" : "applyOptionalGreeter", "parameters" : [ { "label" : "_", - "name" : "point", + "name" : "value", "type" : { - "swiftStruct" : { - "_0" : "DataPoint" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + }, + { + "label" : "_", + "name" : "transform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } } } } ], "returnType" : { - "swiftHeapObject" : { - "_0" : "Container" + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } - } - ], - "protocols" : [ + }, { - "methods" : [ + "abiName" : "bjs_makeOptionalHolder", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeOptionalHolder", + "parameters" : [ { - "abiName" : "bjs_DataProcessor_increment", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "increment", - "parameters" : [ - { - "label" : "by", - "name" : "amount", - "type" : { - "int" : { - + "label" : "nullableGreeter", + "name" : "nullableGreeter", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" } - } - } - ], - "returnType" : { - "void" : { - + }, + "_1" : "null" } } }, { - "abiName" : "bjs_DataProcessor_getValue", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getValue", - "parameters" : [ - - ], - "returnType" : { - "int" : { + "label" : "undefinedNumber", + "name" : "undefinedNumber", + "type" : { + "nullable" : { + "_0" : { + "double" : { + } + }, + "_1" : "undefined" } } - }, + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "OptionalHolder" + } + } + }, + { + "abiName" : "bjs_roundTripOptionalAPIOptionalResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalAPIOptionalResult", + "parameters" : [ { - "abiName" : "bjs_DataProcessor_setLabelElements", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "setLabelElements", - "parameters" : [ - { - "label" : "_", - "name" : "labelPrefix", - "type" : { - "string" : { - - } - } - }, - { - "label" : "_", - "name" : "labelSuffix", - "type" : { - "string" : { - + "label" : "result", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" } - } - } - ], - "returnType" : { - "void" : { - + }, + "_1" : "null" } } - }, - { - "abiName" : "bjs_DataProcessor_getLabel", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getLabel", - "parameters" : [ - - ], - "returnType" : { - "string" : { - + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIOptionalResult" } - } - }, - { - "abiName" : "bjs_DataProcessor_isEven", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false }, - "name" : "isEven", - "parameters" : [ - - ], - "returnType" : { - "bool" : { - + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_roundTripPointerFields", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripPointerFields", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "swiftStruct" : { + "_0" : "PointerFields" } } - }, - { - "abiName" : "bjs_DataProcessor_processGreeter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processGreeter", - "parameters" : [ - { - "label" : "_", - "name" : "greeter", - "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "PointerFields" + } + } + }, + { + "abiName" : "bjs_testStructDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testStructDefault", + "parameters" : [ + { + "defaultValue" : { + "structLiteral" : { + "_0" : "DataPoint", + "_1" : [ + { + "name" : "x", + "value" : { + "float" : { + "_0" : 1 + } + } + }, + { + "name" : "y", + "value" : { + "float" : { + "_0" : 2 + } + } + }, + { + "name" : "label", + "value" : { + "string" : { + "_0" : "default" + } + } + }, + { + "name" : "optCount", + "value" : { + "null" : { + + } + } + }, + { + "name" : "optFlag", + "value" : { + "null" : { + + } + } + } + ] + } + }, + "label" : "point", + "name" : "point", + "type" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_cartToJSObject", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "cartToJSObject", + "parameters" : [ + { + "label" : "_", + "name" : "cart", + "type" : { + "swiftStruct" : { + "_0" : "CopyableCart" + } + } + } + ], + "returnType" : { + "jsObject" : { + + } + } + }, + { + "abiName" : "bjs_nestedCartToJSObject", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "nestedCartToJSObject", + "parameters" : [ + { + "label" : "_", + "name" : "cart", + "type" : { + "swiftStruct" : { + "_0" : "CopyableNestedCart" + } + } + } + ], + "returnType" : { + "jsObject" : { + + } + } + }, + { + "abiName" : "bjs_roundTripDataPoint", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripDataPoint", + "parameters" : [ + { + "label" : "_", + "name" : "data", + "type" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + }, + { + "abiName" : "bjs_roundTripContact", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripContact", + "parameters" : [ + { + "label" : "_", + "name" : "contact", + "type" : { + "swiftStruct" : { + "_0" : "Contact" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Contact" + } + } + }, + { + "abiName" : "bjs_roundTripConfig", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripConfig", + "parameters" : [ + { + "label" : "_", + "name" : "config", + "type" : { + "swiftStruct" : { + "_0" : "Config" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "Config" + } + } + }, + { + "abiName" : "bjs_roundTripSessionData", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripSessionData", + "parameters" : [ + { + "label" : "_", + "name" : "session", + "type" : { + "swiftStruct" : { + "_0" : "SessionData" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "SessionData" + } + } + }, + { + "abiName" : "bjs_roundTripValidationReport", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripValidationReport", + "parameters" : [ + { + "label" : "_", + "name" : "report", + "type" : { + "swiftStruct" : { + "_0" : "ValidationReport" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "ValidationReport" + } + } + }, + { + "abiName" : "bjs_roundTripAdvancedConfig", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripAdvancedConfig", + "parameters" : [ + { + "label" : "_", + "name" : "config", + "type" : { + "swiftStruct" : { + "_0" : "AdvancedConfig" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "AdvancedConfig" + } + } + }, + { + "abiName" : "bjs_roundTripMeasurementConfig", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripMeasurementConfig", + "parameters" : [ + { + "label" : "_", + "name" : "config", + "type" : { + "swiftStruct" : { + "_0" : "MeasurementConfig" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "MeasurementConfig" + } + } + }, + { + "abiName" : "bjs_updateValidationReport", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "updateValidationReport", + "parameters" : [ + { + "label" : "_", + "name" : "newResult", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + }, + { + "label" : "_", + "name" : "report", + "type" : { + "swiftStruct" : { + "_0" : "ValidationReport" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "ValidationReport" + } + } + }, + { + "abiName" : "bjs_testContainerWithStruct", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "testContainerWithStruct", + "parameters" : [ + { + "label" : "_", + "name" : "point", + "type" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "Container" + } + } + }, + { + "abiName" : "bjs_roundTripJSObjectContainer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSObjectContainer", + "parameters" : [ + { + "label" : "_", + "name" : "container", + "type" : { + "swiftStruct" : { + "_0" : "JSObjectContainer" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "JSObjectContainer" + } + } + }, + { + "abiName" : "bjs_roundTripFooContainer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripFooContainer", + "parameters" : [ + { + "label" : "_", + "name" : "container", + "type" : { + "swiftStruct" : { + "_0" : "FooContainer" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "FooContainer" + } + } + }, + { + "abiName" : "bjs_roundTripArrayMembers", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripArrayMembers", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "swiftStruct" : { + "_0" : "ArrayMembers" + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "ArrayMembers" + } + } + }, + { + "abiName" : "bjs_arrayMembersSum", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "arrayMembersSum", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "swiftStruct" : { + "_0" : "ArrayMembers" + } + } + }, + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_arrayMembersFirst", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "arrayMembersFirst", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "swiftStruct" : { + "_0" : "ArrayMembers" + } + } + }, + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "protocols" : [ + { + "methods" : [ + { + "abiName" : "bjs_DataProcessor_increment", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "increment", + "parameters" : [ + { + "label" : "by", + "name" : "amount", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_getValue", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getValue", + "parameters" : [ + + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_setLabelElements", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "setLabelElements", + "parameters" : [ + { + "label" : "_", + "name" : "labelPrefix", + "type" : { + "string" : { + + } + } + }, + { + "label" : "_", + "name" : "labelSuffix", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_getLabel", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getLabel", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_isEven", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "isEven", + "parameters" : [ + + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_processGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processGreeter", + "parameters" : [ + { + "label" : "_", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_createGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createGreeter", + "parameters" : [ + + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + }, + { + "abiName" : "bjs_DataProcessor_processOptionalGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "processOptionalGreeter", + "parameters" : [ + { + "label" : "_", + "name" : "greeter", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_createOptionalGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "createOptionalGreeter", + "parameters" : [ + + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_DataProcessor_handleAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "handleAPIResult", + "parameters" : [ + { + "label" : "_", + "name" : "result", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "void" : { + + } + } + }, + { + "abiName" : "bjs_DataProcessor_getAPIResult", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "getAPIResult", + "parameters" : [ + + ], + "returnType" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + } + ], + "name" : "DataProcessor", + "properties" : [ + { + "isReadonly" : false, + "name" : "count", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "isReadonly" : false, + "name" : "optionalTag", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "optionalCount", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "direction", + "type" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "optionalTheme", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "httpStatus", + "type" : { + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "apiResult", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + }, + { + "isReadonly" : false, + "name" : "helper", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + }, + { + "isReadonly" : false, + "name" : "optionalHelper", + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } + } + ] + } + ], + "structs" : [ + { + "methods" : [ + + ], + "name" : "Point", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "int" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "int" : { + + } + } + } + ], + "swiftCallName" : "Point" + }, + { + "constructor" : { + "abiName" : "bjs_PointerFields_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "raw", + "name" : "raw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" } } } - ], - "returnType" : { - "string" : { + }, + { + "label" : "mutRaw", + "name" : "mutRaw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "label" : "opaque", + "name" : "opaque", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + }, + { + "label" : "ptr", + "name" : "ptr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "label" : "mutPtr", + "name" : "mutPtr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "PointerFields", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "raw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "mutRaw", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "opaque", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "ptr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "mutPtr", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + ], + "swiftCallName" : "PointerFields" + }, + { + "constructor" : { + "abiName" : "bjs_DataPoint_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "x", + "name" : "x", + "type" : { + "double" : { + + } + } + }, + { + "label" : "y", + "name" : "y", + "type" : { + "double" : { + + } + } + }, + { + "label" : "label", + "name" : "label", + "type" : { + "string" : { + + } + } + }, + { + "label" : "optCount", + "name" : "optCount", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "label" : "optFlag", + "name" : "optFlag", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + + } + }, + "_1" : "null" + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "DataPoint", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "x", + "type" : { + "double" : { } } }, { - "abiName" : "bjs_DataProcessor_createGreeter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createGreeter", - "parameters" : [ + "isReadonly" : true, + "isStatic" : false, + "name" : "y", + "type" : { + "double" : { - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "Greeter" } } }, { - "abiName" : "bjs_DataProcessor_processOptionalGreeter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "processOptionalGreeter", - "parameters" : [ - { - "label" : "_", - "name" : "greeter", - "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } - } - } - } - ], - "returnType" : { + "isReadonly" : true, + "isStatic" : false, + "name" : "label", + "type" : { "string" : { } } }, { - "abiName" : "bjs_DataProcessor_createOptionalGreeter", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "createOptionalGreeter", - "parameters" : [ - - ], - "returnType" : { - "optional" : { + "isReadonly" : true, + "isStatic" : false, + "name" : "optCount", + "type" : { + "nullable" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "int" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_DataProcessor_handleAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "handleAPIResult", - "parameters" : [ - { - "label" : "_", - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } + "isReadonly" : true, + "isStatic" : false, + "name" : "optFlag", + "type" : { + "nullable" : { + "_0" : { + "bool" : { + } - } + }, + "_1" : "null" } - ], - "returnType" : { - "void" : { + } + } + ], + "swiftCallName" : "DataPoint" + }, + { + "methods" : [ + + ], + "name" : "Address", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "street", + "type" : { + "string" : { } } }, { - "abiName" : "bjs_DataProcessor_getAPIResult", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "getAPIResult", - "parameters" : [ + "isReadonly" : true, + "isStatic" : false, + "name" : "city", + "type" : { + "string" : { - ], - "returnType" : { - "optional" : { + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "zipCode", + "type" : { + "nullable" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "int" : { + } - } + }, + "_1" : "null" } } } ], - "name" : "DataProcessor", + "swiftCallName" : "Address" + }, + { + "methods" : [ + + ], + "name" : "Contact", "properties" : [ { - "isReadonly" : false, - "name" : "count", + "isReadonly" : true, + "isStatic" : false, + "name" : "name", "type" : { - "int" : { + "string" : { } } }, { "isReadonly" : true, - "name" : "name", + "isStatic" : false, + "name" : "age", "type" : { - "string" : { + "int" : { } } }, { - "isReadonly" : false, - "name" : "optionalTag", + "isReadonly" : true, + "isStatic" : false, + "name" : "address", "type" : { - "optional" : { - "_0" : { - "string" : { - - } - } + "swiftStruct" : { + "_0" : "Address" } } }, { - "isReadonly" : false, - "name" : "optionalCount", + "isReadonly" : true, + "isStatic" : false, + "name" : "email", "type" : { - "optional" : { + "nullable" : { "_0" : { - "int" : { + "string" : { } - } + }, + "_1" : "null" } } }, { - "isReadonly" : false, - "name" : "direction", + "isReadonly" : true, + "isStatic" : false, + "name" : "secondaryAddress", "type" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "swiftStruct" : { + "_0" : "Address" } - } + }, + "_1" : "null" } } - }, + } + ], + "swiftCallName" : "Contact" + }, + { + "methods" : [ + + ], + "name" : "Config", + "properties" : [ { - "isReadonly" : false, - "name" : "optionalTheme", + "isReadonly" : true, + "isStatic" : false, + "name" : "name", "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } + "string" : { + } } }, { - "isReadonly" : false, - "name" : "httpStatus", + "isReadonly" : true, + "isStatic" : false, + "name" : "theme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "_0" : "Theme", + "_1" : "String" } - } + }, + "_1" : "null" } } }, { - "isReadonly" : false, - "name" : "apiResult", + "isReadonly" : true, + "isStatic" : false, + "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "caseEnum" : { + "_0" : "Direction" } - } - } - } - }, - { - "isReadonly" : false, - "name" : "helper", - "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" + }, + "_1" : "null" } } }, { - "isReadonly" : false, - "name" : "optionalHelper", + "isReadonly" : true, + "isStatic" : false, + "name" : "status", "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "caseEnum" : { + "_0" : "Status" } } } - ] - } - ], - "structs" : [ + ], + "swiftCallName" : "Config" + }, { "methods" : [ ], - "name" : "Point", + "name" : "SessionData", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "x", + "name" : "id", "type" : { "int" : { @@ -9986,229 +11987,92 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "y", + "name" : "owner", "type" : { - "int" : { - + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" } } } ], - "swiftCallName" : "Point" + "swiftCallName" : "SessionData" }, { - "constructor" : { - "abiName" : "bjs_PointerFields_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "raw", - "name" : "raw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - }, - { - "label" : "mutRaw", - "name" : "mutRaw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } - }, - { - "label" : "opaque", - "name" : "opaque", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } - } - } - }, - { - "label" : "ptr", - "name" : "ptr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } - } - } - }, - { - "label" : "mutPtr", - "name" : "mutPtr", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } - } - ] - }, "methods" : [ ], - "name" : "PointerFields", + "name" : "ValidationReport", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "raw", - "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "mutRaw", + "name" : "id", "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "int" : { + } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "opaque", + "name" : "result", "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } + "associatedValueEnum" : { + "_0" : "APIResult" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "ptr", + "name" : "status", "type" : { - "unsafePointer" : { + "nullable" : { "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } + "caseEnum" : { + "_0" : "Status" + } + }, + "_1" : "null" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "mutPtr", + "name" : "outcome", "type" : { - "unsafePointer" : { + "nullable" : { "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" } } } ], - "swiftCallName" : "PointerFields" + "swiftCallName" : "ValidationReport" }, { - "constructor" : { - "abiName" : "bjs_DataPoint_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "x", - "name" : "x", - "type" : { - "double" : { - - } - } - }, - { - "label" : "y", - "name" : "y", - "type" : { - "double" : { - - } - } - }, - { - "label" : "label", - "name" : "label", - "type" : { - "string" : { - - } - } - }, - { - "label" : "optCount", - "name" : "optCount", - "type" : { - "optional" : { - "_0" : { - "int" : { - - } - } - } - } - }, - { - "label" : "optFlag", - "name" : "optFlag", - "type" : { - "optional" : { - "_0" : { - "bool" : { - - } - } - } - } - } - ] - }, "methods" : [ ], - "name" : "DataPoint", + "name" : "AdvancedConfig", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "x", + "name" : "id", "type" : { - "double" : { + "int" : { } } @@ -10216,9 +12080,9 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "y", + "name" : "title", "type" : { - "double" : { + "string" : { } } @@ -10226,9 +12090,9 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "label", + "name" : "enabled", "type" : { - "string" : { + "bool" : { } } @@ -10236,156 +12100,355 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "optCount", + "name" : "theme", + "type" : { + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "status", + "type" : { + "caseEnum" : { + "_0" : "Status" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { - "int" : { - + "associatedValueEnum" : { + "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "optFlag", + "name" : "metadata", "type" : { - "optional" : { + "nullable" : { "_0" : { - "bool" : { + "jsObject" : { } - } + }, + "_1" : "null" } } - } - ], - "swiftCallName" : "DataPoint" - }, - { - "methods" : [ - - ], - "name" : "Address", - "properties" : [ + }, { "isReadonly" : true, "isStatic" : false, - "name" : "street", + "name" : "location", "type" : { - "string" : { - + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + }, + "_1" : "null" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "city", + "name" : "defaults", "type" : { - "string" : { - + "swiftStruct" : { + "_0" : "ConfigStruct" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "zipCode", + "name" : "overrideDefaults", "type" : { - "optional" : { + "nullable" : { "_0" : { - "int" : { - + "swiftStruct" : { + "_0" : "ConfigStruct" } - } + }, + "_1" : "null" } } } ], - "swiftCallName" : "Address" + "swiftCallName" : "AdvancedConfig" }, { "methods" : [ ], - "name" : "Contact", + "name" : "MeasurementConfig", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "name", + "name" : "precision", "type" : { - "string" : { - + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "age", + "name" : "ratio", "type" : { - "int" : { - + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "address", + "name" : "optionalPrecision", "type" : { - "swiftStruct" : { - "_0" : "Address" + "nullable" : { + "_0" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + }, + "_1" : "null" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "email", + "name" : "optionalRatio", "type" : { - "optional" : { + "nullable" : { "_0" : { - "string" : { + "rawValueEnum" : { + "_0" : "Ratio", + "_1" : "Double" + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "MeasurementConfig" + }, + { + "constructor" : { + "abiName" : "bjs_MathOperations_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "defaultValue" : { + "double" : { + "_0" : 0 + } + }, + "label" : "baseValue", + "name" : "baseValue", + "type" : { + "double" : { + + } + } + } + ] + }, + "methods" : [ + { + "abiName" : "bjs_MathOperations_add", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "add", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "defaultValue" : { + "double" : { + "_0" : 10 + } + }, + "label" : "b", + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "abiName" : "bjs_MathOperations_multiply", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "multiply", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "double" : { } } } + ], + "returnType" : { + "double" : { + + } } }, + { + "abiName" : "bjs_MathOperations_static_subtract", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "subtract", + "parameters" : [ + { + "label" : "a", + "name" : "a", + "type" : { + "double" : { + + } + } + }, + { + "label" : "b", + "name" : "b", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + }, + "staticContext" : { + "structName" : { + "_0" : "MathOperations" + } + } + } + ], + "name" : "MathOperations", + "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "secondaryAddress", + "name" : "baseValue", "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Address" + "double" : { + + } + } + } + ], + "swiftCallName" : "MathOperations" + }, + { + "methods" : [ + { + "abiName" : "bjs_CopyableCart_static_fromJSObject", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "fromJSObject", + "parameters" : [ + { + "label" : "_", + "name" : "object", + "type" : { + "jsObject" : { + } } } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "CopyableCart" + } + }, + "staticContext" : { + "structName" : { + "_0" : "CopyableCart" + } } } ], - "swiftCallName" : "Contact" - }, - { - "methods" : [ - - ], - "name" : "Config", + "name" : "CopyableCart", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "name", + "name" : "x", "type" : { - "string" : { + "int" : { } } @@ -10393,57 +12456,33 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "theme", - "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "direction", + "name" : "note", "type" : { - "optional" : { + "nullable" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "string" : { + } - } - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "status", - "type" : { - "caseEnum" : { - "_0" : "Status" + }, + "_1" : "null" } } } ], - "swiftCallName" : "Config" + "swiftCallName" : "CopyableCart" }, { "methods" : [ ], - "name" : "SessionData", + "name" : "CopyableCartItem", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "id", + "name" : "sku", "type" : { - "int" : { + "string" : { } } @@ -10451,25 +12490,50 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "owner", + "name" : "quantity", "type" : { - "optional" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "int" : { + } } } ], - "swiftCallName" : "SessionData" + "swiftCallName" : "CopyableCartItem" }, { "methods" : [ + { + "abiName" : "bjs_CopyableNestedCart_static_fromJSObject", + "effects" : { + "isAsync" : false, + "isStatic" : true, + "isThrows" : false + }, + "name" : "fromJSObject", + "parameters" : [ + { + "label" : "_", + "name" : "object", + "type" : { + "jsObject" : { + } + } + } + ], + "returnType" : { + "swiftStruct" : { + "_0" : "CopyableNestedCart" + } + }, + "staticContext" : { + "structName" : { + "_0" : "CopyableNestedCart" + } + } + } ], - "name" : "ValidationReport", + "name" : "CopyableNestedCart", "properties" : [ { "isReadonly" : true, @@ -10484,64 +12548,41 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "result", - "type" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "status", + "name" : "item", "type" : { - "optional" : { - "_0" : { - "caseEnum" : { - "_0" : "Status" - } - } + "swiftStruct" : { + "_0" : "CopyableCartItem" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "outcome", + "name" : "shippingAddress", "type" : { - "optional" : { + "nullable" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "swiftStruct" : { + "_0" : "Address" } - } + }, + "_1" : "null" } } } ], - "swiftCallName" : "ValidationReport" + "swiftCallName" : "CopyableNestedCart" }, { "methods" : [ ], - "name" : "AdvancedConfig", + "name" : "ConfigStruct", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "id", - "type" : { - "int" : { - - } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "title", + "name" : "name", "type" : { "string" : { @@ -10551,704 +12592,678 @@ { "isReadonly" : true, "isStatic" : false, - "name" : "enabled", + "name" : "value", "type" : { - "bool" : { + "int" : { } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "theme", - "type" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "isReadonly" : false, + "isStatic" : true, + "name" : "defaultConfig", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "status", + }, "type" : { - "caseEnum" : { - "_0" : "Status" + "string" : { + } } }, { "isReadonly" : true, - "isStatic" : false, - "name" : "result", - "type" : { - "optional" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - } + "isStatic" : true, + "name" : "maxRetries", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "metadata", + }, "type" : { - "optional" : { - "_0" : { - "jsObject" : { + "int" : { - } - } } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "location", + "isReadonly" : false, + "isStatic" : true, + "name" : "timeout", + "staticContext" : { + "structName" : { + "_0" : "ConfigStruct" + } + }, "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "double" : { + } } }, { "isReadonly" : true, - "isStatic" : false, - "name" : "defaults", - "type" : { - "swiftStruct" : { + "isStatic" : true, + "name" : "computedSetting", + "staticContext" : { + "structName" : { "_0" : "ConfigStruct" } - } - }, - { - "isReadonly" : true, - "isStatic" : false, - "name" : "overrideDefaults", + }, "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "ConfigStruct" - } - } + "string" : { + } } } ], - "swiftCallName" : "AdvancedConfig" + "swiftCallName" : "ConfigStruct" }, { "methods" : [ ], - "name" : "MeasurementConfig", + "name" : "JSObjectContainer", "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "precision", + "name" : "object", "type" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" + "jsObject" : { + } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "ratio", + "name" : "optionalObject", "type" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" } } - }, + } + ], + "swiftCallName" : "JSObjectContainer" + }, + { + "methods" : [ + + ], + "name" : "FooContainer", + "properties" : [ { "isReadonly" : true, "isStatic" : false, - "name" : "optionalPrecision", + "name" : "foo", "type" : { - "optional" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } + "jsObject" : { + "_0" : "Foo" } } }, { "isReadonly" : true, "isStatic" : false, - "name" : "optionalRatio", + "name" : "optionalFoo", "type" : { - "optional" : { + "nullable" : { "_0" : { - "rawValueEnum" : { - "_0" : "Ratio", - "_1" : "Double" + "jsObject" : { + "_0" : "Foo" } - } + }, + "_1" : "null" } } } ], - "swiftCallName" : "MeasurementConfig" + "swiftCallName" : "FooContainer" }, { - "constructor" : { - "abiName" : "bjs_MathOperations_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "defaultValue" : { - "double" : { - "_0" : 0 - } - }, - "label" : "baseValue", - "name" : "baseValue", - "type" : { - "double" : { - - } - } - } - ] - }, "methods" : [ { - "abiName" : "bjs_MathOperations_add", + "abiName" : "bjs_ArrayMembers_sumValues", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "add", + "name" : "sumValues", "parameters" : [ { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "defaultValue" : { - "double" : { - "_0" : 10 - } - }, - "label" : "b", - "name" : "b", + "label" : "_", + "name" : "values", "type" : { - "double" : { + "array" : { + "_0" : { + "int" : { + } + } } } } ], "returnType" : { - "double" : { + "int" : { } } }, { - "abiName" : "bjs_MathOperations_multiply", + "abiName" : "bjs_ArrayMembers_firstString", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "multiply", + "name" : "firstString", "parameters" : [ { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "label" : "b", - "name" : "b", + "label" : "_", + "name" : "values", "type" : { - "double" : { + "array" : { + "_0" : { + "string" : { + } + } } } } ], "returnType" : { - "double" : { + "nullable" : { + "_0" : { + "string" : { + } + }, + "_1" : "null" } } - }, + } + ], + "name" : "ArrayMembers", + "properties" : [ { - "abiName" : "bjs_MathOperations_static_subtract", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "subtract", - "parameters" : [ - { - "label" : "a", - "name" : "a", - "type" : { - "double" : { - - } - } - }, - { - "label" : "b", - "name" : "b", - "type" : { - "double" : { + "isReadonly" : true, + "isStatic" : false, + "name" : "ints", + "type" : { + "array" : { + "_0" : { + "int" : { } } } - ], - "returnType" : { - "double" : { - - } - }, - "staticContext" : { - "structName" : { - "_0" : "MathOperations" - } } - } - ], - "name" : "MathOperations", - "properties" : [ + }, { "isReadonly" : true, "isStatic" : false, - "name" : "baseValue", + "name" : "optStrings", "type" : { - "double" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + } + } + } + }, + "_1" : "null" } } } ], - "swiftCallName" : "MathOperations" - }, + "swiftCallName" : "ArrayMembers" + } + ] + }, + "imported" : { + "children" : [ { - "methods" : [ + "functions" : [ + + ], + "types" : [ { - "abiName" : "bjs_CopyableCart_static_fromJSObject", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false + "constructor" : { + "parameters" : [ + { + "name" : "value", + "type" : { + "string" : { + + } + } + } + ] }, - "name" : "fromJSObject", - "parameters" : [ + "getters" : [ { - "label" : "_", - "name" : "object", + "name" : "value", "type" : { - "jsObject" : { + "string" : { } } } ], - "returnType" : { - "swiftStruct" : { - "_0" : "CopyableCart" - } - }, - "staticContext" : { - "structName" : { - "_0" : "CopyableCart" - } - } + "methods" : [ + + ], + "name" : "Foo", + "setters" : [ + + ], + "staticMethods" : [ + + ] } - ], - "name" : "CopyableCart", - "properties" : [ + ] + }, + { + "functions" : [ { - "isReadonly" : true, - "isStatic" : false, - "name" : "x", - "type" : { - "int" : { + "name" : "jsRoundTripVoid", + "parameters" : [ + + ], + "returnType" : { + "void" : { } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "note", - "type" : { - "optional" : { - "_0" : { - "string" : { + "name" : "jsRoundTripNumber", + "parameters" : [ + { + "name" : "v", + "type" : { + "double" : { } } - } - } - } - ], - "swiftCallName" : "CopyableCart" - }, - { - "methods" : [ - - ], - "name" : "CopyableCartItem", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "sku", - "type" : { - "string" : { + } + ], + "returnType" : { + "double" : { } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "quantity", - "type" : { - "int" : { + "name" : "jsRoundTripBool", + "parameters" : [ + { + "name" : "v", + "type" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "bool" : { } } - } - ], - "swiftCallName" : "CopyableCartItem" - }, - { - "methods" : [ + }, { - "abiName" : "bjs_CopyableNestedCart_static_fromJSObject", - "effects" : { - "isAsync" : false, - "isStatic" : true, - "isThrows" : false - }, - "name" : "fromJSObject", + "name" : "jsRoundTripString", "parameters" : [ { - "label" : "_", - "name" : "object", + "name" : "v", "type" : { - "jsObject" : { + "string" : { } } } ], "returnType" : { - "swiftStruct" : { - "_0" : "CopyableNestedCart" - } - }, - "staticContext" : { - "structName" : { - "_0" : "CopyableNestedCart" - } - } - } - ], - "name" : "CopyableNestedCart", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "id", - "type" : { - "int" : { + "string" : { } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "item", - "type" : { - "swiftStruct" : { - "_0" : "CopyableCartItem" + "name" : "jsRoundTripJSValue", + "parameters" : [ + { + "name" : "v", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "shippingAddress", - "type" : { - "optional" : { - "_0" : { - "swiftStruct" : { - "_0" : "Address" + "name" : "jsRoundTripJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } } } } - } - } - ], - "swiftCallName" : "CopyableNestedCart" - }, - { - "methods" : [ - - ], - "name" : "ConfigStruct", - "properties" : [ - { - "isReadonly" : true, - "isStatic" : false, - "name" : "name", - "type" : { - "string" : { + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + } + } } } }, { - "isReadonly" : true, - "isStatic" : false, - "name" : "value", - "type" : { - "int" : { + "name" : "jsRoundTripOptionalJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + } + } + } + }, + "_1" : "null" } } }, { - "isReadonly" : false, - "isStatic" : true, - "name" : "defaultConfig", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" + "name" : "jsThrowOrVoid", + "parameters" : [ + { + "name" : "shouldThrow", + "type" : { + "bool" : { + + } + } } - }, - "type" : { - "string" : { + ], + "returnType" : { + "void" : { } } }, { - "isReadonly" : true, - "isStatic" : true, - "name" : "maxRetries", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" + "name" : "jsThrowOrNumber", + "parameters" : [ + { + "name" : "shouldThrow", + "type" : { + "bool" : { + + } + } } - }, - "type" : { - "int" : { + ], + "returnType" : { + "double" : { } } }, { - "isReadonly" : false, - "isStatic" : true, - "name" : "timeout", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" + "name" : "jsThrowOrBool", + "parameters" : [ + { + "name" : "shouldThrow", + "type" : { + "bool" : { + + } + } } - }, - "type" : { - "double" : { + ], + "returnType" : { + "bool" : { } } }, { - "isReadonly" : true, - "isStatic" : true, - "name" : "computedSetting", - "staticContext" : { - "structName" : { - "_0" : "ConfigStruct" + "name" : "jsThrowOrString", + "parameters" : [ + { + "name" : "shouldThrow", + "type" : { + "bool" : { + + } + } } - }, - "type" : { + ], + "returnType" : { "string" : { } } - } - ], - "swiftCallName" : "ConfigStruct" - } - ] - }, - "imported" : { - "children" : [ - { - "functions" : [ - - ], - "types" : [ + }, { - "constructor" : { - "parameters" : [ - { - "name" : "value", - "type" : { - "string" : { - - } - } - } - ] - }, - "getters" : [ + "name" : "jsRoundTripFeatureFlag", + "parameters" : [ { - "name" : "value", + "name" : "flag", "type" : { - "string" : { - + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" } } } ], - "methods" : [ + "returnType" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + }, + { + "name" : "runAsyncWorks", + "parameters" : [ ], - "name" : "Foo", - "setters" : [ - - ] - } - ] - }, - { - "functions" : [ + "returnType" : { + "jsObject" : { + "_0" : "JSPromise" + } + } + }, { - "name" : "jsRoundTripVoid", + "jsName" : "$jsWeirdFunction", + "name" : "_jsWeirdFunction", "parameters" : [ ], "returnType" : { - "void" : { + "double" : { } } }, { - "name" : "jsRoundTripNumber", + "name" : "jsRoundTripNumberArray", "parameters" : [ { - "name" : "v", + "name" : "values", "type" : { - "double" : { + "array" : { + "_0" : { + "double" : { + } + } } } } ], "returnType" : { - "double" : { + "array" : { + "_0" : { + "double" : { + } + } } } }, { - "name" : "jsRoundTripBool", + "name" : "jsRoundTripStringArray", "parameters" : [ { - "name" : "v", + "name" : "values", "type" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } } ], "returnType" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } }, { - "name" : "jsRoundTripString", + "name" : "jsRoundTripBoolArray", "parameters" : [ { - "name" : "v", + "name" : "values", "type" : { - "string" : { + "array" : { + "_0" : { + "bool" : { + } + } } } } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "bool" : { + } + } } } }, { - "name" : "jsThrowOrVoid", + "name" : "jsSumNumberArray", "parameters" : [ { - "name" : "shouldThrow", + "name" : "values", "type" : { - "bool" : { + "array" : { + "_0" : { + "double" : { + } + } } } } ], "returnType" : { - "void" : { + "double" : { } } }, { - "name" : "jsThrowOrNumber", + "name" : "jsCreateNumberArray", + "parameters" : [ + + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "from" : "global", + "name" : "parseInt", "parameters" : [ { - "name" : "shouldThrow", + "name" : "string", "type" : { - "bool" : { + "string" : { } } @@ -11259,118 +13274,226 @@ } } - }, + } + ], + "globalGetters" : [ { - "name" : "jsThrowOrBool", - "parameters" : [ + "from" : "global", + "name" : "globalObject1", + "type" : { + "jsValue" : { + + } + } + } + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "name" : "prefix", + "type" : { + "string" : { + + } + } + } + ] + }, + "getters" : [ { - "name" : "shouldThrow", + "name" : "name", "type" : { - "bool" : { + "string" : { + + } + } + }, + { + "name" : "prefix", + "type" : { + "string" : { + + } + } + } + ], + "methods" : [ + { + "name" : "greet", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + }, + { + "name" : "changeName", + "parameters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "JsGreeter", + "setters" : [ + { + "functionName" : "name_set", + "name" : "name", + "type" : { + "string" : { + + } + } + } + ], + "staticMethods" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + + ] + }, + "getters" : [ + + ], + "jsName" : "$WeirdClass", + "methods" : [ + { + "jsName" : "method-with-dashes", + "name" : "method_with_dashes", + "parameters" : [ + + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "_WeirdClass", + "setters" : [ + + ], + "staticMethods" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ] + }, + "getters" : [ - } - } - } ], - "returnType" : { - "bool" : { - - } - } - }, - { - "name" : "jsThrowOrString", - "parameters" : [ + "methods" : [ { - "name" : "shouldThrow", - "type" : { - "bool" : { + "name" : "value", + "parameters" : [ + + ], + "returnType" : { + "double" : { } } } ], - "returnType" : { - "string" : { + "name" : "StaticBox", + "setters" : [ - } - } - }, - { - "name" : "jsRoundTripFeatureFlag", - "parameters" : [ + ], + "staticMethods" : [ { - "name" : "flag", - "type" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "String" + "name" : "create", + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" } } - } - ], - "returnType" : { - "rawValueEnum" : { - "_0" : "FeatureFlag", - "_1" : "String" - } - } - }, - { - "name" : "runAsyncWorks", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "JSPromise" - } - } - }, - { - "jsName" : "$jsWeirdFunction", - "name" : "_jsWeirdFunction", - "parameters" : [ + }, + { + "name" : "value", + "parameters" : [ - ], - "returnType" : { - "double" : { + ], + "returnType" : { + "double" : { - } - } - }, - { - "from" : "global", - "name" : "parseInt", - "parameters" : [ + } + } + }, { - "name" : "string", - "type" : { - "string" : { + "name" : "makeDefault", + "parameters" : [ + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" } } - } - ], - "returnType" : { - "double" : { - - } - } - } - ], - "globalGetters" : [ - { - "from" : "global", - "name" : "globalObject1", - "type" : { - "jsObject" : { + }, + { + "jsName" : "with-dashes", + "name" : "with_dashes", + "parameters" : [ + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } } - } - } - ], - "types" : [ + ] + }, { "constructor" : { "parameters" : [ @@ -11383,15 +13506,24 @@ } }, { - "name" : "prefix", + "name" : "age", "type" : { - "string" : { + "double" : { + + } + } + }, + { + "name" : "isCat", + "type" : { + "bool" : { } } } ] }, + "from" : "global", "getters" : [ { "name" : "name", @@ -11402,9 +13534,17 @@ } }, { - "name" : "prefix", + "name" : "age", "type" : { - "string" : { + "double" : { + + } + } + }, + { + "name" : "isCat", + "type" : { + "bool" : { } } @@ -11412,7 +13552,7 @@ ], "methods" : [ { - "name" : "greet", + "name" : "bark", "parameters" : [ ], @@ -11423,25 +13563,18 @@ } }, { - "name" : "changeName", + "name" : "getIsCat", "parameters" : [ - { - "name" : "name", - "type" : { - "string" : { - } - } - } ], "returnType" : { - "void" : { + "bool" : { } } } ], - "name" : "JsGreeter", + "name" : "Animal", "setters" : [ { "functionName" : "name_set", @@ -11449,169 +13582,286 @@ "type" : { "string" : { + } + } + }, + { + "functionName" : "age_set", + "name" : "age", + "type" : { + "double" : { + + } + } + }, + { + "functionName" : "isCat_set", + "name" : "isCat", + "type" : { + "bool" : { + } } } + ], + "staticMethods" : [ + ] - }, + } + ] + }, + { + "functions" : [ { - "constructor" : { - "parameters" : [ + "name" : "jsRoundTripIntArray", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { - ] - }, - "getters" : [ + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "jsArrayLength", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + } + } + } + } + } ], - "jsName" : "$WeirdClass", - "methods" : [ + "returnType" : { + "int" : { + + } + } + }, + { + "name" : "makeArrayHost", + "parameters" : [ { - "jsName" : "method-with-dashes", - "name" : "method_with_dashes", - "parameters" : [ + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { - ], - "returnType" : { - "string" : { + } + } + } + } + }, + { + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + } + } } } } ], - "name" : "_WeirdClass", - "setters" : [ - - ] - }, + "returnType" : { + "jsObject" : { + "_0" : "ArrayHost" + } + } + } + ], + "types" : [ { "constructor" : { "parameters" : [ { - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "name" : "age", + "name" : "numbers", "type" : { - "double" : { + "array" : { + "_0" : { + "int" : { + } + } } } }, { - "name" : "isCat", + "name" : "labels", "type" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } } ] }, - "from" : "global", "getters" : [ { - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "name" : "age", + "name" : "numbers", "type" : { - "double" : { + "array" : { + "_0" : { + "int" : { + } + } } } }, { - "name" : "isCat", + "name" : "labels", "type" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } } ], "methods" : [ { - "name" : "bark", + "name" : "concatNumbers", "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + } + } + } + } + } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "int" : { + } + } } } }, { - "name" : "getIsCat", + "name" : "concatLabels", "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + } + } + } + } + } ], "returnType" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } - } - ], - "name" : "Animal", - "setters" : [ + }, { - "functionName" : "name_set", - "name" : "name", - "type" : { + "name" : "firstLabel", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { "string" : { } } - }, + } + ], + "name" : "ArrayHost", + "setters" : [ { - "functionName" : "age_set", - "name" : "age", + "functionName" : "numbers_set", + "name" : "numbers", "type" : { - "double" : { + "array" : { + "_0" : { + "int" : { + } + } } } }, { - "functionName" : "isCat_set", - "name" : "isCat", + "functionName" : "labels_set", + "name" : "labels", "type" : { - "bool" : { + "array" : { + "_0" : { + "string" : { + } + } } } } + ], + "staticMethods" : [ + ] } ] }, - { - "functions" : [ - - ], - "types" : [ - - ] - }, - { - "functions" : [ - - ], - "types" : [ - - ] - }, { "functions" : [ { @@ -11861,15 +14111,129 @@ }, { "functions" : [ + { + "name" : "runJsOptionalSupportTests", + "parameters" : [ - ], - "types" : [ + ], + "returnType" : { + "void" : { - ] - }, - { - "functions" : [ + } + } + }, + { + "name" : "jsRoundTripOptionalNumberNull", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "jsRoundTripOptionalNumberUndefined", + "parameters" : [ + { + "name" : "value", + "type" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "int" : { + + } + }, + "_1" : "undefined" + } + } + }, + { + "name" : "jsRoundTripOptionalStringNull", + "parameters" : [ + { + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + }, + { + "name" : "jsRoundTripOptionalStringUndefined", + "parameters" : [ + { + "name" : "name", + "type" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + } + }, + "_1" : "undefined" + } + } + } ], "types" : [ diff --git a/Tests/BridgeJSRuntimeTests/GlobalThisImportTests.swift b/Tests/BridgeJSRuntimeTests/GlobalThisImportTests.swift index 2f6251341..fdd22401d 100644 --- a/Tests/BridgeJSRuntimeTests/GlobalThisImportTests.swift +++ b/Tests/BridgeJSRuntimeTests/GlobalThisImportTests.swift @@ -13,7 +13,11 @@ final class GlobalThisImportTests: XCTestCase { } func testGlobalGetterImport() throws { - let value = try globalObject1["prop_2"].number + guard let object = try globalObject1.object else { + XCTFail("globalObject1 was not an object") + return + } + let value = object[dynamicMember: "prop_2"].number XCTAssertEqual(value, 2) } } diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index ea9f8c68f..4aa96e1b2 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -35,6 +35,50 @@ class ImportAPITests: XCTestCase { } } + func testRoundTripJSValue() throws { + let symbol = JSSymbol("roundTrip") + let bigInt = JSBigInt(_slowBridge: Int64(123456789)) + let values: [JSValue] = [ + .boolean(true), + .number(42), + .string(JSString("hello")), + .object(JSObject.global), + .null, + .undefined, + .symbol(symbol), + .bigInt(bigInt), + ] + for value in values { + try XCTAssertEqual(jsRoundTripJSValue(value), value) + } + } + + 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) @@ -114,6 +158,33 @@ class ImportAPITests: XCTestCase { XCTAssertEqual(prefixer("world!"), "Hello, world!") } + 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 testClosureParameterIntToVoid() throws { var total = 0 let ret = try jsCallTwice(5) { total += $0 } @@ -127,4 +198,51 @@ class ImportAPITests: XCTestCase { let obj = try _WeirdClass() XCTAssertEqual(try obj.method_with_dashes(), "ok") } + + func testJSClassStaticFunctions() throws { + let created = try StaticBox.create(10) + XCTAssertEqual(try created.value(), 10) + + let defaultBox = try StaticBox.makeDefault() + XCTAssertEqual(try defaultBox.value(), 0) + + XCTAssertEqual(try StaticBox.value(), 99) + + 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 new file mode 100644 index 000000000..3f33de86a --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift @@ -0,0 +1,17 @@ +@_spi(Experimental) @_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/JavaScript/OptionalSupportTests.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs new file mode 100644 index 000000000..8a856582d --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs @@ -0,0 +1,219 @@ +// @ts-check + +import assert from 'node:assert'; +import { + StatusValues, + ThemeValues, + HttpStatusValues, + TSDirection, + TSTheme, + APIResultValues, + APIOptionalResultValues, + AllTypesResultValues, + OptionalAllTypesResultValues, +} from '../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.js'; + +import { ImportedFoo } from './Types.mjs'; + +/** + * Optional value bridging coverage for BridgeJS runtime tests. + * @param {import('../../../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports + */ +export function runJsOptionalSupportTests(exports) { + assert.equal(exports.roundTripOptionalString(null), null); + assert.equal(exports.roundTripOptionalInt(null), null); + assert.equal(exports.roundTripOptionalBool(null), null); + assert.equal(exports.roundTripOptionalFloat(null), null); + assert.equal(exports.roundTripOptionalDouble(null), null); + + assert.equal(exports.roundTripOptionalString('Hello'), 'Hello'); + assert.equal(exports.roundTripOptionalInt(42), 42); + assert.equal(exports.roundTripOptionalBool(true), true); + assert.equal(exports.roundTripOptionalFloat(3.141592502593994), 3.141592502593994); // Float32 precision + assert.equal(exports.roundTripOptionalDouble(2.718), 2.718); + + assert.equal(exports.roundTripOptionalSyntax(null), null); + assert.equal(exports.roundTripOptionalSyntax('Test'), 'Test'); + assert.equal(exports.roundTripOptionalMixSyntax(null), null); + assert.equal(exports.roundTripOptionalMixSyntax('Mix'), 'Mix'); + assert.equal(exports.roundTripOptionalSwiftSyntax(null), null); + assert.equal(exports.roundTripOptionalSwiftSyntax('Swift'), 'Swift'); + assert.equal(exports.roundTripOptionalWithSpaces(null), null); + assert.equal(exports.roundTripOptionalWithSpaces(1.618), 1.618); + assert.equal(exports.roundTripOptionalTypeAlias(null), null); + assert.equal(exports.roundTripOptionalTypeAlias(25), 25); + assert.equal(exports.roundTripOptionalStatus(exports.Status.Success), StatusValues.Success); + assert.equal(exports.roundTripOptionalTheme(exports.Theme.Light), ThemeValues.Light); + assert.equal(exports.roundTripOptionalHttpStatus(exports.HttpStatus.Ok), HttpStatusValues.Ok); + assert.equal(exports.roundTripOptionalTSDirection(TSDirection.North), TSDirection.North); + assert.equal(exports.roundTripOptionalTSTheme(TSTheme.Light), TSTheme.Light); + assert.equal(exports.roundTripOptionalNetworkingAPIMethod(exports.Networking.API.Method.Get), exports.Networking.API.Method.Get); + + const pVal = 3.141592653589793; + const p1 = { tag: APIResultValues.Tag.Precise, param0: pVal }; + const cl1 = { tag: exports.ComplexResult.Tag.Location, param0: 37.7749, param1: -122.4194, param2: 'San Francisco' }; + + assert.deepEqual(exports.roundTripOptionalAPIResult(p1), p1); + assert.deepEqual(exports.roundTripOptionalComplexResult(cl1), cl1); + + const apiSuccess = { tag: exports.APIResult.Tag.Success, param0: 'test success' }; + const apiFailure = { tag: exports.APIResult.Tag.Failure, param0: 404 }; + const apiInfo = { tag: exports.APIResult.Tag.Info }; + + assert.equal(exports.compareAPIResults(apiSuccess, apiFailure), 'r1:success:test success,r2:failure:404'); + assert.equal(exports.compareAPIResults(null, apiInfo), 'r1:nil,r2:info'); + assert.equal(exports.compareAPIResults(apiFailure, null), 'r1:failure:404,r2:nil'); + assert.equal(exports.compareAPIResults(null, null), 'r1:nil,r2:nil'); + + const optionalGreeter = new exports.Greeter('Schrödinger'); + const optionalGreeter2 = exports.roundTripOptionalClass(optionalGreeter); + assert.equal(optionalGreeter2?.greet() ?? '', 'Hello, Schrödinger!'); + assert.equal(optionalGreeter2?.name ?? '', 'Schrödinger'); + assert.equal(optionalGreeter2?.prefix ?? '', 'Hello'); + assert.equal(exports.roundTripOptionalClass(null), null); + optionalGreeter.release(); + optionalGreeter2?.release(); + + const optionalsHolder = new exports.OptionalPropertyHolder(null); + + assert.equal(optionalsHolder.optionalName, null); + assert.equal(optionalsHolder.optionalAge, null); + assert.equal(optionalsHolder.optionalGreeter, null); + + optionalsHolder.optionalName = 'Alice'; + optionalsHolder.optionalAge = 25; + assert.equal(optionalsHolder.optionalName, 'Alice'); + assert.equal(optionalsHolder.optionalAge, 25); + + const testPropertyGreeter = new exports.Greeter('Bob'); + optionalsHolder.optionalGreeter = testPropertyGreeter; + assert.equal(optionalsHolder.optionalGreeter.greet(), 'Hello, Bob!'); + assert.equal(optionalsHolder.optionalGreeter.name, 'Bob'); + + optionalsHolder.optionalName = null; + optionalsHolder.optionalAge = null; + optionalsHolder.optionalGreeter = null; + assert.equal(optionalsHolder.optionalName, null); + assert.equal(optionalsHolder.optionalAge, null); + assert.equal(optionalsHolder.optionalGreeter, null); + testPropertyGreeter.release(); + optionalsHolder.release(); + + const optGreeter = new exports.Greeter('Optionaly'); + assert.equal(exports.roundTripOptionalGreeter(null), null); + const optGreeterReturned = exports.roundTripOptionalGreeter(optGreeter); + assert.equal(optGreeterReturned.name, 'Optionaly'); + assert.equal(optGreeterReturned.greet(), 'Hello, Optionaly!'); + + const appliedOptional = exports.applyOptionalGreeter(null, (g) => g ?? optGreeter); + assert.equal(appliedOptional.name, 'Optionaly'); + + const holderOpt = exports.makeOptionalHolder(null, undefined); + assert.equal(holderOpt.nullableGreeter, null); + assert.equal(holderOpt.undefinedNumber, undefined); + holderOpt.nullableGreeter = optGreeter; + holderOpt.undefinedNumber = 123.5; + assert.equal(holderOpt.nullableGreeter.name, 'Optionaly'); + assert.equal(holderOpt.undefinedNumber, 123.5); + holderOpt.release(); + optGreeterReturned.release(); + optGreeter.release(); + + const aor1 = { tag: APIOptionalResultValues.Tag.Success, param0: 'hello world' }; + const aor2 = { tag: APIOptionalResultValues.Tag.Success, param0: null }; + const aor3 = { tag: APIOptionalResultValues.Tag.Failure, param0: 404, param1: true }; + const aor4 = { tag: APIOptionalResultValues.Tag.Failure, param0: 404, param1: null }; + const aor5 = { tag: APIOptionalResultValues.Tag.Failure, param0: null, param1: null }; + const aor6 = { tag: APIOptionalResultValues.Tag.Status, param0: true, param1: 200, param2: 'OK' }; + const aor7 = { tag: APIOptionalResultValues.Tag.Status, param0: true, param1: null, param2: 'Partial' }; + const aor8 = { tag: APIOptionalResultValues.Tag.Status, param0: null, param1: null, param2: 'Zero' }; + const aor9 = { tag: APIOptionalResultValues.Tag.Status, param0: false, param1: 500, param2: null }; + const aor10 = { tag: APIOptionalResultValues.Tag.Status, param0: null, param1: 0, param2: 'Zero' }; + + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor1), aor1); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor2), aor2); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor3), aor3); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor4), aor4); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor5), aor5); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor6), aor6); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor7), aor7); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor8), aor8); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor9), aor9); + assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor10), aor10); + assert.equal(exports.roundTripOptionalAPIOptionalResult(null), null); + + // Optional TypedPayloadResult roundtrip + const tpr_precision = { tag: exports.TypedPayloadResult.Tag.Precision, param0: Math.fround(0.1) }; + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_precision), tpr_precision); + const tpr_direction = { tag: exports.TypedPayloadResult.Tag.Direction, param0: exports.Direction.North }; + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_direction), tpr_direction); + const tpr_optPrecisionSome = { tag: exports.TypedPayloadResult.Tag.OptPrecision, param0: Math.fround(0.001) }; + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionSome), tpr_optPrecisionSome); + const tpr_optPrecisionNull = { tag: exports.TypedPayloadResult.Tag.OptPrecision, param0: null }; + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionNull), tpr_optPrecisionNull); + const tpr_empty = { tag: exports.TypedPayloadResult.Tag.Empty }; + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_empty), tpr_empty); + assert.equal(exports.roundTripOptionalTypedPayloadResult(null), null); + + // Optional AllTypesResult roundtrip + const atr_struct = { tag: AllTypesResultValues.Tag.StructPayload, param0: { street: "100 Main St", city: "Boston", zipCode: 2101 } }; + assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_struct), atr_struct); + const atr_array = { tag: AllTypesResultValues.Tag.ArrayPayload, param0: [10, 20, 30] }; + assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_array), atr_array); + const atr_empty = { tag: AllTypesResultValues.Tag.Empty }; + assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_empty), atr_empty); + assert.equal(exports.roundTripOptionalAllTypesResult(null), null); + + // OptionalAllTypesResult — optional struct, class, JSObject, nested enum, array as associated value payloads + const oatr_structSome = { tag: OptionalAllTypesResultValues.Tag.OptStruct, param0: { street: "200 Oak St", city: "Denver", zipCode: null } }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_structSome), oatr_structSome); + + const oatr_structNone = { tag: OptionalAllTypesResultValues.Tag.OptStruct, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_structNone), oatr_structNone); + + const oatr_classSome = { tag: OptionalAllTypesResultValues.Tag.OptClass, param0: new exports.Greeter("OptEnumUser") }; + const oatr_classSome_result = exports.roundTripOptionalPayloadResult(oatr_classSome); + assert.equal(oatr_classSome_result.tag, OptionalAllTypesResultValues.Tag.OptClass); + assert.equal(oatr_classSome_result.param0.name, "OptEnumUser"); + + const oatr_classNone = { tag: OptionalAllTypesResultValues.Tag.OptClass, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_classNone), oatr_classNone); + + const oatr_jsObjectSome = { tag: OptionalAllTypesResultValues.Tag.OptJSObject, param0: { key: "value" } }; + const oatr_jsObjectSome_result = exports.roundTripOptionalPayloadResult(oatr_jsObjectSome); + assert.equal(oatr_jsObjectSome_result.tag, OptionalAllTypesResultValues.Tag.OptJSObject); + assert.equal(oatr_jsObjectSome_result.param0.key, "value"); + + const oatr_jsObjectNone = { tag: OptionalAllTypesResultValues.Tag.OptJSObject, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_jsObjectNone), oatr_jsObjectNone); + + const oatr_nestedEnumSome = { tag: OptionalAllTypesResultValues.Tag.OptNestedEnum, param0: { tag: APIResultValues.Tag.Failure, param0: 404 } }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_nestedEnumSome), oatr_nestedEnumSome); + + const oatr_nestedEnumNone = { tag: OptionalAllTypesResultValues.Tag.OptNestedEnum, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_nestedEnumNone), oatr_nestedEnumNone); + + const oatr_arraySome = { tag: OptionalAllTypesResultValues.Tag.OptArray, param0: [1, 2, 3] }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_arraySome), oatr_arraySome); + + const oatr_arrayNone = { tag: OptionalAllTypesResultValues.Tag.OptArray, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_arrayNone), oatr_arrayNone); + + const oatr_jsClassSome = { tag: OptionalAllTypesResultValues.Tag.OptJsClass, param0: new ImportedFoo("optEnumFoo") }; + const oatr_jsClassSome_result = exports.roundTripOptionalPayloadResult(oatr_jsClassSome); + assert.equal(oatr_jsClassSome_result.tag, OptionalAllTypesResultValues.Tag.OptJsClass); + assert.equal(oatr_jsClassSome_result.param0.value, "optEnumFoo"); + + const oatr_jsClassNone = { tag: OptionalAllTypesResultValues.Tag.OptJsClass, param0: null }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_jsClassNone), oatr_jsClassNone); + + const oatr_empty = { tag: OptionalAllTypesResultValues.Tag.Empty }; + assert.deepEqual(exports.roundTripOptionalPayloadResult(oatr_empty), oatr_empty); + + // Optional OptionalAllTypesResult roundtrip + assert.deepEqual(exports.roundTripOptionalPayloadResultOpt(oatr_structSome), oatr_structSome); + assert.deepEqual(exports.roundTripOptionalPayloadResultOpt(oatr_structNone), oatr_structNone); + assert.deepEqual(exports.roundTripOptionalPayloadResultOpt(oatr_empty), oatr_empty); + assert.equal(exports.roundTripOptionalPayloadResultOpt(null), null); + +} diff --git a/Tests/BridgeJSRuntimeTests/JavaScript/Types.mjs b/Tests/BridgeJSRuntimeTests/JavaScript/Types.mjs new file mode 100644 index 000000000..b4c2079d8 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/JavaScript/Types.mjs @@ -0,0 +1,6 @@ +export class ImportedFoo { + /** @param {string} value */ + constructor(value) { + this.value = value; + } +} diff --git a/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift b/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift new file mode 100644 index 000000000..adfd51dea --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift @@ -0,0 +1,231 @@ +import XCTest +@_spi(Experimental) import JavaScriptKit +import JavaScriptEventLoop + +@JSFunction func runJsOptionalSupportTests() throws + +final class OptionalSupportTests: XCTestCase { + func testRunJsOptionalSupportTests() throws { + try runJsOptionalSupportTests() + } + + func testRoundTripOptionalStringNull() throws { + try XCTAssertEqual(jsRoundTripOptionalStringNull("hello"), "hello") + try XCTAssertNil(jsRoundTripOptionalStringNull(nil)) + } + + func testRoundTripOptionalStringUndefined() throws { + let some = try jsRoundTripOptionalStringUndefined(.value("hi")) + switch some { + case .value(let value): + XCTAssertEqual(value, "hi") + case .undefined: + XCTFail("Expected defined value") + } + + let undefined = try jsRoundTripOptionalStringUndefined(.undefinedValue) + if case .value = undefined { + XCTFail("Expected undefined") + } + } + + func testRoundTripOptionalNumberNull() throws { + try XCTAssertEqual(jsRoundTripOptionalNumberNull(42), 42) + try XCTAssertNil(jsRoundTripOptionalNumberNull(nil)) + } + + func testRoundTripOptionalNumberUndefined() throws { + let some = try jsRoundTripOptionalNumberUndefined(.value(42)) + switch some { + case .value(let value): + XCTAssertEqual(value, 42) + case .undefined: + XCTFail("Expected defined value") + } + + let undefined = try jsRoundTripOptionalNumberUndefined(.undefined) + if case .value = undefined { + XCTFail("Expected undefined") + } + } +} + +// MARK: - Optional Bridging + +@JSFunction func jsRoundTripOptionalNumberNull(_ value: Int?) throws -> Int? +@JSFunction func jsRoundTripOptionalNumberUndefined(_ value: JSUndefinedOr) throws -> JSUndefinedOr +@JSFunction func jsRoundTripOptionalStringNull(_ name: String?) throws -> String? +@JSFunction func jsRoundTripOptionalStringUndefined(_ name: JSUndefinedOr) throws -> JSUndefinedOr + +@JS func roundTripOptionalString(name: String?) -> String? { + name +} + +@JS func roundTripOptionalInt(value: Int?) -> Int? { + value +} + +@JS func roundTripOptionalBool(flag: Bool?) -> Bool? { + flag +} + +@JS func roundTripOptionalFloat(number: Float?) -> Float? { + number +} + +@JS func roundTripOptionalDouble(precision: Double?) -> Double? { + precision +} + +@JS func roundTripOptionalSyntax(name: Optional) -> Optional { + name +} + +@JS func roundTripOptionalMixSyntax(name: String?) -> Optional { + name +} + +@JS func roundTripOptionalSwiftSyntax(name: Swift.Optional) -> Swift.Optional { + name +} + +@JS func roundTripOptionalWithSpaces(value: Optional) -> Optional { + value +} + +typealias OptionalAge = Int? +@JS func roundTripOptionalTypeAlias(age: OptionalAge) -> OptionalAge { + age +} + +@JS func roundTripOptionalStatus(value: Status?) -> Status? { + value +} + +@JS func roundTripOptionalTheme(value: Theme?) -> Theme? { + value +} + +@JS func roundTripOptionalHttpStatus(value: HttpStatus?) -> HttpStatus? { + value +} + +@JS func roundTripOptionalTSDirection(value: TSDirection?) -> TSDirection? { + value +} + +@JS func roundTripOptionalTSTheme(value: TSTheme?) -> TSTheme? { + value +} + +@JS func roundTripOptionalNetworkingAPIMethod(_ method: Networking.API.Method?) -> Networking.API.Method? { + method +} + +@JS func roundTripOptionalAPIResult(value: APIResult?) -> APIResult? { + value +} + +@JS func roundTripOptionalTypedPayloadResult(_ result: TypedPayloadResult?) -> TypedPayloadResult? { + result +} + +@JS func compareAPIResults(_ r1: APIResult?, _ r2: APIResult?) -> String { + let r1Str: String + switch r1 { + case .none: r1Str = "nil" + case .some(.success(let msg)): r1Str = "success:\(msg)" + case .some(.failure(let code)): r1Str = "failure:\(code)" + case .some(.info): r1Str = "info" + case .some(.flag(let b)): r1Str = "flag:\(b)" + case .some(.rate(let r)): r1Str = "rate:\(r)" + case .some(.precise(let p)): r1Str = "precise:\(p)" + } + + let r2Str: String + switch r2 { + case .none: r2Str = "nil" + case .some(.success(let msg)): r2Str = "success:\(msg)" + case .some(.failure(let code)): r2Str = "failure:\(code)" + case .some(.info): r2Str = "info" + case .some(.flag(let b)): r2Str = "flag:\(b)" + case .some(.rate(let r)): r2Str = "rate:\(r)" + case .some(.precise(let p)): r2Str = "precise:\(p)" + } + + return "r1:\(r1Str),r2:\(r2Str)" +} + +@JS func roundTripOptionalComplexResult(_ result: ComplexResult?) -> ComplexResult? { + result +} + +@JS func roundTripOptionalAllTypesResult(_ result: AllTypesResult?) -> AllTypesResult? { + result +} + +@JS +enum OptionalAllTypesResult { + case optStruct(Address?) + case optClass(Greeter?) + case optJSObject(JSObject?) + case optNestedEnum(APIResult?) + case optArray([Int]?) + case optJsClass(Foo?) + case empty +} + +@JS func roundTripOptionalPayloadResult(_ result: OptionalAllTypesResult) -> OptionalAllTypesResult { + result +} + +@JS func roundTripOptionalPayloadResultOpt(_ result: OptionalAllTypesResult?) -> OptionalAllTypesResult? { + result +} + +@JS func roundTripOptionalClass(value: Greeter?) -> Greeter? { + value +} + +@JS func roundTripOptionalGreeter(_ value: Greeter?) -> Greeter? { + value +} + +@JS func applyOptionalGreeter(_ value: Greeter?, _ transform: (Greeter?) -> Greeter?) -> Greeter? { + transform(value) +} + +@JS class OptionalHolder { + @JS var nullableGreeter: Greeter? + @JS var undefinedNumber: JSUndefinedOr + + @JS init(nullableGreeter: Greeter?, undefinedNumber: JSUndefinedOr) { + self.nullableGreeter = nullableGreeter + self.undefinedNumber = undefinedNumber + } +} + +@JS func makeOptionalHolder(nullableGreeter: Greeter?, undefinedNumber: JSUndefinedOr) -> OptionalHolder { + OptionalHolder(nullableGreeter: nullableGreeter, undefinedNumber: undefinedNumber) +} + +@JS class OptionalPropertyHolder { + @JS var optionalName: String? + @JS var optionalAge: Int? = nil + @JS var optionalGreeter: Greeter? = nil + + @JS init(optionalName: String?) { + self.optionalName = optionalName + } +} + +@JS +enum APIOptionalResult { + case success(String?) + case failure(Int?, Bool?) + case status(Bool?, Int?, String?) +} + +@JS func roundTripOptionalAPIOptionalResult(result: APIOptionalResult?) -> APIOptionalResult? { + result +} diff --git a/Tests/BridgeJSRuntimeTests/StructAPIs.swift b/Tests/BridgeJSRuntimeTests/StructAPIs.swift index 5c9fed511..49869e0f5 100644 --- a/Tests/BridgeJSRuntimeTests/StructAPIs.swift +++ b/Tests/BridgeJSRuntimeTests/StructAPIs.swift @@ -214,3 +214,48 @@ @JS func testContainerWithStruct(_ point: DataPoint) -> Container { return Container(location: point, config: nil) } + +// Struct with JSObject fields +@JS struct JSObjectContainer { + var object: JSObject + var optionalObject: JSObject? +} + +@JS func roundTripJSObjectContainer(_ container: JSObjectContainer) -> JSObjectContainer { + return container +} + +// Struct with @JSClass fields (Foo is defined in ExportAPITests.swift) +@JS struct FooContainer { + var foo: Foo + var optionalFoo: Foo? +} + +@JS func roundTripFooContainer(_ container: FooContainer) -> FooContainer { + return container +} + +@JS struct ArrayMembers { + var ints: [Int] + var optStrings: [String]? + + @JS func sumValues(_ values: [Int]) -> Int { + values.reduce(0, +) + } + + @JS func firstString(_ values: [String]) -> String? { + values.first + } +} + +@JS func roundTripArrayMembers(_ value: ArrayMembers) -> ArrayMembers { + value +} + +@JS func arrayMembersSum(_ value: ArrayMembers, _ values: [Int]) -> Int { + value.sumValues(values) +} + +@JS func arrayMembersFirst(_ value: ArrayMembers, _ values: [String]) -> String? { + value.firstString(values) +} diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index 983d6052d..ff69f5de9 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -2,6 +2,10 @@ export function jsRoundTripVoid(): void export function jsRoundTripNumber(v: number): number 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 @@ -31,3 +35,18 @@ export class $WeirdClass { constructor(); "method-with-dashes"(): string; } + +export class StaticBox { + constructor(value: number); + value(): number; + static create(value: number): StaticBox; + static value(): number; + 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 12307d605..92f5079d4 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -1,17 +1,56 @@ // @ts-check import { - DirectionValues, StatusValues, ThemeValues, HttpStatusValues, TSDirection, TSTheme, APIResultValues, ComplexResultValues, APIOptionalResultValues, StaticCalculatorValues, StaticPropertyEnumValues + DirectionValues, StatusValues, ThemeValues, HttpStatusValues, TSDirection, TSTheme, APIResultValues, ComplexResultValues, APIOptionalResultValues, StaticCalculatorValues, StaticPropertyEnumValues, PrecisionValues, TypedPayloadResultValues, AllTypesResultValues, OptionalAllTypesResultValues } from '../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.js'; +import { ImportedFoo } from './BridgeJSRuntimeTests/JavaScript/Types.mjs'; +import { runJsOptionalSupportTests } from './BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs'; /** @type {import('../.build/plugins/PackageToJS/outputs/PackageTests/test.d.ts').SetupOptionsFn} */ export async function setupOptions(options, context) { Error.stackTraceLimit = 100; setupTestGlobals(globalThis); + class StaticBox { + constructor(value) { + this._value = value; + } + value() { + return this._value; + } + static create(value) { + return new StaticBox(value); + } + static value() { + return 99; + } + static makeDefault() { + return new StaticBox(0); + } + static ["with-dashes"]() { + return new StaticBox(7); + } + } + 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; @@ -25,6 +64,33 @@ export async function setupOptions(options, context) { "jsRoundTripString": (v) => { return v; }, + "jsRoundTripOptionalNumberNull": (v) => { + return v ?? null; + }, + "jsRoundTripOptionalNumberUndefined": (v) => { + return v === undefined ? undefined : v; + }, + "jsRoundTripOptionalStringNull": (v) => { + return v ?? null; + }, + "jsRoundTripOptionalStringUndefined": (v) => { + return v === undefined ? undefined : v; + }, + "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"); @@ -51,9 +117,16 @@ export async function setupOptions(options, context) { "jsRoundTripFeatureFlag": (flag) => { return flag; }, + "jsEchoJSValue": (v) => { + return v; + }, "$jsWeirdFunction": () => { return 42; }, + ArrayHost, + makeArrayHost: (numbers, labels) => { + return new ArrayHost(numbers, labels); + }, JsGreeter: class { /** * @param {string} name @@ -78,6 +151,7 @@ export async function setupOptions(options, context) { return "ok"; } }, + StaticBox, Foo: ImportedFoo, runAsyncWorks: async () => { const exports = importsContext.getExports(); @@ -106,6 +180,29 @@ 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; + }, + runJsOptionalSupportTests: () => { + const exports = importsContext.getExports(); + if (!exports) { throw new Error("No exports!?"); } + runJsOptionalSupportTests(exports); } }; }, @@ -142,13 +239,6 @@ export async function setupOptions(options, context) { import assert from "node:assert"; -class ImportedFoo { - /** @param {string} value */ - constructor(value) { - this.value = value; - } -} - /** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { exports.roundTripVoid(); @@ -189,6 +279,16 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { ]) { assert.equal(exports.roundTripString(v), v); } + const arrayStruct = { ints: [1, 2, 3], optStrings: ["a", "b"] }; + const arrayStructRoundTrip = exports.roundTripArrayMembers(arrayStruct); + assert.deepEqual(arrayStructRoundTrip.ints, [1, 2, 3]); + assert.deepEqual(arrayStructRoundTrip.optStrings, ["a", "b"]); + assert.equal(exports.arrayMembersSum(arrayStruct, [10, 20]), 30); + assert.equal(exports.arrayMembersFirst(arrayStruct, ["x", "y"]), "x"); + const jsValueArray = [true, 42, "ok", { nested: 1 }, null, undefined]; + assert.deepEqual(exports.roundTripJSValueArray(jsValueArray), jsValueArray); + assert.deepEqual(exports.roundTripOptionalJSValueArray(jsValueArray), jsValueArray); + assert.equal(exports.roundTripOptionalJSValueArray(null), null); for (const p of [1, 4, 1024, 65536, 2147483647]) { assert.equal(exports.roundTripUnsafeRawPointer(p), p); @@ -436,6 +536,20 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { const anyObject = {}; assert.equal(exports.roundTripJSObject(anyObject), anyObject); + const symbolValue = Symbol("roundTrip"); + const bigIntValue = 12345678901234567890n; + const objectValue = { nested: true }; + const jsValues = [true, 42, "hello", objectValue, null, undefined, symbolValue, bigIntValue]; + for (const value of jsValues) { + const result = exports.roundTripJSValue(value); + assert.strictEqual(result, value); + } + + assert.strictEqual(exports.roundTripOptionalJSValue(null), null); + assert.strictEqual(exports.roundTripOptionalJSValue(undefined), null); + assert.strictEqual(exports.roundTripOptionalJSValue(objectValue), objectValue); + assert.strictEqual(exports.roundTripOptionalJSValue(symbolValue), symbolValue); + try { exports.throwsSwiftError(true); assert.fail("Expected error"); @@ -527,6 +641,11 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.equal(converter.toString(123), "123"); converter.release(); + assert.equal(exports.Utils.StringUtils.uppercase("hello"), "HELLO"); + assert.equal(exports.Utils.StringUtils.uppercase(""), ""); + assert.equal(exports.Utils.StringUtils.lowercase("WORLD"), "world"); + assert.equal(exports.Utils.StringUtils.lowercase("HeLLo"), "hello"); + const httpServer = new exports.Networking.API.HTTPServer(); httpServer.call(exports.Networking.API.Method.Get); httpServer.call(exports.Networking.API.Method.Post); @@ -611,102 +730,62 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.deepEqual(exports.makeAPINetworkingResultSuccess("Connected"), { tag: exports.API.NetworkingResult.Tag.Success, param0: "Connected" }); assert.deepEqual(exports.makeAPINetworkingResultFailure("Timeout", 408), { tag: exports.API.NetworkingResult.Tag.Failure, param0: "Timeout", param1: 408 }); - assert.equal(exports.roundTripOptionalString(null), null); - assert.equal(exports.roundTripOptionalInt(null), null); - assert.equal(exports.roundTripOptionalBool(null), null); - assert.equal(exports.roundTripOptionalFloat(null), null); - assert.equal(exports.roundTripOptionalDouble(null), null); - - assert.equal(exports.roundTripOptionalString("Hello"), "Hello"); - assert.equal(exports.roundTripOptionalInt(42), 42); - assert.equal(exports.roundTripOptionalBool(true), true); - assert.equal(exports.roundTripOptionalFloat(3.141592502593994), 3.141592502593994); // Float32 precision - assert.equal(exports.roundTripOptionalDouble(2.718), 2.718); - - assert.equal(exports.roundTripOptionalSyntax(null), null); - assert.equal(exports.roundTripOptionalSyntax("Test"), "Test"); - assert.equal(exports.roundTripOptionalMixSyntax(null), null); - assert.equal(exports.roundTripOptionalMixSyntax("Mix"), "Mix"); - assert.equal(exports.roundTripOptionalSwiftSyntax(null), null); - assert.equal(exports.roundTripOptionalSwiftSyntax("Swift"), "Swift"); - assert.equal(exports.roundTripOptionalWithSpaces(null), null); - assert.equal(exports.roundTripOptionalWithSpaces(1.618), 1.618); - assert.equal(exports.roundTripOptionalTypeAlias(null), null); - assert.equal(exports.roundTripOptionalTypeAlias(25), 25); - assert.equal(exports.roundTripOptionalStatus(exports.Status.Success), StatusValues.Success); - assert.equal(exports.roundTripOptionalTheme(exports.Theme.Light), ThemeValues.Light); - assert.equal(exports.roundTripOptionalHttpStatus(exports.HttpStatus.Ok), HttpStatusValues.Ok); - assert.equal(exports.roundTripOptionalTSDirection(TSDirection.North), TSDirection.North); - assert.equal(exports.roundTripOptionalTSTheme(TSTheme.Light), TSTheme.Light); - assert.equal(exports.roundTripOptionalNetworkingAPIMethod(exports.Networking.API.Method.Get), exports.Networking.API.Method.Get); - assert.deepEqual(exports.roundTripOptionalAPIResult(p1), p1); - assert.deepEqual(exports.roundTripOptionalComplexResult(cl1), cl1); - - const apiSuccess = { tag: exports.APIResult.Tag.Success, param0: "test success" }; - const apiFailure = { tag: exports.APIResult.Tag.Failure, param0: 404 }; - const apiInfo = { tag: exports.APIResult.Tag.Info }; - - assert.equal(exports.compareAPIResults(apiSuccess, apiFailure), "r1:success:test success,r2:failure:404"); - assert.equal(exports.compareAPIResults(null, apiInfo), "r1:nil,r2:info"); - assert.equal(exports.compareAPIResults(apiFailure, null), "r1:failure:404,r2:nil"); - assert.equal(exports.compareAPIResults(null, null), "r1:nil,r2:nil"); - - const optionalGreeter = new exports.Greeter("Schrödinger"); - const optionalGreeter2 = exports.roundTripOptionalClass(optionalGreeter); - assert.equal(optionalGreeter2?.greet() ?? "", "Hello, Schrödinger!"); - assert.equal(optionalGreeter2?.name ?? "", "Schrödinger"); - assert.equal(optionalGreeter2?.prefix ?? "", "Hello"); - assert.equal(exports.roundTripOptionalClass(null), null); - optionalGreeter.release(); - optionalGreeter2?.release(); - - const optionalsHolder = new exports.OptionalPropertyHolder(null); - - assert.equal(optionalsHolder.optionalName, null); - assert.equal(optionalsHolder.optionalAge, null); - assert.equal(optionalsHolder.optionalGreeter, null); - - optionalsHolder.optionalName = "Alice"; - optionalsHolder.optionalAge = 25; - assert.equal(optionalsHolder.optionalName, "Alice"); - assert.equal(optionalsHolder.optionalAge, 25); - - const testPropertyGreeter = new exports.Greeter("Bob"); - optionalsHolder.optionalGreeter = testPropertyGreeter; - assert.equal(optionalsHolder.optionalGreeter.greet(), "Hello, Bob!"); - assert.equal(optionalsHolder.optionalGreeter.name, "Bob"); - - optionalsHolder.optionalName = null; - optionalsHolder.optionalAge = null; - optionalsHolder.optionalGreeter = null; - assert.equal(optionalsHolder.optionalName, null); - assert.equal(optionalsHolder.optionalAge, null); - assert.equal(optionalsHolder.optionalGreeter, null); - testPropertyGreeter.release(); - optionalsHolder.release(); - - const aor1 = { tag: APIOptionalResultValues.Tag.Success, param0: "hello world" }; - const aor2 = { tag: APIOptionalResultValues.Tag.Success, param0: null }; - const aor3 = { tag: APIOptionalResultValues.Tag.Failure, param0: 404, param1: true }; - const aor4 = { tag: APIOptionalResultValues.Tag.Failure, param0: 404, param1: null }; - const aor5 = { tag: APIOptionalResultValues.Tag.Failure, param0: null, param1: null }; - const aor6 = { tag: APIOptionalResultValues.Tag.Status, param0: true, param1: 200, param2: "OK" }; - const aor7 = { tag: APIOptionalResultValues.Tag.Status, param0: true, param1: null, param2: "Partial" }; - const aor8 = { tag: APIOptionalResultValues.Tag.Status, param0: null, param1: null, param2: "Zero" }; - const aor9 = { tag: APIOptionalResultValues.Tag.Status, param0: false, param1: 500, param2: null }; - const aor10 = { tag: APIOptionalResultValues.Tag.Status, param0: null, param1: 0, param2: "Zero" }; - - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor1), aor1); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor2), aor2); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor3), aor3); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor4), aor4); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor5), aor5); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor6), aor6); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor7), aor7); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor8), aor8); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor9), aor9); - assert.deepEqual(exports.roundTripOptionalAPIOptionalResult(aor10), aor10); - assert.equal(exports.roundTripOptionalAPIOptionalResult(null), null); + // TypedPayloadResult — rawValueEnum and caseEnum as associated value payloads + assert.equal(exports.Precision.Rough, 0.1); + assert.equal(exports.Precision.Fine, 0.001); + + const tpr_precision = { tag: exports.TypedPayloadResult.Tag.Precision, param0: Math.fround(0.1) }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_precision), tpr_precision); + + const tpr_direction = { tag: exports.TypedPayloadResult.Tag.Direction, param0: exports.Direction.North }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_direction), tpr_direction); + + const tpr_dirSouth = { tag: exports.TypedPayloadResult.Tag.Direction, param0: exports.Direction.South }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_dirSouth), tpr_dirSouth); + + const tpr_optPrecisionSome = { tag: exports.TypedPayloadResult.Tag.OptPrecision, param0: Math.fround(0.001) }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_optPrecisionSome), tpr_optPrecisionSome); + + const tpr_optPrecisionNull = { tag: exports.TypedPayloadResult.Tag.OptPrecision, param0: null }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_optPrecisionNull), tpr_optPrecisionNull); + + const tpr_optDirectionSome = { tag: exports.TypedPayloadResult.Tag.OptDirection, param0: exports.Direction.East }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_optDirectionSome), tpr_optDirectionSome); + + const tpr_optDirectionNull = { tag: exports.TypedPayloadResult.Tag.OptDirection, param0: null }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_optDirectionNull), tpr_optDirectionNull); + + const tpr_empty = { tag: exports.TypedPayloadResult.Tag.Empty }; + assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_empty), tpr_empty); + + // AllTypesResult — struct, class, JSObject, nested enum, array as associated value payloads + const atr_struct = { tag: AllTypesResultValues.Tag.StructPayload, param0: { street: "100 Main St", city: "Boston", zipCode: 2101 } }; + assert.deepEqual(exports.roundTripAllTypesResult(atr_struct), atr_struct); + + const atr_class = { tag: AllTypesResultValues.Tag.ClassPayload, param0: new exports.Greeter("EnumUser") }; + const atr_class_result = exports.roundTripAllTypesResult(atr_class); + assert.equal(atr_class_result.tag, AllTypesResultValues.Tag.ClassPayload); + assert.equal(atr_class_result.param0.name, "EnumUser"); + + const atr_jsObject = { tag: AllTypesResultValues.Tag.JsObjectPayload, param0: { custom: "data", value: 42 } }; + const atr_jsObject_result = exports.roundTripAllTypesResult(atr_jsObject); + assert.equal(atr_jsObject_result.tag, AllTypesResultValues.Tag.JsObjectPayload); + assert.equal(atr_jsObject_result.param0.custom, "data"); + assert.equal(atr_jsObject_result.param0.value, 42); + + const atr_nestedEnum = { tag: AllTypesResultValues.Tag.NestedEnum, param0: { tag: APIResultValues.Tag.Success, param0: "nested!" } }; + assert.deepEqual(exports.roundTripAllTypesResult(atr_nestedEnum), atr_nestedEnum); + + const atr_array = { tag: AllTypesResultValues.Tag.ArrayPayload, param0: [10, 20, 30] }; + assert.deepEqual(exports.roundTripAllTypesResult(atr_array), atr_array); + + const atr_jsClass = { tag: AllTypesResultValues.Tag.JsClassPayload, param0: new ImportedFoo("enumFoo") }; + const atr_jsClass_result = exports.roundTripAllTypesResult(atr_jsClass); + assert.equal(atr_jsClass_result.tag, AllTypesResultValues.Tag.JsClassPayload); + assert.equal(atr_jsClass_result.param0.value, "enumFoo"); + + const atr_empty = { tag: AllTypesResultValues.Tag.Empty }; + assert.deepEqual(exports.roundTripAllTypesResult(atr_empty), atr_empty); assert.equal(exports.MathUtils.add(2147483647, 0), 2147483647); assert.equal(exports.StaticCalculator.roundtrip(42), 42); @@ -717,6 +796,11 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { assert.equal(exports.StaticUtils.Nested.roundtrip("hello world"), "hello world"); assert.equal(exports.StaticUtils.Nested.roundtrip("test"), "test"); + assert.equal(exports.Services.Graph.GraphOperations.createGraph(5), 50); + assert.equal(exports.Services.Graph.GraphOperations.createGraph(0), 0); + assert.equal(exports.Services.Graph.GraphOperations.nodeCount(42), 42); + assert.equal(exports.Services.Graph.GraphOperations.nodeCount(0), 0); + // Test default parameters assert.equal(exports.testStringDefault(), "Hello World"); assert.equal(exports.testStringDefault("Custom Message"), "Custom Message"); @@ -1154,6 +1238,32 @@ function testStructSupport(exports) { optionalRatio: null }; assert.deepEqual(exports.roundTripMeasurementConfig(mc2), mc2); + + // Struct with JSObject field + const containerObj1 = { value: "hello", nested: { x: 1 } }; + const containerObj2 = { items: [1, 2, 3] }; + const container1 = { object: containerObj1, optionalObject: containerObj2 }; + const containerResult1 = exports.roundTripJSObjectContainer(container1); + assert.equal(containerResult1.object, containerObj1); + assert.equal(containerResult1.optionalObject, containerObj2); + + const container2 = { object: containerObj1, optionalObject: null }; + const containerResult2 = exports.roundTripJSObjectContainer(container2); + assert.equal(containerResult2.object, containerObj1); + assert.equal(containerResult2.optionalObject, null); + + // Struct with @JSClass field + const foo1 = new ImportedFoo("first"); + const foo2 = new ImportedFoo("second"); + const fooContainer1 = { foo: foo1, optionalFoo: foo2 }; + const fooContainerResult1 = exports.roundTripFooContainer(fooContainer1); + assert.equal(fooContainerResult1.foo.value, "first"); + assert.equal(fooContainerResult1.optionalFoo.value, "second"); + + const fooContainer2 = { foo: foo1, optionalFoo: null }; + const fooContainerResult2 = exports.roundTripFooContainer(fooContainer2); + assert.equal(fooContainerResult2.foo.value, "first"); + assert.equal(fooContainerResult2.optionalFoo, null); } /** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ @@ -1385,6 +1495,8 @@ function testArraySupport(exports) { assert.deepEqual(exports.roundTripUnsafeRawPointerArray(pointerValues), pointerValues); assert.deepEqual(exports.roundTripUnsafeMutableRawPointerArray(pointerValues), pointerValues); assert.deepEqual(exports.roundTripOpaquePointerArray(pointerValues), pointerValues); + assert.deepEqual(exports.roundTripUnsafePointerArray(pointerValues), pointerValues); + assert.deepEqual(exports.roundTripUnsafeMutablePointerArray(pointerValues), pointerValues); assert.deepEqual(exports.roundTripUnsafeRawPointerArray([]), []); // Default values @@ -1425,6 +1537,36 @@ function testArraySupport(exports) { assert.equal(result[0].count, 1); helper1.release(); + + // JSObject arrays + const jsObj1 = { a: 1, b: "hello" }; + const jsObj2 = { x: [1, 2, 3], y: { nested: true } }; + const jsObjResult = exports.roundTripJSObjectArray([jsObj1, jsObj2]); + assert.equal(jsObjResult.length, 2); + assert.equal(jsObjResult[0], jsObj1); + assert.equal(jsObjResult[1], jsObj2); + assert.deepEqual(exports.roundTripJSObjectArray([]), []); + + const optJsResult = exports.roundTripOptionalJSObjectArray([jsObj1, null, jsObj2]); + assert.equal(optJsResult.length, 3); + assert.equal(optJsResult[0], jsObj1); + assert.equal(optJsResult[1], null); + assert.equal(optJsResult[2], jsObj2); + + // @JSClass struct arrays + const foo1 = new ImportedFoo("first"); + const foo2 = new ImportedFoo("second"); + const fooResult = exports.roundTripFooArray([foo1, foo2]); + assert.equal(fooResult.length, 2); + assert.equal(fooResult[0].value, "first"); + assert.equal(fooResult[1].value, "second"); + assert.deepEqual(exports.roundTripFooArray([]), []); + + const optFooResult = exports.roundTripOptionalFooArray([foo1, null, foo2]); + assert.equal(optFooResult.length, 3); + assert.equal(optFooResult[0].value, "first"); + assert.equal(optFooResult[1], null); + assert.equal(optFooResult[2].value, "second"); } /** @param {import('./../.build/plugins/PackageToJS/outputs/PackageTests/bridge-js.d.ts').Exports} exports */ diff --git a/Utilities/build-examples.sh b/Utilities/build-examples.sh index 4d99c8627..bc84e6943 100755 --- a/Utilities/build-examples.sh +++ b/Utilities/build-examples.sh @@ -2,7 +2,7 @@ set -euo pipefail -EXCLUDED_EXAMPLES=("Embedded") +EXCLUDED_EXAMPLES=() for example in Examples/*; do skip_example=false diff --git a/package-lock.json b/package-lock.json index bf7f36315..9366b618d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,8 @@ "rollup": "^4.37.0", "rollup-plugin-dts": "^6.2.1", "tslib": "^2.8.1", - "typescript": "^5.8.2" + "typescript": "^5.8.2", + "vitest": "^4.0.18" } }, "node_modules/@babel/code-frame": { @@ -51,11 +52,454 @@ "integrity": "sha512-54kpBQX69TZ8I1zyDC8sziv/zPT1zoIadv3CmdIZNZ5WDF1houMjAzRZ3dwWvhXObiEBjOxXyS8Ja7vA0EfGEQ==", "dev": true }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.2.tgz", + "integrity": "sha512-GZMB+a0mOMZs4MpDbj8RJp4cw+w1WV5NYD6xzgvzUJ5Ek2jerwfO2eADyI6ExDSUED+1X8aMbegahsJi+8mgpw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.2.tgz", + "integrity": "sha512-DVNI8jlPa7Ujbr1yjU2PfUSRtAUZPG9I1RwW4F4xFB1Imiu2on0ADiI/c3td+KmDtVKNbi+nffGDQMfcIMkwIA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.2.tgz", + "integrity": "sha512-pvz8ZZ7ot/RBphf8fv60ljmaoydPU12VuXHImtAs0XhLLw+EXBi2BLe3OYSBslR4rryHvweW5gmkKFwTiFy6KA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.2.tgz", + "integrity": "sha512-z8Ank4Byh4TJJOh4wpz8g2vDy75zFL0TlZlkUkEwYXuPSgX8yzep596n6mT7905kA9uHZsf/o2OJZubl2l3M7A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.2.tgz", + "integrity": "sha512-davCD2Zc80nzDVRwXTcQP/28fiJbcOwvdolL0sOiOsbwBa72kegmVU0Wrh1MYrbuCL98Omp5dVhQFWRKR2ZAlg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.2.tgz", + "integrity": "sha512-ZxtijOmlQCBWGwbVmwOF/UCzuGIbUkqB1faQRf5akQmxRJ1ujusWsb3CVfk/9iZKr2L5SMU5wPBi1UWbvL+VQA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.2.tgz", + "integrity": "sha512-lS/9CN+rgqQ9czogxlMcBMGd+l8Q3Nj1MFQwBZJyoEKI50XGxwuzznYdwcav6lpOGv5BqaZXqvBSiB/kJ5op+g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.2.tgz", + "integrity": "sha512-tAfqtNYb4YgPnJlEFu4c212HYjQWSO/w/h/lQaBK7RbwGIkBOuNKQI9tqWzx7Wtp7bTPaGC6MJvWI608P3wXYA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.2.tgz", + "integrity": "sha512-vWfq4GaIMP9AIe4yj1ZUW18RDhx6EPQKjwe7n8BbIecFtCQG4CfHGaHuh7fdfq+y3LIA2vGS/o9ZBGVxIDi9hw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.2.tgz", + "integrity": "sha512-hYxN8pr66NsCCiRFkHUAsxylNOcAQaxSSkHMMjcpx0si13t1LHFphxJZUiGwojB1a/Hd5OiPIqDdXONia6bhTw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.2.tgz", + "integrity": "sha512-MJt5BRRSScPDwG2hLelYhAAKh9imjHK5+NE/tvnRLbIqUWa+0E9N4WNMjmp/kXXPHZGqPLxggwVhz7QP8CTR8w==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.2.tgz", + "integrity": "sha512-lugyF1atnAT463aO6KPshVCJK5NgRnU4yb3FUumyVz+cGvZbontBgzeGFO1nF+dPueHD367a2ZXe1NtUkAjOtg==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.2.tgz", + "integrity": "sha512-nlP2I6ArEBewvJ2gjrrkESEZkB5mIoaTswuqNFRv/WYd+ATtUpe9Y09RnJvgvdag7he0OWgEZWhviS1OTOKixw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.2.tgz", + "integrity": "sha512-C92gnpey7tUQONqg1n6dKVbx3vphKtTHJaNG2Ok9lGwbZil6DrfyecMsp9CrmXGQJmZ7iiVXvvZH6Ml5hL6XdQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.2.tgz", + "integrity": "sha512-B5BOmojNtUyN8AXlK0QJyvjEZkWwy/FKvakkTDCziX95AowLZKR6aCDhG7LeF7uMCXEJqwa8Bejz5LTPYm8AvA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.2.tgz", + "integrity": "sha512-p4bm9+wsPwup5Z8f4EpfN63qNagQ47Ua2znaqGH6bqLlmJ4bx97Y9JdqxgGZ6Y8xVTixUnEkoKSHcpRlDnNr5w==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.2.tgz", + "integrity": "sha512-uwp2Tip5aPmH+NRUwTcfLb+W32WXjpFejTIOWZFw/v7/KnpCDKG66u4DLcurQpiYTiYwQ9B7KOeMJvLCu/OvbA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.2.tgz", + "integrity": "sha512-Kj6DiBlwXrPsCRDeRvGAUb/LNrBASrfqAIok+xB0LxK8CHqxZ037viF13ugfsIpePH93mX7xfJp97cyDuTZ3cw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.2.tgz", + "integrity": "sha512-HwGDZ0VLVBY3Y+Nw0JexZy9o/nUAWq9MlV7cahpaXKW6TOzfVno3y3/M8Ga8u8Yr7GldLOov27xiCnqRZf0tCA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.2.tgz", + "integrity": "sha512-DNIHH2BPQ5551A7oSHD0CKbwIA/Ox7+78/AWkbS5QoRzaqlev2uFayfSxq68EkonB+IKjiuxBFoV8ESJy8bOHA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.2.tgz", + "integrity": "sha512-/it7w9Nb7+0KFIzjalNJVR5bOzA9Vay+yIPLVHfIQYG/j+j9VTH84aNB8ExGKPU4AzfaEvN9/V4HV+F+vo8OEg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.2.tgz", + "integrity": "sha512-LRBbCmiU51IXfeXk59csuX/aSaToeG7w48nMwA6049Y4J4+VbWALAuXcs+qcD04rHDuSCSRKdmY63sruDS5qag==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.2.tgz", + "integrity": "sha512-kMtx1yqJHTmqaqHPAzKCAkDaKsffmXkPHThSfRwZGyuqyIeBvf08KSsYXl+abf5HDAPMJIPnbBfXvP2ZC2TfHg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.2.tgz", + "integrity": "sha512-Yaf78O/B3Kkh+nKABUF++bvJv5Ijoy9AN1ww904rOXZFLWVc5OLOfL56W+C8F9xn5JQZa3UX6m+IktJnIb1Jjg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.2.tgz", + "integrity": "sha512-Iuws0kxo4yusk7sw70Xa2E2imZU5HoixzxfGCdxwBdhiDgt9vX9VUCBhqcwY7/uh//78A1hMkkROMJq9l27oLQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.2.tgz", + "integrity": "sha512-sRdU18mcKf7F+YgheI/zGf5alZatMUTKj/jNS6l744f9u3WFu4v7twcUI9vu4mknF4Y9aDlblIie0IM+5xxaqQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", - "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", - "dev": true + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "dev": true, + "license": "MIT" }, "node_modules/@rollup/plugin-typescript": { "version": "12.1.2", @@ -108,9 +552,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.37.0.tgz", - "integrity": "sha512-l7StVw6WAa8l3vA1ov80jyetOAEo1FtHvZDbzXDO/02Sq/QVvqlHkYoFwDJPIMj0GKiistsBudfx5tGFnwYWDQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.57.1.tgz", + "integrity": "sha512-A6ehUVSiSaaliTxai040ZpZ2zTevHYbvu/lDoeAteHI8QnaosIzm4qwtezfRg1jOYaUmnzLX1AOD6Z+UJjtifg==", "cpu": [ "arm" ], @@ -122,9 +566,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.37.0.tgz", - "integrity": "sha512-6U3SlVyMxezt8Y+/iEBcbp945uZjJwjZimu76xoG7tO1av9VO691z8PkhzQ85ith2I8R2RddEPeSfcbyPfD4hA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.57.1.tgz", + "integrity": "sha512-dQaAddCY9YgkFHZcFNS/606Exo8vcLHwArFZ7vxXq4rigo2bb494/xKMMwRRQW6ug7Js6yXmBZhSBRuBvCCQ3w==", "cpu": [ "arm64" ], @@ -136,9 +580,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.37.0.tgz", - "integrity": "sha512-+iTQ5YHuGmPt10NTzEyMPbayiNTcOZDWsbxZYR1ZnmLnZxG17ivrPSWFO9j6GalY0+gV3Jtwrrs12DBscxnlYA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.57.1.tgz", + "integrity": "sha512-crNPrwJOrRxagUYeMn/DZwqN88SDmwaJ8Cvi/TN1HnWBU7GwknckyosC2gd0IqYRsHDEnXf328o9/HC6OkPgOg==", "cpu": [ "arm64" ], @@ -150,9 +594,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.37.0.tgz", - "integrity": "sha512-m8W2UbxLDcmRKVjgl5J/k4B8d7qX2EcJve3Sut7YGrQoPtCIQGPH5AMzuFvYRWZi0FVS0zEY4c8uttPfX6bwYQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.57.1.tgz", + "integrity": "sha512-Ji8g8ChVbKrhFtig5QBV7iMaJrGtpHelkB3lsaKzadFBe58gmjfGXAOfI5FV0lYMH8wiqsxKQ1C9B0YTRXVy4w==", "cpu": [ "x64" ], @@ -164,9 +608,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.37.0.tgz", - "integrity": "sha512-FOMXGmH15OmtQWEt174v9P1JqqhlgYge/bUjIbiVD1nI1NeJ30HYT9SJlZMqdo1uQFyt9cz748F1BHghWaDnVA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.57.1.tgz", + "integrity": "sha512-R+/WwhsjmwodAcz65guCGFRkMb4gKWTcIeLy60JJQbXrJ97BOXHxnkPFrP+YwFlaS0m+uWJTstrUA9o+UchFug==", "cpu": [ "arm64" ], @@ -178,9 +622,9 @@ ] }, "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.37.0.tgz", - "integrity": "sha512-SZMxNttjPKvV14Hjck5t70xS3l63sbVwl98g3FlVVx2YIDmfUIy29jQrsw06ewEYQ8lQSuY9mpAPlmgRD2iSsA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.57.1.tgz", + "integrity": "sha512-IEQTCHeiTOnAUC3IDQdzRAGj3jOAYNr9kBguI7MQAAZK3caezRrg0GxAb6Hchg4lxdZEI5Oq3iov/w/hnFWY9Q==", "cpu": [ "x64" ], @@ -192,9 +636,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.37.0.tgz", - "integrity": "sha512-hhAALKJPidCwZcj+g+iN+38SIOkhK2a9bqtJR+EtyxrKKSt1ynCBeqrQy31z0oWU6thRZzdx53hVgEbRkuI19w==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.57.1.tgz", + "integrity": "sha512-F8sWbhZ7tyuEfsmOxwc2giKDQzN3+kuBLPwwZGyVkLlKGdV1nvnNwYD0fKQ8+XS6hp9nY7B+ZeK01EBUE7aHaw==", "cpu": [ "arm" ], @@ -206,9 +650,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.37.0.tgz", - "integrity": "sha512-jUb/kmn/Gd8epbHKEqkRAxq5c2EwRt0DqhSGWjPFxLeFvldFdHQs/n8lQ9x85oAeVb6bHcS8irhTJX2FCOd8Ag==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.57.1.tgz", + "integrity": "sha512-rGfNUfn0GIeXtBP1wL5MnzSj98+PZe/AXaGBCRmT0ts80lU5CATYGxXukeTX39XBKsxzFpEeK+Mrp9faXOlmrw==", "cpu": [ "arm" ], @@ -220,9 +664,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.37.0.tgz", - "integrity": "sha512-oNrJxcQT9IcbcmKlkF+Yz2tmOxZgG9D9GRq+1OE6XCQwCVwxixYAa38Z8qqPzQvzt1FCfmrHX03E0pWoXm1DqA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.57.1.tgz", + "integrity": "sha512-MMtej3YHWeg/0klK2Qodf3yrNzz6CGjo2UntLvk2RSPlhzgLvYEB3frRvbEF2wRKh1Z2fDIg9KRPe1fawv7C+g==", "cpu": [ "arm64" ], @@ -234,9 +678,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.37.0.tgz", - "integrity": "sha512-pfxLBMls+28Ey2enpX3JvjEjaJMBX5XlPCZNGxj4kdJyHduPBXtxYeb8alo0a7bqOoWZW2uKynhHxF/MWoHaGQ==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.57.1.tgz", + "integrity": "sha512-1a/qhaaOXhqXGpMFMET9VqwZakkljWHLmZOX48R0I/YLbhdxr1m4gtG1Hq7++VhVUmf+L3sTAf9op4JlhQ5u1Q==", "cpu": [ "arm64" ], @@ -247,10 +691,24 @@ "linux" ] }, - "node_modules/@rollup/rollup-linux-loongarch64-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loongarch64-gnu/-/rollup-linux-loongarch64-gnu-4.37.0.tgz", - "integrity": "sha512-yCE0NnutTC/7IGUq/PUHmoeZbIwq3KRh02e9SfFh7Vmc1Z7atuJRYWhRME5fKgT8aS20mwi1RyChA23qSyRGpA==", + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.57.1.tgz", + "integrity": "sha512-QWO6RQTZ/cqYtJMtxhkRkidoNGXc7ERPbZN7dVW5SdURuLeVU7lwKMpo18XdcmpWYd0qsP1bwKPf7DNSUinhvA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.57.1.tgz", + "integrity": "sha512-xpObYIf+8gprgWaPP32xiN5RVTi/s5FCR+XMXSKmhfoJjrpRAjCuuqQXyxUa/eJTdAE6eJ+KDKaoEqjZQxh3Gw==", "cpu": [ "loong64" ], @@ -261,10 +719,24 @@ "linux" ] }, - "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.37.0.tgz", - "integrity": "sha512-NxcICptHk06E2Lh3a4Pu+2PEdZ6ahNHuK7o6Np9zcWkrBMuv21j10SQDJW3C9Yf/A/P7cutWoC/DptNLVsZ0VQ==", + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.57.1.tgz", + "integrity": "sha512-4BrCgrpZo4hvzMDKRqEaW1zeecScDCR+2nZ86ATLhAoJ5FQ+lbHVD3ttKe74/c7tNT9c6F2viwB3ufwp01Oh2w==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.57.1.tgz", + "integrity": "sha512-NOlUuzesGauESAyEYFSe3QTUguL+lvrN1HtwEEsU2rOwdUDeTMJdO5dUYl/2hKf9jWydJrO9OL/XSSf65R5+Xw==", "cpu": [ "ppc64" ], @@ -276,9 +748,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.37.0.tgz", - "integrity": "sha512-PpWwHMPCVpFZLTfLq7EWJWvrmEuLdGn1GMYcm5MV7PaRgwCEYJAwiN94uBuZev0/J/hFIIJCsYw4nLmXA9J7Pw==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.57.1.tgz", + "integrity": "sha512-ptA88htVp0AwUUqhVghwDIKlvJMD/fmL/wrQj99PRHFRAG6Z5nbWoWG4o81Nt9FT+IuqUQi+L31ZKAFeJ5Is+A==", "cpu": [ "riscv64" ], @@ -290,9 +762,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-musl": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.37.0.tgz", - "integrity": "sha512-DTNwl6a3CfhGTAOYZ4KtYbdS8b+275LSLqJVJIrPa5/JuIufWWZ/QFvkxp52gpmguN95eujrM68ZG+zVxa8zHA==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.57.1.tgz", + "integrity": "sha512-S51t7aMMTNdmAMPpBg7OOsTdn4tySRQvklmL3RpDRyknk87+Sp3xaumlatU+ppQ+5raY7sSTcC2beGgvhENfuw==", "cpu": [ "riscv64" ], @@ -304,103 +776,361 @@ ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.37.0.tgz", - "integrity": "sha512-hZDDU5fgWvDdHFuExN1gBOhCuzo/8TMpidfOR+1cPZJflcEzXdCy1LjnklQdW8/Et9sryOPJAKAQRw8Jq7Tg+A==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.57.1.tgz", + "integrity": "sha512-Bl00OFnVFkL82FHbEqy3k5CUCKH6OEJL54KCyx2oqsmZnFTR8IoNqBF+mjQVcRCT5sB6yOvK8A37LNm/kPJiZg==", "cpu": [ "s390x" ], "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ] + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.57.1.tgz", + "integrity": "sha512-ABca4ceT4N+Tv/GtotnWAeXZUZuM/9AQyCyKYyKnpk4yoA7QIAuBt6Hkgpw8kActYlew2mvckXkvx0FfoInnLg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.57.1.tgz", + "integrity": "sha512-HFps0JeGtuOR2convgRRkHCekD7j+gdAuXM+/i6kGzQtFhlCtQkpwtNzkNj6QhCDp7DRJ7+qC/1Vg2jt5iSOFw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.57.1.tgz", + "integrity": "sha512-H+hXEv9gdVQuDTgnqD+SQffoWoc0Of59AStSzTEj/feWTBAnSfSD3+Dql1ZruJQxmykT/JVY0dE8Ka7z0DH1hw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.57.1.tgz", + "integrity": "sha512-4wYoDpNg6o/oPximyc/NG+mYUejZrCU2q+2w6YZqrAs2UcNUChIZXjtafAiiZSUc7On8v5NyNj34Kzj/Ltk6dQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.57.1.tgz", + "integrity": "sha512-O54mtsV/6LW3P8qdTcamQmuC990HDfR71lo44oZMZlXU4tzLrbvTii87Ni9opq60ds0YzuAlEr/GNwuNluZyMQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.57.1.tgz", + "integrity": "sha512-P3dLS+IerxCT/7D2q2FYcRdWRl22dNbrbBEtxdWhXrfIMPP9lQhb5h4Du04mdl5Woq05jVCDPCMF7Ub0NAjIew==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.57.1.tgz", + "integrity": "sha512-VMBH2eOOaKGtIJYleXsi2B8CPVADrh+TyNxJ4mWPnKfLB/DBUmzW+5m1xUrcwWoMfSLagIRpjUFeW5CO5hyciQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.57.1.tgz", + "integrity": "sha512-mxRFDdHIWRxg3UfIIAwCm6NzvxG0jDX/wBN6KsQFTvKFqqg9vTrWUE68qEjHt19A5wwx5X5aUi2zuZT7YR0jrA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@standard-schema/spec": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.1.0.tgz", + "integrity": "sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "22.13.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.14.tgz", + "integrity": "sha512-Zs/Ollc1SJ8nKUAgc7ivOEdIBM8JAKgrqqUYi2J997JuKO7/tpQC+WCetQ1sypiKCQWHdvdg9wBNpUPEWZae7w==", + "dev": true, + "peer": true, + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/@vitest/expect": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.18.tgz", + "integrity": "sha512-8sCWUyckXXYvx4opfzVY03EOiYVxyNrHS5QxX3DAIi5dpJAAkyJezHCP77VMX4HKA2LDT/Jpfo8i2r5BE3GnQQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.0.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.0.18", + "@vitest/utils": "4.0.18", + "chai": "^6.2.1", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.18.tgz", + "integrity": "sha512-HhVd0MDnzzsgevnOWCBj5Otnzobjy5wLBe4EdeeFGv8luMsGcYqDuFRMcttKWZA5vVO8RFjexVovXvAM4JoJDQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.0.18", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0-0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/mocker/node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.18.tgz", + "integrity": "sha512-P24GK3GulZWC5tz87ux0m8OADrQIUVDPIjjj65vBXYG17ZeU3qD7r+MNZ1RNv4l8CGU2vtTRqixrOi9fYk/yKw==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.18.tgz", + "integrity": "sha512-rpk9y12PGa22Jg6g5M3UVVnTS7+zycIGk9ZNGN+m6tZHKQb7jrP7/77WfZy13Y/EUDd52NDsLRQhYKtv7XfPQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.0.18", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } }, - "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.37.0.tgz", - "integrity": "sha512-pKivGpgJM5g8dwj0ywBwe/HeVAUSuVVJhUTa/URXjxvoyTT/AxsLTAbkHkDHG7qQxLoW2s3apEIl26uUe08LVQ==", - "cpu": [ - "x64" - ], + "node_modules/@vitest/snapshot": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.18.tgz", + "integrity": "sha512-PCiV0rcl7jKQjbgYqjtakly6T1uwv/5BQ9SwBLekVg/EaYeQFPiXcgrC2Y7vDMA8dM1SUEAEV82kgSQIlXNMvA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ] + "dependencies": { + "@vitest/pretty-format": "4.0.18", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } }, - "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.37.0.tgz", - "integrity": "sha512-E2lPrLKE8sQbY/2bEkVTGDEk4/49UYRVWgj90MY8yPjpnGBQ+Xi1Qnr7b7UIWw1NOggdFQFOLZ8+5CzCiz143w==", - "cpu": [ - "x64" - ], + "node_modules/@vitest/spy": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.18.tgz", + "integrity": "sha512-cbQt3PTSD7P2OARdVW3qWER5EGq7PHlvE+QfzSC0lbwO+xnt7+XH06ZzFjFRgzUX//JmpxrCu92VdwvEPlWSNw==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "linux" - ] + "funding": { + "url": "https://opencollective.com/vitest" + } }, - "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.37.0.tgz", - "integrity": "sha512-Jm7biMazjNzTU4PrQtr7VS8ibeys9Pn29/1bm4ph7CP2kf21950LgN+BaE2mJ1QujnvOc6p54eWWiVvn05SOBg==", - "cpu": [ - "arm64" - ], + "node_modules/@vitest/utils": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.18.tgz", + "integrity": "sha512-msMRKLMVLWygpK3u2Hybgi4MNjcYJvwTb0Ru09+fOyCXIgT5raYP041DRRdiJiI3k/2U6SEbAETB3YtBrUkCFA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ] + "dependencies": { + "@vitest/pretty-format": "4.0.18", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } }, - "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.37.0.tgz", - "integrity": "sha512-e3/1SFm1OjefWICB2Ucstg2dxYDkDTZGDYgwufcbsxTHyqQps1UQf33dFEChBNmeSsTOyrjw2JJq0zbG5GF6RA==", - "cpu": [ - "ia32" - ], + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ] + "engines": { + "node": ">=12" + } }, - "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.37.0.tgz", - "integrity": "sha512-LWbXUBwn/bcLx2sSsqy7pK5o+Nr+VCoRoAohfJ5C/aBio9nfJmGQqHAhU6pwxV/RmyTk5AqdySma7uwWGlmeuA==", - "cpu": [ - "x64" - ], + "node_modules/chai": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz", + "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "win32" - ] + "engines": { + "node": ">=18" + } }, - "node_modules/@types/estree": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", - "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "node_modules/es-module-lexer": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", + "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", "dev": true, "license": "MIT" }, - "node_modules/@types/node": { - "version": "22.13.14", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.14.tgz", - "integrity": "sha512-Zs/Ollc1SJ8nKUAgc7ivOEdIBM8JAKgrqqUYi2J997JuKO7/tpQC+WCetQ1sypiKCQWHdvdg9wBNpUPEWZae7w==", + "node_modules/esbuild": { + "version": "0.27.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.2.tgz", + "integrity": "sha512-HyNQImnsOC7X9PMNaCIeAm4ISCQXs5a5YasTXVliKv4uuBo1dKrG0A+uQS8M5eXjVMnLg3WgXaKvprHlFJQffw==", "dev": true, - "dependencies": { - "undici-types": "~6.20.0" + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.27.2", + "@esbuild/android-arm": "0.27.2", + "@esbuild/android-arm64": "0.27.2", + "@esbuild/android-x64": "0.27.2", + "@esbuild/darwin-arm64": "0.27.2", + "@esbuild/darwin-x64": "0.27.2", + "@esbuild/freebsd-arm64": "0.27.2", + "@esbuild/freebsd-x64": "0.27.2", + "@esbuild/linux-arm": "0.27.2", + "@esbuild/linux-arm64": "0.27.2", + "@esbuild/linux-ia32": "0.27.2", + "@esbuild/linux-loong64": "0.27.2", + "@esbuild/linux-mips64el": "0.27.2", + "@esbuild/linux-ppc64": "0.27.2", + "@esbuild/linux-riscv64": "0.27.2", + "@esbuild/linux-s390x": "0.27.2", + "@esbuild/linux-x64": "0.27.2", + "@esbuild/netbsd-arm64": "0.27.2", + "@esbuild/netbsd-x64": "0.27.2", + "@esbuild/openbsd-arm64": "0.27.2", + "@esbuild/openbsd-x64": "0.27.2", + "@esbuild/openharmony-arm64": "0.27.2", + "@esbuild/sunos-x64": "0.27.2", + "@esbuild/win32-arm64": "0.27.2", + "@esbuild/win32-ia32": "0.27.2", + "@esbuild/win32-x64": "0.27.2" } }, "node_modules/estree-walker": { @@ -410,6 +1140,34 @@ "dev": true, "license": "MIT" }, + "node_modules/expect-type": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz", + "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -472,14 +1230,45 @@ "optional": true }, "node_modules/magic-string": { - "version": "0.30.17", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", - "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", "dev": true, + "license": "MIT", "dependencies": { - "@jridgewell/sourcemap-codec": "^1.5.0" + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/nanoid": { + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", + "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/obug": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.1.tgz", + "integrity": "sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT" + }, "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", @@ -487,17 +1276,23 @@ "dev": true, "license": "MIT" }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "dev": true, - "optional": true + "dev": true }, "node_modules/picomatch": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", - "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", + "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", "engines": { @@ -539,6 +1334,35 @@ "node": ">=18" } }, + "node_modules/postcss": { + "version": "8.5.6", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", + "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.11", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/prettier": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", @@ -577,14 +1401,14 @@ } }, "node_modules/rollup": { - "version": "4.37.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.37.0.tgz", - "integrity": "sha512-iAtQy/L4QFU+rTJ1YUjXqJOJzuwEghqWzCEYD2FEghT7Gsy1VdABntrO4CLopA5IkflTyqNiLNwPcOJ3S7UKLg==", + "version": "4.57.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.57.1.tgz", + "integrity": "sha512-oQL6lgK3e2QZeQ7gcgIkS2YZPg5slw37hYufJ3edKlfQSGGm8ICoxswK15ntSzF/a8+h7ekRy7k7oWc3BQ7y8A==", "dev": true, "license": "MIT", "peer": true, "dependencies": { - "@types/estree": "1.0.6" + "@types/estree": "1.0.8" }, "bin": { "rollup": "dist/bin/rollup" @@ -594,26 +1418,31 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.37.0", - "@rollup/rollup-android-arm64": "4.37.0", - "@rollup/rollup-darwin-arm64": "4.37.0", - "@rollup/rollup-darwin-x64": "4.37.0", - "@rollup/rollup-freebsd-arm64": "4.37.0", - "@rollup/rollup-freebsd-x64": "4.37.0", - "@rollup/rollup-linux-arm-gnueabihf": "4.37.0", - "@rollup/rollup-linux-arm-musleabihf": "4.37.0", - "@rollup/rollup-linux-arm64-gnu": "4.37.0", - "@rollup/rollup-linux-arm64-musl": "4.37.0", - "@rollup/rollup-linux-loongarch64-gnu": "4.37.0", - "@rollup/rollup-linux-powerpc64le-gnu": "4.37.0", - "@rollup/rollup-linux-riscv64-gnu": "4.37.0", - "@rollup/rollup-linux-riscv64-musl": "4.37.0", - "@rollup/rollup-linux-s390x-gnu": "4.37.0", - "@rollup/rollup-linux-x64-gnu": "4.37.0", - "@rollup/rollup-linux-x64-musl": "4.37.0", - "@rollup/rollup-win32-arm64-msvc": "4.37.0", - "@rollup/rollup-win32-ia32-msvc": "4.37.0", - "@rollup/rollup-win32-x64-msvc": "4.37.0", + "@rollup/rollup-android-arm-eabi": "4.57.1", + "@rollup/rollup-android-arm64": "4.57.1", + "@rollup/rollup-darwin-arm64": "4.57.1", + "@rollup/rollup-darwin-x64": "4.57.1", + "@rollup/rollup-freebsd-arm64": "4.57.1", + "@rollup/rollup-freebsd-x64": "4.57.1", + "@rollup/rollup-linux-arm-gnueabihf": "4.57.1", + "@rollup/rollup-linux-arm-musleabihf": "4.57.1", + "@rollup/rollup-linux-arm64-gnu": "4.57.1", + "@rollup/rollup-linux-arm64-musl": "4.57.1", + "@rollup/rollup-linux-loong64-gnu": "4.57.1", + "@rollup/rollup-linux-loong64-musl": "4.57.1", + "@rollup/rollup-linux-ppc64-gnu": "4.57.1", + "@rollup/rollup-linux-ppc64-musl": "4.57.1", + "@rollup/rollup-linux-riscv64-gnu": "4.57.1", + "@rollup/rollup-linux-riscv64-musl": "4.57.1", + "@rollup/rollup-linux-s390x-gnu": "4.57.1", + "@rollup/rollup-linux-x64-gnu": "4.57.1", + "@rollup/rollup-linux-x64-musl": "4.57.1", + "@rollup/rollup-openbsd-x64": "4.57.1", + "@rollup/rollup-openharmony-arm64": "4.57.1", + "@rollup/rollup-win32-arm64-msvc": "4.57.1", + "@rollup/rollup-win32-ia32-msvc": "4.57.1", + "@rollup/rollup-win32-x64-gnu": "4.57.1", + "@rollup/rollup-win32-x64-msvc": "4.57.1", "fsevents": "~2.3.2" } }, @@ -639,6 +1468,37 @@ "typescript": "^4.5 || ^5.0" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", + "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", + "dev": true, + "license": "MIT" + }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -652,6 +1512,50 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.2.tgz", + "integrity": "sha512-W/KYk+NFhkmsYpuHq5JykngiOCnxeVL8v8dFnqxSD8qEEdRfXk1SDM6JzNqcERbcGYj9tMrDQBYV9cjgnunFIg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", + "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.3" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyrainbow": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.0.3.tgz", + "integrity": "sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -680,6 +1584,191 @@ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", "dev": true + }, + "node_modules/vite": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.1.tgz", + "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.27.0", + "fdir": "^6.5.0", + "picomatch": "^4.0.3", + "postcss": "^8.5.6", + "rollup": "^4.43.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "lightningcss": "^1.21.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vite/node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/vitest": { + "version": "4.0.18", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.18.tgz", + "integrity": "sha512-hOQuK7h0FGKgBAas7v0mSAsnvrIgAvWmRFjmzpJ7SwFHH3g1k2u37JtYwOwmEKhK6ZO3v9ggDBBm0La1LCK4uQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.0.18", + "@vitest/mocker": "4.0.18", + "@vitest/pretty-format": "4.0.18", + "@vitest/runner": "4.0.18", + "@vitest/snapshot": "4.0.18", + "@vitest/spy": "4.0.18", + "@vitest/utils": "4.0.18", + "es-module-lexer": "^1.7.0", + "expect-type": "^1.2.2", + "magic-string": "^0.30.21", + "obug": "^2.1.1", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^3.10.0", + "tinybench": "^2.9.0", + "tinyexec": "^1.0.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.0.3", + "vite": "^6.0.0 || ^7.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.0.18", + "@vitest/browser-preview": "4.0.18", + "@vitest/browser-webdriverio": "4.0.18", + "@vitest/ui": "4.0.18", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } } } } diff --git a/package.json b/package.json index da7d5356d..1f3f1871b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "rollup": "^4.37.0", "rollup-plugin-dts": "^6.2.1", "tslib": "^2.8.1", - "typescript": "^5.8.2" + "typescript": "^5.8.2", + "vitest": "^4.0.18" } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..c13ef64e3 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "strict": true, + "skipLibCheck": true + } +}