From 4fa48cf5dd6c5b686b22d832b1953f495d746de4 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Feb 2026 16:18:51 +0700 Subject: [PATCH 01/34] BridgeJS: Fix namespace enum with `@JS(namespace:)` attribute (#562) --- .../Sources/BridgeJSCore/ExportSwift.swift | 9 +- .../BridgeJSCore/SwiftToSkeleton.swift | 8 +- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 10 +- .../Inputs/EnumNamespace.swift | 15 +- .../EnumNamespace.Export.d.ts | 9 + .../BridgeJSLinkTests/EnumNamespace.Export.js | 24 +++ .../EnumNamespace.Global.Export.d.ts | 18 ++ .../EnumNamespace.Global.Export.js | 36 ++++ .../EnumNamespace.Global.json | 123 ++++++++++++ .../EnumNamespace.Global.swift | 47 +++++ .../ExportSwiftTests/EnumNamespace.json | 123 ++++++++++++ .../ExportSwiftTests/EnumNamespace.swift | 47 +++++ .../StaticFunctions.Global.json | 2 +- .../ExportSwiftTests/StaticFunctions.json | 2 +- .../StaticProperties.Global.json | 10 +- .../ExportSwiftTests/StaticProperties.json | 10 +- .../Generated/JavaScript/BridgeJS.json | 10 +- .../BridgeJSRuntimeTests/ExportAPITests.swift | 21 ++ .../Generated/BridgeJS.swift | 44 +++++ .../Generated/JavaScript/BridgeJS.json | 185 +++++++++++++++++- Tests/prelude.mjs | 10 + 21 files changed, 723 insertions(+), 40 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index d7d5c8200..1f8f72ad7 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -533,14 +533,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 { diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index ea79d3f3b..b780012f0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -990,7 +990,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 +1188,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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 33cc94479..5013dda66 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -242,7 +242,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 +533,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 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift index 26a4e9c3a..dbf044834 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/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/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.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.Export.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.Export.js index b01148873..1eb483365 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js @@ -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/EnumNamespace.Global.Export.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.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.Export.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.Export.js index 77c327e8d..f48a0050e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js @@ -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__/ExportSwiftTests/EnumNamespace.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json index 42a084c44..135908d7f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json @@ -400,6 +400,129 @@ ], "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, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift index 9683b5307..43e3f69a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift @@ -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__/ExportSwiftTests/EnumNamespace.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json index 23bb06429..374ae13f4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json @@ -400,6 +400,129 @@ ], "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, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift index 9683b5307..43e3f69a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift @@ -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__/ExportSwiftTests/StaticFunctions.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json index 3b6937c30..0eec726c8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json @@ -311,7 +311,7 @@ }, "staticContext" : { "namespaceEnum" : { - + "_0" : "Utils.String" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json index 652465dff..372504135 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json @@ -311,7 +311,7 @@ }, "staticContext" : { "namespaceEnum" : { - + "_0" : "Utils.String" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json index 4ec19f83c..28457fb63 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json @@ -220,7 +220,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace" } }, "type" : { @@ -238,7 +238,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace" } }, "type" : { @@ -274,7 +274,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { @@ -293,7 +293,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { @@ -312,7 +312,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json index 0e8b2de22..829c20718 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json @@ -220,7 +220,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace" } }, "type" : { @@ -238,7 +238,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace" } }, "type" : { @@ -274,7 +274,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { @@ -293,7 +293,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { @@ -312,7 +312,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "PropertyNamespace.Nested" } }, "type" : { 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..f82106ac1 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -295,6 +295,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 { @@ -788,6 +798,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 { diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 35a53805d..42f360ce7 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -1350,6 +1350,28 @@ extension TSDirection: _BridgedSwiftCaseEnum { extension TSTheme: _BridgedSwiftEnumNoPayload { } +@_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 { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { return bridgeJSRawValue @@ -1992,6 +2014,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 diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index c79139ea4..5d75ef55e 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -3500,6 +3500,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", @@ -4356,7 +4441,7 @@ }, "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticUtils.Nested" } } } @@ -4367,6 +4452,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 +4674,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace" } }, "type" : { @@ -4519,7 +4692,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace" } }, "type" : { @@ -4555,7 +4728,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -4574,7 +4747,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { @@ -4593,7 +4766,7 @@ ], "staticContext" : { "namespaceEnum" : { - + "_0" : "StaticPropertyNamespace.NestedProperties" } }, "type" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 12307d605..0319ce424 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -527,6 +527,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); @@ -717,6 +722,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"); From d0724f291a7c66b464653284edb0ff1aef7070dd Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Feb 2026 17:33:06 +0700 Subject: [PATCH 02/34] BridgeJS: Add intrinsic extensions for stack-based lifting and refactor Swift glue code generation to use them (#554) BridgeJS: Add reusable intrinsics for stack-based types --- .../Sources/Generated/BridgeJS.Macros.swift | 2 +- Benchmarks/Sources/Generated/BridgeJS.swift | 514 +++------ .../Generated/BridgeJS.Macros.swift | 2 +- .../Sources/BridgeJSCore/ExportSwift.swift | 244 ++--- .../Sources/TS2Swift/JavaScript/src/cli.js | 2 +- .../TS2Swift/JavaScript/src/processor.js | 4 +- .../ExportSwiftTests/ArrayTypes.swift | 299 +----- .../ExportSwiftTests/DefaultParameters.swift | 108 +- .../EnumAssociatedValue.swift | 272 ++--- .../EnumNamespace.Global.swift | 4 +- .../ExportSwiftTests/EnumNamespace.swift | 4 +- .../ExportSwiftTests/EnumRawType.swift | 24 +- .../ExportSwiftTests/Protocol.swift | 67 +- .../StaticFunctions.Global.swift | 18 +- .../ExportSwiftTests/StaticFunctions.swift | 18 +- .../ExportSwiftTests/SwiftClosure.swift | 40 +- .../ExportSwiftTests/SwiftStruct.swift | 79 +- .../ExportSwiftTests/UnsafePointer.swift | 20 +- .../ImportTSTests/ArrayParameter.Macros.swift | 2 +- .../ImportTSTests/Async.Macros.swift | 2 +- .../ImportTSTests/Interface.Macros.swift | 2 +- .../InvalidPropertyNames.Macros.swift | 2 +- .../MultipleImportedTypes.Macros.swift | 2 +- .../PrimitiveParameters.Macros.swift | 2 +- .../PrimitiveReturn.Macros.swift | 2 +- .../ImportTSTests/ReExportFrom.Macros.swift | 2 +- .../ImportTSTests/StringEnum.Macros.swift | 4 +- .../StringParameter.Macros.swift | 2 +- .../ImportTSTests/StringReturn.Macros.swift | 2 +- .../TS2SkeletonLike.Macros.swift | 2 +- .../ImportTSTests/TypeAlias.Macros.swift | 2 +- .../TypeScriptClass.Macros.swift | 2 +- .../VoidParameterVoidReturn.Macros.swift | 2 +- Plugins/PackageToJS/Templates/instantiate.js | 3 + .../JavaScriptKit/BridgeJSIntrinsics.swift | 355 ++++++- .../Generated/BridgeJS.swift | 4 +- .../BridgeJSRuntimeTests/ExportAPITests.swift | 6 + .../Generated/BridgeJS.Macros.swift | 4 +- .../Generated/BridgeJS.swift | 981 +++++------------- .../Generated/JavaScript/BridgeJS.json | 78 ++ Tests/prelude.mjs | 2 + 41 files changed, 1223 insertions(+), 1963 deletions(-) diff --git a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift index bc2ceb32b..edf727004 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift @@ -4,7 +4,7 @@ // 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 diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 86f4c87dc..1a413268d 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) @@ -68,22 +65,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() case .flag(let param0): _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() case .rate(let param0): _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() case .precise(let param0): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() 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) @@ -189,58 +162,37 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() case .location(let param0, let param1, let param2): _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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() case .status(let param0, let param1, let param2): _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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() case .coordinates(let param0, let param1, let param2): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() 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(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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() 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/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift index 221302716..cc62396ea 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift @@ -4,7 +4,7 @@ // 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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 1f8f72ad7..0c5debeac 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -793,60 +793,56 @@ 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, .swiftStruct, .swiftHeapObject: + return "\(raw: type.swiftType).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 .associatedValueEnum: + return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" 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 .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, + .jsObject, .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()" + case .swiftProtocol(let protocolName): + return "[Any\(raw: protocolName)].bridgeJSLiftParameter()" + case .optional, .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 """ @@ -865,45 +861,9 @@ struct StackCodegen { private func liftOptionalExpression(wrappedType: BridgeType) -> ExprSyntax { 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, + .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: + return "Optional<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" case .array(let elementType): let arrayLift = liftArrayExpression(elementType: elementType) let swiftTypeName = elementType.swiftType @@ -917,9 +877,8 @@ struct StackCodegen { } }() """ - default: - // Fallback for other optional types - return "Optional.bridgeJSLiftParameter(_swift_js_pop_i32(), _swift_js_pop_i32())" + case .void, .namespaceEnum, .closure, .optional, .unsafePointer, .swiftProtocol: + fatalError("Invalid optional wrapped type: \(wrappedType)") } } @@ -935,56 +894,23 @@ 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 .string, .int, .uint, .bool, .float, .double: + return ["\(raw: accessor).bridgeJSLowerStackReturn()"] 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())"] + return ["\(raw: accessor).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): 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) } @@ -994,6 +920,29 @@ struct StackCodegen { elementType: BridgeType, accessor: String, varPrefix: String + ) -> [CodeBlockItemSyntax] { + switch elementType { + case .int, .uint, .float, .double, .string, .bool, + .jsObject, .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return ["\(raw: accessor).bridgeJSLowerReturn()"] + case .swiftProtocol(let protocolName): + return ["\(raw: accessor).map { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"] + case .optional, .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)" @@ -1042,43 +991,20 @@ 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: + 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())"] + return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] case .array(let elementType): return lowerArrayStatements(elementType: elementType, accessor: unwrappedVar, varPrefix: varPrefix) default: @@ -1145,7 +1071,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 { diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js index 645be1f5a..922b8dbbc 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/cli.js @@ -154,7 +154,7 @@ export function main(args) { "// To update this file, just rebuild your project or run", "// `swift package bridge-js`.", "", - "@_spi(Experimental) import JavaScriptKit", + "@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit", "", "", ].join("\n"); diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index e48510466..1d2d0f64f 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -399,7 +399,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 +410,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; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift index 711694c9d..55a6258b0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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,19 +436,8 @@ public func _bjs_processNestedPointArray() -> Void { @_cdecl("bjs_processItemArray") public func _bjs_processItemArray() -> Void { #if arch(wasm32) - let ret = processItemArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Item] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Item.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 = processItemArray(_: [Item].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -644,24 +452,13 @@ public func _bjs_processNestedItemArray() -> Void { var __result: [[Item]] = [] __result.reserveCapacity(__count) for _ in 0 ..< __count { - __result.append({ - let __count = Int(_swift_js_pop_i32()) - var __result: [Item] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Item.bridgeJSLiftParameter(_swift_js_pop_pointer())) - } - __result.reverse() - return __result - }()) + __result.append([Item].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") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift index 5232bdd53..4c4c69c99 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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__/ExportSwiftTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift index e35da2f77..0854cba74 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift @@ -2,15 +2,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: @@ -23,22 +23,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) @@ -59,22 +56,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() case .flag(let param0): _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() case .rate(let param0): _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() case .precise(let param0): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() case .info: _swift_js_push_tag(Int32(5)) } @@ -85,15 +79,15 @@ 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 .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 3: - 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 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())) + 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: @@ -106,50 +100,32 @@ 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 .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) 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(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)) - } + 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) @@ -170,50 +146,32 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() 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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() 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) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() 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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() case .info: _swift_js_push_tag(Int32(5)) } @@ -224,11 +182,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)") } @@ -239,25 +197,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) } } @@ -276,25 +225,16 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() 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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() } } } @@ -303,9 +243,9 @@ 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())) + 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 NetworkingResult case ID: \(caseId)") } @@ -316,17 +256,11 @@ extension 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) } } @@ -345,17 +279,11 @@ extension NetworkingResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() } } } @@ -364,11 +292,11 @@ 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())) + return .success(Optional.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 .failure(Optional.bridgeJSLiftParameter(), Optional.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 .status(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) default: fatalError("Unknown APIOptionalResult case ID: \(caseId)") } @@ -381,42 +309,36 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + __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 { - _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) + __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 { - _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)) + __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 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) return Int32(2) @@ -439,42 +361,36 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { _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)) - } + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _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)) + __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) + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() } _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) + __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)) + __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 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift index 43e3f69a4..b1b5e9c8c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift index 43e3f69a4..b1b5e9c8c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift index 12fdeba04..55c902af0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift index 0558e2a1f..21178521d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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) } } @@ -404,37 +401,25 @@ extension Result: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() } } } -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__/ExportSwiftTests/StaticFunctions.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift index 378eff8bb..ed6cb98c0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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) } } @@ -86,13 +83,10 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift index 378eff8bb..ed6cb98c0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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) } } @@ -86,13 +83,10 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift index 415aa54f6..df6046693 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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) @@ -734,22 +731,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() case .flag(let param0): _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() case .rate(let param0): _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() case .precise(let param0): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() case .info: _swift_js_push_tag(Int32(5)) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift index af4428979..9b7ddd024 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift index 4c368908b..752cc6bc3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/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__/ImportTSTests/ArrayParameter.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift index cf1118df0..551385093 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift @@ -4,7 +4,7 @@ // 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 checkArray(_ a: JSObject) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift index dd0377377..032fcadfc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift @@ -4,7 +4,7 @@ // 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 asyncReturnVoid() throws (JSException) -> JSPromise diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift index 5d13234ca..8c60cd218 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift @@ -4,7 +4,7 @@ // 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 returnAnimatable() throws (JSException) -> Animatable diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift index 43d6a3eb9..37ccd0287 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift @@ -4,7 +4,7 @@ // 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 createArrayBuffer() throws (JSException) -> ArrayBufferLike diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift index 47efcbc84..f7b2ebc3b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift @@ -4,7 +4,7 @@ // 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 createDatabaseConnection(_ config: JSObject) throws (JSException) -> DatabaseConnection diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift index eea42f30d..72f503afa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift @@ -4,6 +4,6 @@ // 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 check(_ a: Double, _ b: Bool) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift index 15867131d..1f24ec359 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift @@ -4,7 +4,7 @@ // 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 checkNumber() throws (JSException) -> Double diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift index 0c0dfb362..f71778e26 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift @@ -4,7 +4,7 @@ // 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 jsRoundTripNumber(_ v: Double) throws (JSException) -> Double diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift index b0049af28..7140ecac7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift @@ -4,13 +4,13 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -@_spi(Experimental) import JavaScriptKit +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit enum FeatureFlag: String { case foo = "foo" case bar = "bar" } -extension FeatureFlag: _BridgedSwiftEnumNoPayload {} +extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift index 38fe0dd2b..75ba0eefd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift @@ -4,7 +4,7 @@ // 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 checkString(_ a: String) 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 index 60aae03c4..c7618d7ac 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift @@ -4,6 +4,6 @@ // 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 checkString() throws (JSException) -> String diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift index e0d6c9d24..eab06f1db 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift @@ -4,7 +4,7 @@ // 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 createTS2Skeleton() throws (JSException) -> TypeScriptProcessor diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift index 62b2b4663..ef9500566 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift @@ -4,6 +4,6 @@ // 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 checkSimple(_ a: Double) throws (JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift index 1fbf3376d..a0857a57e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift @@ -4,7 +4,7 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -@_spi(Experimental) import JavaScriptKit +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit @JSClass struct Greeter { @JSGetter var name: String diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift index b3a7fc6f6..7247e3aff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift @@ -4,6 +4,6 @@ // 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 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..7b2d97f06 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,13 @@ public protocol _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { consuming func bridgeJSLowerReturn() -> WasmCoreType } -extension Bool: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType { +public protocol _BridgedSwiftStackType { + associatedtype StackLiftResult = Self + static func bridgeJSLiftParameter() -> StackLiftResult + consuming func bridgeJSLowerStackReturn() +} + +extension Bool: _BridgedSwiftTypeLoweredIntoSingleWasmCoreType, _BridgedSwiftStackType { // MARK: ImportTS @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { self ? 1 : 0 @@ -106,12 +117,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 +140,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 +163,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 +222,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 +245,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 +289,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 +328,23 @@ 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()) + } } /// 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 +363,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 +398,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 +427,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 +459,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 +482,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 +515,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 +845,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 +877,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 +907,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 +939,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 +971,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,9 +1003,15 @@ 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 { @@ -847,6 +1041,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: @@ -897,6 +1097,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 { @@ -943,6 +1149,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 +1196,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 +1245,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: @@ -1053,7 +1278,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 +1346,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 +1366,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 +1393,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 +1441,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 +1487,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 +1552,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 +1591,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 +1621,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 +1652,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 +1693,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 +1737,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 +1774,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 +1789,25 @@ extension Optional where Wrapped: _BridgedSwiftStruct { } } } + +// MARK: - Array Support + +extension Array where Element: _BridgedSwiftStackType, Element.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.. [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 diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index b0b24137a..6836000c6 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -4,7 +4,7 @@ // 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 @@ -26,7 +26,7 @@ enum FeatureFlag: String { case foo = "foo" case bar = "bar" } -extension FeatureFlag: _BridgedSwiftEnumNoPayload {} +extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @JSFunction func jsRoundTripFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> FeatureFlag diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 42f360ce7..55a77466e 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -1292,16 +1292,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 +1347,7 @@ extension TSDirection: _BridgedSwiftCaseEnum { } } -extension TSTheme: _BridgedSwiftEnumNoPayload { +extension TSTheme: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum { } @_expose(wasm, "bjs_Utils_StringUtils_static_uppercase") @@ -1415,10 +1415,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 { @@ -1460,15 +1460,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: @@ -1481,22 +1481,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) @@ -1517,22 +1514,19 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() case .failure(let param0): _swift_js_push_tag(Int32(1)) - _swift_js_push_i32(Int32(param0)) + param0.bridgeJSLowerStackReturn() case .flag(let param0): _swift_js_push_tag(Int32(2)) - _swift_js_push_i32(param0 ? 1 : 0) + param0.bridgeJSLowerStackReturn() case .rate(let param0): _swift_js_push_tag(Int32(3)) - _swift_js_push_f32(param0) + param0.bridgeJSLowerStackReturn() case .precise(let param0): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) + param0.bridgeJSLowerStackReturn() case .info: _swift_js_push_tag(Int32(5)) } @@ -1543,17 +1537,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: @@ -1566,58 +1560,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) @@ -1638,58 +1611,37 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() case .location(let param0, let param1, let param2): _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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() case .status(let param0, let param1, let param2): _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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() case .coordinates(let param0, let param1, let param2): _swift_js_push_tag(Int32(4)) - _swift_js_push_f64(param0) - _swift_js_push_f64(param1) - _swift_js_push_f64(param2) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() 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(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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() + param3.bridgeJSLowerStackReturn() + param4.bridgeJSLowerStackReturn() + param5.bridgeJSLowerStackReturn() + param6.bridgeJSLowerStackReturn() + param7.bridgeJSLowerStackReturn() + param8.bridgeJSLowerStackReturn() case .info: _swift_js_push_tag(Int32(6)) } @@ -1700,11 +1652,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)") } @@ -1715,25 +1667,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) } } @@ -1752,25 +1695,16 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() 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)) - } + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() + param2.bridgeJSLowerStackReturn() } } } @@ -1779,9 +1713,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)") } @@ -1792,17 +1726,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) } } @@ -1821,17 +1749,11 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + param0.bridgeJSLowerStackReturn() 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)) + param0.bridgeJSLowerStackReturn() + param1.bridgeJSLowerStackReturn() } } } @@ -1840,11 +1762,11 @@ 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())) + return .success(Optional.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 .failure(Optional.bridgeJSLiftParameter(), Optional.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 .status(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) default: fatalError("Unknown APIOptionalResult case ID: \(caseId)") } @@ -1857,42 +1779,36 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { 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)) - } + __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 { - _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) + __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 { - _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)) + __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 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) return Int32(2) @@ -1915,42 +1831,36 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { _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)) - } + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _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)) + __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) + __bjs_unwrapped_param1.bridgeJSLowerStackReturn() } _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) + __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)) + __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 { - var __bjs_str_param2 = __bjs_unwrapped_param2 - __bjs_str_param2.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - } + __bjs_unwrapped_param2.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) } @@ -2264,14 +2174,14 @@ public func _bjs_StaticPropertyNamespace_NestedProperties_static_nestedDouble_se 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()) + let y = Int.bridgeJSLiftParameter() + let x = Int.bridgeJSLiftParameter() return Point(x: x, y: y) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - _swift_js_push_i32(Int32(self.x)) - _swift_js_push_i32(Int32(self.y)) + self.x.bridgeJSLowerStackReturn() + self.y.bridgeJSLowerStackReturn() } init(unsafelyCopying jsObject: JSObject) { @@ -2309,20 +2219,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) { @@ -2371,29 +2281,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) } @@ -2444,24 +2351,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) } @@ -2501,27 +2402,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 @@ -2567,31 +2462,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) { @@ -2629,16 +2518,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) } @@ -2678,19 +2567,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 @@ -2735,31 +2624,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()) @@ -2767,7 +2650,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 @@ -2818,24 +2701,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) } @@ -2875,12 +2758,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) { @@ -2962,19 +2845,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) } @@ -3025,17 +2905,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) { @@ -3073,14 +2950,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 { @@ -3135,17 +3012,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) { @@ -4610,16 +4484,7 @@ public func _bjs_testEmptyInit(_ object: UnsafeMutableRawPointer) -> UnsafeMutab @_cdecl("bjs_arrayWithDefault") public func _bjs_arrayWithDefault() -> Int32 { #if arch(wasm32) - let ret = arrayWithDefault(_: { - 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 = arrayWithDefault(_: [Int].bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -4634,16 +4499,7 @@ public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { 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() } }()) return ret.bridgeJSLowerReturn() @@ -4656,16 +4512,7 @@ public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { @_cdecl("bjs_arrayMixedDefaults") public func _bjs_arrayMixedDefaults(_ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { #if arch(wasm32) - let ret = arrayMixedDefaults(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength), 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 - }(), suffix: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) + 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") @@ -4709,19 +4556,8 @@ public func _bjs_makeAdder(_ base: Int32) -> UnsafeMutableRawPointer { @_cdecl("bjs_roundTripIntArray") public func _bjs_roundTripIntArray() -> Void { #if arch(wasm32) - let ret = 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 = roundTripIntArray(_: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4731,22 +4567,8 @@ public func _bjs_roundTripIntArray() -> Void { @_cdecl("bjs_roundTripStringArray") public func _bjs_roundTripStringArray() -> Void { #if arch(wasm32) - let ret = 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 = roundTripStringArray(_: [String].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4756,19 +4578,8 @@ public func _bjs_roundTripStringArray() -> Void { @_cdecl("bjs_roundTripDoubleArray") public func _bjs_roundTripDoubleArray() -> 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())) - } - __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 = roundTripDoubleArray(_: [Double].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4778,19 +4589,8 @@ public func _bjs_roundTripDoubleArray() -> Void { @_cdecl("bjs_roundTripBoolArray") public func _bjs_roundTripBoolArray() -> 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())) - } - __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 = roundTripBoolArray(_: [Bool].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4800,19 +4600,8 @@ public func _bjs_roundTripBoolArray() -> Void { @_cdecl("bjs_roundTripDirectionArray") public func _bjs_roundTripDirectionArray() -> 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())) - } - __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 = roundTripDirectionArray(_: [Direction].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4822,19 +4611,8 @@ public func _bjs_roundTripDirectionArray() -> Void { @_cdecl("bjs_roundTripStatusArray") public func _bjs_roundTripStatusArray() -> Void { #if arch(wasm32) - let ret = roundTripStatusArray(_: { - 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 = roundTripStatusArray(_: [Status].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4844,22 +4622,8 @@ public func _bjs_roundTripStatusArray() -> Void { @_cdecl("bjs_roundTripThemeArray") public func _bjs_roundTripThemeArray() -> Void { #if arch(wasm32) - let ret = roundTripThemeArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Theme] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(Theme.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.rawValue - __bjs_ret_elem.withUTF8 { ptr in - _swift_js_push_string(ptr.baseAddress, Int32(ptr.count)) - }} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripThemeArray(_: [Theme].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4869,19 +4633,8 @@ public func _bjs_roundTripThemeArray() -> Void { @_cdecl("bjs_roundTripHttpStatusArray") public func _bjs_roundTripHttpStatusArray() -> Void { #if arch(wasm32) - let ret = roundTripHttpStatusArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [HttpStatus] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __result.append(HttpStatus.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 = roundTripHttpStatusArray(_: [HttpStatus].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4891,19 +4644,8 @@ public func _bjs_roundTripHttpStatusArray() -> Void { @_cdecl("bjs_roundTripDataPointArray") public func _bjs_roundTripDataPointArray() -> Void { #if arch(wasm32) - let ret = roundTripDataPointArray(_: { - 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 - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripDataPointArray(_: [DataPoint].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4913,19 +4655,8 @@ public func _bjs_roundTripDataPointArray() -> Void { @_cdecl("bjs_roundTripGreeterArray") public func _bjs_roundTripGreeterArray() -> Void { #if arch(wasm32) - let ret = roundTripGreeterArray(_: { - 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 - }()) - for __bjs_elem_ret in ret { - _swift_js_push_pointer(__bjs_elem_ret.bridgeJSLowerReturn())} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripGreeterArray(_: [Greeter].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4940,7 +4671,7 @@ public func _bjs_roundTripOptionalIntArray() -> 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 @@ -4948,7 +4679,7 @@ public func _bjs_roundTripOptionalIntArray() -> 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 @@ -4965,7 +4696,7 @@ public func _bjs_roundTripOptionalStringArray() -> 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 @@ -4973,10 +4704,7 @@ public func _bjs_roundTripOptionalStringArray() -> 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 @@ -4993,7 +4721,7 @@ public func _bjs_roundTripOptionalDataPointArray() -> 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 @@ -5018,7 +4746,7 @@ public func _bjs_roundTripOptionalDirectionArray() -> 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 @@ -5026,7 +4754,7 @@ public func _bjs_roundTripOptionalDirectionArray() -> 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 @@ -5043,7 +4771,7 @@ public func _bjs_roundTripOptionalStatusArray() -> 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 @@ -5051,7 +4779,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.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -5067,23 +4795,12 @@ public func _bjs_roundTripOptionalIntArrayType(_ 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") @@ -5098,26 +4815,12 @@ public func _bjs_roundTripOptionalStringArrayType(_ values: Int32) -> Void { 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 - }() + return [String].bridgeJSLiftParameter() } }()) 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))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") @@ -5132,23 +4835,12 @@ public func _bjs_roundTripOptionalGreeterArrayType(_ greeters: Int32) -> Void { 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 - }() + return [Greeter].bridgeJSLiftParameter() } }()) 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))} + __bjs_unwrapped_ret.bridgeJSLowerReturn()} _swift_js_push_i32(__bjs_isSome_ret ? 1 : 0) #else fatalError("Only available on WebAssembly") @@ -5164,24 +4856,13 @@ public func _bjs_roundTripNestedIntArray() -> 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") @@ -5197,27 +4878,13 @@ public func _bjs_roundTripNestedStringArray() -> 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") @@ -5233,24 +4900,13 @@ public func _bjs_roundTripNestedDoubleArray() -> Void { 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.append([Double].bridgeJSLiftParameter()) } __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))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -5266,24 +4922,13 @@ public func _bjs_roundTripNestedBoolArray() -> Void { 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.append([Bool].bridgeJSLiftParameter()) } __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))} + __bjs_elem_ret.bridgeJSLowerReturn()} _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -5299,24 +4944,13 @@ public func _bjs_roundTripNestedDataPointArray() -> Void { 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.append([DataPoint].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") @@ -5332,24 +4966,13 @@ public func _bjs_roundTripNestedDirectionArray() -> Void { 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.append([Direction].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.bridgeJSLowerParameter()))} - _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") @@ -5365,24 +4988,13 @@ public func _bjs_roundTripNestedGreeterArray() -> Void { 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.append([Greeter].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") @@ -5393,19 +5005,8 @@ public func _bjs_roundTripNestedGreeterArray() -> Void { @_cdecl("bjs_roundTripUnsafeRawPointerArray") public func _bjs_roundTripUnsafeRawPointerArray() -> 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 = roundTripUnsafeRawPointerArray(_: [UnsafeRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -5415,19 +5016,8 @@ public func _bjs_roundTripUnsafeRawPointerArray() -> Void { @_cdecl("bjs_roundTripUnsafeMutableRawPointerArray") public func _bjs_roundTripUnsafeMutableRawPointerArray() -> 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 = roundTripUnsafeMutableRawPointerArray(_: [UnsafeMutableRawPointer].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -5437,19 +5027,30 @@ public func _bjs_roundTripUnsafeMutableRawPointerArray() -> Void { @_cdecl("bjs_roundTripOpaquePointerArray") public func _bjs_roundTripOpaquePointerArray() -> 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 = 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 @@ -5459,16 +5060,7 @@ public func _bjs_roundTripOpaquePointerArray() -> Void { @_cdecl("bjs_consumeDataProcessorArrayType") public func _bjs_consumeDataProcessorArrayType() -> Int32 { #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 = consumeDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -5479,19 +5071,10 @@ public func _bjs_consumeDataProcessorArrayType() -> Int32 { @_cdecl("bjs_roundTripDataProcessorArrayType") public func _bjs_roundTripDataProcessorArrayType() -> 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 = roundTripDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + ret.map { + $0 as! AnyDataProcessor + } .bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 5d75ef55e..e31c69a51 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -9310,6 +9310,84 @@ } } }, + { + "abiName" : "bjs_roundTripUnsafePointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripUnsafePointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } + } + } + } + } + }, + { + "abiName" : "bjs_roundTripUnsafeMutablePointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripUnsafeMutablePointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } + } + } + } + } + }, { "abiName" : "bjs_consumeDataProcessorArrayType", "effects" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 0319ce424..684ff02fc 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -1395,6 +1395,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 From 794e7862bf526aec3eb80607b08e183b10398e8a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 3 Feb 2026 20:02:07 +0900 Subject: [PATCH 03/34] BridgeJS: Re-organize snapshot test structure (#561) --- .github/workflows/test.yml | 2 +- .gitignore | 2 +- CONTRIBUTING.md | 6 + Plugins/BridgeJS/Package.swift | 2 +- Plugins/BridgeJS/README.md | 8 +- .../Sources/TS2Swift/JavaScript/package.json | 3 + .../Sources/TS2Swift/JavaScript/src/cli.js | 129 +- .../test/__snapshots__/ts2swift.test.js.snap | 313 ++++ .../test/fixtures}/ArrayParameter.d.ts | 0 .../JavaScript/test/fixtures}/Async.d.ts | 0 .../JavaScript/test/fixtures}/Interface.d.ts | 0 .../test/fixtures}/InvalidPropertyNames.d.ts | 0 .../test/fixtures}/MultipleImportedTypes.d.ts | 0 .../test/fixtures}/PrimitiveParameters.d.ts | 0 .../test/fixtures}/PrimitiveReturn.d.ts | 0 .../test/fixtures}/ReExportFrom.d.ts | 0 .../JavaScript/test/fixtures}/StringEnum.d.ts | 0 .../test/fixtures}/StringParameter.d.ts | 0 .../test/fixtures}/StringReturn.d.ts | 0 .../fixtures}/Support/ReExportTarget.d.ts | 0 .../test/fixtures}/TS2SkeletonLike.d.ts | 0 .../JavaScript/test/fixtures}/TypeAlias.d.ts | 0 .../test/fixtures}/TypeScriptClass.d.ts | 0 .../fixtures}/VoidParameterVoidReturn.d.ts | 0 .../JavaScript/test/fixtures}/tsconfig.json | 0 .../TS2Swift/JavaScript/test/ts2swift.test.js | 41 + .../TS2Swift/JavaScript/vitest.config.js | 9 + .../JSGetterMacroTests.swift | 2 +- .../BridgeJSCodegenTests.swift | 169 ++ .../BridgeJSToolTests/BridgeJSLinkTests.swift | 61 +- .../BridgeJSToolTests/ExportSwiftTests.swift | 158 -- .../BridgeJSToolTests/ImportTSTests.swift | 101 -- .../Inputs/{ => MacroSwift}/ArrayTypes.swift | 4 + .../Inputs/{ => MacroSwift}/Async.swift | 0 .../{ => MacroSwift}/DefaultParameters.swift | 0 .../EnumAssociatedValue.swift | 0 .../Inputs/{ => MacroSwift}/EnumCase.swift | 0 .../{ => MacroSwift}/EnumNamespace.swift | 0 .../Inputs/{ => MacroSwift}/EnumRawType.swift | 10 + .../MacroSwift}/GlobalGetter.swift | 0 .../MacroSwift}/GlobalThisImports.swift | 0 .../ImportedTypeInExportedInterface.swift | 0 .../MacroSwift/InvalidPropertyNames.swift | 29 + .../Inputs/MacroSwift/JSClass.swift | 15 + .../Inputs/{ => MacroSwift}/MixedGlobal.swift | 0 .../{ => MacroSwift}/MixedPrivate.swift | 0 .../Multifile}/CrossFileClassA.swift | 0 .../Multifile}/CrossFileClassB.swift | 0 .../Multifile}/CrossFileFunctionA.swift | 0 .../Multifile}/CrossFileFunctionB.swift | 0 .../Inputs/{ => MacroSwift}/Namespaces.swift | 0 .../Inputs/{ => MacroSwift}/Optionals.swift | 0 .../MacroSwift/PrimitiveParameters.swift | 2 + .../{ => MacroSwift}/PrimitiveReturn.swift | 3 + .../{ => MacroSwift}/PropertyTypes.swift | 0 .../Inputs/{ => MacroSwift}/Protocol.swift | 0 .../{ => MacroSwift}/StaticFunctions.swift | 0 .../{ => MacroSwift}/StaticProperties.swift | 0 .../Inputs/MacroSwift/StringParameter.swift | 5 + .../Inputs/MacroSwift/StringReturn.swift | 2 + .../Inputs/{ => MacroSwift}/SwiftClass.swift | 0 .../{ => MacroSwift}/SwiftClosure.swift | 0 .../MacroSwift}/SwiftClosureImports.swift | 0 .../Inputs/{ => MacroSwift}/SwiftStruct.swift | 0 .../MacroSwift}/SwiftStructImports.swift | 0 .../Inputs/{ => MacroSwift}/Throws.swift | 0 .../{ => MacroSwift}/UnsafePointer.swift | 0 .../MacroSwift/VoidParameterVoidReturn.swift | 2 + .../Inputs/PrimitiveParameters.swift | 1 - .../Inputs/StringParameter.swift | 2 - .../Inputs/StringReturn.swift | 1 - .../Inputs/VoidParameterVoidReturn.swift | 1 - .../TS2SwiftVitestTests.swift | 34 + .../BridgeJSCodegenTests/ArrayTypes.json | 1059 +++++++++++ .../ArrayTypes.swift | 54 +- .../BridgeJSCodegenTests/Async.json | 187 ++ .../Async.swift | 0 .../CrossFileFunctionTypes.ReverseOrder.json | 152 ++ .../CrossFileFunctionTypes.ReverseOrder.swift | 0 .../CrossFileFunctionTypes.json | 152 ++ .../CrossFileFunctionTypes.swift | 0 .../CrossFileTypeResolution.ReverseOrder.json | 64 + ...CrossFileTypeResolution.ReverseOrder.swift | 0 .../CrossFileTypeResolution.json | 64 + .../CrossFileTypeResolution.swift | 0 .../DefaultParameters.json | 1273 ++++++++++++++ .../DefaultParameters.swift | 0 .../EnumAssociatedValue.json | 847 +++++++++ .../EnumAssociatedValue.swift | 0 .../BridgeJSCodegenTests/EnumCase.json | 323 ++++ .../EnumCase.swift | 0 .../EnumNamespace.Global.json | 541 ++++++ .../EnumNamespace.Global.swift | 0 .../BridgeJSCodegenTests/EnumNamespace.json | 541 ++++++ .../EnumNamespace.swift | 0 .../BridgeJSCodegenTests/EnumRawType.json | 1543 +++++++++++++++++ .../EnumRawType.swift | 44 +- .../BridgeJSCodegenTests/GlobalGetter.json | 71 + .../GlobalGetter.swift} | 4 +- .../GlobalThisImports.json | 126 ++ .../GlobalThisImports.swift} | 10 +- .../ImportedTypeInExportedInterface.json | 65 + .../ImportedTypeInExportedInterface.swift | 17 + .../InvalidPropertyNames.json | 258 +++ .../InvalidPropertyNames.swift | 99 +- .../BridgeJSCodegenTests/JSClass.json | 172 ++ .../JSClass.swift} | 68 +- .../BridgeJSCodegenTests/MixedGlobal.json | 79 + .../MixedGlobal.swift | 0 .../BridgeJSCodegenTests/MixedPrivate.json | 79 + .../MixedPrivate.swift | 0 .../Namespaces.Global.json | 185 ++ .../Namespaces.Global.swift | 0 .../BridgeJSCodegenTests/Namespaces.json | 185 ++ .../Namespaces.swift | 0 .../BridgeJSCodegenTests/Optionals.json | 702 ++++++++ .../Optionals.swift | 0 .../PrimitiveParameters.json | 118 ++ .../PrimitiveParameters.swift | 27 + .../BridgeJSCodegenTests/PrimitiveReturn.json | 138 ++ .../PrimitiveReturn.swift | 34 + .../BridgeJSCodegenTests/PropertyTypes.json | 363 ++++ .../PropertyTypes.swift | 0 .../BridgeJSCodegenTests/Protocol.json | 901 ++++++++++ .../Protocol.swift | 0 .../StaticFunctions.Global.json | 339 ++++ .../StaticFunctions.Global.swift | 0 .../BridgeJSCodegenTests/StaticFunctions.json | 339 ++++ .../StaticFunctions.swift | 0 .../StaticProperties.Global.json | 342 ++++ .../StaticProperties.Global.swift | 0 .../StaticProperties.json | 342 ++++ .../StaticProperties.swift | 0 .../BridgeJSCodegenTests/StringParameter.json | 125 ++ .../StringParameter.swift | 25 +- .../BridgeJSCodegenTests/StringReturn.json | 59 + .../StringReturn.swift | 13 +- .../BridgeJSCodegenTests/SwiftClass.json | 145 ++ .../SwiftClass.swift | 0 .../BridgeJSCodegenTests/SwiftClosure.json | 1078 ++++++++++++ .../SwiftClosure.swift | 0 .../SwiftClosureImports.json | 110 ++ .../SwiftClosureImports.swift} | 30 +- .../BridgeJSCodegenTests/SwiftStruct.json | 523 ++++++ .../SwiftStruct.swift | 0 .../SwiftStructImports.json | 94 + .../SwiftStructImports.swift | 64 + .../BridgeJSCodegenTests/Throws.json | 37 + .../Throws.swift | 0 .../BridgeJSCodegenTests/UnsafePointer.json | 416 +++++ .../UnsafePointer.swift | 0 .../VoidParameterVoidReturn.json | 59 + .../VoidParameterVoidReturn.swift | 12 +- .../ArrayParameter.Import.d.ts | 20 - .../ArrayParameter.Import.js | 245 --- ...ArrayTypes.Export.d.ts => ArrayTypes.d.ts} | 3 + .../{ArrayTypes.Export.js => ArrayTypes.js} | 23 + .../BridgeJSLinkTests/Async.Import.d.ts | 24 - .../BridgeJSLinkTests/Async.Import.js | 289 --- .../{Async.Export.d.ts => Async.d.ts} | 0 .../{Async.Export.js => Async.js} | 0 ...ers.Export.d.ts => DefaultParameters.d.ts} | 0 ...ameters.Export.js => DefaultParameters.js} | 0 ...e.Export.d.ts => EnumAssociatedValue.d.ts} | 0 ...Value.Export.js => EnumAssociatedValue.js} | 0 .../{EnumCase.Export.d.ts => EnumCase.d.ts} | 0 .../{EnumCase.Export.js => EnumCase.js} | 0 ....Export.d.ts => EnumNamespace.Global.d.ts} | 0 ...obal.Export.js => EnumNamespace.Global.js} | 0 ...mespace.Export.d.ts => EnumNamespace.d.ts} | 0 ...umNamespace.Export.js => EnumNamespace.js} | 0 ...umRawType.Export.d.ts => EnumRawType.d.ts} | 2 + .../{EnumRawType.Export.js => EnumRawType.js} | 45 +- ...er.ImportMacros.d.ts => GlobalGetter.d.ts} | 0 ...Getter.ImportMacros.js => GlobalGetter.js} | 0 ...portMacros.d.ts => GlobalThisImports.d.ts} | 0 ...s.ImportMacros.js => GlobalThisImports.js} | 0 ...s => ImportedTypeInExportedInterface.d.ts} | 0 ....js => ImportedTypeInExportedInterface.js} | 0 .../BridgeJSLinkTests/Interface.Import.d.ts | 22 - .../BridgeJSLinkTests/Interface.Import.js | 251 --- ....Import.d.ts => InvalidPropertyNames.d.ts} | 5 - ...ames.Import.js => InvalidPropertyNames.js} | 27 - ...peScriptClass.Import.d.ts => JSClass.d.ts} | 5 + .../{TypeScriptClass.Import.js => JSClass.js} | 27 + ...xedGlobal.Export.d.ts => MixedGlobal.d.ts} | 0 .../{MixedGlobal.Export.js => MixedGlobal.js} | 0 ...dModules.Export.d.ts => MixedModules.d.ts} | 0 ...MixedModules.Export.js => MixedModules.js} | 0 ...dPrivate.Export.d.ts => MixedPrivate.d.ts} | 0 ...MixedPrivate.Export.js => MixedPrivate.js} | 0 .../MultipleImportedTypes.Import.d.ts | 36 - .../MultipleImportedTypes.Import.js | 354 ---- ...bal.Export.d.ts => Namespaces.Global.d.ts} | 0 ....Global.Export.js => Namespaces.Global.js} | 0 ...Namespaces.Export.d.ts => Namespaces.d.ts} | 0 .../{Namespaces.Export.js => Namespaces.js} | 0 .../{Optionals.Export.d.ts => Optionals.d.ts} | 0 .../{Optionals.Export.js => Optionals.js} | 0 .../PrimitiveParameters.Export.js | 225 --- .../PrimitiveParameters.Import.d.ts | 18 - ...s.Export.d.ts => PrimitiveParameters.d.ts} | 1 + ...eters.Import.js => PrimitiveParameters.js} | 3 + .../PrimitiveReturn.Import.d.ts | 19 - .../PrimitiveReturn.Import.js | 242 --- ...eturn.Export.d.ts => PrimitiveReturn.d.ts} | 2 + ...iveReturn.Export.js => PrimitiveReturn.js} | 20 + ...tyTypes.Export.d.ts => PropertyTypes.d.ts} | 0 ...opertyTypes.Export.js => PropertyTypes.js} | 0 .../{Protocol.Export.d.ts => Protocol.d.ts} | 0 .../{Protocol.Export.js => Protocol.js} | 0 .../ReExportFrom.Import.d.ts | 24 - .../BridgeJSLinkTests/ReExportFrom.Import.js | 252 --- ...xport.d.ts => StaticFunctions.Global.d.ts} | 0 ...al.Export.js => StaticFunctions.Global.js} | 0 ...tions.Export.d.ts => StaticFunctions.d.ts} | 0 ...Functions.Export.js => StaticFunctions.js} | 0 ...port.d.ts => StaticProperties.Global.d.ts} | 0 ...l.Export.js => StaticProperties.Global.js} | 0 ...ties.Export.d.ts => StaticProperties.d.ts} | 0 ...operties.Export.js => StaticProperties.js} | 0 .../BridgeJSLinkTests/StringEnum.Import.d.ts | 19 - .../BridgeJSLinkTests/StringEnum.Import.js | 242 --- .../StringParameter.Export.d.ts | 19 - .../StringParameter.Export.js | 237 --- ...meter.Import.d.ts => StringParameter.d.ts} | 2 + ...Parameter.Import.js => StringParameter.js} | 15 + .../BridgeJSLinkTests/StringReturn.Export.js | 228 --- .../StringReturn.Import.d.ts | 18 - ...ngReturn.Export.d.ts => StringReturn.d.ts} | 1 + ...StringReturn.Import.js => StringReturn.js} | 6 + ...SwiftClass.Export.d.ts => SwiftClass.d.ts} | 0 .../{SwiftClass.Export.js => SwiftClass.js} | 0 ...tClosure.Export.d.ts => SwiftClosure.d.ts} | 0 ...SwiftClosure.Export.js => SwiftClosure.js} | 0 ...rtMacros.d.ts => SwiftClosureImports.d.ts} | 0 ...ImportMacros.js => SwiftClosureImports.js} | 0 ...iftStruct.Export.d.ts => SwiftStruct.d.ts} | 0 .../{SwiftStruct.Export.js => SwiftStruct.js} | 0 ...ortMacros.d.ts => SwiftStructImports.d.ts} | 0 ....ImportMacros.js => SwiftStructImports.js} | 0 .../TS2SkeletonLike.Import.d.ts | 28 - .../TS2SkeletonLike.Import.js | 293 ---- .../{Throws.Export.d.ts => Throws.d.ts} | 0 .../{Throws.Export.js => Throws.js} | 0 .../BridgeJSLinkTests/TypeAlias.Import.d.ts | 18 - .../BridgeJSLinkTests/TypeAlias.Import.js | 231 --- ...Pointer.Export.d.ts => UnsafePointer.d.ts} | 0 ...safePointer.Export.js => UnsafePointer.js} | 0 .../VoidParameterVoidReturn.Export.d.ts | 18 - .../VoidParameterVoidReturn.Export.js | 225 --- ...port.d.ts => VoidParameterVoidReturn.d.ts} | 1 + ...n.Import.js => VoidParameterVoidReturn.js} | 3 + .../ExportSwiftTests/ArrayTypes.json | 983 ----------- .../__Snapshots__/ExportSwiftTests/Async.json | 184 -- .../CrossFileFunctionTypes.ReverseOrder.json | 149 -- .../CrossFileFunctionTypes.json | 149 -- .../CrossFileTypeResolution.ReverseOrder.json | 61 - .../CrossFileTypeResolution.json | 61 - .../ExportSwiftTests/DefaultParameters.json | 1270 -------------- .../ExportSwiftTests/EnumAssociatedValue.json | 844 --------- .../ExportSwiftTests/EnumCase.json | 320 ---- .../EnumNamespace.Global.json | 538 ------ .../ExportSwiftTests/EnumNamespace.json | 538 ------ .../ExportSwiftTests/EnumRawType.json | 1498 ---------------- .../ImportedTypeInExportedInterface.json | 34 - .../ExportSwiftTests/MixedGlobal.json | 76 - .../ExportSwiftTests/MixedPrivate.json | 76 - .../ExportSwiftTests/Namespaces.Global.json | 182 -- .../ExportSwiftTests/Namespaces.json | 182 -- .../ExportSwiftTests/Optionals.json | 699 -------- .../ExportSwiftTests/PrimitiveParameters.json | 78 - .../PrimitiveParameters.swift | 9 - .../ExportSwiftTests/PrimitiveReturn.json | 102 -- .../ExportSwiftTests/PropertyTypes.json | 360 ---- .../ExportSwiftTests/Protocol.json | 898 ---------- .../StaticFunctions.Global.json | 336 ---- .../ExportSwiftTests/StaticFunctions.json | 336 ---- .../StaticProperties.Global.json | 339 ---- .../ExportSwiftTests/StaticProperties.json | 339 ---- .../ExportSwiftTests/StringParameter.json | 67 - .../ExportSwiftTests/StringParameter.swift | 20 - .../ExportSwiftTests/StringReturn.json | 34 - .../ExportSwiftTests/StringReturn.swift | 10 - .../ExportSwiftTests/SwiftClass.json | 142 -- .../ExportSwiftTests/SwiftClosure.json | 1075 ------------ .../ExportSwiftTests/SwiftStruct.json | 520 ------ .../ExportSwiftTests/Throws.json | 34 - .../ExportSwiftTests/UnsafePointer.json | 413 ----- .../VoidParameterVoidReturn.json | 34 - .../VoidParameterVoidReturn.swift | 9 - .../ImportTSTests/ArrayParameter.Macros.swift | 13 - .../ImportTSTests/ArrayParameter.swift | 51 - .../ImportTSTests/Async.Macros.swift | 21 - .../__Snapshots__/ImportTSTests/Async.swift | 124 -- .../ImportTSTests/Interface.Macros.swift | 14 - .../ImportTSTests/Interface.swift | 55 - .../InvalidPropertyNames.Macros.swift | 44 - .../MultipleImportedTypes.Macros.swift | 33 - .../ImportTSTests/MultipleImportedTypes.swift | 254 --- .../PrimitiveParameters.Macros.swift | 9 - .../ImportTSTests/PrimitiveParameters.swift | 17 - .../PrimitiveReturn.Macros.swift | 11 - .../ImportTSTests/PrimitiveReturn.swift | 33 - .../ImportTSTests/ReExportFrom.Macros.swift | 14 - .../ImportTSTests/ReExportFrom.swift | 53 - .../ImportTSTests/StringEnum.Macros.swift | 17 - .../ImportTSTests/StringEnum.swift | 33 - .../StringParameter.Macros.swift | 11 - .../ImportTSTests/StringReturn.Macros.swift | 9 - .../SwiftStructImports.ImportMacros.swift | 19 - .../TS2SkeletonLike.Macros.swift | 22 - .../ImportTSTests/TS2SkeletonLike.swift | 127 -- .../ImportTSTests/TypeAlias.Macros.swift | 9 - .../ImportTSTests/TypeAlias.swift | 16 - .../TypeScriptClass.Macros.swift | 16 - .../VoidParameterVoidReturn.Macros.swift | 9 - package-lock.json | 1397 +++++++++++++-- package.json | 3 +- 319 files changed, 16721 insertions(+), 18314 deletions(-) create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/ArrayParameter.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/Async.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/Interface.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/InvalidPropertyNames.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/MultipleImportedTypes.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/PrimitiveParameters.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/PrimitiveReturn.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/ReExportFrom.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/StringEnum.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/StringParameter.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/StringReturn.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/Support/ReExportTarget.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/TS2SkeletonLike.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/TypeAlias.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/TypeScriptClass.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/VoidParameterVoidReturn.d.ts (100%) rename Plugins/BridgeJS/{Tests/BridgeJSToolTests/Inputs => Sources/TS2Swift/JavaScript/test/fixtures}/tsconfig.json (100%) create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/ts2swift.test.js create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/vitest.config.js create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/ExportSwiftTests.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/ImportTSTests.swift rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/ArrayTypes.swift (88%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/Async.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/DefaultParameters.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/EnumAssociatedValue.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/EnumCase.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/EnumNamespace.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/EnumRawType.swift (91%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{ImportMacroInputs => Inputs/MacroSwift}/GlobalGetter.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{ImportMacroInputs => Inputs/MacroSwift}/GlobalThisImports.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/ImportedTypeInExportedInterface.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/InvalidPropertyNames.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClass.swift rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/MixedGlobal.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/MixedPrivate.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{MultifileInputs => Inputs/MacroSwift/Multifile}/CrossFileClassA.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{MultifileInputs => Inputs/MacroSwift/Multifile}/CrossFileClassB.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{MultifileInputs => Inputs/MacroSwift/Multifile}/CrossFileFunctionA.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{MultifileInputs => Inputs/MacroSwift/Multifile}/CrossFileFunctionB.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/Namespaces.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/Optionals.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/PrimitiveParameters.swift rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/PrimitiveReturn.swift (65%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/PropertyTypes.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/Protocol.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/StaticFunctions.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/StaticProperties.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringParameter.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/StringReturn.swift rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/SwiftClass.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/SwiftClosure.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{ImportMacroInputs => Inputs/MacroSwift}/SwiftClosureImports.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/SwiftStruct.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/{ImportMacroInputs => Inputs/MacroSwift}/SwiftStructImports.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/Throws.swift (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/{ => MacroSwift}/UnsafePointer.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/VoidParameterVoidReturn.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/PrimitiveParameters.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringParameter.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/StringReturn.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/VoidParameterVoidReturn.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/TS2SwiftVitestTests.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/ArrayTypes.swift (91%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Async.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Async.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.ReverseOrder.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/CrossFileFunctionTypes.ReverseOrder.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileFunctionTypes.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/CrossFileFunctionTypes.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/CrossFileTypeResolution.ReverseOrder.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/CrossFileTypeResolution.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/DefaultParameters.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/EnumAssociatedValue.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/EnumCase.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/EnumNamespace.Global.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/EnumNamespace.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/EnumRawType.swift (90%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests/GlobalGetter.ImportMacros.swift => BridgeJSCodegenTests/GlobalGetter.swift} (88%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests/GlobalThisImports.ImportMacros.swift => BridgeJSCodegenTests/GlobalThisImports.swift} (88%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/ImportedTypeInExportedInterface.swift (62%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests => BridgeJSCodegenTests}/InvalidPropertyNames.swift (77%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests/TypeScriptClass.swift => BridgeJSCodegenTests/JSClass.swift} (55%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedGlobal.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/MixedGlobal.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/MixedPrivate.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/MixedPrivate.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Namespaces.Global.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Namespaces.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Optionals.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveParameters.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PrimitiveReturn.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/PrimitiveReturn.swift (59%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/PropertyTypes.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/PropertyTypes.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Protocol.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/StaticFunctions.Global.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/StaticFunctions.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/StaticProperties.Global.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/StaticProperties.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringParameter.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests => BridgeJSCodegenTests}/StringParameter.swift (54%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StringReturn.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests => BridgeJSCodegenTests}/StringReturn.swift (53%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClass.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/SwiftClass.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/SwiftClosure.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests/SwiftClosureImports.ImportMacros.swift => BridgeJSCodegenTests/SwiftClosureImports.swift} (62%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/SwiftStruct.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Throws.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/Throws.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ExportSwiftTests => BridgeJSCodegenTests}/UnsafePointer.swift (100%) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/VoidParameterVoidReturn.json rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/{ImportTSTests => BridgeJSCodegenTests}/VoidParameterVoidReturn.swift (54%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayParameter.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{ArrayTypes.Export.d.ts => ArrayTypes.d.ts} (96%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{ArrayTypes.Export.js => ArrayTypes.js} (97%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Async.Export.d.ts => Async.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Async.Export.js => Async.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{DefaultParameters.Export.d.ts => DefaultParameters.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{DefaultParameters.Export.js => DefaultParameters.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumAssociatedValue.Export.d.ts => EnumAssociatedValue.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumAssociatedValue.Export.js => EnumAssociatedValue.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumCase.Export.d.ts => EnumCase.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumCase.Export.js => EnumCase.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumNamespace.Global.Export.d.ts => EnumNamespace.Global.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumNamespace.Global.Export.js => EnumNamespace.Global.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumNamespace.Export.d.ts => EnumNamespace.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumNamespace.Export.js => EnumNamespace.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumRawType.Export.d.ts => EnumRawType.d.ts} (98%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{EnumRawType.Export.js => EnumRawType.js} (91%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{GlobalGetter.ImportMacros.d.ts => GlobalGetter.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{GlobalGetter.ImportMacros.js => GlobalGetter.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{GlobalThisImports.ImportMacros.d.ts => GlobalThisImports.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{GlobalThisImports.ImportMacros.js => GlobalThisImports.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{ImportedTypeInExportedInterface.Export.d.ts => ImportedTypeInExportedInterface.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{ImportedTypeInExportedInterface.Export.js => ImportedTypeInExportedInterface.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Interface.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{InvalidPropertyNames.Import.d.ts => InvalidPropertyNames.d.ts} (85%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{InvalidPropertyNames.Import.js => InvalidPropertyNames.js} (93%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{TypeScriptClass.Import.d.ts => JSClass.d.ts} (81%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{TypeScriptClass.Import.js => JSClass.js} (89%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedGlobal.Export.d.ts => MixedGlobal.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedGlobal.Export.js => MixedGlobal.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedModules.Export.d.ts => MixedModules.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedModules.Export.js => MixedModules.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedPrivate.Export.d.ts => MixedPrivate.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{MixedPrivate.Export.js => MixedPrivate.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MultipleImportedTypes.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Namespaces.Global.Export.d.ts => Namespaces.Global.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Namespaces.Global.Export.js => Namespaces.Global.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Namespaces.Export.d.ts => Namespaces.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Namespaces.Export.js => Namespaces.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Optionals.Export.d.ts => Optionals.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Optionals.Export.js => Optionals.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Export.js delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.d.ts rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PrimitiveParameters.Export.d.ts => PrimitiveParameters.d.ts} (93%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PrimitiveParameters.Import.js => PrimitiveParameters.js} (98%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PrimitiveReturn.Export.d.ts => PrimitiveReturn.d.ts} (91%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PrimitiveReturn.Export.js => PrimitiveReturn.js} (92%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PropertyTypes.Export.d.ts => PropertyTypes.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{PropertyTypes.Export.js => PropertyTypes.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Protocol.Export.d.ts => Protocol.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Protocol.Export.js => Protocol.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticFunctions.Global.Export.d.ts => StaticFunctions.Global.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticFunctions.Global.Export.js => StaticFunctions.Global.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticFunctions.Export.d.ts => StaticFunctions.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticFunctions.Export.js => StaticFunctions.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticProperties.Global.Export.d.ts => StaticProperties.Global.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticProperties.Global.Export.js => StaticProperties.Global.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticProperties.Export.d.ts => StaticProperties.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StaticProperties.Export.js => StaticProperties.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringEnum.Import.js delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Export.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StringParameter.Import.d.ts => StringParameter.d.ts} (89%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StringParameter.Import.js => StringParameter.js} (92%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.js delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.d.ts rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StringReturn.Export.d.ts => StringReturn.d.ts} (95%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{StringReturn.Import.js => StringReturn.js} (97%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClass.Export.d.ts => SwiftClass.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClass.Export.js => SwiftClass.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClosure.Export.d.ts => SwiftClosure.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClosure.Export.js => SwiftClosure.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClosureImports.ImportMacros.d.ts => SwiftClosureImports.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftClosureImports.ImportMacros.js => SwiftClosureImports.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftStruct.Export.d.ts => SwiftStruct.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftStruct.Export.js => SwiftStruct.js} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftStructImports.ImportMacros.d.ts => SwiftStructImports.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{SwiftStructImports.ImportMacros.js => SwiftStructImports.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TS2SkeletonLike.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Throws.Export.d.ts => Throws.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{Throws.Export.js => Throws.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeAlias.Import.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{UnsafePointer.Export.d.ts => UnsafePointer.d.ts} (100%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{UnsafePointer.Export.js => UnsafePointer.js} (100%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.d.ts delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Export.js rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{VoidParameterVoidReturn.Import.d.ts => VoidParameterVoidReturn.d.ts} (96%) rename Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/{VoidParameterVoidReturn.Import.js => VoidParameterVoidReturn.js} (98%) delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Async.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.ReverseOrder.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileFunctionTypes.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.ReverseOrder.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/CrossFileTypeResolution.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumCase.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedGlobal.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/MixedPrivate.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.Global.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Namespaces.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveParameters.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PrimitiveReturn.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/PropertyTypes.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.Global.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticProperties.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringParameter.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StringReturn.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClass.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Throws.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.json delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/VoidParameterVoidReturn.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ArrayParameter.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Async.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/Interface.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/InvalidPropertyNames.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/MultipleImportedTypes.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveParameters.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/PrimitiveReturn.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/ReExportFrom.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringEnum.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringParameter.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/StringReturn.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/SwiftStructImports.ImportMacros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TS2SkeletonLike.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeAlias.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/TypeScriptClass.Macros.swift delete mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ImportTSTests/VoidParameterVoidReturn.Macros.swift diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b5ace046..2859b7043 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,7 +86,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. 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/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/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/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 922b8dbbc..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) @_spi(BridgeJS) 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/test/__snapshots__/ts2swift.test.js.snap b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap new file mode 100644 index 000000000..5b5316a40 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -0,0 +1,313 @@ +// 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 checkArray(_ a: JSObject) throws (JSException) -> Void + +@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws (JSException) -> Void + +@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void +" +`; + +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: JSObject) 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: JSObject, _ options: JSObject) throws (JSException) -> JSObject + @JSFunction func getAnimations(_ options: JSObject) throws (JSException) -> JSObject +} +" +`; + +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: 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 +} +" +`; + +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: JSObject) 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 +} +" +`; + +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/Tests/BridgeJSToolTests/Inputs/ArrayParameter.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayParameter.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts 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/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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/TypeScriptClass.d.ts rename to Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts 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..ed83bc074 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift @@ -0,0 +1,169 @@ +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") + } +} 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/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift similarity index 88% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift index 8454b7520..678bc3698 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift @@ -54,3 +54,7 @@ @JS func processItemArray(_ items: [Item]) -> [Item] @JS func processNestedItemArray(_ items: [[Item]]) -> [[Item]] + +@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/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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumAssociatedValue.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/EnumNamespace.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumNamespace.swift 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/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/ImportedTypeInExportedInterface.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift 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/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/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/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Optionals.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/SwiftStruct.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift 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/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..c90347177 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json @@ -0,0 +1,1059 @@ +{ + "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" : { + "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" + } + ] + }, + "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" : "checkArray", + "parameters" : [ + { + "name" : "a", + "type" : { + "jsObject" : { + + } + } + } + ], + "returnType" : { + "void" : { + + } + } + } + ], + "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 91% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index 55a6258b0..4452446b9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -488,4 +488,56 @@ 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_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__/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/CrossFileTypeResolution.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json new file mode 100644 index 000000000..7f21c86cf --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json @@ -0,0 +1,64 @@ +{ + "exported" : { + "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" : [ + + ] + }, + "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..3f8129109 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json @@ -0,0 +1,64 @@ +{ + "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" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "ClassB" + } + } + } + } + } + ], + "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..64cc1a845 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json @@ -0,0 +1,1273 @@ +{ + "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" : { + "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" + } + ] + }, + "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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/DefaultParameters.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift 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..ecf045c3c --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json @@ -0,0 +1,847 @@ +{ + "exported" : { + "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" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumAssociatedValue.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift 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..2d5d5f2fa --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json @@ -0,0 +1,323 @@ +{ + "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" : { + "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" : [ + + ] + }, + "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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.Global.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumNamespace.swift 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..20ef1f42f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json @@ -0,0 +1,1543 @@ +{ + "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" : { + "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" : "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" : { + "optional" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + } + } + } + ], + "returnType" : { + "optional" : { + "_0" : { + "rawValueEnum" : { + "_0" : "FeatureFlag", + "_1" : "String" + } + } + } + } + }, + { + "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" : [ + + ] + }, + "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 90% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift index 55c902af0..210361b3b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumRawType.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.swift @@ -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..c9be60d8a --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json @@ -0,0 +1,71 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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" : [ + + ] + } + ] + } + ] + }, + "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..5cec23259 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json @@ -0,0 +1,126 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "url", + "type" : { + "string" : { + + } + } + } + ] + }, + "from" : "global", + "getters" : [ + + ], + "methods" : [ + { + "name" : "close", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "WebSocket", + "setters" : [ + + ] + } + ] + } + ] + }, + "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/ImportedTypeInExportedInterface.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json new file mode 100644 index 000000000..10a18983b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json @@ -0,0 +1,65 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_makeFoo", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : true + }, + "name" : "makeFoo", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + + ] + }, + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "Foo", + "setters" : [ + + ] + } + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift similarity index 62% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift index 0bebd4e73..29b615b0f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/ImportedTypeInExportedInterface.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift @@ -21,4 +21,21 @@ public func _bjs_makeFoo() -> Int32 { #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..40b97c12b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json @@ -0,0 +1,258 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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" : { + + } + } + } + ] + }, + { + "constructor" : { + "parameters" : [ + + ] + }, + "getters" : [ + + ], + "jsName" : "$Weird", + "methods" : [ + { + "jsName" : "method-with-dashes", + "name" : "method_with_dashes", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + } + ], + "name" : "_Weird", + "setters" : [ + + ] + } + ] + } + ] + }, + "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..07906a404 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json @@ -0,0 +1,172 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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" : { + + } + } + } + ] + }, + { + "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" : [ + + ] + } + ] + } + ] + }, + "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/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..2af32886b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json @@ -0,0 +1,702 @@ +{ + "exported" : { + "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" : [ + + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Optionals.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift 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..5713a2898 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -0,0 +1,901 @@ +{ + "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" : { + "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" : [ + + ] + }, + "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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/Protocol.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.Global.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/StaticFunctions.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift 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..9b1d0d6b8 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json @@ -0,0 +1,342 @@ +{ + "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" : { + "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" : { + "_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..b3ccf7e93 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json @@ -0,0 +1,342 @@ +{ + "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" : { + "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" : { + "_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..345582e86 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json @@ -0,0 +1,1078 @@ +{ + "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" : [ + { + "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" : [ + + ] + }, + "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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftClosure.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift 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..12f76a912 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json @@ -0,0 +1,110 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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..fa5f333f0 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json @@ -0,0 +1,523 @@ +{ + "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" + } + } + } + ], + "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" + } + ] + }, + "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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/SwiftStruct.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/UnsafePointer.swift rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift 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 96% 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..1bb9ff18c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts @@ -66,6 +66,9 @@ export type Exports = { Status: StatusObject } export type Imports = { + checkArray(a: any): void; + checkArrayWithLength(a: any, b: number): void; + checkArray(a: any): void; } 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 97% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 7388f4150..3cb11c794 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -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); @@ -247,6 +248,28 @@ 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_checkArray"] = function bjs_checkArray(a) { + try { + imports.checkArray(swift.memory.getObject(a)); + } catch (error) { + setException(error); + } + } }, setInstance: (i) => { instance = i; 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.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js deleted file mode 100644 index 981cecbe5..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Import.js +++ /dev/null @@ -1,289 +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_asyncReturnVoid"] = function bjs_asyncReturnVoid() { - try { - let ret = imports.asyncReturnVoid(); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripInt"] = function bjs_asyncRoundTripInt(v) { - try { - let ret = imports.asyncRoundTripInt(v); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripString"] = function bjs_asyncRoundTripString(v) { - try { - const vObject = swift.memory.getObject(v); - swift.memory.release(v); - let ret = imports.asyncRoundTripString(vObject); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripBool"] = function bjs_asyncRoundTripBool(v) { - try { - let ret = imports.asyncRoundTripBool(v !== 0); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripFloat"] = function bjs_asyncRoundTripFloat(v) { - try { - let ret = imports.asyncRoundTripFloat(v); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripDouble"] = function bjs_asyncRoundTripDouble(v) { - try { - let ret = imports.asyncRoundTripDouble(v); - return swift.memory.retain(ret); - } catch (error) { - setException(error); - return 0 - } - } - TestModule["bjs_asyncRoundTripJSObject"] = function bjs_asyncRoundTripJSObject(v) { - try { - let ret = imports.asyncRoundTripJSObject(swift.memory.getObject(v)); - 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/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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js 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 100% 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 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js 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..1e137e6eb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -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); @@ -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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js 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..ab030062a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -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..5b7541b1c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/TypeScriptClass.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -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/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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js 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.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.d.ts deleted file mode 100644 index 5442ebfa2..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.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 = { - check(a: number, b: boolean): 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/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 98% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index fe6c3ae04..97e03063a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -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.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Import.js deleted file mode 100644 index e3263af05..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.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_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; - 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/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 92% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index 836a82f21..871310bb8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.Export.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -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); @@ -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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.Import.d.ts deleted file mode 100644 index db6d2be05..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ReExportFrom.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 interface JsGreeter { - greet(): string; -} -export type Exports = { -} -export type Imports = { - jsRoundTripNumber(v: number): number; - JsGreeter: { - new(name: string): JsGreeter; - } -} -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/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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js 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 92% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index 718f776c7..03a4bc9b1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -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.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.Import.d.ts deleted file mode 100644 index cb7783667..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.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 = { - checkString(): string; -} -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.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts similarity index 95% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts index c6a9f65a4..b43ff062c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Export.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.d.ts @@ -8,6 +8,7 @@ export type Exports = { checkString(): string; } export type Imports = { + checkString(): string; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js similarity index 97% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index bb5278068..98ea9fa4a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.d.ts rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.d.ts diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js similarity index 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.ImportMacros.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js 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 100% rename from Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.Export.js rename to Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js 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..f37cbd90b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.Import.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -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/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 135908d7f..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.Global.json +++ /dev/null @@ -1,538 +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" - }, - { - "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" : [ - - ] -} \ 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 374ae13f4..000000000 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/ExportSwiftTests/EnumNamespace.json +++ /dev/null @@ -1,538 +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" - }, - { - "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" : [ - - ] -} \ 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/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/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 0eec726c8..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" : { - "_0" : "Utils.String" - } - } - } - ], - "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 372504135..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" : { - "_0" : "Utils.String" - } - } - } - ], - "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 28457fb63..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" : { - "_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" : [ - - ] -} \ 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 829c20718..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" : { - "_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" : [ - - ] -} \ 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 551385093..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) @_spi(BridgeJS) 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 032fcadfc..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) @_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: 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 8c60cd218..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) @_spi(BridgeJS) 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 37ccd0287..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) @_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 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 f7b2ebc3b..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) @_spi(BridgeJS) 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 72f503afa..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) @_spi(BridgeJS) 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 1f24ec359..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) @_spi(BridgeJS) 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 f71778e26..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) @_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 -} 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 7140ecac7..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) @_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 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 75ba0eefd..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) @_spi(BridgeJS) 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 c7618d7ac..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) @_spi(BridgeJS) 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 eab06f1db..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) @_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: 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 ef9500566..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) @_spi(BridgeJS) 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 a0857a57e..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) @_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 -} 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 7247e3aff..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) @_spi(BridgeJS) import JavaScriptKit - -@JSFunction func check() throws (JSException) -> Void 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" } } From d4da0e3e7981b8b8db5b7a86d10724e3d7aab58f Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 3 Feb 2026 11:07:28 +0100 Subject: [PATCH 04/34] BridgeJS: Exception checking on protocol wrapper methods BridgeJS: Enforce throws(JSException) on @JS protocol methods --- .../Sources/BridgeJSCore/ExportSwift.swift | 4 +- .../Sources/BridgeJSCore/ImportTS.swift | 32 +-- .../BridgeJSCore/SwiftToSkeleton.swift | 9 + .../Sources/BridgeJSLink/JSGlueGen.swift | 20 +- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 1 + .../Inputs/MacroSwift/Protocol.swift | 24 +- .../BridgeJSCodegenTests/Protocol.json | 24 +- .../BridgeJSCodegenTests/Protocol.swift | 60 ++++- .../Exporting-Swift-Protocols.md | 30 +-- .../BridgeJSRuntimeTests/ExportAPITests.swift | 60 ++--- .../Generated/BridgeJS.swift | 209 +++++++++++++++--- .../Generated/JavaScript/BridgeJS.json | 40 ++-- 12 files changed, 359 insertions(+), 154 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 0c5debeac..85aeee131 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1346,7 +1346,7 @@ struct ProtocolCodegen { let builder = ImportTS.CallJSEmission( moduleName: moduleName, abiName: "_extern_\(method.name)", - context: .exportSwift + context: .exportSwiftProtocol ) try builder.lowerParameter(param: Parameter(label: nil, name: "jsObject", type: .jsObject(nil))) for param in method.parameters { @@ -1359,7 +1359,7 @@ struct ProtocolCodegen { let signature = SwiftSignatureBuilder.buildFunctionSignature( parameters: method.parameters, returnType: method.returnType, - effects: nil + effects: method.effects ) // Build extern declaration using helper function diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 7c391eea0..70dda3848 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -187,8 +187,8 @@ public struct ImportTS { body.append("let ret = \(raw: callExpr)") } - // Add exception check for ImportTS context - if context == .importTS { + // Add exception check for contexts that call INTO JavaScript + if context == .importTS || context == .exportSwiftProtocol { body.append("if let error = _swift_js_take_exception() { throw error }") } } @@ -887,7 +887,7 @@ extension BridgeType { Swift classes can only be used in @JS protocols where Swift owns the instance. """ ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LoweringParameterInfo(loweredParameters: [("pointer", .pointer)]) } case .swiftProtocol: @@ -896,14 +896,14 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LoweringParameterInfo(loweredParameters: [("value", .i32)]) } case .rawValueEnum(_, let rawType): switch context { case .importTS: return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: // For protocol export we return .i32 for String raw value type instead of nil return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) } @@ -911,7 +911,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LoweringParameterInfo(loweredParameters: [("caseId", .i32)]) } case .swiftStruct: @@ -919,7 +919,7 @@ extension BridgeType { case .importTS: // Swift structs are bridged as JS objects (object IDs) in imported signatures. return LoweringParameterInfo(loweredParameters: [("objectId", .i32)]) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LoweringParameterInfo(loweredParameters: []) } case .namespaceEnum: @@ -928,7 +928,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) var params = [("isSome", WasmCoreType.i32)] params.append(contentsOf: wrappedInfo.loweredParameters) @@ -938,7 +938,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LoweringParameterInfo(loweredParameters: []) } } @@ -981,7 +981,7 @@ extension BridgeType { JavaScript cannot create Swift heap objects. """ ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LiftingReturnInfo(valueToLift: .pointer) } case .swiftProtocol: @@ -990,14 +990,14 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LiftingReturnInfo(valueToLift: .i32) } case .rawValueEnum(_, let rawType): switch context { case .importTS: return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: // For protocol export we return .i32 for String raw value type instead of nil return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) } @@ -1005,7 +1005,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LiftingReturnInfo(valueToLift: .i32) } case .swiftStruct: @@ -1013,7 +1013,7 @@ extension BridgeType { case .importTS: // Swift structs are bridged as JS objects (object IDs) in imported signatures. return LiftingReturnInfo(valueToLift: .i32) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LiftingReturnInfo(valueToLift: nil) } case .namespaceEnum: @@ -1022,7 +1022,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) } @@ -1030,7 +1030,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return LiftingReturnInfo(valueToLift: nil) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index b780012f0..edcb0a391 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1608,6 +1608,15 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { return nil } + guard effects.isThrows else { + diagnose( + node: node, + message: "@JS protocol methods must be throws.", + hint: "Declare the method as 'throws(JSException)'." + ) + return nil + } + return ExportedFunction( name: name, abiName: abiName, diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 28f756a43..9a1979491 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -1477,7 +1477,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return .swiftHeapObjectLiftParameter(name) } case .swiftProtocol: return .jsObjectLiftParameter @@ -1491,7 +1491,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Optional types are not supported for imported JS functions: \(wrappedType)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return try .optionalLiftParameter(wrappedType: wrappedType) } case .caseEnum: return .identity @@ -1508,7 +1508,7 @@ struct IntrinsicJSFragment: Sendable { message: "Associated value enums are not supported to be passed as parameters to imported JS functions: \(fullName)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: let base = fullName.components(separatedBy: ".").last ?? fullName return IntrinsicJSFragment( parameters: ["caseId"], @@ -1526,7 +1526,7 @@ struct IntrinsicJSFragment: Sendable { switch context { case .importTS: return .jsObjectLiftRetainedObjectId - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: let base = fullName.components(separatedBy: ".").last ?? fullName return IntrinsicJSFragment( parameters: [], @@ -1558,7 +1558,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Arrays are not yet supported to be passed as parameters to imported JS functions" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return try arrayLift(elementType: elementType) } } @@ -1578,7 +1578,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return .swiftHeapObjectLowerReturn } case .swiftProtocol: return .jsObjectLowerReturn @@ -1589,7 +1589,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Optional types are not supported for imported JS functions: \(wrappedType)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return try .optionalLowerReturn(wrappedType: wrappedType) } case .caseEnum: return .identity @@ -1606,7 +1606,7 @@ struct IntrinsicJSFragment: Sendable { message: "Associated value enums are not supported to be returned from imported JS functions: \(fullName)" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return associatedValueLowerReturn(fullName: fullName) } case .swiftStruct(let fullName): @@ -1614,7 +1614,7 @@ struct IntrinsicJSFragment: Sendable { case .importTS: // ImportTS expects Swift structs to come back as a retained JS object ID. return .jsObjectLowerReturn - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return swiftStructLowerReturn(fullName: fullName) } case .closure: @@ -1640,7 +1640,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Arrays are not yet supported to be returned from imported JS functions" ) - case .exportSwift: + case .exportSwift, .exportSwiftProtocol: return try arrayLower(elementType: elementType) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 5013dda66..01382e642 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -71,6 +71,7 @@ public struct ABINameGenerator { public enum BridgeContext: Sendable { case importTS case exportSwift + case exportSwiftProtocol } public struct ClosureSignature: Codable, Equatable, Hashable, Sendable { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift index fbbad0615..3e8df7405 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift @@ -47,18 +47,18 @@ import JavaScriptKit var directionOptional: Direction? { get set } var priority: Priority { get set } var priorityOptional: Priority? { get set } - func onSomethingHappened() - func onValueChanged(_ value: String) - func onCountUpdated(count: Int) -> Bool - func onLabelUpdated(_ prefix: String, _ suffix: String) - func isCountEven() -> Bool - func onHelperUpdated(_ helper: Helper) - func createHelper() -> Helper - func onOptionalHelperUpdated(_ helper: Helper?) - func createOptionalHelper() -> Helper? - func createEnum() -> ExampleEnum - func handleResult(_ result: Result) - func getResult() -> Result + func onSomethingHappened() throws(JSException) + func onValueChanged(_ value: String) throws(JSException) + func onCountUpdated(count: Int) throws(JSException) -> Bool + func onLabelUpdated(_ prefix: String, _ suffix: String) throws(JSException) + func isCountEven() throws(JSException) -> Bool + func onHelperUpdated(_ helper: Helper) throws(JSException) + func createHelper() throws(JSException) -> Helper + func onOptionalHelperUpdated(_ helper: Helper?) throws(JSException) + func createOptionalHelper() throws(JSException) -> Helper? + func createEnum() throws(JSException) -> ExampleEnum + func handleResult(_ result: Result) throws(JSException) + func getResult() throws(JSException) -> Result } @JS class MyViewController { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json index 5713a2898..2f9c27ace 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -499,7 +499,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onSomethingHappened", "parameters" : [ @@ -516,7 +516,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onValueChanged", "parameters" : [ @@ -541,7 +541,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onCountUpdated", "parameters" : [ @@ -566,7 +566,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onLabelUpdated", "parameters" : [ @@ -600,7 +600,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "isCountEven", "parameters" : [ @@ -617,7 +617,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onHelperUpdated", "parameters" : [ @@ -642,7 +642,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "createHelper", "parameters" : [ @@ -659,7 +659,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "onOptionalHelperUpdated", "parameters" : [ @@ -688,7 +688,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "createOptionalHelper", "parameters" : [ @@ -709,7 +709,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "createEnum", "parameters" : [ @@ -727,7 +727,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "handleResult", "parameters" : [ @@ -752,7 +752,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getResult", "parameters" : [ diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index 21178521d..91efeda7f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -1,76 +1,112 @@ struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProtocolWrapper { let jsObject: JSObject - func onSomethingHappened() -> Void { + func onSomethingHappened() throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() _extern_onSomethingHappened(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } } - func onValueChanged(_ value: String) -> Void { + func onValueChanged(_ value: String) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let valueValue = value.bridgeJSLowerParameter() _extern_onValueChanged(jsObjectValue, valueValue) + if let error = _swift_js_take_exception() { + throw error + } } - func onCountUpdated(count: Int) -> Bool { + func onCountUpdated(count: Int) throws(JSException) -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let countValue = count.bridgeJSLowerParameter() let ret = _extern_onCountUpdated(jsObjectValue, countValue) + if let error = _swift_js_take_exception() { + throw error + } return Bool.bridgeJSLiftReturn(ret) } - func onLabelUpdated(_ prefix: String, _ suffix: String) -> Void { + func onLabelUpdated(_ prefix: String, _ suffix: String) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let prefixValue = prefix.bridgeJSLowerParameter() let suffixValue = suffix.bridgeJSLowerParameter() _extern_onLabelUpdated(jsObjectValue, prefixValue, suffixValue) + if let error = _swift_js_take_exception() { + throw error + } } - func isCountEven() -> Bool { + func isCountEven() throws(JSException) -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_isCountEven(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Bool.bridgeJSLiftReturn(ret) } - func onHelperUpdated(_ helper: Helper) -> Void { + func onHelperUpdated(_ helper: Helper) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let helperPointer = helper.bridgeJSLowerParameter() _extern_onHelperUpdated(jsObjectValue, helperPointer) + if let error = _swift_js_take_exception() { + throw error + } } - func createHelper() -> Helper { + func createHelper() throws(JSException) -> Helper { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createHelper(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Helper.bridgeJSLiftReturn(ret) } - func onOptionalHelperUpdated(_ helper: Optional) -> Void { + func onOptionalHelperUpdated(_ helper: Optional) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (helperIsSome, helperPointer) = helper.bridgeJSLowerParameter() _extern_onOptionalHelperUpdated(jsObjectValue, helperIsSome, helperPointer) + if let error = _swift_js_take_exception() { + throw error + } } - func createOptionalHelper() -> Optional { + func createOptionalHelper() throws(JSException) -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createOptionalHelper(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Optional.bridgeJSLiftReturn(ret) } - func createEnum() -> ExampleEnum { + func createEnum() throws(JSException) -> ExampleEnum { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createEnum(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return ExampleEnum.bridgeJSLiftReturn(ret) } - func handleResult(_ result: Result) -> Void { + func handleResult(_ result: Result) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let resultCaseId = result.bridgeJSLowerParameter() _extern_handleResult(jsObjectValue, resultCaseId) + if let error = _swift_js_take_exception() { + throw error + } } - func getResult() -> Result { + func getResult() throws(JSException) -> Result { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getResult(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Result.bridgeJSLiftReturn(ret) } diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md index 111b1f052..4b58276ea 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md @@ -15,7 +15,7 @@ When you mark a protocol with `@JS`, BridgeJS generates: ## Example: Counter Protocol -Mark a Swift protocol with `@JS` to expose it: +Mark a Swift protocol with `@JS` to expose it. Protocol methods must declare `throws(JSException)` to align with the import side error handling: ```swift import JavaScriptKit @@ -24,9 +24,9 @@ import JavaScriptKit var count: Int { get set } var name: String { get } var label: String? { get set } - func increment(by amount: Int) - func reset() - func getValue() -> Int + func increment(by amount: Int) throws(JSException) + func reset() throws(JSException) + func getValue() throws(JSException) -> Int } @JS class CounterManager { @@ -122,24 +122,24 @@ You can also implement protocols in Swift and use them from JavaScript: @JS protocol Counter { var count: Int { get set } var name: String { get } - func increment(by amount: Int) - func reset() - func getValue() -> Int + func increment(by amount: Int) throws(JSException) + func reset() throws(JSException) + func getValue() throws(JSException) -> Int } final class SwiftCounter: Counter { var count = 0 let name = "SwiftCounter" - - func increment(by amount: Int) { + + func increment(by amount: Int) throws(JSException) { count += amount } - - func reset() { + + func reset() throws(JSException) { count = 0 } - - func getValue() -> Int { + + func getValue() throws(JSException) -> Int { return count } } @@ -195,7 +195,7 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { } } - func increment(by amount: Int) { + func increment(by amount: Int) throws(JSException) { @_extern(wasm, module: "TestModule", name: "bjs_Counter_increment") func _extern_increment(this: Int32, amount: Int32) _extern_increment( @@ -212,7 +212,7 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { | Swift Feature | Status | |:--------------|:-------| -| Method requirements: `func foo(_ param: String?) -> FooClass?` | ✅ | +| Method requirements: `func foo(_ param: String?) throws(JSException) -> FooClass?` | ✅ | | Property requirements: `var property: Type { get }` / `var property: Type { get set }` | ✅ | | Optional parameters / return values in methods | ✅ | | Optional properties | ✅ | diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 711a42e2d..520fe8298 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -988,17 +988,17 @@ enum GraphOperations { var apiResult: APIResult? { get set } var helper: Greeter { get set } var optionalHelper: Greeter? { get set } - func increment(by amount: Int) - func getValue() -> Int - func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) - func getLabel() -> String - func isEven() -> Bool - func processGreeter(_ greeter: Greeter) -> String - func createGreeter() -> Greeter - func processOptionalGreeter(_ greeter: Greeter?) -> String - func createOptionalGreeter() -> Greeter? - func handleAPIResult(_ result: APIResult?) - func getAPIResult() -> APIResult? + func increment(by amount: Int) throws(JSException) + func getValue() throws(JSException) -> Int + func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) throws(JSException) + func getLabel() throws(JSException) -> String + func isEven() throws(JSException) -> Bool + func processGreeter(_ greeter: Greeter) throws(JSException) -> String + func createGreeter() throws(JSException) -> Greeter + func processOptionalGreeter(_ greeter: Greeter?) throws(JSException) -> String + func createOptionalGreeter() throws(JSException) -> Greeter? + func handleAPIResult(_ result: APIResult?) throws(JSException) + func getAPIResult() throws(JSException) -> APIResult? } @JS class DataProcessorManager { @@ -1011,33 +1011,33 @@ enum GraphOperations { self.backupProcessor = nil } - @JS func incrementByAmount(_ amount: Int) { - processor.increment(by: amount) + @JS func incrementByAmount(_ amount: Int) throws(JSException) { + try processor.increment(by: amount) } - @JS func setProcessorLabel(_ prefix: String, _ suffix: String) { - processor.setLabelElements(prefix, suffix) + @JS func setProcessorLabel(_ prefix: String, _ suffix: String) throws(JSException) { + try processor.setLabelElements(prefix, suffix) } - @JS func isProcessorEven() -> Bool { - return processor.isEven() + @JS func isProcessorEven() throws(JSException) -> Bool { + return try processor.isEven() } - @JS func getProcessorLabel() -> String { - return processor.getLabel() + @JS func getProcessorLabel() throws(JSException) -> String { + return try processor.getLabel() } - @JS func getCurrentValue() -> Int { - return processor.getValue() + @JS func getCurrentValue() throws(JSException) -> Int { + return try processor.getValue() } - @JS func incrementBoth() { - processor.increment(by: 1) - backupProcessor?.increment(by: 1) + @JS func incrementBoth() throws(JSException) { + try processor.increment(by: 1) + try backupProcessor?.increment(by: 1) } - @JS func getBackupValue() -> Int? { - return backupProcessor?.getValue() + @JS func getBackupValue() throws(JSException) -> Int? { + return try backupProcessor?.getValue() } @JS func hasBackup() -> Bool { @@ -1084,12 +1084,12 @@ enum GraphOperations { processor.httpStatus = status } - @JS func getProcessorAPIResult() -> APIResult? { - return processor.getAPIResult() + @JS func getProcessorAPIResult() throws(JSException) -> APIResult? { + return try processor.getAPIResult() } - @JS func setProcessorAPIResult(_ apiResult: APIResult?) { - processor.handleAPIResult(apiResult) + @JS func setProcessorAPIResult(_ apiResult: APIResult?) throws(JSException) { + try processor.handleAPIResult(apiResult) } } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 55a77466e..b9b7dc1dc 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -921,72 +921,105 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsy_S struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { let jsObject: JSObject - func increment(by amount: Int) -> Void { + func increment(by amount: Int) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let amountValue = amount.bridgeJSLowerParameter() _extern_increment(jsObjectValue, amountValue) + if let error = _swift_js_take_exception() { + throw error + } } - func getValue() -> Int { + func getValue() throws(JSException) -> Int { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getValue(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Int.bridgeJSLiftReturn(ret) } - func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) -> Void { + func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let labelPrefixValue = labelPrefix.bridgeJSLowerParameter() let labelSuffixValue = labelSuffix.bridgeJSLowerParameter() _extern_setLabelElements(jsObjectValue, labelPrefixValue, labelSuffixValue) + if let error = _swift_js_take_exception() { + throw error + } } - func getLabel() -> String { + func getLabel() throws(JSException) -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getLabel(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return String.bridgeJSLiftReturn(ret) } - func isEven() -> Bool { + func isEven() throws(JSException) -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_isEven(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Bool.bridgeJSLiftReturn(ret) } - func processGreeter(_ greeter: Greeter) -> String { + func processGreeter(_ greeter: Greeter) throws(JSException) -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let greeterPointer = greeter.bridgeJSLowerParameter() let ret = _extern_processGreeter(jsObjectValue, greeterPointer) + if let error = _swift_js_take_exception() { + throw error + } return String.bridgeJSLiftReturn(ret) } - func createGreeter() -> Greeter { + func createGreeter() throws(JSException) -> Greeter { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createGreeter(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Greeter.bridgeJSLiftReturn(ret) } - func processOptionalGreeter(_ greeter: Optional) -> String { + func processOptionalGreeter(_ greeter: Optional) throws(JSException) -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (greeterIsSome, greeterPointer) = greeter.bridgeJSLowerParameter() let ret = _extern_processOptionalGreeter(jsObjectValue, greeterIsSome, greeterPointer) + if let error = _swift_js_take_exception() { + throw error + } return String.bridgeJSLiftReturn(ret) } - func createOptionalGreeter() -> Optional { + func createOptionalGreeter() throws(JSException) -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createOptionalGreeter(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Optional.bridgeJSLiftReturn(ret) } - func handleAPIResult(_ result: Optional) -> Void { + func handleAPIResult(_ result: Optional) throws(JSException) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (resultIsSome, resultCaseId) = result.bridgeJSLowerParameter() _extern_handleAPIResult(jsObjectValue, resultIsSome, resultCaseId) + if let error = _swift_js_take_exception() { + throw error + } } - func getAPIResult() -> Optional { + func getAPIResult() throws(JSException) -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getAPIResult(jsObjectValue) + if let error = _swift_js_take_exception() { + throw error + } return Optional.bridgeJSLiftReturn(ret) } @@ -6559,7 +6592,21 @@ public func _bjs_DataProcessorManager_init(_ processor: Int32) -> UnsafeMutableR @_cdecl("bjs_DataProcessorManager_incrementByAmount") public func _bjs_DataProcessorManager_incrementByAmount(_ _self: UnsafeMutableRawPointer, _ amount: Int32) -> Void { #if arch(wasm32) - DataProcessorManager.bridgeJSLiftParameter(_self).incrementByAmount(_: Int.bridgeJSLiftParameter(amount)) + do { + try DataProcessorManager.bridgeJSLiftParameter(_self).incrementByAmount(_: Int.bridgeJSLiftParameter(amount)) + } 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6569,7 +6616,21 @@ public func _bjs_DataProcessorManager_incrementByAmount(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_setProcessorLabel") public func _bjs_DataProcessorManager_setProcessorLabel(_ _self: UnsafeMutableRawPointer, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { #if arch(wasm32) - DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorLabel(_: String.bridgeJSLiftParameter(prefixBytes, prefixLength), _: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) + do { + try DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorLabel(_: String.bridgeJSLiftParameter(prefixBytes, prefixLength), _: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) + } 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6579,8 +6640,22 @@ public func _bjs_DataProcessorManager_setProcessorLabel(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_isProcessorEven") public func _bjs_DataProcessorManager_isProcessorEven(_ _self: UnsafeMutableRawPointer) -> Int32 { #if arch(wasm32) - let ret = DataProcessorManager.bridgeJSLiftParameter(_self).isProcessorEven() - return ret.bridgeJSLowerReturn() + do { + let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).isProcessorEven() + 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 @@ -6590,8 +6665,22 @@ public func _bjs_DataProcessorManager_isProcessorEven(_ _self: UnsafeMutableRawP @_cdecl("bjs_DataProcessorManager_getProcessorLabel") public func _bjs_DataProcessorManager_getProcessorLabel(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorLabel() - return ret.bridgeJSLowerReturn() + do { + let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorLabel() + 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6601,8 +6690,22 @@ public func _bjs_DataProcessorManager_getProcessorLabel(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_getCurrentValue") public func _bjs_DataProcessorManager_getCurrentValue(_ _self: UnsafeMutableRawPointer) -> Int32 { #if arch(wasm32) - let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getCurrentValue() - return ret.bridgeJSLowerReturn() + do { + let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getCurrentValue() + 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 @@ -6612,7 +6715,21 @@ public func _bjs_DataProcessorManager_getCurrentValue(_ _self: UnsafeMutableRawP @_cdecl("bjs_DataProcessorManager_incrementBoth") public func _bjs_DataProcessorManager_incrementBoth(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - DataProcessorManager.bridgeJSLiftParameter(_self).incrementBoth() + do { + try DataProcessorManager.bridgeJSLiftParameter(_self).incrementBoth() + } 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6622,8 +6739,22 @@ public func _bjs_DataProcessorManager_incrementBoth(_ _self: UnsafeMutableRawPoi @_cdecl("bjs_DataProcessorManager_getBackupValue") public func _bjs_DataProcessorManager_getBackupValue(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getBackupValue() - return ret.bridgeJSLowerReturn() + do { + let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getBackupValue() + 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6749,8 +6880,22 @@ public func _bjs_DataProcessorManager_setProcessorHttpStatus(_ _self: UnsafeMuta @_cdecl("bjs_DataProcessorManager_getProcessorAPIResult") public func _bjs_DataProcessorManager_getProcessorAPIResult(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorAPIResult() - return ret.bridgeJSLowerReturn() + do { + let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorAPIResult() + 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 + } #else fatalError("Only available on WebAssembly") #endif @@ -6760,7 +6905,21 @@ public func _bjs_DataProcessorManager_getProcessorAPIResult(_ _self: UnsafeMutab @_cdecl("bjs_DataProcessorManager_setProcessorAPIResult") public func _bjs_DataProcessorManager_setProcessorAPIResult(_ _self: UnsafeMutableRawPointer, _ apiResultIsSome: Int32, _ apiResultCaseId: Int32) -> Void { #if arch(wasm32) - DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorAPIResult(_: Optional.bridgeJSLiftParameter(apiResultIsSome, apiResultCaseId)) + do { + try DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorAPIResult(_: Optional.bridgeJSLiftParameter(apiResultIsSome, apiResultCaseId)) + } 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 + } #else fatalError("Only available on WebAssembly") #endif diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index e31c69a51..83845dd45 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -1365,7 +1365,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "incrementByAmount", "parameters" : [ @@ -1390,7 +1390,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "setProcessorLabel", "parameters" : [ @@ -1424,7 +1424,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "isProcessorEven", "parameters" : [ @@ -1441,7 +1441,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getProcessorLabel", "parameters" : [ @@ -1458,7 +1458,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getCurrentValue", "parameters" : [ @@ -1475,7 +1475,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "incrementBoth", "parameters" : [ @@ -1492,7 +1492,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getBackupValue", "parameters" : [ @@ -1784,7 +1784,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getProcessorAPIResult", "parameters" : [ @@ -1805,7 +1805,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "setProcessorAPIResult", "parameters" : [ @@ -9844,7 +9844,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "increment", "parameters" : [ @@ -9869,7 +9869,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getValue", "parameters" : [ @@ -9886,7 +9886,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "setLabelElements", "parameters" : [ @@ -9920,7 +9920,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getLabel", "parameters" : [ @@ -9937,7 +9937,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "isEven", "parameters" : [ @@ -9954,7 +9954,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "processGreeter", "parameters" : [ @@ -9979,7 +9979,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "createGreeter", "parameters" : [ @@ -9996,7 +9996,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "processOptionalGreeter", "parameters" : [ @@ -10025,7 +10025,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "createOptionalGreeter", "parameters" : [ @@ -10046,7 +10046,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "handleAPIResult", "parameters" : [ @@ -10075,7 +10075,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : false + "isThrows" : true }, "name" : "getAPIResult", "parameters" : [ From 1714f28643d04ef6c078675ba61f6efede1f65ff Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 29 Jan 2026 13:58:18 +0400 Subject: [PATCH 05/34] BridgeJS: Add JSObject and @JSClass struct support for arrays and struct --- .../Sources/BridgeJSCore/ExportSwift.swift | 24 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 1 - .../Inputs/MacroSwift/ArrayTypes.swift | 5 +- .../ImportedTypeInExportedInterface.swift | 10 + .../Inputs/MacroSwift/SwiftStruct.swift | 7 + .../BridgeJSCodegenTests/ArrayTypes.json | 133 +++++++-- .../BridgeJSCodegenTests/ArrayTypes.swift | 75 +++-- .../ImportedTypeInExportedInterface.json | 131 +++++++++ .../ImportedTypeInExportedInterface.swift | 111 ++++++++ .../BridgeJSCodegenTests/SwiftStruct.json | 58 ++++ .../BridgeJSCodegenTests/SwiftStruct.swift | 60 ++++ .../BridgeJSLinkTests/ArrayTypes.d.ts | 4 +- .../BridgeJSLinkTests/ArrayTypes.js | 93 +++++- .../ImportedTypeInExportedInterface.d.ts | 7 + .../ImportedTypeInExportedInterface.js | 138 +++++++++ .../BridgeJSLinkTests/SwiftStruct.d.ts | 5 + .../BridgeJSLinkTests/SwiftStruct.js | 85 ++++++ .../Exporting-Swift/Exporting-Swift-Array.md | 2 + .../Exporting-Swift/Exporting-Swift-Struct.md | 2 + .../BridgeJSRuntimeTests/ExportAPITests.swift | 16 ++ .../Generated/BridgeJS.swift | 207 ++++++++++++++ .../Generated/JavaScript/BridgeJS.json | 264 ++++++++++++++++++ Tests/BridgeJSRuntimeTests/StructAPIs.swift | 20 ++ Tests/prelude.mjs | 56 ++++ 24 files changed, 1463 insertions(+), 51 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 85aeee131..33c455642 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -794,8 +794,10 @@ struct StackCodegen { func liftExpression(for type: BridgeType) -> ExprSyntax { switch type { case .string, .int, .uint, .bool, .float, .double, - .jsObject, .swiftStruct, .swiftHeapObject: + .jsObject(nil), .swiftStruct, .swiftHeapObject: return "\(raw: type.swiftType).bridgeJSLiftParameter()" + case .jsObject(let className?): + return "\(raw: className)(unsafelyWrapping: JSObject.bridgeJSLiftParameter())" case .unsafePointer: return "\(raw: type.swiftType).bridgeJSLiftParameter()" case .swiftProtocol(let protocolName): @@ -830,9 +832,11 @@ struct StackCodegen { func liftArrayExpression(elementType: BridgeType) -> ExprSyntax { switch elementType { case .int, .uint, .float, .double, .string, .bool, - .jsObject, .swiftStruct, .caseEnum, .swiftHeapObject, + .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 .optional, .array, .closure: @@ -861,9 +865,11 @@ struct StackCodegen { private func liftOptionalExpression(wrappedType: BridgeType) -> ExprSyntax { switch wrappedType { - case .string, .int, .uint, .bool, .float, .double, .jsObject, + case .string, .int, .uint, .bool, .float, .double, .jsObject(nil), .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: return "Optional<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" + case .jsObject(let className?): + return "Optional.bridgeJSLiftParameter().map { \(raw: className)(unsafelyWrapping: $0) }" case .array(let elementType): let arrayLift = liftArrayExpression(elementType: elementType) let swiftTypeName = elementType.swiftType @@ -896,8 +902,10 @@ struct StackCodegen { switch type { case .string, .int, .uint, .bool, .float, .double: return ["\(raw: accessor).bridgeJSLowerStackReturn()"] - case .jsObject: + 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): @@ -923,9 +931,11 @@ struct StackCodegen { ) -> [CodeBlockItemSyntax] { switch elementType { case .int, .uint, .float, .double, .string, .bool, - .jsObject, .swiftStruct, .caseEnum, .swiftHeapObject, + .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 .optional, .array, .closure: @@ -1003,8 +1013,10 @@ struct StackCodegen { case .associatedValueEnum: // Push payloads via bridgeJSLowerParameter(), then push the returned case ID return ["_swift_js_push_i32(\(raw: unwrappedVar).bridgeJSLowerParameter())"] - case .jsObject: + 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: diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 9a1979491..791bb8a8d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -2474,7 +2474,6 @@ 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 [] } ) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift index 678bc3698..c1980cbc2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift @@ -55,6 +55,9 @@ @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 checkArray(_ a: JSObject) throws(JSException) -> Void diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift index 9e3524284..db167c5a9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportedTypeInExportedInterface.swift @@ -5,3 +5,13 @@ @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/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftStruct.swift index ac316a05a..0d84f4736 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/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/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json index c90347177..7950cb66a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json @@ -945,6 +945,121 @@ } } } + }, + { + "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" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + }, + { + "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" : [ @@ -1027,24 +1142,6 @@ "returnType" : { "void" : { - } - } - }, - { - "name" : "checkArray", - "parameters" : [ - { - "name" : "a", - "type" : { - "jsObject" : { - - } - } - } - ], - "returnType" : { - "void" : { - } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index 4452446b9..c7c80c3b2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -465,6 +465,64 @@ public func _bjs_processNestedItemArray() -> Void { #endif } +@_expose(wasm, "bjs_processJSObjectArray") +@_cdecl("bjs_processJSObjectArray") +public func _bjs_processJSObjectArray() -> Void { + #if arch(wasm32) + 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: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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 { + __bjs_elem_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(Int32(ret.count)) + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_Item_deinit") @_cdecl("bjs_Item_deinit") public func _bjs_Item_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { @@ -523,21 +581,4 @@ func _$checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> V if let error = _swift_js_take_exception() { throw error } -} - -#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 - } } \ 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 index 10a18983b..c40f0dc82 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json @@ -24,13 +24,144 @@ "_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" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + } + }, + { + "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" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + ], + "swiftCallName" : "FooContainer" + } ] }, "imported" : { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift index 29b615b0f..6d9bee080 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift @@ -1,3 +1,54 @@ +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 { @@ -23,6 +74,66 @@ public func _bjs_makeFoo() -> Int32 { #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 diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json index fa5f333f0..1b2dc531f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json @@ -113,6 +113,31 @@ "_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" : [ @@ -516,6 +541,39 @@ } ], "swiftCallName" : "ConfigStruct" + }, + { + "methods" : [ + + ], + "name" : "Container", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "object", + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalObject", + "type" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "swiftCallName" : "Container" } ] }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift index 9b7ddd024..ca2467249 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift @@ -388,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 { @@ -399,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__/BridgeJSLinkTests/ArrayTypes.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts index 1bb9ff18c..3316cd7c3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts @@ -62,13 +62,15 @@ 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; - checkArray(a: any): void; } export function createInstantiator(options: { imports: Imports; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 3cb11c794..da5920660 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -263,13 +263,6 @@ export async function createInstantiator(options, swift) { setException(error); } } - TestModule["bjs_checkArray"] = function bjs_checkArray(a) { - try { - imports.checkArray(swift.memory.getObject(a)); - } catch (error) { - setException(error); - } - } }, setInstance: (i) => { instance = i; @@ -850,6 +843,92 @@ export async function createInstantiator(options, swift) { 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(); + arrayResult.push(arrayResult1); + } + arrayResult.reverse(); + for (const cleanup of arrayCleanups) { cleanup(); } + return arrayResult; + }, Direction: DirectionValues, Status: StatusValues, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.d.ts index 654b4bc04..22b4e6a1c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 094c2241d..e4ce9e8fe 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -34,6 +34,70 @@ export async function createInstantiator(options, swift) { 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 { /** @@ -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/SwiftStruct.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.d.ts index 7769ebcbe..4a61a26e3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index a3d60d0bd..dbeb70e69 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -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 { /** @@ -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; @@ -549,6 +624,9 @@ export async function createInstantiator(options, swift) { 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/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-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/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 520fe8298..b482fcdb1 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -1443,6 +1443,22 @@ enum GraphOperations { 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.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index b9b7dc1dc..fbd913c75 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -3152,6 +3152,106 @@ public func _bjs_ConfigStruct_static_computedSetting_get() -> Void { #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) + } + + @_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_JSObjectContainer(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_JSObjectContainer())) + } +} + +#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 + +#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 + +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_roundTripVoid") @_cdecl("bjs_roundTripVoid") public func _bjs_roundTripVoid() -> Void { @@ -5113,6 +5213,91 @@ public func _bjs_roundTripDataProcessorArrayType() -> Void { #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] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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_roundTripFooArray") +@_cdecl("bjs_roundTripFooArray") +public func _bjs_roundTripFooArray() -> Void { + #if arch(wasm32) + let ret = roundTripFooArray(_: { + 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_roundTripOptionalFooArray") +@_cdecl("bjs_roundTripOptionalFooArray") +public func _bjs_roundTripOptionalFooArray() -> Void { + #if arch(wasm32) + let ret = roundTripOptionalFooArray(_: { + 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_roundTripPointerFields") @_cdecl("bjs_roundTripPointerFields") public func _bjs_roundTripPointerFields() -> Void { @@ -5258,6 +5443,28 @@ public func _bjs_testContainerWithStruct() -> UnsafeMutableRawPointer { #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_Greeter_init") @_cdecl("bjs_Greeter_init") public func _bjs_Greeter_init(_ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 83845dd45..646374778 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -9450,6 +9450,154 @@ } } }, + { + "abiName" : "bjs_roundTripJSObjectArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripJSObjectArray", + "parameters" : [ + { + "label" : "_", + "name" : "objects", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + + } + } + } + } + }, + { + "abiName" : "bjs_roundTripOptionalJSObjectArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalJSObjectArray", + "parameters" : [ + { + "label" : "_", + "name" : "objects", + "type" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + } + }, + { + "abiName" : "bjs_roundTripFooArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripFooArray", + "parameters" : [ + { + "label" : "_", + "name" : "foos", + "type" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + }, + { + "abiName" : "bjs_roundTripOptionalFooArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalFooArray", + "parameters" : [ + { + "label" : "_", + "name" : "foos", + "type" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + } + }, { "abiName" : "bjs_roundTripPointerFields", "effects" : { @@ -9834,6 +9982,56 @@ "_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" + } + } } ], "protocols" : [ @@ -11365,6 +11563,72 @@ } ], "swiftCallName" : "ConfigStruct" + }, + { + "methods" : [ + + ], + "name" : "JSObjectContainer", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "object", + "type" : { + "jsObject" : { + + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalObject", + "type" : { + "optional" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "swiftCallName" : "JSObjectContainer" + }, + { + "methods" : [ + + ], + "name" : "FooContainer", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "foo", + "type" : { + "jsObject" : { + "_0" : "Foo" + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optionalFoo", + "type" : { + "optional" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + } + } + ], + "swiftCallName" : "FooContainer" } ] }, diff --git a/Tests/BridgeJSRuntimeTests/StructAPIs.swift b/Tests/BridgeJSRuntimeTests/StructAPIs.swift index 5c9fed511..c7de5d137 100644 --- a/Tests/BridgeJSRuntimeTests/StructAPIs.swift +++ b/Tests/BridgeJSRuntimeTests/StructAPIs.swift @@ -214,3 +214,23 @@ @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 +} diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 684ff02fc..850b31b6e 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -1164,6 +1164,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 */ @@ -1437,6 +1463,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 */ From 0662e3b2405e2f618b01e7de2989dba15afcaa22 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Tue, 3 Feb 2026 23:06:32 +0900 Subject: [PATCH 06/34] Revert "BridgeJS: Enforce throws(JSException) on @JS protocol methods" (#565) --- .../Sources/BridgeJSCore/ExportSwift.swift | 4 +- .../Sources/BridgeJSCore/ImportTS.swift | 32 +-- .../BridgeJSCore/SwiftToSkeleton.swift | 9 - .../Sources/BridgeJSLink/JSGlueGen.swift | 20 +- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 1 - .../Inputs/MacroSwift/Protocol.swift | 24 +- .../BridgeJSCodegenTests/Protocol.json | 24 +- .../BridgeJSCodegenTests/Protocol.swift | 60 +---- .../Exporting-Swift-Protocols.md | 30 +-- .../BridgeJSRuntimeTests/ExportAPITests.swift | 60 ++--- .../Generated/BridgeJS.swift | 209 +++--------------- .../Generated/JavaScript/BridgeJS.json | 40 ++-- 12 files changed, 154 insertions(+), 359 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 85aeee131..0c5debeac 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1346,7 +1346,7 @@ struct ProtocolCodegen { let builder = ImportTS.CallJSEmission( moduleName: moduleName, abiName: "_extern_\(method.name)", - context: .exportSwiftProtocol + context: .exportSwift ) try builder.lowerParameter(param: Parameter(label: nil, name: "jsObject", type: .jsObject(nil))) for param in method.parameters { @@ -1359,7 +1359,7 @@ struct ProtocolCodegen { let signature = SwiftSignatureBuilder.buildFunctionSignature( parameters: method.parameters, returnType: method.returnType, - effects: method.effects + effects: nil ) // Build extern declaration using helper function diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 70dda3848..7c391eea0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -187,8 +187,8 @@ public struct ImportTS { body.append("let ret = \(raw: callExpr)") } - // Add exception check for contexts that call INTO JavaScript - if context == .importTS || context == .exportSwiftProtocol { + // Add exception check for ImportTS context + if context == .importTS { body.append("if let error = _swift_js_take_exception() { throw error }") } } @@ -887,7 +887,7 @@ extension BridgeType { Swift classes can only be used in @JS protocols where Swift owns the instance. """ ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LoweringParameterInfo(loweredParameters: [("pointer", .pointer)]) } case .swiftProtocol: @@ -896,14 +896,14 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LoweringParameterInfo(loweredParameters: [("value", .i32)]) } case .rawValueEnum(_, let rawType): switch context { case .importTS: return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: // For protocol export we return .i32 for String raw value type instead of nil return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)]) } @@ -911,7 +911,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LoweringParameterInfo(loweredParameters: [("caseId", .i32)]) } case .swiftStruct: @@ -919,7 +919,7 @@ extension BridgeType { case .importTS: // Swift structs are bridged as JS objects (object IDs) in imported signatures. return LoweringParameterInfo(loweredParameters: [("objectId", .i32)]) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LoweringParameterInfo(loweredParameters: []) } case .namespaceEnum: @@ -928,7 +928,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) var params = [("isSome", WasmCoreType.i32)] params.append(contentsOf: wrappedInfo.loweredParameters) @@ -938,7 +938,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LoweringParameterInfo(loweredParameters: []) } } @@ -981,7 +981,7 @@ extension BridgeType { JavaScript cannot create Swift heap objects. """ ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LiftingReturnInfo(valueToLift: .pointer) } case .swiftProtocol: @@ -990,14 +990,14 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LiftingReturnInfo(valueToLift: .i32) } case .rawValueEnum(_, let rawType): switch context { case .importTS: return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: // For protocol export we return .i32 for String raw value type instead of nil return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32) } @@ -1005,7 +1005,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LiftingReturnInfo(valueToLift: .i32) } case .swiftStruct: @@ -1013,7 +1013,7 @@ extension BridgeType { case .importTS: // Swift structs are bridged as JS objects (object IDs) in imported signatures. return LiftingReturnInfo(valueToLift: .i32) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LiftingReturnInfo(valueToLift: nil) } case .namespaceEnum: @@ -1022,7 +1022,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) } @@ -1030,7 +1030,7 @@ extension BridgeType { switch context { case .importTS: throw BridgeJSCoreError("Array types are not yet supported in TypeScript imports") - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return LiftingReturnInfo(valueToLift: nil) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index edcb0a391..b780012f0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1608,15 +1608,6 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { return nil } - guard effects.isThrows else { - diagnose( - node: node, - message: "@JS protocol methods must be throws.", - hint: "Declare the method as 'throws(JSException)'." - ) - return nil - } - return ExportedFunction( name: name, abiName: abiName, diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 9a1979491..28f756a43 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -1477,7 +1477,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return .swiftHeapObjectLiftParameter(name) } case .swiftProtocol: return .jsObjectLiftParameter @@ -1491,7 +1491,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Optional types are not supported for imported JS functions: \(wrappedType)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return try .optionalLiftParameter(wrappedType: wrappedType) } case .caseEnum: return .identity @@ -1508,7 +1508,7 @@ struct IntrinsicJSFragment: Sendable { message: "Associated value enums are not supported to be passed as parameters to imported JS functions: \(fullName)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: let base = fullName.components(separatedBy: ".").last ?? fullName return IntrinsicJSFragment( parameters: ["caseId"], @@ -1526,7 +1526,7 @@ struct IntrinsicJSFragment: Sendable { switch context { case .importTS: return .jsObjectLiftRetainedObjectId - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: let base = fullName.components(separatedBy: ".").last ?? fullName return IntrinsicJSFragment( parameters: [], @@ -1558,7 +1558,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Arrays are not yet supported to be passed as parameters to imported JS functions" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return try arrayLift(elementType: elementType) } } @@ -1578,7 +1578,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "swiftHeapObject '\(name)' can only be used in protocol exports, not in \(context)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return .swiftHeapObjectLowerReturn } case .swiftProtocol: return .jsObjectLowerReturn @@ -1589,7 +1589,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Optional types are not supported for imported JS functions: \(wrappedType)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return try .optionalLowerReturn(wrappedType: wrappedType) } case .caseEnum: return .identity @@ -1606,7 +1606,7 @@ struct IntrinsicJSFragment: Sendable { message: "Associated value enums are not supported to be returned from imported JS functions: \(fullName)" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return associatedValueLowerReturn(fullName: fullName) } case .swiftStruct(let fullName): @@ -1614,7 +1614,7 @@ struct IntrinsicJSFragment: Sendable { case .importTS: // ImportTS expects Swift structs to come back as a retained JS object ID. return .jsObjectLowerReturn - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return swiftStructLowerReturn(fullName: fullName) } case .closure: @@ -1640,7 +1640,7 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Arrays are not yet supported to be returned from imported JS functions" ) - case .exportSwift, .exportSwiftProtocol: + case .exportSwift: return try arrayLower(elementType: elementType) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 01382e642..5013dda66 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -71,7 +71,6 @@ public struct ABINameGenerator { public enum BridgeContext: Sendable { case importTS case exportSwift - case exportSwiftProtocol } public struct ClosureSignature: Codable, Equatable, Hashable, Sendable { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift index 3e8df7405..fbbad0615 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Protocol.swift @@ -47,18 +47,18 @@ import JavaScriptKit var directionOptional: Direction? { get set } var priority: Priority { get set } var priorityOptional: Priority? { get set } - func onSomethingHappened() throws(JSException) - func onValueChanged(_ value: String) throws(JSException) - func onCountUpdated(count: Int) throws(JSException) -> Bool - func onLabelUpdated(_ prefix: String, _ suffix: String) throws(JSException) - func isCountEven() throws(JSException) -> Bool - func onHelperUpdated(_ helper: Helper) throws(JSException) - func createHelper() throws(JSException) -> Helper - func onOptionalHelperUpdated(_ helper: Helper?) throws(JSException) - func createOptionalHelper() throws(JSException) -> Helper? - func createEnum() throws(JSException) -> ExampleEnum - func handleResult(_ result: Result) throws(JSException) - func getResult() throws(JSException) -> Result + func onSomethingHappened() + func onValueChanged(_ value: String) + func onCountUpdated(count: Int) -> Bool + func onLabelUpdated(_ prefix: String, _ suffix: String) + func isCountEven() -> Bool + func onHelperUpdated(_ helper: Helper) + func createHelper() -> Helper + func onOptionalHelperUpdated(_ helper: Helper?) + func createOptionalHelper() -> Helper? + func createEnum() -> ExampleEnum + func handleResult(_ result: Result) + func getResult() -> Result } @JS class MyViewController { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json index 2f9c27ace..5713a2898 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -499,7 +499,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onSomethingHappened", "parameters" : [ @@ -516,7 +516,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onValueChanged", "parameters" : [ @@ -541,7 +541,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onCountUpdated", "parameters" : [ @@ -566,7 +566,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onLabelUpdated", "parameters" : [ @@ -600,7 +600,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "isCountEven", "parameters" : [ @@ -617,7 +617,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onHelperUpdated", "parameters" : [ @@ -642,7 +642,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "createHelper", "parameters" : [ @@ -659,7 +659,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "onOptionalHelperUpdated", "parameters" : [ @@ -688,7 +688,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "createOptionalHelper", "parameters" : [ @@ -709,7 +709,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "createEnum", "parameters" : [ @@ -727,7 +727,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "handleResult", "parameters" : [ @@ -752,7 +752,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getResult", "parameters" : [ diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index 91efeda7f..21178521d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -1,112 +1,76 @@ struct AnyMyViewControllerDelegate: MyViewControllerDelegate, _BridgedSwiftProtocolWrapper { let jsObject: JSObject - func onSomethingHappened() throws(JSException) -> Void { + func onSomethingHappened() -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() _extern_onSomethingHappened(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } } - func onValueChanged(_ value: String) throws(JSException) -> Void { + func onValueChanged(_ value: String) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let valueValue = value.bridgeJSLowerParameter() _extern_onValueChanged(jsObjectValue, valueValue) - if let error = _swift_js_take_exception() { - throw error - } } - func onCountUpdated(count: Int) throws(JSException) -> Bool { + func onCountUpdated(count: Int) -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let countValue = count.bridgeJSLowerParameter() let ret = _extern_onCountUpdated(jsObjectValue, countValue) - if let error = _swift_js_take_exception() { - throw error - } return Bool.bridgeJSLiftReturn(ret) } - func onLabelUpdated(_ prefix: String, _ suffix: String) throws(JSException) -> Void { + func onLabelUpdated(_ prefix: String, _ suffix: String) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let prefixValue = prefix.bridgeJSLowerParameter() let suffixValue = suffix.bridgeJSLowerParameter() _extern_onLabelUpdated(jsObjectValue, prefixValue, suffixValue) - if let error = _swift_js_take_exception() { - throw error - } } - func isCountEven() throws(JSException) -> Bool { + func isCountEven() -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_isCountEven(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Bool.bridgeJSLiftReturn(ret) } - func onHelperUpdated(_ helper: Helper) throws(JSException) -> Void { + func onHelperUpdated(_ helper: Helper) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let helperPointer = helper.bridgeJSLowerParameter() _extern_onHelperUpdated(jsObjectValue, helperPointer) - if let error = _swift_js_take_exception() { - throw error - } } - func createHelper() throws(JSException) -> Helper { + func createHelper() -> Helper { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createHelper(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Helper.bridgeJSLiftReturn(ret) } - func onOptionalHelperUpdated(_ helper: Optional) throws(JSException) -> Void { + func onOptionalHelperUpdated(_ helper: Optional) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (helperIsSome, helperPointer) = helper.bridgeJSLowerParameter() _extern_onOptionalHelperUpdated(jsObjectValue, helperIsSome, helperPointer) - if let error = _swift_js_take_exception() { - throw error - } } - func createOptionalHelper() throws(JSException) -> Optional { + func createOptionalHelper() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createOptionalHelper(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Optional.bridgeJSLiftReturn(ret) } - func createEnum() throws(JSException) -> ExampleEnum { + func createEnum() -> ExampleEnum { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createEnum(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return ExampleEnum.bridgeJSLiftReturn(ret) } - func handleResult(_ result: Result) throws(JSException) -> Void { + func handleResult(_ result: Result) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let resultCaseId = result.bridgeJSLowerParameter() _extern_handleResult(jsObjectValue, resultCaseId) - if let error = _swift_js_take_exception() { - throw error - } } - func getResult() throws(JSException) -> Result { + func getResult() -> Result { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getResult(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Result.bridgeJSLiftReturn(ret) } diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md index 4b58276ea..111b1f052 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Protocols.md @@ -15,7 +15,7 @@ When you mark a protocol with `@JS`, BridgeJS generates: ## Example: Counter Protocol -Mark a Swift protocol with `@JS` to expose it. Protocol methods must declare `throws(JSException)` to align with the import side error handling: +Mark a Swift protocol with `@JS` to expose it: ```swift import JavaScriptKit @@ -24,9 +24,9 @@ import JavaScriptKit var count: Int { get set } var name: String { get } var label: String? { get set } - func increment(by amount: Int) throws(JSException) - func reset() throws(JSException) - func getValue() throws(JSException) -> Int + func increment(by amount: Int) + func reset() + func getValue() -> Int } @JS class CounterManager { @@ -122,24 +122,24 @@ You can also implement protocols in Swift and use them from JavaScript: @JS protocol Counter { var count: Int { get set } var name: String { get } - func increment(by amount: Int) throws(JSException) - func reset() throws(JSException) - func getValue() throws(JSException) -> Int + func increment(by amount: Int) + func reset() + func getValue() -> Int } final class SwiftCounter: Counter { var count = 0 let name = "SwiftCounter" - - func increment(by amount: Int) throws(JSException) { + + func increment(by amount: Int) { count += amount } - - func reset() throws(JSException) { + + func reset() { count = 0 } - - func getValue() throws(JSException) -> Int { + + func getValue() -> Int { return count } } @@ -195,7 +195,7 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { } } - func increment(by amount: Int) throws(JSException) { + func increment(by amount: Int) { @_extern(wasm, module: "TestModule", name: "bjs_Counter_increment") func _extern_increment(this: Int32, amount: Int32) _extern_increment( @@ -212,7 +212,7 @@ struct AnyCounter: Counter, _BridgedSwiftProtocolWrapper { | Swift Feature | Status | |:--------------|:-------| -| Method requirements: `func foo(_ param: String?) throws(JSException) -> FooClass?` | ✅ | +| Method requirements: `func foo(_ param: String?) -> FooClass?` | ✅ | | Property requirements: `var property: Type { get }` / `var property: Type { get set }` | ✅ | | Optional parameters / return values in methods | ✅ | | Optional properties | ✅ | diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 520fe8298..711a42e2d 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -988,17 +988,17 @@ enum GraphOperations { var apiResult: APIResult? { get set } var helper: Greeter { get set } var optionalHelper: Greeter? { get set } - func increment(by amount: Int) throws(JSException) - func getValue() throws(JSException) -> Int - func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) throws(JSException) - func getLabel() throws(JSException) -> String - func isEven() throws(JSException) -> Bool - func processGreeter(_ greeter: Greeter) throws(JSException) -> String - func createGreeter() throws(JSException) -> Greeter - func processOptionalGreeter(_ greeter: Greeter?) throws(JSException) -> String - func createOptionalGreeter() throws(JSException) -> Greeter? - func handleAPIResult(_ result: APIResult?) throws(JSException) - func getAPIResult() throws(JSException) -> APIResult? + func increment(by amount: Int) + func getValue() -> Int + func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) + func getLabel() -> String + func isEven() -> Bool + func processGreeter(_ greeter: Greeter) -> String + func createGreeter() -> Greeter + func processOptionalGreeter(_ greeter: Greeter?) -> String + func createOptionalGreeter() -> Greeter? + func handleAPIResult(_ result: APIResult?) + func getAPIResult() -> APIResult? } @JS class DataProcessorManager { @@ -1011,33 +1011,33 @@ enum GraphOperations { self.backupProcessor = nil } - @JS func incrementByAmount(_ amount: Int) throws(JSException) { - try processor.increment(by: amount) + @JS func incrementByAmount(_ amount: Int) { + processor.increment(by: amount) } - @JS func setProcessorLabel(_ prefix: String, _ suffix: String) throws(JSException) { - try processor.setLabelElements(prefix, suffix) + @JS func setProcessorLabel(_ prefix: String, _ suffix: String) { + processor.setLabelElements(prefix, suffix) } - @JS func isProcessorEven() throws(JSException) -> Bool { - return try processor.isEven() + @JS func isProcessorEven() -> Bool { + return processor.isEven() } - @JS func getProcessorLabel() throws(JSException) -> String { - return try processor.getLabel() + @JS func getProcessorLabel() -> String { + return processor.getLabel() } - @JS func getCurrentValue() throws(JSException) -> Int { - return try processor.getValue() + @JS func getCurrentValue() -> Int { + return processor.getValue() } - @JS func incrementBoth() throws(JSException) { - try processor.increment(by: 1) - try backupProcessor?.increment(by: 1) + @JS func incrementBoth() { + processor.increment(by: 1) + backupProcessor?.increment(by: 1) } - @JS func getBackupValue() throws(JSException) -> Int? { - return try backupProcessor?.getValue() + @JS func getBackupValue() -> Int? { + return backupProcessor?.getValue() } @JS func hasBackup() -> Bool { @@ -1084,12 +1084,12 @@ enum GraphOperations { processor.httpStatus = status } - @JS func getProcessorAPIResult() throws(JSException) -> APIResult? { - return try processor.getAPIResult() + @JS func getProcessorAPIResult() -> APIResult? { + return processor.getAPIResult() } - @JS func setProcessorAPIResult(_ apiResult: APIResult?) throws(JSException) { - try processor.handleAPIResult(apiResult) + @JS func setProcessorAPIResult(_ apiResult: APIResult?) { + processor.handleAPIResult(apiResult) } } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index b9b7dc1dc..55a77466e 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -921,105 +921,72 @@ public func _invoke_swift_closure_BridgeJSRuntimeTests_20BridgeJSRuntimeTestsy_S struct AnyDataProcessor: DataProcessor, _BridgedSwiftProtocolWrapper { let jsObject: JSObject - func increment(by amount: Int) throws(JSException) -> Void { + func increment(by amount: Int) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let amountValue = amount.bridgeJSLowerParameter() _extern_increment(jsObjectValue, amountValue) - if let error = _swift_js_take_exception() { - throw error - } } - func getValue() throws(JSException) -> Int { + func getValue() -> Int { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getValue(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Int.bridgeJSLiftReturn(ret) } - func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) throws(JSException) -> Void { + func setLabelElements(_ labelPrefix: String, _ labelSuffix: String) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let labelPrefixValue = labelPrefix.bridgeJSLowerParameter() let labelSuffixValue = labelSuffix.bridgeJSLowerParameter() _extern_setLabelElements(jsObjectValue, labelPrefixValue, labelSuffixValue) - if let error = _swift_js_take_exception() { - throw error - } } - func getLabel() throws(JSException) -> String { + func getLabel() -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getLabel(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return String.bridgeJSLiftReturn(ret) } - func isEven() throws(JSException) -> Bool { + func isEven() -> Bool { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_isEven(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Bool.bridgeJSLiftReturn(ret) } - func processGreeter(_ greeter: Greeter) throws(JSException) -> String { + func processGreeter(_ greeter: Greeter) -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let greeterPointer = greeter.bridgeJSLowerParameter() let ret = _extern_processGreeter(jsObjectValue, greeterPointer) - if let error = _swift_js_take_exception() { - throw error - } return String.bridgeJSLiftReturn(ret) } - func createGreeter() throws(JSException) -> Greeter { + func createGreeter() -> Greeter { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createGreeter(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Greeter.bridgeJSLiftReturn(ret) } - func processOptionalGreeter(_ greeter: Optional) throws(JSException) -> String { + func processOptionalGreeter(_ greeter: Optional) -> String { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (greeterIsSome, greeterPointer) = greeter.bridgeJSLowerParameter() let ret = _extern_processOptionalGreeter(jsObjectValue, greeterIsSome, greeterPointer) - if let error = _swift_js_take_exception() { - throw error - } return String.bridgeJSLiftReturn(ret) } - func createOptionalGreeter() throws(JSException) -> Optional { + func createOptionalGreeter() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_createOptionalGreeter(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Optional.bridgeJSLiftReturn(ret) } - func handleAPIResult(_ result: Optional) throws(JSException) -> Void { + func handleAPIResult(_ result: Optional) -> Void { let jsObjectValue = jsObject.bridgeJSLowerParameter() let (resultIsSome, resultCaseId) = result.bridgeJSLowerParameter() _extern_handleAPIResult(jsObjectValue, resultIsSome, resultCaseId) - if let error = _swift_js_take_exception() { - throw error - } } - func getAPIResult() throws(JSException) -> Optional { + func getAPIResult() -> Optional { let jsObjectValue = jsObject.bridgeJSLowerParameter() let ret = _extern_getAPIResult(jsObjectValue) - if let error = _swift_js_take_exception() { - throw error - } return Optional.bridgeJSLiftReturn(ret) } @@ -6592,21 +6559,7 @@ public func _bjs_DataProcessorManager_init(_ processor: Int32) -> UnsafeMutableR @_cdecl("bjs_DataProcessorManager_incrementByAmount") public func _bjs_DataProcessorManager_incrementByAmount(_ _self: UnsafeMutableRawPointer, _ amount: Int32) -> Void { #if arch(wasm32) - do { - try DataProcessorManager.bridgeJSLiftParameter(_self).incrementByAmount(_: Int.bridgeJSLiftParameter(amount)) - } 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 - } + DataProcessorManager.bridgeJSLiftParameter(_self).incrementByAmount(_: Int.bridgeJSLiftParameter(amount)) #else fatalError("Only available on WebAssembly") #endif @@ -6616,21 +6569,7 @@ public func _bjs_DataProcessorManager_incrementByAmount(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_setProcessorLabel") public func _bjs_DataProcessorManager_setProcessorLabel(_ _self: UnsafeMutableRawPointer, _ prefixBytes: Int32, _ prefixLength: Int32, _ suffixBytes: Int32, _ suffixLength: Int32) -> Void { #if arch(wasm32) - do { - try DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorLabel(_: String.bridgeJSLiftParameter(prefixBytes, prefixLength), _: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) - } 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 - } + DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorLabel(_: String.bridgeJSLiftParameter(prefixBytes, prefixLength), _: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) #else fatalError("Only available on WebAssembly") #endif @@ -6640,22 +6579,8 @@ public func _bjs_DataProcessorManager_setProcessorLabel(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_isProcessorEven") public func _bjs_DataProcessorManager_isProcessorEven(_ _self: UnsafeMutableRawPointer) -> Int32 { #if arch(wasm32) - do { - let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).isProcessorEven() - 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 - } + let ret = DataProcessorManager.bridgeJSLiftParameter(_self).isProcessorEven() + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6665,22 +6590,8 @@ public func _bjs_DataProcessorManager_isProcessorEven(_ _self: UnsafeMutableRawP @_cdecl("bjs_DataProcessorManager_getProcessorLabel") public func _bjs_DataProcessorManager_getProcessorLabel(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - do { - let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorLabel() - 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 - } + let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorLabel() + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6690,22 +6601,8 @@ public func _bjs_DataProcessorManager_getProcessorLabel(_ _self: UnsafeMutableRa @_cdecl("bjs_DataProcessorManager_getCurrentValue") public func _bjs_DataProcessorManager_getCurrentValue(_ _self: UnsafeMutableRawPointer) -> Int32 { #if arch(wasm32) - do { - let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getCurrentValue() - 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 - } + let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getCurrentValue() + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6715,21 +6612,7 @@ public func _bjs_DataProcessorManager_getCurrentValue(_ _self: UnsafeMutableRawP @_cdecl("bjs_DataProcessorManager_incrementBoth") public func _bjs_DataProcessorManager_incrementBoth(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - do { - try DataProcessorManager.bridgeJSLiftParameter(_self).incrementBoth() - } 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 - } + DataProcessorManager.bridgeJSLiftParameter(_self).incrementBoth() #else fatalError("Only available on WebAssembly") #endif @@ -6739,22 +6622,8 @@ public func _bjs_DataProcessorManager_incrementBoth(_ _self: UnsafeMutableRawPoi @_cdecl("bjs_DataProcessorManager_getBackupValue") public func _bjs_DataProcessorManager_getBackupValue(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - do { - let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getBackupValue() - 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 - } + let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getBackupValue() + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6880,22 +6749,8 @@ public func _bjs_DataProcessorManager_setProcessorHttpStatus(_ _self: UnsafeMuta @_cdecl("bjs_DataProcessorManager_getProcessorAPIResult") public func _bjs_DataProcessorManager_getProcessorAPIResult(_ _self: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - do { - let ret = try DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorAPIResult() - 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 - } + let ret = DataProcessorManager.bridgeJSLiftParameter(_self).getProcessorAPIResult() + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6905,21 +6760,7 @@ public func _bjs_DataProcessorManager_getProcessorAPIResult(_ _self: UnsafeMutab @_cdecl("bjs_DataProcessorManager_setProcessorAPIResult") public func _bjs_DataProcessorManager_setProcessorAPIResult(_ _self: UnsafeMutableRawPointer, _ apiResultIsSome: Int32, _ apiResultCaseId: Int32) -> Void { #if arch(wasm32) - do { - try DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorAPIResult(_: Optional.bridgeJSLiftParameter(apiResultIsSome, apiResultCaseId)) - } 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 - } + DataProcessorManager.bridgeJSLiftParameter(_self).setProcessorAPIResult(_: Optional.bridgeJSLiftParameter(apiResultIsSome, apiResultCaseId)) #else fatalError("Only available on WebAssembly") #endif diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 83845dd45..e31c69a51 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -1365,7 +1365,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "incrementByAmount", "parameters" : [ @@ -1390,7 +1390,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "setProcessorLabel", "parameters" : [ @@ -1424,7 +1424,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "isProcessorEven", "parameters" : [ @@ -1441,7 +1441,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getProcessorLabel", "parameters" : [ @@ -1458,7 +1458,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getCurrentValue", "parameters" : [ @@ -1475,7 +1475,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "incrementBoth", "parameters" : [ @@ -1492,7 +1492,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getBackupValue", "parameters" : [ @@ -1784,7 +1784,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getProcessorAPIResult", "parameters" : [ @@ -1805,7 +1805,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "setProcessorAPIResult", "parameters" : [ @@ -9844,7 +9844,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "increment", "parameters" : [ @@ -9869,7 +9869,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getValue", "parameters" : [ @@ -9886,7 +9886,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "setLabelElements", "parameters" : [ @@ -9920,7 +9920,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getLabel", "parameters" : [ @@ -9937,7 +9937,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "isEven", "parameters" : [ @@ -9954,7 +9954,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "processGreeter", "parameters" : [ @@ -9979,7 +9979,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "createGreeter", "parameters" : [ @@ -9996,7 +9996,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "processOptionalGreeter", "parameters" : [ @@ -10025,7 +10025,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "createOptionalGreeter", "parameters" : [ @@ -10046,7 +10046,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "handleAPIResult", "parameters" : [ @@ -10075,7 +10075,7 @@ "effects" : { "isAsync" : false, "isStatic" : false, - "isThrows" : true + "isThrows" : false }, "name" : "getAPIResult", "parameters" : [ From bc6103856f61bc0fd9b6147d20bce3af8c366679 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 01:36:30 +0900 Subject: [PATCH 07/34] TS2Swift: Skip type checks when translating TS -> Swift (#567) --- .../BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index 1d2d0f64f..776477580 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); } /** From edabb977f4e0e2a62703111dfdc27d537a695a2f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 02:45:26 +0900 Subject: [PATCH 08/34] BridgeJS: emit typed throws without extra space (#571) --- .../Sources/Generated/BridgeJS.Macros.swift | 6 +- .../Generated/BridgeJS.Macros.swift | 4 +- .../TS2Swift/JavaScript/src/processor.js | 2 +- .../test/__snapshots__/ts2swift.test.js.snap | 122 +++++++++--------- .../Generated/BridgeJS.Macros.swift | 48 +++---- 5 files changed, 91 insertions(+), 91 deletions(-) diff --git a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift index edf727004..39a46d22c 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.Macros.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.Macros.swift @@ -6,8 +6,8 @@ @_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/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift index cc62396ea..c619a8883 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.Macros.swift @@ -6,8 +6,8 @@ @_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/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index 776477580..258334ee8 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -874,7 +874,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 index 5b5316a40..6add64de4 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -9,11 +9,11 @@ exports[`ts2swift > snapshots Swift output for ArrayParameter.d.ts > ArrayParame @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void +@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void -@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws (JSException) -> Void +@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void -@JSFunction func checkArray(_ a: JSObject) throws (JSException) -> Void +@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void " `; @@ -26,19 +26,19 @@ exports[`ts2swift > snapshots Swift output for Async.d.ts > Async 1`] = ` @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func asyncReturnVoid() throws (JSException) -> JSPromise +@JSFunction func asyncReturnVoid() throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripInt(_ v: Double) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripInt(_ v: Double) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripString(_ v: String) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripString(_ v: String) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripBool(_ v: Bool) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripBool(_ v: Bool) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripFloat(_ v: Double) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripFloat(_ v: Double) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripDouble(_ v: Double) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws (JSException) -> JSPromise +@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws(JSException) -> JSPromise " `; @@ -51,11 +51,11 @@ exports[`ts2swift > snapshots Swift output for Interface.d.ts > Interface 1`] = @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func returnAnimatable() throws (JSException) -> Animatable +@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 + @JSFunction func animate(_ keyframes: JSObject, _ options: JSObject) throws(JSException) -> JSObject + @JSFunction func getAnimations(_ options: JSObject) throws(JSException) -> JSObject } " `; @@ -69,42 +69,42 @@ exports[`ts2swift > snapshots Swift output for InvalidPropertyNames.d.ts > Inval @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func createArrayBuffer() throws (JSException) -> ArrayBufferLike +@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 slice(_ begin: Double, _ end: Double) throws(JSException) -> ArrayBufferLike } -@JSFunction func createWeirdObject() throws (JSException) -> WeirdNaming +@JSFunction func createWeirdObject() throws(JSException) -> WeirdNaming @JSClass struct WeirdNaming { @JSGetter var normalProperty: String - @JSSetter func setNormalProperty(_ value: String) throws (JSException) + @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) + @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) + @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) + @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) + @JSSetter(jsName: "@specialChar") func set_specialChar(_ value: Double) throws(JSException) @JSGetter var constructor: String - @JSSetter func setConstructor(_ value: String) throws (JSException) + @JSSetter func setConstructor(_ value: String) throws(JSException) @JSGetter var \`for\`: String - @JSSetter func setFor(_ value: String) throws (JSException) + @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 + @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 init() throws(JSException) + @JSFunction(jsName: "method-with-dashes") func method_with_dashes() throws(JSException) -> Void } -@JSFunction func createWeirdClass() throws (JSException) -> _Weird +@JSFunction func createWeirdClass() throws(JSException) -> _Weird " `; @@ -117,29 +117,29 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func createDatabaseConnection(_ config: JSObject) throws (JSException) -> DatabaseConnection +@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 + @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) + @JSSetter func setConnectionTimeout(_ value: Double) throws(JSException) } -@JSFunction func createLogger(_ level: String) throws (JSException) -> Logger +@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 + @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 +@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 + @JSFunction func get(_ key: String) throws(JSException) -> JSObject + @JSFunction func set(_ key: String, _ value: JSObject) throws(JSException) -> Void @JSGetter var configPath: String } " @@ -154,7 +154,7 @@ exports[`ts2swift > snapshots Swift output for PrimitiveParameters.d.ts > Primit @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func check(_ a: Double, _ b: Bool) throws (JSException) -> Void +@JSFunction func check(_ a: Double, _ b: Bool) throws(JSException) -> Void " `; @@ -167,9 +167,9 @@ exports[`ts2swift > snapshots Swift output for PrimitiveReturn.d.ts > PrimitiveR @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkNumber() throws (JSException) -> Double +@JSFunction func checkNumber() throws(JSException) -> Double -@JSFunction func checkBoolean() throws (JSException) -> Bool +@JSFunction func checkBoolean() throws(JSException) -> Bool " `; @@ -182,11 +182,11 @@ exports[`ts2swift > snapshots Swift output for ReExportFrom.d.ts > ReExportFrom @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func jsRoundTripNumber(_ v: Double) throws (JSException) -> Double +@JSFunction func jsRoundTripNumber(_ v: Double) throws(JSException) -> Double @JSClass struct JsGreeter { - @JSFunction init(_ name: String) throws (JSException) - @JSFunction func greet() throws (JSException) -> String + @JSFunction init(_ name: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String } " `; @@ -206,9 +206,9 @@ enum FeatureFlag: String { } extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} -@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws (JSException) -> Void +@JSFunction func takesFeatureFlag(_ flag: FeatureFlag) throws(JSException) -> Void -@JSFunction func returnsFeatureFlag() throws (JSException) -> FeatureFlag +@JSFunction func returnsFeatureFlag() throws(JSException) -> FeatureFlag " `; @@ -221,9 +221,9 @@ exports[`ts2swift > snapshots Swift output for StringParameter.d.ts > StringPara @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkString(_ a: String) throws (JSException) -> Void +@JSFunction func checkString(_ a: String) throws(JSException) -> Void -@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws (JSException) -> Void +@JSFunction func checkStringWithLength(_ a: String, _ b: Double) throws(JSException) -> Void " `; @@ -236,7 +236,7 @@ exports[`ts2swift > snapshots Swift output for StringReturn.d.ts > StringReturn @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkString() throws (JSException) -> String +@JSFunction func checkString() throws(JSException) -> String " `; @@ -249,18 +249,18 @@ exports[`ts2swift > snapshots Swift output for TS2SkeletonLike.d.ts > TS2Skeleto @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func createTS2Skeleton() throws (JSException) -> TypeScriptProcessor +@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 + @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 +@JSFunction func createCodeGenerator(_ format: String) throws(JSException) -> CodeGenerator @JSClass struct CodeGenerator { - @JSFunction func generate(_ input: JSObject) throws (JSException) -> String + @JSFunction func generate(_ input: JSObject) throws(JSException) -> String @JSGetter var outputFormat: String } " @@ -275,7 +275,7 @@ exports[`ts2swift > snapshots Swift output for TypeAlias.d.ts > TypeAlias 1`] = @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkSimple(_ a: Double) throws (JSException) -> Void +@JSFunction func checkSimple(_ a: Double) throws(JSException) -> Void " `; @@ -290,11 +290,11 @@ exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScript @JSClass struct Greeter { @JSGetter var name: String - @JSSetter func setName(_ value: String) throws (JSException) + @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 init(_ name: String) throws(JSException) + @JSFunction func greet() throws(JSException) -> String + @JSFunction func changeName(_ name: String) throws(JSException) -> Void } " `; @@ -308,6 +308,6 @@ exports[`ts2swift > snapshots Swift output for VoidParameterVoidReturn.d.ts > Vo @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func check() throws (JSException) -> Void +@JSFunction func check() throws(JSException) -> Void " `; diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index 6836000c6..e066ad272 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -6,21 +6,21 @@ @_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 jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void -@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws (JSException) -> Double +@JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double -@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws (JSException) -> Bool +@JSFunction func jsThrowOrBool(_ shouldThrow: Bool) throws(JSException) -> Bool -@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws (JSException) -> String +@JSFunction func jsThrowOrString(_ shouldThrow: Bool) throws(JSException) -> String enum FeatureFlag: String { case foo = "foo" @@ -28,38 +28,38 @@ enum FeatureFlag: String { } 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 } -@JSFunction(from: .global) func parseInt(_ string: String) 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 From 89ed56e9cccf5a41d07fba75e6fcb51b1c4ad64b Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 11:34:58 +0900 Subject: [PATCH 09/34] CI: Cancel previous workflow runs on PRs --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2859b7043..06faa39f0 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 From 6990143e74bbd28f7e7bc8c99f22efd40e504c2c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 01:22:49 +0900 Subject: [PATCH 10/34] BridgeJS: Support `@JSFunction static func` --- .../Generated/JavaScript/BridgeJS.json | 3 + .../Sources/BridgeJSCore/ImportTS.swift | 22 ++++ .../BridgeJSCore/SwiftToSkeleton.swift | 51 ++++++++- .../Sources/BridgeJSLink/BridgeJSLink.swift | 42 ++++++- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 11 +- .../TS2Swift/JavaScript/src/processor.js | 6 +- .../MacroSwift/JSClassStaticFunctions.swift | 13 +++ .../BridgeJSCodegenTests/GlobalGetter.json | 3 + .../GlobalThisImports.json | 6 + .../ImportedTypeInExportedInterface.json | 3 + .../InvalidPropertyNames.json | 6 + .../BridgeJSCodegenTests/JSClass.json | 6 + .../JSClassStaticFunctions.json | 108 ++++++++++++++++++ .../JSClassStaticFunctions.swift | 86 ++++++++++++++ .../Generated/BridgeJS.Macros.swift | 9 ++ .../Generated/BridgeJS.swift | 105 +++++++++++++++++ .../Generated/JavaScript/BridgeJS.json | 100 ++++++++++++++++ .../BridgeJSRuntimeTests/ImportAPITests.swift | 13 +++ Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 9 ++ Tests/prelude.mjs | 22 ++++ 20 files changed, 615 insertions(+), 9 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json index 1cf8e64c6..2952e2157 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json @@ -191,6 +191,9 @@ "name" : "TS2Swift", "setters" : [ + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 7c391eea0..234bdc66c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -398,6 +398,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 +480,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)) } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index b780012f0..7928a5c1b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1856,6 +1856,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private let inputFilePath: String private var jsClassNames: Set private let parent: SwiftToSkeleton + private var staticMethodsByType: [String: [ImportedFunctionSkeleton]] = [:] // MARK: - State Management @@ -1876,6 +1877,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { let from: JSImportFrom? var constructor: ImportedConstructorSkeleton? var methods: [ImportedFunctionSkeleton] + var staticMethods: [ImportedFunctionSkeleton] var getters: [ImportedGetterSkeleton] var setters: [ImportedSetterSkeleton] } @@ -2094,6 +2096,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: nil, constructor: nil, methods: [], + staticMethods: [], getters: [], setters: [] ) @@ -2107,6 +2110,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: from, constructor: nil, methods: [], + staticMethods: [], getters: [], setters: [] ) @@ -2114,6 +2118,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private func exitJSClass() { if case .jsClassBody(let typeName) = state, let type = currentType, type.name == typeName { + let externalStaticMethods = staticMethodsByType[type.name] ?? [] importedTypes.append( ImportedTypeSkeleton( name: type.name, @@ -2121,11 +2126,13 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: type.from, constructor: type.constructor, methods: type.methods, + staticMethods: type.staticMethods + externalStaticMethods, getters: type.getters, setters: type.setters, documentation: nil ) ) + staticMethodsByType[type.name] = nil currentType = nil } stateStack.removeLast() @@ -2217,8 +2224,14 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { ) -> Bool { if let jsFunction = AttributeChecker.firstJSFunctionAttribute(node.attributes) { if isStaticMember { - parseFunction(jsFunction, node, enclosingTypeName: typeName, isStaticMember: true).map { - importedFunctions.append($0) + parseFunction( + jsFunction, + node, + enclosingTypeName: typeName, + isStaticMember: true, + includeTypeNameForStatic: false + ).map { + type.staticMethods.append($0) } } else { parseFunction(jsFunction, node, enclosingTypeName: typeName, isStaticMember: false).map { @@ -2319,9 +2332,34 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { 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) + let parsed = parseFunction( + jsFunction, + function, + enclosingTypeName: typeName, + isStaticMember: true, + includeTypeNameForStatic: !jsClassNames.contains(typeName) + ) { - importedFunctions.append(parsed) + if jsClassNames.contains(typeName) { + if let index = importedTypes.firstIndex(where: { $0.name == typeName }) { + let existing = importedTypes[index] + importedTypes[index] = ImportedTypeSkeleton( + name: existing.name, + jsName: existing.jsName, + from: existing.from, + constructor: existing.constructor, + methods: existing.methods, + staticMethods: existing.staticMethods + [parsed], + getters: existing.getters, + setters: existing.setters, + documentation: existing.documentation + ) + } else { + staticMethodsByType[typeName, default: []].append(parsed) + } + } else { + importedFunctions.append(parsed) + } } else if AttributeChecker.hasJSSetterAttribute(function.attributes) { errors.append( DiagnosticError( @@ -2366,7 +2404,8 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { _ jsFunction: AttributeSyntax, _ node: FunctionDeclSyntax, enclosingTypeName: String?, - isStaticMember: Bool + isStaticMember: Bool, + includeTypeNameForStatic: Bool = true ) -> ImportedFunctionSkeleton? { guard validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSFunction") != nil else { @@ -2377,7 +2416,7 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { let jsName = AttributeChecker.extractJSName(from: jsFunction) let from = AttributeChecker.extractJSImportFrom(from: jsFunction) let name: String - if isStaticMember, let enclosingTypeName { + if isStaticMember, includeTypeNameForStatic, let enclosingTypeName { name = "\(enclosingTypeName)_\(baseName)" } else { name = baseName diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 60b55cd47..c1b4d2e77 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -2246,6 +2246,14 @@ 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) @@ -2318,7 +2326,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)" @@ -3130,6 +3138,12 @@ 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) + } for method in type.methods { let (js, dts) = try renderImportedMethod(context: type, method: method) importObjectBuilder.assignToImportObject(name: method.abiName(context: type), function: js) @@ -3207,6 +3221,32 @@ extension BridgeJSLink { return (funcLines, []) } + func renderImportedStaticMethod( + context: ImportedTypeSkeleton, + method: ImportedFunctionSkeleton + ) throws -> (js: [String], dts: [String]) { + let thunkBuilder = ImportedThunkBuilder() + 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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 5013dda66..66dda6cb0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -640,9 +640,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 ) } } @@ -752,6 +757,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? @@ -762,6 +769,7 @@ public struct ImportedTypeSkeleton: Codable { from: JSImportFrom? = nil, constructor: ImportedConstructorSkeleton? = nil, methods: [ImportedFunctionSkeleton], + staticMethods: [ImportedFunctionSkeleton] = [], getters: [ImportedGetterSkeleton] = [], setters: [ImportedSetterSkeleton] = [], documentation: String? = nil @@ -771,6 +779,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 diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index 258334ee8..0bd17422b 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -821,8 +821,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}`); } /** 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..fdfe02003 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift @@ -0,0 +1,13 @@ +extension StaticBox { + @JSFunction static func makeDefault() throws(JSException) -> StaticBox +} + +@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 +} + +extension StaticBox { + @JSFunction(jsName: "with-dashes") static func dashed() throws(JSException) -> StaticBox +} diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json index c9be60d8a..031870e57 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json @@ -61,6 +61,9 @@ "name" : "JSConsole", "setters" : [ + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json index 5cec23259..c75d9e011 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json @@ -81,6 +81,9 @@ "name" : "JSConsole", "setters" : [ + ], + "staticMethods" : [ + ] }, { @@ -116,6 +119,9 @@ "name" : "WebSocket", "setters" : [ + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json index c40f0dc82..659232d56 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json @@ -186,6 +186,9 @@ "name" : "Foo", "setters" : [ + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json index 40b97c12b..b983f27a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json @@ -219,6 +219,9 @@ } } } + ], + "staticMethods" : [ + ] }, { @@ -248,6 +251,9 @@ "name" : "_Weird", "setters" : [ + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json index 07906a404..be1d0f4cd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json @@ -107,6 +107,9 @@ } } } + ], + "staticMethods" : [ + ] }, { @@ -162,6 +165,9 @@ "name" : "Animatable", "setters" : [ + ], + "staticMethods" : [ + ] } ] 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..55fdb844c --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -0,0 +1,108 @@ +{ + "exported" : { + "classes" : [ + + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "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" + } + } + } + ] + } + ] + } + ] + }, + "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..ed54edf9d --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift @@ -0,0 +1,86 @@ +#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) +} \ No newline at end of file diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index e066ad272..1e8737280 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -48,6 +48,15 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @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 @JSClass(from: .global) struct Animal { diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 94359a709..556409c07 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -8140,6 +8140,111 @@ func _$_WeirdClass_method_with_dashes(_ self: JSObject) throws(JSException) -> S 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_StaticBox_with_dashes_static") +fileprivate func bjs_StaticBox_with_dashes_static() -> Int32 +#else +fileprivate func bjs_StaticBox_with_dashes_static() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", 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_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 _$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_with_dashes() throws(JSException) -> StaticBox { + let ret = bjs_StaticBox_with_dashes_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: "BridgeJSRuntimeTests", name: "bjs_Animal_init") fileprivate func bjs_Animal_init(_ name: Int32, _ age: Float64, _ isCat: Int32) -> Int32 diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 4b8ac7c7b..a2e4310d9 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -11668,6 +11668,9 @@ "name" : "Foo", "setters" : [ + ], + "staticMethods" : [ + ] } ] @@ -11967,6 +11970,9 @@ } } } + ], + "staticMethods" : [ + ] }, { @@ -11996,6 +12002,97 @@ "name" : "_WeirdClass", "setters" : [ + ], + "staticMethods" : [ + + ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ] + }, + "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" : "with_dashes", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + } ] }, { @@ -12107,6 +12204,9 @@ } } } + ], + "staticMethods" : [ + ] } ] diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index ea9f8c68f..b43a711e2 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -127,4 +127,17 @@ 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) + } } diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index 983d6052d..e38445805 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -31,3 +31,12 @@ 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; +} diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 850b31b6e..58a85acc2 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -9,6 +9,27 @@ 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) => { @@ -78,6 +99,7 @@ export async function setupOptions(options, context) { return "ok"; } }, + StaticBox, Foo: ImportedFoo, runAsyncWorks: async () => { const exports = importsContext.getExports(); From a2aa6e1d07e60f8397bf02fd7b8acc51c9d058c7 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 11:19:11 +0900 Subject: [PATCH 11/34] BridgeJS: Cover static methods in ts2swift tests --- .../JavaScript/test/__snapshots__/ts2swift.test.js.snap | 1 + .../TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts | 2 ++ 2 files changed, 3 insertions(+) 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 index 6add64de4..c7f3b6652 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -295,6 +295,7 @@ exports[`ts2swift > snapshots Swift output for TypeScriptClass.d.ts > TypeScript @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 } " `; diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/TypeScriptClass.d.ts index 074772f24..0745de1f9 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/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; } From 4e3f02b623375316981153bcaf9280bda115bb99 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 11:33:10 +0900 Subject: [PATCH 12/34] BridgeJS: Fix d.ts rendering of static methods --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 32 +- .../MacroSwift/JSClassStaticFunctions.swift | 5 + .../JSClassStaticFunctions.json | 44 +++ .../JSClassStaticFunctions.swift | 36 +++ .../JSClassStaticFunctions.d.ts | 32 ++ .../JSClassStaticFunctions.js | 286 ++++++++++++++++++ 6 files changed, 422 insertions(+), 13 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index c1b4d2e77..d39b524b5 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -3144,6 +3144,25 @@ extension BridgeJSLink { 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) @@ -3174,19 +3193,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( diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift index fdfe02003..ecf1b2473 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift @@ -11,3 +11,8 @@ extension StaticBox { extension 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 +} \ 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 index 55fdb844c..df3d3829e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -99,6 +99,50 @@ } } ] + }, + { + "constructor" : { + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ] + }, + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "WithCtor", + "setters" : [ + + ], + "staticMethods" : [ + { + "name" : "create", + "parameters" : [ + { + "name" : "value", + "type" : { + "double" : { + + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "WithCtor" + } + } + } + ] } ] } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift index ed54edf9d..5e297f929 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift @@ -83,4 +83,40 @@ func _$StaticBox_value(_ self: JSObject) throws(JSException) -> Double { 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__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts new file mode 100644 index 000000000..3b2b5de99 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts @@ -0,0 +1,32 @@ +// 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 StaticBox { + value(): number; +} +export interface WithCtor { +} +export type Exports = { +} +export type Imports = { + 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: { + 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/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js new file mode 100644 index 000000000..f8f0ba86f --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -0,0 +1,286 @@ +// 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_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { + try { + let ret = imports.StaticBox.create(value); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { + try { + let ret = imports.StaticBox.value(); + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { + try { + let ret = imports.StaticBox.makeDefault(); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { + try { + let ret = imports.StaticBox["with-dashes"](); + return swift.memory.retain(ret); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_StaticBox_value"] = function bjs_StaticBox_value(self) { + try { + let ret = swift.memory.getObject(self).value(); + return ret; + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_WithCtor_init"] = function bjs_WithCtor_init(value) { + try { + return swift.memory.retain(new imports.WithCtor(value)); + } catch (error) { + setException(error); + return 0 + } + } + TestModule["bjs_WithCtor_create_static"] = function bjs_WithCtor_create_static(value) { + try { + let ret = imports.WithCtor.create(value); + 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 From 0c3cb258e028fd10bc1c2bad2255074cd80ed04e Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 11:36:11 +0900 Subject: [PATCH 13/34] ./Utilities/format.swift --- Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift | 3 ++- .../Inputs/MacroSwift/JSClassStaticFunctions.swift | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index d39b524b5..fd5faee24 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -3156,7 +3156,8 @@ extension BridgeJSLink { } 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)));" + let signature = + "\(renderTSPropertyName(methodName))\(renderTSSignature(parameters: method.parameters, returnType: method.returnType, effects: Effects(isAsync: false, isThrows: false)));" dtsPrinter.write(signature) } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift index ecf1b2473..891eab118 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift @@ -15,4 +15,4 @@ extension StaticBox { @JSClass struct WithCtor { @JSFunction init(_ value: Double) throws(JSException) @JSFunction static func create(_ value: Double) throws(JSException) -> WithCtor -} \ No newline at end of file +} From cf6c745538acdea29e2c30f114f894ec3b2704fa Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 12:22:20 +0900 Subject: [PATCH 14/34] BridgeJS: Simplify static method naming --- .../BridgeJSCore/SwiftToSkeleton.swift | 54 ++++------------- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 4 +- .../JSClassStaticFunctions.json | 60 ++++++++++++------- .../JSClassStaticFunctions.swift | 56 ++++++++--------- .../JSClassStaticFunctions.d.ts | 8 ++- .../JSClassStaticFunctions.js | 20 +++---- 6 files changed, 93 insertions(+), 109 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 7928a5c1b..d84d30506 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -2198,7 +2198,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 @@ -2223,19 +2223,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, - includeTypeNameForStatic: false - ).map { - type.staticMethods.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 @@ -2332,30 +2324,12 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { 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, - includeTypeNameForStatic: !jsClassNames.contains(typeName) - ) - { + let parsed = parseFunction(jsFunction, function) { if jsClassNames.contains(typeName) { if let index = importedTypes.firstIndex(where: { $0.name == typeName }) { - let existing = importedTypes[index] - importedTypes[index] = ImportedTypeSkeleton( - name: existing.name, - jsName: existing.jsName, - from: existing.from, - constructor: existing.constructor, - methods: existing.methods, - staticMethods: existing.staticMethods + [parsed], - getters: existing.getters, - setters: existing.setters, - documentation: existing.documentation - ) + importedTypes[index].staticMethods.append(parsed) } else { - staticMethodsByType[typeName, default: []].append(parsed) + importedTypes.append(ImportedTypeSkeleton(name: typeName, staticMethods: [parsed])) } } else { importedFunctions.append(parsed) @@ -2403,9 +2377,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private func parseFunction( _ jsFunction: AttributeSyntax, _ node: FunctionDeclSyntax, - enclosingTypeName: String?, - isStaticMember: Bool, - includeTypeNameForStatic: Bool = true ) -> ImportedFunctionSkeleton? { guard validateEffects(node.signature.effectSpecifiers, node: node, attributeName: "JSFunction") != nil else { @@ -2415,12 +2386,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, includeTypeNameForStatic, 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/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 66dda6cb0..6fe88a6a0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -758,7 +758,7 @@ public struct ImportedTypeSkeleton: Codable { public let constructor: ImportedConstructorSkeleton? public let methods: [ImportedFunctionSkeleton] /// Static methods available on the JavaScript constructor. - public var staticMethods: [ImportedFunctionSkeleton] = [] + public var staticMethods: [ImportedFunctionSkeleton] public let getters: [ImportedGetterSkeleton] public let setters: [ImportedSetterSkeleton] public let documentation: String? @@ -768,7 +768,7 @@ public struct ImportedTypeSkeleton: Codable { jsName: String? = nil, from: JSImportFrom? = nil, constructor: ImportedConstructorSkeleton? = nil, - methods: [ImportedFunctionSkeleton], + methods: [ImportedFunctionSkeleton] = [], staticMethods: [ImportedFunctionSkeleton] = [], getters: [ImportedGetterSkeleton] = [], setters: [ImportedSetterSkeleton] = [], diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json index df3d3829e..7bf5db0fd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -24,6 +24,43 @@ ], "types" : [ + { + "getters" : [ + + ], + "methods" : [ + + ], + "name" : "StaticBox", + "setters" : [ + + ], + "staticMethods" : [ + { + "name" : "makeDefault", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + }, + { + "jsName" : "with-dashes", + "name" : "dashed", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + } + ] + }, { "getters" : [ @@ -74,29 +111,6 @@ } } - }, - { - "name" : "makeDefault", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "StaticBox" - } - } - }, - { - "jsName" : "with-dashes", - "name" : "dashed", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "StaticBox" - } - } } ] }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift index 5e297f929..efb83f406 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift @@ -1,35 +1,51 @@ #if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_create_static") -fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_makeDefault_static") +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 #else -fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 { +fileprivate func bjs_StaticBox_makeDefault_static() -> 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 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_dashed_static") +fileprivate func bjs_StaticBox_dashed_static() -> Int32 #else -fileprivate func bjs_StaticBox_value_static() -> Float64 { +fileprivate func bjs_StaticBox_dashed_static() -> Int32 { fatalError("Only available on WebAssembly") } #endif +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) +} + #if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_makeDefault_static") -fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_create_static") +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 #else -fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 { +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_dashed_static") -fileprivate func bjs_StaticBox_dashed_static() -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_value_static") +fileprivate func bjs_StaticBox_value_static() -> Float64 #else -fileprivate func bjs_StaticBox_dashed_static() -> Int32 { +fileprivate func bjs_StaticBox_value_static() -> Float64 { fatalError("Only available on WebAssembly") } #endif @@ -60,22 +76,6 @@ func _$StaticBox_value() throws(JSException) -> Double { 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) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts index 3b2b5de99..e4c59459a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts @@ -4,6 +4,8 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. +export interface StaticBox { +} export interface StaticBox { value(): number; } @@ -13,11 +15,13 @@ export type Exports = { } export type Imports = { StaticBox: { - create(value: number): StaticBox; - value(): number; makeDefault(): StaticBox; "with-dashes"(): StaticBox; } + StaticBox: { + create(value: number): StaticBox; + value(): number; + } WithCtor: { new(value: number): WithCtor; create(value: number): WithCtor; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index f8f0ba86f..4acf43685 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -203,37 +203,37 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { + TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { try { - let ret = imports.StaticBox.create(value); + let ret = imports.StaticBox.makeDefault(); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { + TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { try { - let ret = imports.StaticBox.value(); - return ret; + let ret = imports.StaticBox["with-dashes"](); + return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { + TestModule["bjs_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { try { - let ret = imports.StaticBox.makeDefault(); + let ret = imports.StaticBox.create(value); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { + TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { try { - let ret = imports.StaticBox["with-dashes"](); - return swift.memory.retain(ret); + let ret = imports.StaticBox.value(); + return ret; } catch (error) { setException(error); return 0 From 5161a41903aa660c84ad30f332070c07e2f4fcc5 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 12:54:10 +0900 Subject: [PATCH 15/34] BridgeJS: Remove support for static members in extensions --- .../BridgeJSCore/SwiftToSkeleton.swift | 51 +--------------- .../MacroSwift/JSClassStaticFunctions.swift | 8 +-- .../JSClassStaticFunctions.json | 60 +++++++------------ .../JSClassStaticFunctions.swift | 56 ++++++++--------- .../JSClassStaticFunctions.d.ts | 8 +-- .../JSClassStaticFunctions.js | 20 +++---- 6 files changed, 65 insertions(+), 138 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index d84d30506..9fb8b8ab0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1856,8 +1856,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private let inputFilePath: String private var jsClassNames: Set private let parent: SwiftToSkeleton - private var staticMethodsByType: [String: [ImportedFunctionSkeleton]] = [:] - // MARK: - State Management enum State { @@ -2118,7 +2116,6 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { private func exitJSClass() { if case .jsClassBody(let typeName) = state, let type = currentType, type.name == typeName { - let externalStaticMethods = staticMethodsByType[type.name] ?? [] importedTypes.append( ImportedTypeSkeleton( name: type.name, @@ -2126,13 +2123,12 @@ private final class ImportSwiftMacrosAPICollector: SyntaxAnyVisitor { from: type.from, constructor: type.constructor, methods: type.methods, - staticMethods: type.staticMethods + externalStaticMethods, + staticMethods: type.staticMethods, getters: type.getters, setters: type.setters, documentation: nil ) ) - staticMethodsByType[type.name] = nil currentType = nil } stateStack.removeLast() @@ -2172,12 +2168,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: @@ -2318,45 +2308,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) { - if jsClassNames.contains(typeName) { - if let index = importedTypes.firstIndex(where: { $0.name == typeName }) { - importedTypes[index].staticMethods.append(parsed) - } else { - importedTypes.append(ImportedTypeSkeleton(name: typeName, staticMethods: [parsed])) - } - } else { - 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( diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift index 891eab118..c64952565 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSClassStaticFunctions.swift @@ -1,14 +1,8 @@ -extension StaticBox { - @JSFunction static func makeDefault() throws(JSException) -> StaticBox -} - @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 -} - -extension StaticBox { + @JSFunction static func makeDefault() throws(JSException) -> StaticBox @JSFunction(jsName: "with-dashes") static func dashed() throws(JSException) -> StaticBox } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json index 7bf5db0fd..df3d3829e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -24,43 +24,6 @@ ], "types" : [ - { - "getters" : [ - - ], - "methods" : [ - - ], - "name" : "StaticBox", - "setters" : [ - - ], - "staticMethods" : [ - { - "name" : "makeDefault", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "StaticBox" - } - } - }, - { - "jsName" : "with-dashes", - "name" : "dashed", - "parameters" : [ - - ], - "returnType" : { - "jsObject" : { - "_0" : "StaticBox" - } - } - } - ] - }, { "getters" : [ @@ -111,6 +74,29 @@ } } + }, + { + "name" : "makeDefault", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } + }, + { + "jsName" : "with-dashes", + "name" : "dashed", + "parameters" : [ + + ], + "returnType" : { + "jsObject" : { + "_0" : "StaticBox" + } + } } ] }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift index efb83f406..5e297f929 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.swift @@ -1,51 +1,35 @@ #if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_makeDefault_static") -fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_create_static") +fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 #else -fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 { +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_dashed_static") -fileprivate func bjs_StaticBox_dashed_static() -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_value_static") +fileprivate func bjs_StaticBox_value_static() -> Float64 #else -fileprivate func bjs_StaticBox_dashed_static() -> Int32 { +fileprivate func bjs_StaticBox_value_static() -> Float64 { fatalError("Only available on WebAssembly") } #endif -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) -} - #if arch(wasm32) -@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_create_static") -fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_makeDefault_static") +fileprivate func bjs_StaticBox_makeDefault_static() -> Int32 #else -fileprivate func bjs_StaticBox_create_static(_ value: Float64) -> Int32 { +fileprivate func bjs_StaticBox_makeDefault_static() -> 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 +@_extern(wasm, module: "TestModule", name: "bjs_StaticBox_dashed_static") +fileprivate func bjs_StaticBox_dashed_static() -> Int32 #else -fileprivate func bjs_StaticBox_value_static() -> Float64 { +fileprivate func bjs_StaticBox_dashed_static() -> Int32 { fatalError("Only available on WebAssembly") } #endif @@ -76,6 +60,22 @@ func _$StaticBox_value() throws(JSException) -> Double { 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) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts index e4c59459a..3b2b5de99 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.d.ts @@ -4,8 +4,6 @@ // To update this file, just rebuild your project or run // `swift package bridge-js`. -export interface StaticBox { -} export interface StaticBox { value(): number; } @@ -14,13 +12,11 @@ export interface WithCtor { export type Exports = { } export type Imports = { - StaticBox: { - makeDefault(): StaticBox; - "with-dashes"(): StaticBox; - } StaticBox: { create(value: number): StaticBox; value(): number; + makeDefault(): StaticBox; + "with-dashes"(): StaticBox; } WithCtor: { new(value: number): WithCtor; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 4acf43685..f8f0ba86f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -203,37 +203,37 @@ export async function createInstantiator(options, swift) { return pointer || 0; } const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; - TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { + TestModule["bjs_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { try { - let ret = imports.StaticBox.makeDefault(); + let ret = imports.StaticBox.create(value); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { + TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { try { - let ret = imports.StaticBox["with-dashes"](); - return swift.memory.retain(ret); + let ret = imports.StaticBox.value(); + return ret; } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_create_static"] = function bjs_StaticBox_create_static(value) { + TestModule["bjs_StaticBox_makeDefault_static"] = function bjs_StaticBox_makeDefault_static() { try { - let ret = imports.StaticBox.create(value); + let ret = imports.StaticBox.makeDefault(); return swift.memory.retain(ret); } catch (error) { setException(error); return 0 } } - TestModule["bjs_StaticBox_value_static"] = function bjs_StaticBox_value_static() { + TestModule["bjs_StaticBox_dashed_static"] = function bjs_StaticBox_dashed_static() { try { - let ret = imports.StaticBox.value(); - return ret; + let ret = imports.StaticBox["with-dashes"](); + return swift.memory.retain(ret); } catch (error) { setException(error); return 0 From fc7e237ae303d0a8b373ae98024083f7efaf91be Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 00:45:00 +0900 Subject: [PATCH 16/34] BridgeJS: Support `T | null` and `T | undefined` --- .../Sources/BridgeJSCore/ExportSwift.swift | 39 +- .../Sources/BridgeJSCore/ImportTS.swift | 30 +- .../BridgeJSCore/SwiftToSkeleton.swift | 24 ++ .../Sources/BridgeJSLink/BridgeJSLink.swift | 2 + .../Sources/BridgeJSLink/JSGlueGen.swift | 228 ++++++++-- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 16 +- .../TS2Swift/JavaScript/src/processor.js | 24 ++ .../JavaScriptKit/BridgeJSIntrinsics.swift | 19 +- Sources/JavaScriptKit/JSUndefinedOr.swift | 408 ++++++++++++++++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 23 + .../Generated/BridgeJS.Macros.swift | 4 + .../Generated/BridgeJS.swift | 195 +++++++++ .../Generated/JavaScript/BridgeJS.json | 267 ++++++++++++ .../BridgeJSRuntimeTests/ImportAPITests.swift | 20 + Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 2 + Tests/prelude.mjs | 26 ++ tsconfig.json | 6 + 17 files changed, 1250 insertions(+), 83 deletions(-) create mode 100644 Sources/JavaScriptKit/JSUndefinedOr.swift create mode 100644 tsconfig.json diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index dc8b5e048..39281ddfb 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -820,6 +820,8 @@ struct StackCodegen { return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" case .optional(let wrappedType): return liftOptionalExpression(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return liftUndefinedExpression(wrappedType: wrappedType) case .array(let elementType): return liftArrayExpression(elementType: elementType) case .closure: @@ -839,7 +841,7 @@ struct StackCodegen { return liftArrayExpressionInline(elementType: elementType) case .swiftProtocol(let protocolName): return "[Any\(raw: protocolName)].bridgeJSLiftParameter()" - case .optional, .array, .closure: + case .optional, .undefinedOr, .array, .closure: return liftArrayExpressionInline(elementType: elementType) case .void, .namespaceEnum: fatalError("Invalid array element type: \(elementType)") @@ -883,11 +885,34 @@ struct StackCodegen { } }() """ - case .void, .namespaceEnum, .closure, .optional, .unsafePointer, .swiftProtocol: + case .undefinedOr, .void, .namespaceEnum, .closure, .optional, .unsafePointer, .swiftProtocol: fatalError("Invalid optional wrapped type: \(wrappedType)") } } + private func liftUndefinedExpression(wrappedType: BridgeType) -> ExprSyntax { + switch wrappedType { + case .string, .int, .uint, .bool, .float, .double, .jsObject, + .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: + return "JSUndefinedOr<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" + case .array(let elementType): + let arrayLift = liftArrayExpression(elementType: elementType) + let swiftTypeName = elementType.swiftType + return """ + { + let __isDefined = _swift_js_pop_i32() + if __isDefined == 0 { + return JSUndefinedOr<\(raw: swiftTypeName)>.undefined + } else { + return JSUndefinedOr<\(raw: swiftTypeName)>(optional: \(arrayLift)) + } + }() + """ + case .void, .namespaceEnum, .closure, .optional, .undefinedOr, .unsafePointer, .swiftProtocol: + fatalError("Invalid undefinedOr wrapped type: \(wrappedType)") + } + } + /// Generates statements to lower/push a value onto the stack. /// - Parameters: /// - type: The BridgeType to lower @@ -917,6 +942,8 @@ struct StackCodegen { return ["\(raw: accessor).bridgeJSLowerReturn()"] case .optional(let wrappedType): return lowerOptionalStatements(wrappedType: wrappedType, accessor: accessor, varPrefix: varPrefix) + case .undefinedOr(let wrappedType): + return lowerOptionalStatements(wrappedType: wrappedType, accessor: accessor, varPrefix: varPrefix) case .void, .namespaceEnum: return [] case .array(let elementType): @@ -938,7 +965,7 @@ struct StackCodegen { return ["\(raw: accessor).map { $0.jsObject }.bridgeJSLowerReturn()"] case .swiftProtocol(let protocolName): return ["\(raw: accessor).map { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"] - case .optional, .array, .closure: + case .optional, .undefinedOr, .array, .closure: return lowerArrayStatementsInline( elementType: elementType, accessor: accessor, @@ -1597,6 +1624,7 @@ extension BridgeType { case .swiftProtocol(let name): return "Any\(name)" case .void: return "Void" case .optional(let wrappedType): return "Optional<\(wrappedType.swiftType)>" + case .undefinedOr(let wrappedType): return "JSUndefinedOr<\(wrappedType.swiftType)>" case .array(let elementType): return "[\(elementType.swiftType)]" case .caseEnum(let name): return name case .rawValueEnum(let name, _): return name @@ -1644,6 +1672,10 @@ extension BridgeType { var optionalParams: [(name: String, type: WasmCoreType)] = [("isSome", .i32)] optionalParams.append(contentsOf: try wrappedType.liftParameterInfo().parameters) return LiftingIntrinsicInfo(parameters: optionalParams) + case .undefinedOr(let wrappedType): + var params: [(name: String, type: WasmCoreType)] = [("isDefined", .i32)] + params.append(contentsOf: try wrappedType.liftParameterInfo().parameters) + return LiftingIntrinsicInfo(parameters: params) case .caseEnum: return .caseEnum case .rawValueEnum(_, let rawType): return rawType.liftingIntrinsicInfo @@ -1693,6 +1725,7 @@ extension BridgeType { case .swiftProtocol: return .jsObject case .void: return .void case .optional: return .optional + case .undefinedOr: 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..7ac72cffc 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -925,15 +925,15 @@ 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) - } + let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) + var params = [("isSome", WasmCoreType.i32)] + params.append(contentsOf: wrappedInfo.loweredParameters) + return LoweringParameterInfo(loweredParameters: params) + case .undefinedOr(let wrappedType): + let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) + var params = [("isDefined", WasmCoreType.i32)] + params.append(contentsOf: wrappedInfo.loweredParameters) + return LoweringParameterInfo(loweredParameters: params) case .array: switch context { case .importTS: @@ -1019,13 +1019,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) - } + let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) + return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) + case .undefinedOr(let wrappedType): + let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) + return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) case .array: switch context { case .importTS: diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index b780012f0..67f1421a2 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -133,6 +133,30 @@ public final class SwiftToSkeleton { return .optional(baseType) } } + // 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 .undefinedOr(baseType) + } + } + // 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 .undefinedOr(wrappedType) + } + } // Optional if let identifierType = type.as(IdentifierTypeSyntax.self), identifierType.name.text == "Optional", diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 60b55cd47..0b1be8a10 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -3405,6 +3405,8 @@ extension BridgeType { return "number" case .optional(let wrappedType): return "\(wrappedType.tsType) | null" + case .undefinedOr(let wrappedType): + return "\(wrappedType.tsType) | undefined" case .caseEnum(let name): return "\(name)Tag" case .rawValueEnum(let name, _): diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index c78a92de7..ad27dc6f3 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -296,7 +296,10 @@ struct IntrinsicJSFragment: Sendable { ) } - static func optionalLiftParameter(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + static func optionalLiftParameter( + wrappedType: BridgeType, + absenceLiteral: String = "null" + ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["isSome", "wrappedValue"], printCode: { arguments, scope, printer, cleanupCode in @@ -306,9 +309,9 @@ struct IntrinsicJSFragment: Sendable { 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 +323,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 +342,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 @@ -356,7 +359,7 @@ struct IntrinsicJSFragment: Sendable { ) } 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 +372,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(structVar) = null;") + printer.write("\(structVar) = \(absenceLiteral);") } printer.write("}") resultExpr = structVar @@ -387,12 +390,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] @@ -514,7 +517,8 @@ struct IntrinsicJSFragment: Sendable { static func optionalLiftReturn( wrappedType: BridgeType, - context: BridgeContext = .exportSwift + context: BridgeContext = .exportSwift, + absenceLiteral: String = "null" ) -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: [], @@ -550,7 +554,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);") @@ -586,7 +590,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("let \(resultVar);") printer.write("if (\(isNullVar)) {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("} else {") printer.indent { @@ -608,7 +612,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("}") case .array(let elementType): @@ -625,7 +629,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(resultVar) = null;") + printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("}") default: @@ -637,7 +641,10 @@ struct IntrinsicJSFragment: Sendable { ) } - static func optionalLowerReturn(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + static func optionalLowerReturn( + wrappedType: BridgeType, + presenceCheck: (@Sendable (String) -> String)? = nil + ) throws -> IntrinsicJSFragment { switch wrappedType { case .void, .optional, .namespaceEnum, .closure: throw BridgeJSLinkError(message: "Unsupported optional wrapped type for protocol export: \(wrappedType)") @@ -649,7 +656,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 = presenceCheck?(value) ?? "\(value) != null" + printer.write("const \(isSomeVar) = \(presenceExpr);") switch wrappedType { case .bool: @@ -905,7 +913,7 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType): + case .optional(let wrappedType), .undefinedOr(let wrappedType): return try closureOptionalLiftParameter(wrappedType: wrappedType) default: throw BridgeJSLinkError(message: "Unsupported closure parameter type for lifting: \(type)") @@ -1106,7 +1114,7 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType): + case .optional(let wrappedType), .undefinedOr(let wrappedType): return try closureOptionalLowerReturn(wrappedType: wrappedType) default: throw BridgeJSLinkError(message: "Unsupported closure return type for lowering: \(type)") @@ -1303,19 +1311,28 @@ struct IntrinsicJSFragment: Sendable { ) case .optional(let wrappedType): return try closureOptionalLiftReturn(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return try closureOptionalLiftReturn(wrappedType: wrappedType, absenceLiteral: "undefined") 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, + absenceLiteral: String = "null" + ) 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, + absenceLiteral: absenceLiteral + ) let lifted = baseFragment.printCode([], scope, printer, cleanupCode) if !lifted.isEmpty { printer.write("return \(lifted[0]);") @@ -1361,6 +1378,8 @@ struct IntrinsicJSFragment: Sendable { default: printer.write("return;") } + case .undefinedOr: + printer.write("return;") default: printer.write("return 0;") } @@ -1384,6 +1403,8 @@ struct IntrinsicJSFragment: Sendable { case .void: return .void case .optional(let wrappedType): return try .optionalLowerParameter(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return try .optionalLowerParameter(wrappedType: wrappedType) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1428,6 +1449,8 @@ struct IntrinsicJSFragment: Sendable { case .swiftProtocol: return .jsObjectLiftReturn case .void: return .void case .optional(let wrappedType): return .optionalLiftReturn(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return .optionalLiftReturn(wrappedType: wrappedType, absenceLiteral: "undefined") case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1486,14 +1509,9 @@ struct IntrinsicJSFragment: Sendable { 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) - } + return try .optionalLiftParameter(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return try .optionalLiftParameter(wrappedType: wrappedType, absenceLiteral: "undefined") case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1584,14 +1602,12 @@ 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) - } + return try .optionalLowerReturn(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return try .optionalLowerReturn( + wrappedType: wrappedType, + presenceCheck: { value in "\(value) !== undefined" } + ) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1998,6 +2014,67 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") } + return [] + } + ) + case .undefinedOr(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) !== undefined;") + + 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);") + default: + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + } + return [] } ) @@ -2083,6 +2160,34 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") + return [optVar] + } + ) + case .undefinedOr(let wrappedType): + 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 { + let wrappedFragment = associatedValuePopPayload(type: wrappedType) + let wrappedResults = wrappedFragment.printCode([], scope, printer, cleanup) + if let wrappedResult = wrappedResults.first { + printer.write("\(optVar) = \(wrappedResult);") + } else { + printer.write("\(optVar) = undefined;") + } + } + printer.write("} else {") + printer.indent { + printer.write("\(optVar) = undefined;") + } + printer.write("}") + return [optVar] } ) @@ -2331,6 +2436,8 @@ struct IntrinsicJSFragment: Sendable { return try! arrayLift(elementType: innerElementType) case .optional(let wrappedType): return try optionalElementRaiseFragment(wrappedType: wrappedType) + case .undefinedOr(let wrappedType): + return try optionalElementRaiseFragment(wrappedType: wrappedType, absenceLiteral: "undefined") case .unsafePointer: return IntrinsicJSFragment( parameters: [], @@ -2458,6 +2565,14 @@ struct IntrinsicJSFragment: Sendable { return [] } ) + case .undefinedOr: + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + printer.write("throw new Error(\"Unsupported array element type for lowering: \(elementType)\");") + return [] + } + ) case .swiftHeapObject: return IntrinsicJSFragment( parameters: ["value"], @@ -2479,6 +2594,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLower(elementType: innerElementType) + case .undefinedOr: + throw BridgeJSLinkError(message: "Unsupported array element type: \(elementType)") case .optional(let wrappedType): return try optionalElementLowerFragment(wrappedType: wrappedType) case .swiftProtocol: @@ -2506,7 +2623,10 @@ struct IntrinsicJSFragment: Sendable { } } - private static func optionalElementRaiseFragment(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + private static func optionalElementRaiseFragment( + wrappedType: BridgeType, + absenceLiteral: String = "null" + ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -2517,7 +2637,7 @@ 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 { @@ -2536,14 +2656,18 @@ struct IntrinsicJSFragment: Sendable { ) } - private static func optionalElementLowerFragment(wrappedType: BridgeType) throws -> IntrinsicJSFragment { + private static func optionalElementLowerFragment( + wrappedType: BridgeType, + presenceCheck: (@Sendable (String) -> String)? = nil + ) 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 = presenceCheck?(value) ?? "\(value) != null" + 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)) {") @@ -3095,6 +3219,14 @@ struct IntrinsicJSFragment: Sendable { } } ) + case .undefinedOr: + return IntrinsicJSFragment( + parameters: ["value"], + printCode: { arguments, scope, printer, cleanup in + printer.write("throw new Error(\"Unsupported struct field type for lowering: \(field.type)\");") + return [] + } + ) case .swiftStruct(let nestedName): return IntrinsicJSFragment( parameters: ["value"], @@ -3451,6 +3583,14 @@ struct IntrinsicJSFragment: Sendable { return [varName] } ) + case .undefinedOr: + return IntrinsicJSFragment( + parameters: [], + printCode: { arguments, scope, printer, cleanup in + printer.write("throw new Error(\"Unsupported struct field type: \(field.type)\");") + return [] + } + ) case .void, .swiftProtocol, .namespaceEnum, .closure: // These types should not appear as struct fields return IntrinsicJSFragment( diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 5013dda66..fabff5d3e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -130,6 +130,7 @@ public enum BridgeType: Codable, Equatable, Hashable, Sendable { case int, uint, float, double, string, bool, jsObject(String?), swiftHeapObject(String), void case unsafePointer(UnsafePointerType) indirect case optional(BridgeType) + indirect case undefinedOr(BridgeType) indirect case array(BridgeType) case caseEnum(String) case rawValueEnum(String, SwiftEnumRawType) @@ -895,7 +896,7 @@ extension BridgeType { return .pointer case .unsafePointer: return .pointer - case .optional(_): + case .optional(_), .undefinedOr(_): return nil case .caseEnum: return .i32 @@ -923,6 +924,7 @@ extension BridgeType { /// Returns true if this type is optional public var isOptional: Bool { if case .optional = self { return true } + if case .undefinedOr = self { return true } return false } @@ -961,6 +963,8 @@ extension BridgeType { return kindCode case .optional(let wrapped): return "Sq\(wrapped.mangleTypeName)" + case .undefinedOr(let wrapped): + return "Su\(wrapped.mangleTypeName)" case .caseEnum(let name), .rawValueEnum(let name, _), .associatedValueEnum(let name), @@ -987,7 +991,15 @@ 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 } + let wrappedType: BridgeType + switch self { + case .optional(let wrapped): + wrappedType = wrapped + case .undefinedOr(let wrapped): + wrappedType = wrapped + default: + return false + } switch wrappedType { case .string, .int, .float, .double, .jsObject, .swiftProtocol: diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index 258334ee8..fd31967b0 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -676,6 +676,30 @@ 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 `JSUndefinedOr>`; + } + if (hasNull) { + return `Optional<${wrapped}>`; + } + return `JSUndefinedOr<${wrapped}>`; + } + } + /** @type {Record} */ const typeMap = { "number": "Double", diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 7b2d97f06..ac60ca860 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -1015,11 +1015,6 @@ extension UnsafeMutablePointer: _BridgedSwiftStackType { } 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() -> ( @@ -1071,11 +1066,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() -> ( @@ -1123,14 +1113,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 { diff --git a/Sources/JavaScriptKit/JSUndefinedOr.swift b/Sources/JavaScriptKit/JSUndefinedOr.swift new file mode 100644 index 000000000..f70cfc0df --- /dev/null +++ b/Sources/JavaScriptKit/JSUndefinedOr.swift @@ -0,0 +1,408 @@ +@frozen public enum JSUndefinedOr { + case undefined + case value(Wrapped) + + /// Convenience accessor for the undefined case. + public static var undefinedValue: Self { .undefined } + + @inlinable + init(optional: Wrapped?) { + self = optional.map(Self.value) ?? .undefined + } + + @inlinable + 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 Optional-style conformances + +extension JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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()) + } +} + +extension JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr where Wrapped: _BridgedSwiftTypeLoweredIntoVoidType { + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { + optionalRepresentation.bridgeJSLowerReturn() + } +} + +extension JSUndefinedOr +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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr +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 JSUndefinedOr +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 JSUndefinedOr 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 JSUndefinedOr 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() + } +} diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index a20ea2dd5..007f0b265 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -611,6 +611,29 @@ typealias OptionalAge = Int? @JS func roundTripOptionalClass(value: Greeter?) -> Greeter? { return 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 diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index e066ad272..ee0455c35 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -14,6 +14,10 @@ @JSFunction func jsRoundTripString(_ v: String) throws(JSException) -> String +@JSFunction func jsRoundTripOptionalNumberNull(_ v: Optional) throws(JSException) -> Optional + +@JSFunction func jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr + @JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void @JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 94359a709..a572f4c6f 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 @@ -4416,6 +4464,39 @@ public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: Unsa #endif } +@_expose(wasm, "bjs_roundTripOptionalGreeter") +@_cdecl("bjs_roundTripOptionalGreeter") +public func _bjs_roundTripOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_applyOptionalGreeter") +@_cdecl("bjs_applyOptionalGreeter") +public func _bjs_applyOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer, _ transform: Int32) -> Void { + #if arch(wasm32) + 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_makeOptionalHolder") +@_cdecl("bjs_makeOptionalHolder") +public func _bjs_makeOptionalHolder(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsDefined: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = makeOptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsDefined, undefinedNumberValue)) + 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 { @@ -5826,6 +5907,84 @@ fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int } #endif +@_expose(wasm, "bjs_OptionalHolder_init") +@_cdecl("bjs_OptionalHolder_init") +public func _bjs_OptionalHolder_init(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsDefined: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = OptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsDefined, 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, _ valueIsDefined: Int32, _ valueValue: Float64) -> Void { + #if arch(wasm32) + OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber = JSUndefinedOr.bridgeJSLiftParameter(valueIsDefined, 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 { @@ -7855,6 +8014,42 @@ func _$jsRoundTripString(_ v: String) throws(JSException) -> String { return String.bridgeJSLiftReturn(ret) } +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberNull") +fileprivate func bjs_jsRoundTripOptionalNumberNull(_ vIsSome: Int32, _ vValue: Float64) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalNumberNull(_ vIsSome: Int32, _ vValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalNumberNull(_ v: Optional) throws(JSException) -> Optional { + let (vIsSome, vValue) = v.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalNumberNull(vIsSome, vValue) + 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(_ vIsDefined: Int32, _ vValue: Float64) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsDefined: Int32, _ vValue: Float64) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { + let (vIsDefined, vValue) = v.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalNumberUndefined(vIsDefined, vValue) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsThrowOrVoid") fileprivate func bjs_jsThrowOrVoid(_ shouldThrow: Int32) -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 4b8ac7c7b..3c71881a5 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -525,6 +525,79 @@ ], "swiftCallName" : "Internal.TestServer" }, + { + "constructor" : { + "abiName" : "bjs_OptionalHolder_init", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "parameters" : [ + { + "label" : "nullableGreeter", + "name" : "nullableGreeter", + "type" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "label" : "undefinedNumber", + "name" : "undefinedNumber", + "type" : { + "undefinedOr" : { + "_0" : { + "double" : { + + } + } + } + } + } + ] + }, + "methods" : [ + + ], + "name" : "OptionalHolder", + "properties" : [ + { + "isReadonly" : false, + "isStatic" : false, + "name" : "nullableGreeter", + "type" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "isReadonly" : false, + "isStatic" : false, + "name" : "undefinedNumber", + "type" : { + "undefinedOr" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "swiftCallName" : "OptionalHolder" + }, { "constructor" : { "abiName" : "bjs_OptionalPropertyHolder_init", @@ -7444,6 +7517,148 @@ } } }, + { + "abiName" : "bjs_roundTripOptionalGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalGreeter", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + } + ], + "returnType" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "abiName" : "bjs_applyOptionalGreeter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "applyOptionalGreeter", + "parameters" : [ + { + "label" : "_", + "name" : "value", + "type" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "label" : "_", + "name" : "transform", + "type" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + ], + "returnType" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + } + } + } + } + ], + "returnType" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "abiName" : "bjs_makeOptionalHolder", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeOptionalHolder", + "parameters" : [ + { + "label" : "nullableGreeter", + "name" : "nullableGreeter", + "type" : { + "optional" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } + }, + { + "label" : "undefinedNumber", + "name" : "undefinedNumber", + "type" : { + "undefinedOr" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "OptionalHolder" + } + } + }, { "abiName" : "bjs_roundTripOptionalAPIOptionalResult", "effects" : { @@ -11739,6 +11954,58 @@ } } }, + { + "name" : "jsRoundTripOptionalNumberNull", + "parameters" : [ + { + "name" : "v", + "type" : { + "optional" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "optional" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripOptionalNumberUndefined", + "parameters" : [ + { + "name" : "v", + "type" : { + "undefinedOr" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "undefinedOr" : { + "_0" : { + "double" : { + + } + } + } + } + }, { "name" : "jsThrowOrVoid", "parameters" : [ diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index ea9f8c68f..136bd36f8 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -35,6 +35,26 @@ class ImportAPITests: XCTestCase { } } + 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(.undefinedValue) + if case .value = undefined { + XCTFail("Expected undefined") + } + } + func testRoundTripFeatureFlag() throws { for v in [FeatureFlag.foo, .bar] { try XCTAssertEqual(jsRoundTripFeatureFlag(v), v) diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index 983d6052d..d1140e20f 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -2,6 +2,8 @@ export function jsRoundTripVoid(): void export function jsRoundTripNumber(v: number): number export function jsRoundTripBool(v: boolean): boolean export function jsRoundTripString(v: string): string +export function jsRoundTripOptionalNumberNull(v: number | null): number | null +export function jsRoundTripOptionalNumberUndefined(v: number | undefined): number | undefined export function jsThrowOrVoid(shouldThrow: boolean): void export function jsThrowOrNumber(shouldThrow: boolean): number export function jsThrowOrBool(shouldThrow: boolean): boolean diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 850b31b6e..29931ba3a 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -25,6 +25,12 @@ export async function setupOptions(options, context) { "jsRoundTripString": (v) => { return v; }, + "jsRoundTripOptionalNumberNull": (v) => { + return v ?? null; + }, + "jsRoundTripOptionalNumberUndefined": (v) => { + return v === undefined ? undefined : v; + }, "jsThrowOrVoid": (shouldThrow) => { if (shouldThrow) { throw new Error("TestError"); @@ -690,6 +696,26 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { 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 }; 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 + } +} From 6a230daddf1cb158878b35b63bf6c7cf4568f9ee Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 13:33:30 +0900 Subject: [PATCH 17/34] BridgeJS: Simplify Optional and JSUndefinedOr code paths --- .../Generated/JavaScript/BridgeJS.json | 110 ++- .../Sources/BridgeJSCore/ClosureCodegen.swift | 2 +- .../Sources/BridgeJSCore/ExportSwift.swift | 98 +-- .../Sources/BridgeJSCore/ImportTS.swift | 12 +- .../BridgeJSCore/SwiftToSkeleton.swift | 32 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 21 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 206 +---- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 47 +- .../BridgeJSCodegenTests/ArrayTypes.json | 70 +- .../CrossFileTypeResolution.ReverseOrder.json | 5 +- .../CrossFileTypeResolution.json | 5 +- .../DefaultParameters.json | 50 +- .../EnumAssociatedValue.json | 95 +- .../BridgeJSCodegenTests/EnumCase.json | 20 +- .../BridgeJSCodegenTests/EnumRawType.json | 120 ++- .../ImportedTypeInExportedInterface.json | 15 +- .../BridgeJSCodegenTests/Optionals.json | 190 ++-- .../BridgeJSCodegenTests/Protocol.json | 40 +- .../StaticProperties.Global.json | 5 +- .../StaticProperties.json | 5 +- .../BridgeJSCodegenTests/SwiftClosure.json | 45 +- .../BridgeJSCodegenTests/SwiftStruct.json | 40 +- .../JavaScriptKit/BridgeJSIntrinsics.swift | 381 ++++++++ Sources/JavaScriptKit/JSUndefinedOr.swift | 371 +------- .../Generated/BridgeJS.swift | 20 +- .../Generated/JavaScript/BridgeJS.json | 825 +++++++++++------- 26 files changed, 1522 insertions(+), 1308 deletions(-) diff --git a/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json index cb081ab39..4dff97132 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" } } } 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 39281ddfb..cb267c210 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) @@ -818,10 +828,8 @@ struct StackCodegen { } case .associatedValueEnum: return "\(raw: type.swiftType).bridgeJSLiftParameter(_swift_js_pop_i32())" - case .optional(let wrappedType): - return liftOptionalExpression(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): - return liftUndefinedExpression(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return liftNullableExpression(wrappedType: wrappedType, kind: kind) case .array(let elementType): return liftArrayExpression(elementType: elementType) case .closure: @@ -841,7 +849,7 @@ struct StackCodegen { return liftArrayExpressionInline(elementType: elementType) case .swiftProtocol(let protocolName): return "[Any\(raw: protocolName)].bridgeJSLiftParameter()" - case .optional, .undefinedOr, .array, .closure: + case .nullable, .array, .closure: return liftArrayExpressionInline(elementType: elementType) case .void, .namespaceEnum: fatalError("Invalid array element type: \(elementType)") @@ -865,51 +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, .int, .uint, .bool, .float, .double, .jsObject(nil), .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: - return "Optional<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" + return "\(raw: typeName)<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" case .jsObject(let className?): - return "Optional.bridgeJSLiftParameter().map { \(raw: className)(unsafelyWrapping: $0) }" + 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) } }() """ - case .undefinedOr, .void, .namespaceEnum, .closure, .optional, .unsafePointer, .swiftProtocol: - fatalError("Invalid optional wrapped type: \(wrappedType)") - } - } - - private func liftUndefinedExpression(wrappedType: BridgeType) -> ExprSyntax { - switch wrappedType { - case .string, .int, .uint, .bool, .float, .double, .jsObject, - .swiftStruct, .swiftHeapObject, .caseEnum, .associatedValueEnum, .rawValueEnum: - return "JSUndefinedOr<\(raw: wrappedType.swiftType)>.bridgeJSLiftParameter()" - case .array(let elementType): - let arrayLift = liftArrayExpression(elementType: elementType) - let swiftTypeName = elementType.swiftType - return """ - { - let __isDefined = _swift_js_pop_i32() - if __isDefined == 0 { - return JSUndefinedOr<\(raw: swiftTypeName)>.undefined - } else { - return JSUndefinedOr<\(raw: swiftTypeName)>(optional: \(arrayLift)) - } - }() - """ - case .void, .namespaceEnum, .closure, .optional, .undefinedOr, .unsafePointer, .swiftProtocol: - fatalError("Invalid undefinedOr wrapped type: \(wrappedType)") + case .nullable, .void, .namespaceEnum, .closure, .unsafePointer, .swiftProtocol: + fatalError("Invalid nullable wrapped type: \(wrappedType)") } } @@ -940,9 +929,7 @@ struct StackCodegen { return ["\(raw: accessor).bridgeJSLowerStackReturn()"] case .associatedValueEnum, .swiftStruct: return ["\(raw: accessor).bridgeJSLowerReturn()"] - case .optional(let wrappedType): - return lowerOptionalStatements(wrappedType: wrappedType, accessor: accessor, varPrefix: varPrefix) - case .undefinedOr(let wrappedType): + case .nullable(let wrappedType, _): return lowerOptionalStatements(wrappedType: wrappedType, accessor: accessor, varPrefix: varPrefix) case .void, .namespaceEnum: return [] @@ -965,7 +952,7 @@ struct StackCodegen { return ["\(raw: accessor).map { $0.jsObject }.bridgeJSLowerReturn()"] case .swiftProtocol(let protocolName): return ["\(raw: accessor).map { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"] - case .optional, .undefinedOr, .array, .closure: + case .nullable, .array, .closure: return lowerArrayStatementsInline( elementType: elementType, accessor: accessor, @@ -1623,8 +1610,8 @@ extension BridgeType { 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 .undefinedOr(let wrappedType): return "JSUndefinedOr<\(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 @@ -1668,14 +1655,10 @@ extension BridgeType { 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) - case .undefinedOr(let wrappedType): - var params: [(name: String, type: WasmCoreType)] = [("isDefined", .i32)] - params.append(contentsOf: try wrappedType.liftParameterInfo().parameters) - return LiftingIntrinsicInfo(parameters: params) case .caseEnum: return .caseEnum case .rawValueEnum(_, let rawType): return rawType.liftingIntrinsicInfo @@ -1724,8 +1707,7 @@ extension BridgeType { case .unsafePointer: return .unsafePointer case .swiftProtocol: return .jsObject case .void: return .void - case .optional: return .optional - case .undefinedOr: 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 7ac72cffc..cd3f84443 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -924,16 +924,11 @@ extension BridgeType { } case .namespaceEnum: throw BridgeJSCoreError("Namespace enums cannot be used as parameters") - case .optional(let wrappedType): + 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 .undefinedOr(let wrappedType): - let wrappedInfo = try wrappedType.loweringParameterInfo(context: context) - var params = [("isDefined", WasmCoreType.i32)] - params.append(contentsOf: wrappedInfo.loweredParameters) - return LoweringParameterInfo(loweredParameters: params) case .array: switch context { case .importTS: @@ -1018,10 +1013,7 @@ extension BridgeType { } case .namespaceEnum: throw BridgeJSCoreError("Namespace enums cannot be used as return values") - case .optional(let wrappedType): - let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) - return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) - case .undefinedOr(let wrappedType): + case .nullable(let wrappedType, _): let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) case .array: diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 67f1421a2..adc49c89b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -130,7 +130,7 @@ 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 @@ -141,7 +141,7 @@ public final class SwiftToSkeleton { let argType = TypeSyntax(genericArgs.first?.argument) { if let baseType = lookupType(for: argType, errors: &errors) { - return .undefinedOr(baseType) + return .nullable(baseType, .undefined) } } // JavaScriptKit.JSUndefinedOr @@ -154,7 +154,7 @@ public final class SwiftToSkeleton { let argType = TypeSyntax(genericArgs.first?.argument) { if let wrappedType = lookupType(for: argType, errors: &errors) { - return .undefinedOr(wrappedType) + return .nullable(wrappedType, .undefined) } } // Optional @@ -165,7 +165,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 @@ -178,7 +178,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] @@ -559,7 +559,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 @@ -608,7 +608,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", @@ -664,10 +664,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: @@ -803,7 +803,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( @@ -858,11 +858,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 } @@ -984,7 +984,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 } @@ -1422,7 +1422,7 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor { switch associatedValue.type { case .string, .int, .float, .double, .bool: break - case .optional(let wrappedType): + case .nullable(let wrappedType, _): switch wrappedType { case .string, .int, .float, .double, .bool: break @@ -1611,7 +1611,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 } @@ -1836,7 +1836,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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 0b1be8a10..97678dc64 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -297,7 +297,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 @@ -746,7 +746,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 @@ -764,7 +764,7 @@ public struct BridgeJSLink { // 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 +782,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)"] @@ -1428,8 +1428,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 @@ -2250,7 +2251,7 @@ extension BridgeJSLink { 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") } @@ -3403,10 +3404,8 @@ extension BridgeType { return name case .unsafePointer: return "number" - case .optional(let wrappedType): - return "\(wrappedType.tsType) | null" - case .undefinedOr(let wrappedType): - return "\(wrappedType.tsType) | undefined" + 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/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ad27dc6f3..44e751d3a 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -298,7 +298,7 @@ struct IntrinsicJSFragment: Sendable { static func optionalLiftParameter( wrappedType: BridgeType, - absenceLiteral: String = "null" + kind: JSOptionalKind ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["isSome", "wrappedValue"], @@ -306,6 +306,7 @@ struct IntrinsicJSFragment: Sendable { let isSome = arguments[0] let wrappedValue = arguments[1] let resultExpr: String + let absenceLiteral = kind.absenceLiteral switch wrappedType { case .int, .float, .double, .caseEnum: @@ -518,8 +519,9 @@ struct IntrinsicJSFragment: Sendable { static func optionalLiftReturn( wrappedType: BridgeType, context: BridgeContext = .exportSwift, - absenceLiteral: String = "null" + kind: JSOptionalKind ) -> IntrinsicJSFragment { + let absenceLiteral = kind.absenceLiteral return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanupCode in @@ -646,7 +648,7 @@ struct IntrinsicJSFragment: Sendable { presenceCheck: (@Sendable (String) -> String)? = nil ) 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 } @@ -913,15 +915,19 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType), .undefinedOr(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: @@ -983,7 +989,7 @@ struct IntrinsicJSFragment: Sendable { printer.unindent() printer.write("} else {") printer.indent() - printer.write("\(targetVar) = null;") + printer.write("\(targetVar) = \(absenceLiteral);") printer.unindent() printer.write("}") @@ -1114,7 +1120,7 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType), .undefinedOr(let wrappedType): + case .nullable(let wrappedType, _): return try closureOptionalLowerReturn(wrappedType: wrappedType) default: throw BridgeJSLinkError(message: "Unsupported closure return type for lowering: \(type)") @@ -1309,10 +1315,8 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .optional(let wrappedType): - return try closureOptionalLiftReturn(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): - return try closureOptionalLiftReturn(wrappedType: wrappedType, absenceLiteral: "undefined") + case .nullable(let wrappedType, let kind): + return try closureOptionalLiftReturn(wrappedType: wrappedType, kind: kind) default: throw BridgeJSLinkError(message: "Unsupported closure return type for lifting: \(type)") } @@ -1321,7 +1325,7 @@ struct IntrinsicJSFragment: Sendable { /// Handles optional return lifting for Swift closure returns private static func closureOptionalLiftReturn( wrappedType: BridgeType, - absenceLiteral: String = "null" + kind: JSOptionalKind ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["invokeCall"], @@ -1331,7 +1335,7 @@ struct IntrinsicJSFragment: Sendable { let baseFragment = optionalLiftReturn( wrappedType: wrappedType, context: .importTS, - absenceLiteral: absenceLiteral + kind: kind ) let lifted = baseFragment.printCode([], scope, printer, cleanupCode) if !lifted.isEmpty { @@ -1371,15 +1375,13 @@ struct IntrinsicJSFragment: Sendable { } case .associatedValueEnum: printer.write("return;") - case .optional(let wrappedType): + case .nullable(let wrappedType, _): switch wrappedType { case .swiftHeapObject: printer.write("return 0;") default: printer.write("return;") } - case .undefinedOr: - printer.write("return;") default: printer.write("return 0;") } @@ -1401,9 +1403,7 @@ struct IntrinsicJSFragment: Sendable { return .swiftHeapObjectLowerParameter case .swiftProtocol: return .jsObjectLowerParameter case .void: return .void - case .optional(let wrappedType): - return try .optionalLowerParameter(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): + case .nullable(let wrappedType, _): return try .optionalLowerParameter(wrappedType: wrappedType) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): @@ -1448,9 +1448,8 @@ struct IntrinsicJSFragment: Sendable { case .unsafePointer: return .identity case .swiftProtocol: return .jsObjectLiftReturn case .void: return .void - case .optional(let wrappedType): return .optionalLiftReturn(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): - return .optionalLiftReturn(wrappedType: wrappedType, absenceLiteral: "undefined") + case .nullable(let wrappedType, let kind): + return .optionalLiftReturn(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1508,10 +1507,8 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError( message: "Void can't appear in parameters of imported JS functions" ) - case .optional(let wrappedType): - return try .optionalLiftParameter(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): - return try .optionalLiftParameter(wrappedType: wrappedType, absenceLiteral: "undefined") + case .nullable(let wrappedType, let kind): + return try .optionalLiftParameter(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -1601,12 +1598,10 @@ struct IntrinsicJSFragment: Sendable { } case .swiftProtocol: return .jsObjectLowerReturn case .void: return .void - case .optional(let wrappedType): - return try .optionalLowerReturn(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): + case .nullable(let wrappedType, let kind): return try .optionalLowerReturn( wrappedType: wrappedType, - presenceCheck: { value in "\(value) !== undefined" } + presenceCheck: { value in kind.presenceCheck(value: value) } ) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): @@ -1956,74 +1951,13 @@ struct IntrinsicJSFragment: Sendable { 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;") - - 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);") - default: - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") - } - - return [] - } - ) - case .undefinedOr(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) !== undefined;") + printer.write("const \(isSomeVar) = \(kind.presenceCheck(value: value));") switch wrappedType { case .string: @@ -2135,35 +2069,7 @@ struct IntrinsicJSFragment: Sendable { 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") - - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") - printer.write("let \(optVar);") - printer.write("if (\(isSomeVar)) {") - printer.indent { - let wrappedFragment = associatedValuePopPayload(type: wrappedType) - let wrappedResults = wrappedFragment.printCode([], scope, printer, cleanup) - if let wrappedResult = wrappedResults.first { - printer.write("\(optVar) = \(wrappedResult);") - } else { - printer.write("\(optVar) = undefined;") - } - } - printer.write("} else {") - printer.indent { - printer.write("\(optVar) = null;") - } - printer.write("}") - - return [optVar] - } - ) - case .undefinedOr(let wrappedType): + case .nullable(let wrappedType, let kind): return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -2184,7 +2090,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(optVar) = undefined;") + printer.write("\(optVar) = \(kind.absenceLiteral);") } printer.write("}") @@ -2434,10 +2340,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLift(elementType: innerElementType) - case .optional(let wrappedType): - return try optionalElementRaiseFragment(wrappedType: wrappedType) - case .undefinedOr(let wrappedType): - return try optionalElementRaiseFragment(wrappedType: wrappedType, absenceLiteral: "undefined") + case .nullable(let wrappedType, let kind): + return try optionalElementRaiseFragment(wrappedType: wrappedType, kind: kind) case .unsafePointer: return IntrinsicJSFragment( parameters: [], @@ -2565,14 +2469,6 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .undefinedOr: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("throw new Error(\"Unsupported array element type for lowering: \(elementType)\");") - return [] - } - ) case .swiftHeapObject: return IntrinsicJSFragment( parameters: ["value"], @@ -2594,10 +2490,11 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLower(elementType: innerElementType) - case .undefinedOr: - throw BridgeJSLinkError(message: "Unsupported array element type: \(elementType)") - case .optional(let wrappedType): - return try optionalElementLowerFragment(wrappedType: wrappedType) + case .nullable(let wrappedType, let kind): + return try optionalElementLowerFragment( + wrappedType: wrappedType, + presenceCheck: { kind.presenceCheck(value: $0) } + ) case .swiftProtocol: // Same as jsObject but no cleanup — Swift's AnyProtocol wrapper releases via deinit return IntrinsicJSFragment( @@ -2625,8 +2522,9 @@ struct IntrinsicJSFragment: Sendable { private static func optionalElementRaiseFragment( wrappedType: BridgeType, - absenceLiteral: String = "null" + kind: JSOptionalKind ) throws -> IntrinsicJSFragment { + let absenceLiteral = kind.absenceLiteral return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -2973,13 +2871,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)) {") @@ -3219,14 +3117,6 @@ struct IntrinsicJSFragment: Sendable { } } ) - case .undefinedOr: - return IntrinsicJSFragment( - parameters: ["value"], - printCode: { arguments, scope, printer, cleanup in - printer.write("throw new Error(\"Unsupported struct field type for lowering: \(field.type)\");") - return [] - } - ) case .swiftStruct(let nestedName): return IntrinsicJSFragment( parameters: ["value"], @@ -3434,7 +3324,7 @@ struct IntrinsicJSFragment: Sendable { return [pVar] } ) - case .optional(let wrappedType): + case .nullable(let wrappedType, let kind): return IntrinsicJSFragment( parameters: [], printCode: { arguments, scope, printer, cleanup in @@ -3472,7 +3362,7 @@ struct IntrinsicJSFragment: Sendable { } printer.write("} else {") printer.indent { - printer.write("\(optVar) = null;") + printer.write("\(optVar) = \(kind.absenceLiteral);") } printer.write("}") return [optVar] @@ -3583,14 +3473,6 @@ struct IntrinsicJSFragment: Sendable { return [varName] } ) - case .undefinedOr: - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - printer.write("throw new Error(\"Unsupported struct field type: \(field.type)\");") - return [] - } - ) case .void, .swiftProtocol, .namespaceEnum, .closure: // These types should not appear as struct fields return IntrinsicJSFragment( diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index fabff5d3e..caf725ee5 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -126,11 +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 unsafePointer(UnsafePointerType) - indirect case optional(BridgeType) - indirect case undefinedOr(BridgeType) + indirect case nullable(BridgeType, JSOptionalKind) indirect case array(BridgeType) case caseEnum(String) case rawValueEnum(String, SwiftEnumRawType) @@ -896,7 +917,7 @@ extension BridgeType { return .pointer case .unsafePointer: return .pointer - case .optional(_), .undefinedOr(_): + case .nullable: return nil case .caseEnum: return .i32 @@ -921,10 +942,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 .undefinedOr = self { return true } + if case .nullable = self { return true } return false } @@ -961,10 +981,9 @@ extension BridgeType { return "\(kindCode)\(p.count)\(p)" } return kindCode - case .optional(let wrapped): - return "Sq\(wrapped.mangleTypeName)" - case .undefinedOr(let wrapped): - return "Su\(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,13 +1010,7 @@ 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 { - let wrappedType: BridgeType - switch self { - case .optional(let wrapped): - wrappedType = wrapped - case .undefinedOr(let wrapped): - wrappedType = wrapped - default: + guard case .nullable(let wrappedType, _) = self else { return false } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json index 7950cb66a..8dde2cfb7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json @@ -516,12 +516,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -531,12 +532,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -557,12 +559,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -572,12 +575,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -596,7 +600,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -605,13 +609,14 @@ } } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -620,7 +625,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -639,12 +645,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -654,12 +661,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Point" } - } + }, + "_1" : "null" } } } @@ -680,12 +688,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -695,12 +704,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -721,13 +731,14 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Status", "_1" : "Int" } - } + }, + "_1" : "null" } } } @@ -737,13 +748,14 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Status", "_1" : "Int" } - } + }, + "_1" : "null" } } } @@ -994,12 +1006,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } @@ -1009,12 +1022,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json index 7f21c86cf..59fb8484a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.ReverseOrder.json @@ -12,12 +12,13 @@ "isStatic" : false, "name" : "linkedB", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "ClassB" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json index 3f8129109..cc10331a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileTypeResolution.json @@ -33,12 +33,13 @@ "isStatic" : false, "name" : "linkedB", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "ClassB" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json index 64cc1a845..8c088a35e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.json @@ -135,12 +135,13 @@ "label" : "tag", "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -196,12 +197,13 @@ "isStatic" : false, "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -414,23 +416,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -452,23 +456,25 @@ "label" : "greeting", "name" : "greeting", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -646,23 +652,25 @@ "label" : "point", "name" : "point", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } }, @@ -710,23 +718,25 @@ "label" : "point", "name" : "point", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json index ecf045c3c..ba9ee9324 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json @@ -398,12 +398,13 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -414,23 +415,25 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -441,34 +444,37 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -570,23 +576,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -670,23 +678,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } }, @@ -703,23 +713,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "Utilities.Result" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "Utilities.Result" } - } + }, + "_1" : "null" } } }, @@ -736,23 +748,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "NetworkingResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "NetworkingResult" } - } + }, + "_1" : "null" } } }, @@ -769,23 +783,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } }, @@ -802,12 +818,13 @@ "label" : "result1", "name" : "result1", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } }, @@ -815,23 +832,25 @@ "label" : "result2", "name" : "result2", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json index 2d5d5f2fa..ea32ad739 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumCase.json @@ -216,23 +216,25 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -291,23 +293,25 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "TSDirection" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "TSDirection" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json index 20ef1f42f..ba36405ba 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumRawType.json @@ -517,25 +517,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -596,25 +598,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSTheme", "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSTheme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -675,25 +679,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "FeatureFlag", "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "FeatureFlag", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -754,25 +760,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -833,25 +841,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSHttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSHttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -912,25 +922,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Priority", "_1" : "Int32" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Priority", "_1" : "Int32" } - } + }, + "_1" : "null" } } }, @@ -991,25 +1003,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "FileSize", "_1" : "Int64" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "FileSize", "_1" : "Int64" } - } + }, + "_1" : "null" } } }, @@ -1070,25 +1084,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "UserId", "_1" : "UInt" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "UserId", "_1" : "UInt" } - } + }, + "_1" : "null" } } }, @@ -1149,25 +1165,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TokenId", "_1" : "UInt32" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TokenId", "_1" : "UInt32" } - } + }, + "_1" : "null" } } }, @@ -1228,25 +1246,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "SessionId", "_1" : "UInt64" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "SessionId", "_1" : "UInt64" } - } + }, + "_1" : "null" } } }, @@ -1307,25 +1327,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Precision", "_1" : "Float" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Precision", "_1" : "Float" } - } + }, + "_1" : "null" } } }, @@ -1386,25 +1408,27 @@ "label" : "_", "name" : "input", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Ratio", "_1" : "Double" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Ratio", "_1" : "Double" } - } + }, + "_1" : "null" } } }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json index c40f0dc82..cecf16c9c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.json @@ -73,12 +73,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -88,12 +89,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -150,12 +152,13 @@ "isStatic" : false, "name" : "optionalFoo", "type" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json index 2af32886b..ea5c675f0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json @@ -14,12 +14,13 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -56,12 +57,13 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -80,12 +82,13 @@ "isStatic" : false, "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -114,12 +117,13 @@ "isStatic" : false, "name" : "optionalName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -128,12 +132,13 @@ "isStatic" : false, "name" : "optionalAge", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -142,12 +147,13 @@ "isStatic" : false, "name" : "optionalGreeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -173,23 +179,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -206,23 +214,25 @@ "label" : "_", "name" : "holder", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "OptionalPropertyHolder" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "OptionalPropertyHolder" } - } + }, + "_1" : "null" } } }, @@ -239,23 +249,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -272,23 +284,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -305,23 +319,25 @@ "label" : "flag", "name" : "flag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, @@ -338,23 +354,25 @@ "label" : "number", "name" : "number", "type" : { - "optional" : { + "nullable" : { "_0" : { "float" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "float" : { } - } + }, + "_1" : "null" } } }, @@ -371,23 +389,25 @@ "label" : "precision", "name" : "precision", "type" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -404,23 +424,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -437,23 +459,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -470,23 +494,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -503,23 +529,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -536,23 +564,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -569,23 +599,25 @@ "label" : "age", "name" : "age", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -602,23 +634,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -635,12 +669,13 @@ "label" : "firstName", "name" : "firstName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -648,12 +683,13 @@ "label" : "lastName", "name" : "lastName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -661,12 +697,13 @@ "label" : "age", "name" : "age", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -681,12 +718,13 @@ } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json index 5713a2898..e9f5264cd 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.json @@ -237,12 +237,13 @@ "isStatic" : false, "name" : "secondDelegate", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftProtocol" : { "_0" : "MyViewControllerDelegate" } - } + }, + "_1" : "null" } } } @@ -667,12 +668,13 @@ "label" : "_", "name" : "helper", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Helper" } - } + }, + "_1" : "null" } } } @@ -695,12 +697,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Helper" } - } + }, + "_1" : "null" } } }, @@ -789,12 +792,13 @@ "isReadonly" : false, "name" : "optionalName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -802,13 +806,14 @@ "isReadonly" : false, "name" : "optionalRawEnum", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "ExampleEnum", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -835,12 +840,13 @@ "isReadonly" : false, "name" : "optionalResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "Result" } - } + }, + "_1" : "null" } } }, @@ -857,12 +863,13 @@ "isReadonly" : false, "name" : "directionOptional", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -880,13 +887,14 @@ "isReadonly" : false, "name" : "priorityOptional", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Priority", "_1" : "Int" } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json index 9b1d0d6b8..bb9e48091 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.Global.json @@ -118,12 +118,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json index b3ccf7e93..d385e3887 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticProperties.json @@ -118,12 +118,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json index 345582e86..d71726828 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json @@ -202,30 +202,33 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Person" } - } + }, + "_1" : "null" } }, { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } }, { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } ], @@ -325,12 +328,13 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Person" } - } + }, + "_1" : "null" } } ], @@ -353,12 +357,13 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Person" } - } + }, + "_1" : "null" } } ], @@ -700,12 +705,13 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], @@ -746,13 +752,14 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } ], @@ -793,12 +800,13 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } ], @@ -838,12 +846,13 @@ "moduleName" : "TestModule", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json index 1b2dc531f..00c6af5cb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.json @@ -184,12 +184,13 @@ "label" : "optCount", "name" : "optCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -197,12 +198,13 @@ "label" : "optFlag", "name" : "optFlag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -248,12 +250,13 @@ "isStatic" : false, "name" : "optCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -262,12 +265,13 @@ "isStatic" : false, "name" : "optFlag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -305,12 +309,13 @@ "isStatic" : false, "name" : "zipCode", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -358,12 +363,13 @@ "isStatic" : false, "name" : "email", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -431,13 +437,14 @@ "isStatic" : false, "name" : "optionalPrecision", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Precision", "_1" : "Float" } - } + }, + "_1" : "null" } } } @@ -563,12 +570,13 @@ "isStatic" : false, "name" : "optionalObject", "type" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index ac60ca860..e337124ee 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -105,6 +105,14 @@ public protocol _BridgedSwiftStackType { 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 { @@ -1773,6 +1781,379 @@ 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 where Element: _BridgedSwiftStackType, Element.StackLiftResult == Element { diff --git a/Sources/JavaScriptKit/JSUndefinedOr.swift b/Sources/JavaScriptKit/JSUndefinedOr.swift index f70cfc0df..82e218105 100644 --- a/Sources/JavaScriptKit/JSUndefinedOr.swift +++ b/Sources/JavaScriptKit/JSUndefinedOr.swift @@ -6,12 +6,12 @@ public static var undefinedValue: Self { .undefined } @inlinable - init(optional: Wrapped?) { + public init(optional: Wrapped?) { self = optional.map(Self.value) ?? .undefined } @inlinable - var optionalRepresentation: Wrapped? { + public var optionalRepresentation: Wrapped? { switch self { case .undefined: return nil @@ -40,369 +40,6 @@ extension JSUndefinedOr: ConvertibleToJSValue where Wrapped: ConvertibleToJSValu } } -// MARK: - BridgeJS Optional-style conformances +// MARK: - BridgeJS (via _BridgedAsOptional in BridgeJSIntrinsics) -extension JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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()) - } -} - -extension JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr where Wrapped: _BridgedSwiftTypeLoweredIntoVoidType { - @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() -> Void { - optionalRepresentation.bridgeJSLowerReturn() - } -} - -extension JSUndefinedOr -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 JSUndefinedOr 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 JSUndefinedOr 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 JSUndefinedOr -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 JSUndefinedOr -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 JSUndefinedOr 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 JSUndefinedOr 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() - } -} +extension JSUndefinedOr: _BridgedAsOptional {} diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index a572f4c6f..72b104683 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -4488,9 +4488,9 @@ public func _bjs_applyOptionalGreeter(_ valueIsSome: Int32, _ valueValue: Unsafe @_expose(wasm, "bjs_makeOptionalHolder") @_cdecl("bjs_makeOptionalHolder") -public func _bjs_makeOptionalHolder(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsDefined: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { +public func _bjs_makeOptionalHolder(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsSome: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = makeOptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsDefined, undefinedNumberValue)) + let ret = makeOptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsSome, undefinedNumberValue)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -5909,9 +5909,9 @@ fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int @_expose(wasm, "bjs_OptionalHolder_init") @_cdecl("bjs_OptionalHolder_init") -public func _bjs_OptionalHolder_init(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsDefined: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { +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(undefinedNumberIsDefined, undefinedNumberValue)) + let ret = OptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsSome, undefinedNumberValue)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") @@ -5952,9 +5952,9 @@ public func _bjs_OptionalHolder_undefinedNumber_get(_ _self: UnsafeMutableRawPoi @_expose(wasm, "bjs_OptionalHolder_undefinedNumber_set") @_cdecl("bjs_OptionalHolder_undefinedNumber_set") -public func _bjs_OptionalHolder_undefinedNumber_set(_ _self: UnsafeMutableRawPointer, _ valueIsDefined: Int32, _ valueValue: Float64) -> Void { +public func _bjs_OptionalHolder_undefinedNumber_set(_ _self: UnsafeMutableRawPointer, _ valueIsSome: Int32, _ valueValue: Float64) -> Void { #if arch(wasm32) - OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber = JSUndefinedOr.bridgeJSLiftParameter(valueIsDefined, valueValue) + OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber = JSUndefinedOr.bridgeJSLiftParameter(valueIsSome, valueValue) #else fatalError("Only available on WebAssembly") #endif @@ -8034,16 +8034,16 @@ func _$jsRoundTripOptionalNumberNull(_ v: Optional) throws(JSException) #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberUndefined") -fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsDefined: Int32, _ vValue: Float64) -> Void +fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsSome: Int32, _ vValue: Float64) -> Void #else -fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsDefined: Int32, _ vValue: Float64) -> Void { +fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsSome: Int32, _ vValue: Float64) -> Void { fatalError("Only available on WebAssembly") } #endif func _$jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { - let (vIsDefined, vValue) = v.bridgeJSLowerParameter() - bjs_jsRoundTripOptionalNumberUndefined(vIsDefined, vValue) + let (vIsSome, vValue) = v.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalNumberUndefined(vIsSome, vValue) if let error = _swift_js_take_exception() { throw error } diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 3c71881a5..f73b25c32 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -538,12 +538,13 @@ "label" : "nullableGreeter", "name" : "nullableGreeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -551,12 +552,13 @@ "label" : "undefinedNumber", "name" : "undefinedNumber", "type" : { - "undefinedOr" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "undefined" } } } @@ -572,12 +574,13 @@ "isStatic" : false, "name" : "nullableGreeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -586,12 +589,13 @@ "isStatic" : false, "name" : "undefinedNumber", "type" : { - "undefinedOr" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "undefined" } } } @@ -611,12 +615,13 @@ "label" : "optionalName", "name" : "optionalName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -632,12 +637,13 @@ "isStatic" : false, "name" : "optionalName", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -646,12 +652,13 @@ "isStatic" : false, "name" : "optionalAge", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -660,12 +667,13 @@ "isStatic" : false, "name" : "optionalGreeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -1130,12 +1138,13 @@ "label" : "tag", "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1207,12 +1216,13 @@ "isStatic" : false, "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1366,12 +1376,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -1385,12 +1396,13 @@ } }, "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1572,12 +1584,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1610,12 +1623,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -1632,12 +1646,13 @@ "label" : "_", "name" : "tag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -1660,12 +1675,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -1682,12 +1698,13 @@ "label" : "_", "name" : "count", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -1710,12 +1727,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -1732,12 +1750,13 @@ "label" : "_", "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -1760,13 +1779,14 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -1783,13 +1803,14 @@ "label" : "_", "name" : "theme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } } @@ -1812,13 +1833,14 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -1835,13 +1857,14 @@ "label" : "_", "name" : "status", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } } @@ -1864,12 +1887,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -1886,12 +1910,13 @@ "label" : "_", "name" : "apiResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -1920,12 +1945,13 @@ "isStatic" : false, "name" : "backupProcessor", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftProtocol" : { "_0" : "DataProcessor" } - } + }, + "_1" : "null" } } } @@ -2110,12 +2136,13 @@ "label" : "_", "name" : "greeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -2138,12 +2165,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -2160,12 +2188,13 @@ "label" : "_", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -2188,12 +2217,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -2225,12 +2255,13 @@ "isStatic" : false, "name" : "optionalTag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -2239,12 +2270,13 @@ "isStatic" : false, "name" : "optionalCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -2253,12 +2285,13 @@ "isStatic" : false, "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -2267,13 +2300,14 @@ "isStatic" : false, "name" : "optionalTheme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -2282,13 +2316,14 @@ "isStatic" : false, "name" : "httpStatus", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -2297,12 +2332,13 @@ "isStatic" : false, "name" : "apiResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -2321,12 +2357,13 @@ "isStatic" : false, "name" : "optionalHelper", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -2512,12 +2549,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } ], @@ -2558,12 +2596,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } ], @@ -2604,12 +2643,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } ], @@ -2649,12 +2689,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } ], @@ -2689,12 +2730,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -3030,12 +3072,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], @@ -3076,13 +3119,14 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } ], @@ -3123,12 +3167,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } ], @@ -3168,12 +3213,13 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } ], @@ -3215,12 +3261,13 @@ "label" : "config", "name" : "config", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } } @@ -3246,12 +3293,13 @@ "isStatic" : false, "name" : "config", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Config" } - } + }, + "_1" : "null" } } } @@ -4315,12 +4363,13 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -4331,23 +4380,25 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -4358,34 +4409,37 @@ "associatedValues" : [ { "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, { "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -6855,23 +6909,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -6888,23 +6944,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -6921,23 +6979,25 @@ "label" : "flag", "name" : "flag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } }, @@ -6954,23 +7014,25 @@ "label" : "number", "name" : "number", "type" : { - "optional" : { + "nullable" : { "_0" : { "float" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "float" : { } - } + }, + "_1" : "null" } } }, @@ -6987,23 +7049,25 @@ "label" : "precision", "name" : "precision", "type" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -7020,23 +7084,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -7053,23 +7119,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -7086,23 +7154,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -7119,23 +7189,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -7152,23 +7224,25 @@ "label" : "age", "name" : "age", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -7185,23 +7259,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Status" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Status" } - } + }, + "_1" : "null" } } }, @@ -7218,25 +7294,27 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -7253,25 +7331,27 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -7288,23 +7368,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "TSDirection" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "TSDirection" } - } + }, + "_1" : "null" } } }, @@ -7321,25 +7403,27 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSTheme", "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "TSTheme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -7356,23 +7440,25 @@ "label" : "_", "name" : "method", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Networking.API.Method" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Networking.API.Method" } - } + }, + "_1" : "null" } } }, @@ -7389,23 +7475,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -7422,12 +7510,13 @@ "label" : "_", "name" : "r1", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -7435,12 +7524,13 @@ "label" : "_", "name" : "r2", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -7464,23 +7554,25 @@ "label" : "_", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } }, @@ -7497,23 +7589,25 @@ "label" : "value", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -7530,23 +7624,25 @@ "label" : "_", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -7563,12 +7659,13 @@ "label" : "_", "name" : "value", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -7584,22 +7681,24 @@ "moduleName" : "BridgeJSRuntimeTests", "parameters" : [ { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -7608,12 +7707,13 @@ } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -7630,12 +7730,13 @@ "label" : "nullableGreeter", "name" : "nullableGreeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -7643,12 +7744,13 @@ "label" : "undefinedNumber", "name" : "undefinedNumber", "type" : { - "undefinedOr" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "undefined" } } } @@ -7672,23 +7774,25 @@ "label" : "result", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } }, @@ -7929,23 +8033,25 @@ "label" : "name", "name" : "name", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -8237,7 +8343,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -8246,7 +8352,8 @@ } } } - } + }, + "_1" : "null" } } } @@ -8814,12 +8921,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -8829,12 +8937,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -8855,12 +8964,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -8870,12 +8980,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -8896,12 +9007,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "DataPoint" } - } + }, + "_1" : "null" } } } @@ -8911,12 +9023,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "DataPoint" } - } + }, + "_1" : "null" } } } @@ -8937,12 +9050,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -8952,12 +9066,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } } @@ -8978,12 +9093,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Status" } - } + }, + "_1" : "null" } } } @@ -8993,12 +9109,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Status" } - } + }, + "_1" : "null" } } } @@ -9017,7 +9134,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9026,13 +9143,14 @@ } } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9041,7 +9159,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -9058,7 +9177,7 @@ "label" : "_", "name" : "values", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9067,13 +9186,14 @@ } } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9082,7 +9202,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -9099,7 +9220,7 @@ "label" : "_", "name" : "greeters", "type" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9108,13 +9229,14 @@ } } } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "array" : { "_0" : { @@ -9123,7 +9245,8 @@ } } } - } + }, + "_1" : "null" } } }, @@ -9713,12 +9836,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } @@ -9728,12 +9852,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } @@ -9787,12 +9912,13 @@ "type" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -9802,12 +9928,13 @@ "returnType" : { "array" : { "_0" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -10148,12 +10275,13 @@ "label" : "_", "name" : "newResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -10417,12 +10545,13 @@ "label" : "_", "name" : "greeter", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -10445,12 +10574,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, @@ -10467,12 +10597,13 @@ "label" : "_", "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -10495,12 +10626,13 @@ ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -10529,12 +10661,13 @@ "isReadonly" : false, "name" : "optionalTag", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -10542,12 +10675,13 @@ "isReadonly" : false, "name" : "optionalCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -10555,12 +10689,13 @@ "isReadonly" : false, "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -10568,13 +10703,14 @@ "isReadonly" : false, "name" : "optionalTheme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -10582,13 +10718,14 @@ "isReadonly" : false, "name" : "httpStatus", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "HttpStatus", "_1" : "Int" } - } + }, + "_1" : "null" } } }, @@ -10596,12 +10733,13 @@ "isReadonly" : false, "name" : "apiResult", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -10618,12 +10756,13 @@ "isReadonly" : false, "name" : "optionalHelper", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -10838,12 +10977,13 @@ "label" : "optCount", "name" : "optCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -10851,12 +10991,13 @@ "label" : "optFlag", "name" : "optFlag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -10902,12 +11043,13 @@ "isStatic" : false, "name" : "optCount", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } }, @@ -10916,12 +11058,13 @@ "isStatic" : false, "name" : "optFlag", "type" : { - "optional" : { + "nullable" : { "_0" : { "bool" : { } - } + }, + "_1" : "null" } } } @@ -10959,12 +11102,13 @@ "isStatic" : false, "name" : "zipCode", "type" : { - "optional" : { + "nullable" : { "_0" : { "int" : { } - } + }, + "_1" : "null" } } } @@ -11012,12 +11156,13 @@ "isStatic" : false, "name" : "email", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } }, @@ -11026,12 +11171,13 @@ "isStatic" : false, "name" : "secondaryAddress", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Address" } - } + }, + "_1" : "null" } } } @@ -11059,13 +11205,14 @@ "isStatic" : false, "name" : "theme", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Theme", "_1" : "String" } - } + }, + "_1" : "null" } } }, @@ -11074,12 +11221,13 @@ "isStatic" : false, "name" : "direction", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Direction" } - } + }, + "_1" : "null" } } }, @@ -11117,12 +11265,13 @@ "isStatic" : false, "name" : "owner", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftHeapObject" : { "_0" : "Greeter" } - } + }, + "_1" : "null" } } } @@ -11160,12 +11309,13 @@ "isStatic" : false, "name" : "status", "type" : { - "optional" : { + "nullable" : { "_0" : { "caseEnum" : { "_0" : "Status" } - } + }, + "_1" : "null" } } }, @@ -11174,12 +11324,13 @@ "isStatic" : false, "name" : "outcome", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } } @@ -11248,12 +11399,13 @@ "isStatic" : false, "name" : "result", "type" : { - "optional" : { + "nullable" : { "_0" : { "associatedValueEnum" : { "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, @@ -11262,12 +11414,13 @@ "isStatic" : false, "name" : "metadata", "type" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } }, @@ -11276,12 +11429,13 @@ "isStatic" : false, "name" : "location", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "DataPoint" } - } + }, + "_1" : "null" } } }, @@ -11300,12 +11454,13 @@ "isStatic" : false, "name" : "overrideDefaults", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "ConfigStruct" } - } + }, + "_1" : "null" } } } @@ -11345,13 +11500,14 @@ "isStatic" : false, "name" : "optionalPrecision", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Precision", "_1" : "Float" } - } + }, + "_1" : "null" } } }, @@ -11360,13 +11516,14 @@ "isStatic" : false, "name" : "optionalRatio", "type" : { - "optional" : { + "nullable" : { "_0" : { "rawValueEnum" : { "_0" : "Ratio", "_1" : "Double" } - } + }, + "_1" : "null" } } } @@ -11577,12 +11734,13 @@ "isStatic" : false, "name" : "note", "type" : { - "optional" : { + "nullable" : { "_0" : { "string" : { } - } + }, + "_1" : "null" } } } @@ -11678,12 +11836,13 @@ "isStatic" : false, "name" : "shippingAddress", "type" : { - "optional" : { + "nullable" : { "_0" : { "swiftStruct" : { "_0" : "Address" } - } + }, + "_1" : "null" } } } @@ -11800,12 +11959,13 @@ "isStatic" : false, "name" : "optionalObject", "type" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { } - } + }, + "_1" : "null" } } } @@ -11833,12 +11993,13 @@ "isStatic" : false, "name" : "optionalFoo", "type" : { - "optional" : { + "nullable" : { "_0" : { "jsObject" : { "_0" : "Foo" } - } + }, + "_1" : "null" } } } @@ -11960,23 +12121,25 @@ { "name" : "v", "type" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } } ], "returnType" : { - "optional" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "null" } } }, @@ -11986,23 +12149,25 @@ { "name" : "v", "type" : { - "undefinedOr" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "undefined" } } } ], "returnType" : { - "undefinedOr" : { + "nullable" : { "_0" : { "double" : { } - } + }, + "_1" : "undefined" } } }, From d6551ac8aff85147de52d559c6ee0dff2ce048f0 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 14:02:40 +0900 Subject: [PATCH 18/34] BridgeJS: Add te2swift unit tests --- .../TS2Swift/JavaScript/src/processor.js | 2 +- .../test/__snapshots__/ts2swift.test.js.snap | 41 +++++++++++++++++++ .../test/fixtures/OptionalNullUndefined.d.ts | 20 +++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/OptionalNullUndefined.d.ts diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index fd31967b0..0e458ed43 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -691,7 +691,7 @@ export class TypeProcessor { if (nonNullableTypes.length === 1 && (hasNull || hasUndefined)) { const wrapped = this.visitType(nonNullableTypes[0], node); if (hasNull && hasUndefined) { - return `JSUndefinedOr>`; + return "JSObject"; } if (hasNull) { return `Optional<${wrapped}>`; 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 index 6add64de4..c1db3e32e 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -145,6 +145,47 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult " `; +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. 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 From ab2c0682d4d188cc89a25f426e150d07411a6137 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 14:10:37 +0900 Subject: [PATCH 19/34] BridgeJS: Simplify optional presence check handling --- .../Sources/BridgeJSLink/JSGlueGen.swift | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 44e751d3a..90ea5ab0c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -643,10 +643,7 @@ struct IntrinsicJSFragment: Sendable { ) } - static func optionalLowerReturn( - wrappedType: BridgeType, - presenceCheck: (@Sendable (String) -> String)? = nil - ) throws -> IntrinsicJSFragment { + static func optionalLowerReturn(wrappedType: BridgeType, kind: JSOptionalKind) throws -> IntrinsicJSFragment { switch wrappedType { case .void, .nullable, .namespaceEnum, .closure: throw BridgeJSLinkError(message: "Unsupported optional wrapped type for protocol export: \(wrappedType)") @@ -658,7 +655,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanupCode in let value = arguments[0] let isSomeVar = scope.variable("isSome") - let presenceExpr = presenceCheck?(value) ?? "\(value) != null" + let presenceExpr = kind.presenceCheck(value: value) printer.write("const \(isSomeVar) = \(presenceExpr);") switch wrappedType { @@ -1599,10 +1596,7 @@ struct IntrinsicJSFragment: Sendable { case .swiftProtocol: return .jsObjectLowerReturn case .void: return .void case .nullable(let wrappedType, let kind): - return try .optionalLowerReturn( - wrappedType: wrappedType, - presenceCheck: { value in kind.presenceCheck(value: value) } - ) + return try .optionalLowerReturn(wrappedType: wrappedType, kind: kind) case .caseEnum: return .identity case .rawValueEnum(_, let rawType): switch rawType { @@ -2493,7 +2487,7 @@ struct IntrinsicJSFragment: Sendable { case .nullable(let wrappedType, let kind): return try optionalElementLowerFragment( wrappedType: wrappedType, - presenceCheck: { kind.presenceCheck(value: $0) } + kind: kind ) case .swiftProtocol: // Same as jsObject but no cleanup — Swift's AnyProtocol wrapper releases via deinit @@ -2556,7 +2550,7 @@ struct IntrinsicJSFragment: Sendable { private static func optionalElementLowerFragment( wrappedType: BridgeType, - presenceCheck: (@Sendable (String) -> String)? = nil + kind: JSOptionalKind ) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( parameters: ["value"], @@ -2564,7 +2558,7 @@ struct IntrinsicJSFragment: Sendable { let value = arguments[0] let isSomeVar = scope.variable("isSome") - let presenceExpr = presenceCheck?(value) ?? "\(value) != null" + 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() From 667d787dd3371fd887a427337a004b629d7bbe62 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 14:19:38 +0900 Subject: [PATCH 20/34] BridgeJS: Cover Optional/Undefined usage on import side --- .../Inputs/MacroSwift/Optionals.swift | 32 ++ .../BridgeJSCodegenTests/Optionals.json | 490 ++++++++++++++++++ .../BridgeJSCodegenTests/Optionals.swift | 461 +++++++++++++++- .../BridgeJSLinkTests/Optionals.d.ts | 21 + .../BridgeJSLinkTests/Optionals.js | 268 ++++++++++ 5 files changed, 1271 insertions(+), 1 deletion(-) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift index d256a8753..3fabe55c6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift @@ -90,3 +90,35 @@ typealias OptionalNameAlias = Optional 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 +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json index ea5c675f0..f74b3cdf7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json @@ -736,5 +736,495 @@ ] }, + "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" + } + } + } + ] + } + ] + } + ] + }, "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 index 88195f37d..471d38a6c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.swift @@ -338,4 +338,463 @@ fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPoi fileprivate func _bjs_OptionalPropertyHolder_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_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__/BridgeJSLinkTests/Optionals.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.d.ts index 5f63e9db5..b1a67ccde 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 2c08e3d9f..0ec2f81c9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -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); @@ -213,6 +214,273 @@ 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) { + const bytes = textEncoder.encode(ret); + bjs["swift_js_return_optional_string"](1, bytes, bytes.length); + return bytes.length; + } else { + bjs["swift_js_return_optional_string"](0, 0, 0); + return -1; + } + } 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) { + const bytes = textEncoder.encode(ret); + bjs["swift_js_return_optional_string"](1, bytes, bytes.length); + return bytes.length; + } else { + bjs["swift_js_return_optional_string"](0, 0, 0); + return -1; + } + } 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) { + const bytes = textEncoder.encode(ret); + bjs["swift_js_return_optional_string"](1, bytes, bytes.length); + return bytes.length; + } else { + bjs["swift_js_return_optional_string"](0, 0, 0); + return -1; + } + } 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) { + const bytes = textEncoder.encode(ret); + bjs["swift_js_return_optional_string"](1, bytes, bytes.length); + return bytes.length; + } else { + bjs["swift_js_return_optional_string"](0, 0, 0); + return -1; + } + } 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; From 966b2d71b9b9f85d04f66a58cc79ef40a0c55d3f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 14:21:26 +0900 Subject: [PATCH 21/34] ./Utilities/format.swift --- .../Inputs/MacroSwift/Optionals.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift index 3fabe55c6..57d994519 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Optionals.swift @@ -99,14 +99,18 @@ func testMixedOptionals(firstName: String?, lastName: String?, age: Int?, active @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 + @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 + @JSFunction func roundTripDoubleOrUndefined( + value: JSUndefinedOr + ) throws(JSException) -> JSUndefinedOr @JSGetter var boolOrNull: Bool? @JSSetter func setBoolOrNull(_ value: Bool?) throws(JSException) @@ -121,4 +125,4 @@ func testMixedOptionals(firstName: String?, lastName: String?, age: Int?, active @JSSetter func setIntOrUndefined(_ value: JSUndefinedOr) throws(JSException) @JSFunction func roundTripIntOrNull(value: Int?) throws(JSException) -> Int? @JSFunction func roundTripIntOrUndefined(value: JSUndefinedOr) throws(JSException) -> JSUndefinedOr -} \ No newline at end of file +} From 0bd50f8fd323a66fdfc4ae7e97c9e7cb50259d6c Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 19:02:59 +0900 Subject: [PATCH 22/34] [NFC] BridgeJS: Avoid emitting empty skeletons (#574) --- .../Generated/JavaScript/BridgeJS.json | 8 ----- .../Generated/JavaScript/BridgeJS.json | 8 ----- .../BridgeJSCore/SwiftToSkeleton.swift | 16 ++++++---- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 8 +++++ .../BridgeJSCodegenTests.swift | 18 +++++++++++ .../MacroSwift/Multifile/ExportedOnly.swift | 3 ++ .../Multifile/ImportedFunctions.swift | 1 + .../CrossFileSkipsEmptySkeletons.json | 25 +++++++++++++++ .../CrossFileSkipsEmptySkeletons.swift | 16 ++++++++++ .../BridgeJSCodegenTests/GlobalGetter.json | 18 ----------- .../GlobalThisImports.json | 18 ----------- .../InvalidPropertyNames.json | 18 ----------- .../BridgeJSCodegenTests/JSClass.json | 18 ----------- .../JSClassStaticFunctions.json | 18 ----------- .../BridgeJSCodegenTests/Optionals.json | 3 ++ .../SwiftClosureImports.json | 18 ----------- .../Generated/JavaScript/BridgeJS.json | 32 ------------------- 17 files changed, 83 insertions(+), 163 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ExportedOnly.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ImportedFunctions.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptySkeletons.swift diff --git a/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json index 4dff97132..eacd18cb3 100644 --- a/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json +++ b/Benchmarks/Sources/Generated/JavaScript/BridgeJS.json @@ -2737,14 +2737,6 @@ }, "imported" : { "children" : [ - { - "functions" : [ - - ], - "types" : [ - - ] - }, { "functions" : [ { diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json index 2952e2157..743925c5f 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json @@ -197,14 +197,6 @@ ] } ] - }, - { - "functions" : [ - - ], - "types" : [ - - ] } ] }, diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index f52aa7008..32b9f6418 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? { diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 3e2d51f8f..a9812e2e0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -624,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 @@ -854,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 { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift index ed83bc074..9754fbced 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift @@ -166,4 +166,22 @@ import Testing 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/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/__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/GlobalGetter.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json index 031870e57..55ac7dd70 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalGetter.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json index c75d9e011..5e002e34f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/GlobalThisImports.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json index b983f27a4..935f7a7f2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/InvalidPropertyNames.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json index be1d0f4cd..689e86150 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClass.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json index df3d3829e..a8b64558f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSClassStaticFunctions.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json index f74b3cdf7..9c99bb8c4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Optionals.json @@ -1220,6 +1220,9 @@ } } } + ], + "staticMethods" : [ + ] } ] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json index 12f76a912..9e0e0a491 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosureImports.json @@ -1,22 +1,4 @@ { - "exported" : { - "classes" : [ - - ], - "enums" : [ - - ], - "exposeToGlobal" : false, - "functions" : [ - - ], - "protocols" : [ - - ], - "structs" : [ - - ] - }, "imported" : { "children" : [ { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 476f60e34..0cb32079a 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -12643,22 +12643,6 @@ } ] }, - { - "functions" : [ - - ], - "types" : [ - - ] - }, - { - "functions" : [ - - ], - "types" : [ - - ] - }, { "functions" : [ { @@ -12904,22 +12888,6 @@ ], "types" : [ - ] - }, - { - "functions" : [ - - ], - "types" : [ - - ] - }, - { - "functions" : [ - - ], - "types" : [ - ] } ] From 56aabfae337f0949c992ab500415572030a4875d Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 19:04:00 +0900 Subject: [PATCH 23/34] [NFC] BridgeJS: Omit trailing spaces on empty lines in generated JS code (#575) When generating JavaScript code, avoid adding trailing spaces to empty lines. --- .../BridgeJSLink/CodeFragmentPrinter.swift | 5 ++ .../BridgeJSLinkTests/ArrayTypes.js | 8 +-- .../__Snapshots__/BridgeJSLinkTests/Async.js | 2 +- .../BridgeJSLinkTests/DefaultParameters.js | 14 ++--- .../BridgeJSLinkTests/EnumAssociatedValue.js | 12 ++-- .../BridgeJSLinkTests/EnumCase.js | 2 +- .../BridgeJSLinkTests/EnumNamespace.Global.js | 10 +-- .../BridgeJSLinkTests/EnumNamespace.js | 10 +-- .../BridgeJSLinkTests/EnumRawType.js | 2 +- .../BridgeJSLinkTests/GlobalGetter.js | 2 +- .../BridgeJSLinkTests/GlobalThisImports.js | 2 +- .../ImportedTypeInExportedInterface.js | 4 +- .../BridgeJSLinkTests/InvalidPropertyNames.js | 2 +- .../BridgeJSLinkTests/JSClass.js | 2 +- .../JSClassStaticFunctions.js | 2 +- .../BridgeJSLinkTests/MixedGlobal.js | 6 +- .../BridgeJSLinkTests/MixedModules.js | 8 +-- .../BridgeJSLinkTests/MixedPrivate.js | 6 +- .../BridgeJSLinkTests/Namespaces.Global.js | 10 +-- .../BridgeJSLinkTests/Namespaces.js | 10 +-- .../BridgeJSLinkTests/Optionals.js | 8 +-- .../BridgeJSLinkTests/PrimitiveParameters.js | 2 +- .../BridgeJSLinkTests/PrimitiveReturn.js | 2 +- .../BridgeJSLinkTests/PropertyTypes.js | 6 +- .../BridgeJSLinkTests/Protocol.js | 12 ++-- .../StaticFunctions.Global.js | 8 +-- .../BridgeJSLinkTests/StaticFunctions.js | 8 +-- .../StaticProperties.Global.js | 6 +- .../BridgeJSLinkTests/StaticProperties.js | 6 +- .../BridgeJSLinkTests/StringParameter.js | 2 +- .../BridgeJSLinkTests/StringReturn.js | 2 +- .../BridgeJSLinkTests/SwiftClass.js | 10 +-- .../BridgeJSLinkTests/SwiftClosure.js | 62 +++++++++---------- .../BridgeJSLinkTests/SwiftClosureImports.js | 6 +- .../BridgeJSLinkTests/SwiftStruct.js | 20 +++--- .../BridgeJSLinkTests/SwiftStructImports.js | 4 +- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 2 +- .../BridgeJSLinkTests/UnsafePointer.js | 4 +- .../VoidParameterVoidReturn.js | 2 +- 39 files changed, 148 insertions(+), 143 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift index c4624e694..258a0ad18 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift @@ -12,6 +12,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/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index da5920660..491fc610e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -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 = () => { @@ -288,7 +288,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,11 +298,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) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 4015b6261..d5a195430 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 978272568..bc669993b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -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 = () => { @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 2d8dbc0ca..6eb4b3985 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -506,7 +506,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -683,19 +683,19 @@ export async function createInstantiator(options, swift) { 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) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 89a0f0897..874b4c4c0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -55,7 +55,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index f48a0050e..78f08ffb5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -75,7 +75,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index 1eb483365..cddeac767 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -56,7 +56,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index 1e137e6eb..315b74262 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -106,7 +106,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index b3b809476..b5053b266 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 35a3d76ec..0d9eb79c3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index e4ce9e8fe..11aa2b3d8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; const __bjs_createFooContainerHelpers = () => { @@ -300,7 +300,7 @@ export async function createInstantiator(options, swift) { 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(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index ab030062a..6a11003b3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index 5b7541b1c..b60a698b4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index f8f0ba86f..214a32294 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index f079de1da..e1345f94b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 2c43b91e8..0703be789 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 4b8ce8a66..0cc377f4c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index 671868eab..630651aea 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index ae7bf7451..b3073da70 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 0ec2f81c9..27e9c3c6b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -506,7 +506,7 @@ export async function createInstantiator(options, swift) { obj.registry.register(this, obj.pointer); return obj; } - + release() { this.registry.unregister(this); this.deinit(this.pointer); @@ -516,7 +516,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; @@ -571,7 +571,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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index 97e03063a..98f50e850 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index 871310bb8..e68e4e6a2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index fc13a471a..7bf565105 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 24c02750f..ce9065ac4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -95,7 +95,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -579,7 +579,7 @@ export async function createInstantiator(options, swift) { 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 +600,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 +610,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 +630,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 +688,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) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index e7bebfe6c..b79c6ebf4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -82,7 +82,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) { 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 +288,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 +298,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index 8b5a54315..2f240c428 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -82,7 +82,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -267,7 +267,7 @@ export async function createInstantiator(options, swift) { 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 +288,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 +298,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index 9806fc631..15edf8c60 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index ee127ed07..d90e96f0e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -36,7 +36,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index 03a4bc9b1..fc67c0027 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index 98ea9fa4a..50edf3b06 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index d04cd6507..f3d5cafcb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 40378d042..59512a7eb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -133,7 +133,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -303,7 +303,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 +315,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule10HttpStatusO_Si"] = function(closurePtr) { return function(param0) { try { @@ -326,7 +326,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 +345,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule5ThemeO_SS"] = function(closurePtr) { return function(param0) { try { @@ -361,7 +361,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 +375,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule5ThemeO_Sb"] = function(closurePtr) { return function(param0) { try { @@ -388,7 +388,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 +405,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule6PersonC_SS"] = function(closurePtr) { return function(param0) { try { @@ -419,7 +419,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModule9APIResultO_SS"] = function(callbackId, param0Id) { try { const callback = swift.memory.getObject(callbackId); @@ -436,7 +436,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9APIResultO_SS"] = function(closurePtr) { return function(param0) { try { @@ -451,7 +451,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 +468,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9DirectionO_SS"] = function(closurePtr) { return function(param0) { try { @@ -482,7 +482,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 +494,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModule9DirectionO_Sb"] = function(closurePtr) { return function(param0) { try { @@ -505,7 +505,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 +524,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSS_SS"] = function(closurePtr) { return function(param0) { try { @@ -540,7 +540,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 +564,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq5ThemeO_SS"] = function(closurePtr) { return function(param0) { try { @@ -584,7 +584,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 +620,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 +642,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 +664,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq6PersonC_SS"] = function(closurePtr) { return function(param0) { try { @@ -679,7 +679,7 @@ export async function createInstantiator(options, swift) { } }; }; - + bjs["invoke_js_callback_TestModule_10TestModuleSq9APIResultO_SS"] = function(callbackId, param0IsSome, param0Value) { try { const callback = swift.memory.getObject(callbackId); @@ -701,7 +701,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq9APIResultO_SS"] = function(closurePtr) { return function(param0) { try { @@ -722,7 +722,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 +744,7 @@ export async function createInstantiator(options, swift) { return 0; } }; - + bjs["lower_closure_TestModule_10TestModuleSq9DirectionO_SS"] = function(closurePtr) { return function(param0) { try { @@ -778,7 +778,7 @@ export async function createInstantiator(options, swift) { 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 +799,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 +809,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 +822,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 9ab218df1..145eeb756 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index dbeb70e69..f389900dc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -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 = () => { @@ -569,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); @@ -579,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); @@ -608,25 +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) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index f4e7e61e9..afed321ce 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -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 = () => { @@ -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/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 5a492295a..8a1c49647 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 2ac28b7e9..61f6c6cf3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -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 = () => { @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index f37cbd90b..053c55672 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -31,7 +31,7 @@ export async function createInstantiator(options, swift) { let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; - + let _exports = null; let bjs = null; From 81885ea1194b3b2f7f2025fe0abba367be3b0b4b Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 20:54:05 +0900 Subject: [PATCH 24/34] BridgeJS: Perf-tune `SwiftToSkeleton` by avoiding unnecessary Syntax node allocation (#577) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `trimmedDescription` allocates two new Syntax nodes just to get the trimmed description of a node. ```swift extension SyntaxProtocol { public var trimmedDescription: String { // TODO: We shouldn't need to create to copies just to get the trimmed // description. return self.trimmed.description } public var trimmed: Self { // TODO: Should only need one new node here return self.with(\.leadingTrivia, []).with(\.trailingTrivia, []) } } ``` ``` $ cat check.d.ts export function getCanvas(x: string): HTMLCanvasElement; $ node Plugins/BridgeJS/Sources/TS2Swift/JavaScript/bin/ts2swift.js check.d.ts -p tsconfig.json -o out.swift $ hyperfine "./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift" "./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift" Benchmark 1: ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift Time (mean ± σ): 16.531 s ± 0.317 s [User: 16.355 s, System: 0.107 s] Range (min … max): 16.026 s … 17.252 s 10 runs Benchmark 2: ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift Time (mean ± σ): 4.068 s ± 0.134 s [User: 3.976 s, System: 0.039 s] Range (min … max): 4.000 s … 4.445 s 10 runs Summary ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift ran 4.06 ± 0.15 times faster than ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift ``` --- .../BridgeJSCore/SwiftToSkeleton.swift | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 32b9f6418..d32d85f55 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -394,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 } } } @@ -1916,9 +1922,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 { @@ -1926,9 +1930,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 { @@ -1936,9 +1938,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 { @@ -1946,16 +1946,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 } } From 16e3f4467581c7231025c51eb13bfc8a9d87cd46 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 4 Feb 2026 21:29:57 +0900 Subject: [PATCH 25/34] BridgeJS: Add JSValue parameter/return support (#570) * BridgeJS: Add support for `JSValue` * BridgeJS: Fix unused result warnings * BridgeJS: Keep translating object-like types to JSObject * UPDATE_SNAPSHOTS=1 swift test --package-path ./Plugins/BridgeJS * BridgeJS: Update object-like check not to rely on definition location * BridgeJS: Add __bjs_jsValueLower/Lift helper functions * UPDATE_SNAPSHOTS=1 swift test --package-path ./Plugins/BridgeJS --- .../Sources/BridgeJSCore/ExportSwift.swift | 17 +- .../Sources/BridgeJSCore/ImportTS.swift | 24 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 171 +++++-- .../BridgeJSLink/CodeFragmentPrinter.swift | 34 ++ .../Sources/BridgeJSLink/JSGlueGen.swift | 360 +++++++++++++- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 7 +- .../TS2Swift/JavaScript/src/processor.js | 9 +- .../test/__snapshots__/ts2swift.test.js.snap | 31 +- .../test/fixtures/ObjectLikeTypes.d.ts | 1 + .../Inputs/MacroSwift/JSValue.swift | 32 ++ .../BridgeJSCodegenTests/JSValue.json | 273 +++++++++++ .../BridgeJSCodegenTests/JSValue.swift | 149 ++++++ .../BridgeJSLinkTests/JSValue.d.ts | 37 ++ .../BridgeJSLinkTests/JSValue.js | 456 ++++++++++++++++++ .../JavaScriptKit/BridgeJSIntrinsics.swift | 141 ++++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 8 + .../Generated/BridgeJS.Macros.swift | 4 +- .../Generated/BridgeJS.swift | 50 +- .../Generated/JavaScript/BridgeJS.json | 80 ++- .../GlobalThisImportTests.swift | 6 +- .../BridgeJSRuntimeTests/ImportAPITests.swift | 18 + Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 2 + Tests/prelude.mjs | 20 + 23 files changed, 1841 insertions(+), 89 deletions(-) create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ObjectLikeTypes.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index cb267c210..1137343b0 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -804,7 +804,7 @@ struct StackCodegen { func liftExpression(for type: BridgeType) -> ExprSyntax { switch type { case .string, .int, .uint, .bool, .float, .double, - .jsObject(nil), .swiftStruct, .swiftHeapObject: + .jsObject(nil), .jsValue, .swiftStruct, .swiftHeapObject: return "\(raw: type.swiftType).bridgeJSLiftParameter()" case .jsObject(let className?): return "\(raw: className)(unsafelyWrapping: JSObject.bridgeJSLiftParameter())" @@ -841,7 +841,7 @@ struct StackCodegen { func liftArrayExpression(elementType: BridgeType) -> ExprSyntax { switch elementType { - case .int, .uint, .float, .double, .string, .bool, + case .int, .uint, .float, .double, .string, .bool, .jsValue, .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, .unsafePointer, .rawValueEnum, .associatedValueEnum: return "[\(raw: elementType.swiftType)].bridgeJSLiftParameter()" @@ -876,7 +876,7 @@ struct StackCodegen { private func liftNullableExpression(wrappedType: BridgeType, kind: JSOptionalKind) -> ExprSyntax { let typeName = kind == .null ? "Optional" : "JSUndefinedOr" switch wrappedType { - case .string, .int, .uint, .bool, .float, .double, .jsObject(nil), + 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?): @@ -914,7 +914,7 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch type { - case .string, .int, .uint, .bool, .float, .double: + case .string, .int, .uint, .bool, .float, .double, .jsValue: return ["\(raw: accessor).bridgeJSLowerStackReturn()"] case .jsObject(nil): return ["\(raw: accessor).bridgeJSLowerStackReturn()"] @@ -944,7 +944,7 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch elementType { - case .int, .uint, .float, .double, .string, .bool, + case .int, .uint, .float, .double, .string, .bool, .jsValue, .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, .unsafePointer, .rawValueEnum, .associatedValueEnum: return ["\(raw: accessor).bridgeJSLowerReturn()"] @@ -1015,7 +1015,7 @@ struct StackCodegen { varPrefix: String ) -> [CodeBlockItemSyntax] { switch wrappedType { - case .string, .int, .uint, .bool, .float, .double: + case .string, .int, .uint, .bool, .float, .double, .jsValue: return ["\(raw: unwrappedVar).bridgeJSLowerStackReturn()"] case .caseEnum, .rawValueEnum: // Enums conform to _BridgedSwiftStackType @@ -1604,6 +1604,7 @@ 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 @@ -1634,6 +1635,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: []) @@ -1651,6 +1653,7 @@ 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 @@ -1684,6 +1687,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) @@ -1703,6 +1707,7 @@ 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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index bcfc344b3..22e0ef162 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -178,13 +178,19 @@ public struct ImportTS { rightParen: .rightParenToken() ) - if returnType == .void { - body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) - } else if returnType.usesSideChannelForOptionalReturn() { - // Side channel returns don't need "let ret =" - body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) + let needsRetBinding: Bool + let liftingInfo = try returnType.liftingReturnInfo(context: context) + if liftingInfo.valueToLift == nil || returnType.usesSideChannelForOptionalReturn() { + // Void and side-channel returns don't need "let ret =" + needsRetBinding = false } else { + needsRetBinding = true + } + + if needsRetBinding { body.append("let ret = \(raw: callExpr)") + } else { + body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) } // Add exception check for ImportTS context @@ -883,6 +889,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: []) } @@ -894,6 +905,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. @@ -970,6 +982,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) } @@ -983,6 +996,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. diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 87fbf59aa..4695f3283 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] = [], @@ -758,7 +759,7 @@ 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 @@ -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,37 @@ 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) } - printer.nextLine() - printer.write(contentsOf: generateAddImports(needsImportsObject: data.needsImportsObject)) + bodyPrinter.nextLine() + bodyPrinter.write(contentsOf: generateAddImports(needsImportsObject: data.needsImportsObject)) + + if !intrinsicRegistry.isEmpty { + printer.write(lines: intrinsicRegistry.emitLines()) + printer.nextLine() + } + + printer.write(lines: bodyPrinter.lines) } printer.indent() @@ -1111,11 +1126,6 @@ public struct BridgeJSLink { ) printer.write(lines: namespaceInitCode) - let propertyAssignments = try generateNamespacePropertyAssignments( - data: data, - exportedSkeletons: exportedSkeletons, - namespaceBuilder: namespaceBuilder - ) printer.write(lines: propertyAssignments) } printer.write("},") @@ -1128,6 +1138,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) @@ -1222,6 +1233,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 +1305,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() } @@ -1516,7 +1528,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) } @@ -1752,12 +1767,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) } @@ -1790,7 +1810,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) } @@ -1801,7 +1824,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) } @@ -1829,7 +1855,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) } @@ -1857,7 +1886,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) } @@ -1879,7 +1911,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) } @@ -1904,7 +1939,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!) @@ -1921,7 +1959,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) @@ -1967,7 +2006,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) } @@ -1999,7 +2041,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) } @@ -2022,7 +2067,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) @@ -2073,7 +2121,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() } @@ -2095,7 +2146,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() } @@ -2134,9 +2188,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 } @@ -2622,6 +2676,7 @@ extension BridgeJSLink { fileprivate func buildHierarchicalExportsObject( exportedSkeletons: [ExportedSkeleton], + intrinsicRegistry: JSIntrinsicRegistry, renderFunctionImpl: (ExportedFunction) throws -> [String] ) throws -> [String] { let printer = CodeFragmentPrinter() @@ -2631,7 +2686,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: []) @@ -2652,10 +2710,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 @@ -2678,14 +2742,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() @@ -2705,7 +2770,10 @@ extension BridgeJSLink { // Recursively process child nodes for (_, childNode) in node.children { - try populatePropertyImplementations(node: childNode) + try populatePropertyImplementations( + node: childNode, + intrinsicRegistry: intrinsicRegistry + ) } } @@ -3045,7 +3113,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) } @@ -3076,7 +3144,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( @@ -3177,7 +3245,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) } @@ -3202,7 +3270,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( @@ -3218,7 +3286,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( @@ -3233,7 +3301,7 @@ extension BridgeJSLink { context: ImportedTypeSkeleton, method: ImportedFunctionSkeleton ) throws -> (js: [String], dts: [String]) { - let thunkBuilder = ImportedThunkBuilder() + let thunkBuilder = ImportedThunkBuilder(intrinsicRegistry: intrinsicRegistry) for param in method.parameters { try thunkBuilder.liftParameter(param: param) } @@ -3259,7 +3327,7 @@ extension BridgeJSLink { 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) @@ -3286,7 +3354,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( @@ -3304,7 +3375,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) @@ -3324,7 +3398,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) @@ -3447,6 +3524,8 @@ extension BridgeType { return "boolean" case .jsObject(let name): return name ?? "any" + case .jsValue: + return "any" case .swiftHeapObject(let name): return name case .unsafePointer: diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift index 258a0ad18..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] = [] diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 90ea5ab0c..ef72cf6f6 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 @@ -296,10 +578,24 @@ struct IntrinsicJSFragment: Sendable { ) } - static func optionalLiftParameter( - wrappedType: BridgeType, - kind: JSOptionalKind - ) 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 @@ -446,6 +742,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") @@ -634,6 +933,22 @@ struct IntrinsicJSFragment: Sendable { 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;") + } + printer.write("}") default: printer.write("const \(resultVar) = \(JSGlueVariableScope.reservedStorageToReturnString);") printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = undefined;") @@ -702,6 +1017,17 @@ 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 .rawValueEnum(_, let rawType): switch rawType { case .string: @@ -1396,6 +1722,7 @@ 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 @@ -1441,6 +1768,7 @@ 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 @@ -1489,6 +1817,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 { @@ -1583,6 +1912,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 { @@ -1709,7 +2039,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) @@ -1737,7 +2067,7 @@ struct IntrinsicJSFragment: Sendable { 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) @@ -2208,6 +2538,8 @@ struct IntrinsicJSFragment: Sendable { private static func arrayElementRaiseFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { + case .jsValue: + throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") case .string: return IntrinsicJSFragment( parameters: [], @@ -2352,6 +2684,8 @@ struct IntrinsicJSFragment: Sendable { private static func arrayElementLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { + case .jsValue: + throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") case .string: return IntrinsicJSFragment( parameters: ["value"], @@ -2622,6 +2956,7 @@ struct IntrinsicJSFragment: Sendable { generateStructLowerCode( structDef: capturedStructDef, allStructs: capturedAllStructs, + scope: scope, printer: printer ) } @@ -2634,6 +2969,7 @@ struct IntrinsicJSFragment: Sendable { generateStructLiftCode( structDef: capturedStructDef, allStructs: capturedAllStructs, + scope: scope, printer: printer, attachMethods: true ) @@ -2656,10 +2992,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() @@ -2687,10 +3024,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)] = [] @@ -2724,7 +3062,7 @@ struct IntrinsicJSFragment: Sendable { "\(instanceVar).\(method.name) = function(\(paramList)) {" ) printer.indent { - let methodScope = JSGlueVariableScope() + let methodScope = scope.makeChildScope() let methodCleanup = CodeFragmentPrinter() // Lower the struct instance (this) using the helper's lower function @@ -2778,6 +3116,8 @@ struct IntrinsicJSFragment: Sendable { allStructs: [ExportedStruct] ) -> IntrinsicJSFragment { switch field.type { + case .jsValue: + preconditionFailure("Struct field of JSValue is not supported yet") case .string: return IntrinsicJSFragment( parameters: ["value"], @@ -3264,6 +3604,8 @@ struct IntrinsicJSFragment: Sendable { allStructs: [ExportedStruct] ) -> IntrinsicJSFragment { switch field.type { + case .jsValue: + preconditionFailure("Struct field of JSValue is not supported yet") case .string: return IntrinsicJSFragment( parameters: [], diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index a9812e2e0..0d4a78d3e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -149,7 +149,7 @@ public enum JSOptionalKind: String, Codable, Equatable, Hashable, Sendable { } 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 nullable(BridgeType, JSOptionalKind) indirect case array(BridgeType) @@ -905,6 +905,8 @@ extension BridgeType { self = .string case "Bool": self = .bool + case "JSValue": + self = .jsValue case "Void": self = .void case "JSObject": @@ -929,6 +931,7 @@ 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 @@ -979,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): diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index e2c7d00f0..c06ba94aa 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -706,8 +706,8 @@ export class TypeProcessor { "string": "String", "boolean": "Bool", "void": "Void", - "any": "JSObject", - "unknown": "JSObject", + "any": "JSValue", + "unknown": "JSValue", "null": "Void", "undefined": "Void", "bigint": "Int", @@ -716,12 +716,11 @@ 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); 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 index 2413c56af..f81a2ce07 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -38,7 +38,7 @@ exports[`ts2swift > snapshots Swift output for Async.d.ts > Async 1`] = ` @JSFunction func asyncRoundTripDouble(_ v: Double) throws(JSException) -> JSPromise -@JSFunction func asyncRoundTripJSObject(_ v: JSObject) throws(JSException) -> JSPromise +@JSFunction func asyncRoundTripJSObject(_ v: JSValue) throws(JSException) -> JSPromise " `; @@ -54,8 +54,8 @@ exports[`ts2swift > snapshots Swift output for Interface.d.ts > Interface 1`] = @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 + @JSFunction func animate(_ keyframes: JSValue, _ options: JSValue) throws(JSException) -> JSValue + @JSFunction func getAnimations(_ options: JSValue) throws(JSException) -> JSValue } " `; @@ -117,11 +117,11 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func createDatabaseConnection(_ config: JSObject) throws(JSException) -> DatabaseConnection +@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) -> JSObject + @JSFunction func execute(_ query: String) throws(JSException) -> JSValue @JSGetter var isConnected: Bool @JSGetter var connectionTimeout: Double @JSSetter func setConnectionTimeout(_ value: Double) throws(JSException) @@ -131,20 +131,33 @@ exports[`ts2swift > snapshots Swift output for MultipleImportedTypes.d.ts > Mult @JSClass struct Logger { @JSFunction func log(_ message: String) throws(JSException) -> Void - @JSFunction func error(_ message: String, _ error: JSObject) 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) -> JSObject - @JSFunction func set(_ key: String, _ value: JSObject) throws(JSException) -> Void + @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. @@ -301,7 +314,7 @@ exports[`ts2swift > snapshots Swift output for TS2SkeletonLike.d.ts > TS2Skeleto @JSFunction func createCodeGenerator(_ format: String) throws(JSException) -> CodeGenerator @JSClass struct CodeGenerator { - @JSFunction func generate(_ input: JSObject) throws(JSException) -> String + @JSFunction func generate(_ input: JSValue) throws(JSException) -> String @JSGetter var outputFormat: String } " 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/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift new file mode 100644 index 000000000..84251f6b3 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift @@ -0,0 +1,32 @@ +@JS func roundTripJSValue(_ value: JSValue) -> JSValue { + return value +} + +@JS func roundTripOptionalJSValue(_ value: JSValue?) -> JSValue? { + return value +} + +@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 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..d10d673d4 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json @@ -0,0 +1,273 @@ +{ + "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" + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "jsEchoJSValue", + "parameters" : [ + { + "name" : "value", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "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..3a3be5079 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift @@ -0,0 +1,149 @@ +@_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_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() +} \ No newline at end of file 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..9e2a85ac7 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts @@ -0,0 +1,37 @@ +// 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; +} +export type Imports = { + jsEchoJSValue(value: 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..f272b0ff0 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -0,0 +1,456 @@ +// 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 = 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); + } + } + }, + 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; + }, + }; + _exports = exports; + return exports; + }, + } +} \ No newline at end of file diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index e337124ee..e385a3c60 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -349,6 +349,92 @@ extension JSObject: _BridgedSwiftStackType { } } +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. @@ -1253,6 +1339,61 @@ 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: _BridgedSwiftProtocolWrapper { // MARK: ExportSwift diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 007f0b265..345f5dbcf 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -52,6 +52,14 @@ func runJsWorks() -> Void return v } +@JS func roundTripJSValue(v: JSValue) -> JSValue { + return v +} + +@JS func roundTripOptionalJSValue(v: JSValue?) -> JSValue? { + return v +} + @JSClass struct Foo { @JSGetter var value: String @JSFunction init(_ value: String) throws(JSException) diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index eaddcea1c..358f0501d 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -18,6 +18,8 @@ @JSFunction func jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr +@JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue + @JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void @JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double @@ -75,4 +77,4 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @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 c8f428934..ee9f97508 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -3420,6 +3420,28 @@ 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_makeImportedFoo") @_cdecl("bjs_makeImportedFoo") public func _bjs_makeImportedFoo(_ valueBytes: Int32, _ valueLength: Int32) -> Int32 { @@ -7929,19 +7951,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) @@ -8050,6 +8072,24 @@ func _$jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSE return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() } +#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_jsThrowOrVoid") fileprivate func bjs_jsThrowOrVoid(_ shouldThrow: Int32) -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 0cb32079a..e2877ee76 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -5275,6 +5275,66 @@ } } }, + { + "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_makeImportedFoo", "effects" : { @@ -12174,6 +12234,24 @@ } } }, + { + "name" : "jsRoundTripJSValue", + "parameters" : [ + { + "name" : "v", + "type" : { + "jsValue" : { + + } + } + } + ], + "returnType" : { + "jsValue" : { + + } + } + }, { "name" : "jsThrowOrVoid", "parameters" : [ @@ -12314,7 +12392,7 @@ "from" : "global", "name" : "globalObject1", "type" : { - "jsObject" : { + "jsValue" : { } } 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 c4ab0c2e0..460297133 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -55,6 +55,24 @@ 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 testRoundTripFeatureFlag() throws { for v in [FeatureFlag.foo, .bar] { try XCTAssertEqual(jsRoundTripFeatureFlag(v), v) diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index 42bca7401..03ecb5b39 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -4,6 +4,8 @@ export function jsRoundTripBool(v: boolean): boolean export function jsRoundTripString(v: string): string export function jsRoundTripOptionalNumberNull(v: number | null): number | null export function jsRoundTripOptionalNumberUndefined(v: number | undefined): number | undefined +export type JSValue = any +export function jsRoundTripJSValue(v: JSValue): JSValue export function jsThrowOrVoid(shouldThrow: boolean): void export function jsThrowOrNumber(shouldThrow: boolean): number export function jsThrowOrBool(shouldThrow: boolean): boolean diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index dc904579d..6a8dd58a2 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -52,6 +52,9 @@ export async function setupOptions(options, context) { "jsRoundTripOptionalNumberUndefined": (v) => { return v === undefined ? undefined : v; }, + "jsRoundTripJSValue": (v) => { + return v; + }, "jsThrowOrVoid": (shouldThrow) => { if (shouldThrow) { throw new Error("TestError"); @@ -78,6 +81,9 @@ export async function setupOptions(options, context) { "jsRoundTripFeatureFlag": (flag) => { return flag; }, + "jsEchoJSValue": (v) => { + return v; + }, "$jsWeirdFunction": () => { return 42; }, @@ -464,6 +470,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"); From dcc148fd307c7619fa9857b50e0bdfba1487a517 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Tue, 27 Jan 2026 21:09:33 +0700 Subject: [PATCH 26/34] BridgeJS: Support all missing types as associated values in exported enums --- Benchmarks/Sources/Generated/BridgeJS.swift | 22 +- .../Sources/BridgeJSCore/ExportSwift.swift | 4 +- .../BridgeJSCore/SwiftToSkeleton.swift | 10 +- .../Sources/BridgeJSLink/BridgeJSLink.swift | 29 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 770 ++++----- .../MacroSwift/EnumAssociatedValue.swift | 63 + .../EnumAssociatedValue.json | 557 +++++++ .../EnumAssociatedValue.swift | 506 +++++- .../BridgeJSCodegenTests/Protocol.swift | 4 +- .../StaticFunctions.Global.swift | 4 +- .../StaticFunctions.swift | 4 +- .../BridgeJSCodegenTests/SwiftClosure.swift | 10 +- .../BridgeJSLinkTests/ArrayTypes.js | 24 +- .../__Snapshots__/BridgeJSLinkTests/Async.js | 4 +- .../BridgeJSLinkTests/DefaultParameters.js | 4 +- .../EnumAssociatedValue.d.ts | 91 ++ .../BridgeJSLinkTests/EnumAssociatedValue.js | 1446 +++++++++++------ .../BridgeJSLinkTests/EnumCase.js | 4 +- .../BridgeJSLinkTests/EnumNamespace.Global.js | 4 +- .../BridgeJSLinkTests/EnumNamespace.js | 4 +- .../BridgeJSLinkTests/EnumRawType.js | 4 +- .../BridgeJSLinkTests/GlobalGetter.js | 4 +- .../BridgeJSLinkTests/GlobalThisImports.js | 4 +- .../ImportedTypeInExportedInterface.js | 4 +- .../BridgeJSLinkTests/InvalidPropertyNames.js | 4 +- .../BridgeJSLinkTests/JSClass.js | 4 +- .../JSClassStaticFunctions.js | 4 +- .../BridgeJSLinkTests/JSValue.js | 4 +- .../BridgeJSLinkTests/MixedGlobal.js | 4 +- .../BridgeJSLinkTests/MixedModules.js | 4 +- .../BridgeJSLinkTests/MixedPrivate.js | 4 +- .../BridgeJSLinkTests/Namespaces.Global.js | 4 +- .../BridgeJSLinkTests/Namespaces.js | 4 +- .../BridgeJSLinkTests/Optionals.js | 4 +- .../BridgeJSLinkTests/PrimitiveParameters.js | 4 +- .../BridgeJSLinkTests/PrimitiveReturn.js | 4 +- .../BridgeJSLinkTests/PropertyTypes.js | 4 +- .../BridgeJSLinkTests/Protocol.js | 95 +- .../StaticFunctions.Global.js | 91 +- .../BridgeJSLinkTests/StaticFunctions.js | 91 +- .../StaticProperties.Global.js | 4 +- .../BridgeJSLinkTests/StaticProperties.js | 4 +- .../BridgeJSLinkTests/StringParameter.js | 4 +- .../BridgeJSLinkTests/StringReturn.js | 4 +- .../BridgeJSLinkTests/SwiftClass.js | 4 +- .../BridgeJSLinkTests/SwiftClosure.js | 157 +- .../BridgeJSLinkTests/SwiftClosureImports.js | 4 +- .../BridgeJSLinkTests/SwiftStruct.js | 16 +- .../BridgeJSLinkTests/SwiftStructImports.js | 4 +- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 4 +- .../BridgeJSLinkTests/UnsafePointer.js | 4 +- .../VoidParameterVoidReturn.js | 4 +- .../Exporting-Swift/Exporting-Swift-Enum.md | 9 +- .../BridgeJSRuntimeTests/ExportAPITests.swift | 54 + .../Generated/BridgeJS.swift | 416 ++++- .../Generated/JavaScript/BridgeJS.json | 482 ++++++ Tests/prelude.mjs | 125 +- 57 files changed, 3911 insertions(+), 1297 deletions(-) diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 1a413268d..5a480694c 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.swift @@ -64,20 +64,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .flag(let param0): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .rate(let param0): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .precise(let param0): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) case .info: _swift_js_push_tag(Int32(5)) } @@ -161,29 +161,28 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .error(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .location(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .coordinates(let param0, let param1, let param2): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(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_tag(Int32(5)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() @@ -193,6 +192,7 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { param6.bridgeJSLowerStackReturn() param7.bridgeJSLowerStackReturn() param8.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(5)) case .info: _swift_js_push_tag(Int32(6)) } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 1137343b0..51ff91695 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1221,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 diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index d32d85f55..39e3090cd 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -1428,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 .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: @@ -1447,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" ) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 4695f3283..27ef60760 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -246,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) = [];", @@ -388,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) {") @@ -1059,6 +1059,18 @@ public struct BridgeJSLink { _ = fragment.printCode([structDef.name], structScope, structPrinter, structCleanup) 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)) @@ -1094,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 { @@ -1109,18 +1119,19 @@ 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 ) @@ -1151,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() @@ -1616,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: diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ef72cf6f6..1547d63a4 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -571,7 +571,7 @@ 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] } @@ -652,7 +652,7 @@ 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("}") @@ -678,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 { @@ -886,8 +885,10 @@ 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 { @@ -896,7 +897,7 @@ struct IntrinsicJSFragment: Sendable { 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("}") @@ -1233,7 +1234,7 @@ 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 [] } @@ -1304,7 +1305,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)") @@ -1632,7 +1633,7 @@ 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 [] @@ -1857,7 +1858,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] } @@ -2001,13 +2002,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: {") @@ -2020,13 +2022,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() @@ -2058,10 +2072,10 @@ 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() @@ -2228,62 +2242,77 @@ 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 .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) = \(kind.presenceCheck(value: value));") + return associatedValueOptionalPushPayload(wrappedType: wrappedType, kind: kind) + default: + return try! stackLowerFragment(elementType: type) + } + } - switch wrappedType { + 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);") @@ -2293,8 +2322,12 @@ struct IntrinsicJSFragment: Sendable { 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( + "\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" + ) + printer.write( + "\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);" + ) printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") } printer.write("} else {") @@ -2303,107 +2336,169 @@ struct IntrinsicJSFragment: Sendable { 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 .nullable(let wrappedType, let kind): - return IntrinsicJSFragment( - parameters: [], - printCode: { arguments, scope, printer, cleanup in - let optVar = scope.variable("optional") - let isSomeVar = scope.variable("isSome") + 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 { @@ -2412,23 +2507,16 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(optVar) = undefined;") } } - printer.write("} else {") - printer.indent { - printer.write("\(optVar) = \(kind.absenceLiteral);") - } - 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 { @@ -2489,7 +2577,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 { @@ -2523,7 +2611,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));") @@ -2536,7 +2624,7 @@ struct IntrinsicJSFragment: Sendable { ) } - private static func arrayElementRaiseFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { + private static func stackLiftFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { case .jsValue: throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") @@ -2592,7 +2680,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] } @@ -2617,6 +2705,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: [], @@ -2632,11 +2738,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] } @@ -2648,7 +2752,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] } ) @@ -2682,7 +2786,7 @@ struct IntrinsicJSFragment: Sendable { } } - private static func arrayElementLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { + private static func stackLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { case .jsValue: throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") @@ -2693,7 +2797,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));") @@ -2739,8 +2843,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 [] } @@ -2762,7 +2868,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));" ) @@ -2772,6 +2880,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"], @@ -2790,7 +2914,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)(); }") @@ -2867,7 +2991,7 @@ struct IntrinsicJSFragment: Sendable { } 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);") @@ -2898,7 +3022,7 @@ struct IntrinsicJSFragment: Sendable { 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 @@ -3065,13 +3189,11 @@ struct IntrinsicJSFragment: Sendable { let methodScope = scope.makeChildScope() 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) @@ -3079,7 +3201,6 @@ struct IntrinsicJSFragment: Sendable { 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);") @@ -3118,61 +3239,6 @@ struct IntrinsicJSFragment: Sendable { switch field.type { case .jsValue: preconditionFailure("Struct field of JSValue is not supported yet") - 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 [] - } - ) case .jsObject: return IntrinsicJSFragment( parameters: ["value"], @@ -3233,7 +3299,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));" ) @@ -3326,7 +3394,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));") @@ -3369,7 +3439,6 @@ struct IntrinsicJSFragment: Sendable { cleanup.write("}") return [idVar] } else { - // Handle optional primitive types using helper switch wrappedType { case .int, .uint: pushOptionalPrimitive( @@ -3430,7 +3499,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, @@ -3464,83 +3532,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( @@ -3550,8 +3541,8 @@ struct IntrinsicJSFragment: Sendable { return [] } ) - case .array(let elementType): - return try! arrayLower(elementType: elementType) + default: + return try! stackLowerFragment(elementType: field.type) } } @@ -3606,60 +3597,6 @@ struct IntrinsicJSFragment: Sendable { switch field.type { case .jsValue: preconditionFailure("Struct field of JSValue is not supported yet") - 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 .nullable(let wrappedType, let kind): return IntrinsicJSFragment( parameters: [], @@ -3676,7 +3613,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( @@ -3715,65 +3652,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: [], @@ -3797,18 +3675,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( @@ -3818,8 +3684,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/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/EnumAssociatedValue.swift index efb6cd1b1..a0e6cbfeb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/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/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json index ba9ee9324..3c624fa12 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.json @@ -1,7 +1,16 @@ { "exported" : { "classes" : [ + { + "methods" : [ + + ], + "name" : "User", + "properties" : [ + ], + "swiftCallName" : "User" + } ], "enums" : [ { @@ -492,6 +501,346 @@ ], "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, @@ -853,13 +1202,221 @@ "_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" diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift index 0854cba74..26454a2a7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift @@ -55,20 +55,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .flag(let param0): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .rate(let param0): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .precise(let param0): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) case .info: _swift_js_push_tag(Int32(5)) } @@ -145,24 +145,23 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .error(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .coordinates(let param0, let param1, let param2): - _swift_js_push_tag(Int32(3)) 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): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() @@ -172,6 +171,7 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { param6.bridgeJSLowerStackReturn() param7.bridgeJSLowerStackReturn() param8.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) case .info: _swift_js_push_tag(Int32(5)) } @@ -224,17 +224,17 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) } } } @@ -278,12 +278,12 @@ extension NetworkingResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) } } } @@ -358,14 +358,13 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { @_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 { __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): - _swift_js_push_tag(Int32(1)) let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { __bjs_unwrapped_param0.bridgeJSLowerStackReturn() @@ -376,8 +375,8 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { __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): - _swift_js_push_tag(Int32(2)) let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { __bjs_unwrapped_param0.bridgeJSLowerStackReturn() @@ -393,10 +392,388 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { __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 { @@ -527,4 +904,95 @@ public func _bjs_compareAPIResults(_ result1IsSome: Int32, _ result1CaseId: Int3 #else fatalError("Only available on WebAssembly") #endif -} \ No newline at end of file +} + +@_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/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index 21178521d..3536b53cb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -400,11 +400,11 @@ extension Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift index ed6cb98c0..3e5b40def 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.Global.swift @@ -82,11 +82,11 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift index ed6cb98c0..3e5b40def 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/StaticFunctions.swift @@ -82,11 +82,11 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift index df6046693..94351dbdf 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.swift @@ -730,20 +730,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .flag(let param0): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .rate(let param0): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .precise(let param0): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) case .info: _swift_js_push_tag(Int32(5)) } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 491fc610e..4610d03ba 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.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 = []; @@ -98,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); @@ -382,9 +382,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); @@ -446,9 +446,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); @@ -610,8 +610,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); @@ -766,9 +766,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); @@ -805,7 +805,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(); @@ -833,7 +833,7 @@ 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(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index d5a195430..0aa9148c1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.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 = []; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index bc669993b..754c47b0a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.d.ts index 20962c388..9ab117011 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.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 index 6eb4b3985..123ba56fa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -14,78 +14,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 const ComplexResultValues = { Tag: { Success: 0, @@ -96,127 +24,6 @@ export const ComplexResultValues = { 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, @@ -224,124 +31,12 @@ export const ResultValues = { 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, @@ -349,135 +44,46 @@ export const APIOptionalResultValues = { Status: 2, }, }; +export const PrecisionValues = { + Rough: 0.1, + Fine: 0.001, +}; -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 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; @@ -493,7 +99,7 @@ export async function createInstantiator(options, swift) { let tmpRetOptionalFloat; let tmpRetOptionalDouble; let tmpRetOptionalHeapObject; - let tmpRetTag; + let tmpRetTag = []; let tmpRetStrings = []; let tmpRetInts = []; let tmpRetF32s = []; @@ -509,6 +115,771 @@ export async function createInstantiator(options, swift) { 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 { /** @@ -545,7 +916,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); @@ -586,6 +957,17 @@ export async function createInstantiator(options, swift) { 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; @@ -676,34 +1058,80 @@ export async function createInstantiator(options, swift) { 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; - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); + 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, textEncoder, swift); + const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); enumHelpers.ComplexResult = ComplexResultHelpers; - const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); + const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); enumHelpers.Result = ResultHelpers; - const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); + const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); enumHelpers.NetworkingResult = NetworkingResultHelpers; - const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, textEncoder, swift); + const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); 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 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); @@ -711,13 +1139,13 @@ export async function createInstantiator(options, swift) { }, getResult: function bjs_getResult() { instance.exports.bjs_getResult(); - const ret = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + 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, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -730,12 +1158,13 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalAPIResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + optResult = enumHelpers.APIResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -747,13 +1176,13 @@ export async function createInstantiator(options, swift) { }, getComplexResult: function bjs_getComplexResult() { instance.exports.bjs_getComplexResult(); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + 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, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -766,12 +1195,13 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalComplexResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.ComplexResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + optResult = enumHelpers.ComplexResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -785,12 +1215,13 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalUtilitiesResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.Result.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + optResult = enumHelpers.Result.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -804,12 +1235,13 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalNetworkingResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.NetworkingResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + optResult = enumHelpers.NetworkingResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -823,12 +1255,13 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalAPIOptionalResult(+isSome, isSome ? resultCaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIOptionalResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + optResult = enumHelpers.APIOptionalResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -849,20 +1282,107 @@ export async function createInstantiator(options, swift) { result2Cleanup = enumResult1.cleanup; } instance.exports.bjs_compareAPIResults(+isSome, isSome ? result1CaseId : 0, +isSome1, isSome1 ? result2CaseId : 0); - const isNull = (tmpRetTag === -1); + const tag = tmpRetTag.pop(); + const isNull = (tag === -1); let optResult; if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIOptionalResult.lift(tmpRetTag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s); + 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, }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 874b4c4c0..9ca596a6e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.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 = []; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index 78f08ffb5..a7a2c4b98 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index cddeac767..b195b6945 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index 315b74262..c906f27ff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.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 = []; @@ -146,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index b5053b266..ac6170b08 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.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 = []; @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 0d9eb79c3..dc2220715 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.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 = []; @@ -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/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 11aa2b3d8..efcbbe2d6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.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 = []; @@ -135,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index 6a11003b3..d64ff7e96 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.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 = []; @@ -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/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index b60a698b4..096e3a345 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.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 = []; @@ -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/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 214a32294..cacaa87a3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.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 = []; @@ -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/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index f272b0ff0..2bd696c3d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.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 = []; @@ -160,7 +160,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/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index e1345f94b..4ac3b11b7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.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 = []; @@ -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/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 0703be789..9eb55f30b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.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 = []; @@ -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/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 0cc377f4c..e81a95669 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.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 = []; @@ -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/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index 630651aea..c8d0b935e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.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 = []; @@ -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/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index b3073da70..bb2c93649 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.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 = []; @@ -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/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 27e9c3c6b..341fcd966 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.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 = []; @@ -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/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index 98f50e850..2d754a5c3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.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 = []; @@ -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/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index e68e4e6a2..f348869b2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.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 = []; @@ -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/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index 7bf565105..7be6cd924 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.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 = []; @@ -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/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index ce9065ac4..7c20130b3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.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 = []; @@ -98,6 +58,45 @@ export async function createInstantiator(options, swift) { 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) } @@ -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/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index b79c6ebf4..391c7167e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.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 = []; @@ -85,6 +45,45 @@ export async function createInstantiator(options, swift) { 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) } @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index 2f240c428..b38668c57 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.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 = []; @@ -85,6 +45,45 @@ export async function createInstantiator(options, swift) { 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) } @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js index 15edf8c60..293ae4f7d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index d90e96f0e..27e3df464 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index fc67c0027..e57c5153d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.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 = []; @@ -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/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index 50edf3b06..74d140236 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.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 = []; @@ -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/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index f3d5cafcb..27398d2a4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.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 = []; @@ -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/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 59512a7eb..ff5af72f9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.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 = []; @@ -136,6 +64,77 @@ export async function createInstantiator(options, swift) { 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); @@ -423,7 +422,7 @@ 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"); @@ -685,7 +684,7 @@ export async function createInstantiator(options, swift) { 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; } @@ -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) } @@ -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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 145eeb756..52e12ef7c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.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 = []; @@ -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/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index f389900dc..adbe18856 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.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 = []; @@ -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 }; } }); }; @@ -328,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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index afed321ce..8f90491df 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 8a1c49647..2e2f8bf6a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.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 = []; @@ -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/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 61f6c6cf3..bbeeffa0d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.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 = []; @@ -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); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 053c55672..45374093b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.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 = []; @@ -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/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/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 345f5dbcf..fe73ea6fb 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -586,6 +586,22 @@ typealias OptionalAge = Int? return value } +@JS enum TypedPayloadResult { + case precision(Precision) + case direction(Direction) + case optPrecision(Precision?) + case optDirection(Direction?) + case empty +} + +@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult { + return result +} + +@JS func roundTripOptionalTypedPayloadResult(_ result: TypedPayloadResult?) -> TypedPayloadResult? { + return result +} + @JS func compareAPIResults(_ r1: APIResult?, _ r2: APIResult?) -> String { let r1Str: String switch r1 { @@ -616,6 +632,44 @@ typealias OptionalAge = Int? return result } +@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 roundTripAllTypesResult(_ result: AllTypesResult) -> AllTypesResult { + return result +} + +@JS func roundTripOptionalAllTypesResult(_ result: AllTypesResult?) -> AllTypesResult? { + return 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 { + return result +} + +@JS func roundTripOptionalPayloadResultOpt(_ result: OptionalAllTypesResult?) -> OptionalAllTypesResult? { + return result +} + @JS func roundTripOptionalClass(value: Greeter?) -> Greeter? { return value } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index ee9f97508..0e06c7edc 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -1561,20 +1561,20 @@ extension APIResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .flag(let param0): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .rate(let param0): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .precise(let param0): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(4)) case .info: _swift_js_push_tag(Int32(5)) } @@ -1658,29 +1658,28 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .error(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .location(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(3)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(3)) case .coordinates(let param0, let param1, let param2): - _swift_js_push_tag(Int32(4)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(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_tag(Int32(5)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() @@ -1690,6 +1689,7 @@ extension ComplexResult: _BridgedSwiftAssociatedValueEnum { param6.bridgeJSLowerStackReturn() param7.bridgeJSLowerStackReturn() param8.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(5)) case .info: _swift_js_push_tag(Int32(6)) } @@ -1742,17 +1742,17 @@ extension Utilities.Result: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) case .status(let param0, let param1, let param2): - _swift_js_push_tag(Int32(2)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() param2.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(2)) } } } @@ -1796,12 +1796,324 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { switch self { case .success(let param0): - _swift_js_push_tag(Int32(0)) param0.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(0)) case .failure(let param0, let param1): - _swift_js_push_tag(Int32(1)) param0.bridgeJSLowerStackReturn() param1.bridgeJSLowerStackReturn() + _swift_js_push_tag(Int32(1)) + } + } +} + +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 { + __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(Address.bridgeJSLiftParameter()) + case 1: + return .classPayload(Greeter.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 .jsClassPayload(Foo(unsafelyWrapping: JSObject.bridgeJSLiftParameter())) + case 6: + 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 .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 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)") + } + } + + // 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 .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) + } + } + + @_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 .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)) } } } @@ -1876,14 +2188,13 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { @_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 { __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): - _swift_js_push_tag(Int32(1)) let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { __bjs_unwrapped_param0.bridgeJSLowerStackReturn() @@ -1894,8 +2205,8 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { __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): - _swift_js_push_tag(Int32(2)) let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { __bjs_unwrapped_param0.bridgeJSLowerStackReturn() @@ -1911,6 +2222,7 @@ extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { __bjs_unwrapped_param2.bridgeJSLowerStackReturn() } _swift_js_push_i32(__bjs_isSome_param2 ? 1 : 0) + _swift_js_push_tag(Int32(2)) } } } @@ -4451,6 +4763,28 @@ public func _bjs_roundTripOptionalAPIResult(_ valueIsSome: Int32, _ valueCaseId: #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_compareAPIResults") @_cdecl("bjs_compareAPIResults") public func _bjs_compareAPIResults(_ r1IsSome: Int32, _ r1CaseId: Int32, _ r2IsSome: Int32, _ r2CaseId: Int32) -> Void { @@ -4475,6 +4809,50 @@ public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultC #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_roundTripOptionalClass") @_cdecl("bjs_roundTripOptionalClass") public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index e2877ee76..41d2ccf89 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -4357,6 +4357,308 @@ "swiftCallName" : "API.NetworkingResult", "tsFullPath" : "API.NetworkingResult" }, + { + "cases" : [ + { + "associatedValues" : [ + { + "type" : { + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" + } + } + } + ], + "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" : [ + { + "type" : { + "swiftStruct" : { + "_0" : "Address" + } + } + } + ], + "name" : "structPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + ], + "name" : "classPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "jsObject" : { + + } + } + } + ], + "name" : "jsObjectPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + } + } + ], + "name" : "nestedEnum" + }, + { + "associatedValues" : [ + { + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "name" : "arrayPayload" + }, + { + "associatedValues" : [ + { + "type" : { + "jsObject" : { + "_0" : "Foo" + } + } + } + ], + "name" : "jsClassPayload" + }, + { + "associatedValues" : [ + + ], + "name" : "empty" + } + ], + "emitStyle" : "const", + "name" : "AllTypesResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "AllTypesResult", + "tsFullPath" : "AllTypesResult" + }, + { + "cases" : [ + { + "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" + } + ], + "emitStyle" : "const", + "name" : "OptionalAllTypesResult", + "staticMethods" : [ + + ], + "staticProperties" : [ + + ], + "swiftCallName" : "OptionalAllTypesResult", + "tsFullPath" : "OptionalAllTypesResult" + }, { "cases" : [ { @@ -7557,6 +7859,66 @@ } } }, + { + "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_compareAPIResults", "effects" : { @@ -7636,6 +7998,126 @@ } } }, + { + "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" + } + } + }, { "abiName" : "bjs_roundTripOptionalClass", "effects" : { diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 6a8dd58a2..cc21a864a 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -1,7 +1,7 @@ // @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'; /** @type {import('../.build/plugins/PackageToJS/outputs/PackageTests/test.d.ts').SetupOptionsFn} */ @@ -781,6 +781,129 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { 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); + + // Optional TypedPayloadResult roundtrip + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_precision), tpr_precision); + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_direction), tpr_direction); + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionSome), tpr_optPrecisionSome); + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionNull), tpr_optPrecisionNull); + assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_empty), tpr_empty); + assert.equal(exports.roundTripOptionalTypedPayloadResult(null), null); + + // 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); + + // Optional AllTypesResult roundtrip + assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_struct), atr_struct); + assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_array), atr_array); + 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); + assert.equal(exports.MathUtils.add(2147483647, 0), 2147483647); assert.equal(exports.StaticCalculator.roundtrip(42), 42); assert.equal(StaticCalculatorValues.Scientific, 0); From 43a05d9ad7e77801f6dc1f4a163bb126edcc8460 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Wed, 4 Feb 2026 09:50:08 +0100 Subject: [PATCH 27/34] BridgeJS: Few more array import tests BridgeJS: Array import --- .../Sources/BridgeJSCore/ImportTS.swift | 88 +-- .../Sources/BridgeJSLink/BridgeJSLink.swift | 8 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 56 +- .../TS2Swift/JavaScript/src/processor.js | 11 +- .../test/__snapshots__/ts2swift.test.js.snap | 12 +- .../test/fixtures/ArrayParameter.d.ts | 20 +- .../Inputs/MacroSwift/ArrayTypes.swift | 6 + .../Inputs/MacroSwift/ImportArray.swift | 2 + .../BridgeJSCodegenTests/ArrayTypes.json | 115 +++ .../BridgeJSCodegenTests/ArrayTypes.swift | 88 +++ .../BridgeJSCodegenTests/ImportArray.json | 62 ++ .../BridgeJSCodegenTests/ImportArray.swift | 34 + .../BridgeJSLinkTests/ArrayTypes.d.ts | 5 + .../BridgeJSLinkTests/ArrayTypes.js | 89 +++ .../BridgeJSLinkTests/ImportArray.d.ts | 19 + .../BridgeJSLinkTests/ImportArray.js | 257 +++++++ .../JavaScriptKit/BridgeJSIntrinsics.swift | 23 +- .../Articles/BridgeJS/Supported-Types.md | 2 +- .../Generated/BridgeJS.Macros.swift | 10 + .../Generated/BridgeJS.swift | 407 +++++++++++ .../Generated/JavaScript/BridgeJS.json | 663 ++++++++++++++++-- .../BridgeJSRuntimeTests/ImportAPITests.swift | 61 ++ .../ImportArrayAPIs.swift | 17 + Tests/BridgeJSRuntimeTests/StructAPIs.swift | 25 + Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 6 + Tests/prelude.mjs | 50 ++ 26 files changed, 2011 insertions(+), 125 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ImportArray.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportArray.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js create mode 100644 Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 22e0ef162..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(), @@ -178,19 +204,15 @@ public struct ImportTS { rightParen: .rightParenToken() ) - let needsRetBinding: Bool - let liftingInfo = try returnType.liftingReturnInfo(context: context) - if liftingInfo.valueToLift == nil || returnType.usesSideChannelForOptionalReturn() { - // Void and side-channel returns don't need "let ret =" - needsRetBinding = false + if returnType == .void { + body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) + } 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 { - needsRetBinding = true - } - - if needsRetBinding { body.append("let ret = \(raw: callExpr)") - } else { - body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr))))) } // Add exception check for ImportTS context @@ -934,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: @@ -964,12 +981,7 @@ extension BridgeType { 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: []) } } @@ -1025,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: @@ -1053,12 +1060,7 @@ extension BridgeType { 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/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 27ef60760..7a5e02f2d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -2212,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 { diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 1547d63a4..410bce672 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -1895,14 +1895,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) } } @@ -1971,14 +1964,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) } } @@ -3215,11 +3201,10 @@ struct IntrinsicJSFragment: Sendable { // 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);") - } + let liftArgs = liftFragment.parameters.isEmpty ? [] : ["ret"] + let lifted = liftFragment.printCode(liftArgs, methodScope, printer, methodCleanup) + if let liftedValue = lifted.first { + printer.write("return \(liftedValue);") } } } @@ -3508,9 +3493,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);") diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index c06ba94aa..ef446af0f 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -663,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; @@ -727,7 +736,7 @@ export class TypeProcessor { 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 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 index f81a2ce07..6fdb79f78 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/__snapshots__/ts2swift.test.js.snap @@ -9,11 +9,17 @@ exports[`ts2swift > snapshots Swift output for ArrayParameter.d.ts > ArrayParame @_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit -@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void +@JSFunction func processNumbers(_ values: [Double]) throws(JSException) -> Void -@JSFunction func checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> Void +@JSFunction func getNumbers() throws(JSException) -> [Double] -@JSFunction func checkArray(_ a: JSObject) throws(JSException) -> Void +@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] " `; diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts index 59674e071..b5a099388 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/ArrayParameter.d.ts @@ -1,3 +1,17 @@ -export function checkArray(a: number[]): void; -export function checkArrayWithLength(a: number[], b: number): void; -export function checkArray(a: Array): void; +// 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/MacroSwift/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift index c1980cbc2..0cea90512 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/ArrayTypes.swift @@ -61,3 +61,9 @@ @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/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/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json index 8dde2cfb7..8eab0c059 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.json @@ -1158,6 +1158,121 @@ } } + }, + { + "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" : [ diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index c7c80c3b2..023caf21f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -581,4 +581,92 @@ func _$checkArrayWithLength(_ a: JSObject, _ b: Double) throws(JSException) -> V 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/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__/BridgeJSLinkTests/ArrayTypes.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts index 3316cd7c3..8dc76156b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.d.ts @@ -71,6 +71,11 @@ export type Exports = { 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.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 4610d03ba..6cca17cf6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -263,6 +263,95 @@ export async function createInstantiator(options, swift) { 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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts new file mode 100644 index 000000000..5d1e2c4dc --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.d.ts @@ -0,0 +1,19 @@ +// 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 = { + roundtrip(items: number[]): number[]; + logStrings(items: string[]): 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/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js new file mode 100644 index 000000000..daa601aed --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -0,0 +1,257 @@ +// 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.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; + } + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_roundtrip"] = function bjs_roundtrip() { + try { + 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); + } + } + TestModule["bjs_logStrings"] = function bjs_logStrings() { + try { + 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); + } + } + }, + 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/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index e385a3c60..349cecb91 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -2297,7 +2297,9 @@ extension _BridgedAsOptional where Wrapped: _BridgedSwiftStruct { // MARK: - Array Support -extension Array where Element: _BridgedSwiftStackType, Element.StackLiftResult == Element { +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] = [] @@ -2309,10 +2311,23 @@ extension Array where Element: _BridgedSwiftStackType, Element.StackLiftResult = return result } - @_spi(BridgeJS) public func bridgeJSLowerReturn() { - for elem in self { + @_spi(BridgeJS) public static func bridgeJSLiftReturn() -> [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(self.count)) + _swift_js_push_i32(Int32(array.count)) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() { + bridgeJSLowerReturn() } } 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/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index 358f0501d..9e05b3ae8 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -63,6 +63,16 @@ extension FeatureFlag: _BridgedSwiftEnumNoPayload, _BridgedSwiftRawValueEnum {} @JSFunction(jsName: "with-dashes") static func with_dashes() throws(JSException) -> StaticBox } +@JSFunction func jsRoundTripNumberArray(_ values: [Double]) throws(JSException) -> [Double] + +@JSFunction func jsRoundTripStringArray(_ values: [String]) throws(JSException) -> [String] + +@JSFunction func jsRoundTripBoolArray(_ values: [Bool]) throws(JSException) -> [Bool] + +@JSFunction func jsSumNumberArray(_ values: [Double]) throws(JSException) -> Double + +@JSFunction func jsCreateNumberArray() throws(JSException) -> [Double] + @JSFunction(from: .global) func parseInt(_ string: String) throws(JSException) -> Double @JSClass(from: .global) struct Animal { diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 0e06c7edc..5638d0442 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -3579,6 +3579,84 @@ fileprivate func _bjs_struct_lift_FooContainer() -> Int32 { } #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 { @@ -5913,6 +5991,43 @@ public func _bjs_roundTripFooContainer() -> Void { #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_arrayMembersSum") +@_cdecl("bjs_arrayMembersSum") +public func _bjs_arrayMembersSum() -> Int32 { + #if arch(wasm32) + 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_arrayMembersFirst") +@_cdecl("bjs_arrayMembersFirst") +public func _bjs_arrayMembersFirst() -> Void { + #if arch(wasm32) + 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") + #endif +} + @_expose(wasm, "bjs_Greeter_init") @_cdecl("bjs_Greeter_init") public func _bjs_Greeter_init(_ nameBytes: Int32, _ nameLength: Int32) -> UnsafeMutableRawPointer { @@ -8591,6 +8706,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 @@ -9022,6 +9226,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 diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 41d2ccf89..366115792 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -10917,6 +10917,112 @@ "_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" : [ @@ -12547,6 +12653,110 @@ } ], "swiftCallName" : "FooContainer" + }, + { + "methods" : [ + { + "abiName" : "bjs_ArrayMembers_sumValues", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "sumValues", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "abiName" : "bjs_ArrayMembers_firstString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "firstString", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "string" : { + + } + }, + "_1" : "null" + } + } + } + ], + "name" : "ArrayMembers", + "properties" : [ + { + "isReadonly" : true, + "isStatic" : false, + "name" : "ints", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "isReadonly" : true, + "isStatic" : false, + "name" : "optStrings", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "swiftCallName" : "ArrayMembers" } ] }, @@ -12850,70 +13060,185 @@ } }, { - "from" : "global", - "name" : "parseInt", + "name" : "jsRoundTripNumberArray", "parameters" : [ { - "name" : "string", + "name" : "values", "type" : { - "string" : { + "array" : { + "_0" : { + "double" : { + } + } } } } ], "returnType" : { - "double" : { - - } - } - } - ], - "globalGetters" : [ - { - "from" : "global", - "name" : "globalObject1", - "type" : { - "jsValue" : { + "array" : { + "_0" : { + "double" : { + } + } } } - } - ], - "types" : [ + }, { - "constructor" : { - "parameters" : [ - { - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "name" : "prefix", - "type" : { - "string" : { + "name" : "jsRoundTripStringArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + } } } } - ] - }, - "getters" : [ - { - "name" : "name", - "type" : { + } + ], + "returnType" : { + "array" : { + "_0" : { "string" : { } } - }, - { - "name" : "prefix", - "type" : { + } + } + }, + { + "name" : "jsRoundTripBoolArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "bool" : { + + } + } + } + } + }, + { + "name" : "jsSumNumberArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "double" : { + + } + } + }, + { + "name" : "jsCreateNumberArray", + "parameters" : [ + + ], + "returnType" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "from" : "global", + "name" : "parseInt", + "parameters" : [ + { + "name" : "string", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "double" : { + + } + } + } + ], + "globalGetters" : [ + { + "from" : "global", + "name" : "globalObject1", + "type" : { + "jsValue" : { + + } + } + } + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "name" : "prefix", + "type" : { + "string" : { + + } + } + } + ] + }, + "getters" : [ + { + "name" : "name", + "type" : { + "string" : { + + } + } + }, + { + "name" : "prefix", + "type" : { "string" : { } @@ -13203,6 +13528,258 @@ } ] }, + { + "functions" : [ + { + "name" : "jsRoundTripIntArray", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "jsArrayLength", + "parameters" : [ + { + "name" : "items", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "int" : { + + } + } + }, + { + "name" : "makeArrayHost", + "parameters" : [ + { + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "jsObject" : { + "_0" : "ArrayHost" + } + } + } + ], + "types" : [ + { + "constructor" : { + "parameters" : [ + { + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ] + }, + "getters" : [ + { + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "methods" : [ + { + "name" : "concatNumbers", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "concatLabels", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + }, + { + "name" : "firstLabel", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "returnType" : { + "string" : { + + } + } + } + ], + "name" : "ArrayHost", + "setters" : [ + { + "functionName" : "numbers_set", + "name" : "numbers", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "functionName" : "labels_set", + "name" : "labels", + "type" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } + } + ], + "staticMethods" : [ + + ] + } + ] + }, { "functions" : [ { diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index 460297133..a465c57b4 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -152,6 +152,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 } @@ -178,4 +205,38 @@ class ImportAPITests: XCTestCase { let dashed = try StaticBox.with_dashes() XCTAssertEqual(try dashed.value(), 7) } + + func testRoundTripNumberArray() throws { + let input: [Double] = [1.0, 2.5, 3.0, -4.5] + let result = try jsRoundTripNumberArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try jsRoundTripNumberArray([]), []) + XCTAssertEqual(try jsRoundTripNumberArray([42.0]), [42.0]) + } + + func testRoundTripStringArray() throws { + let input = ["Hello", "World", "🎉"] + let result = try jsRoundTripStringArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try jsRoundTripStringArray([]), []) + XCTAssertEqual(try jsRoundTripStringArray(["", "a", ""]), ["", "a", ""]) + } + + func testRoundTripBoolArray() throws { + let input = [true, false, true, false] + let result = try jsRoundTripBoolArray(input) + XCTAssertEqual(result, input) + XCTAssertEqual(try jsRoundTripBoolArray([]), []) + } + + func testSumNumberArray() throws { + XCTAssertEqual(try jsSumNumberArray([1.0, 2.0, 3.0, 4.0]), 10.0) + XCTAssertEqual(try jsSumNumberArray([]), 0.0) + XCTAssertEqual(try jsSumNumberArray([42.0]), 42.0) + } + + func testCreateNumberArray() throws { + let result = try jsCreateNumberArray() + XCTAssertEqual(result, [1.0, 2.0, 3.0, 4.0, 5.0]) + } } diff --git a/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift b/Tests/BridgeJSRuntimeTests/ImportArrayAPIs.swift 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/StructAPIs.swift b/Tests/BridgeJSRuntimeTests/StructAPIs.swift index c7de5d137..49869e0f5 100644 --- a/Tests/BridgeJSRuntimeTests/StructAPIs.swift +++ b/Tests/BridgeJSRuntimeTests/StructAPIs.swift @@ -234,3 +234,28 @@ @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 03ecb5b39..b7dc6c48d 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -44,3 +44,9 @@ export class StaticBox { static makeDefault(): StaticBox; static "with-dashes"(): StaticBox; } + +export function jsRoundTripNumberArray(values: number[]): number[]; +export function jsRoundTripStringArray(values: string[]): string[]; +export function jsRoundTripBoolArray(values: boolean[]): boolean[]; +export function jsSumNumberArray(values: number[]): number; +export function jsCreateNumberArray(): number[]; diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index cc21a864a..e8f0b081c 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -33,6 +33,22 @@ export async function setupOptions(options, context) { return { ...options, getImports: (importsContext) => { + const ArrayHost = class { + constructor(numbers, labels) { + this.numbers = numbers; + this.labels = labels; + } + concatNumbers(values) { + return [...this.numbers, ...values]; + } + concatLabels(values) { + return [...this.labels, ...values]; + } + firstLabel(values) { + const merged = [...values, ...this.labels]; + return merged.length > 0 ? merged[0] : ""; + } + }; return { "jsRoundTripVoid": () => { return; @@ -55,6 +71,12 @@ export async function setupOptions(options, context) { "jsRoundTripJSValue": (v) => { return v; }, + "jsRoundTripIntArray": (items) => { + return items; + }, + "jsArrayLength": (items) => { + return items.length; + }, "jsThrowOrVoid": (shouldThrow) => { if (shouldThrow) { throw new Error("TestError"); @@ -87,6 +109,10 @@ export async function setupOptions(options, context) { "$jsWeirdFunction": () => { return 42; }, + ArrayHost, + makeArrayHost: (numbers, labels) => { + return new ArrayHost(numbers, labels); + }, JsGreeter: class { /** * @param {string} name @@ -140,6 +166,24 @@ 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; } }; }, @@ -223,6 +267,12 @@ 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"); for (const p of [1, 4, 1024, 65536, 2147483647]) { assert.equal(exports.roundTripUnsafeRawPointer(p), p); From 66f0d1270f202839bc8d961b171bf14474755e5d Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 4 Feb 2026 17:47:17 +0000 Subject: [PATCH 28/34] build-examples.sh: re-enable Embedded example package (#490) The compiler crash should be fixed in `swift-DEVELOPMENT-SNAPSHOT-2026-01-07-a`. Resolves https://github.com/swiftwasm/JavaScriptKit/issues/449. --- .github/workflows/test.yml | 2 +- Examples/Embedded/build.sh | 2 +- Utilities/build-examples.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 06faa39f0..7b5a808bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -153,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/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/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 From ffa6c066fb561011b2d0f362f75170b2caf00f20 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 10:12:33 +0900 Subject: [PATCH 29/34] - Added JSValue-aware stack lift/lower fragments so arrays push/pop JSValue payloads using the shared helpers, enabling `[JSValue]` round-trips in both directions (`Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift`). - Extended JSValue test inputs with array and optional-array cases plus a JS-imported array echo to exercise the new path (`Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift`). - Updated codegen/link snapshots to reflect the new JSValue array glue (`Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift`, `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json`, `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js`, `Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts`). Tests: `UPDATE_SNAPSHOTS=1 swift test --package-path ./Plugins/BridgeJS`. Next step: run `make unittest SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1` for the full runtime suite if you want end-to-end validation. --- .../Sources/BridgeJSLink/JSGlueGen.swift | 33 +++++- .../Inputs/MacroSwift/JSValue.swift | 9 ++ .../BridgeJSCodegenTests/JSValue.json | 102 ++++++++++++++++++ .../BridgeJSCodegenTests/JSValue.swift | 49 +++++++++ .../BridgeJSLinkTests/JSValue.d.ts | 3 + .../BridgeJSLinkTests/JSValue.js | 83 ++++++++++++++ 6 files changed, 277 insertions(+), 2 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 410bce672..cdb23f606 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -2613,7 +2613,23 @@ struct IntrinsicJSFragment: Sendable { private static func stackLiftFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { case .jsValue: - throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") + 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: [], @@ -2775,7 +2791,20 @@ struct IntrinsicJSFragment: Sendable { private static func stackLowerFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { case .jsValue: - throw BridgeJSLinkError(message: "Array of JSValue is not supported yet") + 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"], diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift index 84251f6b3..2a34f5f2b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/JSValue.swift @@ -6,6 +6,14 @@ 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? @@ -30,3 +38,4 @@ } @JSFunction func jsEchoJSValue(_ value: JSValue) throws(JSException) -> JSValue +@JSFunction func jsEchoJSValueArray(_ values: [JSValue]) throws(JSException) -> [JSValue] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json index d10d673d4..5bd83be27 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.json @@ -231,6 +231,82 @@ "_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" : [ @@ -261,6 +337,32 @@ } } + }, + { + "name" : "jsEchoJSValueArray", + "parameters" : [ + { + "name" : "values", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } } ], "types" : [ diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift index 3a3be5079..f3550129c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift @@ -20,6 +20,37 @@ public func _bjs_roundTripOptionalJSValue(_ valueIsSome: Int32, _ valueKind: Int #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 { @@ -146,4 +177,22 @@ func _$jsEchoJSValue(_ value: JSValue) throws(JSException) -> JSValue { 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__/BridgeJSLinkTests/JSValue.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts index 9e2a85ac7..f4c13c610 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.d.ts @@ -24,9 +24,12 @@ export type Exports = { } 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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 2bd696c3d..f5c360bb0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -312,6 +312,31 @@ export async function createInstantiator(options, swift) { 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; @@ -448,6 +473,64 @@ export async function createInstantiator(options, swift) { } 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; From 3dba5dfe81e9d17f64b62c4f6f1cebfd9dea5254 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 10:27:11 +0900 Subject: [PATCH 30/34] - Added JSValue array support end-to-end: JS glue now lowers/lifts optional JSValue arrays, using tmp stacks and JSValue helpers, and Swift intrinsics gained Optional<[JSValue]> bridging (`Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift`, `Sources/JavaScriptKit/BridgeJSIntrinsics.swift`). - Expanded runtime coverage with JSValue array round-trips (including optionals) on both import and export paths plus JS prelude wiring and d.ts definitions (`Tests/BridgeJSRuntimeTests/ExportAPITests.swift`, `Tests/BridgeJSRuntimeTests/ImportAPITests.swift`, `Tests/BridgeJSRuntimeTests/bridge-js.d.ts`, `Tests/prelude.mjs`), and regenerated BridgeJS outputs (`Tests/BridgeJSRuntimeTests/Generated/*`, `Tests/BridgeJSGlobalTests/Generated/*`, plugin outputs). - Runtime tests now include JSValue array cases and all suites pass with the prescribed SDK. Tests: `make unittest SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1`. --- .../Sources/BridgeJSLink/JSGlueGen.swift | 14 ++ .../JavaScriptKit/BridgeJSIntrinsics.swift | 44 ++++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 8 + .../Generated/BridgeJS.Macros.swift | 4 + .../Generated/BridgeJS.swift | 67 +++++++++ .../Generated/JavaScript/BridgeJS.json | 138 ++++++++++++++++++ .../BridgeJSRuntimeTests/ImportAPITests.swift | 26 ++++ Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 2 + Tests/prelude.mjs | 10 ++ 9 files changed, 313 insertions(+) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index cdb23f606..60a6bd338 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -1029,6 +1029,20 @@ struct IntrinsicJSFragment: Sendable { 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: diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 349cecb91..1c8592724 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -1394,6 +1394,50 @@ extension Optional where Wrapped == JSValue { } } +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 diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index fe73ea6fb..05fcf146a 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -60,6 +60,14 @@ func runJsWorks() -> Void 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) diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index 9e05b3ae8..675bf9dfb 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -20,6 +20,10 @@ @JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue +@JSFunction func jsRoundTripJSValueArray(_ v: [JSValue]) throws(JSException) -> [JSValue] + +@JSFunction func jsRoundTripOptionalJSValueArray(_ v: Optional<[JSValue]>) throws(JSException) -> Optional<[JSValue]> + @JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void @JSFunction func jsThrowOrNumber(_ shouldThrow: Bool) throws(JSException) -> Double diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 5638d0442..40f1a5690 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -3832,6 +3832,37 @@ public func _bjs_roundTripOptionalJSValue(_ vIsSome: Int32, _ vKind: Int32, _ vP #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 { @@ -8583,6 +8614,42 @@ func _$jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue { 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 diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 366115792..e9591185d 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -5637,6 +5637,82 @@ } } }, + { + "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" : { @@ -12944,6 +13020,68 @@ } } }, + { + "name" : "jsRoundTripJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripOptionalJSValueArray", + "parameters" : [ + { + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "jsValue" : { + + } + } + } + }, + "_1" : "null" + } + } + }, { "name" : "jsThrowOrVoid", "parameters" : [ diff --git a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index a465c57b4..43aa6d565 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -73,6 +73,32 @@ class ImportAPITests: XCTestCase { } } + func testRoundTripJSValueArray() throws { + let object = JSObject.global + let symbol = JSSymbol("array") + let bigInt = JSBigInt(_slowBridge: Int64(42)) + let values: [JSValue] = [ + .boolean(false), + .number(123.5), + .string(JSString("hello")), + .object(object), + .null, + .undefined, + .symbol(symbol), + .bigInt(bigInt), + ] + let roundTripped = try jsRoundTripJSValueArray(values) + XCTAssertEqual(roundTripped, values) + XCTAssertEqual(try jsRoundTripJSValueArray([]), []) + } + + func testRoundTripOptionalJSValueArray() throws { + XCTAssertNil(try jsRoundTripOptionalJSValueArray(nil)) + let values: [JSValue] = [.number(1), .undefined, .null] + let result = try jsRoundTripOptionalJSValueArray(values) + XCTAssertEqual(result, values) + } + func testRoundTripFeatureFlag() throws { for v in [FeatureFlag.foo, .bar] { try XCTAssertEqual(jsRoundTripFeatureFlag(v), v) diff --git a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index b7dc6c48d..2f01a5a6e 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -6,6 +6,8 @@ export function jsRoundTripOptionalNumberNull(v: number | null): number | null export function jsRoundTripOptionalNumberUndefined(v: number | undefined): number | undefined 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 diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index e8f0b081c..2809a96e9 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -71,6 +71,12 @@ export async function setupOptions(options, context) { "jsRoundTripJSValue": (v) => { return v; }, + "jsRoundTripJSValueArray": (values) => { + return values; + }, + "jsRoundTripOptionalJSValueArray": (values) => { + return values ?? null; + }, "jsRoundTripIntArray": (items) => { return items; }, @@ -273,6 +279,10 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { 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); From f56d72f1709e5d172352a763bb2f2e3838a3de2f Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 15:07:13 +0900 Subject: [PATCH 31/34] BridgeJS: Fix throws hint spacing (#584) --- Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 39e3090cd..3de74f74b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -2017,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 From 4db13d9af83cc1318c3e122aa32834436b2e1f2a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 15:07:28 +0900 Subject: [PATCH 32/34] [NFC] BridgeJS: Split out OptionalSupportTests.swift (#583) BridgeJS: Split out OptionalSupportTests.swift --- Package.swift | 1 + Package@swift-6.2.swift | 1 + .../BridgeJSRuntimeTests/ExportAPITests.swift | 190 +- .../Generated/BridgeJS.Macros.swift | 4 - .../Generated/BridgeJS.swift | 2748 ++++++----- .../Generated/JavaScript/BridgeJS.json | 4382 +++++++++-------- .../BridgeJSRuntimeTests/ImportAPITests.swift | 20 - .../JavaScript/OptionalSupportTests.mjs | 219 + .../BridgeJSRuntimeTests/JavaScript/Types.mjs | 6 + .../OptionalSupportTests.swift | 232 + Tests/BridgeJSRuntimeTests/bridge-js.d.ts | 2 - Tests/prelude.mjs | 203 +- 12 files changed, 4108 insertions(+), 3900 deletions(-) create mode 100644 Tests/BridgeJSRuntimeTests/JavaScript/OptionalSupportTests.mjs create mode 100644 Tests/BridgeJSRuntimeTests/JavaScript/Types.mjs create mode 100644 Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift 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/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index fe73ea6fb..a41cc3029 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -515,123 +515,6 @@ 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 enum TypedPayloadResult { - case precision(Precision) - case direction(Direction) - case optPrecision(Precision?) - case optDirection(Direction?) - case empty -} - -@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult { - return result -} - -@JS func roundTripOptionalTypedPayloadResult(_ result: TypedPayloadResult?) -> TypedPayloadResult? { - return 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? { - return result -} - @JS enum AllTypesResult { case structPayload(Address) @@ -644,76 +527,19 @@ enum AllTypesResult { } @JS func roundTripAllTypesResult(_ result: AllTypesResult) -> AllTypesResult { - return result -} - -@JS func roundTripOptionalAllTypesResult(_ result: AllTypesResult?) -> AllTypesResult? { - return result + result } -@JS -enum OptionalAllTypesResult { - case optStruct(Address?) - case optClass(Greeter?) - case optJSObject(JSObject?) - case optNestedEnum(APIResult?) - case optArray([Int]?) - case optJsClass(Foo?) +@JS enum TypedPayloadResult { + case precision(Precision) + case direction(Direction) + case optPrecision(Precision?) + case optDirection(Direction?) case empty } -@JS func roundTripOptionalPayloadResult(_ result: OptionalAllTypesResult) -> OptionalAllTypesResult { - return result -} - -@JS func roundTripOptionalPayloadResultOpt(_ result: OptionalAllTypesResult?) -> OptionalAllTypesResult? { - return result -} - -@JS func roundTripOptionalClass(value: Greeter?) -> Greeter? { - return 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? { - return result +@JS func roundTripTypedPayloadResult(_ result: TypedPayloadResult) -> TypedPayloadResult { + result } // MARK: - Property Tests diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift index 9e05b3ae8..dcaad63fa 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.Macros.swift @@ -14,10 +14,6 @@ @JSFunction func jsRoundTripString(_ v: String) throws(JSException) -> String -@JSFunction func jsRoundTripOptionalNumberNull(_ v: Optional) throws(JSException) -> Optional - -@JSFunction func jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr - @JSFunction func jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue @JSFunction func jsThrowOrVoid(_ shouldThrow: Bool) throws(JSException) -> Void diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 5638d0442..51751dec1 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -1806,91 +1806,6 @@ extension API.NetworkingResult: _BridgedSwiftAssociatedValueEnum { } } -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 { - __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 { @@ -1976,34 +1891,21 @@ extension AllTypesResult: _BridgedSwiftAssociatedValueEnum { } } -extension OptionalAllTypesResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> OptionalAllTypesResult { +extension TypedPayloadResult: _BridgedSwiftAssociatedValueEnum { + private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> TypedPayloadResult { switch caseId { case 0: - return .optStruct(Optional
.bridgeJSLiftParameter()) + return .precision(Precision.bridgeJSLiftParameter(_swift_js_pop_f32())) case 1: - return .optClass(Optional.bridgeJSLiftParameter()) + return .direction(Direction.bridgeJSLiftParameter(_swift_js_pop_i32())) case 2: - return .optJSObject(Optional.bridgeJSLiftParameter()) + return .optPrecision(Optional.bridgeJSLiftParameter()) case 3: - return .optNestedEnum(Optional.bridgeJSLiftParameter()) + return .optDirection(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)") + fatalError("Unknown TypedPayloadResult case ID: \(caseId)") } } @@ -2011,248 +1913,95 @@ extension OptionalAllTypesResult: _BridgedSwiftAssociatedValueEnum { @_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) + case .precision(let param0): + param0.bridgeJSLowerStackReturn() 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) + case .direction(let param0): + param0.bridgeJSLowerStackReturn() return Int32(1) - case .optJSObject(let param0): + 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 .optNestedEnum(let param0): + case .optDirection(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _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) + return Int32(4) } } - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> OptionalAllTypesResult { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ caseId: Int32) -> TypedPayloadResult { return _bridgeJSLiftFromCaseId(caseId) } // MARK: ExportSwift - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> OptionalAllTypesResult { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ caseId: Int32) -> TypedPayloadResult { 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) + case .precision(let param0): + param0.bridgeJSLowerStackReturn() _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) + case .direction(let param0): + param0.bridgeJSLowerStackReturn() _swift_js_push_tag(Int32(1)) - case .optJSObject(let param0): + 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 .optNestedEnum(let param0): + case .optDirection(let param0): let __bjs_isSome_param0 = param0 != nil if let __bjs_unwrapped_param0 = param0 { - _swift_js_push_i32(__bjs_unwrapped_param0.bridgeJSLowerParameter()) + __bjs_unwrapped_param0.bridgeJSLowerStackReturn() } _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)) + _swift_js_push_tag(Int32(4)) } } } -extension APIOptionalResult: _BridgedSwiftAssociatedValueEnum { - private static func _bridgeJSLiftFromCaseId(_ caseId: Int32) -> APIOptionalResult { - switch caseId { +extension StaticCalculator: _BridgedSwiftCaseEnum { + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { + return bridgeJSRawValue + } + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ value: Int32) -> StaticCalculator { + return bridgeJSLiftParameter(value) + } + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> StaticCalculator { + return StaticCalculator(bridgeJSRawValue: value)! + } + @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { + return bridgeJSLowerParameter() + } + + private init?(bridgeJSRawValue: Int32) { + switch bridgeJSRawValue { case 0: - return .success(Optional.bridgeJSLiftParameter()) + self = .scientific case 1: - return .failure(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) - case 2: - return .status(Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter(), Optional.bridgeJSLiftParameter()) + self = .basic default: - fatalError("Unknown APIOptionalResult case ID: \(caseId)") + return nil } } - // 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 StaticCalculator: _BridgedSwiftCaseEnum { - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerParameter() -> Int32 { - return bridgeJSRawValue - } - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftReturn(_ value: Int32) -> StaticCalculator { - return bridgeJSLiftParameter(value) - } - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter(_ value: Int32) -> StaticCalculator { - return StaticCalculator(bridgeJSRawValue: value)! - } - @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() -> Int32 { - return bridgeJSLowerParameter() - } - - private init?(bridgeJSRawValue: Int32) { - switch bridgeJSRawValue { - case 0: - self = .scientific - case 1: - self = .basic - default: - return nil - } - } - - private var bridgeJSRawValue: Int32 { + private var bridgeJSRawValue: Int32 { switch self { case .scientific: return 0 @@ -2532,108 +2281,359 @@ public func _bjs_StaticPropertyNamespace_NestedProperties_static_nestedDouble_se #endif } -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) +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() { - self.x.bridgeJSLowerStackReturn() - self.y.bridgeJSLowerStackReturn() - } + // 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 -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 + // MARK: ExportSwift -extension PointerFields: _BridgedSwiftStruct { - @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> PointerFields { - 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 static func bridgeJSLiftParameter(_ caseId: Int32) -> OptionalAllTypesResult { + return _bridgeJSLiftFromCaseId(caseId) } @_spi(BridgeJS) @_transparent public consuming func bridgeJSLowerReturn() { - self.raw.bridgeJSLowerStackReturn() - self.mutRaw.bridgeJSLowerStackReturn() - self.opaque.bridgeJSLowerStackReturn() - self.ptr.bridgeJSLowerStackReturn() - self.mutPtr.bridgeJSLowerStackReturn() - } - - init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PointerFields(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_PointerFields())) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PointerFields") -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 -#else -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -#if arch(wasm32) -@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PointerFields") -fileprivate func _bjs_struct_lift_PointerFields() -> Int32 -#else -fileprivate func _bjs_struct_lift_PointerFields() -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -@_expose(wasm, "bjs_PointerFields_init") -@_cdecl("bjs_PointerFields_init") -public func _bjs_PointerFields_init(_ raw: UnsafeMutableRawPointer, _ mutRaw: UnsafeMutableRawPointer, _ opaque: UnsafeMutableRawPointer, _ ptr: UnsafeMutableRawPointer, _ mutPtr: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - let ret = PointerFields(raw: UnsafeRawPointer.bridgeJSLiftParameter(raw), mutRaw: UnsafeMutableRawPointer.bridgeJSLiftParameter(mutRaw), opaque: OpaquePointer.bridgeJSLiftParameter(opaque), ptr: UnsafePointer.bridgeJSLiftParameter(ptr), mutPtr: UnsafeMutablePointer.bridgeJSLiftParameter(mutPtr)) - return ret.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") +} +#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 + +extension PointerFields: _BridgedSwiftStruct { + @_spi(BridgeJS) @_transparent public static func bridgeJSLiftParameter() -> PointerFields { + 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() { + self.raw.bridgeJSLowerStackReturn() + self.mutRaw.bridgeJSLowerStackReturn() + self.opaque.bridgeJSLowerStackReturn() + self.ptr.bridgeJSLowerStackReturn() + self.mutPtr.bridgeJSLowerStackReturn() + } + + init(unsafelyCopying jsObject: JSObject) { + let __bjs_cleanupId = _bjs_struct_lower_PointerFields(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_PointerFields())) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PointerFields") +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 +#else +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PointerFields") +fileprivate func _bjs_struct_lift_PointerFields() -> Int32 +#else +fileprivate func _bjs_struct_lift_PointerFields() -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +@_expose(wasm, "bjs_PointerFields_init") +@_cdecl("bjs_PointerFields_init") +public func _bjs_PointerFields_init(_ raw: UnsafeMutableRawPointer, _ mutRaw: UnsafeMutableRawPointer, _ opaque: UnsafeMutableRawPointer, _ ptr: UnsafeMutableRawPointer, _ mutPtr: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + let ret = PointerFields(raw: UnsafeRawPointer.bridgeJSLiftParameter(raw), mutRaw: UnsafeMutableRawPointer.bridgeJSLiftParameter(mutRaw), opaque: OpaquePointer.bridgeJSLiftParameter(opaque), ptr: UnsafePointer.bridgeJSLiftParameter(ptr), mutPtr: UnsafeMutablePointer.bridgeJSLiftParameter(mutPtr)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -4654,683 +4654,802 @@ 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 { - #if arch(wasm32) - let ret = roundTripOptionalString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - 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 { - #if arch(wasm32) - let ret = roundTripOptionalInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - 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 { - #if arch(wasm32) - let ret = roundTripOptionalBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) - 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 { - #if arch(wasm32) - 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 { +@_expose(wasm, "bjs_roundTripAllTypesResult") +@_cdecl("bjs_roundTripAllTypesResult") +public func _bjs_roundTripAllTypesResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalSyntax(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_roundTripOptionalMixSyntax") -@_cdecl("bjs_roundTripOptionalMixSyntax") -public func _bjs_roundTripOptionalMixSyntax(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripTypedPayloadResult") +@_cdecl("bjs_roundTripTypedPayloadResult") +public func _bjs_roundTripTypedPayloadResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalMixSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + let ret = roundTripTypedPayloadResult(_: TypedPayloadResult.bridgeJSLiftParameter(result)) 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_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 = roundTripOptionalSwiftSyntax(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + 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_roundTripOptionalWithSpaces") -@_cdecl("bjs_roundTripOptionalWithSpaces") -public func _bjs_roundTripOptionalWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { +@_expose(wasm, "bjs_testPropertyHolder") +@_cdecl("bjs_testPropertyHolder") +public func _bjs_testPropertyHolder(_ holder: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = roundTripOptionalWithSpaces(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = testPropertyHolder(holder: PropertyHolder.bridgeJSLiftParameter(holder)) 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_resetObserverCounts") +@_cdecl("bjs_resetObserverCounts") +public func _bjs_resetObserverCounts() -> Void { #if arch(wasm32) - let ret = roundTripOptionalTypeAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) - return ret.bridgeJSLowerReturn() + resetObserverCounts() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStatus") -@_cdecl("bjs_roundTripOptionalStatus") -public func _bjs_roundTripOptionalStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { +@_expose(wasm, "bjs_getObserverStats") +@_cdecl("bjs_getObserverStats") +public func _bjs_getObserverStats() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = getObserverStats() 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 { +@_expose(wasm, "bjs_testStringDefault") +@_cdecl("bjs_testStringDefault") +public func _bjs_testStringDefault(_ messageBytes: Int32, _ messageLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + let ret = testStringDefault(message: String.bridgeJSLiftParameter(messageBytes, messageLength)) 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 { +@_expose(wasm, "bjs_testIntDefault") +@_cdecl("bjs_testIntDefault") +public func _bjs_testIntDefault(_ count: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalHttpStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + let ret = testIntDefault(count: Int.bridgeJSLiftParameter(count)) 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_testBoolDefault") +@_cdecl("bjs_testBoolDefault") +public func _bjs_testBoolDefault(_ flag: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalTSDirection(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_roundTripOptionalTSTheme") -@_cdecl("bjs_roundTripOptionalTSTheme") -public func _bjs_roundTripOptionalTSTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: 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 = roundTripOptionalTSTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + let ret = testOptionalDefault(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) 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_testMultipleDefaults") +@_cdecl("bjs_testMultipleDefaults") +public func _bjs_testMultipleDefaults(_ titleBytes: Int32, _ titleLength: Int32, _ count: Int32, _ enabled: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalNetworkingAPIMethod(_: Optional.bridgeJSLiftParameter(methodIsSome, methodValue)) + 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_roundTripOptionalAPIResult") -@_cdecl("bjs_roundTripOptionalAPIResult") -public func _bjs_roundTripOptionalAPIResult(_ valueIsSome: Int32, _ valueCaseId: Int32) -> Void { +@_expose(wasm, "bjs_testSimpleEnumDefault") +@_cdecl("bjs_testSimpleEnumDefault") +public func _bjs_testSimpleEnumDefault(_ status: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalAPIResult(value: Optional.bridgeJSLiftParameter(valueIsSome, valueCaseId)) + let ret = testSimpleEnumDefault(status: Status.bridgeJSLiftParameter(status)) return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripTypedPayloadResult") -@_cdecl("bjs_roundTripTypedPayloadResult") -public func _bjs_roundTripTypedPayloadResult(_ result: Int32) -> Void { +@_expose(wasm, "bjs_testDirectionDefault") +@_cdecl("bjs_testDirectionDefault") +public func _bjs_testDirectionDefault(_ direction: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripTypedPayloadResult(_: TypedPayloadResult.bridgeJSLiftParameter(result)) + let ret = testDirectionDefault(direction: Direction.bridgeJSLiftParameter(direction)) 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 { +@_expose(wasm, "bjs_testRawStringEnumDefault") +@_cdecl("bjs_testRawStringEnumDefault") +public func _bjs_testRawStringEnumDefault(_ themeBytes: Int32, _ themeLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalTypedPayloadResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + 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_roundTripAllTypesResult") -@_cdecl("bjs_roundTripAllTypesResult") -public func _bjs_roundTripAllTypesResult(_ result: Int32) -> Void { +@_expose(wasm, "bjs_arrayWithDefault") +@_cdecl("bjs_arrayWithDefault") +public func _bjs_arrayWithDefault() -> Int32 { #if arch(wasm32) - let ret = roundTripAllTypesResult(_: AllTypesResult.bridgeJSLiftParameter(result)) + let ret = arrayWithDefault(_: [Int].bridgeJSLiftParameter()) 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 { +@_expose(wasm, "bjs_arrayWithOptionalDefault") +@_cdecl("bjs_arrayWithOptionalDefault") +public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { #if arch(wasm32) - let ret = roundTripOptionalAllTypesResult(_: 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_roundTripOptionalPayloadResult") -@_cdecl("bjs_roundTripOptionalPayloadResult") -public func _bjs_roundTripOptionalPayloadResult(_ result: Int32) -> Void { +@_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 = roundTripOptionalPayloadResult(_: OptionalAllTypesResult.bridgeJSLiftParameter(result)) + 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_roundTripOptionalPayloadResultOpt") -@_cdecl("bjs_roundTripOptionalPayloadResultOpt") -public func _bjs_roundTripOptionalPayloadResultOpt(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { +@_expose(wasm, "bjs_formatName") +@_cdecl("bjs_formatName") +public func _bjs_formatName(_ nameBytes: Int32, _ nameLength: Int32, _ transform: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalPayloadResultOpt(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + 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_roundTripOptionalClass") -@_cdecl("bjs_roundTripOptionalClass") -public func _bjs_roundTripOptionalClass(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_makeFormatter") +@_cdecl("bjs_makeFormatter") +public func _bjs_makeFormatter(_ prefixBytes: Int32, _ prefixLength: Int32) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = roundTripOptionalClass(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - return ret.bridgeJSLowerReturn() + 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_roundTripOptionalGreeter") -@_cdecl("bjs_roundTripOptionalGreeter") -public func _bjs_roundTripOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_makeAdder") +@_cdecl("bjs_makeAdder") +public func _bjs_makeAdder(_ base: Int32) -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = roundTripOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) - 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_applyOptionalGreeter") -@_cdecl("bjs_applyOptionalGreeter") -public func _bjs_applyOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer, _ transform: Int32) -> Void { +@_expose(wasm, "bjs_roundTripIntArray") +@_cdecl("bjs_roundTripIntArray") +public func _bjs_roundTripIntArray() -> Void { #if arch(wasm32) - let ret = applyOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue), _: _BJS_Closure_20BridgeJSRuntimeTestsSq7GreeterC_Sq7GreeterC.bridgeJSLift(transform)) - return ret.bridgeJSLowerReturn() + let ret = roundTripIntArray(_: [Int].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_makeOptionalHolder") -@_cdecl("bjs_makeOptionalHolder") -public func _bjs_makeOptionalHolder(_ nullableGreeterIsSome: Int32, _ nullableGreeterValue: UnsafeMutableRawPointer, _ undefinedNumberIsSome: Int32, _ undefinedNumberValue: Float64) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_roundTripStringArray") +@_cdecl("bjs_roundTripStringArray") +public func _bjs_roundTripStringArray() -> Void { #if arch(wasm32) - let ret = makeOptionalHolder(nullableGreeter: Optional.bridgeJSLiftParameter(nullableGreeterIsSome, nullableGreeterValue), undefinedNumber: JSUndefinedOr.bridgeJSLiftParameter(undefinedNumberIsSome, undefinedNumberValue)) - return ret.bridgeJSLowerReturn() + let ret = roundTripStringArray(_: [String].bridgeJSLiftParameter()) + 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_roundTripDoubleArray") +@_cdecl("bjs_roundTripDoubleArray") +public func _bjs_roundTripDoubleArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDoubleArray(_: [Double].bridgeJSLiftParameter()) + 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_roundTripBoolArray") +@_cdecl("bjs_roundTripBoolArray") +public func _bjs_roundTripBoolArray() -> 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)) - return ret.bridgeJSLowerReturn() + let ret = roundTripBoolArray(_: [Bool].bridgeJSLiftParameter()) + 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_roundTripDirectionArray") +@_cdecl("bjs_roundTripDirectionArray") +public func _bjs_roundTripDirectionArray() -> Void { #if arch(wasm32) - let ret = testPropertyHolder(holder: PropertyHolder.bridgeJSLiftParameter(holder)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDirectionArray(_: [Direction].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_resetObserverCounts") -@_cdecl("bjs_resetObserverCounts") -public func _bjs_resetObserverCounts() -> Void { +@_expose(wasm, "bjs_roundTripStatusArray") +@_cdecl("bjs_roundTripStatusArray") +public func _bjs_roundTripStatusArray() -> Void { #if arch(wasm32) - resetObserverCounts() + let ret = roundTripStatusArray(_: [Status].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_getObserverStats") -@_cdecl("bjs_getObserverStats") -public func _bjs_getObserverStats() -> Void { +@_expose(wasm, "bjs_roundTripThemeArray") +@_cdecl("bjs_roundTripThemeArray") +public func _bjs_roundTripThemeArray() -> Void { #if arch(wasm32) - let ret = getObserverStats() - return ret.bridgeJSLowerReturn() + let ret = roundTripThemeArray(_: [Theme].bridgeJSLiftParameter()) + ret.bridgeJSLowerReturn() #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_roundTripHttpStatusArray") +@_cdecl("bjs_roundTripHttpStatusArray") +public func _bjs_roundTripHttpStatusArray() -> Void { #if arch(wasm32) - let ret = testStringDefault(message: String.bridgeJSLiftParameter(messageBytes, messageLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripHttpStatusArray(_: [HttpStatus].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_roundTripDataPointArray") +@_cdecl("bjs_roundTripDataPointArray") +public func _bjs_roundTripDataPointArray() -> Void { #if arch(wasm32) - let ret = testIntDefault(count: Int.bridgeJSLiftParameter(count)) - return ret.bridgeJSLowerReturn() + let ret = roundTripDataPointArray(_: [DataPoint].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_roundTripGreeterArray") +@_cdecl("bjs_roundTripGreeterArray") +public func _bjs_roundTripGreeterArray() -> Void { #if arch(wasm32) - let ret = testBoolDefault(flag: Bool.bridgeJSLiftParameter(flag)) - return ret.bridgeJSLowerReturn() + let ret = roundTripGreeterArray(_: [Greeter].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_roundTripOptionalIntArray") +@_cdecl("bjs_roundTripOptionalIntArray") +public func _bjs_roundTripOptionalIntArray() -> Void { #if arch(wasm32) - let ret = testOptionalDefault(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalIntArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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_testMultipleDefaults") -@_cdecl("bjs_testMultipleDefaults") -public func _bjs_testMultipleDefaults(_ titleBytes: Int32, _ titleLength: Int32, _ count: Int32, _ enabled: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalStringArray") +@_cdecl("bjs_roundTripOptionalStringArray") +public func _bjs_roundTripOptionalStringArray() -> 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 = roundTripOptionalStringArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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_testSimpleEnumDefault") -@_cdecl("bjs_testSimpleEnumDefault") -public func _bjs_testSimpleEnumDefault(_ status: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripOptionalDataPointArray") +@_cdecl("bjs_roundTripOptionalDataPointArray") +public func _bjs_roundTripOptionalDataPointArray() -> Void { #if arch(wasm32) - let ret = testSimpleEnumDefault(status: Status.bridgeJSLiftParameter(status)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalDataPointArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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.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_testDirectionDefault") -@_cdecl("bjs_testDirectionDefault") -public func _bjs_testDirectionDefault(_ direction: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripOptionalDirectionArray") +@_cdecl("bjs_roundTripOptionalDirectionArray") +public func _bjs_roundTripOptionalDirectionArray() -> Void { #if arch(wasm32) - let ret = testDirectionDefault(direction: Direction.bridgeJSLiftParameter(direction)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalDirectionArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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_testRawStringEnumDefault") -@_cdecl("bjs_testRawStringEnumDefault") -public func _bjs_testRawStringEnumDefault(_ themeBytes: Int32, _ themeLength: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalStatusArray") +@_cdecl("bjs_roundTripOptionalStatusArray") +public func _bjs_roundTripOptionalStatusArray() -> Void { #if arch(wasm32) - let ret = testRawStringEnumDefault(theme: Theme.bridgeJSLiftParameter(themeBytes, themeLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalStatusArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [Optional] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __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_testComplexInit") -@_cdecl("bjs_testComplexInit") -public func _bjs_testComplexInit(_ greeter: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_roundTripOptionalIntArrayType") +@_cdecl("bjs_roundTripOptionalIntArrayType") +public func _bjs_roundTripOptionalIntArrayType(_ values: Int32) -> Void { #if arch(wasm32) - let ret = testComplexInit(greeter: Greeter.bridgeJSLiftParameter(greeter)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalIntArrayType(_: { + if values == 0 { + return Optional<[Int]>.none + } else { + return [Int].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_testEmptyInit") -@_cdecl("bjs_testEmptyInit") -public func _bjs_testEmptyInit(_ object: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_roundTripOptionalStringArrayType") +@_cdecl("bjs_roundTripOptionalStringArrayType") +public func _bjs_roundTripOptionalStringArrayType(_ values: Int32) -> Void { #if arch(wasm32) - let ret = testEmptyInit(_: StaticPropertyHolder.bridgeJSLiftParameter(object)) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalStringArrayType(_: { + if values == 0 { + return Optional<[String]>.none + } else { + return [String].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_arrayWithDefault") -@_cdecl("bjs_arrayWithDefault") -public func _bjs_arrayWithDefault() -> Int32 { +@_expose(wasm, "bjs_roundTripOptionalGreeterArrayType") +@_cdecl("bjs_roundTripOptionalGreeterArrayType") +public func _bjs_roundTripOptionalGreeterArrayType(_ greeters: Int32) -> Void { #if arch(wasm32) - let ret = arrayWithDefault(_: [Int].bridgeJSLiftParameter()) - return ret.bridgeJSLowerReturn() + let ret = roundTripOptionalGreeterArrayType(_: { + if greeters == 0 { + return Optional<[Greeter]>.none + } else { + return [Greeter].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_arrayWithOptionalDefault") -@_cdecl("bjs_arrayWithOptionalDefault") -public func _bjs_arrayWithOptionalDefault(_ values: Int32) -> Int32 { +@_expose(wasm, "bjs_roundTripNestedIntArray") +@_cdecl("bjs_roundTripNestedIntArray") +public func _bjs_roundTripNestedIntArray() -> Void { #if arch(wasm32) - let ret = arrayWithOptionalDefault(_: { - if values == 0 { - return Optional<[Int]>.none - } else { - return [Int].bridgeJSLiftParameter() + let ret = roundTripNestedIntArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[Int]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([Int].bridgeJSLiftParameter()) } + __result.reverse() + return __result }()) - return ret.bridgeJSLowerReturn() + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _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_roundTripNestedStringArray") +@_cdecl("bjs_roundTripNestedStringArray") +public func _bjs_roundTripNestedStringArray() -> Void { #if arch(wasm32) - let ret = arrayMixedDefaults(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength), values: [Int].bridgeJSLiftParameter(), suffix: String.bridgeJSLiftParameter(suffixBytes, suffixLength)) - return ret.bridgeJSLowerReturn() + let ret = roundTripNestedStringArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[String]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([String].bridgeJSLiftParameter()) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(Int32(ret.count)) #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 { +@_expose(wasm, "bjs_roundTripNestedDoubleArray") +@_cdecl("bjs_roundTripNestedDoubleArray") +public func _bjs_roundTripNestedDoubleArray() -> Void { #if arch(wasm32) - let ret = formatName(_: String.bridgeJSLiftParameter(nameBytes, nameLength), transform: _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLift(transform)) - return ret.bridgeJSLowerReturn() + let ret = roundTripNestedDoubleArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[Double]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([Double].bridgeJSLiftParameter()) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_makeFormatter") -@_cdecl("bjs_makeFormatter") -public func _bjs_makeFormatter(_ prefixBytes: Int32, _ prefixLength: Int32) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_roundTripNestedBoolArray") +@_cdecl("bjs_roundTripNestedBoolArray") +public func _bjs_roundTripNestedBoolArray() -> Void { #if arch(wasm32) - let ret = makeFormatter(prefix: String.bridgeJSLiftParameter(prefixBytes, prefixLength)) - return _BJS_Closure_20BridgeJSRuntimeTestsSS_SS.bridgeJSLower(ret) + let ret = roundTripNestedBoolArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[Bool]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([Bool].bridgeJSLiftParameter()) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_makeAdder") -@_cdecl("bjs_makeAdder") -public func _bjs_makeAdder(_ base: Int32) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_roundTripNestedDataPointArray") +@_cdecl("bjs_roundTripNestedDataPointArray") +public func _bjs_roundTripNestedDataPointArray() -> Void { #if arch(wasm32) - let ret = makeAdder(base: Int.bridgeJSLiftParameter(base)) - return _BJS_Closure_20BridgeJSRuntimeTestsSi_Si.bridgeJSLower(ret) + let ret = roundTripNestedDataPointArray(_: { + 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 + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _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_roundTripNestedDirectionArray") +@_cdecl("bjs_roundTripNestedDirectionArray") +public func _bjs_roundTripNestedDirectionArray() -> Void { #if arch(wasm32) - let ret = roundTripIntArray(_: [Int].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripNestedDirectionArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[Direction]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([Direction].bridgeJSLiftParameter()) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _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_roundTripNestedGreeterArray") +@_cdecl("bjs_roundTripNestedGreeterArray") +public func _bjs_roundTripNestedGreeterArray() -> Void { #if arch(wasm32) - let ret = roundTripStringArray(_: [String].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripNestedGreeterArray(_: { + let __count = Int(_swift_js_pop_i32()) + var __result: [[Greeter]] = [] + __result.reserveCapacity(__count) + for _ in 0 ..< __count { + __result.append([Greeter].bridgeJSLiftParameter()) + } + __result.reverse() + return __result + }()) + for __bjs_elem_ret in ret { + __bjs_elem_ret.bridgeJSLowerReturn()} + _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_roundTripUnsafeRawPointerArray") +@_cdecl("bjs_roundTripUnsafeRawPointerArray") +public func _bjs_roundTripUnsafeRawPointerArray() -> Void { #if arch(wasm32) - let ret = roundTripDoubleArray(_: [Double].bridgeJSLiftParameter()) + let ret = roundTripUnsafeRawPointerArray(_: [UnsafeRawPointer].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripBoolArray") -@_cdecl("bjs_roundTripBoolArray") -public func _bjs_roundTripBoolArray() -> Void { +@_expose(wasm, "bjs_roundTripUnsafeMutableRawPointerArray") +@_cdecl("bjs_roundTripUnsafeMutableRawPointerArray") +public func _bjs_roundTripUnsafeMutableRawPointerArray() -> Void { #if arch(wasm32) - let ret = roundTripBoolArray(_: [Bool].bridgeJSLiftParameter()) + let ret = roundTripUnsafeMutableRawPointerArray(_: [UnsafeMutableRawPointer].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDirectionArray") -@_cdecl("bjs_roundTripDirectionArray") -public func _bjs_roundTripDirectionArray() -> Void { +@_expose(wasm, "bjs_roundTripOpaquePointerArray") +@_cdecl("bjs_roundTripOpaquePointerArray") +public func _bjs_roundTripOpaquePointerArray() -> Void { #if arch(wasm32) - let ret = roundTripDirectionArray(_: [Direction].bridgeJSLiftParameter()) + let ret = roundTripOpaquePointerArray(_: [OpaquePointer].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripStatusArray") -@_cdecl("bjs_roundTripStatusArray") -public func _bjs_roundTripStatusArray() -> Void { +@_expose(wasm, "bjs_roundTripUnsafePointerArray") +@_cdecl("bjs_roundTripUnsafePointerArray") +public func _bjs_roundTripUnsafePointerArray() -> Void { #if arch(wasm32) - let ret = roundTripStatusArray(_: [Status].bridgeJSLiftParameter()) + let ret = roundTripUnsafePointerArray(_: [UnsafePointer].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripThemeArray") -@_cdecl("bjs_roundTripThemeArray") -public func _bjs_roundTripThemeArray() -> Void { +@_expose(wasm, "bjs_roundTripUnsafeMutablePointerArray") +@_cdecl("bjs_roundTripUnsafeMutablePointerArray") +public func _bjs_roundTripUnsafeMutablePointerArray() -> Void { #if arch(wasm32) - let ret = roundTripThemeArray(_: [Theme].bridgeJSLiftParameter()) + let ret = roundTripUnsafeMutablePointerArray(_: [UnsafeMutablePointer].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripHttpStatusArray") -@_cdecl("bjs_roundTripHttpStatusArray") -public func _bjs_roundTripHttpStatusArray() -> Void { +@_expose(wasm, "bjs_consumeDataProcessorArrayType") +@_cdecl("bjs_consumeDataProcessorArrayType") +public func _bjs_consumeDataProcessorArrayType() -> Int32 { #if arch(wasm32) - let ret = roundTripHttpStatusArray(_: [HttpStatus].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = consumeDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripDataPointArray") -@_cdecl("bjs_roundTripDataPointArray") -public func _bjs_roundTripDataPointArray() -> Void { +@_expose(wasm, "bjs_roundTripDataProcessorArrayType") +@_cdecl("bjs_roundTripDataProcessorArrayType") +public func _bjs_roundTripDataProcessorArrayType() -> Void { #if arch(wasm32) - let ret = roundTripDataPointArray(_: [DataPoint].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + ret.map { + $0 as! AnyDataProcessor + } .bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripGreeterArray") -@_cdecl("bjs_roundTripGreeterArray") -public func _bjs_roundTripGreeterArray() -> Void { +@_expose(wasm, "bjs_roundTripJSObjectArray") +@_cdecl("bjs_roundTripJSObjectArray") +public func _bjs_roundTripJSObjectArray() -> Void { #if arch(wasm32) - let ret = roundTripGreeterArray(_: [Greeter].bridgeJSLiftParameter()) + let ret = roundTripJSObjectArray(_: [JSObject].bridgeJSLiftParameter()) ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalIntArray") -@_cdecl("bjs_roundTripOptionalIntArray") -public func _bjs_roundTripOptionalIntArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalJSObjectArray") +@_cdecl("bjs_roundTripOptionalJSObjectArray") +public func _bjs_roundTripOptionalJSObjectArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalIntArray(_: { + 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()) + __result.append(Optional.bridgeJSLiftParameter()) } __result.reverse() return __result @@ -5346,41 +5465,40 @@ public func _bjs_roundTripOptionalIntArray() -> Void { #endif } -@_expose(wasm, "bjs_roundTripOptionalStringArray") -@_cdecl("bjs_roundTripOptionalStringArray") -public func _bjs_roundTripOptionalStringArray() -> Void { +@_expose(wasm, "bjs_roundTripFooArray") +@_cdecl("bjs_roundTripFooArray") +public func _bjs_roundTripFooArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalStringArray(_: { + 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()) + __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 { - __bjs_unwrapped_ret_elem.bridgeJSLowerStackReturn()} - _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_roundTripOptionalDataPointArray") -@_cdecl("bjs_roundTripOptionalDataPointArray") -public func _bjs_roundTripOptionalDataPointArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalFooArray") +@_cdecl("bjs_roundTripOptionalFooArray") +public func _bjs_roundTripOptionalFooArray() -> Void { #if arch(wasm32) - let ret = roundTripOptionalDataPointArray(_: { + 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()) + __result.append(Optional.bridgeJSLiftParameter().map { + Foo(unsafelyWrapping: $0) + }) } __result.reverse() return __result @@ -5388,7 +5506,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.jsObject.bridgeJSLowerStackReturn()} _swift_js_push_i32(__bjs_isSome_ret_elem ? 1 : 0)} _swift_js_push_i32(Int32(ret.count)) #else @@ -5396,429 +5514,311 @@ public func _bjs_roundTripOptionalDataPointArray() -> Void { #endif } -@_expose(wasm, "bjs_roundTripOptionalDirectionArray") -@_cdecl("bjs_roundTripOptionalDirectionArray") -public func _bjs_roundTripOptionalDirectionArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalString") +@_cdecl("bjs_roundTripOptionalString") +public func _bjs_roundTripOptionalString(_ nameIsSome: Int32, _ nameBytes: Int32, _ nameLength: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalDirectionArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __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)) + let ret = roundTripOptionalString(name: Optional.bridgeJSLiftParameter(nameIsSome, nameBytes, nameLength)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalStatusArray") -@_cdecl("bjs_roundTripOptionalStatusArray") -public func _bjs_roundTripOptionalStatusArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalInt") +@_cdecl("bjs_roundTripOptionalInt") +public func _bjs_roundTripOptionalInt(_ valueIsSome: Int32, _ valueValue: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalStatusArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __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)) + let ret = roundTripOptionalInt(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalIntArrayType") -@_cdecl("bjs_roundTripOptionalIntArrayType") -public func _bjs_roundTripOptionalIntArrayType(_ values: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalBool") +@_cdecl("bjs_roundTripOptionalBool") +public func _bjs_roundTripOptionalBool(_ flagIsSome: Int32, _ flagValue: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalIntArrayType(_: { - if values == 0 { - return Optional<[Int]>.none - } else { - return [Int].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) + let ret = roundTripOptionalBool(flag: Optional.bridgeJSLiftParameter(flagIsSome, flagValue)) + 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 { + #if arch(wasm32) + 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_roundTripOptionalStringArrayType") -@_cdecl("bjs_roundTripOptionalStringArrayType") -public func _bjs_roundTripOptionalStringArrayType(_ values: Int32) -> Void { +@_expose(wasm, "bjs_roundTripOptionalWithSpaces") +@_cdecl("bjs_roundTripOptionalWithSpaces") +public func _bjs_roundTripOptionalWithSpaces(_ valueIsSome: Int32, _ valueValue: Float64) -> Void { #if arch(wasm32) - let ret = roundTripOptionalStringArrayType(_: { - if values == 0 { - return Optional<[String]>.none - } else { - return [String].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) + let ret = roundTripOptionalWithSpaces(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_roundTripOptionalTypeAlias") +@_cdecl("bjs_roundTripOptionalTypeAlias") +public func _bjs_roundTripOptionalTypeAlias(_ ageIsSome: Int32, _ ageValue: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalGreeterArrayType(_: { - if greeters == 0 { - return Optional<[Greeter]>.none - } else { - return [Greeter].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) + let ret = roundTripOptionalTypeAlias(age: Optional.bridgeJSLiftParameter(ageIsSome, ageValue)) + 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_roundTripOptionalStatus") +@_cdecl("bjs_roundTripOptionalStatus") +public func _bjs_roundTripOptionalStatus(_ valueIsSome: Int32, _ valueValue: Int32) -> 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([Int].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + 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_roundTripOptionalTheme") +@_cdecl("bjs_roundTripOptionalTheme") +public func _bjs_roundTripOptionalTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: 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([String].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + 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_roundTripOptionalHttpStatus") +@_cdecl("bjs_roundTripOptionalHttpStatus") +public func _bjs_roundTripOptionalHttpStatus(_ valueIsSome: Int32, _ valueValue: 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([Double].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalHttpStatus(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + 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_roundTripOptionalTSDirection") +@_cdecl("bjs_roundTripOptionalTSDirection") +public func _bjs_roundTripOptionalTSDirection(_ valueIsSome: Int32, _ valueValue: 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([Bool].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalTSDirection(value: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + 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_roundTripOptionalTSTheme") +@_cdecl("bjs_roundTripOptionalTSTheme") +public func _bjs_roundTripOptionalTSTheme(_ valueIsSome: Int32, _ valueBytes: Int32, _ valueLength: 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([DataPoint].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalTSTheme(value: Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength)) + 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_roundTripOptionalNetworkingAPIMethod") +@_cdecl("bjs_roundTripOptionalNetworkingAPIMethod") +public func _bjs_roundTripOptionalNetworkingAPIMethod(_ methodIsSome: Int32, _ methodValue: 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([Direction].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalNetworkingAPIMethod(_: Optional.bridgeJSLiftParameter(methodIsSome, methodValue)) + 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_roundTripOptionalAPIResult") +@_cdecl("bjs_roundTripOptionalAPIResult") +public func _bjs_roundTripOptionalAPIResult(_ valueIsSome: Int32, _ valueCaseId: 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([Greeter].bridgeJSLiftParameter()) - } - __result.reverse() - return __result - }()) - for __bjs_elem_ret in ret { - __bjs_elem_ret.bridgeJSLowerReturn()} - _swift_js_push_i32(Int32(ret.count)) + let ret = roundTripOptionalAPIResult(value: Optional.bridgeJSLiftParameter(valueIsSome, valueCaseId)) + 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_roundTripOptionalTypedPayloadResult") +@_cdecl("bjs_roundTripOptionalTypedPayloadResult") +public func _bjs_roundTripOptionalTypedPayloadResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripUnsafeRawPointerArray(_: [UnsafeRawPointer].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripOptionalTypedPayloadResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + 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_compareAPIResults") +@_cdecl("bjs_compareAPIResults") +public func _bjs_compareAPIResults(_ r1IsSome: Int32, _ r1CaseId: Int32, _ r2IsSome: Int32, _ r2CaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripUnsafeMutableRawPointerArray(_: [UnsafeMutableRawPointer].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + 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_roundTripOpaquePointerArray") -@_cdecl("bjs_roundTripOpaquePointerArray") -public func _bjs_roundTripOpaquePointerArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalComplexResult") +@_cdecl("bjs_roundTripOptionalComplexResult") +public func _bjs_roundTripOptionalComplexResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOpaquePointerArray(_: [OpaquePointer].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripOptionalComplexResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripUnsafePointerArray") -@_cdecl("bjs_roundTripUnsafePointerArray") -public func _bjs_roundTripUnsafePointerArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalAllTypesResult") +@_cdecl("bjs_roundTripOptionalAllTypesResult") +public func _bjs_roundTripOptionalAllTypesResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripUnsafePointerArray(_: [UnsafePointer].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripOptionalAllTypesResult(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripUnsafeMutablePointerArray") -@_cdecl("bjs_roundTripUnsafeMutablePointerArray") -public func _bjs_roundTripUnsafeMutablePointerArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalPayloadResult") +@_cdecl("bjs_roundTripOptionalPayloadResult") +public func _bjs_roundTripOptionalPayloadResult(_ result: Int32) -> Void { #if arch(wasm32) - let ret = roundTripUnsafeMutablePointerArray(_: [UnsafeMutablePointer].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripOptionalPayloadResult(_: OptionalAllTypesResult.bridgeJSLiftParameter(result)) + 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_roundTripOptionalPayloadResultOpt") +@_cdecl("bjs_roundTripOptionalPayloadResultOpt") +public func _bjs_roundTripOptionalPayloadResultOpt(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = consumeDataProcessorArrayType(_: [AnyDataProcessor].bridgeJSLiftParameter()) + let ret = roundTripOptionalPayloadResultOpt(_: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) 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() +@_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_roundTripJSObjectArray") -@_cdecl("bjs_roundTripJSObjectArray") -public func _bjs_roundTripJSObjectArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalGreeter") +@_cdecl("bjs_roundTripOptionalGreeter") +public func _bjs_roundTripOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = roundTripJSObjectArray(_: [JSObject].bridgeJSLiftParameter()) - ret.bridgeJSLowerReturn() + let ret = roundTripOptionalGreeter(_: Optional.bridgeJSLiftParameter(valueIsSome, valueValue)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_roundTripOptionalJSObjectArray") -@_cdecl("bjs_roundTripOptionalJSObjectArray") -public func _bjs_roundTripOptionalJSObjectArray() -> Void { +@_expose(wasm, "bjs_applyOptionalGreeter") +@_cdecl("bjs_applyOptionalGreeter") +public func _bjs_applyOptionalGreeter(_ valueIsSome: Int32, _ valueValue: UnsafeMutableRawPointer, _ transform: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalJSObjectArray(_: { - let __count = Int(_swift_js_pop_i32()) - var __result: [Optional] = [] - __result.reserveCapacity(__count) - for _ in 0 ..< __count { - __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)) + 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_roundTripFooArray") -@_cdecl("bjs_roundTripFooArray") -public func _bjs_roundTripFooArray() -> Void { +@_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 = roundTripFooArray(_: { - 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() + 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_roundTripOptionalFooArray") -@_cdecl("bjs_roundTripOptionalFooArray") -public func _bjs_roundTripOptionalFooArray() -> Void { +@_expose(wasm, "bjs_roundTripOptionalAPIOptionalResult") +@_cdecl("bjs_roundTripOptionalAPIOptionalResult") +public func _bjs_roundTripOptionalAPIOptionalResult(_ resultIsSome: Int32, _ resultCaseId: Int32) -> Void { #if arch(wasm32) - let ret = roundTripOptionalFooArray(_: { - 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)) + let ret = roundTripOptionalAPIOptionalResult(result: Optional.bridgeJSLiftParameter(resultIsSome, resultCaseId)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif @@ -6299,302 +6299,125 @@ public func _bjs_Converter_init() -> UnsafeMutableRawPointer { public func _bjs_Converter_toString(_ _self: UnsafeMutableRawPointer, _ value: Int32) -> Void { #if arch(wasm32) let ret = Utils.Converter.bridgeJSLiftParameter(_self).toString(value: Int.bridgeJSLiftParameter(value)) - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_Converter_deinit") -@_cdecl("bjs_Converter_deinit") -public func _bjs_Converter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension Utils.Converter: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_Converter_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Converter_wrap") -fileprivate func _bjs_Converter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_Converter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -@_expose(wasm, "bjs_HTTPServer_init") -@_cdecl("bjs_HTTPServer_init") -public func _bjs_HTTPServer_init() -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = Networking.API.HTTPServer() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_HTTPServer_call") -@_cdecl("bjs_HTTPServer_call") -public func _bjs_HTTPServer_call(_ _self: UnsafeMutableRawPointer, _ method: Int32) -> Void { - #if arch(wasm32) - Networking.API.HTTPServer.bridgeJSLiftParameter(_self).call(_: Networking.API.Method.bridgeJSLiftParameter(method)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_HTTPServer_deinit") -@_cdecl("bjs_HTTPServer_deinit") -public func _bjs_HTTPServer_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension Networking.API.HTTPServer: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_HTTPServer_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_HTTPServer_wrap") -fileprivate func _bjs_HTTPServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_HTTPServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { - fatalError("Only available on WebAssembly") -} -#endif - -@_expose(wasm, "bjs_TestServer_init") -@_cdecl("bjs_TestServer_init") -public func _bjs_TestServer_init() -> UnsafeMutableRawPointer { - #if arch(wasm32) - let ret = Internal.TestServer() - return ret.bridgeJSLowerReturn() - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_TestServer_call") -@_cdecl("bjs_TestServer_call") -public func _bjs_TestServer_call(_ _self: UnsafeMutableRawPointer, _ method: Int32) -> Void { - #if arch(wasm32) - Internal.TestServer.bridgeJSLiftParameter(_self).call(_: Internal.SupportedMethod.bridgeJSLiftParameter(method)) - #else - fatalError("Only available on WebAssembly") - #endif -} - -@_expose(wasm, "bjs_TestServer_deinit") -@_cdecl("bjs_TestServer_deinit") -public func _bjs_TestServer_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { - #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() - #else - fatalError("Only available on WebAssembly") - #endif -} - -extension Internal.TestServer: ConvertibleToJSValue, _BridgedSwiftHeapObject { - var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_TestServer_wrap(Unmanaged.passRetained(self).toOpaque())))) - } -} - -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_TestServer_wrap") -fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 -#else -fileprivate func _bjs_TestServer_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) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_OptionalHolder_deinit") -@_cdecl("bjs_OptionalHolder_deinit") -public func _bjs_OptionalHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_Converter_deinit") +@_cdecl("bjs_Converter_deinit") +public func _bjs_Converter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() + Unmanaged.fromOpaque(pointer).release() #else fatalError("Only available on WebAssembly") #endif } -extension OptionalHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { +extension Utils.Converter: ConvertibleToJSValue, _BridgedSwiftHeapObject { var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) + return .object(JSObject(id: UInt32(bitPattern: _bjs_Converter_wrap(Unmanaged.passRetained(self).toOpaque())))) } } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalHolder_wrap") -fileprivate func _bjs_OptionalHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Converter_wrap") +fileprivate func _bjs_Converter_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 #else -fileprivate func _bjs_OptionalHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { +fileprivate func _bjs_Converter_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 { +@_expose(wasm, "bjs_HTTPServer_init") +@_cdecl("bjs_HTTPServer_init") +public func _bjs_HTTPServer_init() -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = OptionalPropertyHolder(optionalName: Optional.bridgeJSLiftParameter(optionalNameIsSome, optionalNameBytes, optionalNameLength)) + let ret = Networking.API.HTTPServer() 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 { +@_expose(wasm, "bjs_HTTPServer_call") +@_cdecl("bjs_HTTPServer_call") +public func _bjs_HTTPServer_call(_ _self: UnsafeMutableRawPointer, _ method: Int32) -> Void { #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName - return ret.bridgeJSLowerReturn() + Networking.API.HTTPServer.bridgeJSLiftParameter(_self).call(_: Networking.API.Method.bridgeJSLiftParameter(method)) #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 { +@_expose(wasm, "bjs_HTTPServer_deinit") +@_cdecl("bjs_HTTPServer_deinit") +public func _bjs_HTTPServer_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) + Unmanaged.fromOpaque(pointer).release() #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 +extension Networking.API.HTTPServer: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_HTTPServer_wrap(Unmanaged.passRetained(self).toOpaque())))) + } } -@_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 +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_HTTPServer_wrap") +fileprivate func _bjs_HTTPServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_HTTPServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") - #endif } +#endif -@_expose(wasm, "bjs_OptionalPropertyHolder_optionalGreeter_get") -@_cdecl("bjs_OptionalPropertyHolder_optionalGreeter_get") -public func _bjs_OptionalPropertyHolder_optionalGreeter_get(_ _self: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_TestServer_init") +@_cdecl("bjs_TestServer_init") +public func _bjs_TestServer_init() -> UnsafeMutableRawPointer { #if arch(wasm32) - let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter + let ret = Internal.TestServer() 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 { +@_expose(wasm, "bjs_TestServer_call") +@_cdecl("bjs_TestServer_call") +public func _bjs_TestServer_call(_ _self: UnsafeMutableRawPointer, _ method: Int32) -> Void { #if arch(wasm32) - OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) + Internal.TestServer.bridgeJSLiftParameter(_self).call(_: Internal.SupportedMethod.bridgeJSLiftParameter(method)) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_OptionalPropertyHolder_deinit") -@_cdecl("bjs_OptionalPropertyHolder_deinit") -public func _bjs_OptionalPropertyHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { +@_expose(wasm, "bjs_TestServer_deinit") +@_cdecl("bjs_TestServer_deinit") +public func _bjs_TestServer_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - Unmanaged.fromOpaque(pointer).release() + Unmanaged.fromOpaque(pointer).release() #else fatalError("Only available on WebAssembly") #endif } -extension OptionalPropertyHolder: ConvertibleToJSValue, _BridgedSwiftHeapObject { +extension Internal.TestServer: ConvertibleToJSValue, _BridgedSwiftHeapObject { var jsValue: JSValue { - return .object(JSObject(id: UInt32(bitPattern: _bjs_OptionalPropertyHolder_wrap(Unmanaged.passRetained(self).toOpaque())))) + return .object(JSObject(id: UInt32(bitPattern: _bjs_TestServer_wrap(Unmanaged.passRetained(self).toOpaque())))) } } #if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_OptionalPropertyHolder_wrap") -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_TestServer_wrap") +fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 #else -fileprivate func _bjs_OptionalPropertyHolder_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { +fileprivate func _bjs_TestServer_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { fatalError("Only available on WebAssembly") } #endif @@ -8147,181 +7970,358 @@ public func _bjs_TextProcessor_processOptionalGreeter(_ _self: UnsafeMutableRawP #endif } -@_expose(wasm, "bjs_TextProcessor_makeOptionalStringFormatter") -@_cdecl("bjs_TextProcessor_makeOptionalStringFormatter") -public func _bjs_TextProcessor_makeOptionalStringFormatter(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_TextProcessor_makeOptionalStringFormatter") +@_cdecl("bjs_TextProcessor_makeOptionalStringFormatter") +public func _bjs_TextProcessor_makeOptionalStringFormatter(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalStringFormatter() + return _BJS_Closure_20BridgeJSRuntimeTestsSqSS_SS.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeOptionalGreeterCreator") +@_cdecl("bjs_TextProcessor_makeOptionalGreeterCreator") +public func _bjs_TextProcessor_makeOptionalGreeterCreator(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalGreeterCreator() + return _BJS_Closure_20BridgeJSRuntimeTestsy_Sq7GreeterC.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processDirection") +@_cdecl("bjs_TextProcessor_processDirection") +public func _bjs_TextProcessor_processDirection(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processDirection(_: _BJS_Closure_20BridgeJSRuntimeTests9DirectionO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processTheme") +@_cdecl("bjs_TextProcessor_processTheme") +public func _bjs_TextProcessor_processTheme(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processTheme(_: _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processHttpStatus") +@_cdecl("bjs_TextProcessor_processHttpStatus") +public func _bjs_TextProcessor_processHttpStatus(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Int32 { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processHttpStatus(_: _BJS_Closure_20BridgeJSRuntimeTests10HttpStatusO_Si.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processAPIResult") +@_cdecl("bjs_TextProcessor_processAPIResult") +public func _bjs_TextProcessor_processAPIResult(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processAPIResult(_: _BJS_Closure_20BridgeJSRuntimeTests9APIResultO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeDirectionChecker") +@_cdecl("bjs_TextProcessor_makeDirectionChecker") +public func _bjs_TextProcessor_makeDirectionChecker(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeDirectionChecker() + return _BJS_Closure_20BridgeJSRuntimeTests9DirectionO_Sb.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeThemeValidator") +@_cdecl("bjs_TextProcessor_makeThemeValidator") +public func _bjs_TextProcessor_makeThemeValidator(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeThemeValidator() + return _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_Sb.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeStatusCodeExtractor") +@_cdecl("bjs_TextProcessor_makeStatusCodeExtractor") +public func _bjs_TextProcessor_makeStatusCodeExtractor(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeStatusCodeExtractor() + return _BJS_Closure_20BridgeJSRuntimeTests10HttpStatusO_Si.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_makeAPIResultHandler") +@_cdecl("bjs_TextProcessor_makeAPIResultHandler") +public func _bjs_TextProcessor_makeAPIResultHandler(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).makeAPIResultHandler() + return _BJS_Closure_20BridgeJSRuntimeTests9APIResultO_SS.bridgeJSLower(ret) + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processOptionalDirection") +@_cdecl("bjs_TextProcessor_processOptionalDirection") +public func _bjs_TextProcessor_processOptionalDirection(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processOptionalDirection(_: _BJS_Closure_20BridgeJSRuntimeTestsSq9DirectionO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processOptionalTheme") +@_cdecl("bjs_TextProcessor_processOptionalTheme") +public func _bjs_TextProcessor_processOptionalTheme(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { + #if arch(wasm32) + let ret = TextProcessor.bridgeJSLiftParameter(_self).processOptionalTheme(_: _BJS_Closure_20BridgeJSRuntimeTestsSq5ThemeO_SS.bridgeJSLift(callback)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_TextProcessor_processOptionalAPIResult") +@_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)) + 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) - let ret = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalStringFormatter() - return _BJS_Closure_20BridgeJSRuntimeTestsSqSS_SS.bridgeJSLower(ret) + Unmanaged.fromOpaque(pointer).release() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeOptionalGreeterCreator") -@_cdecl("bjs_TextProcessor_makeOptionalGreeterCreator") -public func _bjs_TextProcessor_makeOptionalGreeterCreator(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +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 = TextProcessor.bridgeJSLiftParameter(_self).makeOptionalGreeterCreator() - return _BJS_Closure_20BridgeJSRuntimeTestsy_Sq7GreeterC.bridgeJSLower(ret) + 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_TextProcessor_processDirection") -@_cdecl("bjs_TextProcessor_processDirection") -public func _bjs_TextProcessor_processDirection(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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 = TextProcessor.bridgeJSLiftParameter(_self).processDirection(_: _BJS_Closure_20BridgeJSRuntimeTests9DirectionO_SS.bridgeJSLift(callback)) + let ret = OptionalHolder.bridgeJSLiftParameter(_self).nullableGreeter return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processTheme") -@_cdecl("bjs_TextProcessor_processTheme") -public func _bjs_TextProcessor_processTheme(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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) - let ret = TextProcessor.bridgeJSLiftParameter(_self).processTheme(_: _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_SS.bridgeJSLift(callback)) - return ret.bridgeJSLowerReturn() + OptionalHolder.bridgeJSLiftParameter(_self).nullableGreeter = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processHttpStatus") -@_cdecl("bjs_TextProcessor_processHttpStatus") -public func _bjs_TextProcessor_processHttpStatus(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Int32 { +@_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 = TextProcessor.bridgeJSLiftParameter(_self).processHttpStatus(_: _BJS_Closure_20BridgeJSRuntimeTests10HttpStatusO_Si.bridgeJSLift(callback)) + let ret = OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processAPIResult") -@_cdecl("bjs_TextProcessor_processAPIResult") -public func _bjs_TextProcessor_processAPIResult(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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) - let ret = TextProcessor.bridgeJSLiftParameter(_self).processAPIResult(_: _BJS_Closure_20BridgeJSRuntimeTests9APIResultO_SS.bridgeJSLift(callback)) - return ret.bridgeJSLowerReturn() + OptionalHolder.bridgeJSLiftParameter(_self).undefinedNumber = JSUndefinedOr.bridgeJSLiftParameter(valueIsSome, valueValue) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeDirectionChecker") -@_cdecl("bjs_TextProcessor_makeDirectionChecker") -public func _bjs_TextProcessor_makeDirectionChecker(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_expose(wasm, "bjs_OptionalHolder_deinit") +@_cdecl("bjs_OptionalHolder_deinit") +public func _bjs_OptionalHolder_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { #if arch(wasm32) - let ret = TextProcessor.bridgeJSLiftParameter(_self).makeDirectionChecker() - return _BJS_Closure_20BridgeJSRuntimeTests9DirectionO_Sb.bridgeJSLower(ret) + Unmanaged.fromOpaque(pointer).release() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeThemeValidator") -@_cdecl("bjs_TextProcessor_makeThemeValidator") -public func _bjs_TextProcessor_makeThemeValidator(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +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 = TextProcessor.bridgeJSLiftParameter(_self).makeThemeValidator() - return _BJS_Closure_20BridgeJSRuntimeTests5ThemeO_Sb.bridgeJSLower(ret) + let ret = OptionalPropertyHolder(optionalName: Optional.bridgeJSLiftParameter(optionalNameIsSome, optionalNameBytes, optionalNameLength)) + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeStatusCodeExtractor") -@_cdecl("bjs_TextProcessor_makeStatusCodeExtractor") -public func _bjs_TextProcessor_makeStatusCodeExtractor(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_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 = TextProcessor.bridgeJSLiftParameter(_self).makeStatusCodeExtractor() - return _BJS_Closure_20BridgeJSRuntimeTests10HttpStatusO_Si.bridgeJSLower(ret) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName + return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_makeAPIResultHandler") -@_cdecl("bjs_TextProcessor_makeAPIResultHandler") -public func _bjs_TextProcessor_makeAPIResultHandler(_ _self: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { +@_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) - let ret = TextProcessor.bridgeJSLiftParameter(_self).makeAPIResultHandler() - return _BJS_Closure_20BridgeJSRuntimeTests9APIResultO_SS.bridgeJSLower(ret) + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalName = Optional.bridgeJSLiftParameter(valueIsSome, valueBytes, valueLength) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processOptionalDirection") -@_cdecl("bjs_TextProcessor_processOptionalDirection") -public func _bjs_TextProcessor_processOptionalDirection(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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 = TextProcessor.bridgeJSLiftParameter(_self).processOptionalDirection(_: _BJS_Closure_20BridgeJSRuntimeTestsSq9DirectionO_SS.bridgeJSLift(callback)) + let ret = OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge return ret.bridgeJSLowerReturn() #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processOptionalTheme") -@_cdecl("bjs_TextProcessor_processOptionalTheme") -public func _bjs_TextProcessor_processOptionalTheme(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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) - let ret = TextProcessor.bridgeJSLiftParameter(_self).processOptionalTheme(_: _BJS_Closure_20BridgeJSRuntimeTestsSq5ThemeO_SS.bridgeJSLift(callback)) - return ret.bridgeJSLowerReturn() + OptionalPropertyHolder.bridgeJSLiftParameter(_self).optionalAge = Optional.bridgeJSLiftParameter(valueIsSome, valueValue) #else fatalError("Only available on WebAssembly") #endif } -@_expose(wasm, "bjs_TextProcessor_processOptionalAPIResult") -@_cdecl("bjs_TextProcessor_processOptionalAPIResult") -public func _bjs_TextProcessor_processOptionalAPIResult(_ _self: UnsafeMutableRawPointer, _ callback: Int32) -> Void { +@_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 = TextProcessor.bridgeJSLiftParameter(_self).processOptionalAPIResult(_: _BJS_Closure_20BridgeJSRuntimeTestsSq9APIResultO_SS.bridgeJSLift(callback)) + 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 @@ -8529,42 +8529,6 @@ func _$jsRoundTripString(_ v: String) throws(JSException) -> String { return String.bridgeJSLiftReturn(ret) } -#if arch(wasm32) -@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalNumberNull") -fileprivate func bjs_jsRoundTripOptionalNumberNull(_ vIsSome: Int32, _ vValue: Float64) -> Void -#else -fileprivate func bjs_jsRoundTripOptionalNumberNull(_ vIsSome: Int32, _ vValue: Float64) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$jsRoundTripOptionalNumberNull(_ v: Optional) throws(JSException) -> Optional { - let (vIsSome, vValue) = v.bridgeJSLowerParameter() - bjs_jsRoundTripOptionalNumberNull(vIsSome, vValue) - 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(_ vIsSome: Int32, _ vValue: Float64) -> Void -#else -fileprivate func bjs_jsRoundTripOptionalNumberUndefined(_ vIsSome: Int32, _ vValue: Float64) -> Void { - fatalError("Only available on WebAssembly") -} -#endif - -func _$jsRoundTripOptionalNumberUndefined(_ v: JSUndefinedOr) throws(JSException) -> JSUndefinedOr { - let (vIsSome, vValue) = v.bridgeJSLowerParameter() - bjs_jsRoundTripOptionalNumberUndefined(vIsSome, vValue) - if let error = _swift_js_take_exception() { - throw error - } - return JSUndefinedOr.bridgeJSLiftReturnFromSideChannel() -} - #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripJSValue") fileprivate func bjs_jsRoundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void @@ -9540,4 +9504,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 366115792..01d47b5a0 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -525,161 +525,6 @@ ], "swiftCallName" : "Internal.TestServer" }, - { - "constructor" : { - "abiName" : "bjs_OptionalHolder_init", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "parameters" : [ - { - "label" : "nullableGreeter", - "name" : "nullableGreeter", - "type" : { - "nullable" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - }, - "_1" : "null" - } - } - }, - { - "label" : "undefinedNumber", - "name" : "undefinedNumber", - "type" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "undefined" - } - } - } - ] - }, - "methods" : [ - - ], - "name" : "OptionalHolder", - "properties" : [ - { - "isReadonly" : false, - "isStatic" : false, - "name" : "nullableGreeter", - "type" : { - "nullable" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - }, - "_1" : "null" - } - } - }, - { - "isReadonly" : false, - "isStatic" : false, - "name" : "undefinedNumber", - "type" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "undefined" - } - } - } - ], - "swiftCallName" : "OptionalHolder" - }, - { - "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" : [ - { - "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" - }, { "constructor" : { "abiName" : "bjs_SimplePropertyHolder_init", @@ -3241,7 +3086,7 @@ }, { "constructor" : { - "abiName" : "bjs_Container_init", + "abiName" : "bjs_OptionalHolder_init", "effects" : { "isAsync" : false, "isStatic" : false, @@ -3249,25 +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" : { "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "Config" + "double" : { + } }, - "_1" : "null" + "_1" : "undefined" } } } @@ -3276,51 +3126,201 @@ "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" : { "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "Config" + "double" : { + } }, - "_1" : "null" + "_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" + } + } + }, + { + "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" + }, + { + "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" : [ @@ -4357,86 +4357,6 @@ "swiftCallName" : "API.NetworkingResult", "tsFullPath" : "API.NetworkingResult" }, - { - "cases" : [ - { - "associatedValues" : [ - { - "type" : { - "rawValueEnum" : { - "_0" : "Precision", - "_1" : "Float" - } - } - } - ], - "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" : [ { @@ -4539,35 +4459,26 @@ "associatedValues" : [ { "type" : { - "nullable" : { - "_0" : { - "swiftStruct" : { - "_0" : "Address" - } - }, - "_1" : "null" + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" } } } ], - "name" : "optStruct" + "name" : "precision" }, { "associatedValues" : [ { "type" : { - "nullable" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - }, - "_1" : "null" + "caseEnum" : { + "_0" : "Direction" } } } ], - "name" : "optClass" + "name" : "direction" }, { "associatedValues" : [ @@ -4575,8 +4486,9 @@ "type" : { "nullable" : { "_0" : { - "jsObject" : { - + "rawValueEnum" : { + "_0" : "Precision", + "_1" : "Float" } }, "_1" : "null" @@ -4584,7 +4496,7 @@ } } ], - "name" : "optJSObject" + "name" : "optPrecision" }, { "associatedValues" : [ @@ -4592,8 +4504,8 @@ "type" : { "nullable" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" + "caseEnum" : { + "_0" : "Direction" } }, "_1" : "null" @@ -4601,45 +4513,7 @@ } } ], - "name" : "optNestedEnum" - }, - { - "associatedValues" : [ - { - "type" : { - "nullable" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } - } - }, - "_1" : "null" - } - } - } - ], - "name" : "optArray" - }, - { - "associatedValues" : [ - { - "type" : { - "nullable" : { - "_0" : { - "jsObject" : { - "_0" : "Foo" - } - }, - "_1" : "null" - } - } - } - ], - "name" : "optJsClass" + "name" : "optDirection" }, { "associatedValues" : [ @@ -4649,116 +4523,15 @@ } ], "emitStyle" : "const", - "name" : "OptionalAllTypesResult", - "staticMethods" : [ - - ], - "staticProperties" : [ - - ], - "swiftCallName" : "OptionalAllTypesResult", - "tsFullPath" : "OptionalAllTypesResult" - }, - { - "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", + "name" : "TypedPayloadResult", "staticMethods" : [ ], "staticProperties" : [ ], - "swiftCallName" : "APIOptionalResult", - "tsFullPath" : "APIOptionalResult" + "swiftCallName" : "TypedPayloadResult", + "tsFullPath" : "TypedPayloadResult" }, { "cases" : [ @@ -5207,274 +4980,501 @@ ], "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" + } + } } - } - } - ], - "returnType" : { - "int" : { - - } - } - }, - { - "abiName" : "bjs_roundTripUInt", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripUInt", - "parameters" : [ + ], + "name" : "optStruct" + }, { - "label" : "v", - "name" : "v", - "type" : { - "uint" : { - + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } + } } - } - } - ], - "returnType" : { - "uint" : { - - } - } - }, - { - "abiName" : "bjs_roundTripFloat", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripFloat", - "parameters" : [ + ], + "name" : "optClass" + }, { - "label" : "v", - "name" : "v", - "type" : { - "float" : { + "associatedValues" : [ + { + "type" : { + "nullable" : { + "_0" : { + "jsObject" : { + } + }, + "_1" : "null" + } + } } - } - } - ], - "returnType" : { - "float" : { - - } - } - }, - { - "abiName" : "bjs_roundTripDouble", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripDouble", - "parameters" : [ + ], + "name" : "optJSObject" + }, { - "label" : "v", - "name" : "v", - "type" : { - "double" : { + "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" : { - "double" : { + "emitStyle" : "const", + "name" : "OptionalAllTypesResult", + "staticMethods" : [ - } - } + ], + "staticProperties" : [ + + ], + "swiftCallName" : "OptionalAllTypesResult", + "tsFullPath" : "OptionalAllTypesResult" }, { - "abiName" : "bjs_roundTripBool", + "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" : "roundTripBool", + "name" : "roundTripVoid", "parameters" : [ - { - "label" : "v", - "name" : "v", - "type" : { - "bool" : { - } - } - } ], "returnType" : { - "bool" : { + "void" : { } } }, { - "abiName" : "bjs_roundTripString", + "abiName" : "bjs_roundTripInt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripString", + "name" : "roundTripInt", "parameters" : [ { "label" : "v", "name" : "v", "type" : { - "string" : { + "int" : { } } } ], "returnType" : { - "string" : { + "int" : { } } }, { - "abiName" : "bjs_roundTripSwiftHeapObject", + "abiName" : "bjs_roundTripUInt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripSwiftHeapObject", + "name" : "roundTripUInt", "parameters" : [ { "label" : "v", "name" : "v", "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "uint" : { + } } } ], "returnType" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "uint" : { + } } }, { - "abiName" : "bjs_roundTripUnsafeRawPointer", + "abiName" : "bjs_roundTripFloat", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeRawPointer", + "name" : "roundTripFloat", "parameters" : [ { "label" : "v", "name" : "v", "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "float" : { + } } } ], "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "float" : { + } } }, { - "abiName" : "bjs_roundTripUnsafeMutableRawPointer", + "abiName" : "bjs_roundTripDouble", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeMutableRawPointer", + "name" : "roundTripDouble", "parameters" : [ { "label" : "v", "name" : "v", "type" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "double" : { + } } } ], "returnType" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "double" : { + } } }, { - "abiName" : "bjs_roundTripOpaquePointer", + "abiName" : "bjs_roundTripBool", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOpaquePointer", + "name" : "roundTripBool", "parameters" : [ { "label" : "v", "name" : "v", "type" : { - "unsafePointer" : { + "bool" : { + + } + } + } + ], + "returnType" : { + "bool" : { + + } + } + }, + { + "abiName" : "bjs_roundTripString", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripString", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_roundTripSwiftHeapObject", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripSwiftHeapObject", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + ], + "returnType" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + }, + { + "abiName" : "bjs_roundTripUnsafeRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripUnsafeRawPointer", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + } + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } + }, + { + "abiName" : "bjs_roundTripUnsafeMutableRawPointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripUnsafeMutableRawPointer", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + } + ], + "returnType" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + }, + { + "abiName" : "bjs_roundTripOpaquePointer", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOpaquePointer", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "unsafePointer" : { "_0" : { "kind" : "opaquePointer" } @@ -7259,445 +7259,296 @@ } }, { - "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" : { - "nullable" : { - "_0" : { - "string" : { - - } - }, - "_1" : "null" + "associatedValueEnum" : { + "_0" : "AllTypesResult" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "string" : { - - } - }, - "_1" : "null" + "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" : { - "nullable" : { - "_0" : { - "int" : { - - } - }, - "_1" : "null" + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "int" : { - - } - }, - "_1" : "null" + "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" : { - "nullable" : { - "_0" : { - "bool" : { + "int" : { - } - }, - "_1" : "null" } } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "bool" : { + }, + { + "label" : "floatValue", + "name" : "floatValue", + "type" : { + "float" : { } - }, - "_1" : "null" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalFloat", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalFloat", - "parameters" : [ + } + }, { - "label" : "number", - "name" : "number", + "label" : "doubleValue", + "name" : "doubleValue", "type" : { - "nullable" : { - "_0" : { - "float" : { + "double" : { - } - }, - "_1" : "null" } } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "float" : { + }, + { + "label" : "boolValue", + "name" : "boolValue", + "type" : { + "bool" : { } - }, - "_1" : "null" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalDouble", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalDouble", - "parameters" : [ + } + }, { - "label" : "precision", - "name" : "precision", + "label" : "stringValue", + "name" : "stringValue", "type" : { - "nullable" : { - "_0" : { - "double" : { + "string" : { - } - }, - "_1" : "null" } } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "null" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalSyntax", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalSyntax", - "parameters" : [ + }, { - "label" : "name", - "name" : "name", + "label" : "jsObject", + "name" : "jsObject", "type" : { - "nullable" : { - "_0" : { - "string" : { + "jsObject" : { - } - }, - "_1" : "null" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "string" : { - - } - }, - "_1" : "null" + "swiftHeapObject" : { + "_0" : "PropertyHolder" } } }, { - "abiName" : "bjs_roundTripOptionalMixSyntax", + "abiName" : "bjs_testPropertyHolder", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalMixSyntax", + "name" : "testPropertyHolder", "parameters" : [ { - "label" : "name", - "name" : "name", + "label" : "holder", + "name" : "holder", "type" : { - "nullable" : { - "_0" : { - "string" : { - - } - }, - "_1" : "null" + "swiftHeapObject" : { + "_0" : "PropertyHolder" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "string" : { + "string" : { - } - }, - "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalSwiftSyntax", + "abiName" : "bjs_resetObserverCounts", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalSwiftSyntax", + "name" : "resetObserverCounts", "parameters" : [ - { - "label" : "name", - "name" : "name", - "type" : { - "nullable" : { - "_0" : { - "string" : { - } - }, - "_1" : "null" - } - } - } ], "returnType" : { - "nullable" : { - "_0" : { - "string" : { + "void" : { - } - }, - "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalWithSpaces", + "abiName" : "bjs_getObserverStats", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalWithSpaces", + "name" : "getObserverStats", "parameters" : [ - { - "label" : "value", - "name" : "value", - "type" : { - "nullable" : { - "_0" : { - "double" : { - } - }, - "_1" : "null" - } - } - } ], "returnType" : { - "nullable" : { - "_0" : { - "double" : { + "string" : { - } - }, - "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalTypeAlias", + "abiName" : "bjs_testStringDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTypeAlias", + "name" : "testStringDefault", "parameters" : [ { - "label" : "age", - "name" : "age", + "defaultValue" : { + "string" : { + "_0" : "Hello World" + } + }, + "label" : "message", + "name" : "message", "type" : { - "nullable" : { - "_0" : { - "int" : { + "string" : { - } - }, - "_1" : "null" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "int" : { + "string" : { - } - }, - "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalStatus", + "abiName" : "bjs_testIntDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStatus", + "name" : "testIntDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "int" : { + "_0" : 42 + } + }, + "label" : "count", + "name" : "count", "type" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Status" - } - }, - "_1" : "null" + "int" : { + } } } ], "returnType" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Status" - } - }, - "_1" : "null" + "int" : { + } } }, { - "abiName" : "bjs_roundTripOptionalTheme", + "abiName" : "bjs_testBoolDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTheme", + "name" : "testBoolDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "bool" : { + "_0" : true + } + }, + "label" : "flag", + "name" : "flag", "type" : { - "nullable" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - }, - "_1" : "null" + "bool" : { + } } } ], "returnType" : { - "nullable" : { - "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" - } - }, - "_1" : "null" + "bool" : { + } } }, { - "abiName" : "bjs_roundTripOptionalHttpStatus", + "abiName" : "bjs_testOptionalDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalHttpStatus", + "name" : "testOptionalDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "null" : { + + } + }, + "label" : "name", + "name" : "name", "type" : { "nullable" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "string" : { + } }, "_1" : "null" @@ -7708,9 +7559,8 @@ "returnType" : { "nullable" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "string" : { + } }, "_1" : "null" @@ -7718,530 +7568,671 @@ } }, { - "abiName" : "bjs_roundTripOptionalTSDirection", + "abiName" : "bjs_testMultipleDefaults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTSDirection", + "name" : "testMultipleDefaults", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "string" : { + "_0" : "Default Title" + } + }, + "label" : "title", + "name" : "title", "type" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" - } - }, - "_1" : "null" + "string" : { + } } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "TSDirection" + }, + { + "defaultValue" : { + "int" : { + "_0" : -10 } }, - "_1" : "null" - } - } - }, - { - "abiName" : "bjs_roundTripOptionalTSTheme", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "roundTripOptionalTSTheme", - "parameters" : [ + "label" : "count", + "name" : "count", + "type" : { + "int" : { + + } + } + }, { - "label" : "value", - "name" : "value", + "defaultValue" : { + "bool" : { + "_0" : false + } + }, + "label" : "enabled", + "name" : "enabled", "type" : { - "nullable" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - }, - "_1" : "null" + "bool" : { + } } } ], "returnType" : { - "nullable" : { - "_0" : { - "rawValueEnum" : { - "_0" : "TSTheme", - "_1" : "String" - } - }, - "_1" : "null" + "string" : { + } } }, { - "abiName" : "bjs_roundTripOptionalNetworkingAPIMethod", + "abiName" : "bjs_testSimpleEnumDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalNetworkingAPIMethod", + "name" : "testSimpleEnumDefault", "parameters" : [ { - "label" : "_", - "name" : "method", + "defaultValue" : { + "enumCase" : { + "_0" : "Status", + "_1" : "success" + } + }, + "label" : "status", + "name" : "status", "type" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Networking.API.Method" - } - }, - "_1" : "null" + "caseEnum" : { + "_0" : "Status" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Networking.API.Method" - } - }, - "_1" : "null" + "caseEnum" : { + "_0" : "Status" } } }, { - "abiName" : "bjs_roundTripOptionalAPIResult", + "abiName" : "bjs_testDirectionDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalAPIResult", + "name" : "testDirectionDefault", "parameters" : [ { - "label" : "value", - "name" : "value", + "defaultValue" : { + "enumCase" : { + "_0" : "Direction", + "_1" : "north" + } + }, + "label" : "direction", + "name" : "direction", "type" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "_1" : "null" + "caseEnum" : { + "_0" : "Direction" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "_1" : "null" + "caseEnum" : { + "_0" : "Direction" } } }, { - "abiName" : "bjs_roundTripTypedPayloadResult", + "abiName" : "bjs_testRawStringEnumDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripTypedPayloadResult", + "name" : "testRawStringEnumDefault", "parameters" : [ { - "label" : "_", - "name" : "result", + "defaultValue" : { + "enumCase" : { + "_0" : "Theme", + "_1" : "light" + } + }, + "label" : "theme", + "name" : "theme", "type" : { - "associatedValueEnum" : { - "_0" : "TypedPayloadResult" + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } } ], "returnType" : { - "associatedValueEnum" : { - "_0" : "TypedPayloadResult" + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } } }, { - "abiName" : "bjs_roundTripOptionalTypedPayloadResult", + "abiName" : "bjs_testComplexInit", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalTypedPayloadResult", + "name" : "testComplexInit", "parameters" : [ { - "label" : "_", - "name" : "result", - "type" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "TypedPayloadResult" + "defaultValue" : { + "objectWithArguments" : { + "_0" : "Greeter", + "_1" : [ + { + "string" : { + "_0" : "DefaultGreeter" + } } - }, - "_1" : "null" + ] + } + }, + "label" : "greeter", + "name" : "greeter", + "type" : { + "swiftHeapObject" : { + "_0" : "Greeter" } } } ], "returnType" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "TypedPayloadResult" - } - }, - "_1" : "null" + "string" : { + } } }, { - "abiName" : "bjs_compareAPIResults", + "abiName" : "bjs_testEmptyInit", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "compareAPIResults", + "name" : "testEmptyInit", "parameters" : [ { - "label" : "_", - "name" : "r1", - "type" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "_1" : "null" + "defaultValue" : { + "object" : { + "_0" : "StaticPropertyHolder" } - } - }, - { + }, "label" : "_", - "name" : "r2", + "name" : "object", "type" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "APIResult" - } - }, - "_1" : "null" + "swiftHeapObject" : { + "_0" : "StaticPropertyHolder" } } } ], "returnType" : { - "string" : { - + "swiftHeapObject" : { + "_0" : "StaticPropertyHolder" } } }, { - "abiName" : "bjs_roundTripOptionalComplexResult", + "abiName" : "bjs_arrayWithDefault", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalComplexResult", + "name" : "arrayWithDefault", "parameters" : [ { - "label" : "_", - "name" : "result", - "type" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" - } - }, - "_1" : "null" + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 1 + } + }, + { + "int" : { + "_0" : 2 + } + }, + { + "int" : { + "_0" : 3 + } + } + ] + } + }, + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } } } } ], "returnType" : { - "nullable" : { - "_0" : { - "associatedValueEnum" : { - "_0" : "ComplexResult" + "int" : { + + } + } + }, + { + "abiName" : "bjs_arrayWithOptionalDefault", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "arrayWithOptionalDefault", + "parameters" : [ + { + "defaultValue" : { + "null" : { + } }, - "_1" : "null" + "label" : "_", + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "int" : { + } } }, { - "abiName" : "bjs_roundTripAllTypesResult", + "abiName" : "bjs_arrayMixedDefaults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripAllTypesResult", + "name" : "arrayMixedDefaults", "parameters" : [ { - "label" : "_", - "name" : "result", + "defaultValue" : { + "string" : { + "_0" : "Sum" + } + }, + "label" : "prefix", + "name" : "prefix", "type" : { - "associatedValueEnum" : { - "_0" : "AllTypesResult" + "string" : { + + } + } + }, + { + "defaultValue" : { + "array" : { + "_0" : [ + { + "int" : { + "_0" : 10 + } + }, + { + "int" : { + "_0" : 20 + } + } + ] + } + }, + "label" : "values", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "defaultValue" : { + "string" : { + "_0" : "!" + } + }, + "label" : "suffix", + "name" : "suffix", + "type" : { + "string" : { + } } } ], "returnType" : { - "associatedValueEnum" : { - "_0" : "AllTypesResult" + "string" : { + } } }, { - "abiName" : "bjs_roundTripOptionalAllTypesResult", + "abiName" : "bjs_formatName", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalAllTypesResult", + "name" : "formatName", "parameters" : [ { "label" : "_", - "name" : "result", + "name" : "name", "type" : { - "nullable" : { + "string" : { + + } + } + }, + { + "label" : "transform", + "name" : "transform", + "type" : { + "closure" : { "_0" : { - "associatedValueEnum" : { - "_0" : "AllTypesResult" + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSS_SS", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } } - }, - "_1" : "null" + } } } } ], "returnType" : { - "nullable" : { + "string" : { + + } + } + }, + { + "abiName" : "bjs_makeFormatter", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "makeFormatter", + "parameters" : [ + { + "label" : "prefix", + "name" : "prefix", + "type" : { + "string" : { + + } + } + } + ], + "returnType" : { + "closure" : { "_0" : { - "associatedValueEnum" : { - "_0" : "AllTypesResult" + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSS_SS", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "string" : { + + } + } + ], + "returnType" : { + "string" : { + + } } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_roundTripOptionalPayloadResult", + "abiName" : "bjs_makeAdder", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalPayloadResult", + "name" : "makeAdder", + "parameters" : [ + { + "label" : "base", + "name" : "base", + "type" : { + "int" : { + + } + } + } + ], + "returnType" : { + "closure" : { + "_0" : { + "isAsync" : false, + "isThrows" : false, + "mangleName" : "20BridgeJSRuntimeTestsSi_Si", + "moduleName" : "BridgeJSRuntimeTests", + "parameters" : [ + { + "int" : { + + } + } + ], + "returnType" : { + "int" : { + + } + } + } + } + } + }, + { + "abiName" : "bjs_roundTripIntArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripIntArray", "parameters" : [ { "label" : "_", - "name" : "result", + "name" : "values", "type" : { - "associatedValueEnum" : { - "_0" : "OptionalAllTypesResult" + "array" : { + "_0" : { + "int" : { + + } + } } } } ], "returnType" : { - "associatedValueEnum" : { - "_0" : "OptionalAllTypesResult" + "array" : { + "_0" : { + "int" : { + + } + } } } }, { - "abiName" : "bjs_roundTripOptionalPayloadResultOpt", + "abiName" : "bjs_roundTripStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalPayloadResultOpt", + "name" : "roundTripStringArray", "parameters" : [ { "label" : "_", - "name" : "result", + "name" : "values", "type" : { - "nullable" : { + "array" : { "_0" : { - "associatedValueEnum" : { - "_0" : "OptionalAllTypesResult" + "string" : { + } - }, - "_1" : "null" + } } } } ], "returnType" : { - "nullable" : { + "array" : { "_0" : { - "associatedValueEnum" : { - "_0" : "OptionalAllTypesResult" + "string" : { + } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_roundTripOptionalClass", + "abiName" : "bjs_roundTripDoubleArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalClass", + "name" : "roundTripDoubleArray", "parameters" : [ { - "label" : "value", - "name" : "value", + "label" : "_", + "name" : "values", "type" : { - "nullable" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "double" : { + } - }, - "_1" : "null" + } } } } ], "returnType" : { - "nullable" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "double" : { + } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_roundTripOptionalGreeter", + "abiName" : "bjs_roundTripBoolArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalGreeter", + "name" : "roundTripBoolArray", "parameters" : [ { "label" : "_", - "name" : "value", + "name" : "values", "type" : { - "nullable" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "bool" : { + } - }, - "_1" : "null" + } } } } ], "returnType" : { - "nullable" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "bool" : { + } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_applyOptionalGreeter", + "abiName" : "bjs_roundTripDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "applyOptionalGreeter", + "name" : "roundTripDirectionArray", "parameters" : [ { "label" : "_", - "name" : "value", - "type" : { - "nullable" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - }, - "_1" : "null" - } - } - }, - { - "label" : "_", - "name" : "transform", + "name" : "values", "type" : { - "closure" : { + "array" : { "_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" - } + "caseEnum" : { + "_0" : "Direction" } } } @@ -8249,336 +8240,420 @@ } ], "returnType" : { - "nullable" : { + "array" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "caseEnum" : { + "_0" : "Direction" } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_makeOptionalHolder", + "abiName" : "bjs_roundTripStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "makeOptionalHolder", + "name" : "roundTripStatusArray", "parameters" : [ { - "label" : "nullableGreeter", - "name" : "nullableGreeter", - "type" : { - "nullable" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - }, - "_1" : "null" - } - } - }, - { - "label" : "undefinedNumber", - "name" : "undefinedNumber", + "label" : "_", + "name" : "values", "type" : { - "nullable" : { + "array" : { "_0" : { - "double" : { - + "caseEnum" : { + "_0" : "Status" } - }, - "_1" : "undefined" + } } } } ], "returnType" : { - "swiftHeapObject" : { - "_0" : "OptionalHolder" + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + } } } }, { - "abiName" : "bjs_roundTripOptionalAPIOptionalResult", + "abiName" : "bjs_roundTripThemeArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalAPIOptionalResult", + "name" : "roundTripThemeArray", "parameters" : [ { - "label" : "result", - "name" : "result", + "label" : "_", + "name" : "values", "type" : { - "nullable" : { + "array" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } - }, - "_1" : "null" + } } } } ], "returnType" : { - "nullable" : { + "array" : { "_0" : { - "associatedValueEnum" : { - "_0" : "APIOptionalResult" + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } - }, - "_1" : "null" + } } } }, { - "abiName" : "bjs_createPropertyHolder", + "abiName" : "bjs_roundTripHttpStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "createPropertyHolder", + "name" : "roundTripHttpStatusArray", "parameters" : [ { - "label" : "intValue", - "name" : "intValue", - "type" : { - "int" : { - - } - } - }, - { - "label" : "floatValue", - "name" : "floatValue", - "type" : { - "float" : { - - } - } - }, - { - "label" : "doubleValue", - "name" : "doubleValue", - "type" : { - "double" : { - - } - } - }, - { - "label" : "boolValue", - "name" : "boolValue", + "label" : "_", + "name" : "values", "type" : { - "bool" : { - + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" + } + } } } - }, - { - "label" : "stringValue", - "name" : "stringValue", - "type" : { - "string" : { - + } + ], + "returnType" : { + "array" : { + "_0" : { + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" } } - }, + } + } + }, + { + "abiName" : "bjs_roundTripDataPointArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripDataPointArray", + "parameters" : [ { - "label" : "jsObject", - "name" : "jsObject", + "label" : "_", + "name" : "points", "type" : { - "jsObject" : { - + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } } ], "returnType" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } } } }, { - "abiName" : "bjs_testPropertyHolder", + "abiName" : "bjs_roundTripGreeterArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testPropertyHolder", + "name" : "roundTripGreeterArray", "parameters" : [ { - "label" : "holder", - "name" : "holder", + "label" : "_", + "name" : "greeters", "type" : { - "swiftHeapObject" : { - "_0" : "PropertyHolder" + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } } } } ], "returnType" : { - "string" : { - + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } } } }, { - "abiName" : "bjs_resetObserverCounts", + "abiName" : "bjs_roundTripOptionalIntArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "resetObserverCounts", + "name" : "roundTripOptionalIntArray", "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + } + }, + "_1" : "null" + } + } + } + } + } ], "returnType" : { - "void" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "int" : { + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_getObserverStats", + "abiName" : "bjs_roundTripOptionalStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "getObserverStats", + "name" : "roundTripOptionalStringArray", "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + } + }, + "_1" : "null" + } + } + } + } + } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "string" : { + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testStringDefault", + "abiName" : "bjs_roundTripOptionalDataPointArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testStringDefault", + "name" : "roundTripOptionalDataPointArray", "parameters" : [ { - "defaultValue" : { - "string" : { - "_0" : "Hello World" - } - }, - "label" : "message", - "name" : "message", + "label" : "_", + "name" : "points", "type" : { - "string" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "string" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testIntDefault", + "abiName" : "bjs_roundTripOptionalDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testIntDefault", + "name" : "roundTripOptionalDirectionArray", "parameters" : [ { - "defaultValue" : { - "int" : { - "_0" : 42 - } - }, - "label" : "count", - "name" : "count", + "label" : "_", + "name" : "directions", "type" : { - "int" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "int" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testBoolDefault", + "abiName" : "bjs_roundTripOptionalStatusArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testBoolDefault", + "name" : "roundTripOptionalStatusArray", "parameters" : [ { - "defaultValue" : { - "bool" : { - "_0" : true - } - }, - "label" : "flag", - "name" : "flag", + "label" : "_", + "name" : "statuses", "type" : { - "bool" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + }, + "_1" : "null" + } + } } } } ], "returnType" : { - "bool" : { - + "array" : { + "_0" : { + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" + } + }, + "_1" : "null" + } + } } } }, { - "abiName" : "bjs_testOptionalDefault", + "abiName" : "bjs_roundTripOptionalIntArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testOptionalDefault", - "parameters" : [ - { - "defaultValue" : { - "null" : { - - } - }, - "label" : "name", - "name" : "name", + "name" : "roundTripOptionalIntArrayType", + "parameters" : [ + { + "label" : "_", + "name" : "values", "type" : { "nullable" : { "_0" : { - "string" : { + "array" : { + "_0" : { + "int" : { + } + } } }, "_1" : "null" @@ -8589,8 +8664,12 @@ "returnType" : { "nullable" : { "_0" : { - "string" : { + "array" : { + "_0" : { + "int" : { + } + } } }, "_1" : "null" @@ -8598,263 +8677,235 @@ } }, { - "abiName" : "bjs_testMultipleDefaults", + "abiName" : "bjs_roundTripOptionalStringArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testMultipleDefaults", + "name" : "roundTripOptionalStringArrayType", "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" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + } + } + } + }, + "_1" : "null" } } } ], "returnType" : { - "string" : { + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + } + } + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_testSimpleEnumDefault", + "abiName" : "bjs_roundTripOptionalGreeterArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testSimpleEnumDefault", + "name" : "roundTripOptionalGreeterArrayType", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Status", - "_1" : "success" - } - }, - "label" : "status", - "name" : "status", + "label" : "_", + "name" : "greeters", "type" : { - "caseEnum" : { - "_0" : "Status" + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + }, + "_1" : "null" } } } ], "returnType" : { - "caseEnum" : { - "_0" : "Status" + "nullable" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_testDirectionDefault", + "abiName" : "bjs_roundTripNestedIntArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testDirectionDefault", + "name" : "roundTripNestedIntArray", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Direction", - "_1" : "north" - } - }, - "label" : "direction", - "name" : "direction", + "label" : "_", + "name" : "values", "type" : { - "caseEnum" : { - "_0" : "Direction" + "array" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } } } } ], "returnType" : { - "caseEnum" : { - "_0" : "Direction" + "array" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } } } }, { - "abiName" : "bjs_testRawStringEnumDefault", + "abiName" : "bjs_roundTripNestedStringArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testRawStringEnumDefault", + "name" : "roundTripNestedStringArray", "parameters" : [ { - "defaultValue" : { - "enumCase" : { - "_0" : "Theme", - "_1" : "light" - } - }, - "label" : "theme", - "name" : "theme", + "label" : "_", + "name" : "values", "type" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "array" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } } } } ], "returnType" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "array" : { + "_0" : { + "array" : { + "_0" : { + "string" : { + + } + } + } + } } } }, { - "abiName" : "bjs_testComplexInit", + "abiName" : "bjs_roundTripNestedDoubleArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "testComplexInit", + "name" : "roundTripNestedDoubleArray", "parameters" : [ { - "defaultValue" : { - "objectWithArguments" : { - "_0" : "Greeter", - "_1" : [ - { - "string" : { - "_0" : "DefaultGreeter" + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "double" : { + + } } } - ] - } - }, - "label" : "greeter", - "name" : "greeter", - "type" : { - "swiftHeapObject" : { - "_0" : "Greeter" + } } } } ], "returnType" : { - "string" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "double" : { - } - } - }, - { - "abiName" : "bjs_testEmptyInit", - "effects" : { - "isAsync" : false, - "isStatic" : false, - "isThrows" : false - }, - "name" : "testEmptyInit", - "parameters" : [ - { - "defaultValue" : { - "object" : { - "_0" : "StaticPropertyHolder" - } - }, - "label" : "_", - "name" : "object", - "type" : { - "swiftHeapObject" : { - "_0" : "StaticPropertyHolder" + } + } } } } - ], - "returnType" : { - "swiftHeapObject" : { - "_0" : "StaticPropertyHolder" - } } }, { - "abiName" : "bjs_arrayWithDefault", + "abiName" : "bjs_roundTripNestedBoolArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayWithDefault", + "name" : "roundTripNestedBoolArray", "parameters" : [ { - "defaultValue" : { - "array" : { - "_0" : [ - { - "int" : { - "_0" : 1 - } - }, - { - "int" : { - "_0" : 2 - } - }, - { - "int" : { - "_0" : 3 - } - } - ] - } - }, "label" : "_", "name" : "values", "type" : { "array" : { "_0" : { - "int" : { + "array" : { + "_0" : { + "bool" : { + } + } } } } @@ -8862,162 +8913,122 @@ } ], "returnType" : { - "int" : { + "array" : { + "_0" : { + "array" : { + "_0" : { + "bool" : { + } + } + } + } } } }, { - "abiName" : "bjs_arrayWithOptionalDefault", + "abiName" : "bjs_roundTripNestedDataPointArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayWithOptionalDefault", + "name" : "roundTripNestedDataPointArray", "parameters" : [ { - "defaultValue" : { - "null" : { - - } - }, "label" : "_", - "name" : "values", + "name" : "points", "type" : { - "nullable" : { + "array" : { "_0" : { "array" : { "_0" : { - "int" : { - + "swiftStruct" : { + "_0" : "DataPoint" } } } - }, - "_1" : "null" + } } } } ], "returnType" : { - "int" : { - + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftStruct" : { + "_0" : "DataPoint" + } + } + } + } } } }, { - "abiName" : "bjs_arrayMixedDefaults", + "abiName" : "bjs_roundTripNestedDirectionArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "arrayMixedDefaults", + "name" : "roundTripNestedDirectionArray", "parameters" : [ { - "defaultValue" : { - "string" : { - "_0" : "Sum" - } - }, - "label" : "prefix", - "name" : "prefix", + "label" : "_", + "name" : "directions", "type" : { - "string" : { - - } - } - }, - { - "defaultValue" : { "array" : { - "_0" : [ - { - "int" : { - "_0" : 10 - } - }, - { - "int" : { - "_0" : 20 + "_0" : { + "array" : { + "_0" : { + "caseEnum" : { + "_0" : "Direction" + } } } - ] + } } - }, - "label" : "values", - "name" : "values", - "type" : { + } + } + ], + "returnType" : { + "array" : { + "_0" : { "array" : { "_0" : { - "int" : { - + "caseEnum" : { + "_0" : "Direction" } } } } - }, - { - "defaultValue" : { - "string" : { - "_0" : "!" - } - }, - "label" : "suffix", - "name" : "suffix", - "type" : { - "string" : { - - } - } - } - ], - "returnType" : { - "string" : { - } } }, { - "abiName" : "bjs_formatName", + "abiName" : "bjs_roundTripNestedGreeterArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "formatName", + "name" : "roundTripNestedGreeterArray", "parameters" : [ { "label" : "_", - "name" : "name", - "type" : { - "string" : { - - } - } - }, - { - "label" : "transform", - "name" : "transform", + "name" : "greeters", "type" : { - "closure" : { + "array" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSS_SS", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { - "string" : { - + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" } } - ], - "returnType" : { - "string" : { - - } } } } @@ -9025,47 +9036,87 @@ } ], "returnType" : { - "string" : { - + "array" : { + "_0" : { + "array" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + } + } + } } } }, { - "abiName" : "bjs_makeFormatter", + "abiName" : "bjs_roundTripUnsafeRawPointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "makeFormatter", + "name" : "roundTripUnsafeRawPointerArray", "parameters" : [ { - "label" : "prefix", - "name" : "prefix", + "label" : "_", + "name" : "values", "type" : { - "string" : { - + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" + } + } + } } } } ], "returnType" : { - "closure" : { + "array" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSS_SS", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { - "string" : { - - } + "unsafePointer" : { + "_0" : { + "kind" : "unsafeRawPointer" } - ], - "returnType" : { - "string" : { - + } + } + } + } + }, + { + "abiName" : "bjs_roundTripUnsafeMutableRawPointerArray", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripUnsafeMutableRawPointerArray", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" + } + } + } + } + } + } + ], + "returnType" : { + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutableRawPointer" } } } @@ -9073,41 +9124,36 @@ } }, { - "abiName" : "bjs_makeAdder", + "abiName" : "bjs_roundTripOpaquePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "makeAdder", + "name" : "roundTripOpaquePointerArray", "parameters" : [ { - "label" : "base", - "name" : "base", + "label" : "_", + "name" : "values", "type" : { - "int" : { - + "array" : { + "_0" : { + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" + } + } + } } } } ], "returnType" : { - "closure" : { + "array" : { "_0" : { - "isAsync" : false, - "isThrows" : false, - "mangleName" : "20BridgeJSRuntimeTestsSi_Si", - "moduleName" : "BridgeJSRuntimeTests", - "parameters" : [ - { - "int" : { - - } - } - ], - "returnType" : { - "int" : { - + "unsafePointer" : { + "_0" : { + "kind" : "opaquePointer" } } } @@ -9115,13 +9161,13 @@ } }, { - "abiName" : "bjs_roundTripIntArray", + "abiName" : "bjs_roundTripUnsafePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripIntArray", + "name" : "roundTripUnsafePointerArray", "parameters" : [ { "label" : "_", @@ -9129,8 +9175,11 @@ "type" : { "array" : { "_0" : { - "int" : { - + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } } } } @@ -9140,21 +9189,24 @@ "returnType" : { "array" : { "_0" : { - "int" : { - + "unsafePointer" : { + "_0" : { + "kind" : "unsafePointer", + "pointee" : "UInt8" + } } } } } }, { - "abiName" : "bjs_roundTripStringArray", + "abiName" : "bjs_roundTripUnsafeMutablePointerArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripStringArray", + "name" : "roundTripUnsafeMutablePointerArray", "parameters" : [ { "label" : "_", @@ -9162,8 +9214,11 @@ "type" : { "array" : { "_0" : { - "string" : { - + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } } } } @@ -9173,30 +9228,33 @@ "returnType" : { "array" : { "_0" : { - "string" : { - + "unsafePointer" : { + "_0" : { + "kind" : "unsafeMutablePointer", + "pointee" : "UInt8" + } } } } } }, { - "abiName" : "bjs_roundTripDoubleArray", + "abiName" : "bjs_consumeDataProcessorArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDoubleArray", + "name" : "consumeDataProcessorArrayType", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "processors", "type" : { "array" : { "_0" : { - "double" : { - + "swiftProtocol" : { + "_0" : "DataProcessor" } } } @@ -9204,32 +9262,28 @@ } ], "returnType" : { - "array" : { - "_0" : { - "double" : { + "int" : { - } - } } } }, { - "abiName" : "bjs_roundTripBoolArray", + "abiName" : "bjs_roundTripDataProcessorArrayType", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripBoolArray", + "name" : "roundTripDataProcessorArrayType", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "processors", "type" : { "array" : { "_0" : { - "bool" : { - + "swiftProtocol" : { + "_0" : "DataProcessor" } } } @@ -9239,30 +9293,30 @@ "returnType" : { "array" : { "_0" : { - "bool" : { - + "swiftProtocol" : { + "_0" : "DataProcessor" } } } } }, { - "abiName" : "bjs_roundTripDirectionArray", + "abiName" : "bjs_roundTripJSObjectArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDirectionArray", + "name" : "roundTripJSObjectArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "objects", "type" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "jsObject" : { + } } } @@ -9272,30 +9326,35 @@ "returnType" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Direction" + "jsObject" : { + } } } } }, { - "abiName" : "bjs_roundTripStatusArray", + "abiName" : "bjs_roundTripOptionalJSObjectArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripStatusArray", + "name" : "roundTripOptionalJSObjectArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "objects", "type" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" } } } @@ -9305,31 +9364,35 @@ "returnType" : { "array" : { "_0" : { - "caseEnum" : { - "_0" : "Status" + "nullable" : { + "_0" : { + "jsObject" : { + + } + }, + "_1" : "null" } } } } }, { - "abiName" : "bjs_roundTripThemeArray", + "abiName" : "bjs_roundTripFooArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripThemeArray", + "name" : "roundTripFooArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "foos", "type" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "jsObject" : { + "_0" : "Foo" } } } @@ -9339,32 +9402,35 @@ "returnType" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "Theme", - "_1" : "String" + "jsObject" : { + "_0" : "Foo" } } } } }, { - "abiName" : "bjs_roundTripHttpStatusArray", + "abiName" : "bjs_roundTripOptionalFooArray", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripHttpStatusArray", + "name" : "roundTripOptionalFooArray", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "foos", "type" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" } } } @@ -9374,316 +9440,280 @@ "returnType" : { "array" : { "_0" : { - "rawValueEnum" : { - "_0" : "HttpStatus", - "_1" : "Int" + "nullable" : { + "_0" : { + "jsObject" : { + "_0" : "Foo" + } + }, + "_1" : "null" } } } } }, { - "abiName" : "bjs_roundTripDataPointArray", + "abiName" : "bjs_roundTripOptionalString", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDataPointArray", + "name" : "roundTripOptionalString", "parameters" : [ { - "label" : "_", - "name" : "points", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripGreeterArray", + "abiName" : "bjs_roundTripOptionalInt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripGreeterArray", + "name" : "roundTripOptionalInt", "parameters" : [ { - "label" : "_", - "name" : "greeters", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "int" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" + "int" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalIntArray", + "abiName" : "bjs_roundTripOptionalBool", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalIntArray", + "name" : "roundTripOptionalBool", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "flag", + "name" : "flag", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "int" : { + "bool" : { - } - }, - "_1" : "null" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "int" : { + "bool" : { - } - }, - "_1" : "null" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalStringArray", + "abiName" : "bjs_roundTripOptionalFloat", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStringArray", + "name" : "roundTripOptionalFloat", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "number", + "name" : "number", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "string" : { + "float" : { - } - }, - "_1" : "null" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "string" : { + "float" : { - } - }, - "_1" : "null" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalDataPointArray", + "abiName" : "bjs_roundTripOptionalDouble", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalDataPointArray", + "name" : "roundTripOptionalDouble", "parameters" : [ { - "label" : "_", - "name" : "points", + "label" : "precision", + "name" : "precision", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - }, - "_1" : "null" + "double" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - }, - "_1" : "null" + "double" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalDirectionArray", + "abiName" : "bjs_roundTripOptionalSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalDirectionArray", + "name" : "roundTripOptionalSyntax", "parameters" : [ { - "label" : "_", - "name" : "directions", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - }, - "_1" : "null" + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - }, - "_1" : "null" + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalStatusArray", + "abiName" : "bjs_roundTripOptionalMixSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStatusArray", + "name" : "roundTripOptionalMixSyntax", "parameters" : [ { - "label" : "_", - "name" : "statuses", + "label" : "name", + "name" : "name", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Status" - } - }, - "_1" : "null" + "string" : { + } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "caseEnum" : { - "_0" : "Status" - } - }, - "_1" : "null" + "string" : { + } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalIntArrayType", + "abiName" : "bjs_roundTripOptionalSwiftSyntax", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalIntArrayType", + "name" : "roundTripOptionalSwiftSyntax", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "name", + "name" : "name", "type" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "int" : { + "string" : { - } - } } }, "_1" : "null" @@ -9694,12 +9724,8 @@ "returnType" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "int" : { + "string" : { - } - } } }, "_1" : "null" @@ -9707,26 +9733,22 @@ } }, { - "abiName" : "bjs_roundTripOptionalStringArrayType", + "abiName" : "bjs_roundTripOptionalWithSpaces", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalStringArrayType", + "name" : "roundTripOptionalWithSpaces", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { + "double" : { - } - } } }, "_1" : "null" @@ -9737,12 +9759,8 @@ "returnType" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { + "double" : { - } - } } }, "_1" : "null" @@ -9750,26 +9768,22 @@ } }, { - "abiName" : "bjs_roundTripOptionalGreeterArrayType", + "abiName" : "bjs_roundTripOptionalTypeAlias", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalGreeterArrayType", + "name" : "roundTripOptionalTypeAlias", "parameters" : [ { - "label" : "_", - "name" : "greeters", + "label" : "age", + "name" : "age", "type" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "int" : { + } }, "_1" : "null" @@ -9780,12 +9794,8 @@ "returnType" : { "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "int" : { + } }, "_1" : "null" @@ -9793,598 +9803,589 @@ } }, { - "abiName" : "bjs_roundTripNestedIntArray", + "abiName" : "bjs_roundTripOptionalStatus", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedIntArray", + "name" : "roundTripOptionalStatus", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } + "caseEnum" : { + "_0" : "Status" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { - "_0" : { - "array" : { - "_0" : { - "int" : { - - } - } + "nullable" : { + "_0" : { + "caseEnum" : { + "_0" : "Status" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedStringArray", + "abiName" : "bjs_roundTripOptionalTheme", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedStringArray", + "name" : "roundTripOptionalTheme", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { - - } - } + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "string" : { - - } - } + "rawValueEnum" : { + "_0" : "Theme", + "_1" : "String" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDoubleArray", + "abiName" : "bjs_roundTripOptionalHttpStatus", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDoubleArray", + "name" : "roundTripOptionalHttpStatus", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "double" : { - - } - } + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "double" : { - - } - } + "rawValueEnum" : { + "_0" : "HttpStatus", + "_1" : "Int" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedBoolArray", + "abiName" : "bjs_roundTripOptionalTSDirection", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedBoolArray", + "name" : "roundTripOptionalTSDirection", "parameters" : [ { - "label" : "_", - "name" : "values", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "bool" : { - - } - } + "caseEnum" : { + "_0" : "TSDirection" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "bool" : { - - } - } + "caseEnum" : { + "_0" : "TSDirection" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDataPointArray", + "abiName" : "bjs_roundTripOptionalTSTheme", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDataPointArray", + "name" : "roundTripOptionalTSTheme", "parameters" : [ { - "label" : "_", - "name" : "points", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftStruct" : { - "_0" : "DataPoint" - } - } + "rawValueEnum" : { + "_0" : "TSTheme", + "_1" : "String" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedDirectionArray", + "abiName" : "bjs_roundTripOptionalNetworkingAPIMethod", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedDirectionArray", + "name" : "roundTripOptionalNetworkingAPIMethod", "parameters" : [ { "label" : "_", - "name" : "directions", + "name" : "method", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "caseEnum" : { + "_0" : "Networking.API.Method" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "caseEnum" : { - "_0" : "Direction" - } - } + "caseEnum" : { + "_0" : "Networking.API.Method" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripNestedGreeterArray", + "abiName" : "bjs_roundTripOptionalAPIResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripNestedGreeterArray", + "name" : "roundTripOptionalAPIResult", "parameters" : [ { - "label" : "_", - "name" : "greeters", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "associatedValueEnum" : { + "_0" : "APIResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "array" : { - "_0" : { - "swiftHeapObject" : { - "_0" : "Greeter" - } - } + "associatedValueEnum" : { + "_0" : "APIResult" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafeRawPointerArray", + "abiName" : "bjs_roundTripOptionalTypedPayloadResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeRawPointerArray", + "name" : "roundTripOptionalTypedPayloadResult", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "result", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeRawPointer" - } + "associatedValueEnum" : { + "_0" : "TypedPayloadResult" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafeMutableRawPointerArray", + "abiName" : "bjs_compareAPIResults", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeMutableRawPointerArray", + "name" : "compareAPIResults", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "r1", + "type" : { + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "APIResult" + } + }, + "_1" : "null" + } + } + }, + { + "label" : "_", + "name" : "r2", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } + "associatedValueEnum" : { + "_0" : "APIResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutableRawPointer" - } - } - } + "string" : { + } } }, { - "abiName" : "bjs_roundTripOpaquePointerArray", + "abiName" : "bjs_roundTripOptionalComplexResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOpaquePointerArray", + "name" : "roundTripOptionalComplexResult", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "result", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } + "associatedValueEnum" : { + "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "opaquePointer" - } + "associatedValueEnum" : { + "_0" : "ComplexResult" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafePointerArray", + "abiName" : "bjs_roundTripOptionalAllTypesResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafePointerArray", + "name" : "roundTripOptionalAllTypesResult", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "result", "type" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } + "associatedValueEnum" : { + "_0" : "AllTypesResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafePointer", - "pointee" : "UInt8" - } + "associatedValueEnum" : { + "_0" : "AllTypesResult" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripUnsafeMutablePointerArray", + "abiName" : "bjs_roundTripOptionalPayloadResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripUnsafeMutablePointerArray", + "name" : "roundTripOptionalPayloadResult", "parameters" : [ { "label" : "_", - "name" : "values", + "name" : "result", "type" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" } } } ], "returnType" : { - "array" : { - "_0" : { - "unsafePointer" : { - "_0" : { - "kind" : "unsafeMutablePointer", - "pointee" : "UInt8" - } - } - } + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" } } }, { - "abiName" : "bjs_consumeDataProcessorArrayType", + "abiName" : "bjs_roundTripOptionalPayloadResultOpt", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "consumeDataProcessorArrayType", + "name" : "roundTripOptionalPayloadResultOpt", "parameters" : [ { "label" : "_", - "name" : "processors", + "name" : "result", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "int" : { - + "nullable" : { + "_0" : { + "associatedValueEnum" : { + "_0" : "OptionalAllTypesResult" + } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripDataProcessorArrayType", + "abiName" : "bjs_roundTripOptionalClass", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripDataProcessorArrayType", + "name" : "roundTripOptionalClass", "parameters" : [ { - "label" : "_", - "name" : "processors", + "label" : "value", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "swiftProtocol" : { - "_0" : "DataProcessor" + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripJSObjectArray", + "abiName" : "bjs_roundTripOptionalGreeter", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripJSObjectArray", + "name" : "roundTripOptionalGreeter", "parameters" : [ { "label" : "_", - "name" : "objects", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "jsObject" : { - + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "jsObject" : { - + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripOptionalJSObjectArray", + "abiName" : "bjs_applyOptionalGreeter", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalJSObjectArray", + "name" : "applyOptionalGreeter", "parameters" : [ { "label" : "_", - "name" : "objects", + "name" : "value", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "jsObject" : { - + "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" } - }, - "_1" : "null" + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Greeter" + } + }, + "_1" : "null" + } } } } @@ -10392,93 +10393,92 @@ } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "jsObject" : { - - } - }, - "_1" : "null" + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" } } }, { - "abiName" : "bjs_roundTripFooArray", + "abiName" : "bjs_makeOptionalHolder", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripFooArray", + "name" : "makeOptionalHolder", "parameters" : [ { - "label" : "_", - "name" : "foos", + "label" : "nullableGreeter", + "name" : "nullableGreeter", "type" : { - "array" : { + "nullable" : { "_0" : { - "jsObject" : { - "_0" : "Foo" + "swiftHeapObject" : { + "_0" : "Greeter" } - } + }, + "_1" : "null" + } + } + }, + { + "label" : "undefinedNumber", + "name" : "undefinedNumber", + "type" : { + "nullable" : { + "_0" : { + "double" : { + + } + }, + "_1" : "undefined" } } } ], "returnType" : { - "array" : { - "_0" : { - "jsObject" : { - "_0" : "Foo" - } - } + "swiftHeapObject" : { + "_0" : "OptionalHolder" } } }, { - "abiName" : "bjs_roundTripOptionalFooArray", + "abiName" : "bjs_roundTripOptionalAPIOptionalResult", "effects" : { "isAsync" : false, "isStatic" : false, "isThrows" : false }, - "name" : "roundTripOptionalFooArray", + "name" : "roundTripOptionalAPIOptionalResult", "parameters" : [ { - "label" : "_", - "name" : "foos", + "label" : "result", + "name" : "result", "type" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "jsObject" : { - "_0" : "Foo" - } - }, - "_1" : "null" + "associatedValueEnum" : { + "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } } ], "returnType" : { - "array" : { + "nullable" : { "_0" : { - "nullable" : { - "_0" : { - "jsObject" : { - "_0" : "Foo" - } - }, - "_1" : "null" + "associatedValueEnum" : { + "_0" : "APIOptionalResult" } - } + }, + "_1" : "null" } } }, @@ -12870,62 +12870,6 @@ } } }, - { - "name" : "jsRoundTripOptionalNumberNull", - "parameters" : [ - { - "name" : "v", - "type" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "null" - } - } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "null" - } - } - }, - { - "name" : "jsRoundTripOptionalNumberUndefined", - "parameters" : [ - { - "name" : "v", - "type" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "undefined" - } - } - } - ], - "returnType" : { - "nullable" : { - "_0" : { - "double" : { - - } - }, - "_1" : "undefined" - } - } - }, { "name" : "jsRoundTripJSValue", "parameters" : [ @@ -14025,6 +13969,136 @@ ], "types" : [ + ] + }, + { + "functions" : [ + { + "name" : "runJsOptionalSupportTests", + "parameters" : [ + + ], + "returnType" : { + "void" : { + + } + } + }, + { + "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/ImportAPITests.swift b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift index a465c57b4..cef881db0 100644 --- a/Tests/BridgeJSRuntimeTests/ImportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ImportAPITests.swift @@ -35,26 +35,6 @@ class ImportAPITests: XCTestCase { } } - 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(.undefinedValue) - if case .value = undefined { - XCTFail("Expected undefined") - } - } - func testRoundTripJSValue() throws { let symbol = JSSymbol("roundTrip") let bigInt = JSBigInt(_slowBridge: Int64(123456789)) 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..bc0f1fcc8 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift @@ -0,0 +1,232 @@ +import XCTest +@_spi(Experimental) import JavaScriptKit +import JavaScriptEventLoop + +@JSFunction func runJsOptionalSupportTests() throws + +final class OptionalSupportTests: XCTestCase { + func testRunJsOptionalSupportTests() throws { + try runJsOptionalSupportTests() + } + + // FIXME: Optional return type on imported function is broken + // 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/bridge-js.d.ts b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts index b7dc6c48d..08d56adf1 100644 --- a/Tests/BridgeJSRuntimeTests/bridge-js.d.ts +++ b/Tests/BridgeJSRuntimeTests/bridge-js.d.ts @@ -2,8 +2,6 @@ export function jsRoundTripVoid(): void export function jsRoundTripNumber(v: number): number export function jsRoundTripBool(v: boolean): boolean export function jsRoundTripString(v: string): string -export function jsRoundTripOptionalNumberNull(v: number | null): number | null -export function jsRoundTripOptionalNumberUndefined(v: number | undefined): number | undefined export type JSValue = any export function jsRoundTripJSValue(v: JSValue): JSValue export function jsThrowOrVoid(shouldThrow: boolean): void diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index e8f0b081c..70e138e63 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -3,6 +3,8 @@ import { 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) { @@ -68,6 +70,12 @@ export async function setupOptions(options, context) { "jsRoundTripOptionalNumberUndefined": (v) => { return v === undefined ? undefined : v; }, + "jsRoundTripOptionalStringNull": (v) => { + return v ?? null; + }, + "jsRoundTripOptionalStringUndefined": (v) => { + return v === undefined ? undefined : v; + }, "jsRoundTripJSValue": (v) => { return v; }, @@ -184,6 +192,11 @@ export async function setupOptions(options, context) { }, roundTripArrayMembers: (value) => { return value; + }, + runJsOptionalSupportTests: () => { + const exports = importsContext.getExports(); + if (!exports) { throw new Error("No exports!?"); } + runJsOptionalSupportTests(exports); } }; }, @@ -220,13 +233,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(); @@ -714,123 +720,6 @@ 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 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); - // TypedPayloadResult — rawValueEnum and caseEnum as associated value payloads assert.equal(exports.Precision.Rough, 0.1); assert.equal(exports.Precision.Fine, 0.001); @@ -859,14 +748,6 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { const tpr_empty = { tag: exports.TypedPayloadResult.Tag.Empty }; assert.deepEqual(exports.roundTripTypedPayloadResult(tpr_empty), tpr_empty); - // Optional TypedPayloadResult roundtrip - assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_precision), tpr_precision); - assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_direction), tpr_direction); - assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionSome), tpr_optPrecisionSome); - assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_optPrecisionNull), tpr_optPrecisionNull); - assert.deepEqual(exports.roundTripOptionalTypedPayloadResult(tpr_empty), tpr_empty); - assert.equal(exports.roundTripOptionalTypedPayloadResult(null), null); - // 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); @@ -896,64 +777,6 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { const atr_empty = { tag: AllTypesResultValues.Tag.Empty }; assert.deepEqual(exports.roundTripAllTypesResult(atr_empty), atr_empty); - // Optional AllTypesResult roundtrip - assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_struct), atr_struct); - assert.deepEqual(exports.roundTripOptionalAllTypesResult(atr_array), atr_array); - 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); - assert.equal(exports.MathUtils.add(2147483647, 0), 2147483647); assert.equal(exports.StaticCalculator.roundtrip(42), 42); assert.equal(StaticCalculatorValues.Scientific, 0); From b2e93d0322ce11b1e9cbf11b562ace226489c8b4 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 15:01:31 +0900 Subject: [PATCH 33/34] BridgeJS: Fix optional String return handling in generated JS glue code --- .../Sources/BridgeJSLink/JSGlueGen.swift | 20 ++-------- .../BridgeJSLinkTests/Optionals.js | 28 ++++--------- .../OptionalSupportTests.swift | 39 +++++++++---------- 3 files changed, 31 insertions(+), 56 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 410bce672..fc04e4670 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -994,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: @@ -1032,19 +1026,13 @@ struct IntrinsicJSFragment: Sendable { 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: diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 341fcd966..0d45b2169 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -238,12 +238,9 @@ export async function createInstantiator(options, swift) { let ret = swift.memory.getObject(self).stringOrNull; const isSome = ret != null; if (isSome) { - const bytes = textEncoder.encode(ret); - bjs["swift_js_return_optional_string"](1, bytes, bytes.length); - return bytes.length; + tmpRetString = ret; } else { - bjs["swift_js_return_optional_string"](0, 0, 0); - return -1; + tmpRetString = null; } } catch (error) { setException(error); @@ -254,12 +251,9 @@ export async function createInstantiator(options, swift) { let ret = swift.memory.getObject(self).stringOrUndefined; const isSome = ret !== undefined; if (isSome) { - const bytes = textEncoder.encode(ret); - bjs["swift_js_return_optional_string"](1, bytes, bytes.length); - return bytes.length; + tmpRetString = ret; } else { - bjs["swift_js_return_optional_string"](0, 0, 0); - return -1; + tmpRetString = null; } } catch (error) { setException(error); @@ -395,12 +389,9 @@ export async function createInstantiator(options, swift) { let ret = swift.memory.getObject(self).roundTripStringOrNull(valueIsSome ? obj : null); const isSome = ret != null; if (isSome) { - const bytes = textEncoder.encode(ret); - bjs["swift_js_return_optional_string"](1, bytes, bytes.length); - return bytes.length; + tmpRetString = ret; } else { - bjs["swift_js_return_optional_string"](0, 0, 0); - return -1; + tmpRetString = null; } } catch (error) { setException(error); @@ -416,12 +407,9 @@ export async function createInstantiator(options, swift) { let ret = swift.memory.getObject(self).roundTripStringOrUndefined(valueIsSome ? obj : undefined); const isSome = ret !== undefined; if (isSome) { - const bytes = textEncoder.encode(ret); - bjs["swift_js_return_optional_string"](1, bytes, bytes.length); - return bytes.length; + tmpRetString = ret; } else { - bjs["swift_js_return_optional_string"](0, 0, 0); - return -1; + tmpRetString = null; } } catch (error) { setException(error); diff --git a/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift b/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift index bc0f1fcc8..adfd51dea 100644 --- a/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift +++ b/Tests/BridgeJSRuntimeTests/OptionalSupportTests.swift @@ -9,26 +9,25 @@ final class OptionalSupportTests: XCTestCase { try runJsOptionalSupportTests() } - // FIXME: Optional return type on imported function is broken - // 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 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) From b9320732ff0b2a2102507c9002f40663624f145e Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 5 Feb 2026 09:39:03 +0100 Subject: [PATCH 34/34] BridgeJS: Skip directories in generate input file processing --- Plugins/BridgeJS/Sources/BridgeJSTool/BridgeJSTool.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 }