From 76c5abcdbf2729d5445c061481092172398cb091 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 16 Feb 2026 10:42:48 +0900 Subject: [PATCH] BridgeJS: Take ownership of source Uint8Array id in `swift_js_init_memory` This allows us to insert cleanup code for String parameter passing for JS -> Swift. --- .../Sources/BridgeJSLink/BridgeJSLink.swift | 3 + .../Sources/BridgeJSLink/JSGlueGen.swift | 33 +---------- .../BridgeJSLinkTests/ArrayTypes.js | 12 +--- .../__Snapshots__/BridgeJSLinkTests/Async.js | 2 +- .../BridgeJSLinkTests/DefaultParameters.js | 28 +--------- .../BridgeJSLinkTests/DictionaryTypes.js | 22 +------- .../BridgeJSLinkTests/EnumAssociatedValue.js | 55 +++++-------------- .../BridgeJSLinkTests/EnumCase.js | 1 + .../BridgeJSLinkTests/EnumNamespace.Global.js | 1 + .../BridgeJSLinkTests/EnumNamespace.js | 1 + .../BridgeJSLinkTests/EnumRawType.js | 14 +---- .../BridgeJSLinkTests/GlobalGetter.js | 1 + .../BridgeJSLinkTests/GlobalThisImports.js | 1 + .../BridgeJSLinkTests/ImportArray.js | 1 + .../ImportedTypeInExportedInterface.js | 1 + .../BridgeJSLinkTests/InvalidPropertyNames.js | 1 + .../BridgeJSLinkTests/JSClass.js | 1 + .../JSClassStaticFunctions.js | 1 + .../BridgeJSLinkTests/JSValue.js | 1 + .../BridgeJSLinkTests/MixedGlobal.js | 1 + .../BridgeJSLinkTests/MixedModules.js | 1 + .../BridgeJSLinkTests/MixedPrivate.js | 1 + .../BridgeJSLinkTests/Namespaces.Global.js | 2 +- .../BridgeJSLinkTests/Namespaces.js | 2 +- .../BridgeJSLinkTests/Optionals.js | 37 +------------ .../BridgeJSLinkTests/PrimitiveParameters.js | 1 + .../BridgeJSLinkTests/PrimitiveReturn.js | 1 + .../BridgeJSLinkTests/PropertyTypes.js | 6 +- .../BridgeJSLinkTests/Protocol.js | 8 +-- .../StaticFunctions.Global.js | 6 +- .../BridgeJSLinkTests/StaticFunctions.js | 6 +- .../StaticProperties.Global.js | 9 +-- .../BridgeJSLinkTests/StaticProperties.js | 9 +-- .../BridgeJSLinkTests/StringParameter.js | 3 +- .../BridgeJSLinkTests/StringReturn.js | 1 + .../BridgeJSLinkTests/SwiftClass.js | 4 +- .../BridgeJSLinkTests/SwiftClosure.js | 14 +---- .../BridgeJSLinkTests/SwiftClosureImports.js | 1 + .../BridgeJSLinkTests/SwiftStruct.js | 18 +----- .../BridgeJSLinkTests/SwiftStructImports.js | 1 + .../__Snapshots__/BridgeJSLinkTests/Throws.js | 1 + .../BridgeJSLinkTests/UnsafePointer.js | 1 + .../VoidParameterVoidReturn.js | 1 + .../JavaScriptKit/BridgeJSIntrinsics.swift | 6 ++ 44 files changed, 72 insertions(+), 249 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift index 44b6f0c38..b779e0171 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift @@ -297,6 +297,9 @@ public struct BridgeJSLink { printer.write( "const source = \(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).getObject(sourceId);" ) + printer.write( + "\(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).release(sourceId);" + ) printer.write( "const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, bytesPtr);" ) diff --git a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift index ffb50c7a8..8082ea6c3 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift @@ -238,13 +238,12 @@ struct IntrinsicJSFragment: Sendable { static let stringLowerParameter = 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 argument = arguments[0] let bytesLabel = scope.variable("\(argument)Bytes") let bytesIdLabel = scope.variable("\(argument)Id") printer.write("const \(bytesLabel) = \(JSGlueVariableScope.reservedTextEncoder).encode(\(argument));") printer.write("const \(bytesIdLabel) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesLabel));") - cleanupCode.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(bytesIdLabel));") return [bytesIdLabel, "\(bytesLabel).length"] } ) @@ -840,12 +839,6 @@ struct IntrinsicJSFragment: Sendable { printer.write("\(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") } printer.write("}") - cleanupCode.write("if (\(idVar) != undefined) {") - cleanupCode.indent { - cleanupCode.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - } - cleanupCode.write("}") - return ["+\(isSomeVar)", "\(isSomeVar) ? \(idVar) : 0", "\(isSomeVar) ? \(bytesVar).length : 0"] case .jsValue: let lowered = try jsValueLower.printCode([value], context) @@ -1920,11 +1913,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if(\(idVar)) {") - cleanup.indent { - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") - } - cleanup.write("}") case .int, .uint: scope.emitPushI32Parameter("\(isSomeVar) ? (\(value) | 0) : 0", printer: printer) scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) @@ -1964,13 +1952,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write("if(\(idVar)) {") - cleanup.indent { - cleanup.write( - "\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));" - ) - } - cleanup.write("}") case .float: scope.emitPushF32Parameter("\(isSomeVar) ? Math.fround(\(value)) : 0.0", printer: printer) scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) @@ -2554,7 +2535,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 bytesVar = scope.variable("bytes") let idVar = scope.variable("id") @@ -2562,7 +2543,6 @@ struct IntrinsicJSFragment: Sendable { printer.write("const \(idVar) = \(JSGlueVariableScope.reservedSwift).memory.retain(\(bytesVar));") scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) scope.emitPushI32Parameter(idVar, printer: printer) - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [] } ) @@ -2632,7 +2612,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 bytesVar = scope.variable("bytes") let idVar = scope.variable("id") @@ -2644,7 +2624,6 @@ struct IntrinsicJSFragment: Sendable { ) scope.emitPushI32Parameter("\(bytesVar).length", printer: printer) scope.emitPushI32Parameter(idVar, printer: printer) - cleanup.write("\(JSGlueVariableScope.reservedSwift).memory.release(\(idVar));") return [] } ) @@ -3088,9 +3067,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write( - "if(\(idVar) !== undefined) { \(JSGlueVariableScope.reservedSwift).memory.release(\(idVar)); }" - ) return [idVar] case .float: printer.write("if (\(isSomeVar)) {") @@ -3179,9 +3155,6 @@ struct IntrinsicJSFragment: Sendable { } printer.write("}") scope.emitPushI32Parameter("\(isSomeVar) ? 1 : 0", printer: printer) - cleanup.write( - "if(\(idVar) !== undefined) { \(JSGlueVariableScope.reservedSwift).memory.release(\(idVar)); }" - ) return [idVar] } else if case .jsObject = wrappedType { let idVar = scope.variable("id") diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js index 97531d378..52438d27d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js @@ -71,6 +71,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -317,9 +318,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); } i32Stack.push(ret.length); } catch (error) { @@ -411,9 +409,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); } i32Stack.push(values.length); instance.exports.bjs_processStringArray(); @@ -539,7 +534,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_findFirstPoint(matchingId, matchingBytes.length); const structValue = structHelpers.Point.lift(); for (const cleanup of arrayCleanups) { cleanup(); } - swift.memory.release(matchingId); return structValue; }, processUnsafeRawPointerArray: function bjs_processUnsafeRawPointerArray(values) { @@ -632,7 +626,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { swift.memory.release(id); }); } else { i32Stack.push(0); i32Stack.push(0); @@ -817,9 +810,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups1.push(() => { - swift.memory.release(id); - }); } i32Stack.push(elem.length); arrayCleanups.push(() => { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js index b215b3691..bd57f0fd4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -225,7 +226,6 @@ export async function createInstantiator(options, swift) { const ret = instance.exports.bjs_asyncRoundTripString(vId, vBytes.length); const ret1 = swift.memory.getObject(ret); swift.memory.release(ret); - swift.memory.release(vId); return ret1; }, asyncRoundTripBool: function bjs_asyncRoundTripBool(v) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js index fba9f9c6b..6182298a1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js @@ -44,10 +44,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.value | 0)); i32Stack.push(value.enabled ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; - return { cleanup }; + return { cleanup: undefined }; }, lift: () => { const bool = i32Stack.pop() !== 0; @@ -96,6 +93,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -325,7 +323,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_DefaultGreeter_init(nameId, nameBytes.length); - swift.memory.release(nameId); return DefaultGreeter.__construct(ret); } get name() { @@ -338,7 +335,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_DefaultGreeter_name_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } } class EmptyGreeter extends SwiftHeapObject { @@ -366,10 +362,6 @@ export async function createInstantiator(options, swift) { tagId = swift.memory.retain(tagBytes); } const ret = instance.exports.bjs_ConstructorDefaults_init(nameId, nameBytes.length, count, enabled, status, +isSome, isSome ? tagId : 0, isSome ? tagBytes.length : 0); - swift.memory.release(nameId); - if (tagId != undefined) { - swift.memory.release(tagId); - } return ConstructorDefaults.__construct(ret); } get name() { @@ -382,7 +374,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_ConstructorDefaults_name_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } get count() { const ret = instance.exports.bjs_ConstructorDefaults_count_get(this.pointer); @@ -419,9 +410,6 @@ export async function createInstantiator(options, swift) { valueId = swift.memory.retain(valueBytes); } instance.exports.bjs_ConstructorDefaults_tag_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0); - if (valueId != undefined) { - swift.memory.release(valueId); - } } } const ConfigHelpers = __bjs_createConfigHelpers()(); @@ -440,7 +428,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testStringDefault(messageId, messageBytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(messageId); return ret; }, testNegativeIntDefault: function bjs_testNegativeIntDefault(value = -42) { @@ -469,9 +456,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testOptionalDefault(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, testOptionalStringDefault: function bjs_testOptionalStringDefault(greeting = "Hi") { @@ -484,9 +468,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testOptionalStringDefault(+isSome, isSome ? greetingId : 0, isSome ? greetingBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (greetingId != undefined) { - swift.memory.release(greetingId); - } return optResult; }, testMultipleDefaults: function bjs_testMultipleDefaults(title = "Default Title", count = 10, enabled = false) { @@ -495,7 +476,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testMultipleDefaults(titleId, titleBytes.length, count, enabled); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(titleId); return ret; }, testEnumDefault: function bjs_testEnumDefault(status = StatusValues.Active) { @@ -572,9 +552,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); } i32Stack.push(names.length); instance.exports.bjs_testStringArrayDefault(); @@ -650,7 +627,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testMixedWithArrayDefault(nameId, nameBytes.length, enabled); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(nameId); for (const cleanup of arrayCleanups) { cleanup(); } return ret; }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js index 1f7fe91e1..4f71aa76e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -222,9 +223,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); f64Stack.push(value); } i32Stack.push(entries.length); @@ -280,9 +278,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); i32Stack.push((value | 0)); } i32Stack.push(entries.length); @@ -309,16 +304,10 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); const bytes1 = textEncoder.encode(value); const id1 = swift.memory.retain(bytes1); i32Stack.push(bytes1.length); i32Stack.push(id1); - arrayCleanups.push(() => { - swift.memory.release(id1); - }); } i32Stack.push(entries.length); valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } }); @@ -351,9 +340,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); const arrayCleanups1 = []; for (const elem of value) { i32Stack.push((elem | 0)); @@ -390,9 +376,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); ptrStack.push(value.pointer); } i32Stack.push(entries.length); @@ -417,9 +400,6 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - arrayCleanups.push(() => { - swift.memory.release(id); - }); const isSome = value != null ? 1 : 0; if (isSome) { ptrStack.push(value.pointer); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js index 3a4818463..af81d52fe 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumAssociatedValue.js @@ -134,9 +134,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { @@ -205,9 +203,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ComplexResultValues.Tag.Success, cleanup }; } case ComplexResultValues.Tag.Error: { @@ -216,9 +212,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ComplexResultValues.Tag.Error, cleanup }; } case ComplexResultValues.Tag.Status: { @@ -228,9 +222,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.param1 | 0)); i32Stack.push(value.param0 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ComplexResultValues.Tag.Status, cleanup }; } case ComplexResultValues.Tag.Coordinates: { @@ -259,11 +251,7 @@ 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 = () => { - swift.memory.release(id); - swift.memory.release(id1); - swift.memory.release(id2); - }; + const cleanup = undefined; return { caseId: ComplexResultValues.Tag.Comprehensive, cleanup }; } case ComplexResultValues.Tag.Info: { @@ -325,9 +313,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ResultValues.Tag.Success, cleanup }; } case ResultValues.Tag.Failure: { @@ -336,9 +322,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ResultValues.Tag.Failure, cleanup }; } case ResultValues.Tag.Status: { @@ -348,9 +332,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(id); i32Stack.push((value.param1 | 0)); i32Stack.push(value.param0 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ResultValues.Tag.Status, cleanup }; } default: throw new Error("Unknown ResultValues tag: " + String(enumTag)); @@ -389,9 +371,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: NetworkingResultValues.Tag.Success, cleanup }; } case NetworkingResultValues.Tag.Failure: { @@ -400,9 +380,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: NetworkingResultValues.Tag.Failure, cleanup }; } default: throw new Error("Unknown NetworkingResultValues tag: " + String(enumTag)); @@ -443,11 +421,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - if(id) { - swift.memory.release(id); - } - }; + const cleanup = undefined; return { caseId: APIOptionalResultValues.Tag.Success, cleanup }; } case APIOptionalResultValues.Tag.Failure: { @@ -479,11 +453,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 = () => { - if(id) { - swift.memory.release(id); - } - }; + const cleanup = undefined; return { caseId: APIOptionalResultValues.Tag.Status, cleanup }; } default: throw new Error("Unknown APIOptionalResultValues tag: " + String(enumTag)); @@ -889,6 +859,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js index 341ffb260..72d78dbe0 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumCase.js @@ -67,6 +67,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js index fa4586a2d..392788ef6 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js @@ -87,6 +87,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js index 5d85347ee..0a2826a5e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.js @@ -68,6 +68,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js index 04d667b8e..b1ee0538f 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumRawType.js @@ -119,6 +119,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -306,7 +307,6 @@ export async function createInstantiator(options, swift) { const themeBytes = textEncoder.encode(theme); const themeId = swift.memory.retain(themeBytes); instance.exports.bjs_setTheme(themeId, themeBytes.length); - swift.memory.release(themeId); }, getTheme: function bjs_getTheme() { instance.exports.bjs_getTheme(); @@ -324,16 +324,12 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripOptionalTheme(+isSome, isSome ? inputId : 0, isSome ? inputBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (inputId != undefined) { - swift.memory.release(inputId); - } return optResult; }, setTSTheme: function bjs_setTSTheme(theme) { const themeBytes = textEncoder.encode(theme); const themeId = swift.memory.retain(themeBytes); instance.exports.bjs_setTSTheme(themeId, themeBytes.length); - swift.memory.release(themeId); }, getTSTheme: function bjs_getTSTheme() { instance.exports.bjs_getTSTheme(); @@ -351,16 +347,12 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripOptionalTSTheme(+isSome, isSome ? inputId : 0, isSome ? inputBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (inputId != undefined) { - swift.memory.release(inputId); - } return optResult; }, setFeatureFlag: function bjs_setFeatureFlag(flag) { const flagBytes = textEncoder.encode(flag); const flagId = swift.memory.retain(flagBytes); instance.exports.bjs_setFeatureFlag(flagId, flagBytes.length); - swift.memory.release(flagId); }, getFeatureFlag: function bjs_getFeatureFlag() { instance.exports.bjs_getFeatureFlag(); @@ -378,9 +370,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripOptionalFeatureFlag(+isSome, isSome ? inputId : 0, isSome ? inputBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (inputId != undefined) { - swift.memory.release(inputId); - } return optResult; }, setHttpStatus: function bjs_setHttpStatus(status) { @@ -513,7 +502,6 @@ export async function createInstantiator(options, swift) { const themeBytes = textEncoder.encode(theme); const themeId = swift.memory.retain(themeBytes); const ret = instance.exports.bjs_processTheme(themeId, themeBytes.length); - swift.memory.release(themeId); return ret; }, convertPriority: function bjs_convertPriority(status) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js index a60d5377f..6f6bf9531 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalGetter.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js index e0b4f8f94..9d57a04d3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/GlobalThisImports.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js index 80ff1cead..7c946a716 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportArray.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js index 48aab8fbb..5d724202b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ImportedTypeInExportedInterface.js @@ -94,6 +94,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js index 3f5d49f35..54a0f2018 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/InvalidPropertyNames.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js index 66abcf418..a192a1a8b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClass.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js index 138bef6a1..1166d1f62 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSClassStaticFunctions.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js index 426fd8c1a..d45efc771 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/JSValue.js @@ -133,6 +133,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js index 590e84cc3..675aa3798 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedGlobal.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js index 18fb5af6c..6a6c75ef4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedModules.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js index 27bad9aea..f36211310 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/MixedPrivate.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js index 9e6782d12..09ad002a1 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -250,7 +251,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_Greeter_init(nameId, nameBytes.length); - swift.memory.release(nameId); return Greeter.__construct(ret); } greet() { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js index 94a4b73fb..7368e52fa 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -250,7 +251,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_Greeter_init(nameId, nameBytes.length); - swift.memory.release(nameId); return Greeter.__construct(ret); } greet() { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js index f637af601..c4f99c84b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Optionals.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -506,9 +507,6 @@ export async function createInstantiator(options, swift) { nameId = swift.memory.retain(nameBytes); } const ret = instance.exports.bjs_Greeter_init(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); - if (nameId != undefined) { - swift.memory.release(nameId); - } return Greeter.__construct(ret); } greet() { @@ -525,9 +523,6 @@ export async function createInstantiator(options, swift) { nameId = swift.memory.retain(nameBytes); } instance.exports.bjs_Greeter_changeName(this.pointer, +isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); - if (nameId != undefined) { - swift.memory.release(nameId); - } } get name() { instance.exports.bjs_Greeter_name_get(this.pointer); @@ -543,9 +538,6 @@ export async function createInstantiator(options, swift) { valueId = swift.memory.retain(valueBytes); } instance.exports.bjs_Greeter_name_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0); - if (valueId != undefined) { - swift.memory.release(valueId); - } } } class OptionalPropertyHolder extends SwiftHeapObject { @@ -571,9 +563,6 @@ export async function createInstantiator(options, swift) { valueId = swift.memory.retain(valueBytes); } instance.exports.bjs_OptionalPropertyHolder_optionalName_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0); - if (valueId != undefined) { - swift.memory.release(valueId); - } } get optionalAge() { instance.exports.bjs_OptionalPropertyHolder_optionalAge_get(this.pointer); @@ -626,9 +615,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripString(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, roundTripInt: function bjs_roundTripInt(value) { @@ -669,9 +655,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, roundTripMixSyntax: function bjs_roundTripMixSyntax(name) { @@ -684,9 +667,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripMixSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, roundTripSwiftSyntax: function bjs_roundTripSwiftSyntax(name) { @@ -699,9 +679,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripSwiftSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, roundTripMixedSwiftSyntax: function bjs_roundTripMixedSwiftSyntax(name) { @@ -714,9 +691,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripMixedSwiftSyntax(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, roundTripWithSpaces: function bjs_roundTripWithSpaces(value) { @@ -743,9 +717,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundTripOptionalAlias(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (nameId != undefined) { - swift.memory.release(nameId); - } return optResult; }, testMixedOptionals: function bjs_testMixedOptionals(firstName, lastName, age, active) { @@ -765,12 +736,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_testMixedOptionals(+isSome, isSome ? firstNameId : 0, isSome ? firstNameBytes.length : 0, +isSome1, isSome1 ? lastNameId : 0, isSome1 ? lastNameBytes.length : 0, +isSome2, isSome2 ? age : 0, active); const optResult = tmpRetString; tmpRetString = undefined; - if (firstNameId != undefined) { - swift.memory.release(firstNameId); - } - if (lastNameId != undefined) { - swift.memory.release(lastNameId); - } return optResult; }, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js index dd59941f7..83c77397a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveParameters.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js index a67637e58..f1fda2cb7 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PrimitiveReturn.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js index 35bc1d028..b39362233 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/PropertyTypes.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -242,7 +243,6 @@ export async function createInstantiator(options, swift) { const stringValueBytes = textEncoder.encode(stringValue); const stringValueId = swift.memory.retain(stringValueBytes); const ret = instance.exports.bjs_PropertyHolder_init(intValue, floatValue, doubleValue, boolValue, stringValueId, stringValueBytes.length, swift.memory.retain(jsObject)); - swift.memory.release(stringValueId); return PropertyHolder.__construct(ret); } getAllValues() { @@ -289,7 +289,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyHolder_stringValue_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } get readonlyInt() { const ret = instance.exports.bjs_PropertyHolder_readonlyInt_get(this.pointer); @@ -339,7 +338,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyHolder_lazyValue_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } get computedReadonly() { const ret = instance.exports.bjs_PropertyHolder_computedReadonly_get(this.pointer); @@ -355,7 +353,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyHolder_computedReadWrite_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } get observedProperty() { const ret = instance.exports.bjs_PropertyHolder_observedProperty_get(this.pointer); @@ -371,7 +368,6 @@ export async function createInstantiator(options, swift) { const stringValueBytes = textEncoder.encode(stringValue); const stringValueId = swift.memory.retain(stringValueBytes); const ret = instance.exports.bjs_createPropertyHolder(intValue, floatValue, doubleValue, boolValue, stringValueId, stringValueBytes.length, swift.memory.retain(jsObject)); - swift.memory.release(stringValueId); return PropertyHolder.__construct(ret); }, testPropertyHolder: function bjs_testPropertyHolder(holder) { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js index d783e8968..1d413db20 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.js @@ -63,9 +63,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: ResultValues.Tag.Success, cleanup }; } case ResultValues.Tag.Failure: { @@ -106,6 +104,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -632,7 +631,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_MyViewController_updateValue(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } updateCount(count) { const ret = instance.exports.bjs_MyViewController_updateCount(this.pointer, count); @@ -644,8 +642,6 @@ export async function createInstantiator(options, swift) { const suffixBytes = textEncoder.encode(suffix); const suffixId = swift.memory.retain(suffixBytes); instance.exports.bjs_MyViewController_updateLabel(this.pointer, prefixId, prefixBytes.length, suffixId, suffixBytes.length); - swift.memory.release(prefixId); - swift.memory.release(suffixId); } checkEvenCount() { const ret = instance.exports.bjs_MyViewController_checkEvenCount(this.pointer); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js index 892110aca..07f7a3c77 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.Global.js @@ -50,9 +50,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { @@ -93,6 +91,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -341,7 +340,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_Utils_String_static_uppercase(textId, textBytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(textId); return ret; }, }, diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js index f2c93adae..c2c3f9a70 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticFunctions.js @@ -50,9 +50,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { @@ -93,6 +91,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -335,7 +334,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_Utils_String_static_uppercase(textId, textBytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(textId); 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 adb809f6f..3784b5a7e 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.Global.js @@ -48,6 +48,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -279,7 +280,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyClass_static_classVariable_set(valueId, valueBytes.length); - swift.memory.release(valueId); } static get computedProperty() { instance.exports.bjs_PropertyClass_static_computedProperty_get(); @@ -291,7 +291,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyClass_static_computedProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); } static get readOnlyComputed() { const ret = instance.exports.bjs_PropertyClass_static_readOnlyComputed_get(); @@ -311,9 +310,6 @@ export async function createInstantiator(options, swift) { valueId = swift.memory.retain(valueBytes); } instance.exports.bjs_PropertyClass_static_optionalProperty_set(+isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0); - if (valueId != undefined) { - swift.memory.release(valueId); - } } } if (typeof globalThis.PropertyNamespace === 'undefined') { @@ -336,7 +332,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyEnum_static_enumProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); }, get enumConstant() { const ret = instance.exports.bjs_PropertyEnum_static_enumConstant_get(); @@ -352,7 +347,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyEnum_static_computedEnum_set(valueId, valueBytes.length); - swift.memory.release(valueId); } }, PropertyNamespace: { @@ -366,7 +360,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyNamespace_static_namespaceProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); }, get namespaceConstant() { instance.exports.bjs_PropertyNamespace_static_namespaceConstant_get(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js index f1273821a..47f0092af 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StaticProperties.js @@ -48,6 +48,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -279,7 +280,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyClass_static_classVariable_set(valueId, valueBytes.length); - swift.memory.release(valueId); } static get computedProperty() { instance.exports.bjs_PropertyClass_static_computedProperty_get(); @@ -291,7 +291,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyClass_static_computedProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); } static get readOnlyComputed() { const ret = instance.exports.bjs_PropertyClass_static_readOnlyComputed_get(); @@ -311,9 +310,6 @@ export async function createInstantiator(options, swift) { valueId = swift.memory.retain(valueBytes); } instance.exports.bjs_PropertyClass_static_optionalProperty_set(+isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0); - if (valueId != undefined) { - swift.memory.release(valueId); - } } } const exports = { @@ -330,7 +326,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyEnum_static_enumProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); }, get enumConstant() { const ret = instance.exports.bjs_PropertyEnum_static_enumConstant_get(); @@ -346,7 +341,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyEnum_static_computedEnum_set(valueId, valueBytes.length); - swift.memory.release(valueId); } }, PropertyNamespace: { @@ -360,7 +354,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_PropertyNamespace_static_namespaceProperty_set(valueId, valueBytes.length); - swift.memory.release(valueId); }, get namespaceConstant() { instance.exports.bjs_PropertyNamespace_static_namespaceConstant_get(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js index b81a4990b..0f92074d4 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringParameter.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -231,7 +232,6 @@ export async function createInstantiator(options, swift) { const aBytes = textEncoder.encode(a); const aId = swift.memory.retain(aBytes); instance.exports.bjs_checkString(aId, aBytes.length); - swift.memory.release(aId); }, roundtripString: function bjs_roundtripString(a) { const aBytes = textEncoder.encode(a); @@ -239,7 +239,6 @@ export async function createInstantiator(options, swift) { instance.exports.bjs_roundtripString(aId, aBytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(aId); return ret; }, }; diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js index 112f853d4..f86fce218 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/StringReturn.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js index fc2fc58c6..9f8f93c5b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClass.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -270,7 +271,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_Greeter_init(nameId, nameBytes.length); - swift.memory.release(nameId); return Greeter.__construct(ret); } greet() { @@ -283,7 +283,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); instance.exports.bjs_Greeter_changeName(this.pointer, nameId, nameBytes.length); - swift.memory.release(nameId); } get name() { instance.exports.bjs_Greeter_name_get(this.pointer); @@ -295,7 +294,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_Greeter_name_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } } class PublicGreeter extends SwiftHeapObject { diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js index 4df3d5018..3371cf1b3 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosure.js @@ -94,9 +94,7 @@ export async function createInstantiator(options, swift) { const id = swift.memory.retain(bytes); i32Stack.push(bytes.length); i32Stack.push(id); - const cleanup = () => { - swift.memory.release(id); - }; + const cleanup = undefined; return { caseId: APIResultValues.Tag.Success, cleanup }; } case APIResultValues.Tag.Failure: { @@ -169,6 +167,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -366,7 +365,6 @@ export async function createInstantiator(options, swift) { instance.exports.invoke_swift_closure_TestModule_10TestModule5ThemeO_5ThemeO(boxPtr, param0Id, param0Bytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(param0Id); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); @@ -469,7 +467,6 @@ export async function createInstantiator(options, swift) { instance.exports.invoke_swift_closure_TestModule_10TestModuleSS_SS(boxPtr, param0Id, param0Bytes.length); const ret = tmpRetString; tmpRetString = undefined; - swift.memory.release(param0Id); if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); @@ -628,9 +625,6 @@ export async function createInstantiator(options, swift) { instance.exports.invoke_swift_closure_TestModule_10TestModuleSq5ThemeO_Sq5ThemeO(boxPtr, +isSome, isSome ? param0Id : 0, isSome ? param0Bytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (param0Id != undefined) { - swift.memory.release(param0Id); - } if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); @@ -772,9 +766,6 @@ export async function createInstantiator(options, swift) { instance.exports.invoke_swift_closure_TestModule_10TestModuleSqSS_SqSS(boxPtr, +isSome, isSome ? param0Id : 0, isSome ? param0Bytes.length : 0); const optResult = tmpRetString; tmpRetString = undefined; - if (param0Id != undefined) { - swift.memory.release(param0Id); - } if (tmpRetException) { const error = swift.memory.getObject(tmpRetException); swift.memory.release(tmpRetException); @@ -941,7 +932,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_Person_init(nameId, nameBytes.length); - swift.memory.release(nameId); return Person.__construct(ret); } } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js index 8744f5e45..61347e817 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftClosureImports.js @@ -69,6 +69,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js index dca01b33c..316dfb709 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStruct.js @@ -57,10 +57,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome1 ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - }; - return { cleanup }; + return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -104,11 +101,7 @@ export async function createInstantiator(options, swift) { i32Stack.push(0); } i32Stack.push(isSome ? 1 : 0); - const cleanup = () => { - swift.memory.release(id); - swift.memory.release(id1); - }; - return { cleanup }; + return { cleanup: undefined }; }, lift: () => { const isSome = i32Stack.pop(); @@ -147,9 +140,7 @@ export async function createInstantiator(options, swift) { } i32Stack.push(isSome ? 1 : 0); const cleanup = () => { - swift.memory.release(id); if (structResult.cleanup) { structResult.cleanup(); } - if(id1 !== undefined) { swift.memory.release(id1); } }; return { cleanup }; }, @@ -287,6 +278,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } @@ -563,7 +555,6 @@ export async function createInstantiator(options, swift) { const nameBytes = textEncoder.encode(name); const nameId = swift.memory.retain(nameBytes); const ret = instance.exports.bjs_Greeter_init(nameId, nameBytes.length); - swift.memory.release(nameId); return Greeter.__construct(ret); } greet() { @@ -582,7 +573,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_Greeter_name_set(this.pointer, valueId, valueBytes.length); - swift.memory.release(valueId); } } const DataPointHelpers = __bjs_createDataPointHelpers()(); @@ -631,7 +621,6 @@ export async function createInstantiator(options, swift) { const isSome1 = optFlag != null; instance.exports.bjs_DataPoint_init(x, y, labelId, labelBytes.length, +isSome, isSome ? optCount : 0, +isSome1, isSome1 ? optFlag : 0); const structValue = structHelpers.DataPoint.lift(); - swift.memory.release(labelId); return structValue; }, }, @@ -650,7 +639,6 @@ export async function createInstantiator(options, swift) { const valueBytes = textEncoder.encode(value); const valueId = swift.memory.retain(valueBytes); instance.exports.bjs_ConfigStruct_static_defaultConfig_set(valueId, valueBytes.length); - swift.memory.release(valueId); }, get timeout() { const ret = instance.exports.bjs_ConfigStruct_static_timeout_get(); diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js index a33914d89..4962e659b 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/SwiftStructImports.js @@ -58,6 +58,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js index e81050bf6..3726a48ae 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Throws.js @@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js index cdcd6db3a..7c3627d13 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/UnsafePointer.js @@ -63,6 +63,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js index 05a16a3eb..e338c840d 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/VoidParameterVoidReturn.js @@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) { } bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) { const source = swift.memory.getObject(sourceId); + swift.memory.release(sourceId); const bytes = new Uint8Array(memory.buffer, bytesPtr); bytes.set(source); } diff --git a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift index d761e7576..28bdaa6db 100644 --- a/Sources/JavaScriptKit/BridgeJSIntrinsics.swift +++ b/Sources/JavaScriptKit/BridgeJSIntrinsics.swift @@ -716,6 +716,12 @@ private func _swift_js_init_memory_extern(_ sourceId: Int32, _ ptr: UnsafeMutabl } #endif +/// Initializes WebAssembly memory with a Uint8Array referenced by `sourceId` at `ptr`. +/// Note that the ownership of the source Uint8Array id is taken by the callee, so callers +/// must not release the source Uint8Array id by themselves. +/// +/// - Parameter sourceId: The object ID of the source Uint8Array. +/// - Parameter ptr: The pointer to the WebAssembly memory to initialize. @_spi(BridgeJS) @inline(never) public func _swift_js_init_memory(_ sourceId: Int32, _ ptr: UnsafeMutablePointer) { _swift_js_init_memory_extern(sourceId, ptr)