From 89d8165c805218defa8de02eb863ace42b976361 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 16:22:21 +0900 Subject: [PATCH 1/8] [NFC] BridgeJS: Add push/pop JS codegen helpers This is a preparation for unifying stacks for param/ret values to make it direction agnostic. --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 4 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 390 +++++++++--------- 2 files changed, 208 insertions(+), 186 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 7a5e02f2d..c2b0c6ed3 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1065,7 +1065,7 @@ public struct BridgeJSLink { } for enumDef in allAssocEnums { let enumPrinter = CodeFragmentPrinter() - let enumScope = JSGlueVariableScope() + let enumScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) let enumCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.associatedValueEnumHelperFactory(enumDefinition: enumDef) _ = fragment.printCode([enumDef.valuesName], enumScope, enumPrinter, enumCleanup) @@ -1608,7 +1608,7 @@ public struct BridgeJSLink { ) throws -> (jsTopLevel: [String], jsExportEntry: [String], dtsType: [String], dtsExportEntry: [String]) { var jsTopLevelLines: [String] = [] var dtsTypeLines: [String] = [] - let scope = JSGlueVariableScope() + let scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) let cleanup = CodeFragmentPrinter() let printer = CodeFragmentPrinter() let enumValuesName = enumDefinition.valuesName diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 1619c2cd2..772c8c84c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -34,7 +34,7 @@ final class JSGlueVariableScope { static let reservedEnumHelpers = "enumHelpers" static let reservedStructHelpers = "structHelpers" - private let intrinsicRegistry: JSIntrinsicRegistry? + private let intrinsicRegistry: JSIntrinsicRegistry private var variables: Set = [ reservedSwift, @@ -66,7 +66,7 @@ final class JSGlueVariableScope { reservedStructHelpers, ] - init(intrinsicRegistry: JSIntrinsicRegistry? = nil) { + init(intrinsicRegistry: JSIntrinsicRegistry) { self.intrinsicRegistry = intrinsicRegistry } @@ -88,7 +88,7 @@ final class JSGlueVariableScope { } func registerIntrinsic(_ name: String, build: (CodeFragmentPrinter) -> Void) { - intrinsicRegistry?.register(name: name, build: build) + intrinsicRegistry.register(name: name, build: build) } func makeChildScope() -> JSGlueVariableScope { @@ -96,6 +96,53 @@ final class JSGlueVariableScope { } } +extension JSGlueVariableScope { + // MARK: Parameter + + func emitPushI32Parameter(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(value));") + } + func emitPushF64Parameter(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(value));") + } + func emitPushF32Parameter(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(\(value));") + } + func emitPushPointerParameter(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(value));") + } + + // MARK: Return + + func emitPushI32Return(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(value));") + } + func emitPushF64Return(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpRetF64s).push(\(value));") + } + func emitPushPointerReturn(_ value: String, printer: CodeFragmentPrinter) { + printer.write("\(JSGlueVariableScope.reservedTmpRetPointers).push(\(value));") + } + func popTagReturn() -> String { + return "\(JSGlueVariableScope.reservedTmpRetTag).pop()" + } + func popStringReturn() -> String { + return "\(JSGlueVariableScope.reservedTmpRetStrings).pop()" + } + func popI32Return() -> String { + return "\(JSGlueVariableScope.reservedTmpRetInts).pop()" + } + func popF64Return() -> String { + return "\(JSGlueVariableScope.reservedTmpRetF64s).pop()" + } + func popF32Return() -> String { + return "\(JSGlueVariableScope.reservedTmpRetF32s).pop()" + } + func popPointerReturn() -> String { + return "\(JSGlueVariableScope.reservedTmpRetPointers).pop()" + } +} + /// A fragment of JS code used to convert a value between Swift and JS. /// /// See `BridgeJSIntrinsics.swift` in the main JavaScriptKit module for Swift side lowering/lifting implementation. @@ -271,7 +318,7 @@ struct IntrinsicJSFragment: Sendable { helperPrinter.write("}") helperPrinter.write("function \(jsValueLiftHelperName)(kind, payload1, payload2) {") helperPrinter.indent { - let helperScope = JSGlueVariableScope() + let helperScope = scope.makeChildScope() let resultVar = emitJSValueConstruction( kind: "kind", payload1: "payload1", @@ -466,9 +513,9 @@ struct IntrinsicJSFragment: Sendable { 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));") + scope.emitPushI32Parameter(kindVar, printer: printer) + scope.emitPushI32Parameter(payload1Var, printer: printer) + scope.emitPushF64Parameter(payload2Var, printer: printer) return [] } ) @@ -482,9 +529,9 @@ struct IntrinsicJSFragment: Sendable { 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));") + scope.emitPushI32Parameter(kindVar, printer: printer) + scope.emitPushI32Parameter(payload1Var, printer: printer) + scope.emitPushF64Parameter(payload2Var, printer: printer) return [] } ) @@ -497,9 +544,9 @@ struct IntrinsicJSFragment: Sendable { 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();") + printer.write("const \(payload2) = \(scope.popF64Return());") + printer.write("const \(payload1) = \(scope.popI32Return());") + printer.write("const \(kind) = \(scope.popI32Return());") let resultVar = scope.variable("jsValue") registerJSValueHelpers(scope: scope) printer.write( @@ -571,7 +618,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { _, scope, printer, _ in let retName = scope.variable("ret") printer.write( - "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(JSGlueVariableScope.reservedTmpRetTag).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [retName] } @@ -886,7 +933,7 @@ 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();") + printer.write("const \(tagVar) = \(scope.popTagReturn());") let isNullVar = scope.variable("isNull") printer.write("const \(isNullVar) = (\(tagVar) === -1);") printer.write("let \(resultVar);") @@ -904,7 +951,7 @@ struct IntrinsicJSFragment: Sendable { case .swiftStruct(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -919,7 +966,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("}") case .array(let elementType): let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -936,7 +983,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("}") case .jsValue: let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -1018,11 +1065,11 @@ struct IntrinsicJSFragment: Sendable { 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));") + scope.emitPushI32Parameter(kindVar, printer: printer) + scope.emitPushI32Parameter(payload1Var, printer: printer) + scope.emitPushF64Parameter(payload2Var, printer: printer) } - printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .array(let elementType): printer.write("if (\(isSomeVar)) {") printer.indent { @@ -1036,7 +1083,7 @@ struct IntrinsicJSFragment: Sendable { } } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .rawValueEnum(_, let rawType): switch rawType { case .string: @@ -1635,7 +1682,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).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) printer.write("return \(resultVar);") return [] @@ -2259,46 +2306,36 @@ struct IntrinsicJSFragment: Sendable { "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));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) 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);") + scope.emitPushI32Parameter("\(isSomeVar) ? (\(value) | 0) : 0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .bool: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) ? 1 : 0) : 0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? (\(value) ? 1 : 0) : 0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .float: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamF32s).push(\(isSomeVar) ? Math.fround(\(value)) : 0.0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushF32Parameter("\(isSomeVar) ? Math.fround(\(value)) : 0.0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .double: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamF64s).push(\(isSomeVar) ? \(value) : 0.0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushF64Parameter("\(isSomeVar) ? \(value) : 0.0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .caseEnum: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? (\(value) | 0) : 0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .rawValueEnum(_, let rawType): switch rawType { case .string: @@ -2313,20 +2350,16 @@ struct IntrinsicJSFragment: Sendable { printer.write( "\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" ) - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);" - ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" - ) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if(\(idVar)) {") cleanup.indent { cleanup.write( @@ -2335,26 +2368,14 @@ struct IntrinsicJSFragment: Sendable { } cleanup.write("}") case .float: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamF32s).push(\(isSomeVar) ? Math.fround(\(value)) : 0.0);" - ) - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" - ) + scope.emitPushF32Parameter("\(isSomeVar) ? Math.fround(\(value)) : 0.0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .double: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamF64s).push(\(isSomeVar) ? \(value) : 0.0);" - ) - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" - ) + scope.emitPushF64Parameter("\(isSomeVar) ? \(value) : 0.0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) default: - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? (\(value) | 0) : 0);" - ) - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);" - ) + scope.emitPushI32Parameter("\(isSomeVar) ? (\(value) | 0) : 0", printer: printer) + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) } case .swiftStruct(let structName): let structBase = structName.components(separatedBy: ".").last ?? structName @@ -2369,34 +2390,34 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(nestedCleanupVar) = \(structResultVar).cleanup;") } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if (\(nestedCleanupVar)) { \(nestedCleanupVar)(); }") case .swiftHeapObject: printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(value).pointer);") + scope.emitPushPointerParameter("\(value).pointer", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(0);") + scope.emitPushPointerParameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) 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));") + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { printer.write("\(idVar) = undefined;") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) case .associatedValueEnum(let enumName): let base = enumName.components(separatedBy: ".").last ?? enumName let caseIdVar = scope.variable("enumCaseId") @@ -2410,14 +2431,14 @@ struct IntrinsicJSFragment: Sendable { ) printer.write("\(caseIdVar) = \(enumResultVar).caseId;") printer.write("\(enumCleanupVar) = \(enumResultVar).cleanup;") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") + scope.emitPushI32Parameter(caseIdVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if (\(enumCleanupVar)) { \(enumCleanupVar)(); }") case .array(let elementType): // Array cleanup references variables declared inside the if block, @@ -2443,10 +2464,10 @@ struct IntrinsicJSFragment: Sendable { } } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if (\(arrCleanupVar)) { \(arrCleanupVar)(); }") default: - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) } return [] @@ -2473,7 +2494,7 @@ struct IntrinsicJSFragment: Sendable { let optVar = scope.variable("optional") let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(optVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -2482,7 +2503,7 @@ struct IntrinsicJSFragment: Sendable { 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("const \(caseIdVar) = \(scope.popI32Return());") printer.write( "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) @@ -2579,7 +2600,7 @@ struct IntrinsicJSFragment: Sendable { } } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(arr).length);") + scope.emitPushI32Parameter("\(arr).length", printer: printer) cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") return [] } @@ -2595,7 +2616,7 @@ struct IntrinsicJSFragment: Sendable { let lenVar = scope.variable("arrayLen") let iVar = scope.variable("i") - printer.write("const \(lenVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(lenVar) = \(scope.popI32Return());") printer.write("const \(resultVar) = [];") printer.write("for (let \(iVar) = 0; \(iVar) < \(lenVar); \(iVar)++) {") printer.indent { @@ -2622,9 +2643,9 @@ struct IntrinsicJSFragment: Sendable { 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();") + printer.write("const \(payload2Var) = \(scope.popF64Return());") + printer.write("const \(payload1Var) = \(scope.popI32Return());") + printer.write("const \(kindVar) = \(scope.popI32Return());") let resultVar = scope.variable("jsValue") printer.write( "const \(resultVar) = \(jsValueLiftHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" @@ -2637,7 +2658,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let strVar = scope.variable("string") - printer.write("const \(strVar) = \(JSGlueVariableScope.reservedTmpRetStrings).pop();") + printer.write("const \(strVar) = \(scope.popStringReturn());") return [strVar] } ) @@ -2646,7 +2667,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let bVar = scope.variable("bool") - printer.write("const \(bVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop() !== 0;") + printer.write("const \(bVar) = \(scope.popI32Return()) !== 0;") return [bVar] } ) @@ -2655,7 +2676,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let iVar = scope.variable("int") - printer.write("const \(iVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(iVar) = \(scope.popI32Return());") return [iVar] } ) @@ -2664,7 +2685,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let fVar = scope.variable("f32") - printer.write("const \(fVar) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") + printer.write("const \(fVar) = \(scope.popF32Return());") return [fVar] } ) @@ -2673,7 +2694,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let dVar = scope.variable("f64") - printer.write("const \(dVar) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") + printer.write("const \(dVar) = \(scope.popF64Return());") return [dVar] } ) @@ -2694,7 +2715,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("caseId") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(varName) = \(scope.popI32Return());") return [varName] } ) @@ -2705,7 +2726,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetStrings).pop();") + printer.write("const \(varName) = \(scope.popStringReturn());") return [varName] } ) @@ -2714,7 +2735,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF32s).pop();") + printer.write("const \(varName) = \(scope.popF32Return());") return [varName] } ) @@ -2723,7 +2744,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetF64s).pop();") + printer.write("const \(varName) = \(scope.popF64Return());") return [varName] } ) @@ -2732,7 +2753,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(varName) = \(scope.popI32Return());") return [varName] } ) @@ -2744,7 +2765,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let resultVar = scope.variable("enumValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetTag).pop(), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) return [resultVar] } @@ -2755,7 +2776,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let ptrVar = scope.variable("ptr") let objVar = scope.variable("obj") - printer.write("const \(ptrVar) = \(JSGlueVariableScope.reservedTmpRetPointers).pop();") + printer.write("const \(ptrVar) = \(scope.popPointerReturn());") printer.write("const \(objVar) = _exports['\(className)'].__construct(\(ptrVar));") return [objVar] } @@ -2766,7 +2787,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let idVar = scope.variable("objId") let objVar = scope.variable("obj") - printer.write("const \(idVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(idVar) = \(scope.popI32Return());") printer.write("const \(objVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(idVar));") printer.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [objVar] @@ -2781,7 +2802,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let pVar = scope.variable("pointer") - printer.write("const \(pVar) = \(JSGlueVariableScope.reservedTmpRetPointers).pop();") + printer.write("const \(pVar) = \(scope.popPointerReturn());") return [pVar] } ) @@ -2801,9 +2822,9 @@ struct IntrinsicJSFragment: Sendable { 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));") + scope.emitPushI32Parameter(kindVar, printer: printer) + scope.emitPushI32Parameter(payload1Var, printer: printer) + scope.emitPushF64Parameter(payload2Var, printer: printer) return [] } ) @@ -2816,8 +2837,8 @@ struct IntrinsicJSFragment: Sendable { 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));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [] } @@ -2826,7 +2847,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(arguments[0]) ? 1 : 0);") + scope.emitPushI32Parameter("\(arguments[0]) ? 1 : 0", printer: printer) return [] } ) @@ -2834,7 +2855,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") + scope.emitPushI32Parameter("(\(arguments[0]) | 0)", printer: printer) return [] } ) @@ -2842,7 +2863,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") + scope.emitPushF32Parameter("Math.fround(\(arguments[0]))", printer: printer) return [] } ) @@ -2850,7 +2871,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") + scope.emitPushF64Parameter("\(arguments[0])", printer: printer) return [] } ) @@ -2872,7 +2893,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") + scope.emitPushI32Parameter("(\(arguments[0]) | 0)", printer: printer) return [] } ) @@ -2891,8 +2912,8 @@ struct IntrinsicJSFragment: Sendable { printer.write( "const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [] } @@ -2901,7 +2922,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(arguments[0])));") + scope.emitPushF32Parameter("Math.fround(\(arguments[0]))", printer: printer) return [] } ) @@ -2909,7 +2930,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(arguments[0]));") + scope.emitPushF64Parameter("\(arguments[0])", printer: printer) return [] } ) @@ -2917,7 +2938,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(arguments[0]) | 0));") + scope.emitPushI32Parameter("(\(arguments[0]) | 0)", printer: printer) return [] } ) @@ -2933,7 +2954,7 @@ struct IntrinsicJSFragment: Sendable { printer.write( "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") + scope.emitPushI32Parameter(caseIdVar, printer: printer) cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } @@ -2942,7 +2963,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(arguments[0]).pointer);") + scope.emitPushPointerParameter("\(arguments[0]).pointer", printer: printer) return [] } ) @@ -2953,7 +2974,7 @@ struct IntrinsicJSFragment: Sendable { let value = arguments[0] let idVar = scope.variable("objId") printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter(idVar, printer: printer) return [] } ) @@ -2972,7 +2993,7 @@ struct IntrinsicJSFragment: Sendable { let value = arguments[0] let idVar = scope.variable("objId") printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter(idVar, printer: printer) return [] } ) @@ -2980,7 +3001,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, scope, printer, cleanup in - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push((\(arguments[0]) | 0));") + scope.emitPushPointerParameter("(\(arguments[0]) | 0)", printer: printer) return [] } ) @@ -3000,7 +3021,7 @@ struct IntrinsicJSFragment: Sendable { let isSomeVar = scope.variable("isSome") let resultVar = scope.variable("optValue") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar) === 0) {") printer.indent { @@ -3054,23 +3075,23 @@ struct IntrinsicJSFragment: Sendable { // Push placeholders so Swift can unconditionally pop value slots switch wrappedType { case .float: - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(0.0);") + scope.emitPushF32Parameter("0.0", printer: printer) case .double: - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(0.0);") + scope.emitPushF64Parameter("0.0", printer: printer) case .swiftStruct: // No placeholder — Swift only pops struct fields when isSome=1 break case .string, .rawValueEnum(_, .string): - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) + scope.emitPushI32Parameter("0", printer: printer) case .swiftHeapObject: - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(0);") + scope.emitPushPointerParameter("0", printer: printer) default: - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar));") + scope.emitPushI32Parameter(isSomeVar, printer: printer) return [] } @@ -3271,9 +3292,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(idVar) = undefined;") } printer.write("}") - printer.write( - "\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar) !== undefined ? \(idVar) : 0);" - ) + scope.emitPushI32Parameter("\(idVar) !== undefined ? \(idVar) : 0", printer: printer) cleanup.write("if(\(idVar) !== undefined && \(idVar) !== 0) {") cleanup.indent { cleanup.write("try {") @@ -3298,14 +3317,14 @@ struct IntrinsicJSFragment: Sendable { if case .caseEnum = wrappedType { printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(value) | 0));") + scope.emitPushI32Parameter("\(value) | 0", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] } else if case .rawValueEnum(_, let rawType) = wrappedType { switch rawType { @@ -3321,16 +3340,16 @@ struct IntrinsicJSFragment: Sendable { printer.write( "\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));" ) - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(bytesVar).length);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write( "if(\(idVar) !== undefined) { \(JSGlueVariableScope.reservedSwift).memory.release(\(idVar)); }" ) @@ -3338,40 +3357,38 @@ struct IntrinsicJSFragment: Sendable { case .float: printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write( - "\(JSGlueVariableScope.reservedTmpParamF32s).push(Math.fround(\(value)));" - ) + scope.emitPushF32Parameter("Math.fround(\(value))", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(0.0);") + scope.emitPushF32Parameter("0.0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] case .double: printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(value));") + scope.emitPushF64Parameter("\(value)", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(0.0);") + scope.emitPushF64Parameter("0.0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] default: printer.write("if (\(isSomeVar)) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push((\(value) | 0));") + scope.emitPushI32Parameter("\(value) | 0", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] } } else if case .swiftHeapObject = wrappedType { @@ -3380,14 +3397,14 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") printer.indent { printer.write("\(ptrVar) = \(value).pointer;") - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(ptrVar));") + scope.emitPushPointerParameter("\(ptrVar)", printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(0);") + scope.emitPushPointerParameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] } else if case .swiftStruct(let structName) = wrappedType { let nestedCleanupVar = scope.variable("nestedCleanup") @@ -3401,7 +3418,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(nestedCleanupVar) = \(structResultVar).cleanup;") } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if (\(nestedCleanupVar)) { \(nestedCleanupVar)(); }") return [] } else if case .string = wrappedType { @@ -3414,16 +3431,16 @@ struct IntrinsicJSFragment: Sendable { "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));") + scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write( "if(\(idVar) !== undefined) { \(JSGlueVariableScope.reservedSwift).memory.release(\(idVar)); }" ) @@ -3434,15 +3451,15 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") printer.indent { printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(value));") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(idVar));") + scope.emitPushI32Parameter(idVar, printer: printer) } printer.write("} else {") printer.indent { printer.write("\(idVar) = undefined;") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if(\(idVar) !== undefined && \(idVar) !== 0) {") cleanup.indent { cleanup.write("try {") @@ -3463,7 +3480,8 @@ struct IntrinsicJSFragment: Sendable { stack: .tmpParamInts, convert: "| 0", zeroValue: "0", - printer: printer + printer: printer, + scope: scope ) case .bool: pushOptionalPrimitive( @@ -3472,7 +3490,8 @@ struct IntrinsicJSFragment: Sendable { stack: .tmpParamInts, convert: "? 1 : 0", zeroValue: "0", - printer: printer + printer: printer, + scope: scope ) case .float: pushOptionalPrimitive( @@ -3481,7 +3500,8 @@ struct IntrinsicJSFragment: Sendable { stack: .tmpParamF32s, convert: "Math.fround", zeroValue: "0.0", - printer: printer + printer: printer, + scope: scope ) case .double: pushOptionalPrimitive( @@ -3490,7 +3510,8 @@ struct IntrinsicJSFragment: Sendable { stack: .tmpParamF64s, convert: nil, zeroValue: "0.0", - printer: printer + printer: printer, + scope: scope ) case .associatedValueEnum(let enumName): let base = enumName.components(separatedBy: ".").last ?? enumName @@ -3505,14 +3526,14 @@ struct IntrinsicJSFragment: Sendable { ) printer.write("\(caseIdVar) = \(enumResultVar).caseId;") printer.write("\(enumCleanupVar) = \(enumResultVar).cleanup;") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(caseIdVar));") + scope.emitPushI32Parameter(caseIdVar, printer: printer) } printer.write("} else {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(0);") + scope.emitPushI32Parameter("0", printer: printer) } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) cleanup.write("if (\(enumCleanupVar)) { \(enumCleanupVar)(); }") default: let wrappedFragment = structFieldLowerFragment( @@ -3556,7 +3577,7 @@ struct IntrinsicJSFragment: Sendable { } } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) } return [] } @@ -3596,7 +3617,8 @@ struct IntrinsicJSFragment: Sendable { stack: StackType, convert: String?, zeroValue: String, - printer: CodeFragmentPrinter + printer: CodeFragmentPrinter, + scope: JSGlueVariableScope ) { let stackName: String switch stack { @@ -3624,7 +3646,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(stackName).push(\(zeroValue));") } printer.write("}") - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") + scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) } private enum StackType { @@ -3646,7 +3668,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let isSomeVar = scope.variable("isSome") let optVar = scope.variable("optional") - printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(isSomeVar) = \(scope.popI32Return());") printer.write("let \(optVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -3654,7 +3676,7 @@ struct IntrinsicJSFragment: Sendable { if case .associatedValueEnum(let enumName) = wrappedType { let base = enumName.components(separatedBy: ".").last ?? enumName let caseIdVar = scope.variable("enumCaseId") - printer.write("const \(caseIdVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(caseIdVar) = \(scope.popI32Return());") printer.write( "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" ) @@ -3701,7 +3723,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let objectIdVar = scope.variable("objectId") let varName = scope.variable("value") - printer.write("const \(objectIdVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(objectIdVar) = \(scope.popI32Return());") printer.write("let \(varName);") printer.write("if (\(objectIdVar) !== 0) {") printer.indent { From 63b7b7220272279db6682a9d13dd7ea1c8195837 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 18:53:36 +0900 Subject: [PATCH 2/8] [NFC] BridgeJS: Remove explicit stack storage captures from enum/struct helpers (#588) --- .../Sources/BridgeJSLink/JSGlueGen.swift | 36 ++++++------ .../BridgeJSLinkTests/ArrayTypes.js | 10 ++-- .../BridgeJSLinkTests/DefaultParameters.js | 10 ++-- .../BridgeJSLinkTests/EnumAssociatedValue.js | 58 +++++++++---------- .../ImportedTypeInExportedInterface.js | 4 +- .../BridgeJSLinkTests/Protocol.js | 8 +-- .../StaticFunctions.Global.js | 4 +- .../BridgeJSLinkTests/StaticFunctions.js | 4 +- .../BridgeJSLinkTests/SwiftClosure.js | 6 +- .../BridgeJSLinkTests/SwiftStruct.js | 22 +++---- .../BridgeJSLinkTests/SwiftStructImports.js | 2 +- .../BridgeJSLinkTests/UnsafePointer.js | 6 +- 12 files changed, 85 insertions(+), 85 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 772c8c84c..ae83f33e6 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -618,7 +618,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { _, scope, printer, _ in let retName = scope.variable("ret") printer.write( - "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()));" ) return [retName] } @@ -699,7 +699,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), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(enumVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(wrappedValue));" ) } printer.write("}") @@ -711,7 +711,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSome)) {") printer.indent { printer.write( - "\(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();" ) } printer.write("} else {") @@ -944,7 +944,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("} else {") printer.indent { printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(tagVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(tagVar));" ) } printer.write("}") @@ -956,7 +956,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") printer.indent { printer.write( - "\(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();" ) } printer.write("} else {") @@ -1283,7 +1283,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), \(JSGlueVariableScope.reservedTmpRetPointers));" + "let \(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId));" ) return [] } @@ -1354,7 +1354,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), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(targetVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(value));" ) default: fatalError("Unsupported optional wrapped type in closure parameter lifting: \(wrappedType)") @@ -1682,7 +1682,7 @@ struct IntrinsicJSFragment: Sendable { let base = fullName.components(separatedBy: ".").last ?? fullName let resultVar = scope.variable("result") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()));" ) printer.write("return \(resultVar);") return [] @@ -1907,7 +1907,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), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseId));" ) return [resultVar] } @@ -1924,7 +1924,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanupCode in let resultVar = scope.variable("structValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lift();" ) return [resultVar] } @@ -2107,7 +2107,7 @@ struct IntrinsicJSFragment: Sendable { // Generate lift function printer.write( - "lift: (tag, \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers)) => {" + "lift: (tag) => {" ) printer.indent { printer.write("tag = tag | 0;") @@ -2505,7 +2505,7 @@ struct IntrinsicJSFragment: Sendable { let caseIdVar = scope.variable("caseId") printer.write("const \(caseIdVar) = \(scope.popI32Return());") printer.write( - "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar));" ) } else { let wrappedFragment = associatedValuePopPayload(type: wrappedType) @@ -2565,7 +2565,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanupCode in let resultVar = scope.variable("structValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift();" ) return [resultVar] } @@ -2705,7 +2705,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let resultVar = scope.variable("struct") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lift();" ) return [resultVar] } @@ -2765,7 +2765,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let resultVar = scope.variable("enumValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), );" ) return [resultVar] } @@ -3125,7 +3125,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("},") printer.write( - "lift: (\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers)) => {" + "lift: () => {" ) printer.indent { generateStructLiftCode( @@ -3678,7 +3678,7 @@ struct IntrinsicJSFragment: Sendable { let caseIdVar = scope.variable("enumCaseId") printer.write("const \(caseIdVar) = \(scope.popI32Return());") printer.write( - "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), \(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), );" ) } else { let wrappedFragment = structFieldLiftFragment( @@ -3712,7 +3712,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let structVar = scope.variable("struct") printer.write( - "const \(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const \(structVar) = \(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lift();" ) return [structVar] } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 6cca17cf6..42176ae1f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -54,7 +54,7 @@ export async function createInstantiator(options, swift) { tmpParamF64s.push(value.y); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const f64 = tmpRetF64s.pop(); const f641 = tmpRetF64s.pop(); return { x: f641, y: f64 }; @@ -481,7 +481,7 @@ export async function createInstantiator(options, swift) { const arrayLen = tmpRetInts.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const struct = structHelpers.Point.lift(); arrayResult.push(struct); } arrayResult.reverse(); @@ -544,7 +544,7 @@ export async function createInstantiator(options, swift) { const matchingBytes = textEncoder.encode(matching); const matchingId = swift.memory.retain(matchingBytes); instance.exports.bjs_findFirstPoint(matchingId, matchingBytes.length); - const structValue = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.Point.lift(); for (const cleanup of arrayCleanups) { cleanup(); } swift.memory.release(matchingId); return structValue; @@ -715,7 +715,7 @@ export async function createInstantiator(options, swift) { if (isSome1 === 0) { optValue = null; } else { - const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const struct = structHelpers.Point.lift(); optValue = struct; } arrayResult.push(optValue); @@ -873,7 +873,7 @@ export async function createInstantiator(options, swift) { const arrayLen1 = tmpRetInts.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { - const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const struct = structHelpers.Point.lift(); arrayResult1.push(struct); } arrayResult1.reverse(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 754c47b0a..4317cc124 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -54,7 +54,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const bool = tmpRetInts.pop() !== 0; const int = tmpRetInts.pop(); const string = tmpRetStrings.pop(); @@ -68,7 +68,7 @@ export async function createInstantiator(options, swift) { tmpParamF64s.push(value.baseValue); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const f64 = tmpRetF64s.pop(); const instance1 = { baseValue: f64 }; instance1.add = function(a, b = 10.0) { @@ -528,7 +528,7 @@ export async function createInstantiator(options, swift) { const isSome1 = tmpRetInts.pop(); let optResult; if (isSome1) { - optResult = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = structHelpers.Config.lift(); } else { optResult = null; } @@ -546,7 +546,7 @@ export async function createInstantiator(options, swift) { const isSome1 = tmpRetInts.pop(); let optResult; if (isSome1) { - optResult = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = structHelpers.Config.lift(); } else { optResult = null; } @@ -663,7 +663,7 @@ export async function createInstantiator(options, swift) { MathOperations: { init: function(baseValue = 0.0) { instance.exports.bjs_MathOperations_init(baseValue); - const structValue = structHelpers.MathOperations.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.MathOperations.lift(); return structValue; }, subtract: function(a, b) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 123ba56fa..b25276d9f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -122,7 +122,7 @@ export async function createInstantiator(options, swift) { tmpParamF64s.push(value.y); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const f64 = tmpRetF64s.pop(); const f641 = tmpRetF64s.pop(); return { x: f641, y: f64 }; @@ -171,7 +171,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { @@ -278,7 +278,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown ComplexResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case ComplexResultValues.Tag.Success: { @@ -361,7 +361,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case ResultValues.Tag.Success: { @@ -413,7 +413,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown NetworkingResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case NetworkingResultValues.Tag.Success: { @@ -494,7 +494,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown APIOptionalResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case APIOptionalResultValues.Tag.Success: { @@ -595,7 +595,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown TypedPayloadResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case TypedPayloadResultValues.Tag.Precision: { @@ -683,11 +683,11 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown AllTypesResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case AllTypesResultValues.Tag.StructPayload: { - const struct = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const struct = structHelpers.Point.lift(); return { tag: AllTypesResultValues.Tag.StructPayload, param0: struct }; } case AllTypesResultValues.Tag.ClassPayload: { @@ -702,7 +702,7 @@ export async function createInstantiator(options, swift) { return { tag: AllTypesResultValues.Tag.JsObjectPayload, param0: obj }; } case AllTypesResultValues.Tag.NestedEnum: { - const enumValue = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const enumValue = enumHelpers.APIResult.lift(tmpRetTag.pop(), ); return { tag: AllTypesResultValues.Tag.NestedEnum, param0: enumValue }; } case AllTypesResultValues.Tag.ArrayPayload: { @@ -807,14 +807,14 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown OptionalAllTypesResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { 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); + const struct = structHelpers.Point.lift(); optional = struct; } else { optional = null; @@ -851,7 +851,7 @@ export async function createInstantiator(options, swift) { let optional; if (isSome) { const caseId = tmpRetInts.pop(); - optional = enumHelpers.APIResult.lift(caseId, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optional = enumHelpers.APIResult.lift(caseId); } else { optional = null; } @@ -1139,13 +1139,13 @@ export async function createInstantiator(options, swift) { }, getResult: function bjs_getResult() { instance.exports.bjs_getResult(); - const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); return ret; }, roundtripAPIResult: function bjs_roundtripAPIResult(result) { const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); instance.exports.bjs_roundtripAPIResult(resultCaseId); - const ret = enumHelpers.APIResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1164,7 +1164,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.APIResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1176,13 +1176,13 @@ export async function createInstantiator(options, swift) { }, getComplexResult: function bjs_getComplexResult() { instance.exports.bjs_getComplexResult(); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop()); return ret; }, roundtripComplexResult: function bjs_roundtripComplexResult(result) { const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); instance.exports.bjs_roundtripComplexResult(resultCaseId); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1201,7 +1201,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.ComplexResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.ComplexResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1221,7 +1221,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.Result.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.Result.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1241,7 +1241,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.NetworkingResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.NetworkingResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1261,7 +1261,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIOptionalResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.APIOptionalResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1288,7 +1288,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.APIOptionalResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.APIOptionalResult.lift(tag); } if (result1Cleanup) { result1Cleanup(); } if (result2Cleanup) { result2Cleanup(); } @@ -1297,7 +1297,7 @@ export async function createInstantiator(options, swift) { 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); + const ret = enumHelpers.TypedPayloadResult.lift(tmpRetTag.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1316,7 +1316,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.TypedPayloadResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.TypedPayloadResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1324,7 +1324,7 @@ export async function createInstantiator(options, swift) { 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); + const ret = enumHelpers.AllTypesResult.lift(tmpRetTag.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1343,7 +1343,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.AllTypesResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.AllTypesResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; @@ -1351,7 +1351,7 @@ export async function createInstantiator(options, swift) { 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); + const ret = enumHelpers.OptionalAllTypesResult.lift(tmpRetTag.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1370,7 +1370,7 @@ export async function createInstantiator(options, swift) { if (isNull) { optResult = null; } else { - optResult = enumHelpers.OptionalAllTypesResult.lift(tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + optResult = enumHelpers.OptionalAllTypesResult.lift(tag); } if (resultCleanup) { resultCleanup(); } return optResult; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index efcbbe2d6..23db5be56 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -70,7 +70,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -370,7 +370,7 @@ export async function createInstantiator(options, swift) { 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); + const structValue = structHelpers.FooContainer.lift(); if (cleanup) { cleanup(); } return structValue; }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 7c20130b3..965df2b37 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -81,7 +81,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case ResultValues.Tag.Success: { @@ -375,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, tmpRetPointers); + const enumValue = enumHelpers.Result.lift(value); swift.memory.getObject(self).result = enumValue; } catch (error) { setException(error); @@ -399,7 +399,7 @@ export async function createInstantiator(options, swift) { try { let enumValue; if (valueIsSome) { - enumValue = enumHelpers.Result.lift(valueWrappedValue, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + enumValue = enumHelpers.Result.lift(valueWrappedValue); } swift.memory.getObject(self).optionalResult = valueIsSome ? enumValue : null; } catch (error) { @@ -556,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, tmpRetPointers); + const enumValue = enumHelpers.Result.lift(result); swift.memory.getObject(self).handleResult(enumValue); } catch (error) { setException(error); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 391c7167e..451c356a5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -68,7 +68,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { @@ -335,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.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); 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 b38668c57..00135e97d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -68,7 +68,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { @@ -329,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.pop(), tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); if (valueCleanup) { valueCleanup(); } return ret; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index ff5af72f9..9f2c16b2d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -106,7 +106,7 @@ export async function createInstantiator(options, swift) { default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } }, - lift: (tag, tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: (tag) => { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { @@ -422,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, tmpRetPointers); + let param0 = enumHelpers.APIResult.lift(param0Id); const result = callback(param0); if (typeof result !== "string") { throw new TypeError("Callback must return a string"); @@ -684,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, tmpRetPointers); + param0 = enumHelpers.APIResult.lift(param0Value); } else { param0 = null; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index adbe18856..1198f1539 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -67,7 +67,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -115,7 +115,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -158,7 +158,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -167,7 +167,7 @@ export async function createInstantiator(options, swift) { } else { optional = null; } - const struct = structHelpers.Address.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const struct = structHelpers.Address.lift(); const int = tmpRetInts.pop(); const string1 = tmpRetStrings.pop(); return { name: string1, age: int, address: struct, email: optional }; @@ -181,7 +181,7 @@ export async function createInstantiator(options, swift) { tmpParamPointers.push(value.owner.pointer); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const ptr = tmpRetPointers.pop(); const obj = _exports['Greeter'].__construct(ptr); const int = tmpRetInts.pop(); @@ -203,7 +203,7 @@ export async function createInstantiator(options, swift) { tmpParamInts.push(isSome ? 1 : 0); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -223,7 +223,7 @@ export async function createInstantiator(options, swift) { lower: (value) => { return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { return { }; } }); @@ -264,7 +264,7 @@ export async function createInstantiator(options, swift) { }; return { cleanup }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const isSome = tmpRetInts.pop(); let optional; if (isSome) { @@ -632,14 +632,14 @@ export async function createInstantiator(options, swift) { roundtrip: function bjs_roundtrip(session) { const { cleanup: cleanup } = structHelpers.Person.lower(session); instance.exports.bjs_roundtrip(); - const structValue = structHelpers.Person.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.Person.lift(); 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); + const structValue = structHelpers.Container.lift(); if (cleanup) { cleanup(); } return structValue; }, @@ -651,7 +651,7 @@ export async function createInstantiator(options, swift) { const isSome = optCount != null; const isSome1 = optFlag != null; instance.exports.bjs_DataPoint_init(x, y, labelId, labelBytes.length, +isSome, isSome ? optCount : 0, +isSome1, isSome1 ? optFlag : 0); - const structValue = structHelpers.DataPoint.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.DataPoint.lift(); swift.memory.release(labelId); return structValue; }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 8f90491df..393cd6847 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -41,7 +41,7 @@ export async function createInstantiator(options, swift) { tmpParamInts.push((value.y | 0)); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const int = tmpRetInts.pop(); const int1 = tmpRetInts.pop(); return { x: int1, y: int }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index bbeeffa0d..a2240a9e6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -44,7 +44,7 @@ export async function createInstantiator(options, swift) { tmpParamPointers.push((value.mutPtr | 0)); return { cleanup: undefined }; }, - lift: (tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers) => { + lift: () => { const pointer = tmpRetPointers.pop(); const pointer1 = tmpRetPointers.pop(); const pointer2 = tmpRetPointers.pop(); @@ -286,14 +286,14 @@ export async function createInstantiator(options, swift) { roundTripPointerFields: function bjs_roundTripPointerFields(value) { const { cleanup: cleanup } = structHelpers.PointerFields.lower(value); instance.exports.bjs_roundTripPointerFields(); - const structValue = structHelpers.PointerFields.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.PointerFields.lift(); if (cleanup) { cleanup(); } return structValue; }, PointerFields: { init: function(raw, mutRaw, opaque, ptr, mutPtr) { instance.exports.bjs_PointerFields_init(raw, mutRaw, opaque, ptr, mutPtr); - const structValue = structHelpers.PointerFields.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const structValue = structHelpers.PointerFields.lift(); return structValue; }, }, From 20457f42ab5845b81877aa3017eea70bf0a271c2 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 19:28:49 +0900 Subject: [PATCH 3/8] [NFC] BridgeJS: Remove remaining explicit captures from enum/struct helpers --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 6 +-- .../Sources/BridgeJSLink/JSGlueGen.swift | 4 +- .../BridgeJSLinkTests/ArrayTypes.js | 6 +-- .../BridgeJSLinkTests/DefaultParameters.js | 12 +++--- .../BridgeJSLinkTests/EnumAssociatedValue.js | 38 ++++++++--------- .../ImportedTypeInExportedInterface.js | 6 +-- .../BridgeJSLinkTests/Protocol.js | 4 +- .../StaticFunctions.Global.js | 4 +- .../BridgeJSLinkTests/StaticFunctions.js | 4 +- .../BridgeJSLinkTests/SwiftClosure.js | 4 +- .../BridgeJSLinkTests/SwiftStruct.js | 42 +++++++++---------- .../BridgeJSLinkTests/SwiftStructImports.js | 6 +-- .../BridgeJSLinkTests/UnsafePointer.js | 6 +-- 13 files changed, 71 insertions(+), 71 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index c2b0c6ed3..af6961711 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -478,7 +478,7 @@ public struct BridgeJSLink { printer.write("bjs[\"swift_js_struct_lift_\(structDef.name)\"] = function() {") printer.indent { printer.write( - "const value = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lift(\(JSGlueVariableScope.reservedTmpRetStrings), \(JSGlueVariableScope.reservedTmpRetInts), \(JSGlueVariableScope.reservedTmpRetF32s), \(JSGlueVariableScope.reservedTmpRetF64s), \(JSGlueVariableScope.reservedTmpRetPointers));" + "const value = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lift();" ) printer.write("return \(JSGlueVariableScope.reservedSwift).memory.retain(value);") } @@ -1162,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.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers));" + "const \(enumDef.name)Helpers = __bjs_create\(enumDef.valuesName)Helpers()();" ) printer.write("\(JSGlueVariableScope.reservedEnumHelpers).\(enumDef.name) = \(enumDef.name)Helpers;") printer.nextLine() @@ -1178,7 +1178,7 @@ public struct BridgeJSLink { for skeleton in skeletons.compactMap(\.exported) { for structDef in skeleton.structs { printer.write( - "const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()(\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), \(JSGlueVariableScope.reservedTextEncoder), \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedEnumHelpers));" + "const \(structDef.name)Helpers = __bjs_create\(structDef.name)Helpers()();" ) printer.write( "\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name) = \(structDef.name)Helpers;" diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ae83f33e6..ff0343fd3 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -2075,7 +2075,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("const __bjs_create\(enumName)Helpers = () => {") printer.indent() printer.write( - "return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), textEncoder, \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedStructHelpers), \(JSGlueVariableScope.reservedEnumHelpers)) => ({" + "return () => ({" ) printer.indent() @@ -3109,7 +3109,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("const __bjs_create\(structName)Helpers = () => {") printer.indent() printer.write( - "return (\(JSGlueVariableScope.reservedTmpParamInts), \(JSGlueVariableScope.reservedTmpParamF32s), \(JSGlueVariableScope.reservedTmpParamF64s), \(JSGlueVariableScope.reservedTmpParamPointers), \(JSGlueVariableScope.reservedTmpRetPointers), textEncoder, \(JSGlueVariableScope.reservedSwift), \(JSGlueVariableScope.reservedEnumHelpers)) => ({" + "return () => ({" ) printer.indent() diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 42176ae1f..7093fe417 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -48,7 +48,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createPointHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamF64s.push(value.x); tmpParamF64s.push(value.y); @@ -147,7 +147,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Point"] = function() { - const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Point.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -389,7 +389,7 @@ export async function createInstantiator(options, swift) { } } - const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const PointHelpers = __bjs_createPointHelpers()(); structHelpers.Point = PointHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index 4317cc124..e19eb5fb4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -41,7 +41,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createConfigHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { const bytes = textEncoder.encode(value.name); const id = swift.memory.retain(bytes); @@ -63,7 +63,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createMathOperationsHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamF64s.push(value.baseValue); return { cleanup: undefined }; @@ -172,7 +172,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Config"] = function() { - const value = structHelpers.Config.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Config.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_MathOperations"] = function(objectId) { @@ -183,7 +183,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_MathOperations"] = function() { - const value = structHelpers.MathOperations.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.MathOperations.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -431,10 +431,10 @@ export async function createInstantiator(options, swift) { } } } - const ConfigHelpers = __bjs_createConfigHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const ConfigHelpers = __bjs_createConfigHelpers()(); structHelpers.Config = ConfigHelpers; - const MathOperationsHelpers = __bjs_createMathOperationsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const MathOperationsHelpers = __bjs_createMathOperationsHelpers()(); structHelpers.MathOperations = MathOperationsHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index b25276d9f..8491c08a2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -116,7 +116,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createPointHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamF64s.push(value.x); tmpParamF64s.push(value.y); @@ -130,7 +130,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createAPIResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -201,7 +201,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createComplexResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -321,7 +321,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -385,7 +385,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createNetworkingResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -431,7 +431,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createAPIOptionalResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -560,7 +560,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createTypedPayloadResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -635,7 +635,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createAllTypesResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -722,7 +722,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createOptionalAllTypesResultValuesHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -965,7 +965,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Point"] = function() { - const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Point.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -1103,31 +1103,31 @@ export async function createInstantiator(options, swift) { } } - const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const PointHelpers = __bjs_createPointHelpers()(); structHelpers.Point = PointHelpers; - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(); enumHelpers.APIResult = APIResultHelpers; - const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const ComplexResultHelpers = __bjs_createComplexResultValuesHelpers()(); enumHelpers.ComplexResult = ComplexResultHelpers; - const ResultHelpers = __bjs_createResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const ResultHelpers = __bjs_createResultValuesHelpers()(); enumHelpers.Result = ResultHelpers; - const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const NetworkingResultHelpers = __bjs_createNetworkingResultValuesHelpers()(); enumHelpers.NetworkingResult = NetworkingResultHelpers; - const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const APIOptionalResultHelpers = __bjs_createAPIOptionalResultValuesHelpers()(); enumHelpers.APIOptionalResult = APIOptionalResultHelpers; - const TypedPayloadResultHelpers = __bjs_createTypedPayloadResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const TypedPayloadResultHelpers = __bjs_createTypedPayloadResultValuesHelpers()(); enumHelpers.TypedPayloadResult = TypedPayloadResultHelpers; - const AllTypesResultHelpers = __bjs_createAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const AllTypesResultHelpers = __bjs_createAllTypesResultValuesHelpers()(); enumHelpers.AllTypesResult = AllTypesResultHelpers; - const OptionalAllTypesResultHelpers = __bjs_createOptionalAllTypesResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const OptionalAllTypesResultHelpers = __bjs_createOptionalAllTypesResultValuesHelpers()(); enumHelpers.OptionalAllTypesResult = OptionalAllTypesResultHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 23db5be56..1e4e1f508 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createFooContainerHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { let id; if (value.foo != null) { @@ -184,7 +184,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_FooContainer"] = function() { - const value = structHelpers.FooContainer.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.FooContainer.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -298,7 +298,7 @@ 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); + const FooContainerHelpers = __bjs_createFooContainerHelpers()(); structHelpers.FooContainer = FooContainerHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 965df2b37..0ed0be7b6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -59,7 +59,7 @@ 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) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -723,7 +723,7 @@ 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); + const ResultHelpers = __bjs_createResultValuesHelpers()(); enumHelpers.Result = ResultHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 451c356a5..7579c72f7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -46,7 +46,7 @@ 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) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -312,7 +312,7 @@ export async function createInstantiator(options, swift) { return ret; } } - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(); enumHelpers.APIResult = APIResultHelpers; if (typeof globalThis.Utils === 'undefined') { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index 00135e97d..bb3920888 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -46,7 +46,7 @@ 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) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -312,7 +312,7 @@ export async function createInstantiator(options, swift) { return ret; } } - const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, structHelpers, enumHelpers); + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(); enumHelpers.APIResult = APIResultHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 9f2c16b2d..36b712362 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -65,7 +65,7 @@ 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) => ({ + return () => ({ lower: (value) => { const enumTag = value.tag; switch (enumTag) { @@ -926,7 +926,7 @@ 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); + const APIResultHelpers = __bjs_createAPIResultValuesHelpers()(); enumHelpers.APIResult = APIResultHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index 1198f1539..b22afee4d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -40,7 +40,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createDataPointHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamF64s.push(value.x); tmpParamF64s.push(value.y); @@ -92,7 +92,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createAddressHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { const bytes = textEncoder.encode(value.street); const id = swift.memory.retain(bytes); @@ -131,7 +131,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createPersonHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { const bytes = textEncoder.encode(value.name); const id = swift.memory.retain(bytes); @@ -175,7 +175,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createSessionHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamInts.push((value.id | 0)); tmpParamPointers.push(value.owner.pointer); @@ -190,7 +190,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createMeasurementHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamF64s.push(value.value); tmpParamF32s.push(Math.fround(value.precision)); @@ -219,7 +219,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createConfigStructHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { return { cleanup: undefined }; }, @@ -229,7 +229,7 @@ export async function createInstantiator(options, swift) { }); }; const __bjs_createContainerHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { let id; if (value.object != null) { @@ -377,7 +377,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_DataPoint"] = function() { - const value = structHelpers.DataPoint.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.DataPoint.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Address"] = function(objectId) { @@ -388,7 +388,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Address"] = function() { - const value = structHelpers.Address.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Address.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Person"] = function(objectId) { @@ -399,7 +399,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Person"] = function() { - const value = structHelpers.Person.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Person.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Session"] = function(objectId) { @@ -410,7 +410,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Session"] = function() { - const value = structHelpers.Session.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Session.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Measurement"] = function(objectId) { @@ -421,7 +421,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Measurement"] = function() { - const value = structHelpers.Measurement.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Measurement.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_ConfigStruct"] = function(objectId) { @@ -432,7 +432,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_ConfigStruct"] = function() { - const value = structHelpers.ConfigStruct.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.ConfigStruct.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Container"] = function(objectId) { @@ -443,7 +443,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Container"] = function() { - const value = structHelpers.Container.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Container.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -606,25 +606,25 @@ export async function createInstantiator(options, swift) { swift.memory.release(valueId); } } - const DataPointHelpers = __bjs_createDataPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const DataPointHelpers = __bjs_createDataPointHelpers()(); structHelpers.DataPoint = DataPointHelpers; - const AddressHelpers = __bjs_createAddressHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const AddressHelpers = __bjs_createAddressHelpers()(); structHelpers.Address = AddressHelpers; - const PersonHelpers = __bjs_createPersonHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const PersonHelpers = __bjs_createPersonHelpers()(); structHelpers.Person = PersonHelpers; - const SessionHelpers = __bjs_createSessionHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const SessionHelpers = __bjs_createSessionHelpers()(); structHelpers.Session = SessionHelpers; - const MeasurementHelpers = __bjs_createMeasurementHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const MeasurementHelpers = __bjs_createMeasurementHelpers()(); structHelpers.Measurement = MeasurementHelpers; - const ConfigStructHelpers = __bjs_createConfigStructHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const ConfigStructHelpers = __bjs_createConfigStructHelpers()(); structHelpers.ConfigStruct = ConfigStructHelpers; - const ContainerHelpers = __bjs_createContainerHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const ContainerHelpers = __bjs_createContainerHelpers()(); structHelpers.Container = ContainerHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 393cd6847..f6f63ba8d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createPointHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamInts.push((value.x | 0)); tmpParamInts.push((value.y | 0)); @@ -134,7 +134,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_Point"] = function() { - const value = structHelpers.Point.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.Point.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -250,7 +250,7 @@ export async function createInstantiator(options, swift) { /** @param {WebAssembly.Instance} instance */ createExports: (instance) => { const js = swift.memory.heap; - const PointHelpers = __bjs_createPointHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const PointHelpers = __bjs_createPointHelpers()(); structHelpers.Point = PointHelpers; const exports = { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index a2240a9e6..9d94d5f0a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -35,7 +35,7 @@ export async function createInstantiator(options, swift) { let _exports = null; let bjs = null; const __bjs_createPointerFieldsHelpers = () => { - return (tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers) => ({ + return () => ({ lower: (value) => { tmpParamPointers.push((value.raw | 0)); tmpParamPointers.push((value.mutRaw | 0)); @@ -139,7 +139,7 @@ export async function createInstantiator(options, swift) { return 0; } bjs["swift_js_struct_lift_PointerFields"] = function() { - const value = structHelpers.PointerFields.lift(tmpRetStrings, tmpRetInts, tmpRetF32s, tmpRetF64s, tmpRetPointers); + const value = structHelpers.PointerFields.lift(); return swift.memory.retain(value); } bjs["swift_js_return_optional_bool"] = function(isSome, value) { @@ -244,7 +244,7 @@ export async function createInstantiator(options, swift) { /** @param {WebAssembly.Instance} instance */ createExports: (instance) => { const js = swift.memory.heap; - const PointerFieldsHelpers = __bjs_createPointerFieldsHelpers()(tmpParamInts, tmpParamF32s, tmpParamF64s, tmpParamPointers, tmpRetPointers, textEncoder, swift, enumHelpers); + const PointerFieldsHelpers = __bjs_createPointerFieldsHelpers()(); structHelpers.PointerFields = PointerFieldsHelpers; const exports = { From 516fb9d452057ae0083541df346bb9d21e1c47a0 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 19:00:44 +0900 Subject: [PATCH 4/8] BridgeJS: Make Stack ABI storage direction agnostic --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 36 +- .../Sources/BridgeJSLink/JSGlueGen.swift | 160 ++++---- .../BridgeJSLinkTests/ArrayTypes.js | 328 ++++++++------- .../__Snapshots__/BridgeJSLinkTests/Async.js | 36 +- .../BridgeJSLinkTests/DefaultParameters.js | 104 +++-- .../BridgeJSLinkTests/EnumAssociatedValue.js | 378 +++++++++--------- .../BridgeJSLinkTests/EnumCase.js | 36 +- .../BridgeJSLinkTests/EnumNamespace.Global.js | 36 +- .../BridgeJSLinkTests/EnumNamespace.js | 36 +- .../BridgeJSLinkTests/EnumRawType.js | 36 +- .../BridgeJSLinkTests/GlobalGetter.js | 36 +- .../BridgeJSLinkTests/GlobalThisImports.js | 36 +- .../BridgeJSLinkTests/ImportArray.js | 48 +-- .../ImportedTypeInExportedInterface.js | 72 ++-- .../BridgeJSLinkTests/InvalidPropertyNames.js | 36 +- .../BridgeJSLinkTests/JSClass.js | 36 +- .../JSClassStaticFunctions.js | 36 +- .../BridgeJSLinkTests/JSValue.js | 134 +++---- .../BridgeJSLinkTests/MixedGlobal.js | 36 +- .../BridgeJSLinkTests/MixedModules.js | 36 +- .../BridgeJSLinkTests/MixedPrivate.js | 36 +- .../BridgeJSLinkTests/Namespaces.Global.js | 36 +- .../BridgeJSLinkTests/Namespaces.js | 36 +- .../BridgeJSLinkTests/Optionals.js | 36 +- .../BridgeJSLinkTests/PrimitiveParameters.js | 36 +- .../BridgeJSLinkTests/PrimitiveReturn.js | 36 +- .../BridgeJSLinkTests/PropertyTypes.js | 36 +- .../BridgeJSLinkTests/Protocol.js | 66 ++- .../StaticFunctions.Global.js | 48 +-- .../BridgeJSLinkTests/StaticFunctions.js | 48 +-- .../StaticProperties.Global.js | 36 +- .../BridgeJSLinkTests/StaticProperties.js | 36 +- .../BridgeJSLinkTests/StringParameter.js | 36 +- .../BridgeJSLinkTests/StringReturn.js | 36 +- .../BridgeJSLinkTests/SwiftClass.js | 36 +- .../BridgeJSLinkTests/SwiftClosure.js | 58 ++- .../BridgeJSLinkTests/SwiftClosureImports.js | 36 +- .../BridgeJSLinkTests/SwiftStruct.js | 156 ++++---- .../BridgeJSLinkTests/SwiftStructImports.js | 44 +- .../__Snapshots__/BridgeJSLinkTests/Throws.js | 36 +- .../BridgeJSLinkTests/UnsafePointer.js | 56 ++- .../VoidParameterVoidReturn.js | 36 +- 42 files changed, 1268 insertions(+), 1440 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index af6961711..9689f708d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -246,16 +246,12 @@ public struct BridgeJSLink { "let \(JSGlueVariableScope.reservedStorageToReturnOptionalFloat);", "let \(JSGlueVariableScope.reservedStorageToReturnOptionalDouble);", "let \(JSGlueVariableScope.reservedStorageToReturnOptionalHeapObject);", - "let \(JSGlueVariableScope.reservedTmpRetTag) = [];", - "let \(JSGlueVariableScope.reservedTmpRetStrings) = [];", - "let \(JSGlueVariableScope.reservedTmpRetInts) = [];", - "let \(JSGlueVariableScope.reservedTmpRetF32s) = [];", - "let \(JSGlueVariableScope.reservedTmpRetF64s) = [];", - "let \(JSGlueVariableScope.reservedTmpParamInts) = [];", - "let \(JSGlueVariableScope.reservedTmpParamF32s) = [];", - "let \(JSGlueVariableScope.reservedTmpParamF64s) = [];", - "let \(JSGlueVariableScope.reservedTmpRetPointers) = [];", - "let \(JSGlueVariableScope.reservedTmpParamPointers) = [];", + "let \(JSGlueVariableScope.reservedTagStack) = [];", + "let \(JSGlueVariableScope.reservedStringStack) = [];", + "let \(JSGlueVariableScope.reservedI32Stack) = [];", + "let \(JSGlueVariableScope.reservedF32Stack) = [];", + "let \(JSGlueVariableScope.reservedF64Stack) = [];", + "let \(JSGlueVariableScope.reservedPointerStack) = [];", "let \(JSGlueVariableScope.reservedTmpStructCleanups) = [];", "const \(JSGlueVariableScope.reservedEnumHelpers) = {};", "const \(JSGlueVariableScope.reservedStructHelpers) = {};", @@ -388,22 +384,22 @@ public struct BridgeJSLink { printer.write("}") printer.write("bjs[\"swift_js_push_tag\"] = function(tag) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetTag).push(tag);") + printer.write("\(JSGlueVariableScope.reservedTagStack).push(tag);") } printer.write("}") printer.write("bjs[\"swift_js_push_i32\"] = function(v) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(v | 0);") + printer.write("\(JSGlueVariableScope.reservedI32Stack).push(v | 0);") } printer.write("}") printer.write("bjs[\"swift_js_push_f32\"] = function(v) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetF32s).push(Math.fround(v));") + printer.write("\(JSGlueVariableScope.reservedF32Stack).push(Math.fround(v));") } printer.write("}") printer.write("bjs[\"swift_js_push_f64\"] = function(v) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetF64s).push(v);") + printer.write("\(JSGlueVariableScope.reservedF64Stack).push(v);") } printer.write("}") printer.write("bjs[\"swift_js_push_string\"] = function(ptr, len) {") @@ -412,32 +408,32 @@ public struct BridgeJSLink { "const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, ptr, len)\(sharedMemory ? ".slice()" : "");" ) printer.write("const value = \(JSGlueVariableScope.reservedTextDecoder).decode(bytes);") - printer.write("\(JSGlueVariableScope.reservedTmpRetStrings).push(value);") + printer.write("\(JSGlueVariableScope.reservedStringStack).push(value);") } printer.write("}") printer.write("bjs[\"swift_js_pop_i32\"] = function() {") printer.indent { - printer.write("return \(JSGlueVariableScope.reservedTmpParamInts).pop();") + printer.write("return \(JSGlueVariableScope.reservedI32Stack).pop();") } printer.write("}") printer.write("bjs[\"swift_js_pop_f32\"] = function() {") printer.indent { - printer.write("return \(JSGlueVariableScope.reservedTmpParamF32s).pop();") + printer.write("return \(JSGlueVariableScope.reservedF32Stack).pop();") } printer.write("}") printer.write("bjs[\"swift_js_pop_f64\"] = function() {") printer.indent { - printer.write("return \(JSGlueVariableScope.reservedTmpParamF64s).pop();") + printer.write("return \(JSGlueVariableScope.reservedF64Stack).pop();") } printer.write("}") printer.write("bjs[\"swift_js_push_pointer\"] = function(pointer) {") printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpRetPointers).push(pointer);") + printer.write("\(JSGlueVariableScope.reservedPointerStack).push(pointer);") } printer.write("}") printer.write("bjs[\"swift_js_pop_pointer\"] = function() {") printer.indent { - printer.write("return \(JSGlueVariableScope.reservedTmpParamPointers).pop();") + printer.write("return \(JSGlueVariableScope.reservedPointerStack).pop();") } printer.write("}") printer.write("bjs[\"swift_js_struct_cleanup\"] = function(cleanupId) {") diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ff0343fd3..ae595d656 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -20,16 +20,12 @@ final class JSGlueVariableScope { static let reservedStorageToReturnOptionalHeapObject = "tmpRetOptionalHeapObject" static let reservedTextEncoder = "textEncoder" static let reservedTextDecoder = "textDecoder" - static let reservedTmpRetTag = "tmpRetTag" - static let reservedTmpRetStrings = "tmpRetStrings" - static let reservedTmpRetInts = "tmpRetInts" - static let reservedTmpRetF32s = "tmpRetF32s" - static let reservedTmpRetF64s = "tmpRetF64s" - static let reservedTmpParamInts = "tmpParamInts" - static let reservedTmpParamF32s = "tmpParamF32s" - static let reservedTmpParamF64s = "tmpParamF64s" - static let reservedTmpRetPointers = "tmpRetPointers" - static let reservedTmpParamPointers = "tmpParamPointers" + static let reservedTagStack = "tagStack" + static let reservedStringStack = "strStack" + static let reservedI32Stack = "i32Stack" + static let reservedF32Stack = "f32Stack" + static let reservedF64Stack = "f64Stack" + static let reservedPointerStack = "ptrStack" static let reservedTmpStructCleanups = "tmpStructCleanups" static let reservedEnumHelpers = "enumHelpers" static let reservedStructHelpers = "structHelpers" @@ -51,16 +47,12 @@ final class JSGlueVariableScope { reservedStorageToReturnOptionalHeapObject, reservedTextEncoder, reservedTextDecoder, - reservedTmpRetTag, - reservedTmpRetStrings, - reservedTmpRetInts, - reservedTmpRetF32s, - reservedTmpRetF64s, - reservedTmpParamInts, - reservedTmpParamF32s, - reservedTmpParamF64s, - reservedTmpRetPointers, - reservedTmpParamPointers, + reservedTagStack, + reservedStringStack, + reservedI32Stack, + reservedF32Stack, + reservedF64Stack, + reservedPointerStack, reservedTmpStructCleanups, reservedEnumHelpers, reservedStructHelpers, @@ -100,46 +92,46 @@ extension JSGlueVariableScope { // MARK: Parameter func emitPushI32Parameter(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedI32Stack).push(\(value));") } func emitPushF64Parameter(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpParamF64s).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedF64Stack).push(\(value));") } func emitPushF32Parameter(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpParamF32s).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedF32Stack).push(\(value));") } func emitPushPointerParameter(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpParamPointers).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedPointerStack).push(\(value));") } // MARK: Return func emitPushI32Return(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpRetInts).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedI32Stack).push(\(value));") } func emitPushF64Return(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpRetF64s).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedF64Stack).push(\(value));") } func emitPushPointerReturn(_ value: String, printer: CodeFragmentPrinter) { - printer.write("\(JSGlueVariableScope.reservedTmpRetPointers).push(\(value));") + printer.write("\(JSGlueVariableScope.reservedPointerStack).push(\(value));") } - func popTagReturn() -> String { - return "\(JSGlueVariableScope.reservedTmpRetTag).pop()" + func popTag() -> String { + return "\(JSGlueVariableScope.reservedTagStack).pop()" } - func popStringReturn() -> String { - return "\(JSGlueVariableScope.reservedTmpRetStrings).pop()" + func popString() -> String { + return "\(JSGlueVariableScope.reservedStringStack).pop()" } - func popI32Return() -> String { - return "\(JSGlueVariableScope.reservedTmpRetInts).pop()" + func popI32() -> String { + return "\(JSGlueVariableScope.reservedI32Stack).pop()" } - func popF64Return() -> String { - return "\(JSGlueVariableScope.reservedTmpRetF64s).pop()" + func popF64() -> String { + return "\(JSGlueVariableScope.reservedF64Stack).pop()" } - func popF32Return() -> String { - return "\(JSGlueVariableScope.reservedTmpRetF32s).pop()" + func popF32() -> String { + return "\(JSGlueVariableScope.reservedF32Stack).pop()" } - func popPointerReturn() -> String { - return "\(JSGlueVariableScope.reservedTmpRetPointers).pop()" + func popPointer() -> String { + return "\(JSGlueVariableScope.reservedPointerStack).pop()" } } @@ -544,9 +536,9 @@ struct IntrinsicJSFragment: Sendable { let payload2 = scope.variable("jsValuePayload2") let payload1 = scope.variable("jsValuePayload1") let kind = scope.variable("jsValueKind") - printer.write("const \(payload2) = \(scope.popF64Return());") - printer.write("const \(payload1) = \(scope.popI32Return());") - printer.write("const \(kind) = \(scope.popI32Return());") + printer.write("const \(payload2) = \(scope.popF64());") + printer.write("const \(payload1) = \(scope.popI32());") + printer.write("const \(kind) = \(scope.popI32());") let resultVar = scope.variable("jsValue") registerJSValueHelpers(scope: scope) printer.write( @@ -618,7 +610,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { _, scope, printer, _ in let retName = scope.variable("ret") printer.write( - "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTagReturn()));" + "const \(retName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lift(\(scope.popTag()));" ) return [retName] } @@ -933,7 +925,7 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let tagVar = scope.variable("tag") - printer.write("const \(tagVar) = \(scope.popTagReturn());") + printer.write("const \(tagVar) = \(scope.popTag());") let isNullVar = scope.variable("isNull") printer.write("const \(isNullVar) = (\(tagVar) === -1);") printer.write("let \(resultVar);") @@ -951,7 +943,7 @@ struct IntrinsicJSFragment: Sendable { case .swiftStruct(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -966,7 +958,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("}") case .array(let elementType): let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -983,7 +975,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("}") case .jsValue: let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar)) {") printer.indent { @@ -1682,7 +1674,7 @@ struct IntrinsicJSFragment: Sendable { let base = fullName.components(separatedBy: ".").last ?? fullName let resultVar = scope.variable("result") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()));" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTag()));" ) printer.write("return \(resultVar);") return [] @@ -2494,16 +2486,16 @@ struct IntrinsicJSFragment: Sendable { let optVar = scope.variable("optional") let isSomeVar = scope.variable("isSome") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") 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()). + // which pushes caseId to i32Stack (not tagStack like bridgeJSLowerReturn()). if case .associatedValueEnum(let fullName) = wrappedType { let base = fullName.components(separatedBy: ".").last ?? fullName let caseIdVar = scope.variable("caseId") - printer.write("const \(caseIdVar) = \(scope.popI32Return());") + printer.write("const \(caseIdVar) = \(scope.popI32());") printer.write( "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar));" ) @@ -2616,7 +2608,7 @@ struct IntrinsicJSFragment: Sendable { let lenVar = scope.variable("arrayLen") let iVar = scope.variable("i") - printer.write("const \(lenVar) = \(scope.popI32Return());") + printer.write("const \(lenVar) = \(scope.popI32());") printer.write("const \(resultVar) = [];") printer.write("for (let \(iVar) = 0; \(iVar) < \(lenVar); \(iVar)++) {") printer.indent { @@ -2643,9 +2635,9 @@ struct IntrinsicJSFragment: Sendable { let payload2Var = scope.variable("jsValuePayload2") let payload1Var = scope.variable("jsValuePayload1") let kindVar = scope.variable("jsValueKind") - printer.write("const \(payload2Var) = \(scope.popF64Return());") - printer.write("const \(payload1Var) = \(scope.popI32Return());") - printer.write("const \(kindVar) = \(scope.popI32Return());") + printer.write("const \(payload2Var) = \(scope.popF64());") + printer.write("const \(payload1Var) = \(scope.popI32());") + printer.write("const \(kindVar) = \(scope.popI32());") let resultVar = scope.variable("jsValue") printer.write( "const \(resultVar) = \(jsValueLiftHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" @@ -2658,7 +2650,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let strVar = scope.variable("string") - printer.write("const \(strVar) = \(scope.popStringReturn());") + printer.write("const \(strVar) = \(scope.popString());") return [strVar] } ) @@ -2667,7 +2659,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let bVar = scope.variable("bool") - printer.write("const \(bVar) = \(scope.popI32Return()) !== 0;") + printer.write("const \(bVar) = \(scope.popI32()) !== 0;") return [bVar] } ) @@ -2676,7 +2668,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let iVar = scope.variable("int") - printer.write("const \(iVar) = \(scope.popI32Return());") + printer.write("const \(iVar) = \(scope.popI32());") return [iVar] } ) @@ -2685,7 +2677,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let fVar = scope.variable("f32") - printer.write("const \(fVar) = \(scope.popF32Return());") + printer.write("const \(fVar) = \(scope.popF32());") return [fVar] } ) @@ -2694,7 +2686,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let dVar = scope.variable("f64") - printer.write("const \(dVar) = \(scope.popF64Return());") + printer.write("const \(dVar) = \(scope.popF64());") return [dVar] } ) @@ -2715,7 +2707,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("caseId") - printer.write("const \(varName) = \(scope.popI32Return());") + printer.write("const \(varName) = \(scope.popI32());") return [varName] } ) @@ -2726,7 +2718,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(scope.popStringReturn());") + printer.write("const \(varName) = \(scope.popString());") return [varName] } ) @@ -2735,7 +2727,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(scope.popF32Return());") + printer.write("const \(varName) = \(scope.popF32());") return [varName] } ) @@ -2744,7 +2736,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(scope.popF64Return());") + printer.write("const \(varName) = \(scope.popF64());") return [varName] } ) @@ -2753,7 +2745,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let varName = scope.variable("rawValue") - printer.write("const \(varName) = \(scope.popI32Return());") + printer.write("const \(varName) = \(scope.popI32());") return [varName] } ) @@ -2765,7 +2757,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let resultVar = scope.variable("enumValue") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTagReturn()), );" + "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(scope.popTag()), );" ) return [resultVar] } @@ -2776,7 +2768,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let ptrVar = scope.variable("ptr") let objVar = scope.variable("obj") - printer.write("const \(ptrVar) = \(scope.popPointerReturn());") + printer.write("const \(ptrVar) = \(scope.popPointer());") printer.write("const \(objVar) = _exports['\(className)'].__construct(\(ptrVar));") return [objVar] } @@ -2787,7 +2779,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let idVar = scope.variable("objId") let objVar = scope.variable("obj") - printer.write("const \(idVar) = \(scope.popI32Return());") + printer.write("const \(idVar) = \(scope.popI32());") printer.write("const \(objVar) = \(JSGlueVariableScope.reservedSwift).memory.getObject(\(idVar));") printer.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [objVar] @@ -2802,7 +2794,7 @@ struct IntrinsicJSFragment: Sendable { parameters: [], printCode: { arguments, scope, printer, cleanup in let pVar = scope.variable("pointer") - printer.write("const \(pVar) = \(scope.popPointerReturn());") + printer.write("const \(pVar) = \(scope.popPointer());") return [pVar] } ) @@ -3021,7 +3013,7 @@ struct IntrinsicJSFragment: Sendable { let isSomeVar = scope.variable("isSome") let resultVar = scope.variable("optValue") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") printer.write("let \(resultVar);") printer.write("if (\(isSomeVar) === 0) {") printer.indent { @@ -3477,7 +3469,7 @@ struct IntrinsicJSFragment: Sendable { pushOptionalPrimitive( value: value, isSomeVar: isSomeVar, - stack: .tmpParamInts, + stack: .i32Stack, convert: "| 0", zeroValue: "0", printer: printer, @@ -3487,7 +3479,7 @@ struct IntrinsicJSFragment: Sendable { pushOptionalPrimitive( value: value, isSomeVar: isSomeVar, - stack: .tmpParamInts, + stack: .i32Stack, convert: "? 1 : 0", zeroValue: "0", printer: printer, @@ -3497,7 +3489,7 @@ struct IntrinsicJSFragment: Sendable { pushOptionalPrimitive( value: value, isSomeVar: isSomeVar, - stack: .tmpParamF32s, + stack: .f32Stack, convert: "Math.fround", zeroValue: "0.0", printer: printer, @@ -3507,7 +3499,7 @@ struct IntrinsicJSFragment: Sendable { pushOptionalPrimitive( value: value, isSomeVar: isSomeVar, - stack: .tmpParamF64s, + stack: .f64Stack, convert: nil, zeroValue: "0.0", printer: printer, @@ -3622,9 +3614,9 @@ struct IntrinsicJSFragment: Sendable { ) { let stackName: String switch stack { - case .tmpParamInts: stackName = JSGlueVariableScope.reservedTmpParamInts - case .tmpParamF32s: stackName = JSGlueVariableScope.reservedTmpParamF32s - case .tmpParamF64s: stackName = JSGlueVariableScope.reservedTmpParamF64s + case .i32Stack: stackName = JSGlueVariableScope.reservedI32Stack + case .f32Stack: stackName = JSGlueVariableScope.reservedF32Stack + case .f64Stack: stackName = JSGlueVariableScope.reservedF64Stack } printer.write("if (\(isSomeVar)) {") @@ -3650,9 +3642,9 @@ struct IntrinsicJSFragment: Sendable { } private enum StackType { - case tmpParamInts - case tmpParamF32s - case tmpParamF64s + case i32Stack + case f32Stack + case f64Stack } private static func structFieldLiftFragment( @@ -3668,15 +3660,15 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let isSomeVar = scope.variable("isSome") let optVar = scope.variable("optional") - printer.write("const \(isSomeVar) = \(scope.popI32Return());") + printer.write("const \(isSomeVar) = \(scope.popI32());") printer.write("let \(optVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - // Special handling for associated value enum - in struct fields, case ID is pushed to tmpRetInts + // Special handling for associated value enum - in struct fields, case ID is pushed to i32Stack if case .associatedValueEnum(let enumName) = wrappedType { let base = enumName.components(separatedBy: ".").last ?? enumName let caseIdVar = scope.variable("enumCaseId") - printer.write("const \(caseIdVar) = \(scope.popI32Return());") + printer.write("const \(caseIdVar) = \(scope.popI32());") printer.write( "\(optVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lift(\(caseIdVar), );" ) @@ -3723,7 +3715,7 @@ struct IntrinsicJSFragment: Sendable { printCode: { arguments, scope, printer, cleanup in let objectIdVar = scope.variable("objectId") let varName = scope.variable("value") - printer.write("const \(objectIdVar) = \(scope.popI32Return());") + printer.write("const \(objectIdVar) = \(scope.popI32());") printer.write("let \(varName);") printer.write("if (\(objectIdVar) !== 0) {") printer.indent { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 7093fe417..5b8c451e2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -31,16 +31,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -50,13 +46,13 @@ export async function createInstantiator(options, swift) { const __bjs_createPointHelpers = () => { return () => ({ lower: (value) => { - tmpParamF64s.push(value.x); - tmpParamF64s.push(value.y); + f64Stack.push(value.x); + f64Stack.push(value.y); return { cleanup: undefined }; }, lift: () => { - const f64 = tmpRetF64s.pop(); - const f641 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); + const f641 = f64Stack.pop(); return { x: f641, y: f64 }; } }); @@ -98,36 +94,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -265,10 +261,10 @@ export async function createInstantiator(options, swift) { } TestModule["bjs_importProcessNumbers"] = function bjs_importProcessNumbers() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); arrayResult.push(f64); } arrayResult.reverse(); @@ -282,38 +278,38 @@ export async function createInstantiator(options, swift) { let ret = imports.importGetNumbers(); const arrayCleanups = []; for (const elem of ret) { - tmpParamF64s.push(elem); + f64Stack.push(elem); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } } TestModule["bjs_importTransformNumbers"] = function bjs_importTransformNumbers() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); arrayResult.push(f64); } arrayResult.reverse(); let ret = imports.importTransformNumbers(arrayResult); const arrayCleanups = []; for (const elem of ret) { - tmpParamF64s.push(elem); + f64Stack.push(elem); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } } TestModule["bjs_importProcessStrings"] = function bjs_importProcessStrings() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); arrayResult.push(string); } arrayResult.reverse(); @@ -322,32 +318,32 @@ export async function createInstantiator(options, swift) { for (const elem of ret) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); arrayCleanups.push(() => { swift.memory.release(id); }); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } } TestModule["bjs_importProcessBooleans"] = function bjs_importProcessBooleans() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; arrayResult.push(bool); } arrayResult.reverse(); let ret = imports.importProcessBooleans(arrayResult); const arrayCleanups = []; for (const elem of ret) { - tmpParamInts.push(elem ? 1 : 0); + i32Stack.push(elem ? 1 : 0); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } @@ -397,14 +393,14 @@ export async function createInstantiator(options, swift) { processIntArray: function bjs_processIntArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processIntArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -416,18 +412,18 @@ export async function createInstantiator(options, swift) { for (const elem of values) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); arrayCleanups.push(() => { swift.memory.release(id); }); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processStringArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); arrayResult.push(string); } arrayResult.reverse(); @@ -437,14 +433,14 @@ export async function createInstantiator(options, swift) { processDoubleArray: function bjs_processDoubleArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamF64s.push(elem); + f64Stack.push(elem); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processDoubleArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); arrayResult.push(f64); } arrayResult.reverse(); @@ -454,14 +450,14 @@ export async function createInstantiator(options, swift) { processBoolArray: function bjs_processBoolArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push(elem ? 1 : 0); + i32Stack.push(elem ? 1 : 0); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processBoolArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; arrayResult.push(bool); } arrayResult.reverse(); @@ -476,9 +472,9 @@ export async function createInstantiator(options, swift) { if (structCleanup) { structCleanup(); } }); } - tmpParamInts.push(points.length); + i32Stack.push(points.length); instance.exports.bjs_processPointArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { const struct = structHelpers.Point.lift(); @@ -491,14 +487,14 @@ export async function createInstantiator(options, swift) { processDirectionArray: function bjs_processDirectionArray(directions) { const arrayCleanups = []; for (const elem of directions) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(directions.length); + i32Stack.push(directions.length); instance.exports.bjs_processDirectionArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const caseId = tmpRetInts.pop(); + const caseId = i32Stack.pop(); arrayResult.push(caseId); } arrayResult.reverse(); @@ -508,14 +504,14 @@ export async function createInstantiator(options, swift) { processStatusArray: function bjs_processStatusArray(statuses) { const arrayCleanups = []; for (const elem of statuses) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(statuses.length); + i32Stack.push(statuses.length); instance.exports.bjs_processStatusArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const rawValue = tmpRetInts.pop(); + const rawValue = i32Stack.pop(); arrayResult.push(rawValue); } arrayResult.reverse(); @@ -525,9 +521,9 @@ export async function createInstantiator(options, swift) { sumIntArray: function bjs_sumIntArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); const ret = instance.exports.bjs_sumIntArray(); for (const cleanup of arrayCleanups) { cleanup(); } return ret; @@ -540,7 +536,7 @@ export async function createInstantiator(options, swift) { if (structCleanup) { structCleanup(); } }); } - tmpParamInts.push(points.length); + i32Stack.push(points.length); const matchingBytes = textEncoder.encode(matching); const matchingId = swift.memory.retain(matchingBytes); instance.exports.bjs_findFirstPoint(matchingId, matchingBytes.length); @@ -552,14 +548,14 @@ export async function createInstantiator(options, swift) { processUnsafeRawPointerArray: function bjs_processUnsafeRawPointerArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamPointers.push((elem | 0)); + ptrStack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processUnsafeRawPointerArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const pointer = tmpRetPointers.pop(); + const pointer = ptrStack.pop(); arrayResult.push(pointer); } arrayResult.reverse(); @@ -569,14 +565,14 @@ export async function createInstantiator(options, swift) { processUnsafeMutableRawPointerArray: function bjs_processUnsafeMutableRawPointerArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamPointers.push((elem | 0)); + ptrStack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processUnsafeMutableRawPointerArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const pointer = tmpRetPointers.pop(); + const pointer = ptrStack.pop(); arrayResult.push(pointer); } arrayResult.reverse(); @@ -586,14 +582,14 @@ export async function createInstantiator(options, swift) { processOpaquePointerArray: function bjs_processOpaquePointerArray(values) { const arrayCleanups = []; for (const elem of values) { - tmpParamPointers.push((elem | 0)); + ptrStack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processOpaquePointerArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const pointer = tmpRetPointers.pop(); + const pointer = ptrStack.pop(); arrayResult.push(pointer); } arrayResult.reverse(); @@ -605,23 +601,23 @@ export async function createInstantiator(options, swift) { for (const elem of values) { const isSome = elem != null ? 1 : 0; if (isSome) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processOptionalIntArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); optValue = int; } arrayResult.push(optValue); @@ -637,26 +633,26 @@ export async function createInstantiator(options, swift) { if (isSome) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); arrayCleanups.push(() => { swift.memory.release(id); }); } else { - tmpParamInts.push(0); - tmpParamInts.push(0); + i32Stack.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processOptionalStringArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); optValue = string; } arrayResult.push(optValue); @@ -671,19 +667,19 @@ export async function createInstantiator(options, swift) { if (isSome) { const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); } instance.exports.bjs_processOptionalArray(+isSome); - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -703,14 +699,14 @@ export async function createInstantiator(options, swift) { arrayCleanups.push(() => { if (structCleanup) { structCleanup(); } }); } else { } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(points.length); + i32Stack.push(points.length); instance.exports.bjs_processOptionalPointArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; @@ -729,23 +725,23 @@ export async function createInstantiator(options, swift) { for (const elem of directions) { const isSome = elem != null ? 1 : 0; if (isSome) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(directions.length); + i32Stack.push(directions.length); instance.exports.bjs_processOptionalDirectionArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const caseId = tmpRetInts.pop(); + const caseId = i32Stack.pop(); optValue = caseId; } arrayResult.push(optValue); @@ -759,23 +755,23 @@ export async function createInstantiator(options, swift) { for (const elem of statuses) { const isSome = elem != null ? 1 : 0; if (isSome) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(statuses.length); + i32Stack.push(statuses.length); instance.exports.bjs_processOptionalStatusArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const rawValue = tmpRetInts.pop(); + const rawValue = i32Stack.pop(); optValue = rawValue; } arrayResult.push(optValue); @@ -789,22 +785,22 @@ export async function createInstantiator(options, swift) { for (const elem of values) { const arrayCleanups1 = []; for (const elem1 of elem) { - tmpParamInts.push((elem1 | 0)); + i32Stack.push((elem1 | 0)); } - tmpParamInts.push(elem.length); + i32Stack.push(elem.length); arrayCleanups.push(() => { for (const cleanup of arrayCleanups1) { cleanup(); } }); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processNestedIntArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const arrayLen1 = tmpRetInts.pop(); + const arrayLen1 = i32Stack.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult1.push(int); } arrayResult1.reverse(); @@ -821,26 +817,26 @@ export async function createInstantiator(options, swift) { for (const elem1 of elem) { const bytes = textEncoder.encode(elem1); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); arrayCleanups1.push(() => { swift.memory.release(id); }); } - tmpParamInts.push(elem.length); + i32Stack.push(elem.length); arrayCleanups.push(() => { for (const cleanup of arrayCleanups1) { cleanup(); } }); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_processNestedStringArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const arrayLen1 = tmpRetInts.pop(); + const arrayLen1 = i32Stack.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); arrayResult1.push(string); } arrayResult1.reverse(); @@ -860,17 +856,17 @@ export async function createInstantiator(options, swift) { if (structCleanup) { structCleanup(); } }); } - tmpParamInts.push(elem.length); + i32Stack.push(elem.length); arrayCleanups.push(() => { for (const cleanup of arrayCleanups1) { cleanup(); } }); } - tmpParamInts.push(points.length); + i32Stack.push(points.length); instance.exports.bjs_processNestedPointArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const arrayLen1 = tmpRetInts.pop(); + const arrayLen1 = i32Stack.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { const struct = structHelpers.Point.lift(); @@ -886,14 +882,14 @@ export async function createInstantiator(options, swift) { processItemArray: function bjs_processItemArray(items) { const arrayCleanups = []; for (const elem of items) { - tmpParamPointers.push(elem.pointer); + ptrStack.push(elem.pointer); } - tmpParamInts.push(items.length); + i32Stack.push(items.length); instance.exports.bjs_processItemArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const ptr = tmpRetPointers.pop(); + const ptr = ptrStack.pop(); const obj = _exports['Item'].__construct(ptr); arrayResult.push(obj); } @@ -906,22 +902,22 @@ export async function createInstantiator(options, swift) { for (const elem of items) { const arrayCleanups1 = []; for (const elem1 of elem) { - tmpParamPointers.push(elem1.pointer); + ptrStack.push(elem1.pointer); } - tmpParamInts.push(elem.length); + i32Stack.push(elem.length); arrayCleanups.push(() => { for (const cleanup of arrayCleanups1) { cleanup(); } }); } - tmpParamInts.push(items.length); + i32Stack.push(items.length); instance.exports.bjs_processNestedItemArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const arrayLen1 = tmpRetInts.pop(); + const arrayLen1 = i32Stack.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { - const ptr = tmpRetPointers.pop(); + const ptr = ptrStack.pop(); const obj = _exports['Item'].__construct(ptr); arrayResult1.push(obj); } @@ -936,14 +932,14 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of objects) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(objects.length); + i32Stack.push(objects.length); instance.exports.bjs_processJSObjectArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); arrayResult.push(obj); @@ -958,23 +954,23 @@ export async function createInstantiator(options, swift) { const isSome = elem != null ? 1 : 0; if (isSome) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(objects.length); + i32Stack.push(objects.length); instance.exports.bjs_processOptionalJSObjectArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); optValue = obj; @@ -991,22 +987,22 @@ export async function createInstantiator(options, swift) { const arrayCleanups1 = []; for (const elem1 of elem) { const objId = swift.memory.retain(elem1); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(elem.length); + i32Stack.push(elem.length); arrayCleanups.push(() => { for (const cleanup of arrayCleanups1) { cleanup(); } }); } - tmpParamInts.push(objects.length); + i32Stack.push(objects.length); instance.exports.bjs_processNestedJSObjectArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const arrayLen1 = tmpRetInts.pop(); + const arrayLen1 = i32Stack.pop(); const arrayResult1 = []; for (let i1 = 0; i1 < arrayLen1; i1++) { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); arrayResult1.push(obj); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index 0aa9148c1..40ff4884a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index e19eb5fb4..c7b1dc093 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -24,16 +24,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -45,19 +41,19 @@ export async function createInstantiator(options, swift) { lower: (value) => { const bytes = textEncoder.encode(value.name); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - tmpParamInts.push((value.value | 0)); - tmpParamInts.push(value.enabled ? 1 : 0); + i32Stack.push(bytes.length); + i32Stack.push(id); + i32Stack.push((value.value | 0)); + i32Stack.push(value.enabled ? 1 : 0); const cleanup = () => { swift.memory.release(id); }; return { cleanup }; }, lift: () => { - const bool = tmpRetInts.pop() !== 0; - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); + const bool = i32Stack.pop() !== 0; + const int = i32Stack.pop(); + const string = strStack.pop(); return { name: string, value: int, enabled: bool }; } }); @@ -65,11 +61,11 @@ export async function createInstantiator(options, swift) { const __bjs_createMathOperationsHelpers = () => { return () => ({ lower: (value) => { - tmpParamF64s.push(value.baseValue); + f64Stack.push(value.baseValue); return { cleanup: undefined }; }, lift: () => { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); const instance1 = { baseValue: f64 }; instance1.add = function(a, b = 10.0) { const { cleanup: structCleanup } = structHelpers.MathOperations.lower(this); @@ -123,36 +119,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -525,7 +521,7 @@ export async function createInstantiator(options, swift) { pointCleanup = structResult.cleanup; } instance.exports.bjs_testOptionalStructDefault(+isSome); - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { optResult = structHelpers.Config.lift(); @@ -543,7 +539,7 @@ export async function createInstantiator(options, swift) { pointCleanup = structResult.cleanup; } instance.exports.bjs_testOptionalStructWithValueDefault(+isSome); - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { optResult = structHelpers.Config.lift(); @@ -556,14 +552,14 @@ export async function createInstantiator(options, swift) { testIntArrayDefault: function bjs_testIntArrayDefault(values = [1, 2, 3]) { const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_testIntArrayDefault(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -575,18 +571,18 @@ export async function createInstantiator(options, swift) { for (const elem of names) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); arrayCleanups.push(() => { swift.memory.release(id); }); } - tmpParamInts.push(names.length); + i32Stack.push(names.length); instance.exports.bjs_testStringArrayDefault(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); arrayResult.push(string); } arrayResult.reverse(); @@ -596,14 +592,14 @@ export async function createInstantiator(options, swift) { testDoubleArrayDefault: function bjs_testDoubleArrayDefault(values = [1.5, 2.5, 3.5]) { const arrayCleanups = []; for (const elem of values) { - tmpParamF64s.push(elem); + f64Stack.push(elem); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_testDoubleArrayDefault(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); arrayResult.push(f64); } arrayResult.reverse(); @@ -613,14 +609,14 @@ export async function createInstantiator(options, swift) { testBoolArrayDefault: function bjs_testBoolArrayDefault(flags = [true, false, true]) { const arrayCleanups = []; for (const elem of flags) { - tmpParamInts.push(elem ? 1 : 0); + i32Stack.push(elem ? 1 : 0); } - tmpParamInts.push(flags.length); + i32Stack.push(flags.length); instance.exports.bjs_testBoolArrayDefault(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; arrayResult.push(bool); } arrayResult.reverse(); @@ -630,14 +626,14 @@ export async function createInstantiator(options, swift) { testEmptyArrayDefault: function bjs_testEmptyArrayDefault(items = []) { const arrayCleanups = []; for (const elem of items) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(items.length); + i32Stack.push(items.length); instance.exports.bjs_testEmptyArrayDefault(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -649,9 +645,9 @@ export async function createInstantiator(options, swift) { const nameId = swift.memory.retain(nameBytes); const arrayCleanups = []; for (const elem of values) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_testMixedWithArrayDefault(nameId, nameBytes.length, enabled); const ret = tmpRetString; tmpRetString = undefined; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 8491c08a2..f04b464c6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -99,16 +99,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -118,13 +114,13 @@ export async function createInstantiator(options, swift) { const __bjs_createPointHelpers = () => { return () => ({ lower: (value) => { - tmpParamF64s.push(value.x); - tmpParamF64s.push(value.y); + f64Stack.push(value.x); + f64Stack.push(value.y); return { cleanup: undefined }; }, lift: () => { - const f64 = tmpRetF64s.pop(); - const f641 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); + const f641 = f64Stack.pop(); return { x: f641, y: f64 }; } }); @@ -137,30 +133,30 @@ export async function createInstantiator(options, swift) { case APIResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.push((value.param0 | 0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Failure, cleanup }; } case APIResultValues.Tag.Flag: { - tmpParamInts.push(value.param0 ? 1 : 0); + i32Stack.push(value.param0 ? 1 : 0); const cleanup = undefined; return { caseId: APIResultValues.Tag.Flag, cleanup }; } case APIResultValues.Tag.Rate: { - tmpParamF32s.push(Math.fround(value.param0)); + f32Stack.push(Math.fround(value.param0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Rate, cleanup }; } case APIResultValues.Tag.Precise: { - tmpParamF64s.push(value.param0); + f64Stack.push(value.param0); const cleanup = undefined; return { caseId: APIResultValues.Tag.Precise, cleanup }; } @@ -175,23 +171,23 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: APIResultValues.Tag.Success, param0: string }; } case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { tag: APIResultValues.Tag.Failure, param0: int }; } case APIResultValues.Tag.Flag: { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; return { tag: APIResultValues.Tag.Flag, param0: bool }; } case APIResultValues.Tag.Rate: { - const f32 = tmpRetF32s.pop(); + const f32 = f32Stack.pop(); return { tag: APIResultValues.Tag.Rate, param0: f32 }; } case APIResultValues.Tag.Precise: { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); return { tag: APIResultValues.Tag.Precise, param0: f64 }; } case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; @@ -208,19 +204,19 @@ export async function createInstantiator(options, swift) { case ComplexResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: ComplexResultValues.Tag.Success, cleanup }; } case ComplexResultValues.Tag.Error: { - tmpParamInts.push((value.param1 | 0)); + i32Stack.push((value.param1 | 0)); const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; @@ -229,41 +225,41 @@ export async function createInstantiator(options, swift) { 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); + i32Stack.push(bytes.length); + i32Stack.push(id); + i32Stack.push((value.param1 | 0)); + i32Stack.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); + f64Stack.push(value.param2); + f64Stack.push(value.param1); + f64Stack.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); + i32Stack.push(bytes.length); + i32Stack.push(id); const bytes1 = textEncoder.encode(value.param7); const id1 = swift.memory.retain(bytes1); - tmpParamInts.push(bytes1.length); - tmpParamInts.push(id1); + i32Stack.push(bytes1.length); + i32Stack.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); + i32Stack.push(bytes2.length); + i32Stack.push(id2); + f64Stack.push(value.param5); + f64Stack.push(value.param4); + i32Stack.push((value.param3 | 0)); + i32Stack.push((value.param2 | 0)); + i32Stack.push(value.param1 ? 1 : 0); + i32Stack.push(value.param0 ? 1 : 0); const cleanup = () => { swift.memory.release(id); swift.memory.release(id1); @@ -282,36 +278,36 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case ComplexResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: ComplexResultValues.Tag.Success, param0: string }; } case ComplexResultValues.Tag.Error: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); + const int = i32Stack.pop(); + const string = strStack.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; + const string = strStack.pop(); + const int = i32Stack.pop(); + const bool = i32Stack.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(); + const f64 = f64Stack.pop(); + const f641 = f64Stack.pop(); + const f642 = f64Stack.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; + const string = strStack.pop(); + const string1 = strStack.pop(); + const string2 = strStack.pop(); + const f64 = f64Stack.pop(); + const f641 = f64Stack.pop(); + const int = i32Stack.pop(); + const int1 = i32Stack.pop(); + const bool = i32Stack.pop() !== 0; + const bool1 = i32Stack.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 }; @@ -328,19 +324,19 @@ export async function createInstantiator(options, swift) { case ResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: ResultValues.Tag.Success, cleanup }; } case ResultValues.Tag.Failure: { - tmpParamInts.push((value.param1 | 0)); + i32Stack.push((value.param1 | 0)); const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; @@ -349,10 +345,10 @@ export async function createInstantiator(options, swift) { 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); + i32Stack.push(bytes.length); + i32Stack.push(id); + i32Stack.push((value.param1 | 0)); + i32Stack.push(value.param0 ? 1 : 0); const cleanup = () => { swift.memory.release(id); }; @@ -365,18 +361,18 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case ResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: ResultValues.Tag.Success, param0: string }; } case ResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); + const int = i32Stack.pop(); + const string = strStack.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; + const string = strStack.pop(); + const int = i32Stack.pop(); + const bool = i32Stack.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)); @@ -392,19 +388,19 @@ export async function createInstantiator(options, swift) { case NetworkingResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: NetworkingResultValues.Tag.Success, cleanup }; } case NetworkingResultValues.Tag.Failure: { - tmpParamInts.push((value.param1 | 0)); + i32Stack.push((value.param1 | 0)); const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; @@ -417,12 +413,12 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case NetworkingResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: NetworkingResultValues.Tag.Success, param0: string }; } case NetworkingResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); - const string = tmpRetStrings.pop(); + const int = i32Stack.pop(); + const string = strStack.pop(); return { tag: NetworkingResultValues.Tag.Failure, param0: string, param1: int }; } default: throw new Error("Unknown NetworkingResultValues tag returned from Swift: " + String(tag)); @@ -441,13 +437,13 @@ export async function createInstantiator(options, swift) { if (isSome) { let bytes = textEncoder.encode(value.param0); id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); } else { - tmpParamInts.push(0); - tmpParamInts.push(0); + i32Stack.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if(id) { swift.memory.release(id); @@ -457,11 +453,11 @@ export async function createInstantiator(options, swift) { } case APIOptionalResultValues.Tag.Failure: { const isSome = value.param1 != null; - tmpParamInts.push(isSome ? (value.param1 ? 1 : 0) : 0); - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? (value.param1 ? 1 : 0) : 0); + i32Stack.push(isSome ? 1 : 0); const isSome1 = value.param0 != null; - tmpParamInts.push(isSome1 ? (value.param0 | 0) : 0); - tmpParamInts.push(isSome1 ? 1 : 0); + i32Stack.push(isSome1 ? (value.param0 | 0) : 0); + i32Stack.push(isSome1 ? 1 : 0); const cleanup = undefined; return { caseId: APIOptionalResultValues.Tag.Failure, cleanup }; } @@ -471,19 +467,19 @@ export async function createInstantiator(options, swift) { if (isSome) { let bytes = textEncoder.encode(value.param2); id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); } else { - tmpParamInts.push(0); - tmpParamInts.push(0); + i32Stack.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const isSome1 = value.param1 != null; - tmpParamInts.push(isSome1 ? (value.param1 | 0) : 0); - tmpParamInts.push(isSome1 ? 1 : 0); + i32Stack.push(isSome1 ? (value.param1 | 0) : 0); + i32Stack.push(isSome1 ? 1 : 0); const isSome2 = value.param0 != null; - tmpParamInts.push(isSome2 ? (value.param0 ? 1 : 0) : 0); - tmpParamInts.push(isSome2 ? 1 : 0); + i32Stack.push(isSome2 ? (value.param0 ? 1 : 0) : 0); + i32Stack.push(isSome2 ? 1 : 0); const cleanup = () => { if(id) { swift.memory.release(id); @@ -498,10 +494,10 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case APIOptionalResultValues.Tag.Success: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); optional = string; } else { optional = null; @@ -509,18 +505,18 @@ export async function createInstantiator(options, swift) { return { tag: APIOptionalResultValues.Tag.Success, param0: optional }; } case APIOptionalResultValues.Tag.Failure: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; optional = bool; } else { optional = null; } - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optional1; if (isSome1) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); optional1 = int; } else { optional1 = null; @@ -528,26 +524,26 @@ export async function createInstantiator(options, swift) { return { tag: APIOptionalResultValues.Tag.Failure, param0: optional1, param1: optional }; } case APIOptionalResultValues.Tag.Status: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); optional = string; } else { optional = null; } - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optional1; if (isSome1) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); optional1 = int; } else { optional1 = null; } - const isSome2 = tmpRetInts.pop(); + const isSome2 = i32Stack.pop(); let optional2; if (isSome2) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; optional2 = bool; } else { optional2 = null; @@ -565,26 +561,26 @@ export async function createInstantiator(options, swift) { const enumTag = value.tag; switch (enumTag) { case TypedPayloadResultValues.Tag.Precision: { - tmpParamF32s.push(Math.fround(value.param0)); + f32Stack.push(Math.fround(value.param0)); const cleanup = undefined; return { caseId: TypedPayloadResultValues.Tag.Precision, cleanup }; } case TypedPayloadResultValues.Tag.Direction: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.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); + f32Stack.push(isSome ? Math.fround(value.param0) : 0.0); + i32Stack.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); + i32Stack.push(isSome ? (value.param0 | 0) : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = undefined; return { caseId: TypedPayloadResultValues.Tag.OptDirection, cleanup }; } @@ -599,18 +595,18 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case TypedPayloadResultValues.Tag.Precision: { - const rawValue = tmpRetF32s.pop(); + const rawValue = f32Stack.pop(); return { tag: TypedPayloadResultValues.Tag.Precision, param0: rawValue }; } case TypedPayloadResultValues.Tag.Direction: { - const caseId = tmpRetInts.pop(); + const caseId = i32Stack.pop(); return { tag: TypedPayloadResultValues.Tag.Direction, param0: caseId }; } case TypedPayloadResultValues.Tag.OptPrecision: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const rawValue = tmpRetF32s.pop(); + const rawValue = f32Stack.pop(); optional = rawValue; } else { optional = null; @@ -618,10 +614,10 @@ export async function createInstantiator(options, swift) { return { tag: TypedPayloadResultValues.Tag.OptPrecision, param0: optional }; } case TypedPayloadResultValues.Tag.OptDirection: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const caseId = tmpRetInts.pop(); + const caseId = i32Stack.pop(); optional = caseId; } else { optional = null; @@ -647,19 +643,19 @@ export async function createInstantiator(options, swift) { return { caseId: AllTypesResultValues.Tag.StructPayload, cleanup }; } case AllTypesResultValues.Tag.ClassPayload: { - tmpParamPointers.push(value.param0.pointer); + ptrStack.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); + i32Stack.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); + i32Stack.push(caseId); const cleanup = () => { if (enumCleanup) { enumCleanup(); } }; @@ -668,9 +664,9 @@ export async function createInstantiator(options, swift) { case AllTypesResultValues.Tag.ArrayPayload: { const arrayCleanups = []; for (const elem of value.param0) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(value.param0.length); + i32Stack.push(value.param0.length); const cleanup = () => { for (const cleanup of arrayCleanups) { cleanup(); } }; @@ -691,25 +687,25 @@ export async function createInstantiator(options, swift) { return { tag: AllTypesResultValues.Tag.StructPayload, param0: struct }; } case AllTypesResultValues.Tag.ClassPayload: { - const ptr = tmpRetPointers.pop(); + const ptr = ptrStack.pop(); const obj = _exports['User'].__construct(ptr); return { tag: AllTypesResultValues.Tag.ClassPayload, param0: obj }; } case AllTypesResultValues.Tag.JsObjectPayload: { - const objId = tmpRetInts.pop(); + const objId = i32Stack.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(), ); + const enumValue = enumHelpers.APIResult.lift(tagStack.pop(), ); return { tag: AllTypesResultValues.Tag.NestedEnum, param0: enumValue }; } case AllTypesResultValues.Tag.ArrayPayload: { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -733,7 +729,7 @@ export async function createInstantiator(options, swift) { const structResult = structHelpers.Point.lower(value.param0); nestedCleanup = structResult.cleanup; } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if (nestedCleanup) { nestedCleanup(); } }; @@ -742,11 +738,11 @@ export async function createInstantiator(options, swift) { case OptionalAllTypesResultValues.Tag.OptClass: { const isSome = value.param0 != null; if (isSome) { - tmpParamPointers.push(value.param0.pointer); + ptrStack.push(value.param0.pointer); } else { - tmpParamPointers.push(0); + ptrStack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = undefined; return { caseId: OptionalAllTypesResultValues.Tag.OptClass, cleanup }; } @@ -755,12 +751,12 @@ export async function createInstantiator(options, swift) { let id; if (isSome) { id = swift.memory.retain(value.param0); - tmpParamInts.push(id); + i32Stack.push(id); } else { id = undefined; - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = undefined; return { caseId: OptionalAllTypesResultValues.Tag.OptJSObject, cleanup }; } @@ -771,11 +767,11 @@ export async function createInstantiator(options, swift) { const enumResult = enumHelpers.APIResult.lower(value.param0); enumCaseId = enumResult.caseId; enumCleanup = enumResult.cleanup; - tmpParamInts.push(enumCaseId); + i32Stack.push(enumCaseId); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if (enumCleanup) { enumCleanup(); } }; @@ -787,14 +783,14 @@ export async function createInstantiator(options, swift) { if (isSome) { const arrayCleanups = []; for (const elem of value.param0) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(value.param0.length); + i32Stack.push(value.param0.length); arrCleanup = () => { for (const cleanup of arrayCleanups) { cleanup(); } }; } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if (arrCleanup) { arrCleanup(); } }; @@ -811,7 +807,7 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case OptionalAllTypesResultValues.Tag.OptStruct: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { const struct = structHelpers.Point.lift(); @@ -822,10 +818,10 @@ export async function createInstantiator(options, swift) { return { tag: OptionalAllTypesResultValues.Tag.OptStruct, param0: optional }; } case OptionalAllTypesResultValues.Tag.OptClass: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const ptr = tmpRetPointers.pop(); + const ptr = ptrStack.pop(); const obj = _exports['User'].__construct(ptr); optional = obj; } else { @@ -834,10 +830,10 @@ export async function createInstantiator(options, swift) { return { tag: OptionalAllTypesResultValues.Tag.OptClass, param0: optional }; } case OptionalAllTypesResultValues.Tag.OptJSObject: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const objId = tmpRetInts.pop(); + const objId = i32Stack.pop(); const obj = swift.memory.getObject(objId); swift.memory.release(objId); optional = obj; @@ -847,10 +843,10 @@ export async function createInstantiator(options, swift) { return { tag: OptionalAllTypesResultValues.Tag.OptJSObject, param0: optional }; } case OptionalAllTypesResultValues.Tag.OptNestedEnum: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const caseId = tmpRetInts.pop(); + const caseId = i32Stack.pop(); optional = enumHelpers.APIResult.lift(caseId); } else { optional = null; @@ -858,13 +854,13 @@ export async function createInstantiator(options, swift) { return { tag: OptionalAllTypesResultValues.Tag.OptNestedEnum, param0: optional }; } case OptionalAllTypesResultValues.Tag.OptArray: { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); @@ -916,36 +912,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -1139,13 +1135,13 @@ export async function createInstantiator(options, swift) { }, getResult: function bjs_getResult() { instance.exports.bjs_getResult(); - const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); + const ret = enumHelpers.APIResult.lift(tagStack.pop()); return ret; }, roundtripAPIResult: function bjs_roundtripAPIResult(result) { const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); instance.exports.bjs_roundtripAPIResult(resultCaseId); - const ret = enumHelpers.APIResult.lift(tmpRetTag.pop()); + const ret = enumHelpers.APIResult.lift(tagStack.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1158,7 +1154,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalAPIResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1176,13 +1172,13 @@ export async function createInstantiator(options, swift) { }, getComplexResult: function bjs_getComplexResult() { instance.exports.bjs_getComplexResult(); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop()); + const ret = enumHelpers.ComplexResult.lift(tagStack.pop()); return ret; }, roundtripComplexResult: function bjs_roundtripComplexResult(result) { const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); instance.exports.bjs_roundtripComplexResult(resultCaseId); - const ret = enumHelpers.ComplexResult.lift(tmpRetTag.pop()); + const ret = enumHelpers.ComplexResult.lift(tagStack.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1195,7 +1191,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalComplexResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1215,7 +1211,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalUtilitiesResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1235,7 +1231,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalNetworkingResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1255,7 +1251,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalAPIOptionalResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1282,7 +1278,7 @@ export async function createInstantiator(options, swift) { result2Cleanup = enumResult1.cleanup; } instance.exports.bjs_compareAPIResults(+isSome, isSome ? result1CaseId : 0, +isSome1, isSome1 ? result2CaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1297,7 +1293,7 @@ export async function createInstantiator(options, swift) { 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()); + const ret = enumHelpers.TypedPayloadResult.lift(tagStack.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1310,7 +1306,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalTypedPayloadResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1324,7 +1320,7 @@ export async function createInstantiator(options, swift) { 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()); + const ret = enumHelpers.AllTypesResult.lift(tagStack.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1337,7 +1333,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalAllTypesResult(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { @@ -1351,7 +1347,7 @@ export async function createInstantiator(options, swift) { 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()); + const ret = enumHelpers.OptionalAllTypesResult.lift(tagStack.pop()); if (resultCleanup) { resultCleanup(); } return ret; }, @@ -1364,7 +1360,7 @@ export async function createInstantiator(options, swift) { resultCleanup = enumResult.cleanup; } instance.exports.bjs_roundTripOptionalPayloadResultOpt(+isSome, isSome ? resultCaseId : 0); - const tag = tmpRetTag.pop(); + const tag = tagStack.pop(); const isNull = (tag === -1); let optResult; if (isNull) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 9ca596a6e..0c8eee729 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -42,16 +42,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,36 +90,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index a7a2c4b98..28cfe9dd9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -62,16 +62,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -114,36 +110,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index b195b6945..a933ed735 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -43,16 +43,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,36 +91,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index c906f27ff..06ebbe269 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -93,16 +93,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -146,36 +142,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index ac6170b08..97f34b1bb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index dc2220715..bc186d4c1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index daa601aed..3a04c5308 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -205,29 +201,29 @@ export async function createInstantiator(options, swift) { const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; TestModule["bjs_roundtrip"] = function bjs_roundtrip() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); arrayResult.push(int); } arrayResult.reverse(); let ret = imports.roundtrip(arrayResult); const arrayCleanups = []; for (const elem of ret) { - tmpParamInts.push((elem | 0)); + i32Stack.push((elem | 0)); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } } TestModule["bjs_logStrings"] = function bjs_logStrings() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); arrayResult.push(string); } arrayResult.reverse(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 1e4e1f508..4f3fa39a6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -43,17 +39,17 @@ export async function createInstantiator(options, swift) { } else { id = undefined; } - tmpParamInts.push(id !== undefined ? id : 0); + i32Stack.push(id !== undefined ? id : 0); const isSome = value.optionalFoo != null; let id1; if (isSome) { id1 = swift.memory.retain(value.optionalFoo); - tmpParamInts.push(id1); + i32Stack.push(id1); } else { id1 = undefined; - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if(id !== undefined && id !== 0) { try { @@ -71,10 +67,10 @@ export async function createInstantiator(options, swift) { return { cleanup }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const objectId = tmpRetInts.pop(); + const objectId = i32Stack.pop(); let value; if (objectId !== 0) { value = swift.memory.getObject(objectId); @@ -86,7 +82,7 @@ export async function createInstantiator(options, swift) { } else { optional = null; } - const objectId1 = tmpRetInts.pop(); + const objectId1 = i32Stack.pop(); let value1; if (objectId1 !== 0) { value1 = swift.memory.getObject(objectId1); @@ -135,36 +131,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -318,14 +314,14 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of foos) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(foos.length); + i32Stack.push(foos.length); instance.exports.bjs_processFooArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); arrayResult.push(obj); @@ -340,23 +336,23 @@ export async function createInstantiator(options, swift) { const isSome = elem != null ? 1 : 0; if (isSome) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome); + i32Stack.push(isSome); } - tmpParamInts.push(foos.length); + i32Stack.push(foos.length); instance.exports.bjs_processOptionalFooArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optValue; if (isSome1 === 0) { optValue = null; } else { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); optValue = obj; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index d64ff7e96..d3514253a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index 096e3a345..2bbddd396 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index cacaa87a3..c05e4e114 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index f5c360bb0..754a17e3c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -160,36 +156,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -305,21 +301,21 @@ export async function createInstantiator(options, swift) { 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); + i32Stack.push(retKind); + i32Stack.push(retPayload1); + f64Stack.push(retPayload2); } catch (error) { setException(error); } } TestModule["bjs_jsEchoJSValueArray"] = function bjs_jsEchoJSValueArray() { try { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); arrayResult.push(jsValue); } @@ -328,11 +324,11 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of ret) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); - tmpParamInts.push(elemKind); - tmpParamInts.push(elemPayload1); - tmpParamF64s.push(elemPayload2); + i32Stack.push(elemKind); + i32Stack.push(elemPayload1); + f64Stack.push(elemPayload2); } - tmpParamInts.push(ret.length); + i32Stack.push(ret.length); } catch (error) { setException(error); } @@ -389,9 +385,9 @@ export async function createInstantiator(options, swift) { 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 jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; } @@ -399,12 +395,12 @@ export async function createInstantiator(options, swift) { 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(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { @@ -414,9 +410,9 @@ export async function createInstantiator(options, swift) { } get value() { instance.exports.bjs_JSValueHolder_value_get(this.pointer); - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; } @@ -426,12 +422,12 @@ export async function createInstantiator(options, swift) { } get optionalValue() { instance.exports.bjs_JSValueHolder_optionalValue_get(this.pointer); - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optResult; if (isSome) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { @@ -450,9 +446,9 @@ export async function createInstantiator(options, swift) { 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 jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); return jsValue; }, @@ -460,12 +456,12 @@ export async function createInstantiator(options, swift) { const isSome = value != null; const [valueKind, valuePayload1, valuePayload2] = __bjs_jsValueLower(value); instance.exports.bjs_roundTripOptionalJSValue(+isSome, valueKind, valuePayload1, valuePayload2); - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); optResult = jsValue; } else { @@ -477,18 +473,18 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of values) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); - tmpParamInts.push(elemKind); - tmpParamInts.push(elemPayload1); - tmpParamF64s.push(elemPayload2); + i32Stack.push(elemKind); + i32Stack.push(elemPayload1); + f64Stack.push(elemPayload2); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); instance.exports.bjs_roundTripJSValueArray(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); arrayResult.push(jsValue); } @@ -503,23 +499,23 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of values) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); - tmpParamInts.push(elemKind); - tmpParamInts.push(elemPayload1); - tmpParamF64s.push(elemPayload2); + i32Stack.push(elemKind); + i32Stack.push(elemPayload1); + f64Stack.push(elemPayload2); } - tmpParamInts.push(values.length); + i32Stack.push(values.length); valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); } instance.exports.bjs_roundTripOptionalJSValueArray(+isSome); - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optResult; if (isSome1) { - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const jsValuePayload2 = tmpRetF64s.pop(); - const jsValuePayload1 = tmpRetInts.pop(); - const jsValueKind = tmpRetInts.pop(); + const jsValuePayload2 = f64Stack.pop(); + const jsValuePayload1 = i32Stack.pop(); + const jsValueKind = i32Stack.pop(); const jsValue = __bjs_jsValueLift(jsValueKind, jsValuePayload1, jsValuePayload2); arrayResult.push(jsValue); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index 4ac3b11b7..d9521754f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 9eb55f30b..907e955b1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index e81a95669..cbeae41d8 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index c8d0b935e..92aeeae95 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index bb2c93649..e2f425455 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 0d45b2169..923a1f354 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index 2d754a5c3..e148b94ac 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index f348869b2..b803936d0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index 7be6cd924..916d5e1b5 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 0ed0be7b6..ee1a2345c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -42,16 +42,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -66,15 +62,15 @@ export async function createInstantiator(options, swift) { case ResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: ResultValues.Tag.Success, cleanup }; } case ResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.push((value.param0 | 0)); const cleanup = undefined; return { caseId: ResultValues.Tag.Failure, cleanup }; } @@ -85,11 +81,11 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case ResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: ResultValues.Tag.Success, param0: string }; } case ResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { tag: ResultValues.Tag.Failure, param0: int }; } default: throw new Error("Unknown ResultValues tag returned from Swift: " + String(tag)); @@ -133,36 +129,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -689,9 +685,9 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of delegates) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(delegates.length); + i32Stack.push(delegates.length); const ret = instance.exports.bjs_DelegateManager_init(); for (const cleanup of arrayCleanups) { cleanup(); } return DelegateManager.__construct(ret); @@ -701,10 +697,10 @@ export async function createInstantiator(options, swift) { } get delegates() { instance.exports.bjs_DelegateManager_delegates_get(this.pointer); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const objId = tmpRetInts.pop(); + const objId = i32Stack.pop(); const obj = swift.memory.getObject(objId); swift.memory.release(objId); arrayResult.push(obj); @@ -716,9 +712,9 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of value) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(value.length); + i32Stack.push(value.length); instance.exports.bjs_DelegateManager_delegates_set(this.pointer); for (const cleanup of arrayCleanups) { cleanup(); } } @@ -734,14 +730,14 @@ export async function createInstantiator(options, swift) { const arrayCleanups = []; for (const elem of delegates) { const objId = swift.memory.retain(elem); - tmpParamInts.push(objId); + i32Stack.push(objId); } - tmpParamInts.push(delegates.length); + i32Stack.push(delegates.length); instance.exports.bjs_processDelegates(); - const arrayLen = tmpRetInts.pop(); + const arrayLen = i32Stack.pop(); const arrayResult = []; for (let i = 0; i < arrayLen; i++) { - const objId1 = tmpRetInts.pop(); + const objId1 = i32Stack.pop(); const obj = swift.memory.getObject(objId1); swift.memory.release(objId1); arrayResult.push(obj); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 7579c72f7..d07af4cdb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -29,16 +29,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -53,15 +49,15 @@ export async function createInstantiator(options, swift) { case APIResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.push((value.param0 | 0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Failure, cleanup }; } @@ -72,11 +68,11 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: APIResultValues.Tag.Success, param0: string }; } case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { tag: APIResultValues.Tag.Failure, param0: int }; } default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); @@ -120,36 +116,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -335,7 +331,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.pop()); + const ret = enumHelpers.APIResult.lift(tagStack.pop()); 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 bb3920888..63c5c964b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -29,16 +29,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -53,15 +49,15 @@ export async function createInstantiator(options, swift) { case APIResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.push((value.param0 | 0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Failure, cleanup }; } @@ -72,11 +68,11 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: APIResultValues.Tag.Success, param0: string }; } case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { tag: APIResultValues.Tag.Failure, param0: int }; } default: throw new Error("Unknown APIResultValues tag returned from Swift: " + String(tag)); @@ -120,36 +116,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } @@ -329,7 +325,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.pop()); + const ret = enumHelpers.APIResult.lift(tagStack.pop()); 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 293ae4f7d..c1d59bf69 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -23,16 +23,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -75,36 +71,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index 27e3df464..f086f2919 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -23,16 +23,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -75,36 +71,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index e57c5153d..20ea91e3c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index 74d140236..0f002bf31 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index 27398d2a4..ee4333f03 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 36b712362..bc0def6f1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -48,16 +48,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -72,30 +68,30 @@ export async function createInstantiator(options, swift) { case APIResultValues.Tag.Success: { const bytes = textEncoder.encode(value.param0); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const cleanup = () => { swift.memory.release(id); }; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { - tmpParamInts.push((value.param0 | 0)); + i32Stack.push((value.param0 | 0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Failure, cleanup }; } case APIResultValues.Tag.Flag: { - tmpParamInts.push(value.param0 ? 1 : 0); + i32Stack.push(value.param0 ? 1 : 0); const cleanup = undefined; return { caseId: APIResultValues.Tag.Flag, cleanup }; } case APIResultValues.Tag.Rate: { - tmpParamF32s.push(Math.fround(value.param0)); + f32Stack.push(Math.fround(value.param0)); const cleanup = undefined; return { caseId: APIResultValues.Tag.Rate, cleanup }; } case APIResultValues.Tag.Precise: { - tmpParamF64s.push(value.param0); + f64Stack.push(value.param0); const cleanup = undefined; return { caseId: APIResultValues.Tag.Precise, cleanup }; } @@ -110,23 +106,23 @@ export async function createInstantiator(options, swift) { tag = tag | 0; switch (tag) { case APIResultValues.Tag.Success: { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); return { tag: APIResultValues.Tag.Success, param0: string }; } case APIResultValues.Tag.Failure: { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { tag: APIResultValues.Tag.Failure, param0: int }; } case APIResultValues.Tag.Flag: { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; return { tag: APIResultValues.Tag.Flag, param0: bool }; } case APIResultValues.Tag.Rate: { - const f32 = tmpRetF32s.pop(); + const f32 = f32Stack.pop(); return { tag: APIResultValues.Tag.Rate, param0: f32 }; } case APIResultValues.Tag.Precise: { - const f64 = tmpRetF64s.pop(); + const f64 = f64Stack.pop(); return { tag: APIResultValues.Tag.Precise, param0: f64 }; } case APIResultValues.Tag.Info: return { tag: APIResultValues.Tag.Info }; @@ -171,36 +167,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 52e12ef7c..6c1397fff 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index b22afee4d..b4cf995cb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -23,16 +23,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -42,51 +38,51 @@ export async function createInstantiator(options, swift) { const __bjs_createDataPointHelpers = () => { return () => ({ lower: (value) => { - tmpParamF64s.push(value.x); - tmpParamF64s.push(value.y); + f64Stack.push(value.x); + f64Stack.push(value.y); const bytes = textEncoder.encode(value.label); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const isSome = value.optCount != null; if (isSome) { - tmpParamInts.push(value.optCount | 0); + i32Stack.push(value.optCount | 0); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const isSome1 = value.optFlag != null; if (isSome1) { - tmpParamInts.push(value.optFlag ? 1 : 0); + i32Stack.push(value.optFlag ? 1 : 0); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome1 ? 1 : 0); + i32Stack.push(isSome1 ? 1 : 0); const cleanup = () => { swift.memory.release(id); }; return { cleanup }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const bool = tmpRetInts.pop() !== 0; + const bool = i32Stack.pop() !== 0; optional = bool; } else { optional = null; } - const isSome1 = tmpRetInts.pop(); + const isSome1 = i32Stack.pop(); let optional1; if (isSome1) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); optional1 = int; } else { optional1 = null; } - const string = tmpRetStrings.pop(); - const f64 = tmpRetF64s.pop(); - const f641 = tmpRetF64s.pop(); + const string = strStack.pop(); + const f64 = f64Stack.pop(); + const f641 = f64Stack.pop(); return { x: f641, y: f64, label: string, optCount: optional1, optFlag: optional }; } }); @@ -96,19 +92,19 @@ export async function createInstantiator(options, swift) { lower: (value) => { const bytes = textEncoder.encode(value.street); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); + i32Stack.push(bytes.length); + i32Stack.push(id); const bytes1 = textEncoder.encode(value.city); const id1 = swift.memory.retain(bytes1); - tmpParamInts.push(bytes1.length); - tmpParamInts.push(id1); + i32Stack.push(bytes1.length); + i32Stack.push(id1); const isSome = value.zipCode != null; if (isSome) { - tmpParamInts.push(value.zipCode | 0); + i32Stack.push(value.zipCode | 0); } else { - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { swift.memory.release(id); swift.memory.release(id1); @@ -116,16 +112,16 @@ export async function createInstantiator(options, swift) { return { cleanup }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); optional = int; } else { optional = null; } - const string = tmpRetStrings.pop(); - const string1 = tmpRetStrings.pop(); + const string = strStack.pop(); + const string1 = strStack.pop(); return { street: string1, city: string, zipCode: optional }; } }); @@ -135,22 +131,22 @@ export async function createInstantiator(options, swift) { lower: (value) => { const bytes = textEncoder.encode(value.name); const id = swift.memory.retain(bytes); - tmpParamInts.push(bytes.length); - tmpParamInts.push(id); - tmpParamInts.push((value.age | 0)); + i32Stack.push(bytes.length); + i32Stack.push(id); + i32Stack.push((value.age | 0)); const structResult = structHelpers.Address.lower(value.address); const isSome = value.email != null; let id1; if (isSome) { const bytes1 = textEncoder.encode(value.email); id1 = swift.memory.retain(bytes1); - tmpParamInts.push(bytes1.length); - tmpParamInts.push(id1); + i32Stack.push(bytes1.length); + i32Stack.push(id1); } else { - tmpParamInts.push(0); - tmpParamInts.push(0); + i32Stack.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { swift.memory.release(id); if (structResult.cleanup) { structResult.cleanup(); } @@ -159,17 +155,17 @@ export async function createInstantiator(options, swift) { return { cleanup }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const string = tmpRetStrings.pop(); + const string = strStack.pop(); optional = string; } else { optional = null; } const struct = structHelpers.Address.lift(); - const int = tmpRetInts.pop(); - const string1 = tmpRetStrings.pop(); + const int = i32Stack.pop(); + const string1 = strStack.pop(); return { name: string1, age: int, address: struct, email: optional }; } }); @@ -177,14 +173,14 @@ export async function createInstantiator(options, swift) { const __bjs_createSessionHelpers = () => { return () => ({ lower: (value) => { - tmpParamInts.push((value.id | 0)); - tmpParamPointers.push(value.owner.pointer); + i32Stack.push((value.id | 0)); + ptrStack.push(value.owner.pointer); return { cleanup: undefined }; }, lift: () => { - const ptr = tmpRetPointers.pop(); + const ptr = ptrStack.pop(); const obj = _exports['Greeter'].__construct(ptr); - const int = tmpRetInts.pop(); + const int = i32Stack.pop(); return { id: int, owner: obj }; } }); @@ -192,28 +188,28 @@ export async function createInstantiator(options, swift) { const __bjs_createMeasurementHelpers = () => { return () => ({ lower: (value) => { - tmpParamF64s.push(value.value); - tmpParamF32s.push(Math.fround(value.precision)); + f64Stack.push(value.value); + f32Stack.push(Math.fround(value.precision)); const isSome = value.optionalPrecision != null; if (isSome) { - tmpParamF32s.push(Math.fround(value.optionalPrecision)); + f32Stack.push(Math.fround(value.optionalPrecision)); } else { - tmpParamF32s.push(0.0); + f32Stack.push(0.0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); return { cleanup: undefined }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const rawValue = tmpRetF32s.pop(); + const rawValue = f32Stack.pop(); optional = rawValue; } else { optional = null; } - const rawValue1 = tmpRetF32s.pop(); - const f64 = tmpRetF64s.pop(); + const rawValue1 = f32Stack.pop(); + const f64 = f64Stack.pop(); return { value: f64, precision: rawValue1, optionalPrecision: optional }; } }); @@ -237,17 +233,17 @@ export async function createInstantiator(options, swift) { } else { id = undefined; } - tmpParamInts.push(id !== undefined ? id : 0); + i32Stack.push(id !== undefined ? id : 0); const isSome = value.optionalObject != null; let id1; if (isSome) { id1 = swift.memory.retain(value.optionalObject); - tmpParamInts.push(id1); + i32Stack.push(id1); } else { id1 = undefined; - tmpParamInts.push(0); + i32Stack.push(0); } - tmpParamInts.push(isSome ? 1 : 0); + i32Stack.push(isSome ? 1 : 0); const cleanup = () => { if(id !== undefined && id !== 0) { try { @@ -265,10 +261,10 @@ export async function createInstantiator(options, swift) { return { cleanup }; }, lift: () => { - const isSome = tmpRetInts.pop(); + const isSome = i32Stack.pop(); let optional; if (isSome) { - const objectId = tmpRetInts.pop(); + const objectId = i32Stack.pop(); let value; if (objectId !== 0) { value = swift.memory.getObject(objectId); @@ -280,7 +276,7 @@ export async function createInstantiator(options, swift) { } else { optional = null; } - const objectId1 = tmpRetInts.pop(); + const objectId1 = i32Stack.pop(); let value1; if (objectId1 !== 0) { value1 = swift.memory.getObject(objectId1); @@ -328,36 +324,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index f6f63ba8d..959572255 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -37,13 +33,13 @@ export async function createInstantiator(options, swift) { const __bjs_createPointHelpers = () => { return () => ({ lower: (value) => { - tmpParamInts.push((value.x | 0)); - tmpParamInts.push((value.y | 0)); + i32Stack.push((value.x | 0)); + i32Stack.push((value.y | 0)); return { cleanup: undefined }; }, lift: () => { - const int = tmpRetInts.pop(); - const int1 = tmpRetInts.pop(); + const int = i32Stack.pop(); + const int1 = i32Stack.pop(); return { x: int1, y: int }; } }); @@ -85,36 +81,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 2e2f8bf6a..487645d70 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -70,36 +66,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 9d94d5f0a..dc478a642 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -37,19 +33,19 @@ export async function createInstantiator(options, swift) { const __bjs_createPointerFieldsHelpers = () => { return () => ({ lower: (value) => { - tmpParamPointers.push((value.raw | 0)); - tmpParamPointers.push((value.mutRaw | 0)); - tmpParamPointers.push((value.opaque | 0)); - tmpParamPointers.push((value.ptr | 0)); - tmpParamPointers.push((value.mutPtr | 0)); + ptrStack.push((value.raw | 0)); + ptrStack.push((value.mutRaw | 0)); + ptrStack.push((value.opaque | 0)); + ptrStack.push((value.ptr | 0)); + ptrStack.push((value.mutPtr | 0)); return { cleanup: undefined }; }, lift: () => { - const pointer = tmpRetPointers.pop(); - const pointer1 = tmpRetPointers.pop(); - const pointer2 = tmpRetPointers.pop(); - const pointer3 = tmpRetPointers.pop(); - const pointer4 = tmpRetPointers.pop(); + const pointer = ptrStack.pop(); + const pointer1 = ptrStack.pop(); + const pointer2 = ptrStack.pop(); + const pointer3 = ptrStack.pop(); + const pointer4 = ptrStack.pop(); return { raw: pointer4, mutRaw: pointer3, opaque: pointer2, ptr: pointer1, mutPtr: pointer }; } }); @@ -90,36 +86,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 45374093b..428c422e0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -18,16 +18,12 @@ export async function createInstantiator(options, swift) { 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 tagStack = []; + let strStack = []; + let i32Stack = []; + let f32Stack = []; + let f64Stack = []; + let ptrStack = []; let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -71,36 +67,36 @@ export async function createInstantiator(options, swift) { swift.memory.release(id); } bjs["swift_js_push_tag"] = function(tag) { - tmpRetTag.push(tag); + tagStack.push(tag); } bjs["swift_js_push_i32"] = function(v) { - tmpRetInts.push(v | 0); + i32Stack.push(v | 0); } bjs["swift_js_push_f32"] = function(v) { - tmpRetF32s.push(Math.fround(v)); + f32Stack.push(Math.fround(v)); } bjs["swift_js_push_f64"] = function(v) { - tmpRetF64s.push(v); + f64Stack.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); + strStack.push(value); } bjs["swift_js_pop_i32"] = function() { - return tmpParamInts.pop(); + return i32Stack.pop(); } bjs["swift_js_pop_f32"] = function() { - return tmpParamF32s.pop(); + return f32Stack.pop(); } bjs["swift_js_pop_f64"] = function() { - return tmpParamF64s.pop(); + return f64Stack.pop(); } bjs["swift_js_push_pointer"] = function(pointer) { - tmpRetPointers.push(pointer); + ptrStack.push(pointer); } bjs["swift_js_pop_pointer"] = function() { - return tmpParamPointers.pop(); + return ptrStack.pop(); } bjs["swift_js_struct_cleanup"] = function(cleanupId) { if (cleanupId === 0) { return; } From 72ec08dda19736c2f94c0908a3e5727955a44b6a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 19:49:56 +0900 Subject: [PATCH 5/8] BridgeJS: Add Dictionary support (#581) --- .../Sources/BridgeJSCore/ExportSwift.swift | 136 +++++- .../Sources/BridgeJSCore/ImportTS.swift | 4 +- .../BridgeJSCore/SwiftToSkeleton.swift | 39 ++ .../Sources/BridgeJSLink/BridgeJSLink.swift | 5 + .../Sources/BridgeJSLink/JSGlueGen.swift | 190 ++++++- .../BridgeJSSkeleton/BridgeJSSkeleton.swift | 7 + .../Inputs/MacroSwift/DictionaryTypes.swift | 15 + .../BridgeJSCodegenTests/DictionaryTypes.json | 259 ++++++++++ .../DictionaryTypes.swift | 97 ++++ .../BridgeJSLinkTests/DictionaryTypes.d.ts | 34 ++ .../BridgeJSLinkTests/DictionaryTypes.js | 462 ++++++++++++++++++ .../JavaScriptKit/BridgeJSIntrinsics.swift | 119 +++++ .../DictionaryTests.swift | 96 ++++ .../BridgeJSRuntimeTests/ExportAPITests.swift | 8 + .../Generated/BridgeJS.swift | 166 +++++++ .../Generated/JavaScript/BridgeJS.json | 319 ++++++++++++ Tests/prelude.mjs | 29 ++ 17 files changed, 1978 insertions(+), 7 deletions(-) create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DictionaryTypes.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.json create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.swift create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.d.ts create mode 100644 Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js create mode 100644 Tests/BridgeJSRuntimeTests/DictionaryTests.swift diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 51ff91695..aa01a2c5c 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -832,6 +832,8 @@ struct StackCodegen { return liftNullableExpression(wrappedType: wrappedType, kind: kind) case .array(let elementType): return liftArrayExpression(elementType: elementType) + case .dictionary(let valueType): + return liftDictionaryExpression(valueType: valueType) case .closure: return "JSObject.bridgeJSLiftParameter()" case .void, .namespaceEnum: @@ -849,7 +851,7 @@ struct StackCodegen { return liftArrayExpressionInline(elementType: elementType) case .swiftProtocol(let protocolName): return "[Any\(raw: protocolName)].bridgeJSLiftParameter()" - case .nullable, .array, .closure: + case .nullable, .array, .closure, .dictionary: return liftArrayExpressionInline(elementType: elementType) case .void, .namespaceEnum: fatalError("Invalid array element type: \(elementType)") @@ -873,6 +875,51 @@ struct StackCodegen { """ } + func liftDictionaryExpression(valueType: BridgeType) -> ExprSyntax { + switch valueType { + case .int, .uint, .float, .double, .string, .bool, .jsValue, + .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return "[String: \(raw: valueType.swiftType)].bridgeJSLiftParameter()" + case .jsObject(let className?): + return """ + { + let __dict = [String: JSObject].bridgeJSLiftParameter() + return __dict.mapValues { \(raw: className)(unsafelyWrapping: $0) } + }() + """ + case .swiftProtocol(let protocolName): + return """ + { + let __dict = [String: JSObject].bridgeJSLiftParameter() + return __dict.mapValues { $0 as! Any\(raw: protocolName) } + }() + """ + case .nullable, .array, .dictionary, .closure: + return liftDictionaryExpressionInline(valueType: valueType) + case .void, .namespaceEnum: + fatalError("Invalid dictionary value type: \(valueType)") + } + } + + private func liftDictionaryExpressionInline(valueType: BridgeType) -> ExprSyntax { + let valueLift = liftExpression(for: valueType) + let swiftTypeName = valueType.swiftType + return """ + { + let __count = Int(_swift_js_pop_i32()) + var __result: [String: \(raw: swiftTypeName)] = [:] + __result.reserveCapacity(__count) + for _ in 0..<__count { + let __value = \(valueLift) + let __key = String.bridgeJSLiftParameter() + __result[__key] = __value + } + return __result + }() + """ + } + private func liftNullableExpression(wrappedType: BridgeType, kind: JSOptionalKind) -> ExprSyntax { let typeName = kind == .null ? "Optional" : "JSUndefinedOr" switch wrappedType { @@ -897,6 +944,23 @@ struct StackCodegen { } }() """ + case .dictionary(let valueType): + let dictionaryLift = liftDictionaryExpression(valueType: valueType) + let swiftTypeName = valueType.swiftType + let absentExpr = + kind == .null + ? "\(typeName)<[String: \(swiftTypeName)]>.none" + : "\(typeName)<[String: \(swiftTypeName)]>.undefinedValue" + return """ + { + let __isSome = _swift_js_pop_i32() + if __isSome == 0 { + return \(raw: absentExpr) + } else { + return \(dictionaryLift) + } + }() + """ case .nullable, .void, .namespaceEnum, .closure, .unsafePointer, .swiftProtocol: fatalError("Invalid nullable wrapped type: \(wrappedType)") } @@ -935,6 +999,8 @@ struct StackCodegen { return [] case .array(let elementType): return lowerArrayStatements(elementType: elementType, accessor: accessor, varPrefix: varPrefix) + case .dictionary(let valueType): + return lowerDictionaryStatements(valueType: valueType, accessor: accessor, varPrefix: varPrefix) } } @@ -952,7 +1018,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 .nullable, .array, .closure: + case .nullable, .array, .closure, .dictionary: return lowerArrayStatementsInline( elementType: elementType, accessor: accessor, @@ -986,6 +1052,65 @@ struct StackCodegen { return statements } + private func lowerDictionaryStatements( + valueType: BridgeType, + accessor: String, + varPrefix: String + ) -> [CodeBlockItemSyntax] { + switch valueType { + case .int, .uint, .float, .double, .string, .bool, .jsValue, + .jsObject(nil), .swiftStruct, .caseEnum, .swiftHeapObject, + .unsafePointer, .rawValueEnum, .associatedValueEnum: + return ["\(raw: accessor).bridgeJSLowerReturn()"] + case .jsObject(_?): + return ["\(raw: accessor).mapValues { $0.jsObject }.bridgeJSLowerReturn()"] + case .swiftProtocol(let protocolName): + return ["\(raw: accessor).mapValues { $0 as! Any\(raw: protocolName) }.bridgeJSLowerReturn()"] + case .nullable, .array, .dictionary, .closure: + return lowerDictionaryStatementsInline( + valueType: valueType, + accessor: accessor, + varPrefix: varPrefix + ) + case .void, .namespaceEnum: + fatalError("Invalid dictionary value type: \(valueType)") + } + } + + private func lowerDictionaryStatementsInline( + valueType: BridgeType, + accessor: String, + varPrefix: String + ) -> [CodeBlockItemSyntax] { + var statements: [CodeBlockItemSyntax] = [] + let pairVarName = "__bjs_kv_\(varPrefix)" + statements.append("for \(raw: pairVarName) in \(raw: accessor) {") + statements.append("let __bjs_key_\(raw: varPrefix) = \(raw: pairVarName).key") + statements.append("let __bjs_value_\(raw: varPrefix) = \(raw: pairVarName).value") + + let keyStatements = lowerStatements( + for: .string, + accessor: "__bjs_key_\(varPrefix)", + varPrefix: "\(varPrefix)_key" + ) + for stmt in keyStatements { + statements.append(stmt) + } + + let valueStatements = lowerStatements( + for: valueType, + accessor: "__bjs_value_\(varPrefix)", + varPrefix: "\(varPrefix)_value" + ) + for stmt in valueStatements { + statements.append(stmt) + } + + statements.append("}") + statements.append("_swift_js_push_i32(Int32(\(raw: accessor).count))") + return statements + } + private func lowerOptionalStatements( wrappedType: BridgeType, accessor: String, @@ -1033,6 +1158,8 @@ struct StackCodegen { return ["\(raw: unwrappedVar).jsObject.bridgeJSLowerStackReturn()"] case .array(let elementType): return lowerArrayStatements(elementType: elementType, accessor: unwrappedVar, varPrefix: varPrefix) + case .dictionary(let valueType): + return lowerDictionaryStatements(valueType: valueType, accessor: unwrappedVar, varPrefix: varPrefix) default: return ["preconditionFailure(\"BridgeJS: unsupported optional wrapped type\")"] } @@ -1616,6 +1743,7 @@ extension BridgeType { case .nullable(let wrappedType, let kind): return kind == .null ? "Optional<\(wrappedType.swiftType)>" : "JSUndefinedOr<\(wrappedType.swiftType)>" case .array(let elementType): return "[\(elementType.swiftType)]" + case .dictionary(let valueType): return "[String: \(valueType.swiftType)]" case .caseEnum(let name): return name case .rawValueEnum(let name, _): return name case .associatedValueEnum(let name): return name @@ -1675,7 +1803,7 @@ extension BridgeType { throw BridgeJSCoreError("Namespace enums are not supported to pass as parameters") case .closure: return LiftingIntrinsicInfo(parameters: [("callbackId", .i32)]) - case .array: + case .array, .dictionary: return LiftingIntrinsicInfo(parameters: []) } } @@ -1726,7 +1854,7 @@ extension BridgeType { throw BridgeJSCoreError("Namespace enums are not supported to pass as parameters") case .closure: return .swiftHeapObject - case .array: + case .array, .dictionary: return .array } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift index 8db872c6e..7c3ecd6ea 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift @@ -980,7 +980,7 @@ extension BridgeType { var params = [("isSome", WasmCoreType.i32)] params.append(contentsOf: wrappedInfo.loweredParameters) return LoweringParameterInfo(loweredParameters: params) - case .array: + case .array, .dictionary: return LoweringParameterInfo(loweredParameters: []) } } @@ -1059,7 +1059,7 @@ extension BridgeType { case .nullable(let wrappedType, _): let wrappedInfo = try wrappedType.liftingReturnInfo(context: context) return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift) - case .array: + case .array, .dictionary: return LiftingReturnInfo(valueToLift: nil) } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift index 3de74f74b..e571d955e 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift @@ -213,6 +213,45 @@ public final class SwiftToSkeleton { return .array(elementType) } } + // [String: T] + if let dictType = type.as(DictionaryTypeSyntax.self) { + if let keyType = lookupType(for: dictType.key, errors: &errors), + keyType == .string, + let valueType = lookupType(for: dictType.value, errors: &errors) + { + return .dictionary(valueType) + } + } + // Dictionary + if let identifierType = type.as(IdentifierTypeSyntax.self), + identifierType.name.text == "Dictionary", + let genericArgs = identifierType.genericArgumentClause?.arguments, + genericArgs.count == 2, + let keyArg = TypeSyntax(genericArgs.first?.argument), + let valueArg = TypeSyntax(genericArgs.last?.argument), + let keyType = lookupType(for: keyArg, errors: &errors), + keyType == .string + { + if let valueType = lookupType(for: valueArg, errors: &errors) { + return .dictionary(valueType) + } + } + // Swift.Dictionary + if let memberType = type.as(MemberTypeSyntax.self), + let baseType = memberType.baseType.as(IdentifierTypeSyntax.self), + baseType.name.text == "Swift", + memberType.name.text == "Dictionary", + let genericArgs = memberType.genericArgumentClause?.arguments, + genericArgs.count == 2, + let keyArg = TypeSyntax(genericArgs.first?.argument), + let valueArg = TypeSyntax(genericArgs.last?.argument), + let keyType = lookupType(for: keyArg, errors: &errors), + keyType == .string + { + if let valueType = lookupType(for: valueArg, errors: &errors) { + return .dictionary(valueType) + } + } if let aliasDecl = typeDeclResolver.resolveTypeAlias(type) { if let resolvedType = lookupType(for: aliasDecl.initializer.value, errors: &errors) { return resolvedType diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index c2b0c6ed3..9303962a6 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -1462,6 +1462,9 @@ public struct BridgeJSLink { return "(\(elementTypeStr))[]" } return "\(elementTypeStr)[]" + case .dictionary(let valueType): + let valueTypeStr = resolveTypeScriptType(valueType, exportedSkeletons: exportedSkeletons) + return "Record" default: return type.tsType } @@ -3564,6 +3567,8 @@ extension BridgeType { return "(\(inner))[]" } return "\(inner)[]" + case .dictionary(let valueType): + return "Record" } } } diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ae83f33e6..0b170d5d5 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -737,6 +737,23 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") resultExpr = arrayVar + case .dictionary(let valueType): + let dictVar = scope.variable("dictValue") + printer.write("let \(dictVar);") + printer.write("if (\(isSome)) {") + printer.indent { + let dictLiftFragment = try! dictionaryLift(valueType: valueType) + let liftResults = dictLiftFragment.printCode([], scope, printer, cleanupCode) + if let liftResult = liftResults.first { + printer.write("\(dictVar) = \(liftResult);") + } + } + printer.write("} else {") + printer.indent { + printer.write("\(dictVar) = \(absenceLiteral);") + } + printer.write("}") + resultExpr = dictVar default: resultExpr = "\(isSome) ? \(wrappedValue) : \(absenceLiteral)" } @@ -830,6 +847,23 @@ struct IntrinsicJSFragment: Sendable { printer.write("}") cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") return ["+\(isSomeVar)"] + case .dictionary(let valueType): + let cleanupArrayVar = scope.variable("\(value)Cleanups") + printer.write("const \(cleanupArrayVar) = [];") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let dictLowerFragment = try! dictionaryLower(valueType: valueType) + let dictCleanup = CodeFragmentPrinter() + let _ = dictLowerFragment.printCode([value], scope, printer, dictCleanup) + if !dictCleanup.lines.isEmpty { + for line in dictCleanup.lines { + printer.write("\(cleanupArrayVar).push(() => { \(line) });") + } + } + } + printer.write("}") + cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") + return ["+\(isSomeVar)"] default: switch wrappedType { case .swiftHeapObject: @@ -981,6 +1015,23 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(resultVar) = \(absenceLiteral);") } printer.write("}") + case .dictionary(let valueType): + let isSomeVar = scope.variable("isSome") + printer.write("const \(isSomeVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("let \(resultVar);") + printer.write("if (\(isSomeVar)) {") + printer.indent { + let dictLiftFragment = try! dictionaryLift(valueType: valueType) + let liftResults = dictLiftFragment.printCode([], scope, printer, cleanupCode) + if let liftResult = liftResults.first { + printer.write("\(resultVar) = \(liftResult);") + } + } + printer.write("} else {") + printer.indent { + printer.write("\(resultVar) = \(absenceLiteral);") + } + printer.write("}") case .jsValue: let isSomeVar = scope.variable("isSome") printer.write("const \(isSomeVar) = \(scope.popI32Return());") @@ -1133,6 +1184,52 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") + case .dictionary(let valueType): + printer.write("if (\(isSomeVar)) {") + printer.indent { + let cleanupArrayVar = scope.variable("arrayCleanups") + let entriesVar = scope.variable("entries") + let entryVar = scope.variable("entry") + printer.write("const \(cleanupArrayVar) = [];") + printer.write("const \(entriesVar) = Object.entries(\(value));") + printer.write("for (const \(entryVar) of \(entriesVar)) {") + printer.indent { + let keyVar = scope.variable("key") + let valueVar = scope.variable("value") + printer.write("const [\(keyVar), \(valueVar)] = \(entryVar);") + + let keyFragment = try! stackLowerFragment(elementType: .string) + let keyCleanup = CodeFragmentPrinter() + let _ = keyFragment.printCode([keyVar], scope, printer, keyCleanup) + if !keyCleanup.lines.isEmpty { + printer.write("\(cleanupArrayVar).push(() => {") + printer.indent { + for line in keyCleanup.lines { + printer.write(line) + } + } + printer.write("});") + } + + let valueFragment = try! stackLowerFragment(elementType: valueType) + let valueCleanup = CodeFragmentPrinter() + let _ = valueFragment.printCode([valueVar], scope, printer, valueCleanup) + if !valueCleanup.lines.isEmpty { + printer.write("\(cleanupArrayVar).push(() => {") + printer.indent { + for line in valueCleanup.lines { + printer.write(line) + } + } + printer.write("});") + } + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(entriesVar).length);") + cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(isSomeVar) ? 1 : 0);") default: () } @@ -1807,6 +1904,8 @@ struct IntrinsicJSFragment: Sendable { throw BridgeJSLinkError(message: "Namespace enums are not supported to be passed as parameters: \(string)") case .array(let elementType): return try arrayLower(elementType: elementType) + case .dictionary(let valueType): + return try dictionaryLower(valueType: valueType) } } @@ -1854,6 +1953,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let elementType): return try arrayLift(elementType: elementType) + case .dictionary(let valueType): + return try dictionaryLift(valueType: valueType) } } @@ -1945,6 +2046,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let elementType): return try arrayLift(elementType: elementType) + case .dictionary(let valueType): + return try dictionaryLift(valueType: valueType) } } @@ -2014,6 +2117,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let elementType): return try arrayLower(elementType: elementType) + case .dictionary(let valueType): + return try dictionaryLower(valueType: valueType) } } @@ -2607,6 +2712,58 @@ struct IntrinsicJSFragment: Sendable { ) } + /// Lowers a dictionary from JS to Swift by iterating entries and pushing to stacks + static func dictionaryLower(valueType: BridgeType) throws -> IntrinsicJSFragment { + return IntrinsicJSFragment( + parameters: ["dict"], + printCode: { arguments, scope, printer, cleanupCode in + let dict = arguments[0] + let cleanupArrayVar = scope.variable("arrayCleanups") + + printer.write("const \(cleanupArrayVar) = [];") + let entriesVar = scope.variable("entries") + let entryVar = scope.variable("entry") + printer.write("const \(entriesVar) = Object.entries(\(dict));") + printer.write("for (const \(entryVar) of \(entriesVar)) {") + printer.indent { + let keyVar = scope.variable("key") + let valueVar = scope.variable("value") + printer.write("const [\(keyVar), \(valueVar)] = \(entryVar);") + + let keyFragment = try! stackLowerFragment(elementType: .string) + let keyCleanup = CodeFragmentPrinter() + let _ = keyFragment.printCode([keyVar], scope, printer, keyCleanup) + if !keyCleanup.lines.isEmpty { + printer.write("\(cleanupArrayVar).push(() => {") + printer.indent { + for line in keyCleanup.lines { + printer.write(line) + } + } + printer.write("});") + } + + let valueFragment = try! stackLowerFragment(elementType: valueType) + let valueCleanup = CodeFragmentPrinter() + let _ = valueFragment.printCode([valueVar], scope, printer, valueCleanup) + if !valueCleanup.lines.isEmpty { + printer.write("\(cleanupArrayVar).push(() => {") + printer.indent { + for line in valueCleanup.lines { + printer.write(line) + } + } + printer.write("});") + } + } + printer.write("}") + printer.write("\(JSGlueVariableScope.reservedTmpParamInts).push(\(entriesVar).length);") + cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") + return [] + } + ) + } + /// Lifts an array from Swift to JS by popping elements from stacks static func arrayLift(elementType: BridgeType) throws -> IntrinsicJSFragment { return IntrinsicJSFragment( @@ -2633,13 +2790,39 @@ struct IntrinsicJSFragment: Sendable { ) } + /// Lifts a dictionary from Swift to JS by popping key/value pairs from stacks + static func dictionaryLift(valueType: BridgeType) throws -> IntrinsicJSFragment { + return IntrinsicJSFragment( + parameters: [], + printCode: { arguments, scope, printer, cleanupCode in + let resultVar = scope.variable("dictResult") + let lenVar = scope.variable("dictLen") + let iVar = scope.variable("i") + + printer.write("const \(lenVar) = \(JSGlueVariableScope.reservedTmpRetInts).pop();") + printer.write("const \(resultVar) = {};") + printer.write("for (let \(iVar) = 0; \(iVar) < \(lenVar); \(iVar)++) {") + printer.indent { + let valueFragment = try! stackLiftFragment(elementType: valueType) + let valueResults = valueFragment.printCode([], scope, printer, cleanupCode) + let keyFragment = try! stackLiftFragment(elementType: .string) + let keyResults = keyFragment.printCode([], scope, printer, cleanupCode) + if let keyExpr = keyResults.first, let valueExpr = valueResults.first { + printer.write("\(resultVar)[\(keyExpr)] = \(valueExpr);") + } + } + printer.write("}") + return [resultVar] + } + ) + } + private static func stackLiftFragment(elementType: BridgeType) throws -> IntrinsicJSFragment { switch elementType { case .jsValue: return IntrinsicJSFragment( parameters: [], printCode: { _, scope, printer, cleanup in - registerJSValueHelpers(scope: scope) let payload2Var = scope.variable("jsValuePayload2") let payload1Var = scope.variable("jsValuePayload1") let kindVar = scope.variable("jsValueKind") @@ -2647,6 +2830,7 @@ struct IntrinsicJSFragment: Sendable { printer.write("const \(payload1Var) = \(scope.popI32Return());") printer.write("const \(kindVar) = \(scope.popI32Return());") let resultVar = scope.variable("jsValue") + registerJSValueHelpers(scope: scope) printer.write( "const \(resultVar) = \(jsValueLiftHelperName)(\(kindVar), \(payload1Var), \(payload2Var));" ) @@ -2795,6 +2979,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLift(elementType: innerElementType) + case .dictionary(let valueType): + return try! dictionaryLift(valueType: valueType) case .nullable(let wrappedType, let kind): return try optionalElementRaiseFragment(wrappedType: wrappedType, kind: kind) case .unsafePointer: @@ -2980,6 +3166,8 @@ struct IntrinsicJSFragment: Sendable { ) case .array(let innerElementType): return try! arrayLower(elementType: innerElementType) + case .dictionary(let valueType): + return try! dictionaryLower(valueType: valueType) case .nullable(let wrappedType, let kind): return try optionalElementLowerFragment( wrappedType: wrappedType, diff --git a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift index 0d4a78d3e..3029fe0c9 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift @@ -153,6 +153,7 @@ public enum BridgeType: Codable, Equatable, Hashable, Sendable { case unsafePointer(UnsafePointerType) indirect case nullable(BridgeType, JSOptionalKind) indirect case array(BridgeType) + indirect case dictionary(BridgeType) case caseEnum(String) case rawValueEnum(String, SwiftEnumRawType) case associatedValueEnum(String) @@ -959,6 +960,9 @@ extension BridgeType { case .array: // Arrays use stack-based return with length prefix (no direct WASM return type) return nil + case .dictionary: + // Dictionaries use stack-based return with entry count (no direct WASM return type) + return nil } } @@ -1024,6 +1028,9 @@ extension BridgeType { case .array(let elementType): // Array mangling: "Sa" prefix followed by element type return "Sa\(elementType.mangleTypeName)" + case .dictionary(let valueType): + // Dictionary mangling: "SD" prefix followed by value type (key is always String) + return "SD\(valueType.mangleTypeName)" } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DictionaryTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DictionaryTypes.swift new file mode 100644 index 000000000..c699ea79b --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/DictionaryTypes.swift @@ -0,0 +1,15 @@ +@JS class Box { + var value: Int + + init(value: Int) { + self.value = value + } +} + +@JS func mirrorDictionary(_ values: [String: Int]) -> [String: Int] +@JS func optionalDictionary(_ values: [String: String]?) -> [String: String]? +@JS func nestedDictionary(_ values: [String: [Int]]) -> [String: [Int]] +@JS func boxDictionary(_ boxes: [String: Box]) -> [String: Box] +@JS func optionalBoxDictionary(_ boxes: [String: Box?]) -> [String: Box?] + +@JSFunction func importMirrorDictionary(_ values: [String: Double]) throws(JSException) -> [String: Double] diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.json b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.json new file mode 100644 index 000000000..af5b83dc7 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.json @@ -0,0 +1,259 @@ +{ + "exported" : { + "classes" : [ + { + "methods" : [ + + ], + "name" : "Box", + "properties" : [ + + ], + "swiftCallName" : "Box" + } + ], + "enums" : [ + + ], + "exposeToGlobal" : false, + "functions" : [ + { + "abiName" : "bjs_mirrorDictionary", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "mirrorDictionary", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "abiName" : "bjs_optionalDictionary", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "optionalDictionary", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + }, + { + "abiName" : "bjs_nestedDictionary", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "nestedDictionary", + "parameters" : [ + { + "label" : "_", + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "array" : { + "_0" : { + "int" : { + + } + } + } + } + } + } + }, + { + "abiName" : "bjs_boxDictionary", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "boxDictionary", + "parameters" : [ + { + "label" : "_", + "name" : "boxes", + "type" : { + "dictionary" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Box" + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Box" + } + } + } + } + }, + { + "abiName" : "bjs_optionalBoxDictionary", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "optionalBoxDictionary", + "parameters" : [ + { + "label" : "_", + "name" : "boxes", + "type" : { + "dictionary" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Box" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "nullable" : { + "_0" : { + "swiftHeapObject" : { + "_0" : "Box" + } + }, + "_1" : "null" + } + } + } + } + } + ], + "protocols" : [ + + ], + "structs" : [ + + ] + }, + "imported" : { + "children" : [ + { + "functions" : [ + { + "name" : "importMirrorDictionary", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "types" : [ + + ] + } + ] + }, + "moduleName" : "TestModule" +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.swift new file mode 100644 index 000000000..2a41c35a7 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DictionaryTypes.swift @@ -0,0 +1,97 @@ +@_expose(wasm, "bjs_mirrorDictionary") +@_cdecl("bjs_mirrorDictionary") +public func _bjs_mirrorDictionary() -> Void { + #if arch(wasm32) + let ret = mirrorDictionary(_: [String: Int].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_optionalDictionary") +@_cdecl("bjs_optionalDictionary") +public func _bjs_optionalDictionary(_ values: Int32) -> Void { + #if arch(wasm32) + let ret = optionalDictionary(_: Optional<[String: String]>.bridgeJSLiftParameter(values)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_nestedDictionary") +@_cdecl("bjs_nestedDictionary") +public func _bjs_nestedDictionary() -> Void { + #if arch(wasm32) + let ret = nestedDictionary(_: [String: [Int]].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_boxDictionary") +@_cdecl("bjs_boxDictionary") +public func _bjs_boxDictionary() -> Void { + #if arch(wasm32) + let ret = boxDictionary(_: [String: Box].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_optionalBoxDictionary") +@_cdecl("bjs_optionalBoxDictionary") +public func _bjs_optionalBoxDictionary() -> Void { + #if arch(wasm32) + let ret = optionalBoxDictionary(_: [String: Optional].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_Box_deinit") +@_cdecl("bjs_Box_deinit") +public func _bjs_Box_deinit(_ pointer: UnsafeMutableRawPointer) -> Void { + #if arch(wasm32) + Unmanaged.fromOpaque(pointer).release() + #else + fatalError("Only available on WebAssembly") + #endif +} + +extension Box: ConvertibleToJSValue, _BridgedSwiftHeapObject { + var jsValue: JSValue { + return .object(JSObject(id: UInt32(bitPattern: _bjs_Box_wrap(Unmanaged.passRetained(self).toOpaque())))) + } +} + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_Box_wrap") +fileprivate func _bjs_Box_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 +#else +fileprivate func _bjs_Box_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 { + fatalError("Only available on WebAssembly") +} +#endif + +#if arch(wasm32) +@_extern(wasm, module: "TestModule", name: "bjs_importMirrorDictionary") +fileprivate func bjs_importMirrorDictionary() -> Void +#else +fileprivate func bjs_importMirrorDictionary() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$importMirrorDictionary(_ values: [String: Double]) throws(JSException) -> [String: Double] { + let _ = values.bridgeJSLowerParameter() + bjs_importMirrorDictionary() + if let error = _swift_js_take_exception() { + throw error + } + return [String: Double].bridgeJSLiftReturn() +} \ No newline at end of file diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.d.ts new file mode 100644 index 000000000..dadcc74ba --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.d.ts @@ -0,0 +1,34 @@ +// 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 Box extends SwiftHeapObject { +} +export type Exports = { + Box: { + } + mirrorDictionary(values: Record): Record; + optionalDictionary(values: Record | null): Record | null; + nestedDictionary(values: Record): Record; + boxDictionary(boxes: Record): Record; + optionalBoxDictionary(boxes: Record): Record; +} +export type Imports = { + importMirrorDictionary(values: Record): Record; +} +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/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js new file mode 100644 index 000000000..0388f7de1 --- /dev/null +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -0,0 +1,462 @@ +// 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; + } + // Wrapper functions for module: TestModule + if (!importObject["TestModule"]) { + importObject["TestModule"] = {}; + } + importObject["TestModule"]["bjs_Box_wrap"] = function(pointer) { + const obj = Box.__construct(pointer); + return swift.memory.retain(obj); + }; + const TestModule = importObject["TestModule"] = importObject["TestModule"] || {}; + TestModule["bjs_importMirrorDictionary"] = function bjs_importMirrorDictionary() { + try { + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const f64 = tmpRetF64s.pop(); + const string = tmpRetStrings.pop(); + dictResult[string] = f64; + } + let ret = imports.importMirrorDictionary(dictResult); + const arrayCleanups = []; + const entries = Object.entries(ret); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + tmpParamF64s.push(value); + } + tmpParamInts.push(entries.length); + } catch (error) { + setException(error); + } + } + }, + setInstance: (i) => { + instance = i; + memory = instance.exports.memory; + + setException = (error) => { + instance.exports._swift_js_exception.value = swift.memory.retain(error) + } + }, + /** @param {WebAssembly.Instance} instance */ + createExports: (instance) => { + const js = swift.memory.heap; + /// Represents a Swift heap object like a class instance or an actor instance. + class SwiftHeapObject { + static __wrap(pointer, deinit, prototype) { + const obj = Object.create(prototype); + obj.pointer = pointer; + obj.hasReleased = false; + obj.deinit = deinit; + obj.registry = new FinalizationRegistry((pointer) => { + deinit(pointer); + }); + obj.registry.register(this, obj.pointer); + return obj; + } + + release() { + this.registry.unregister(this); + this.deinit(this.pointer); + } + } + class Box extends SwiftHeapObject { + static __construct(ptr) { + return SwiftHeapObject.__wrap(ptr, instance.exports.bjs_Box_deinit, Box.prototype); + } + + } + const exports = { + Box, + mirrorDictionary: function bjs_mirrorDictionary(values) { + const arrayCleanups = []; + const entries = Object.entries(values); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + tmpParamInts.push((value | 0)); + } + tmpParamInts.push(entries.length); + instance.exports.bjs_mirrorDictionary(); + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const int = tmpRetInts.pop(); + const string = tmpRetStrings.pop(); + dictResult[string] = int; + } + for (const cleanup of arrayCleanups) { cleanup(); } + return dictResult; + }, + optionalDictionary: function bjs_optionalDictionary(values) { + const isSome = values != null; + const valuesCleanups = []; + if (isSome) { + const arrayCleanups = []; + const entries = Object.entries(values); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + const bytes1 = textEncoder.encode(value); + const id1 = swift.memory.retain(bytes1); + tmpParamInts.push(bytes1.length); + tmpParamInts.push(id1); + arrayCleanups.push(() => { + swift.memory.release(id1); + }); + } + tmpParamInts.push(entries.length); + valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); + } + instance.exports.bjs_optionalDictionary(+isSome); + const isSome1 = tmpRetInts.pop(); + let optResult; + if (isSome1) { + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const string = tmpRetStrings.pop(); + const string1 = tmpRetStrings.pop(); + dictResult[string1] = string; + } + optResult = dictResult; + } else { + optResult = null; + } + for (const cleanup of valuesCleanups) { cleanup(); } + return optResult; + }, + nestedDictionary: function bjs_nestedDictionary(values) { + const arrayCleanups = []; + const entries = Object.entries(values); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + const arrayCleanups1 = []; + for (const elem of value) { + tmpParamInts.push((elem | 0)); + } + tmpParamInts.push(value.length); + arrayCleanups.push(() => { + for (const cleanup of arrayCleanups1) { cleanup(); } + }); + } + tmpParamInts.push(entries.length); + instance.exports.bjs_nestedDictionary(); + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const arrayLen = tmpRetInts.pop(); + const arrayResult = []; + for (let i1 = 0; i1 < arrayLen; i1++) { + const int = tmpRetInts.pop(); + arrayResult.push(int); + } + arrayResult.reverse(); + const string = tmpRetStrings.pop(); + dictResult[string] = arrayResult; + } + for (const cleanup of arrayCleanups) { cleanup(); } + return dictResult; + }, + boxDictionary: function bjs_boxDictionary(boxes) { + const arrayCleanups = []; + const entries = Object.entries(boxes); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + tmpParamPointers.push(value.pointer); + } + tmpParamInts.push(entries.length); + instance.exports.bjs_boxDictionary(); + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const ptr = tmpRetPointers.pop(); + const obj = _exports['Box'].__construct(ptr); + const string = tmpRetStrings.pop(); + dictResult[string] = obj; + } + for (const cleanup of arrayCleanups) { cleanup(); } + return dictResult; + }, + optionalBoxDictionary: function bjs_optionalBoxDictionary(boxes) { + const arrayCleanups = []; + const entries = Object.entries(boxes); + for (const entry of entries) { + const [key, value] = entry; + const bytes = textEncoder.encode(key); + const id = swift.memory.retain(bytes); + tmpParamInts.push(bytes.length); + tmpParamInts.push(id); + arrayCleanups.push(() => { + swift.memory.release(id); + }); + const isSome = value != null ? 1 : 0; + if (isSome) { + tmpParamPointers.push(value.pointer); + } else { + tmpParamPointers.push(0); + } + tmpParamInts.push(isSome); + } + tmpParamInts.push(entries.length); + instance.exports.bjs_optionalBoxDictionary(); + const dictLen = tmpRetInts.pop(); + const dictResult = {}; + for (let i = 0; i < dictLen; i++) { + const isSome1 = tmpRetInts.pop(); + let optValue; + if (isSome1 === 0) { + optValue = null; + } else { + const ptr = tmpRetPointers.pop(); + const obj = _exports['Box'].__construct(ptr); + optValue = obj; + } + const string = tmpRetStrings.pop(); + dictResult[string] = optValue; + } + for (const cleanup of arrayCleanups) { cleanup(); } + return dictResult; + }, + }; + _exports = exports; + return exports; + }, + } +} \ No newline at end of file diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 1c8592724..fd2cbd909 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -2375,3 +2375,122 @@ extension Array: _BridgedSwiftStackType where Element: _BridgedSwiftStackType, E bridgeJSLowerReturn() } } + +// MARK: - Dictionary Support + +public protocol _BridgedSwiftDictionaryStackType: _BridgedSwiftTypeLoweredIntoVoidType { + associatedtype DictionaryValue: _BridgedSwiftStackType + where DictionaryValue.StackLiftResult == DictionaryValue +} + +extension Dictionary: _BridgedSwiftStackType +where Key == String, Value: _BridgedSwiftStackType, Value.StackLiftResult == Value { + public typealias StackLiftResult = [String: Value] + // Lowering/return use stack-based encoding, so dictionary also behaves like a void-lowered type. + // Optional/JSUndefinedOr wrappers rely on this conformance to push an isSome flag and + // then delegate to the stack-based lowering defined below. + // swiftlint:disable:next type_name +} + +extension Dictionary: _BridgedSwiftTypeLoweredIntoVoidType, _BridgedSwiftDictionaryStackType +where Key == String, Value: _BridgedSwiftStackType, Value.StackLiftResult == Value { + public typealias DictionaryValue = Value + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> [String: Value] { + let count = Int(_swift_js_pop_i32()) + var result: [String: Value] = [:] + result.reserveCapacity(count) + for _ in 0.. [String: Value] { + bridgeJSLiftParameter() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerStackReturn() { + bridgeJSLowerReturn() + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() { + let count = Int32(self.count) + for (key, value) in self { + key.bridgeJSLowerStackReturn() + value.bridgeJSLowerStackReturn() + } + _swift_js_push_i32(count) + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() { + bridgeJSLowerReturn() + } +} + +extension Optional where Wrapped: _BridgedSwiftDictionaryStackType { + typealias DictionaryValue = Wrapped.DictionaryValue + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> Int32 { + switch consume self { + case .none: + return 0 + case .some(let dict): + dict.bridgeJSLowerReturn() + return 1 + } + } + + @_spi(BridgeJS) public consuming func bridgeJSLowerReturn() { + switch consume self { + case .none: + _swift_js_push_i32(0) + case .some(let dict): + dict.bridgeJSLowerReturn() + _swift_js_push_i32(1) + } + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter(_ isSome: Int32) -> [String: Wrapped.DictionaryValue]? { + if isSome == 0 { + return nil + } + return Dictionary.bridgeJSLiftParameter() + } + + @_spi(BridgeJS) public static func bridgeJSLiftParameter() -> [String: Wrapped.DictionaryValue]? { + bridgeJSLiftParameter(_swift_js_pop_i32()) + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn() -> [String: Wrapped.DictionaryValue]? { + let isSome = _swift_js_pop_i32() + if isSome == 0 { + return nil + } + return Dictionary.bridgeJSLiftParameter() + } +} + +extension _BridgedAsOptional where Wrapped: _BridgedSwiftDictionaryStackType { + typealias DictionaryValue = Wrapped.DictionaryValue + + @_spi(BridgeJS) public consuming func bridgeJSLowerParameter() -> Int32 { + let opt = optionalRepresentation + if let dict = opt { + dict.bridgeJSLowerReturn() + return 1 + } + return 0 + } + + @_spi(BridgeJS) public static func bridgeJSLiftReturn() -> Self { + let isSome = _swift_js_pop_i32() + if isSome == 0 { + return Self(optional: nil) + } + let value = Dictionary.bridgeJSLiftParameter() as! Wrapped + return Self(optional: value) + } +} diff --git a/Tests/BridgeJSRuntimeTests/DictionaryTests.swift b/Tests/BridgeJSRuntimeTests/DictionaryTests.swift new file mode 100644 index 000000000..83ca72d04 --- /dev/null +++ b/Tests/BridgeJSRuntimeTests/DictionaryTests.swift @@ -0,0 +1,96 @@ +@_spi(Experimental) @_spi(BridgeJS) import JavaScriptKit +import XCTest + +final class DictionaryTests: XCTestCase { + func testRoundTripDictionary() throws { + let input: [String: Int] = ["a": 1, "b": 2] + let result = try jsRoundTripDictionary(input) + XCTAssertEqual(result, input) + } + + func testRoundTripDictionaryBool() throws { + let input: [String: Bool] = ["yes": true, "no": false] + let result = try jsRoundTripDictionaryBool(input) + XCTAssertEqual(result, input) + } + + func testRoundTripDictionaryDouble() throws { + let input: [String: Double] = ["pi": 3.14, "tau": 6.28] + let result = try jsRoundTripDictionaryDouble(input) + XCTAssertEqual(result, input) + } + + func testRoundTripDictionaryJSObject() throws { + let global = JSObject.global + let input: [String: JSObject] = [ + "global": global + ] + let result = try jsRoundTripDictionaryJSObject(input) + XCTAssertEqual(result, input) + } + + func testRoundTripDictionaryJSValue() throws { + let input: [String: JSValue] = [ + "number": .number(123.5), + "boolean": .boolean(true), + "string": .string("hello"), + "null": .null, + ] + let result = try jsRoundTripDictionaryJSValue(input) + XCTAssertEqual(result, input) + } + + func testRoundTripNestedDictionary() throws { + let input: [String: [Double]] = [ + "xs": [1.0, 2.5], + "ys": [], + ] + let result = try jsRoundTripNestedDictionary(input) + XCTAssertEqual(result, input) + } + + func testRoundTripOptionalDictionaryNull() throws { + let some: [String: String]? = ["k": "v"] + XCTAssertEqual(try jsRoundTripOptionalDictionary(some), some) + XCTAssertNil(try jsRoundTripOptionalDictionary(nil)) + } + + func testRoundTripOptionalDictionaryUndefined() throws { + let some: JSUndefinedOr<[String: Int]> = .value(["n": 42]) + let undefined: JSUndefinedOr<[String: Int]> = .undefinedValue + + let returnedSome = try jsRoundTripUndefinedDictionary(some) + switch returnedSome { + case .value(let dict): + XCTAssertEqual(dict, ["n": 42]) + case .undefined: + XCTFail("Expected defined dictionary") + } + + let returnedUndefined = try jsRoundTripUndefinedDictionary(undefined) + switch returnedUndefined { + case .value: + XCTFail("Expected undefined") + case .undefined: + break + } + } +} + +@JSFunction func jsRoundTripDictionary(_ values: [String: Int]) throws(JSException) -> [String: Int] + +@JSFunction func jsRoundTripDictionaryBool(_ values: [String: Bool]) throws(JSException) -> [String: Bool] + +@JSFunction func jsRoundTripDictionaryDouble(_ values: [String: Double]) throws(JSException) -> [String: Double] + +@JSFunction func jsRoundTripDictionaryJSObject(_ values: [String: JSObject]) throws(JSException) -> [String: JSObject] + +@JSFunction func jsRoundTripDictionaryJSValue(_ values: [String: JSValue]) throws(JSException) -> [String: JSValue] + +@JSFunction func jsRoundTripNestedDictionary(_ values: [String: [Double]]) throws(JSException) -> [String: [Double]] + +@JSFunction func jsRoundTripOptionalDictionary(_ values: [String: String]?) throws(JSException) -> [String: String]? + +@JSFunction func jsRoundTripUndefinedDictionary( + _ values: JSUndefinedOr<[String: Int]> +) throws(JSException) -> JSUndefinedOr<[String: Int]> diff --git a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift index 74817d82b..7f9a20586 100644 --- a/Tests/BridgeJSRuntimeTests/ExportAPITests.swift +++ b/Tests/BridgeJSRuntimeTests/ExportAPITests.swift @@ -52,6 +52,14 @@ func runJsWorks() -> Void return v } +@JS func roundTripDictionaryExport(v: [String: Int]) -> [String: Int] { + return v +} + +@JS func roundTripOptionalDictionaryExport(v: [String: String]?) -> [String: String]? { + return v +} + @JS func roundTripJSValue(v: JSValue) -> JSValue { return v } diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 194ed04b3..7ca92b35c 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -3810,6 +3810,28 @@ public func _bjs_roundTripJSObject(_ v: Int32) -> Int32 { #endif } +@_expose(wasm, "bjs_roundTripDictionaryExport") +@_cdecl("bjs_roundTripDictionaryExport") +public func _bjs_roundTripDictionaryExport() -> Void { + #if arch(wasm32) + let ret = roundTripDictionaryExport(v: [String: Int].bridgeJSLiftParameter()) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + +@_expose(wasm, "bjs_roundTripOptionalDictionaryExport") +@_cdecl("bjs_roundTripOptionalDictionaryExport") +public func _bjs_roundTripOptionalDictionaryExport(_ v: Int32) -> Void { + #if arch(wasm32) + let ret = roundTripOptionalDictionaryExport(v: Optional<[String: String]>.bridgeJSLiftParameter(v)) + return ret.bridgeJSLowerReturn() + #else + fatalError("Only available on WebAssembly") + #endif +} + @_expose(wasm, "bjs_roundTripJSValue") @_cdecl("bjs_roundTripJSValue") public func _bjs_roundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vPayload2: Float64) -> Void { @@ -8437,6 +8459,150 @@ fileprivate func _bjs_Container_wrap(_ pointer: UnsafeMutableRawPointer) -> Int3 } #endif +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionary") +fileprivate func bjs_jsRoundTripDictionary() -> Void +#else +fileprivate func bjs_jsRoundTripDictionary() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripDictionary(_ values: [String: Int]) throws(JSException) -> [String: Int] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripDictionary() + if let error = _swift_js_take_exception() { + throw error + } + return [String: Int].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryBool") +fileprivate func bjs_jsRoundTripDictionaryBool() -> Void +#else +fileprivate func bjs_jsRoundTripDictionaryBool() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripDictionaryBool(_ values: [String: Bool]) throws(JSException) -> [String: Bool] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripDictionaryBool() + if let error = _swift_js_take_exception() { + throw error + } + return [String: Bool].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryDouble") +fileprivate func bjs_jsRoundTripDictionaryDouble() -> Void +#else +fileprivate func bjs_jsRoundTripDictionaryDouble() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripDictionaryDouble(_ values: [String: Double]) throws(JSException) -> [String: Double] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripDictionaryDouble() + if let error = _swift_js_take_exception() { + throw error + } + return [String: Double].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryJSObject") +fileprivate func bjs_jsRoundTripDictionaryJSObject() -> Void +#else +fileprivate func bjs_jsRoundTripDictionaryJSObject() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripDictionaryJSObject(_ values: [String: JSObject]) throws(JSException) -> [String: JSObject] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripDictionaryJSObject() + if let error = _swift_js_take_exception() { + throw error + } + return [String: JSObject].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripDictionaryJSValue") +fileprivate func bjs_jsRoundTripDictionaryJSValue() -> Void +#else +fileprivate func bjs_jsRoundTripDictionaryJSValue() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripDictionaryJSValue(_ values: [String: JSValue]) throws(JSException) -> [String: JSValue] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripDictionaryJSValue() + if let error = _swift_js_take_exception() { + throw error + } + return [String: JSValue].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripNestedDictionary") +fileprivate func bjs_jsRoundTripNestedDictionary() -> Void +#else +fileprivate func bjs_jsRoundTripNestedDictionary() -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripNestedDictionary(_ values: [String: [Double]]) throws(JSException) -> [String: [Double]] { + let _ = values.bridgeJSLowerParameter() + bjs_jsRoundTripNestedDictionary() + if let error = _swift_js_take_exception() { + throw error + } + return [String: [Double]].bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripOptionalDictionary") +fileprivate func bjs_jsRoundTripOptionalDictionary(_ values: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripOptionalDictionary(_ values: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripOptionalDictionary(_ values: Optional<[String: String]>) throws(JSException) -> Optional<[String: String]> { + let valuesIsSome = values.bridgeJSLowerParameter() + bjs_jsRoundTripOptionalDictionary(valuesIsSome) + if let error = _swift_js_take_exception() { + throw error + } + return Optional<[String: String]>.bridgeJSLiftReturn() +} + +#if arch(wasm32) +@_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_jsRoundTripUndefinedDictionary") +fileprivate func bjs_jsRoundTripUndefinedDictionary(_ values: Int32) -> Void +#else +fileprivate func bjs_jsRoundTripUndefinedDictionary(_ values: Int32) -> Void { + fatalError("Only available on WebAssembly") +} +#endif + +func _$jsRoundTripUndefinedDictionary(_ values: JSUndefinedOr<[String: Int]>) throws(JSException) -> JSUndefinedOr<[String: Int]> { + let valuesIsSome = values.bridgeJSLowerParameter() + bjs_jsRoundTripUndefinedDictionary(valuesIsSome) + if let error = _swift_js_take_exception() { + throw error + } + return JSUndefinedOr<[String: Int]>.bridgeJSLiftReturn() +} + #if arch(wasm32) @_extern(wasm, module: "BridgeJSRuntimeTests", name: "bjs_Foo_init") fileprivate func bjs_Foo_init(_ value: Int32) -> Int32 diff --git a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json index 10ca73fe8..8171fd95f 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json +++ b/Tests/BridgeJSRuntimeTests/Generated/JavaScript/BridgeJS.json @@ -5577,6 +5577,82 @@ } } }, + { + "abiName" : "bjs_roundTripDictionaryExport", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripDictionaryExport", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "abiName" : "bjs_roundTripOptionalDictionaryExport", + "effects" : { + "isAsync" : false, + "isStatic" : false, + "isThrows" : false + }, + "name" : "roundTripOptionalDictionaryExport", + "parameters" : [ + { + "label" : "v", + "name" : "v", + "type" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + }, { "abiName" : "bjs_roundTripJSValue", "effects" : { @@ -12838,6 +12914,249 @@ }, "imported" : { "children" : [ + { + "functions" : [ + { + "name" : "jsRoundTripDictionary", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripDictionaryBool", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "bool" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "bool" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripDictionaryDouble", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "double" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "double" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripDictionaryJSObject", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "jsObject" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "jsObject" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripDictionaryJSValue", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "jsValue" : { + + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "jsValue" : { + + } + } + } + } + }, + { + "name" : "jsRoundTripNestedDictionary", + "parameters" : [ + { + "name" : "values", + "type" : { + "dictionary" : { + "_0" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + } + } + ], + "returnType" : { + "dictionary" : { + "_0" : { + "array" : { + "_0" : { + "double" : { + + } + } + } + } + } + } + }, + { + "name" : "jsRoundTripOptionalDictionary", + "parameters" : [ + { + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "string" : { + + } + } + } + }, + "_1" : "null" + } + } + }, + { + "name" : "jsRoundTripUndefinedDictionary", + "parameters" : [ + { + "name" : "values", + "type" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "undefined" + } + } + } + ], + "returnType" : { + "nullable" : { + "_0" : { + "dictionary" : { + "_0" : { + "int" : { + + } + } + } + }, + "_1" : "undefined" + } + } + } + ], + "types" : [ + + ] + }, { "functions" : [ diff --git a/Tests/prelude.mjs b/Tests/prelude.mjs index 92f5079d4..934c4f01c 100644 --- a/Tests/prelude.mjs +++ b/Tests/prelude.mjs @@ -64,6 +64,30 @@ export async function setupOptions(options, context) { "jsRoundTripString": (v) => { return v; }, + "jsRoundTripDictionary": (dict) => { + return { ...dict }; + }, + "jsRoundTripDictionaryBool": (dict) => { + return { ...dict }; + }, + "jsRoundTripDictionaryDouble": (dict) => { + return { ...dict }; + }, + "jsRoundTripDictionaryJSObject": (dict) => { + return dict; + }, + "jsRoundTripDictionaryJSValue": (dict) => { + return dict; + }, + "jsRoundTripNestedDictionary": (dict) => { + return Object.fromEntries(Object.entries(dict).map(([k, v]) => [k, [...v]])); + }, + "jsRoundTripOptionalDictionary": (dict) => { + return dict ?? null; + }, + "jsRoundTripUndefinedDictionary": (dict) => { + return dict; + }, "jsRoundTripOptionalNumberNull": (v) => { return v ?? null; }, @@ -279,6 +303,11 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) { ]) { assert.equal(exports.roundTripString(v), v); } + const dict = { a: 1, b: 2 }; + assert.deepEqual(exports.roundTripDictionaryExport(dict), dict); + const optDict = { hello: "world" }; + assert.deepEqual(exports.roundTripOptionalDictionaryExport(optDict), optDict); + assert.equal(exports.roundTripOptionalDictionaryExport(null), null); const arrayStruct = { ints: [1, 2, 3], optStrings: ["a", "b"] }; const arrayStructRoundTrip = exports.roundTripArrayMembers(arrayStruct); assert.deepEqual(arrayStructRoundTrip.ints, [1, 2, 3]); From 3da2172ec333e73fff759c2c41da83c223851de7 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 5 Feb 2026 12:14:53 +0100 Subject: [PATCH 6/8] PackageToJS: Fix skeleton file discovery path for build plugin output The SkeletonCollector was looking for BridgeJS.json at the wrong path for build-time generated files. Since commit 91d2f061, BridgeJSTool writes skeleton files to `destination/BridgeJS/JavaScript/BridgeJS.json`, but PackageToJS was searching in `destination/BridgeJS/BridgeJS.json` (missing the JavaScript/ subdirectory). This caused projects using dynamic BridgeJS generation via the build plugin to fail - PackageToJS couldn't find the skeleton files, resulting in HAS_BRIDGE=false and stub implementations in instantiate.js. --- Plugins/PackageToJS/Sources/PackageToJSPlugin.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift index 3cbd29014..7e335c68e 100644 --- a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift +++ b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift @@ -751,9 +751,9 @@ class SkeletonCollector { let directories = [ target.directoryURL.appending(path: "Generated/JavaScript"), // context.pluginWorkDirectoryURL: ".build/plugins/PackageToJS/outputs/" - // .build/plugins/outputs/exportswift/MyApp/destination/BridgeJS/BridgeJS.ExportSwift.json + // .build/plugins/outputs/[package]/[target]/destination/BridgeJS/JavaScript/BridgeJS.json context.pluginWorkDirectoryURL.deletingLastPathComponent().deletingLastPathComponent() - .appending(path: "outputs/\(package.id)/\(target.name)/destination/BridgeJS"), + .appending(path: "outputs/\(package.id)/\(target.name)/destination/BridgeJS/JavaScript"), ] for directory in directories { let skeletonURL = directory.appending(path: skeletonFile) From 6b3a697340cf5d1e3a861f25c589b136a107b179 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Thu, 5 Feb 2026 22:22:59 +0900 Subject: [PATCH 7/8] Add ts2swift Record to Dictionary mapping (#582) --- .../TS2Swift/JavaScript/src/processor.js | 54 +++++++++++++++++++ .../test/__snapshots__/ts2swift.test.js.snap | 30 +++++++++++ .../test/fixtures/RecordDictionary.d.ts | 17 ++++++ 3 files changed, 101 insertions(+) create mode 100644 Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/RecordDictionary.d.ts diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js index ef446af0f..04578e9ea 100644 --- a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/src/processor.js @@ -663,6 +663,7 @@ export class TypeProcessor { * @private */ visitType(type, node) { + const typeArguments = this.getTypeArguments(type); if (this.checker.isArrayType(type)) { const typeArgs = this.checker.getTypeArguments(type); if (typeArgs && typeArgs.length > 0) { @@ -672,6 +673,11 @@ export class TypeProcessor { return "[JSObject]"; } + const recordType = this.convertRecordType(type, typeArguments, node); + if (recordType) { + return recordType; + } + // Treat A and A as the same type if (isTypeReference(type)) { type = type.target; @@ -760,6 +766,54 @@ export class TypeProcessor { return swiftType; } + /** + * Convert a `Record` TypeScript type into a Swift dictionary type. + * Falls back to `JSObject` when keys are not string-compatible or type arguments are missing. + * @param {ts.Type} type + * @param {ts.Type[]} typeArguments + * @param {ts.Node} node + * @returns {string | null} + * @private + */ + convertRecordType(type, typeArguments, node) { + const symbol = type.aliasSymbol ?? type.getSymbol(); + if (!symbol || symbol.name !== "Record") { + return null; + } + if (typeArguments.length !== 2) { + this.diagnosticEngine.print("warning", "Record expects two type arguments", node); + return "JSObject"; + } + const [keyType, valueType] = typeArguments; + const stringType = this.checker.getStringType(); + if (!this.checker.isTypeAssignableTo(keyType, stringType)) { + this.diagnosticEngine.print( + "warning", + `Record key type must be assignable to string: ${this.checker.typeToString(keyType)}`, + node + ); + return "JSObject"; + } + + const valueSwiftType = this.visitType(valueType, node); + return `[String: ${valueSwiftType}]`; + } + + /** + * Retrieve type arguments for a given type, including type alias instantiations. + * @param {ts.Type} type + * @returns {ts.Type[]} + * @private + */ + getTypeArguments(type) { + if (isTypeReference(type)) { + return this.checker.getTypeArguments(type); + } + // Non-TypeReference alias instantiations store type arguments separately. + // @ts-ignore: `aliasTypeArguments` is intentionally accessed for alias instantiations. + return type.aliasTypeArguments ?? []; + } + /** * Derive the type name from a type * @param {ts.Type} type - TypeScript type 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 6fdb79f78..e6fb234c4 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 @@ -251,6 +251,36 @@ exports[`ts2swift > snapshots Swift output for ReExportFrom.d.ts > ReExportFrom " `; +exports[`ts2swift > snapshots Swift output for RecordDictionary.d.ts > RecordDictionary 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 takeRecord(_ value: [String: Double]) throws(JSException) -> Void + +@JSFunction func returnRecord() throws(JSException) -> [String: String] + +@JSFunction func optionalRecord(_ value: Optional<[String: Bool]>) throws(JSException) -> Optional<[String: Bool]> + +@JSFunction func nestedRecord(_ value: [String: [String: Double]]) throws(JSException) -> [String: [String: Double]] + +@JSFunction func recordWithArrayValues(_ values: [String: [Double]]) throws(JSException) -> [String: [Double]] + +@JSFunction func recordWithObjects(_ values: [String: Optional]) throws(JSException) -> [String: Optional] + +@JSClass struct Box { + @JSGetter var value: Double + @JSSetter func setValue(_ value: Double) throws(JSException) +} + +@JSFunction func unsupportedKeyRecord(_ values: JSObject) throws(JSException) -> Void +" +`; + exports[`ts2swift > snapshots Swift output for StringEnum.d.ts > StringEnum 1`] = ` "// NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, // DO NOT EDIT. diff --git a/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/RecordDictionary.d.ts b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/RecordDictionary.d.ts new file mode 100644 index 000000000..cfaf5f309 --- /dev/null +++ b/Plugins/BridgeJS/Sources/TS2Swift/JavaScript/test/fixtures/RecordDictionary.d.ts @@ -0,0 +1,17 @@ +export interface Box { + value: number; +} + +export function takeRecord(value: Record): void; + +export function returnRecord(): Record; + +export function optionalRecord(value: Record | null): Record | null; + +export function nestedRecord(value: Record>): Record>; + +export function recordWithArrayValues(values: Record): Record; + +export function recordWithObjects(values: Record): Record; + +export function unsupportedKeyRecord(values: Record): void; From b1fb45edf79e44d5b73136c3303d8fa9104be478 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 5 Feb 2026 21:30:36 +0700 Subject: [PATCH 8/8] BridgeJS: Add missing `function` keyword for namespace function declarations in TypeScript (#592) --- Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift | 2 +- .../BridgeJSLinkTests/EnumNamespace.Global.d.ts | 6 +++--- .../__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts | 2 +- .../__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts | 2 +- .../BridgeJSLinkTests/StaticFunctions.Global.d.ts | 2 +- .../Exporting-Swift/Exporting-Swift-Static-Functions.md | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 39fb77b7d..fb232355d 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -3094,7 +3094,7 @@ extension BridgeJSLink { let sortedFunctions = childNode.content.functions.sorted { $0.name < $1.name } for function in sortedFunctions { let signature = - "\(function.name)\(renderTSSignatureCallback(function.parameters, function.returnType, function.effects));" + "function \(function.name)\(renderTSSignatureCallback(function.parameters, function.returnType, function.effects));" printer.write(signature) } let sortedProperties = childNode.content.staticProperties.sorted { $0.name < $1.name } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts index f1dc0a926..be77e759c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.d.ts @@ -61,9 +61,9 @@ declare global { namespace Services { namespace Graph { namespace GraphOperations { - createGraph(rootId: number): number; - nodeCount(graphId: number): number; - validate(graphId: number): boolean; + function createGraph(rootId: number): number; + function nodeCount(graphId: number): number; + function validate(graphId: number): boolean; } } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts index 67a6eebcf..6f18e53ed 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.d.ts @@ -12,7 +12,7 @@ declare global { constructor(); greet(): string; } - globalFunction(): string; + function globalFunction(): string; } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts index cdf83f36d..77d9cc0e9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts @@ -9,7 +9,7 @@ export {}; declare global { namespace MyModule { namespace Utils { - namespacedFunction(): string; + function namespacedFunction(): string; } } namespace Utils { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts index 069c1628c..a2f1c7d6d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.d.ts @@ -33,7 +33,7 @@ export {}; declare global { namespace Utils { namespace String { - uppercase(text: string): string; + function uppercase(text: string): string; } } } diff --git a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Static-Functions.md b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Static-Functions.md index 00e7c1f22..b6f680d1f 100644 --- a/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Static-Functions.md +++ b/Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Static-Functions.md @@ -140,7 +140,7 @@ Generated TypeScript definitions: declare global { namespace Utils { namespace String { - uppercase(text: string): string; + function uppercase(text: string): string; } } }