From c4bcebc785a5c6d6ba94c1f157bce205bc299f50 Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Fri, 13 Feb 2026 15:36:05 +0100 Subject: [PATCH] NFC: BridgeJS: Reduce retained object cleanup warning noise in BridgeJS glue --- .../Sources/BridgeJSLink/JSGlueGen.swift | 22 +------------------ .../ImportedTypeInExportedInterface.js | 16 +------------- .../BridgeJSLinkTests/SwiftStruct.js | 16 +------------- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index 36d463ab4..ffb50c7a8 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -3026,7 +3026,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 idVar = scope.variable("id") printer.write("let \(idVar);") @@ -3040,16 +3040,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(idVar) !== undefined ? \(idVar) : 0", printer: printer) - cleanup.write("if(\(idVar) !== undefined && \(idVar) !== 0) {") - cleanup.indent { - cleanup.write("try {") - cleanup.indent { - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.getObject(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - } - cleanup.write("} catch(e) {}") - } - cleanup.write("}") return [idVar] } ) @@ -3208,16 +3198,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if(\(idVar) !== undefined && \(idVar) !== 0) {") - cleanup.indent { - cleanup.write("try {") - cleanup.indent { - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.getObject(\(idVar));") - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - } - cleanup.write("} catch(e) {}") - } - cleanup.write("}") return [idVar] } else { switch wrappedType { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 7e2f48981..48aab8fbb 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -49,21 +49,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if(id !== undefined && id !== 0) { - try { - swift.memory.getObject(id); - swift.memory.release(id); - } catch(e) {} - } - if(id1 !== undefined && id1 !== 0) { - try { - swift.memory.getObject(id1); - swift.memory.release(id1); - } catch(e) {} - } - }; - return { cleanup }; + return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index ff8c8f8b0..dca01b33c 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -243,21 +243,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if(id !== undefined && id !== 0) { - try { - swift.memory.getObject(id); - swift.memory.release(id); - } catch(e) {} - } - if(id1 !== undefined && id1 !== 0) { - try { - swift.memory.getObject(id1); - swift.memory.release(id1); - } catch(e) {} - } - }; - return { cleanup }; + return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop();