diff --git a/Benchmarks/Sources/Generated/BridgeJS.swift b/Benchmarks/Sources/Generated/BridgeJS.swift index 6ec87dca8..65e57bdf9 100644 --- a/Benchmarks/Sources/Generated/BridgeJS.swift +++ b/Benchmarks/Sources/Generated/BridgeJS.swift @@ -132,10 +132,7 @@ extension SimpleStruct: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_SimpleStruct(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_SimpleStruct(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -148,9 +145,9 @@ extension SimpleStruct: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_SimpleStruct") -fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_SimpleStruct(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -179,10 +176,7 @@ extension Address: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -195,9 +189,9 @@ extension Address: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Address") -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -232,10 +226,7 @@ extension Person: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -248,9 +239,9 @@ extension Person: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Person") -fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -285,10 +276,7 @@ extension ComplexStruct: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_ComplexStruct(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_ComplexStruct(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -301,9 +289,9 @@ extension ComplexStruct: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ComplexStruct") -fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_ComplexStruct(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -330,10 +318,7 @@ extension Point: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -346,9 +331,9 @@ extension Point: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift index 6e146dbc3..f2aaa9794 100644 --- a/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift +++ b/Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift @@ -24,10 +24,7 @@ extension PlayBridgeJSOutput: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -40,9 +37,9 @@ extension PlayBridgeJSOutput: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSOutput") -fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -77,10 +74,7 @@ extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -93,9 +87,9 @@ extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSDiagnostic") -fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -122,10 +116,7 @@ extension PlayBridgeJSResult: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -138,9 +129,9 @@ extension PlayBridgeJSResult: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSResult") -fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index 207f6ee69..525f6b73b 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -1243,10 +1243,7 @@ struct StructCodegen { printer.write( multilineString: """ \(accessControl)init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = \(lowerFunctionName)(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + \(lowerFunctionName)(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } """ @@ -1274,7 +1271,7 @@ struct StructCodegen { functionName: lowerFunctionName, signature: SwiftSignatureBuilder.buildABIFunctionSignature( abiParameters: [("objectId", .i32)], - returnType: .i32 + returnType: nil ) ) let liftExternDeclPrinter = CodeFragmentPrinter() diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 5bf17256d..61ffc7781 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -261,7 +261,6 @@ public struct BridgeJSLink { "let \(JSGlueVariableScope.reservedF32Stack) = [];", "let \(JSGlueVariableScope.reservedF64Stack) = [];", "let \(JSGlueVariableScope.reservedPointerStack) = [];", - "let \(JSGlueVariableScope.reservedTmpStructCleanups) = [];", "const \(JSGlueVariableScope.reservedEnumHelpers) = {};", "const \(JSGlueVariableScope.reservedStructHelpers) = {};", "", @@ -403,38 +402,13 @@ public struct BridgeJSLink { printer.write("return \(JSGlueVariableScope.reservedPointerStack).pop();") } printer.write("}") - printer.write("bjs[\"swift_js_struct_cleanup\"] = function(cleanupId) {") - printer.indent { - printer.write("if (cleanupId === 0) { return; }") - printer.write("const index = (cleanupId | 0) - 1;") - printer.write("const cleanup = \(JSGlueVariableScope.reservedTmpStructCleanups)[index];") - printer.write("\(JSGlueVariableScope.reservedTmpStructCleanups)[index] = null;") - printer.write("if (cleanup) { cleanup(); }") - printer.write( - "while (\(JSGlueVariableScope.reservedTmpStructCleanups).length > 0 && \(JSGlueVariableScope.reservedTmpStructCleanups)[\(JSGlueVariableScope.reservedTmpStructCleanups).length - 1] == null) {" - ) - printer.indent { - printer.write("\(JSGlueVariableScope.reservedTmpStructCleanups).pop();") - } - printer.write("}") - } - printer.write("}") - if !allStructs.isEmpty { for structDef in allStructs { printer.write("bjs[\"swift_js_struct_lower_\(structDef.name)\"] = function(objectId) {") printer.indent { printer.write( - "const { cleanup: cleanup } = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(\(JSGlueVariableScope.reservedSwift).memory.getObject(objectId));" + "\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(\(JSGlueVariableScope.reservedSwift).memory.getObject(objectId));" ) - printer.write("if (cleanup) {") - printer.indent { - printer.write( - "return \(JSGlueVariableScope.reservedTmpStructCleanups).push(cleanup);" - ) - } - printer.write("}") - printer.write("return 0;") } printer.write("}") @@ -956,14 +930,12 @@ public struct BridgeJSLink { for structDef in allStructs { let structPrinter = CodeFragmentPrinter() let structScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) - let structCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.structHelper(structDefinition: structDef, allStructs: allStructs) _ = try fragment.printCode( [structDef.name], IntrinsicJSFragment.PrintCodeContext( scope: structScope, - printer: structPrinter, - cleanupCode: structCleanup + printer: structPrinter ) ) bodyPrinter.write(lines: structPrinter.lines) @@ -975,14 +947,12 @@ public struct BridgeJSLink { for enumDef in allAssocEnums { let enumPrinter = CodeFragmentPrinter() let enumScope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) - let enumCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.associatedValueEnumHelperFactory(enumDefinition: enumDef) _ = try fragment.printCode( [enumDef.valuesName], IntrinsicJSFragment.PrintCodeContext( scope: enumScope, - printer: enumPrinter, - cleanupCode: enumCleanup + printer: enumPrinter ) ) bodyPrinter.write(lines: enumPrinter.lines) @@ -1227,7 +1197,6 @@ public struct BridgeJSLink { class ExportedThunkBuilder { var body: CodeFragmentPrinter - var cleanupCode: CodeFragmentPrinter var parameterForwardings: [String] = [] let effects: Effects let scope: JSGlueVariableScope @@ -1237,11 +1206,9 @@ public struct BridgeJSLink { self.effects = effects self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) self.body = CodeFragmentPrinter() - self.cleanupCode = CodeFragmentPrinter() self.context = IntrinsicJSFragment.PrintCodeContext( scope: scope, printer: body, - cleanupCode: cleanupCode, hasDirectAccessToSwiftClass: hasDirectAccessToSwiftClass ) } @@ -1312,10 +1279,9 @@ public struct BridgeJSLink { ] } - /// Renders the thunk body (body code, cleanup, exception handling, and optional return) into a printer. + /// Renders the thunk body (body code, exception handling, and optional return) into a printer. func renderFunctionBody(into printer: CodeFragmentPrinter, returnExpr: String?) { printer.write(contentsOf: body) - printer.write(contentsOf: cleanupCode) printer.write(lines: checkExceptionLines()) if let returnExpr = returnExpr { printer.write("return \(returnExpr);") @@ -1541,8 +1507,7 @@ public struct BridgeJSLink { let printer = CodeFragmentPrinter() let context = IntrinsicJSFragment.PrintCodeContext( scope: scope, - printer: printer, - cleanupCode: CodeFragmentPrinter() + printer: printer ) let enumValuesName = enumDefinition.valuesName @@ -2127,7 +2092,6 @@ extension BridgeJSLink { class ImportedThunkBuilder { let body: CodeFragmentPrinter let scope: JSGlueVariableScope - let cleanupCode: CodeFragmentPrinter let context: BridgeContext var parameterNames: [String] = [] var parameterForwardings: [String] = [] @@ -2136,12 +2100,10 @@ extension BridgeJSLink { init(context: BridgeContext = .importTS, intrinsicRegistry: JSIntrinsicRegistry) { self.body = CodeFragmentPrinter() self.scope = JSGlueVariableScope(intrinsicRegistry: intrinsicRegistry) - self.cleanupCode = CodeFragmentPrinter() self.context = context self.printContext = IntrinsicJSFragment.PrintCodeContext( scope: scope, - printer: body, - cleanupCode: cleanupCode + printer: body ) } @@ -2680,7 +2642,6 @@ extension BridgeJSLink { getterPrinter.write("get \(property.name)() {") getterPrinter.indent { getterPrinter.write(contentsOf: getterThunkBuilder.body) - getterPrinter.write(contentsOf: getterThunkBuilder.cleanupCode) getterPrinter.write(lines: getterThunkBuilder.checkExceptionLines()) if let returnExpr = getterReturnExpr { getterPrinter.write("return \(returnExpr);") @@ -2708,7 +2669,6 @@ extension BridgeJSLink { setterPrinter.write("set \(property.name)(value) {") setterPrinter.indent { setterPrinter.write(contentsOf: setterThunkBuilder.body) - setterPrinter.write(contentsOf: setterThunkBuilder.cleanupCode) setterPrinter.write(lines: setterThunkBuilder.checkExceptionLines()) } setterPrinter.write("},") diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index da21a6e08..20903eef8 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -28,7 +28,6 @@ final class JSGlueVariableScope { static let reservedF32Stack = "f32Stack" static let reservedF64Stack = "f64Stack" static let reservedPointerStack = "ptrStack" - static let reservedTmpStructCleanups = "tmpStructCleanups" static let reservedEnumHelpers = "enumHelpers" static let reservedStructHelpers = "structHelpers" static let reservedSwiftClosureRegistry = "swiftClosureRegistry" @@ -56,7 +55,6 @@ final class JSGlueVariableScope { reservedF32Stack, reservedF64Stack, reservedPointerStack, - reservedTmpStructCleanups, reservedEnumHelpers, reservedStructHelpers, reservedSwiftClosureRegistry, @@ -147,8 +145,6 @@ struct IntrinsicJSFragment: Sendable { var scope: JSGlueVariableScope /// The printer to print the main fragment code. var printer: CodeFragmentPrinter - /// The printer to print the code that is expected to be executed at the end of the caller of the fragment. - var cleanupCode: CodeFragmentPrinter /// Whether the fragment has direct access to the SwiftHeapObject classes. /// If false, the fragment needs to use `_exports[""]` to access the class. var hasDirectAccessToSwiftClass: Bool = true @@ -250,7 +246,7 @@ struct IntrinsicJSFragment: Sendable { static let stringLiftReturn = IntrinsicJSFragment( parameters: [], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let resultLabel = scope.variable("ret") printer.write("const \(resultLabel) = \(JSGlueVariableScope.reservedStorageToReturnString);") printer.write("\(JSGlueVariableScope.reservedStorageToReturnString) = undefined;") @@ -260,7 +256,7 @@ struct IntrinsicJSFragment: Sendable { static let stringLiftParameter = IntrinsicJSFragment( parameters: ["objectId"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let objectId = arguments[0] let objectLabel = scope.variable("\(objectId)Object") // TODO: Implement "take" operation @@ -272,7 +268,7 @@ struct IntrinsicJSFragment: Sendable { static let stringLowerReturn = IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) printer.write( "\(JSGlueVariableScope.reservedStorageToReturnBytes) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(arguments[0]));" ) @@ -289,7 +285,7 @@ struct IntrinsicJSFragment: Sendable { static let jsObjectLiftReturn = IntrinsicJSFragment( parameters: ["retId"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) // TODO: Implement "take" operation let resultLabel = scope.variable("ret") let retId = arguments[0] @@ -301,7 +297,7 @@ struct IntrinsicJSFragment: Sendable { static let jsObjectLiftRetainedObjectId = IntrinsicJSFragment( parameters: ["objectId"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let resultLabel = scope.variable("value") let objectId = arguments[0] printer.write( @@ -446,7 +442,7 @@ struct IntrinsicJSFragment: Sendable { static let jsValueLower = IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let kindVar = scope.variable("\(value)Kind") let payload1Var = scope.variable("\(value)Payload1") @@ -572,7 +568,7 @@ struct IntrinsicJSFragment: Sendable { static let jsValueLift = IntrinsicJSFragment( parameters: [], printCode: { _, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let payload2 = scope.variable("jsValuePayload2") let payload1 = scope.variable("jsValuePayload1") let kind = scope.variable("jsValueKind") @@ -590,7 +586,7 @@ struct IntrinsicJSFragment: Sendable { static let jsValueLiftParameter = IntrinsicJSFragment( parameters: ["kind", "payload1", "payload2"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let resultVar = scope.variable("jsValue") registerJSValueHelpers(scope: scope) printer.write( @@ -635,14 +631,12 @@ struct IntrinsicJSFragment: Sendable { IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (printer, cleanup) = (context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] - let caseIdName = "\(value)CaseId" - let cleanupName = "\(value)Cleanup" + let caseIdName = scope.variable("\(value)CaseId") printer.write( - "const { caseId: \(caseIdName), cleanup: \(cleanupName) } = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lower(\(value));" + "const \(caseIdName) = \(JSGlueVariableScope.reservedEnumHelpers).\(enumBase).lower(\(value));" ) - cleanup.write("if (\(cleanupName)) { \(cleanupName)(); }") return [caseIdName] } ) @@ -806,7 +800,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let isSomeVar = scope.variable("isSome") printer.write("const \(isSomeVar) = \(value) != null;") @@ -814,18 +808,13 @@ struct IntrinsicJSFragment: Sendable { switch wrappedType { case .swiftStruct(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName - let cleanupVar = scope.variable("\(value)Cleanup") - printer.write("let \(cleanupVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let resultVar = scope.variable("structResult") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(base).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(base).lower(\(value));" ) - printer.write("\(cleanupVar) = \(resultVar).cleanup;") } printer.write("}") - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") printer.write("\(JSGlueVariableScope.reservedI32Stack).push(+\(isSomeVar));") return [] case .string, .rawValueEnum(_, .string): @@ -846,65 +835,42 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let caseIdVar = scope.variable("\(value)CaseId") - let cleanupVar = scope.variable("\(value)Cleanup") - printer.write("let \(caseIdVar), \(cleanupVar);") + printer.write("let \(caseIdVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let resultVar = scope.variable("enumResult") printer.write( - "const \(resultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "\(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) - printer.write("\(caseIdVar) = \(resultVar).caseId;") - printer.write("\(cleanupVar) = \(resultVar).cleanup;") } printer.write("}") - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return ["+\(isSomeVar)", "\(isSomeVar) ? \(caseIdVar) : 0"] case .rawValueEnum: // Raw value enums with optional - falls through to handle based on raw type return ["+\(isSomeVar)", "\(isSomeVar) ? \(value) : 0"] case .array(let elementType): - let cleanupArrayVar = scope.variable("\(value)Cleanups") - printer.write("const \(cleanupArrayVar) = [];") printer.write("if (\(isSomeVar)) {") try printer.indent { let arrayLowerFragment = try arrayLower(elementType: elementType) - let arrayCleanup = CodeFragmentPrinter() let _ = try arrayLowerFragment.printCode( [value], - context.with(\.cleanupCode, arrayCleanup) + context ) - if !arrayCleanup.lines.isEmpty { - for line in arrayCleanup.lines { - printer.write("\(cleanupArrayVar).push(() => { \(line) });") - } - } } printer.write("}") - cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") printer.write("\(JSGlueVariableScope.reservedI32Stack).push(+\(isSomeVar));") return [] case .dictionary(let valueType): - let cleanupArrayVar = scope.variable("\(value)Cleanups") - printer.write("const \(cleanupArrayVar) = [];") printer.write("if (\(isSomeVar)) {") try printer.indent { let dictLowerFragment = try dictionaryLower(valueType: valueType) - let dictCleanup = CodeFragmentPrinter() let _ = try dictLowerFragment.printCode( [value], - context.with(\.cleanupCode, dictCleanup) + context ) - if !dictCleanup.lines.isEmpty { - for line in dictCleanup.lines { - printer.write("\(cleanupArrayVar).push(() => { \(line) });") - } - } } printer.write("}") - cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") printer.write("\(JSGlueVariableScope.reservedI32Stack).push(+\(isSomeVar));") return [] default: @@ -1105,7 +1071,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let isSomeVar = scope.variable("isSome") let presenceExpr = kind.presenceCheck(value: value) @@ -1166,16 +1132,10 @@ struct IntrinsicJSFragment: Sendable { printer.write("if (\(isSomeVar)) {") try printer.indent { let arrayLowerFragment = try arrayLower(elementType: elementType) - let arrayCleanup = CodeFragmentPrinter() let _ = try arrayLowerFragment.printCode( [value], - context.with(\.cleanupCode, arrayCleanup) + context ) - if !arrayCleanup.lines.isEmpty { - for line in arrayCleanup.lines { - printer.write(line) - } - } } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) @@ -1214,11 +1174,10 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let fullName): let base = fullName.components(separatedBy: ".").last ?? fullName let caseIdVar = scope.variable("caseId") - let cleanupVar = scope.variable("cleanup") printer.write("if (\(isSomeVar)) {") printer.indent { printer.write( - "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "const \(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) printer.write("return \(caseIdVar);") } @@ -1227,14 +1186,11 @@ struct IntrinsicJSFragment: Sendable { printer.write("return -1;") } printer.write("}") - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") case .dictionary(let valueType): printer.write("if (\(isSomeVar)) {") try 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)) {") try printer.indent { @@ -1243,40 +1199,19 @@ struct IntrinsicJSFragment: Sendable { printer.write("const [\(keyVar), \(valueVar)] = \(entryVar);") let keyFragment = try stackLowerFragment(elementType: .string) - let keyCleanup = CodeFragmentPrinter() let _ = try keyFragment.printCode( [keyVar], - context.with(\.cleanupCode, keyCleanup) + context ) - 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 _ = try valueFragment.printCode( [valueVar], - context.with(\.cleanupCode, valueCleanup) + context ) - if !valueCleanup.lines.isEmpty { - printer.write("\(cleanupArrayVar).push(() => {") - printer.indent { - for line in valueCleanup.lines { - printer.write(line) - } - } - printer.write("});") - } } printer.write("}") scope.emitPushI32Parameter("\(entriesVar).length", printer: printer) - cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) @@ -1594,14 +1529,12 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let caseIdVar = scope.variable("caseId") - let cleanupVar = scope.variable("cleanup") printer.write( - "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "const \(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") printer.write("return \(caseIdVar);") return [] } @@ -1662,15 +1595,10 @@ struct IntrinsicJSFragment: Sendable { for enumCase in enumDefinition.cases { let caseName = enumCase.name.capitalizedFirstLetter let caseScope = scope.makeChildScope() - let caseCleanup = CodeFragmentPrinter() - caseCleanup.indent() let fragment = IntrinsicJSFragment.associatedValuePushPayload(enumCase: enumCase) _ = try fragment.printCode( ["value", enumName, caseName], - context.with(\.scope, caseScope).with(\.printer, lowerPrinter).with( - \.cleanupCode, - caseCleanup - ) + context.with(\.scope, caseScope).with(\.printer, lowerPrinter) ) } @@ -1696,15 +1624,11 @@ struct IntrinsicJSFragment: Sendable { for enumCase in enumDefinition.cases { let caseName = enumCase.name.capitalizedFirstLetter let caseScope = scope.makeChildScope() - let caseCleanup = CodeFragmentPrinter() let fragment = IntrinsicJSFragment.associatedValuePopPayload(enumCase: enumCase) _ = try fragment.printCode( [enumName, caseName], - context.with(\.scope, caseScope).with(\.printer, liftPrinter).with( - \.cleanupCode, - caseCleanup - ) + context.with(\.scope, caseScope).with(\.printer, liftPrinter) ) } @@ -1783,7 +1707,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value", "enumName", "caseName"], printCode: { arguments, context in - let (printer, cleanup) = (context.printer, context.cleanupCode) + let printer = context.printer let enumName = arguments[1] let caseName = arguments[2] @@ -1791,8 +1715,7 @@ struct IntrinsicJSFragment: Sendable { try printer.indent { if enumCase.associatedValues.isEmpty { - printer.write("const cleanup = undefined;") - printer.write("return { caseId: \(enumName).Tag.\(caseName), cleanup };") + printer.write("return \(enumName).Tag.\(caseName);") } else { // Process associated values in reverse order (to match the order they'll be popped) let reversedValues = enumCase.associatedValues.enumerated().reversed() @@ -1806,14 +1729,7 @@ struct IntrinsicJSFragment: Sendable { _ = try fragment.printCode(["value.\(prop)"], context) } - if cleanup.lines.isEmpty { - printer.write("const cleanup = undefined;") - } else { - printer.write("const cleanup = () => {") - printer.write(contentsOf: cleanup) - printer.write("};") - } - printer.write("return { caseId: \(enumName).Tag.\(caseName), cleanup };") + printer.write("return \(enumName).Tag.\(caseName);") } } @@ -1882,7 +1798,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanup) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let isSomeVar = scope.variable("isSome") printer.write("const \(isSomeVar) = \(kind.presenceCheck(value: value));") @@ -1959,19 +1875,14 @@ struct IntrinsicJSFragment: Sendable { } case .swiftStruct(let structName): let structBase = structName.components(separatedBy: ".").last ?? structName - let nestedCleanupVar = scope.variable("nestedCleanup") - printer.write("let \(nestedCleanupVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let structResultVar = scope.variable("structResult") printer.write( - "const \(structResultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" ) - printer.write("\(nestedCleanupVar) = \(structResultVar).cleanup;") } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if (\(nestedCleanupVar)) { \(nestedCleanupVar)(); }") case .swiftHeapObject: printer.write("if (\(isSomeVar)) {") printer.indent { @@ -2001,16 +1912,12 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let enumName): let base = enumName.components(separatedBy: ".").last ?? enumName let caseIdVar = scope.variable("enumCaseId") - let enumCleanupVar = scope.variable("enumCleanup") - printer.write("let \(caseIdVar), \(enumCleanupVar);") + printer.write("let \(caseIdVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let enumResultVar = scope.variable("enumResult") printer.write( - "const \(enumResultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "\(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) - printer.write("\(caseIdVar) = \(enumResultVar).caseId;") - printer.write("\(enumCleanupVar) = \(enumResultVar).cleanup;") scope.emitPushI32Parameter(caseIdVar, printer: printer) } printer.write("} else {") @@ -2019,36 +1926,17 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") 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, - // so capture cleanup into a variable declared at the outer scope. - let arrCleanupVar = scope.variable("arrCleanup") - printer.write("let \(arrCleanupVar);") printer.write("if (\(isSomeVar)) {") try printer.indent { - let localCleanup = CodeFragmentPrinter() let arrFragment = try arrayLower(elementType: elementType) _ = try arrFragment.printCode( [value], - context.with(\.cleanupCode, localCleanup) + context ) - let cleanupLines = localCleanup.lines.filter { - !$0.trimmingCharacters(in: .whitespaces).isEmpty - } - if !cleanupLines.isEmpty { - printer.write("\(arrCleanupVar) = () => {") - printer.indent { - for line in cleanupLines { - printer.write(line) - } - } - printer.write("};") - } } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if (\(arrCleanupVar)) { \(arrCleanupVar)(); }") default: scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) } @@ -2117,13 +2005,11 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let printer = context.printer let value = arguments[0] - let cleanupVar = scope.variable("cleanup") printer.write( - "const { cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(base).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(base).lower(\(value));" ) - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } ) @@ -2133,13 +2019,11 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let printer = context.printer let value = arguments[0] - let cleanupVar = scope.variable("cleanup") printer.write( - "const { cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" ) - cleanupCode.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } ) @@ -2166,33 +2050,20 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["arr"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let arr = arguments[0] - let cleanupArrayVar = scope.variable("arrayCleanups") - printer.write("const \(cleanupArrayVar) = [];") let elemVar = scope.variable("elem") printer.write("for (const \(elemVar) of \(arr)) {") try printer.indent { let elementFragment = try stackLowerFragment(elementType: elementType) - let elementCleanup = CodeFragmentPrinter() let _ = try elementFragment.printCode( [elemVar], - context.with(\.cleanupCode, elementCleanup) + context ) - if !elementCleanup.lines.isEmpty { - printer.write("\(cleanupArrayVar).push(() => {") - printer.indent { - for line in elementCleanup.lines { - printer.write(line) - } - } - printer.write("});") - } } printer.write("}") scope.emitPushI32Parameter("\(arr).length", printer: printer) - cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") return [] } ) @@ -2203,11 +2074,9 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["dict"], printCode: { arguments, context in - let (scope, printer, cleanupCode) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) 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));") @@ -2218,40 +2087,19 @@ struct IntrinsicJSFragment: Sendable { printer.write("const [\(keyVar), \(valueVar)] = \(entryVar);") let keyFragment = try stackLowerFragment(elementType: .string) - let keyCleanup = CodeFragmentPrinter() let _ = try keyFragment.printCode( [keyVar], - context.with(\.cleanupCode, keyCleanup) + context ) - 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 _ = try valueFragment.printCode( [valueVar], - context.with(\.cleanupCode, valueCleanup) + context ) - if !valueCleanup.lines.isEmpty { - printer.write("\(cleanupArrayVar).push(() => {") - printer.indent { - for line in valueCleanup.lines { - printer.write(line) - } - } - printer.write("});") - } } printer.write("}") scope.emitPushI32Parameter("\(entriesVar).length", printer: printer) - cleanupCode.write("for (const cleanup of \(cleanupArrayVar)) { cleanup(); }") return [] } ) @@ -2582,13 +2430,11 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanup) = (context.scope, context.printer, context.cleanupCode) + let printer = context.printer let value = arguments[0] - let cleanupVar = scope.variable("structCleanup") printer.write( - "const { cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(structBase).lower(\(value));" ) - cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } ) @@ -2655,15 +2501,13 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanup) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let caseIdVar = scope.variable("caseId") - let cleanupVar = scope.variable("enumCleanup") printer.write( - "const { caseId: \(caseIdVar), cleanup: \(cleanupVar) } = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "const \(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) scope.emitPushI32Parameter(caseIdVar, printer: printer) - cleanup.write("if (\(cleanupVar)) { \(cleanupVar)(); }") return [] } ) @@ -2772,22 +2616,13 @@ struct IntrinsicJSFragment: Sendable { let presenceExpr = kind.presenceCheck(value: value) printer.write("const \(isSomeVar) = \(presenceExpr) ? 1 : 0;") - // Cleanup is written inside the if block so retained id is in scope - let localCleanupWriter = CodeFragmentPrinter() printer.write("if (\(isSomeVar)) {") try printer.indent { let innerFragment = try stackLowerFragment(elementType: wrappedType) let _ = try innerFragment.printCode( [value], - context.with(\.cleanupCode, localCleanupWriter) + context ) - let localCleanupLines = localCleanupWriter.lines.filter { - !$0.trimmingCharacters(in: .whitespaces).isEmpty - } - if !localCleanupLines.isEmpty { - let localCleanupCode = localCleanupLines.joined(separator: " ") - printer.write("arrayCleanups.push(() => { \(localCleanupCode) });") - } } printer.write("} else {") printer.indent { @@ -2877,8 +2712,6 @@ struct IntrinsicJSFragment: Sendable { let (scope, printer) = (context.scope, context.printer) let lowerPrinter = CodeFragmentPrinter() let lowerScope = scope.makeChildScope() - let lowerCleanup = CodeFragmentPrinter() - lowerCleanup.indent() let instanceProps = structDef.properties.filter { !$0.isStatic } for property in instanceProps { @@ -2886,22 +2719,13 @@ struct IntrinsicJSFragment: Sendable { let fieldValue = "value.\(property.name)" _ = try fragment.printCode( [fieldValue], - context.with(\.scope, lowerScope).with(\.printer, lowerPrinter).with(\.cleanupCode, lowerCleanup) + context.with(\.scope, lowerScope).with(\.printer, lowerPrinter) ) } for line in lowerPrinter.lines { printer.write(line) } - - if !lowerCleanup.lines.isEmpty { - printer.write("const cleanup = () => {") - printer.write(contentsOf: lowerCleanup) - printer.write("};") - printer.write("return { cleanup };") - } else { - printer.write("return { cleanup: undefined };") - } } private static func generateStructLiftCode( @@ -2944,12 +2768,8 @@ struct IntrinsicJSFragment: Sendable { "\(instanceVar).\(method.name) = function(\(paramList)) {" ) try printer.indent { - let methodScope = scope.makeChildScope() - let methodCleanup = CodeFragmentPrinter() - - let structCleanupVar = methodScope.variable("structCleanup") printer.write( - "const { cleanup: \(structCleanupVar) } = \(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(this);" + "\(JSGlueVariableScope.reservedStructHelpers).\(structDef.name).lower(this);" ) var paramForwardings: [String] = [] @@ -2966,10 +2786,6 @@ struct IntrinsicJSFragment: Sendable { printer.write("const ret = \(callExpr);") } - // Cleanup - printer.write("if (\(structCleanupVar)) { \(structCleanupVar)(); }") - printer.write(contentsOf: methodCleanup) - // Lift return value if needed if method.returnType != .void { let liftFragment = try IntrinsicJSFragment.liftReturn(type: method.returnType) @@ -3021,7 +2837,7 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer, cleanup) = (context.scope, context.printer, context.cleanupCode) + let (scope, printer) = (context.scope, context.printer) let value = arguments[0] let isSomeVar = scope.variable("isSome") printer.write("const \(isSomeVar) = \(kind.presenceCheck(value: value));") @@ -3116,19 +2932,14 @@ struct IntrinsicJSFragment: Sendable { scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) return [] } else if case .swiftStruct(let structName) = wrappedType { - let nestedCleanupVar = scope.variable("nestedCleanup") - printer.write("let \(nestedCleanupVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let structResultVar = scope.variable("structResult") printer.write( - "const \(structResultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(structName).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(structName).lower(\(value));" ) - printer.write("\(nestedCleanupVar) = \(structResultVar).cleanup;") } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if (\(nestedCleanupVar)) { \(nestedCleanupVar)(); }") return [] } else if case .string = wrappedType { let idVar = scope.variable("id") @@ -3212,16 +3023,12 @@ struct IntrinsicJSFragment: Sendable { case .associatedValueEnum(let enumName): let base = enumName.components(separatedBy: ".").last ?? enumName let caseIdVar = scope.variable("enumCaseId") - let enumCleanupVar = scope.variable("enumCleanup") - printer.write("let \(caseIdVar), \(enumCleanupVar);") + printer.write("let \(caseIdVar);") printer.write("if (\(isSomeVar)) {") printer.indent { - let enumResultVar = scope.variable("enumResult") printer.write( - "const \(enumResultVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" + "\(caseIdVar) = \(JSGlueVariableScope.reservedEnumHelpers).\(base).lower(\(value));" ) - printer.write("\(caseIdVar) = \(enumResultVar).caseId;") - printer.write("\(enumCleanupVar) = \(enumResultVar).cleanup;") scope.emitPushI32Parameter(caseIdVar, printer: printer) } printer.write("} else {") @@ -3230,7 +3037,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if (\(enumCleanupVar)) { \(enumCleanupVar)(); }") default: let wrappedFragment = try structFieldLowerFragment( field: ExportedProperty( @@ -3242,10 +3048,9 @@ struct IntrinsicJSFragment: Sendable { allStructs: allStructs ) let guardedPrinter = CodeFragmentPrinter() - let guardedCleanup = CodeFragmentPrinter() _ = try wrappedFragment.printCode( [value], - context.with(\.printer, guardedPrinter).with(\.cleanupCode, guardedCleanup) + context.with(\.printer, guardedPrinter) ) var loweredLines = guardedPrinter.lines var hoistedCleanupVar: String? @@ -3267,13 +3072,6 @@ struct IntrinsicJSFragment: Sendable { for line in loweredLines { printer.write(line) } - if !guardedCleanup.lines.isEmpty { - cleanup.write("if (\(isSomeVar)) {") - cleanup.indent { - cleanup.write(contentsOf: guardedCleanup) - } - cleanup.write("}") - } } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) @@ -3286,13 +3084,11 @@ struct IntrinsicJSFragment: Sendable { return IntrinsicJSFragment( parameters: ["value"], printCode: { arguments, context in - let (scope, printer) = (context.scope, context.printer) + let printer = context.printer let value = arguments[0] - let structResultVar = scope.variable("structResult") printer.write( - "const \(structResultVar) = \(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lower(\(value));" + "\(JSGlueVariableScope.reservedStructHelpers).\(nestedName).lower(\(value));" ) - context.cleanupCode.write("if (\(structResultVar).cleanup) { \(structResultVar).cleanup(); }") return [] } ) diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift index 3141139ca..12edb29e3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ArrayTypes.swift @@ -57,10 +57,7 @@ extension Point: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -73,9 +70,9 @@ extension Point: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift index e8f367f1c..c905c4239 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/DefaultParameters.swift @@ -52,10 +52,7 @@ extension Config: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Config(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Config(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -68,9 +65,9 @@ extension Config: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Config") -fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -95,10 +92,7 @@ extension MathOperations: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_MathOperations(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_MathOperations(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -111,9 +105,9 @@ extension MathOperations: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_MathOperations") -fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift index 3d23c6bff..588fb1cbc 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/EnumAssociatedValue.swift @@ -413,10 +413,7 @@ extension Point: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -429,9 +426,9 @@ extension Point: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift index 7fcc4d3c7..c142fbd04 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/ImportedTypeInExportedInterface.swift @@ -15,10 +15,7 @@ extension FooContainer: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -31,9 +28,9 @@ extension FooContainer: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_FooContainer") -fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift index fb78c3fd0..29abcebca 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStruct.swift @@ -28,10 +28,7 @@ extension DataPoint: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_DataPoint(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_DataPoint(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -44,9 +41,9 @@ extension DataPoint: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_DataPoint") -fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -90,10 +87,7 @@ extension Address: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -106,9 +100,9 @@ extension Address: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Address") -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -143,10 +137,7 @@ extension Person: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Person(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -159,9 +150,9 @@ extension Person: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Person") -fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Person(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -188,10 +179,7 @@ extension Session: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Session(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Session(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -204,9 +192,9 @@ extension Session: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Session") -fileprivate func _bjs_struct_lower_Session(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Session(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Session(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Session(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -239,10 +227,7 @@ extension Measurement: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Measurement(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Measurement(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -255,9 +240,9 @@ extension Measurement: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Measurement") -fileprivate func _bjs_struct_lower_Measurement(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Measurement(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Measurement(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Measurement(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -280,10 +265,7 @@ extension ConfigStruct: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_ConfigStruct(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_ConfigStruct(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -296,9 +278,9 @@ extension ConfigStruct: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ConfigStruct") -fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -404,10 +386,7 @@ extension Container: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Container(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Container(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -420,9 +399,9 @@ extension Container: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Container") -fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Container(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift index 089912afe..29386e65f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftStructImports.swift @@ -11,10 +11,7 @@ extension Point: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -27,9 +24,9 @@ extension Point: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift index a4f372e9b..9385c0621 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/UnsafePointer.swift @@ -17,10 +17,7 @@ extension PointerFields: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PointerFields(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PointerFields(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -33,9 +30,9 @@ extension PointerFields: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PointerFields") -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 7db995321..e7bdf975b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -36,7 +36,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -47,7 +46,6 @@ export async function createInstantiator(options, swift) { lower: (value) => { f64Stack.push(value.x); f64Stack.push(value.y); - return { cleanup: undefined }; }, lift: () => { const f64 = f64Stack.pop(); @@ -122,22 +120,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_Point"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Point.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Point.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Point"] = function() { const value = structHelpers.Point.lift(); @@ -274,7 +258,6 @@ export async function createInstantiator(options, swift) { TestModule["bjs_importGetNumbers"] = function bjs_importGetNumbers() { try { let ret = imports.importGetNumbers(); - const arrayCleanups = []; for (const elem of ret) { f64Stack.push(elem); } @@ -293,7 +276,6 @@ export async function createInstantiator(options, swift) { } arrayResult.reverse(); let ret = imports.importTransformNumbers(arrayResult); - const arrayCleanups = []; for (const elem of ret) { f64Stack.push(elem); } @@ -312,7 +294,6 @@ export async function createInstantiator(options, swift) { } arrayResult.reverse(); let ret = imports.importProcessStrings(arrayResult); - const arrayCleanups = []; for (const elem of ret) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); @@ -334,7 +315,6 @@ export async function createInstantiator(options, swift) { } arrayResult.reverse(); let ret = imports.importProcessBooleans(arrayResult); - const arrayCleanups = []; for (const elem of ret) { i32Stack.push(elem ? 1 : 0); } @@ -396,7 +376,6 @@ export async function createInstantiator(options, swift) { const exports = { Item, processIntArray: function bjs_processIntArray(values) { - const arrayCleanups = []; for (const elem of values) { i32Stack.push((elem | 0)); } @@ -409,11 +388,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(int); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processStringArray: function bjs_processStringArray(values) { - const arrayCleanups = []; for (const elem of values) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); @@ -429,11 +406,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(string); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processDoubleArray: function bjs_processDoubleArray(values) { - const arrayCleanups = []; for (const elem of values) { f64Stack.push(elem); } @@ -446,11 +421,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(f64); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processBoolArray: function bjs_processBoolArray(values) { - const arrayCleanups = []; for (const elem of values) { i32Stack.push(elem ? 1 : 0); } @@ -463,16 +436,11 @@ export async function createInstantiator(options, swift) { arrayResult.push(bool); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processPointArray: function bjs_processPointArray(points) { - const arrayCleanups = []; for (const elem of points) { - const { cleanup: structCleanup } = structHelpers.Point.lower(elem); - arrayCleanups.push(() => { - if (structCleanup) { structCleanup(); } - }); + structHelpers.Point.lower(elem); } i32Stack.push(points.length); instance.exports.bjs_processPointArray(); @@ -483,11 +451,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(struct); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processDirectionArray: function bjs_processDirectionArray(directions) { - const arrayCleanups = []; for (const elem of directions) { i32Stack.push((elem | 0)); } @@ -500,11 +466,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(caseId); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processStatusArray: function bjs_processStatusArray(statuses) { - const arrayCleanups = []; for (const elem of statuses) { i32Stack.push((elem | 0)); } @@ -517,37 +481,28 @@ export async function createInstantiator(options, swift) { arrayResult.push(rawValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, sumIntArray: function bjs_sumIntArray(values) { - const arrayCleanups = []; for (const elem of values) { i32Stack.push((elem | 0)); } i32Stack.push(values.length); const ret = instance.exports.bjs_sumIntArray(); - for (const cleanup of arrayCleanups) { cleanup(); } return ret; }, findFirstPoint: function bjs_findFirstPoint(points, matching) { - const arrayCleanups = []; for (const elem of points) { - const { cleanup: structCleanup } = structHelpers.Point.lower(elem); - arrayCleanups.push(() => { - if (structCleanup) { structCleanup(); } - }); + structHelpers.Point.lower(elem); } i32Stack.push(points.length); const matchingBytes = textEncoder.encode(matching); const matchingId = swift.memory.retain(matchingBytes); instance.exports.bjs_findFirstPoint(matchingId, matchingBytes.length); const structValue = structHelpers.Point.lift(); - for (const cleanup of arrayCleanups) { cleanup(); } return structValue; }, processUnsafeRawPointerArray: function bjs_processUnsafeRawPointerArray(values) { - const arrayCleanups = []; for (const elem of values) { ptrStack.push((elem | 0)); } @@ -560,11 +515,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(pointer); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processUnsafeMutableRawPointerArray: function bjs_processUnsafeMutableRawPointerArray(values) { - const arrayCleanups = []; for (const elem of values) { ptrStack.push((elem | 0)); } @@ -577,11 +530,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(pointer); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOpaquePointerArray: function bjs_processOpaquePointerArray(values) { - const arrayCleanups = []; for (const elem of values) { ptrStack.push((elem | 0)); } @@ -594,11 +545,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(pointer); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalIntArray: function bjs_processOptionalIntArray(values) { - const arrayCleanups = []; for (const elem of values) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -624,11 +573,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalStringArray: function bjs_processOptionalStringArray(values) { - const arrayCleanups = []; for (const elem of values) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -658,19 +605,15 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalArray: function bjs_processOptionalArray(values) { const isSome = values != null; - const valuesCleanups = []; if (isSome) { - const arrayCleanups = []; for (const elem of values) { i32Stack.push((elem | 0)); } i32Stack.push(values.length); - valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); } i32Stack.push(+isSome); instance.exports.bjs_processOptionalArray(); @@ -688,16 +631,13 @@ export async function createInstantiator(options, swift) { } else { optResult = null; } - for (const cleanup of valuesCleanups) { cleanup(); } return optResult; }, processOptionalPointArray: function bjs_processOptionalPointArray(points) { - const arrayCleanups = []; for (const elem of points) { const isSome = elem != null ? 1 : 0; if (isSome) { - const { cleanup: structCleanup } = structHelpers.Point.lower(elem); - arrayCleanups.push(() => { if (structCleanup) { structCleanup(); } }); + structHelpers.Point.lower(elem); } else { } i32Stack.push(isSome); @@ -718,11 +658,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalDirectionArray: function bjs_processOptionalDirectionArray(directions) { - const arrayCleanups = []; for (const elem of directions) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -748,11 +686,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalStatusArray: function bjs_processOptionalStatusArray(statuses) { - const arrayCleanups = []; for (const elem of statuses) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -778,20 +714,14 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processNestedIntArray: function bjs_processNestedIntArray(values) { - const arrayCleanups = []; for (const elem of values) { - const arrayCleanups1 = []; for (const elem1 of elem) { i32Stack.push((elem1 | 0)); } i32Stack.push(elem.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(values.length); instance.exports.bjs_processNestedIntArray(); @@ -808,13 +738,10 @@ export async function createInstantiator(options, swift) { arrayResult.push(arrayResult1); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processNestedStringArray: function bjs_processNestedStringArray(values) { - const arrayCleanups = []; for (const elem of values) { - const arrayCleanups1 = []; for (const elem1 of elem) { const bytes = textEncoder.encode(elem1); const id = swift.memory.retain(bytes); @@ -822,9 +749,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); } i32Stack.push(elem.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(values.length); instance.exports.bjs_processNestedStringArray(); @@ -841,23 +765,14 @@ export async function createInstantiator(options, swift) { arrayResult.push(arrayResult1); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processNestedPointArray: function bjs_processNestedPointArray(points) { - const arrayCleanups = []; for (const elem of points) { - const arrayCleanups1 = []; for (const elem1 of elem) { - const { cleanup: structCleanup } = structHelpers.Point.lower(elem1); - arrayCleanups1.push(() => { - if (structCleanup) { structCleanup(); } - }); + structHelpers.Point.lower(elem1); } i32Stack.push(elem.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(points.length); instance.exports.bjs_processNestedPointArray(); @@ -874,11 +789,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(arrayResult1); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processItemArray: function bjs_processItemArray(items) { - const arrayCleanups = []; for (const elem of items) { ptrStack.push(elem.pointer); } @@ -892,20 +805,14 @@ export async function createInstantiator(options, swift) { arrayResult.push(obj); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processNestedItemArray: function bjs_processNestedItemArray(items) { - const arrayCleanups = []; for (const elem of items) { - const arrayCleanups1 = []; for (const elem1 of elem) { ptrStack.push(elem1.pointer); } i32Stack.push(elem.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(items.length); instance.exports.bjs_processNestedItemArray(); @@ -923,11 +830,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(arrayResult1); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processJSObjectArray: function bjs_processJSObjectArray(objects) { - const arrayCleanups = []; for (const elem of objects) { const objId = swift.memory.retain(elem); i32Stack.push(objId); @@ -943,11 +848,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(obj); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalJSObjectArray: function bjs_processOptionalJSObjectArray(objects) { - const arrayCleanups = []; for (const elem of objects) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -976,21 +879,15 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processNestedJSObjectArray: function bjs_processNestedJSObjectArray(objects) { - const arrayCleanups = []; for (const elem of objects) { - const arrayCleanups1 = []; for (const elem1 of elem) { const objId = swift.memory.retain(elem1); i32Stack.push(objId); } i32Stack.push(elem.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(objects.length); instance.exports.bjs_processNestedJSObjectArray(); @@ -1009,7 +906,6 @@ export async function createInstantiator(options, swift) { arrayResult.push(arrayResult1); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, Direction: DirectionValues, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index bd57f0fd4..6e7e810ca 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index a89b07fc3..0538b8078 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -29,7 +29,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -44,7 +43,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.value | 0)); i32Stack.push(value.enabled ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const bool = i32Stack.pop() !== 0; @@ -58,21 +56,18 @@ export async function createInstantiator(options, swift) { return () => ({ lower: (value) => { f64Stack.push(value.baseValue); - return { cleanup: undefined }; }, lift: () => { const f64 = f64Stack.pop(); const instance1 = { baseValue: f64 }; instance1.add = function(a, b = 10.0) { - const { cleanup: structCleanup } = structHelpers.MathOperations.lower(this); + structHelpers.MathOperations.lower(this); const ret = instance.exports.bjs_MathOperations_add(a, b); - if (structCleanup) { structCleanup(); } return ret; }.bind(instance1); instance1.multiply = function(a, b) { - const { cleanup: structCleanup } = structHelpers.MathOperations.lower(this); + structHelpers.MathOperations.lower(this); const ret = instance.exports.bjs_MathOperations_multiply(a, b); - if (structCleanup) { structCleanup(); } return ret; }.bind(instance1); return instance1; @@ -144,33 +139,15 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_Config"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Config.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Config.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Config"] = function() { const value = structHelpers.Config.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_MathOperations"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.MathOperations.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.MathOperations.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_MathOperations"] = function() { const value = structHelpers.MathOperations.lift(); @@ -502,10 +479,8 @@ export async function createInstantiator(options, swift) { }, testOptionalStructDefault: function bjs_testOptionalStructDefault(point = null) { const isSome = point != null; - let pointCleanup; if (isSome) { - const structResult = structHelpers.Config.lower(point); - pointCleanup = structResult.cleanup; + structHelpers.Config.lower(point); } i32Stack.push(+isSome); instance.exports.bjs_testOptionalStructDefault(); @@ -516,15 +491,12 @@ export async function createInstantiator(options, swift) { } else { optResult = null; } - if (pointCleanup) { pointCleanup(); } return optResult; }, testOptionalStructWithValueDefault: function bjs_testOptionalStructWithValueDefault(point = { name: "default", value: 42, enabled: true }) { const isSome = point != null; - let pointCleanup; if (isSome) { - const structResult = structHelpers.Config.lower(point); - pointCleanup = structResult.cleanup; + structHelpers.Config.lower(point); } i32Stack.push(+isSome); instance.exports.bjs_testOptionalStructWithValueDefault(); @@ -535,11 +507,9 @@ export async function createInstantiator(options, swift) { } else { optResult = null; } - if (pointCleanup) { pointCleanup(); } return optResult; }, testIntArrayDefault: function bjs_testIntArrayDefault(values = [1, 2, 3]) { - const arrayCleanups = []; for (const elem of values) { i32Stack.push((elem | 0)); } @@ -552,11 +522,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(int); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, testStringArrayDefault: function bjs_testStringArrayDefault(names = ["a", "b", "c"]) { - const arrayCleanups = []; for (const elem of names) { const bytes = textEncoder.encode(elem); const id = swift.memory.retain(bytes); @@ -572,11 +540,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(string); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, testDoubleArrayDefault: function bjs_testDoubleArrayDefault(values = [1.5, 2.5, 3.5]) { - const arrayCleanups = []; for (const elem of values) { f64Stack.push(elem); } @@ -589,11 +555,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(f64); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, testBoolArrayDefault: function bjs_testBoolArrayDefault(flags = [true, false, true]) { - const arrayCleanups = []; for (const elem of flags) { i32Stack.push(elem ? 1 : 0); } @@ -606,11 +570,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(bool); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, testEmptyArrayDefault: function bjs_testEmptyArrayDefault(items = []) { - const arrayCleanups = []; for (const elem of items) { i32Stack.push((elem | 0)); } @@ -623,13 +585,11 @@ export async function createInstantiator(options, swift) { arrayResult.push(int); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, testMixedWithArrayDefault: function bjs_testMixedWithArrayDefault(name = "test", values = [10, 20, 30], enabled = true) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); - const arrayCleanups = []; for (const elem of values) { i32Stack.push((elem | 0)); } @@ -637,7 +597,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testMixedWithArrayDefault(nameId, nameBytes.length, enabled); const ret = tmpRetString; tmpRetString = undefined; - for (const cleanup of arrayCleanups) { cleanup(); } return ret; }, Status: StatusValues, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index d42fd4b2b..efbd9b09e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -215,7 +204,6 @@ export async function createInstantiator(options, swift) { dictResult[string] = f64; } let ret = imports.importMirrorDictionary(dictResult); - const arrayCleanups = []; const entries = Object.entries(ret); for (const entry of entries) { const [key, value] = entry; @@ -280,7 +268,6 @@ export async function createInstantiator(options, swift) { const exports = { Box, mirrorDictionary: function bjs_mirrorDictionary(values) { - const arrayCleanups = []; const entries = Object.entries(values); for (const entry of entries) { const [key, value] = entry; @@ -299,14 +286,11 @@ export async function createInstantiator(options, swift) { const string = strStack.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; @@ -320,7 +304,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(id1); } i32Stack.push(entries.length); - valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); } i32Stack.push(+isSome); instance.exports.bjs_optionalDictionary(); @@ -338,11 +321,9 @@ export async function createInstantiator(options, swift) { } 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; @@ -350,14 +331,10 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const arrayCleanups1 = []; for (const elem of value) { i32Stack.push((elem | 0)); } i32Stack.push(value.length); - arrayCleanups.push(() => { - for (const cleanup of arrayCleanups1) { cleanup(); } - }); } i32Stack.push(entries.length); instance.exports.bjs_nestedDictionary(); @@ -374,11 +351,9 @@ export async function createInstantiator(options, swift) { const string = strStack.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; @@ -398,11 +373,9 @@ export async function createInstantiator(options, swift) { const string = strStack.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; @@ -435,7 +408,6 @@ export async function createInstantiator(options, swift) { const string = strStack.pop(); dictResult[string] = optValue; } - for (const cleanup of arrayCleanups) { cleanup(); } return dictResult; }, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 2d2c6924b..43cc9f964 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -104,7 +104,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -115,7 +114,6 @@ export async function createInstantiator(options, swift) { lower: (value) => { f64Stack.push(value.x); f64Stack.push(value.y); - return { cleanup: undefined }; }, lift: () => { const f64 = f64Stack.pop(); @@ -134,32 +132,26 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Success, cleanup }; + return APIResultValues.Tag.Success; } case APIResultValues.Tag.Failure: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; + return APIResultValues.Tag.Failure; } case APIResultValues.Tag.Flag: { i32Stack.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Flag, cleanup }; + return APIResultValues.Tag.Flag; } case APIResultValues.Tag.Rate: { f32Stack.push(Math.fround(value.param0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Rate, cleanup }; + return APIResultValues.Tag.Rate; } case APIResultValues.Tag.Precise: { f64Stack.push(value.param0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Precise, cleanup }; + return APIResultValues.Tag.Precise; } case APIResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Info, cleanup }; + return APIResultValues.Tag.Info; } default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } @@ -203,8 +195,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Success, cleanup }; + return ComplexResultValues.Tag.Success; } case ComplexResultValues.Tag.Error: { i32Stack.push((value.param1 | 0)); @@ -212,8 +203,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Error, cleanup }; + return ComplexResultValues.Tag.Error; } case ComplexResultValues.Tag.Status: { const bytes = textEncoder.encode(value.param2); @@ -222,15 +212,13 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.param1 | 0)); i32Stack.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Status, cleanup }; + return ComplexResultValues.Tag.Status; } case ComplexResultValues.Tag.Coordinates: { f64Stack.push(value.param2); f64Stack.push(value.param1); f64Stack.push(value.param0); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Coordinates, cleanup }; + return ComplexResultValues.Tag.Coordinates; } case ComplexResultValues.Tag.Comprehensive: { const bytes = textEncoder.encode(value.param8); @@ -251,12 +239,10 @@ export async function createInstantiator(options, swift) { i32Stack.push((value.param2 | 0)); i32Stack.push(value.param1 ? 1 : 0); i32Stack.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Comprehensive, cleanup }; + return ComplexResultValues.Tag.Comprehensive; } case ComplexResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: ComplexResultValues.Tag.Info, cleanup }; + return ComplexResultValues.Tag.Info; } default: throw new Error("Unknown ComplexResultValues tag: " + String(enumTag)); } @@ -313,8 +299,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Success, cleanup }; + return ResultValues.Tag.Success; } case ResultValues.Tag.Failure: { i32Stack.push((value.param1 | 0)); @@ -322,8 +307,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Failure, cleanup }; + return ResultValues.Tag.Failure; } case ResultValues.Tag.Status: { const bytes = textEncoder.encode(value.param2); @@ -332,8 +316,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.param1 | 0)); i32Stack.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Status, cleanup }; + return ResultValues.Tag.Status; } default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); } @@ -371,8 +354,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: NetworkingResultValues.Tag.Success, cleanup }; + return NetworkingResultValues.Tag.Success; } case NetworkingResultValues.Tag.Failure: { i32Stack.push((value.param1 | 0)); @@ -380,8 +362,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: NetworkingResultValues.Tag.Failure, cleanup }; + return NetworkingResultValues.Tag.Failure; } default: throw new Error("Unknown NetworkingResultValues tag: " + String(enumTag)); } @@ -421,8 +402,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = undefined; - return { caseId: APIOptionalResultValues.Tag.Success, cleanup }; + return APIOptionalResultValues.Tag.Success; } case APIOptionalResultValues.Tag.Failure: { const isSome = value.param1 != null; @@ -431,8 +411,7 @@ export async function createInstantiator(options, swift) { const isSome1 = value.param0 != null; i32Stack.push(isSome1 ? (value.param0 | 0) : 0); i32Stack.push(isSome1 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIOptionalResultValues.Tag.Failure, cleanup }; + return APIOptionalResultValues.Tag.Failure; } case APIOptionalResultValues.Tag.Status: { const isSome = value.param2 != null; @@ -453,8 +432,7 @@ export async function createInstantiator(options, swift) { const isSome2 = value.param0 != null; i32Stack.push(isSome2 ? (value.param0 ? 1 : 0) : 0); i32Stack.push(isSome2 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIOptionalResultValues.Tag.Status, cleanup }; + return APIOptionalResultValues.Tag.Status; } default: throw new Error("Unknown APIOptionalResultValues tag: " + String(enumTag)); } @@ -531,31 +509,26 @@ export async function createInstantiator(options, swift) { switch (enumTag) { case TypedPayloadResultValues.Tag.Precision: { f32Stack.push(Math.fround(value.param0)); - const cleanup = undefined; - return { caseId: TypedPayloadResultValues.Tag.Precision, cleanup }; + return TypedPayloadResultValues.Tag.Precision; } case TypedPayloadResultValues.Tag.Direction: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: TypedPayloadResultValues.Tag.Direction, cleanup }; + return TypedPayloadResultValues.Tag.Direction; } case TypedPayloadResultValues.Tag.OptPrecision: { const isSome = value.param0 != null; f32Stack.push(isSome ? Math.fround(value.param0) : 0.0); i32Stack.push(isSome ? 1 : 0); - const cleanup = undefined; - return { caseId: TypedPayloadResultValues.Tag.OptPrecision, cleanup }; + return TypedPayloadResultValues.Tag.OptPrecision; } case TypedPayloadResultValues.Tag.OptDirection: { const isSome = value.param0 != null; i32Stack.push(isSome ? (value.param0 | 0) : 0); i32Stack.push(isSome ? 1 : 0); - const cleanup = undefined; - return { caseId: TypedPayloadResultValues.Tag.OptDirection, cleanup }; + return TypedPayloadResultValues.Tag.OptDirection; } case TypedPayloadResultValues.Tag.Empty: { - const cleanup = undefined; - return { caseId: TypedPayloadResultValues.Tag.Empty, cleanup }; + return TypedPayloadResultValues.Tag.Empty; } default: throw new Error("Unknown TypedPayloadResultValues tag: " + String(enumTag)); } @@ -605,45 +578,32 @@ export async function createInstantiator(options, swift) { const enumTag = value.tag; switch (enumTag) { case AllTypesResultValues.Tag.StructPayload: { - const { cleanup: structCleanup } = structHelpers.Point.lower(value.param0); - const cleanup = () => { - if (structCleanup) { structCleanup(); } - }; - return { caseId: AllTypesResultValues.Tag.StructPayload, cleanup }; + structHelpers.Point.lower(value.param0); + return AllTypesResultValues.Tag.StructPayload; } case AllTypesResultValues.Tag.ClassPayload: { ptrStack.push(value.param0.pointer); - const cleanup = undefined; - return { caseId: AllTypesResultValues.Tag.ClassPayload, cleanup }; + return AllTypesResultValues.Tag.ClassPayload; } case AllTypesResultValues.Tag.JsObjectPayload: { const objId = swift.memory.retain(value.param0); i32Stack.push(objId); - const cleanup = undefined; - return { caseId: AllTypesResultValues.Tag.JsObjectPayload, cleanup }; + return AllTypesResultValues.Tag.JsObjectPayload; } case AllTypesResultValues.Tag.NestedEnum: { - const { caseId: caseId, cleanup: enumCleanup } = enumHelpers.APIResult.lower(value.param0); + const caseId = enumHelpers.APIResult.lower(value.param0); i32Stack.push(caseId); - const cleanup = () => { - if (enumCleanup) { enumCleanup(); } - }; - return { caseId: AllTypesResultValues.Tag.NestedEnum, cleanup }; + return AllTypesResultValues.Tag.NestedEnum; } case AllTypesResultValues.Tag.ArrayPayload: { - const arrayCleanups = []; for (const elem of value.param0) { i32Stack.push((elem | 0)); } i32Stack.push(value.param0.length); - const cleanup = () => { - for (const cleanup of arrayCleanups) { cleanup(); } - }; - return { caseId: AllTypesResultValues.Tag.ArrayPayload, cleanup }; + return AllTypesResultValues.Tag.ArrayPayload; } case AllTypesResultValues.Tag.Empty: { - const cleanup = undefined; - return { caseId: AllTypesResultValues.Tag.Empty, cleanup }; + return AllTypesResultValues.Tag.Empty; } default: throw new Error("Unknown AllTypesResultValues tag: " + String(enumTag)); } @@ -693,16 +653,11 @@ export async function createInstantiator(options, swift) { switch (enumTag) { case OptionalAllTypesResultValues.Tag.OptStruct: { const isSome = value.param0 != null; - let nestedCleanup; if (isSome) { - const structResult = structHelpers.Point.lower(value.param0); - nestedCleanup = structResult.cleanup; + structHelpers.Point.lower(value.param0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if (nestedCleanup) { nestedCleanup(); } - }; - return { caseId: OptionalAllTypesResultValues.Tag.OptStruct, cleanup }; + return OptionalAllTypesResultValues.Tag.OptStruct; } case OptionalAllTypesResultValues.Tag.OptClass: { const isSome = value.param0 != null; @@ -712,8 +667,7 @@ export async function createInstantiator(options, swift) { ptrStack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = undefined; - return { caseId: OptionalAllTypesResultValues.Tag.OptClass, cleanup }; + return OptionalAllTypesResultValues.Tag.OptClass; } case OptionalAllTypesResultValues.Tag.OptJSObject: { const isSome = value.param0 != null; @@ -726,48 +680,33 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = undefined; - return { caseId: OptionalAllTypesResultValues.Tag.OptJSObject, cleanup }; + return OptionalAllTypesResultValues.Tag.OptJSObject; } case OptionalAllTypesResultValues.Tag.OptNestedEnum: { const isSome = value.param0 != null; - let enumCaseId, enumCleanup; + let enumCaseId; if (isSome) { - const enumResult = enumHelpers.APIResult.lower(value.param0); - enumCaseId = enumResult.caseId; - enumCleanup = enumResult.cleanup; + enumCaseId = enumHelpers.APIResult.lower(value.param0); i32Stack.push(enumCaseId); } else { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if (enumCleanup) { enumCleanup(); } - }; - return { caseId: OptionalAllTypesResultValues.Tag.OptNestedEnum, cleanup }; + return OptionalAllTypesResultValues.Tag.OptNestedEnum; } case OptionalAllTypesResultValues.Tag.OptArray: { const isSome = value.param0 != null; - let arrCleanup; if (isSome) { - const arrayCleanups = []; for (const elem of value.param0) { i32Stack.push((elem | 0)); } i32Stack.push(value.param0.length); - arrCleanup = () => { - for (const cleanup of arrayCleanups) { cleanup(); } - }; } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if (arrCleanup) { arrCleanup(); } - }; - return { caseId: OptionalAllTypesResultValues.Tag.OptArray, cleanup }; + return OptionalAllTypesResultValues.Tag.OptArray; } case OptionalAllTypesResultValues.Tag.Empty: { - const cleanup = undefined; - return { caseId: OptionalAllTypesResultValues.Tag.Empty, cleanup }; + return OptionalAllTypesResultValues.Tag.Empty; } default: throw new Error("Unknown OptionalAllTypesResultValues tag: " + String(enumTag)); } @@ -910,22 +849,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_Point"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Point.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Point.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Point"] = function() { const value = structHelpers.Point.lift(); @@ -1107,9 +1032,8 @@ export async function createInstantiator(options, swift) { const exports = { User, handle: function bjs_handle(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); + const resultCaseId = enumHelpers.APIResult.lower(result); instance.exports.bjs_handle(resultCaseId); - if (resultCleanup) { resultCleanup(); } }, getResult: function bjs_getResult() { instance.exports.bjs_getResult(); @@ -1117,19 +1041,16 @@ export async function createInstantiator(options, swift) { return ret; }, roundtripAPIResult: function bjs_roundtripAPIResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.APIResult.lower(result); + const resultCaseId = enumHelpers.APIResult.lower(result); instance.exports.bjs_roundtripAPIResult(resultCaseId); const ret = enumHelpers.APIResult.lift(i32Stack.pop()); - if (resultCleanup) { resultCleanup(); } return ret; }, roundTripOptionalAPIResult: function bjs_roundTripOptionalAPIResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.APIResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.APIResult.lower(result); } instance.exports.bjs_roundTripOptionalAPIResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1140,13 +1061,11 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.APIResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, handleComplex: function bjs_handleComplex(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); + const resultCaseId = enumHelpers.ComplexResult.lower(result); instance.exports.bjs_handleComplex(resultCaseId); - if (resultCleanup) { resultCleanup(); } }, getComplexResult: function bjs_getComplexResult() { instance.exports.bjs_getComplexResult(); @@ -1154,19 +1073,16 @@ export async function createInstantiator(options, swift) { return ret; }, roundtripComplexResult: function bjs_roundtripComplexResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.ComplexResult.lower(result); + const resultCaseId = enumHelpers.ComplexResult.lower(result); instance.exports.bjs_roundtripComplexResult(resultCaseId); const ret = enumHelpers.ComplexResult.lift(i32Stack.pop()); - if (resultCleanup) { resultCleanup(); } return ret; }, roundTripOptionalComplexResult: function bjs_roundTripOptionalComplexResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.ComplexResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.ComplexResult.lower(result); } instance.exports.bjs_roundTripOptionalComplexResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1177,16 +1093,13 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.ComplexResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, roundTripOptionalUtilitiesResult: function bjs_roundTripOptionalUtilitiesResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.Result.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.Result.lower(result); } instance.exports.bjs_roundTripOptionalUtilitiesResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1197,16 +1110,13 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.Result.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, roundTripOptionalNetworkingResult: function bjs_roundTripOptionalNetworkingResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.NetworkingResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.NetworkingResult.lower(result); } instance.exports.bjs_roundTripOptionalNetworkingResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1217,16 +1127,13 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.NetworkingResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, roundTripOptionalAPIOptionalResult: function bjs_roundTripOptionalAPIOptionalResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.APIOptionalResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.APIOptionalResult.lower(result); } instance.exports.bjs_roundTripOptionalAPIOptionalResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1237,23 +1144,18 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.APIOptionalResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, compareAPIResults: function bjs_compareAPIResults(result1, result2) { const isSome = result1 != null; - let result1CaseId, result1Cleanup; + let result1CaseId; if (isSome) { - const enumResult = enumHelpers.APIOptionalResult.lower(result1); - result1CaseId = enumResult.caseId; - result1Cleanup = enumResult.cleanup; + result1CaseId = enumHelpers.APIOptionalResult.lower(result1); } const isSome1 = result2 != null; - let result2CaseId, result2Cleanup; + let result2CaseId; if (isSome1) { - const enumResult1 = enumHelpers.APIOptionalResult.lower(result2); - result2CaseId = enumResult1.caseId; - result2Cleanup = enumResult1.cleanup; + result2CaseId = enumHelpers.APIOptionalResult.lower(result2); } instance.exports.bjs_compareAPIResults(+isSome, isSome ? result1CaseId : 0, +isSome1, isSome1 ? result2CaseId : 0); const tag = i32Stack.pop(); @@ -1264,24 +1166,19 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.APIOptionalResult.lift(tag); } - if (result1Cleanup) { result1Cleanup(); } - if (result2Cleanup) { result2Cleanup(); } return optResult; }, roundTripTypedPayloadResult: function bjs_roundTripTypedPayloadResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.TypedPayloadResult.lower(result); + const resultCaseId = enumHelpers.TypedPayloadResult.lower(result); instance.exports.bjs_roundTripTypedPayloadResult(resultCaseId); const ret = enumHelpers.TypedPayloadResult.lift(i32Stack.pop()); - if (resultCleanup) { resultCleanup(); } return ret; }, roundTripOptionalTypedPayloadResult: function bjs_roundTripOptionalTypedPayloadResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.TypedPayloadResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.TypedPayloadResult.lower(result); } instance.exports.bjs_roundTripOptionalTypedPayloadResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1292,23 +1189,19 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.TypedPayloadResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, roundTripAllTypesResult: function bjs_roundTripAllTypesResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.AllTypesResult.lower(result); + const resultCaseId = enumHelpers.AllTypesResult.lower(result); instance.exports.bjs_roundTripAllTypesResult(resultCaseId); const ret = enumHelpers.AllTypesResult.lift(i32Stack.pop()); - if (resultCleanup) { resultCleanup(); } return ret; }, roundTripOptionalAllTypesResult: function bjs_roundTripOptionalAllTypesResult(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.AllTypesResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.AllTypesResult.lower(result); } instance.exports.bjs_roundTripOptionalAllTypesResult(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1319,23 +1212,19 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.AllTypesResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, roundTripOptionalPayloadResult: function bjs_roundTripOptionalPayloadResult(result) { - const { caseId: resultCaseId, cleanup: resultCleanup } = enumHelpers.OptionalAllTypesResult.lower(result); + const resultCaseId = enumHelpers.OptionalAllTypesResult.lower(result); instance.exports.bjs_roundTripOptionalPayloadResult(resultCaseId); const ret = enumHelpers.OptionalAllTypesResult.lift(i32Stack.pop()); - if (resultCleanup) { resultCleanup(); } return ret; }, roundTripOptionalPayloadResultOpt: function bjs_roundTripOptionalPayloadResultOpt(result) { const isSome = result != null; - let resultCaseId, resultCleanup; + let resultCaseId; if (isSome) { - const enumResult = enumHelpers.OptionalAllTypesResult.lower(result); - resultCaseId = enumResult.caseId; - resultCleanup = enumResult.cleanup; + resultCaseId = enumHelpers.OptionalAllTypesResult.lower(result); } instance.exports.bjs_roundTripOptionalPayloadResultOpt(+isSome, isSome ? resultCaseId : 0); const tag = i32Stack.pop(); @@ -1346,7 +1235,6 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.OptionalAllTypesResult.lift(tag); } - if (resultCleanup) { resultCleanup(); } return optResult; }, APIResult: APIResultValues, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 72d78dbe0..0ea2b0a53 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -47,7 +47,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -118,16 +117,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index ee93a950a..a5f97641c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -67,7 +67,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -138,16 +137,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index 099ef0576..a30709cbb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -48,7 +48,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -119,16 +118,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index b1ee0538f..77d106b57 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -98,7 +98,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -170,16 +169,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index 6f6bf9531..21613733e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index 9d57a04d3..21296b88a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index 7c946a716..2a2fd3d50 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -207,7 +196,6 @@ export async function createInstantiator(options, swift) { } arrayResult.reverse(); let ret = imports.roundtrip(arrayResult); - const arrayCleanups = []; for (const elem of ret) { i32Stack.push((elem | 0)); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 5d724202b..92230667c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -49,7 +48,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -145,22 +143,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_FooContainer"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.FooContainer.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.FooContainer.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_FooContainer"] = function() { const value = structHelpers.FooContainer.lift(); @@ -295,7 +279,6 @@ export async function createInstantiator(options, swift) { return ret1; }, processFooArray: function bjs_processFooArray(foos) { - const arrayCleanups = []; for (const elem of foos) { const objId = swift.memory.retain(elem); i32Stack.push(objId); @@ -311,11 +294,9 @@ export async function createInstantiator(options, swift) { arrayResult.push(obj); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, processOptionalFooArray: function bjs_processOptionalFooArray(foos) { - const arrayCleanups = []; for (const elem of foos) { const isSome = elem != null ? 1 : 0; if (isSome) { @@ -344,14 +325,12 @@ export async function createInstantiator(options, swift) { arrayResult.push(optValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, roundtripFooContainer: function bjs_roundtripFooContainer(container) { - const { cleanup: cleanup } = structHelpers.FooContainer.lower(container); + structHelpers.FooContainer.lower(container); instance.exports.bjs_roundtripFooContainer(); const structValue = structHelpers.FooContainer.lift(); - if (cleanup) { cleanup(); } return structValue; }, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index 54a0f2018..eabfe8c13 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index a192a1a8b..d84c77d45 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 1166d1f62..6912af0f3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 8151ea913..0a4d37845 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -184,16 +183,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -319,7 +308,6 @@ export async function createInstantiator(options, swift) { } arrayResult.reverse(); let ret = imports.jsEchoJSValueArray(arrayResult); - const arrayCleanups = []; for (const elem of ret) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); i32Stack.push(elemKind); @@ -478,7 +466,6 @@ export async function createInstantiator(options, swift) { return optResult; }, roundTripJSValueArray: function bjs_roundTripJSValueArray(values) { - const arrayCleanups = []; for (const elem of values) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); i32Stack.push(elemKind); @@ -497,14 +484,11 @@ export async function createInstantiator(options, swift) { arrayResult.push(jsValue); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, roundTripOptionalJSValueArray: function bjs_roundTripOptionalJSValueArray(values) { const isSome = values != null; - const valuesCleanups = []; if (isSome) { - const arrayCleanups = []; for (const elem of values) { const [elemKind, elemPayload1, elemPayload2] = __bjs_jsValueLower(elem); i32Stack.push(elemKind); @@ -512,7 +496,6 @@ export async function createInstantiator(options, swift) { f64Stack.push(elemPayload2); } i32Stack.push(values.length); - valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); } i32Stack.push(+isSome); instance.exports.bjs_roundTripOptionalJSValueArray(); @@ -533,7 +516,6 @@ export async function createInstantiator(options, swift) { } else { optResult = null; } - for (const cleanup of valuesCleanups) { cleanup(); } return optResult; }, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index 900d9b19c..457661b6c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 9b5f9267e..6c0c5ad9c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 1ab3809cc..a576e82b6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index ea5902783..806697af2 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index 5930b6914..1f5366828 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index 4c0bd0d13..03a3cf565 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index 83c77397a..8999ae8b6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index f1fda2cb7..c8372362d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index e7d80bb4d..dbdd030b6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index 58928211e..9043d19ef 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -47,7 +47,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -63,13 +62,11 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Success, cleanup }; + return ResultValues.Tag.Success; } case ResultValues.Tag.Failure: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: ResultValues.Tag.Failure, cleanup }; + return ResultValues.Tag.Failure; } default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); } @@ -155,16 +152,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -359,7 +346,7 @@ export async function createInstantiator(options, swift) { TestModule["bjs_MyViewControllerDelegate_result_get"] = function bjs_MyViewControllerDelegate_result_get(self) { try { let ret = swift.memory.getObject(self).result; - const { caseId: caseId, cleanup: cleanup } = enumHelpers.Result.lower(ret); + const caseId = enumHelpers.Result.lower(ret); return caseId; } catch (error) { setException(error); @@ -378,7 +365,7 @@ export async function createInstantiator(options, swift) { let ret = swift.memory.getObject(self).optionalResult; const isSome = ret != null; if (isSome) { - const { caseId: caseId, cleanup: cleanup } = enumHelpers.Result.lower(ret); + const caseId = enumHelpers.Result.lower(ret); return caseId; } else { return -1; @@ -558,7 +545,7 @@ export async function createInstantiator(options, swift) { TestModule["bjs_MyViewControllerDelegate_getResult"] = function bjs_MyViewControllerDelegate_getResult(self) { try { let ret = swift.memory.getObject(self).getResult(); - const { caseId: caseId, cleanup: cleanup } = enumHelpers.Result.lower(ret); + const caseId = enumHelpers.Result.lower(ret); return caseId; } catch (error) { setException(error); @@ -686,14 +673,12 @@ export async function createInstantiator(options, swift) { } constructor(delegates) { - const arrayCleanups = []; for (const elem of delegates) { const objId = swift.memory.retain(elem); i32Stack.push(objId); } i32Stack.push(delegates.length); const ret = instance.exports.bjs_DelegateManager_init(); - for (const cleanup of arrayCleanups) { cleanup(); } return DelegateManager.__construct(ret); } notifyAll() { @@ -713,14 +698,12 @@ export async function createInstantiator(options, swift) { return arrayResult; } set delegates(value) { - const arrayCleanups = []; for (const elem of value) { const objId = swift.memory.retain(elem); i32Stack.push(objId); } i32Stack.push(value.length); instance.exports.bjs_DelegateManager_delegates_set(this.pointer); - for (const cleanup of arrayCleanups) { cleanup(); } } } const ResultHelpers = __bjs_createResultValuesHelpers()(); @@ -731,7 +714,6 @@ export async function createInstantiator(options, swift) { MyViewController, DelegateManager, processDelegates: function bjs_processDelegates(delegates) { - const arrayCleanups = []; for (const elem of delegates) { const objId = swift.memory.retain(elem); i32Stack.push(objId); @@ -747,7 +729,6 @@ export async function createInstantiator(options, swift) { arrayResult.push(obj); } arrayResult.reverse(); - for (const cleanup of arrayCleanups) { cleanup(); } return arrayResult; }, Direction: DirectionValues, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 247374a3b..109a403b4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -34,7 +34,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -50,13 +49,11 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Success, cleanup }; + return APIResultValues.Tag.Success; } case APIResultValues.Tag.Failure: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; + return APIResultValues.Tag.Failure; } default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } @@ -142,16 +139,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -335,10 +322,9 @@ export async function createInstantiator(options, swift) { APIResult: { ...APIResultValues, roundtrip: function(value) { - const { caseId: valueCaseId, cleanup: valueCleanup } = enumHelpers.APIResult.lower(value); + const valueCaseId = enumHelpers.APIResult.lower(value); instance.exports.bjs_APIResult_static_roundtrip(valueCaseId); const ret = enumHelpers.APIResult.lift(i32Stack.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 a3bfb8a24..1be36c28e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -34,7 +34,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -50,13 +49,11 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Success, cleanup }; + return APIResultValues.Tag.Success; } case APIResultValues.Tag.Failure: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; + return APIResultValues.Tag.Failure; } default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } @@ -142,16 +139,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -329,10 +316,9 @@ export async function createInstantiator(options, swift) { APIResult: { ...APIResultValues, roundtrip: function(value) { - const { caseId: valueCaseId, cleanup: valueCleanup } = enumHelpers.APIResult.lower(value); + const valueCaseId = enumHelpers.APIResult.lower(value); instance.exports.bjs_APIResult_static_roundtrip(valueCaseId); const ret = enumHelpers.APIResult.lift(i32Stack.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 05127cd14..12afbb82c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -28,7 +28,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -99,16 +98,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index 5e89f1bb4..e9c5d105c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -28,7 +28,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -99,16 +98,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index 0f92074d4..480f40f92 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index f86fce218..49f07b5ef 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index 8f0552b64..cd6c9062b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 5fbde8c82..68bcfbe93 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -53,7 +53,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,32 +93,26 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Success, cleanup }; + return APIResultValues.Tag.Success; } case APIResultValues.Tag.Failure: { i32Stack.push((value.param0 | 0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Failure, cleanup }; + return APIResultValues.Tag.Failure; } case APIResultValues.Tag.Flag: { i32Stack.push(value.param0 ? 1 : 0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Flag, cleanup }; + return APIResultValues.Tag.Flag; } case APIResultValues.Tag.Rate: { f32Stack.push(Math.fround(value.param0)); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Rate, cleanup }; + return APIResultValues.Tag.Rate; } case APIResultValues.Tag.Precise: { f64Stack.push(value.param0); - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Precise, cleanup }; + return APIResultValues.Tag.Precise; } case APIResultValues.Tag.Info: { - const cleanup = undefined; - return { caseId: APIResultValues.Tag.Info, cleanup }; + return APIResultValues.Tag.Info; } default: throw new Error("Unknown APIResultValues tag: " + String(enumTag)); } @@ -218,16 +211,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; @@ -403,7 +386,7 @@ export async function createInstantiator(options, swift) { const callback = swift.memory.getObject(callbackId); const enumValue = enumHelpers.APIResult.lift(param0); let ret = callback(enumValue); - const { caseId: caseId, cleanup: cleanup } = enumHelpers.APIResult.lower(ret); + const caseId = enumHelpers.APIResult.lower(ret); return caseId; } catch (error) { setException(error); @@ -411,10 +394,9 @@ export async function createInstantiator(options, swift) { } bjs["make_swift_closure_TestModule_10TestModule9APIResultO_9APIResultO"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModule9APIResultO_9APIResultO = function(param0) { - const { caseId: param0CaseId, cleanup: param0Cleanup } = enumHelpers.APIResult.lower(param0); + const param0CaseId = enumHelpers.APIResult.lower(param0); instance.exports.invoke_swift_closure_TestModule_10TestModule9APIResultO_9APIResultO(boxPtr, param0CaseId); const ret = enumHelpers.APIResult.lift(i32Stack.pop()); - if (param0Cleanup) { param0Cleanup(); } if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); @@ -672,7 +654,7 @@ export async function createInstantiator(options, swift) { let ret = callback(param0IsSome ? enumValue : null); const isSome = ret != null; if (isSome) { - const { caseId: caseId, cleanup: cleanup } = enumHelpers.APIResult.lower(ret); + const caseId = enumHelpers.APIResult.lower(ret); return caseId; } else { return -1; @@ -684,11 +666,9 @@ export async function createInstantiator(options, swift) { bjs["make_swift_closure_TestModule_10TestModuleSq9APIResultO_Sq9APIResultO"] = function(boxPtr, file, line) { const lower_closure_TestModule_10TestModuleSq9APIResultO_Sq9APIResultO = function(param0) { const isSome = param0 != null; - let param0CaseId, param0Cleanup; + let param0CaseId; if (isSome) { - const enumResult = enumHelpers.APIResult.lower(param0); - param0CaseId = enumResult.caseId; - param0Cleanup = enumResult.cleanup; + param0CaseId = enumHelpers.APIResult.lower(param0); } instance.exports.invoke_swift_closure_TestModule_10TestModuleSq9APIResultO_Sq9APIResultO(boxPtr, +isSome, isSome ? param0CaseId : 0); const tag = i32Stack.pop(); @@ -699,7 +679,6 @@ export async function createInstantiator(options, swift) { } else { optResult = enumHelpers.APIResult.lift(tag); } - if (param0Cleanup) { param0Cleanup(); } if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 61347e817..b5efd2150 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -120,16 +119,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index 6f704013b..dbbbd6bc9 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -28,7 +28,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -57,7 +56,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome1 ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -101,7 +99,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -126,7 +123,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(bytes.length); i32Stack.push(id); i32Stack.push((value.age | 0)); - const structResult = structHelpers.Address.lower(value.address); + structHelpers.Address.lower(value.address); const isSome = value.email != null; let id1; if (isSome) { @@ -139,10 +136,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if (structResult.cleanup) { structResult.cleanup(); } - }; - return { cleanup }; }, lift: () => { const isSome = i32Stack.pop(); @@ -165,7 +158,6 @@ export async function createInstantiator(options, swift) { lower: (value) => { i32Stack.push((value.id | 0)); ptrStack.push(value.owner.pointer); - return { cleanup: undefined }; }, lift: () => { const ptr = ptrStack.pop(); @@ -187,7 +179,6 @@ export async function createInstantiator(options, swift) { f32Stack.push(0.0); } i32Stack.push(isSome ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -207,7 +198,6 @@ export async function createInstantiator(options, swift) { const __bjs_createConfigStructHelpers = () => { return () => ({ lower: (value) => { - return { cleanup: undefined }; }, lift: () => { return { }; @@ -234,7 +224,6 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -329,88 +318,50 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_DataPoint"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.DataPoint.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.DataPoint.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_DataPoint"] = function() { const value = structHelpers.DataPoint.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Address"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Address.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Address.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Address"] = function() { const value = structHelpers.Address.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Person"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Person.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Person.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Person"] = function() { const value = structHelpers.Person.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Session"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Session.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Session.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Session"] = function() { const value = structHelpers.Session.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Measurement"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Measurement.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Measurement.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Measurement"] = function() { const value = structHelpers.Measurement.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_ConfigStruct"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.ConfigStruct.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.ConfigStruct.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_ConfigStruct"] = function() { const value = structHelpers.ConfigStruct.lift(); return swift.memory.retain(value); } bjs["swift_js_struct_lower_Container"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Container.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Container.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Container"] = function() { const value = structHelpers.Container.lift(); @@ -609,17 +560,15 @@ export async function createInstantiator(options, swift) { const exports = { Greeter, roundtrip: function bjs_roundtrip(session) { - const { cleanup: cleanup } = structHelpers.Person.lower(session); + structHelpers.Person.lower(session); instance.exports.bjs_roundtrip(); const structValue = structHelpers.Person.lift(); - if (cleanup) { cleanup(); } return structValue; }, roundtripContainer: function bjs_roundtripContainer(container) { - const { cleanup: cleanup } = structHelpers.Container.lower(container); + structHelpers.Container.lower(container); instance.exports.bjs_roundtripContainer(); const structValue = structHelpers.Container.lift(); - if (cleanup) { cleanup(); } return structValue; }, Precision: PrecisionValues, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index 4962e659b..cf64ab587 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -34,7 +33,6 @@ export async function createInstantiator(options, swift) { lower: (value) => { i32Stack.push((value.x | 0)); i32Stack.push((value.y | 0)); - return { cleanup: undefined }; }, lift: () => { const int = i32Stack.pop(); @@ -109,22 +107,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_Point"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.Point.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.Point.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_Point"] = function() { const value = structHelpers.Point.lift(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index 3726a48ae..2c415fc31 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index 7c3627d13..30c40a18c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -37,7 +36,6 @@ export async function createInstantiator(options, swift) { ptrStack.push((value.opaque | 0)); ptrStack.push((value.ptr | 0)); ptrStack.push((value.mutPtr | 0)); - return { cleanup: undefined }; }, lift: () => { const pointer = ptrStack.pop(); @@ -114,22 +112,8 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.pop(); } - bjs["swift_js_struct_cleanup"] = function(cleanupId) { - if (cleanupId === 0) { return; } - const index = (cleanupId | 0) - 1; - const cleanup = tmpStructCleanups[index]; - tmpStructCleanups[index] = null; - if (cleanup) { cleanup(); } - while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) { - tmpStructCleanups.pop(); - } - } bjs["swift_js_struct_lower_PointerFields"] = function(objectId) { - const { cleanup: cleanup } = structHelpers.PointerFields.lower(swift.memory.getObject(objectId)); - if (cleanup) { - return tmpStructCleanups.push(cleanup); - } - return 0; + structHelpers.PointerFields.lower(swift.memory.getObject(objectId)); } bjs["swift_js_struct_lift_PointerFields"] = function() { const value = structHelpers.PointerFields.lift(); @@ -278,10 +262,9 @@ export async function createInstantiator(options, swift) { return ret; }, roundTripPointerFields: function bjs_roundTripPointerFields(value) { - const { cleanup: cleanup } = structHelpers.PointerFields.lower(value); + structHelpers.PointerFields.lower(value); instance.exports.bjs_roundTripPointerFields(); const structValue = structHelpers.PointerFields.lift(); - if (cleanup) { cleanup(); } return structValue; }, PointerFields: { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index e338c840d..f8737237e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) { let f32Stack = []; let f64Stack = []; let ptrStack = []; - let tmpStructCleanups = []; const enumHelpers = {}; const structHelpers = {}; @@ -95,16 +94,6 @@ export async function createInstantiator(options, swift) { bjs["swift_js_pop_pointer"] = function() { return ptrStack.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; diff --git a/Plugins/PackageToJS/Templates/instantiate.js b/Plugins/PackageToJS/Templates/instantiate.js index c9bc9efb4..fd183583b 100644 --- a/Plugins/PackageToJS/Templates/instantiate.js +++ b/Plugins/PackageToJS/Templates/instantiate.js @@ -1,5 +1,5 @@ // @ts-check -import { SwiftRuntime } from "./runtime.js" +import { SwiftRuntime } from "./runtime.js"; export const MODULE_PATH = "@PACKAGE_TO_JS_MODULE_PATH@"; /* #if USE_SHARED_MEMORY */ @@ -10,12 +10,12 @@ export const MEMORY_TYPE = { maximum: import.meta.PACKAGE_TO_JS_MEMORY_MAXIMUM, // @ts-expect-error Substituted by PackageToJS preprocessor shared: import.meta.PACKAGE_TO_JS_MEMORY_SHARED, -} +}; /* #endif */ /* #if HAS_BRIDGE */ // @ts-expect-error Substituted by PackageToJS preprocessor -import { createInstantiator } from "./bridge-js.js" +import { createInstantiator } from "./bridge-js.js"; /* #else */ /** * @param {import('./instantiate.d').InstantiateOptions} options @@ -30,7 +30,9 @@ async function createInstantiator(options, swift) { addImports: (importObject, importsContext) => { // Provide a default implementation for BridgeJS functions that are not // used at runtime without BridgeJS but required to instantiate the module. - const unexpectedBjsCall = () => { throw new Error("Unexpected call to BridgeJS function") } + const unexpectedBjsCall = () => { + throw new Error("Unexpected call to BridgeJS function"); + }; importObject["bjs"] = { swift_js_return_string: unexpectedBjsCall, swift_js_init_memory: unexpectedBjsCall, @@ -63,9 +65,8 @@ async function createInstantiator(options, swift) { swift_js_get_optional_heap_object_pointer: unexpectedBjsCall, swift_js_push_pointer: unexpectedBjsCall, swift_js_pop_pointer: unexpectedBjsCall, - swift_js_struct_cleanup: unexpectedBjsCall, swift_js_closure_unregister: unexpectedBjsCall, - } + }; }, /** @param {WebAssembly.Instance} instance */ setInstance: (instance) => {}, @@ -73,67 +74,65 @@ async function createInstantiator(options, swift) { createExports: (instance) => { return {}; }, - } + }; } /* #endif */ /** @type {import('./instantiate.d').instantiate} */ -export async function instantiate( - options -) { +export async function instantiate(options) { const result = await _instantiate(options); -/* #if IS_WASI */ + /* #if IS_WASI */ options.wasi.initialize(result.instance); -/* #endif */ + /* #endif */ result.swift.main(); return result; } /** @type {import('./instantiate.d').instantiateForThread} */ -export async function instantiateForThread( - tid, startArg, options -) { +export async function instantiateForThread(tid, startArg, options) { const result = await _instantiate(options); -/* #if IS_WASI */ + /* #if IS_WASI */ options.wasi.setInstance(result.instance); -/* #endif */ - result.swift.startThread(tid, startArg) + /* #endif */ + result.swift.startThread(tid, startArg); return result; } /** @type {import('./instantiate.d').instantiate} */ -async function _instantiate( - options -) { +async function _instantiate(options) { const _WebAssembly = options.WebAssembly || WebAssembly; const moduleSource = options.module; -/* #if IS_WASI */ + /* #if IS_WASI */ const { wasi } = options; -/* #endif */ + /* #endif */ const swift = new SwiftRuntime({ -/* #if USE_SHARED_MEMORY */ + /* #if USE_SHARED_MEMORY */ sharedMemory: true, threadChannel: options.threadChannel, -/* #endif */ + /* #endif */ }); const instantiator = await createInstantiator(options, swift); /** @type {WebAssembly.Imports} */ const importObject = { javascript_kit: swift.wasmImports, -/* #if IS_WASI */ + /* #if IS_WASI */ wasi_snapshot_preview1: wasi.wasiImport, -/* #if USE_SHARED_MEMORY */ + /* #if USE_SHARED_MEMORY */ env: { memory: options.memory, }, wasi: { "thread-spawn": (startArg) => { - return options.threadChannel.spawnThread(module, options.memory, startArg); - } - } -/* #endif */ -/* #endif */ + return options.threadChannel.spawnThread( + module, + options.memory, + startArg, + ); + }, + }, + /* #endif */ + /* #endif */ }; const importsContext = { getInstance: () => instance, @@ -149,9 +148,15 @@ async function _instantiate( if (moduleSource instanceof _WebAssembly.Module) { module = moduleSource; instance = await _WebAssembly.instantiate(module, importObject); - } else if (typeof Response === "function" && (moduleSource instanceof Response || moduleSource instanceof Promise)) { + } else if ( + typeof Response === "function" && + (moduleSource instanceof Response || moduleSource instanceof Promise) + ) { if (typeof _WebAssembly.instantiateStreaming === "function") { - const result = await _WebAssembly.instantiateStreaming(moduleSource, importObject); + const result = await _WebAssembly.instantiateStreaming( + moduleSource, + importObject, + ); module = result.module; instance = result.instance; } else { @@ -164,7 +169,8 @@ async function _instantiate( module = await _WebAssembly.compile(moduleSource); instance = await _WebAssembly.instantiate(module, importObject); } - instance = options.instrumentInstance?.(instance, { _swift: swift }) ?? instance; + instance = + options.instrumentInstance?.(instance, { _swift: swift }) ?? instance; swift.setInstance(instance); instantiator.setInstance(instance); @@ -174,5 +180,5 @@ async function _instantiate( instance, swift, exports, - } + }; } diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index 28bdaa6db..15b5be9ee 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -818,21 +818,6 @@ private func _swift_js_pop_f64_extern() -> Float64 { _swift_js_pop_f64_extern() } -// MARK: Struct bridging helpers (JS-side lowering/raising) - -#if arch(wasm32) -@_extern(wasm, module: "bjs", name: "swift_js_struct_cleanup") -private func _swift_js_struct_cleanup_extern(_ cleanupId: Int32) -#else -private func _swift_js_struct_cleanup_extern(_ cleanupId: Int32) { - _onlyAvailableOnWasm() -} -#endif - -@_spi(BridgeJS) @inline(never) public func _swift_js_struct_cleanup(_ cleanupId: Int32) { - _swift_js_struct_cleanup_extern(cleanupId) -} - // MARK: Wasm externs used by type lowering/lifting #if arch(wasm32) diff --git a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift index 8c1d63854..253087c0d 100644 --- a/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift +++ b/Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift @@ -2720,10 +2720,7 @@ extension Point: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Point(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -2736,9 +2733,9 @@ extension Point: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Point") -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Point(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -2771,10 +2768,7 @@ extension PointerFields: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PointerFields(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PointerFields(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -2787,9 +2781,9 @@ extension PointerFields: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PointerFields") -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PointerFields(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -2841,10 +2835,7 @@ extension DataPoint: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_DataPoint(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_DataPoint(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -2857,9 +2848,9 @@ extension DataPoint: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_DataPoint") -fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_DataPoint(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -2897,10 +2888,7 @@ extension PublicPoint: _BridgedSwiftStruct { } public init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_PublicPoint(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_PublicPoint(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -2913,9 +2901,9 @@ extension PublicPoint: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PublicPoint") -fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_PublicPoint(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -2959,10 +2947,7 @@ extension Address: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Address(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -2975,9 +2960,9 @@ extension Address: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Address") -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Address(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3014,10 +2999,7 @@ extension Contact: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Contact(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Contact(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3030,9 +3012,9 @@ extension Contact: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Contact") -fileprivate func _bjs_struct_lower_Contact(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Contact(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Contact(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Contact(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3071,10 +3053,7 @@ extension Config: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_Config(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_Config(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3087,9 +3066,9 @@ extension Config: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_Config") -fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_Config(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3120,10 +3099,7 @@ extension SessionData: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_SessionData(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_SessionData(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3136,9 +3112,9 @@ extension SessionData: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_SessionData") -fileprivate func _bjs_struct_lower_SessionData(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_SessionData(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_SessionData(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_SessionData(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3177,10 +3153,7 @@ extension ValidationReport: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_ValidationReport(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_ValidationReport(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3193,9 +3166,9 @@ extension ValidationReport: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ValidationReport") -fileprivate func _bjs_struct_lower_ValidationReport(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_ValidationReport(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_ValidationReport(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_ValidationReport(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3246,10 +3219,7 @@ extension AdvancedConfig: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_AdvancedConfig(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_AdvancedConfig(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3262,9 +3232,9 @@ extension AdvancedConfig: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_AdvancedConfig") -fileprivate func _bjs_struct_lower_AdvancedConfig(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_AdvancedConfig(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_AdvancedConfig(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_AdvancedConfig(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3303,10 +3273,7 @@ extension MeasurementConfig: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_MeasurementConfig(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_MeasurementConfig(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3319,9 +3286,9 @@ extension MeasurementConfig: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_MeasurementConfig") -fileprivate func _bjs_struct_lower_MeasurementConfig(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_MeasurementConfig(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_MeasurementConfig(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_MeasurementConfig(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3346,10 +3313,7 @@ extension MathOperations: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_MathOperations(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_MathOperations(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3362,9 +3326,9 @@ extension MathOperations: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_MathOperations") -fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_MathOperations(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3439,10 +3403,7 @@ extension CopyableCart: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_CopyableCart(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_CopyableCart(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3455,9 +3416,9 @@ extension CopyableCart: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_CopyableCart") -fileprivate func _bjs_struct_lower_CopyableCart(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_CopyableCart(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_CopyableCart(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_CopyableCart(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3495,10 +3456,7 @@ extension CopyableCartItem: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_CopyableCartItem(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_CopyableCartItem(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3511,9 +3469,9 @@ extension CopyableCartItem: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_CopyableCartItem") -fileprivate func _bjs_struct_lower_CopyableCartItem(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_CopyableCartItem(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_CopyableCartItem(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_CopyableCartItem(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3542,10 +3500,7 @@ extension CopyableNestedCart: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_CopyableNestedCart(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_CopyableNestedCart(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3558,9 +3513,9 @@ extension CopyableNestedCart: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_CopyableNestedCart") -fileprivate func _bjs_struct_lower_CopyableNestedCart(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_CopyableNestedCart(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_CopyableNestedCart(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_CopyableNestedCart(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3598,10 +3553,7 @@ extension ConfigStruct: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_ConfigStruct(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_ConfigStruct(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3614,9 +3566,9 @@ extension ConfigStruct: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ConfigStruct") -fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_ConfigStruct(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3711,10 +3663,7 @@ extension JSObjectContainer: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_JSObjectContainer(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_JSObjectContainer(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3727,9 +3676,9 @@ extension JSObjectContainer: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_JSObjectContainer") -fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_JSObjectContainer(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3760,10 +3709,7 @@ extension FooContainer: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_FooContainer(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3776,9 +3722,9 @@ extension FooContainer: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_FooContainer") -fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_FooContainer(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif @@ -3805,10 +3751,7 @@ extension ArrayMembers: _BridgedSwiftStruct { } init(unsafelyCopying jsObject: JSObject) { - let __bjs_cleanupId = _bjs_struct_lower_ArrayMembers(jsObject.bridgeJSLowerParameter()) - defer { - _swift_js_struct_cleanup(__bjs_cleanupId) - } + _bjs_struct_lower_ArrayMembers(jsObject.bridgeJSLowerParameter()) self = Self.bridgeJSStackPop() } @@ -3821,9 +3764,9 @@ extension ArrayMembers: _BridgedSwiftStruct { #if arch(wasm32) @_extern(wasm, module: "bjs", name: "swift_js_struct_lower_ArrayMembers") -fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Int32 +fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Void #else -fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Int32 { +fileprivate func _bjs_struct_lower_ArrayMembers(_ objectId: Int32) -> Void { fatalError("Only available on WebAssembly") } #endif