Skip to content

Commit a9dae88

Browse files
BridgeJSLink: remove cleanup hooks
1 parent c6ae64f commit a9dae88

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

+116
-854
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ public struct BridgeJSLink {
296296
printer.write(
297297
"const source = \(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).getObject(sourceId);"
298298
)
299-
printer.write("\(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).release(sourceId);")
299+
printer.write(
300+
"\(JSGlueVariableScope.reservedSwift).\(JSGlueVariableScope.reservedMemory).release(sourceId);"
301+
)
300302
printer.write(
301303
"const bytes = new Uint8Array(\(JSGlueVariableScope.reservedMemory).buffer, bytesPtr);"
302304
)

Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift

Lines changed: 23 additions & 124 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export async function createInstantiator(options, swift) {
3636
let f32Stack = [];
3737
let f64Stack = [];
3838
let ptrStack = [];
39-
let tmpStructCleanups = [];
4039
const enumHelpers = {};
4140
const structHelpers = {};
4241

@@ -122,21 +121,8 @@ export async function createInstantiator(options, swift) {
122121
bjs["swift_js_pop_pointer"] = function() {
123122
return ptrStack.pop();
124123
}
125-
bjs["swift_js_struct_cleanup"] = function(cleanupId) {
126-
if (cleanupId === 0) { return; }
127-
const index = (cleanupId | 0) - 1;
128-
const cleanup = tmpStructCleanups[index];
129-
tmpStructCleanups[index] = null;
130-
if (cleanup) { cleanup(); }
131-
while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) {
132-
tmpStructCleanups.pop();
133-
}
134-
}
135124
bjs["swift_js_struct_lower_Point"] = function(objectId) {
136-
const { cleanup: cleanup } = structHelpers.Point.lower(swift.memory.getObject(objectId));
137-
if (cleanup) {
138-
return tmpStructCleanups.push(cleanup);
139-
}
125+
structHelpers.Point.lower(swift.memory.getObject(objectId));
140126
return 0;
141127
}
142128
bjs["swift_js_struct_lift_Point"] = function() {
@@ -274,7 +260,6 @@ export async function createInstantiator(options, swift) {
274260
TestModule["bjs_importGetNumbers"] = function bjs_importGetNumbers() {
275261
try {
276262
let ret = imports.importGetNumbers();
277-
const arrayCleanups = [];
278263
for (const elem of ret) {
279264
f64Stack.push(elem);
280265
}
@@ -293,7 +278,6 @@ export async function createInstantiator(options, swift) {
293278
}
294279
arrayResult.reverse();
295280
let ret = imports.importTransformNumbers(arrayResult);
296-
const arrayCleanups = [];
297281
for (const elem of ret) {
298282
f64Stack.push(elem);
299283
}
@@ -312,7 +296,6 @@ export async function createInstantiator(options, swift) {
312296
}
313297
arrayResult.reverse();
314298
let ret = imports.importProcessStrings(arrayResult);
315-
const arrayCleanups = [];
316299
for (const elem of ret) {
317300
const bytes = textEncoder.encode(elem);
318301
const id = swift.memory.retain(bytes);
@@ -334,7 +317,6 @@ export async function createInstantiator(options, swift) {
334317
}
335318
arrayResult.reverse();
336319
let ret = imports.importProcessBooleans(arrayResult);
337-
const arrayCleanups = [];
338320
for (const elem of ret) {
339321
i32Stack.push(elem ? 1 : 0);
340322
}
@@ -386,7 +368,6 @@ export async function createInstantiator(options, swift) {
386368
const exports = {
387369
Item,
388370
processIntArray: function bjs_processIntArray(values) {
389-
const arrayCleanups = [];
390371
for (const elem of values) {
391372
i32Stack.push((elem | 0));
392373
}
@@ -402,7 +383,6 @@ export async function createInstantiator(options, swift) {
402383
return arrayResult;
403384
},
404385
processStringArray: function bjs_processStringArray(values) {
405-
const arrayCleanups = [];
406386
for (const elem of values) {
407387
const bytes = textEncoder.encode(elem);
408388
const id = swift.memory.retain(bytes);
@@ -421,7 +401,6 @@ export async function createInstantiator(options, swift) {
421401
return arrayResult;
422402
},
423403
processDoubleArray: function bjs_processDoubleArray(values) {
424-
const arrayCleanups = [];
425404
for (const elem of values) {
426405
f64Stack.push(elem);
427406
}
@@ -437,7 +416,6 @@ export async function createInstantiator(options, swift) {
437416
return arrayResult;
438417
},
439418
processBoolArray: function bjs_processBoolArray(values) {
440-
const arrayCleanups = [];
441419
for (const elem of values) {
442420
i32Stack.push(elem ? 1 : 0);
443421
}
@@ -453,7 +431,6 @@ export async function createInstantiator(options, swift) {
453431
return arrayResult;
454432
},
455433
processPointArray: function bjs_processPointArray(points) {
456-
const arrayCleanups = [];
457434
for (const elem of points) {
458435
structHelpers.Point.lower(elem);
459436
}
@@ -469,7 +446,6 @@ export async function createInstantiator(options, swift) {
469446
return arrayResult;
470447
},
471448
processDirectionArray: function bjs_processDirectionArray(directions) {
472-
const arrayCleanups = [];
473449
for (const elem of directions) {
474450
i32Stack.push((elem | 0));
475451
}
@@ -485,7 +461,6 @@ export async function createInstantiator(options, swift) {
485461
return arrayResult;
486462
},
487463
processStatusArray: function bjs_processStatusArray(statuses) {
488-
const arrayCleanups = [];
489464
for (const elem of statuses) {
490465
i32Stack.push((elem | 0));
491466
}
@@ -501,7 +476,6 @@ export async function createInstantiator(options, swift) {
501476
return arrayResult;
502477
},
503478
sumIntArray: function bjs_sumIntArray(values) {
504-
const arrayCleanups = [];
505479
for (const elem of values) {
506480
i32Stack.push((elem | 0));
507481
}
@@ -510,7 +484,6 @@ export async function createInstantiator(options, swift) {
510484
return ret;
511485
},
512486
findFirstPoint: function bjs_findFirstPoint(points, matching) {
513-
const arrayCleanups = [];
514487
for (const elem of points) {
515488
structHelpers.Point.lower(elem);
516489
}
@@ -522,7 +495,6 @@ export async function createInstantiator(options, swift) {
522495
return structValue;
523496
},
524497
processUnsafeRawPointerArray: function bjs_processUnsafeRawPointerArray(values) {
525-
const arrayCleanups = [];
526498
for (const elem of values) {
527499
ptrStack.push((elem | 0));
528500
}
@@ -538,7 +510,6 @@ export async function createInstantiator(options, swift) {
538510
return arrayResult;
539511
},
540512
processUnsafeMutableRawPointerArray: function bjs_processUnsafeMutableRawPointerArray(values) {
541-
const arrayCleanups = [];
542513
for (const elem of values) {
543514
ptrStack.push((elem | 0));
544515
}
@@ -554,7 +525,6 @@ export async function createInstantiator(options, swift) {
554525
return arrayResult;
555526
},
556527
processOpaquePointerArray: function bjs_processOpaquePointerArray(values) {
557-
const arrayCleanups = [];
558528
for (const elem of values) {
559529
ptrStack.push((elem | 0));
560530
}
@@ -570,7 +540,6 @@ export async function createInstantiator(options, swift) {
570540
return arrayResult;
571541
},
572542
processOptionalIntArray: function bjs_processOptionalIntArray(values) {
573-
const arrayCleanups = [];
574543
for (const elem of values) {
575544
const isSome = elem != null ? 1 : 0;
576545
if (isSome) {
@@ -599,7 +568,6 @@ export async function createInstantiator(options, swift) {
599568
return arrayResult;
600569
},
601570
processOptionalStringArray: function bjs_processOptionalStringArray(values) {
602-
const arrayCleanups = [];
603571
for (const elem of values) {
604572
const isSome = elem != null ? 1 : 0;
605573
if (isSome) {
@@ -633,9 +601,7 @@ export async function createInstantiator(options, swift) {
633601
},
634602
processOptionalArray: function bjs_processOptionalArray(values) {
635603
const isSome = values != null;
636-
const valuesCleanups = [];
637604
if (isSome) {
638-
const arrayCleanups = [];
639605
for (const elem of values) {
640606
i32Stack.push((elem | 0));
641607
}
@@ -660,7 +626,6 @@ export async function createInstantiator(options, swift) {
660626
return optResult;
661627
},
662628
processOptionalPointArray: function bjs_processOptionalPointArray(points) {
663-
const arrayCleanups = [];
664629
for (const elem of points) {
665630
const isSome = elem != null ? 1 : 0;
666631
if (isSome) {
@@ -688,7 +653,6 @@ export async function createInstantiator(options, swift) {
688653
return arrayResult;
689654
},
690655
processOptionalDirectionArray: function bjs_processOptionalDirectionArray(directions) {
691-
const arrayCleanups = [];
692656
for (const elem of directions) {
693657
const isSome = elem != null ? 1 : 0;
694658
if (isSome) {
@@ -717,7 +681,6 @@ export async function createInstantiator(options, swift) {
717681
return arrayResult;
718682
},
719683
processOptionalStatusArray: function bjs_processOptionalStatusArray(statuses) {
720-
const arrayCleanups = [];
721684
for (const elem of statuses) {
722685
const isSome = elem != null ? 1 : 0;
723686
if (isSome) {
@@ -746,9 +709,7 @@ export async function createInstantiator(options, swift) {
746709
return arrayResult;
747710
},
748711
processNestedIntArray: function bjs_processNestedIntArray(values) {
749-
const arrayCleanups = [];
750712
for (const elem of values) {
751-
const arrayCleanups1 = [];
752713
for (const elem1 of elem) {
753714
i32Stack.push((elem1 | 0));
754715
}
@@ -772,9 +733,7 @@ export async function createInstantiator(options, swift) {
772733
return arrayResult;
773734
},
774735
processNestedStringArray: function bjs_processNestedStringArray(values) {
775-
const arrayCleanups = [];
776736
for (const elem of values) {
777-
const arrayCleanups1 = [];
778737
for (const elem1 of elem) {
779738
const bytes = textEncoder.encode(elem1);
780739
const id = swift.memory.retain(bytes);
@@ -801,9 +760,7 @@ export async function createInstantiator(options, swift) {
801760
return arrayResult;
802761
},
803762
processNestedPointArray: function bjs_processNestedPointArray(points) {
804-
const arrayCleanups = [];
805763
for (const elem of points) {
806-
const arrayCleanups1 = [];
807764
for (const elem1 of elem) {
808765
structHelpers.Point.lower(elem1);
809766
}
@@ -827,7 +784,6 @@ export async function createInstantiator(options, swift) {
827784
return arrayResult;
828785
},
829786
processItemArray: function bjs_processItemArray(items) {
830-
const arrayCleanups = [];
831787
for (const elem of items) {
832788
ptrStack.push(elem.pointer);
833789
}
@@ -844,9 +800,7 @@ export async function createInstantiator(options, swift) {
844800
return arrayResult;
845801
},
846802
processNestedItemArray: function bjs_processNestedItemArray(items) {
847-
const arrayCleanups = [];
848803
for (const elem of items) {
849-
const arrayCleanups1 = [];
850804
for (const elem1 of elem) {
851805
ptrStack.push(elem1.pointer);
852806
}
@@ -871,7 +825,6 @@ export async function createInstantiator(options, swift) {
871825
return arrayResult;
872826
},
873827
processJSObjectArray: function bjs_processJSObjectArray(objects) {
874-
const arrayCleanups = [];
875828
for (const elem of objects) {
876829
const objId = swift.memory.retain(elem);
877830
i32Stack.push(objId);
@@ -890,7 +843,6 @@ export async function createInstantiator(options, swift) {
890843
return arrayResult;
891844
},
892845
processOptionalJSObjectArray: function bjs_processOptionalJSObjectArray(objects) {
893-
const arrayCleanups = [];
894846
for (const elem of objects) {
895847
const isSome = elem != null ? 1 : 0;
896848
if (isSome) {
@@ -922,9 +874,7 @@ export async function createInstantiator(options, swift) {
922874
return arrayResult;
923875
},
924876
processNestedJSObjectArray: function bjs_processNestedJSObjectArray(objects) {
925-
const arrayCleanups = [];
926877
for (const elem of objects) {
927-
const arrayCleanups1 = [];
928878
for (const elem1 of elem) {
929879
const objId = swift.memory.retain(elem1);
930880
i32Stack.push(objId);

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export async function createInstantiator(options, swift) {
2323
let f32Stack = [];
2424
let f64Stack = [];
2525
let ptrStack = [];
26-
let tmpStructCleanups = [];
2726
const enumHelpers = {};
2827
const structHelpers = {};
2928

@@ -94,16 +93,6 @@ export async function createInstantiator(options, swift) {
9493
bjs["swift_js_pop_pointer"] = function() {
9594
return ptrStack.pop();
9695
}
97-
bjs["swift_js_struct_cleanup"] = function(cleanupId) {
98-
if (cleanupId === 0) { return; }
99-
const index = (cleanupId | 0) - 1;
100-
const cleanup = tmpStructCleanups[index];
101-
tmpStructCleanups[index] = null;
102-
if (cleanup) { cleanup(); }
103-
while (tmpStructCleanups.length > 0 && tmpStructCleanups[tmpStructCleanups.length - 1] == null) {
104-
tmpStructCleanups.pop();
105-
}
106-
}
10796
bjs["swift_js_return_optional_bool"] = function(isSome, value) {
10897
if (isSome === 0) {
10998
tmpRetOptionalBool = null;

0 commit comments

Comments
 (0)