Skip to content

Commit 9a0f5f7

Browse files
WIP
1 parent a8b249c commit 9a0f5f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+88
-432
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ public struct BridgeJSLink {
297297
printer.write(
298298
"const source = \(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).getObject(sourceId);"
299299
)
300+
printer.write("\(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).release(sourceId);")
300301
printer.write(
301302
"const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, bytesPtr);"
302303
)

Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift

Lines changed: 4 additions & 70 deletions
Large diffs are not rendered by default.

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/ArrayTypes.js

Lines changed: 5 additions & 67 deletions
Large diffs are not rendered by default.

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export async function createInstantiator(options, swift) {
4343
}
4444
bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) {
4545
const source = swift.memory.getObject(sourceId);
46+
swift.memory.release(sourceId);
4647
const bytes = new Uint8Array(memory.buffer, bytesPtr);
4748
bytes.set(source);
4849
}
@@ -225,7 +226,6 @@ export async function createInstantiator(options, swift) {
225226
const ret = instance.exports.bjs_asyncRoundTripString(vId, vBytes.length);
226227
const ret1 = swift.memory.getObject(ret);
227228
swift.memory.release(ret);
228-
swift.memory.release(vId);
229229
return ret1;
230230
},
231231
asyncRoundTripBool: function bjs_asyncRoundTripBool(v) {

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DefaultParameters.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ export async function createInstantiator(options, swift) {
4444
i32Stack.push(id);
4545
i32Stack.push((value.value | 0));
4646
i32Stack.push(value.enabled ? 1 : 0);
47-
const cleanup = () => {
48-
swift.memory.release(id);
49-
};
50-
return { cleanup };
47+
return { cleanup: undefined };
5148
},
5249
lift: () => {
5350
const bool = i32Stack.pop() !== 0;
@@ -96,6 +93,7 @@ export async function createInstantiator(options, swift) {
9693
}
9794
bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) {
9895
const source = swift.memory.getObject(sourceId);
96+
swift.memory.release(sourceId);
9997
const bytes = new Uint8Array(memory.buffer, bytesPtr);
10098
bytes.set(source);
10199
}
@@ -325,7 +323,6 @@ export async function createInstantiator(options, swift) {
325323
const nameBytes = textEncoder.encode(name);
326324
const nameId = swift.memory.retain(nameBytes);
327325
const ret = instance.exports.bjs_DefaultGreeter_init(nameId, nameBytes.length);
328-
swift.memory.release(nameId);
329326
return DefaultGreeter.__construct(ret);
330327
}
331328
get name() {
@@ -338,7 +335,6 @@ export async function createInstantiator(options, swift) {
338335
const valueBytes = textEncoder.encode(value);
339336
const valueId = swift.memory.retain(valueBytes);
340337
instance.exports.bjs_DefaultGreeter_name_set(this.pointer, valueId, valueBytes.length);
341-
swift.memory.release(valueId);
342338
}
343339
}
344340
class EmptyGreeter extends SwiftHeapObject {
@@ -366,10 +362,6 @@ export async function createInstantiator(options, swift) {
366362
tagId = swift.memory.retain(tagBytes);
367363
}
368364
const ret = instance.exports.bjs_ConstructorDefaults_init(nameId, nameBytes.length, count, enabled, status, +isSome, isSome ? tagId : 0, isSome ? tagBytes.length : 0);
369-
swift.memory.release(nameId);
370-
if (tagId != undefined) {
371-
swift.memory.release(tagId);
372-
}
373365
return ConstructorDefaults.__construct(ret);
374366
}
375367
get name() {
@@ -382,7 +374,6 @@ export async function createInstantiator(options, swift) {
382374
const valueBytes = textEncoder.encode(value);
383375
const valueId = swift.memory.retain(valueBytes);
384376
instance.exports.bjs_ConstructorDefaults_name_set(this.pointer, valueId, valueBytes.length);
385-
swift.memory.release(valueId);
386377
}
387378
get count() {
388379
const ret = instance.exports.bjs_ConstructorDefaults_count_get(this.pointer);
@@ -419,9 +410,6 @@ export async function createInstantiator(options, swift) {
419410
valueId = swift.memory.retain(valueBytes);
420411
}
421412
instance.exports.bjs_ConstructorDefaults_tag_set(this.pointer, +isSome, isSome ? valueId : 0, isSome ? valueBytes.length : 0);
422-
if (valueId != undefined) {
423-
swift.memory.release(valueId);
424-
}
425413
}
426414
}
427415
const ConfigHelpers = __bjs_createConfigHelpers()();
@@ -440,7 +428,6 @@ export async function createInstantiator(options, swift) {
440428
instance.exports.bjs_testStringDefault(messageId, messageBytes.length);
441429
const ret = tmpRetString;
442430
tmpRetString = undefined;
443-
swift.memory.release(messageId);
444431
return ret;
445432
},
446433
testNegativeIntDefault: function bjs_testNegativeIntDefault(value = -42) {
@@ -469,9 +456,6 @@ export async function createInstantiator(options, swift) {
469456
instance.exports.bjs_testOptionalDefault(+isSome, isSome ? nameId : 0, isSome ? nameBytes.length : 0);
470457
const optResult = tmpRetString;
471458
tmpRetString = undefined;
472-
if (nameId != undefined) {
473-
swift.memory.release(nameId);
474-
}
475459
return optResult;
476460
},
477461
testOptionalStringDefault: function bjs_testOptionalStringDefault(greeting = "Hi") {
@@ -484,9 +468,6 @@ export async function createInstantiator(options, swift) {
484468
instance.exports.bjs_testOptionalStringDefault(+isSome, isSome ? greetingId : 0, isSome ? greetingBytes.length : 0);
485469
const optResult = tmpRetString;
486470
tmpRetString = undefined;
487-
if (greetingId != undefined) {
488-
swift.memory.release(greetingId);
489-
}
490471
return optResult;
491472
},
492473
testMultipleDefaults: function bjs_testMultipleDefaults(title = "Default Title", count = 10, enabled = false) {
@@ -495,7 +476,6 @@ export async function createInstantiator(options, swift) {
495476
instance.exports.bjs_testMultipleDefaults(titleId, titleBytes.length, count, enabled);
496477
const ret = tmpRetString;
497478
tmpRetString = undefined;
498-
swift.memory.release(titleId);
499479
return ret;
500480
},
501481
testEnumDefault: function bjs_testEnumDefault(status = StatusValues.Active) {
@@ -526,7 +506,6 @@ export async function createInstantiator(options, swift) {
526506
} else {
527507
optResult = null;
528508
}
529-
if (pointCleanup) { pointCleanup(); }
530509
return optResult;
531510
},
532511
testOptionalStructWithValueDefault: function bjs_testOptionalStructWithValueDefault(point = { name: "default", value: 42, enabled: true }) {
@@ -545,7 +524,6 @@ export async function createInstantiator(options, swift) {
545524
} else {
546525
optResult = null;
547526
}
548-
if (pointCleanup) { pointCleanup(); }
549527
return optResult;
550528
},
551529
testIntArrayDefault: function bjs_testIntArrayDefault(values = [1, 2, 3]) {
@@ -562,7 +540,6 @@ export async function createInstantiator(options, swift) {
562540
arrayResult.push(int);
563541
}
564542
arrayResult.reverse();
565-
for (const cleanup of arrayCleanups) { cleanup(); }
566543
return arrayResult;
567544
},
568545
testStringArrayDefault: function bjs_testStringArrayDefault(names = ["a", "b", "c"]) {
@@ -572,9 +549,6 @@ export async function createInstantiator(options, swift) {
572549
const id = swift.memory.retain(bytes);
573550
i32Stack.push(bytes.length);
574551
i32Stack.push(id);
575-
arrayCleanups.push(() => {
576-
swift.memory.release(id);
577-
});
578552
}
579553
i32Stack.push(names.length);
580554
instance.exports.bjs_testStringArrayDefault();
@@ -585,7 +559,6 @@ export async function createInstantiator(options, swift) {
585559
arrayResult.push(string);
586560
}
587561
arrayResult.reverse();
588-
for (const cleanup of arrayCleanups) { cleanup(); }
589562
return arrayResult;
590563
},
591564
testDoubleArrayDefault: function bjs_testDoubleArrayDefault(values = [1.5, 2.5, 3.5]) {
@@ -602,7 +575,6 @@ export async function createInstantiator(options, swift) {
602575
arrayResult.push(f64);
603576
}
604577
arrayResult.reverse();
605-
for (const cleanup of arrayCleanups) { cleanup(); }
606578
return arrayResult;
607579
},
608580
testBoolArrayDefault: function bjs_testBoolArrayDefault(flags = [true, false, true]) {
@@ -619,7 +591,6 @@ export async function createInstantiator(options, swift) {
619591
arrayResult.push(bool);
620592
}
621593
arrayResult.reverse();
622-
for (const cleanup of arrayCleanups) { cleanup(); }
623594
return arrayResult;
624595
},
625596
testEmptyArrayDefault: function bjs_testEmptyArrayDefault(items = []) {
@@ -636,7 +607,6 @@ export async function createInstantiator(options, swift) {
636607
arrayResult.push(int);
637608
}
638609
arrayResult.reverse();
639-
for (const cleanup of arrayCleanups) { cleanup(); }
640610
return arrayResult;
641611
},
642612
testMixedWithArrayDefault: function bjs_testMixedWithArrayDefault(name = "test", values = [10, 20, 30], enabled = true) {
@@ -650,8 +620,6 @@ export async function createInstantiator(options, swift) {
650620
instance.exports.bjs_testMixedWithArrayDefault(nameId, nameBytes.length, enabled);
651621
const ret = tmpRetString;
652622
tmpRetString = undefined;
653-
swift.memory.release(nameId);
654-
for (const cleanup of arrayCleanups) { cleanup(); }
655623
return ret;
656624
},
657625
Status: StatusValues,

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/DictionaryTypes.js

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function createInstantiator(options, swift) {
4444
}
4545
bjs["swift_js_init_memory"] = function(sourceId, bytesPtr) {
4646
const source = swift.memory.getObject(sourceId);
47+
swift.memory.release(sourceId);
4748
const bytes = new Uint8Array(memory.buffer, bytesPtr);
4849
bytes.set(source);
4950
}
@@ -222,9 +223,6 @@ export async function createInstantiator(options, swift) {
222223
const id = swift.memory.retain(bytes);
223224
i32Stack.push(bytes.length);
224225
i32Stack.push(id);
225-
arrayCleanups.push(() => {
226-
swift.memory.release(id);
227-
});
228226
f64Stack.push(value);
229227
}
230228
i32Stack.push(entries.length);
@@ -280,9 +278,6 @@ export async function createInstantiator(options, swift) {
280278
const id = swift.memory.retain(bytes);
281279
i32Stack.push(bytes.length);
282280
i32Stack.push(id);
283-
arrayCleanups.push(() => {
284-
swift.memory.release(id);
285-
});
286281
i32Stack.push((value | 0));
287282
}
288283
i32Stack.push(entries.length);
@@ -294,7 +289,6 @@ export async function createInstantiator(options, swift) {
294289
const string = strStack.pop();
295290
dictResult[string] = int;
296291
}
297-
for (const cleanup of arrayCleanups) { cleanup(); }
298292
return dictResult;
299293
},
300294
optionalDictionary: function bjs_optionalDictionary(values) {
@@ -309,19 +303,12 @@ export async function createInstantiator(options, swift) {
309303
const id = swift.memory.retain(bytes);
310304
i32Stack.push(bytes.length);
311305
i32Stack.push(id);
312-
arrayCleanups.push(() => {
313-
swift.memory.release(id);
314-
});
315306
const bytes1 = textEncoder.encode(value);
316307
const id1 = swift.memory.retain(bytes1);
317308
i32Stack.push(bytes1.length);
318309
i32Stack.push(id1);
319-
arrayCleanups.push(() => {
320-
swift.memory.release(id1);
321-
});
322310
}
323311
i32Stack.push(entries.length);
324-
valuesCleanups.push(() => { for (const cleanup of arrayCleanups) { cleanup(); } });
325312
}
326313
i32Stack.push(+isSome);
327314
instance.exports.bjs_optionalDictionary();
@@ -339,7 +326,6 @@ export async function createInstantiator(options, swift) {
339326
} else {
340327
optResult = null;
341328
}
342-
for (const cleanup of valuesCleanups) { cleanup(); }
343329
return optResult;
344330
},
345331
nestedDictionary: function bjs_nestedDictionary(values) {
@@ -351,17 +337,11 @@ export async function createInstantiator(options, swift) {
351337
const id = swift.memory.retain(bytes);
352338
i32Stack.push(bytes.length);
353339
i32Stack.push(id);
354-
arrayCleanups.push(() => {
355-
swift.memory.release(id);
356-
});
357340
const arrayCleanups1 = [];
358341
for (const elem of value) {
359342
i32Stack.push((elem | 0));
360343
}
361344
i32Stack.push(value.length);
362-
arrayCleanups.push(() => {
363-
for (const cleanup of arrayCleanups1) { cleanup(); }
364-
});
365345
}
366346
i32Stack.push(entries.length);
367347
instance.exports.bjs_nestedDictionary();
@@ -378,7 +358,6 @@ export async function createInstantiator(options, swift) {
378358
const string = strStack.pop();
379359
dictResult[string] = arrayResult;
380360
}
381-
for (const cleanup of arrayCleanups) { cleanup(); }
382361
return dictResult;
383362
},
384363
boxDictionary: function bjs_boxDictionary(boxes) {
@@ -390,9 +369,6 @@ export async function createInstantiator(options, swift) {
390369
const id = swift.memory.retain(bytes);
391370
i32Stack.push(bytes.length);
392371
i32Stack.push(id);
393-
arrayCleanups.push(() => {
394-
swift.memory.release(id);
395-
});
396372
ptrStack.push(value.pointer);
397373
}
398374
i32Stack.push(entries.length);
@@ -405,7 +381,6 @@ export async function createInstantiator(options, swift) {
405381
const string = strStack.pop();
406382
dictResult[string] = obj;
407383
}
408-
for (const cleanup of arrayCleanups) { cleanup(); }
409384
return dictResult;
410385
},
411386
optionalBoxDictionary: function bjs_optionalBoxDictionary(boxes) {
@@ -417,9 +392,6 @@ export async function createInstantiator(options, swift) {
417392
const id = swift.memory.retain(bytes);
418393
i32Stack.push(bytes.length);
419394
i32Stack.push(id);
420-
arrayCleanups.push(() => {
421-
swift.memory.release(id);
422-
});
423395
const isSome = value != null ? 1 : 0;
424396
if (isSome) {
425397
ptrStack.push(value.pointer);
@@ -445,7 +417,6 @@ export async function createInstantiator(options, swift) {
445417
const string = strStack.pop();
446418
dictResult[string] = optValue;
447419
}
448-
for (const cleanup of arrayCleanups) { cleanup(); }
449420
return dictResult;
450421
},
451422
};

0 commit comments

Comments
 (0)