Skip to content

Commit 0e6f357

Browse files
committed
BridgeJS: Guard FinalizationRegistry deinit callback against Wasm teardown
1 parent bbdf7d5 commit 0e6f357

23 files changed

+138
-23
lines changed

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ public struct BridgeJSLink {
5656
return;
5757
}
5858
state.hasReleased = true;
59-
state.deinit(state.pointer);
59+
try {
60+
state.deinit(state.pointer);
61+
} catch {
62+
// The release call may fail if the Wasm instance has already been torn down
63+
// (e.g. during process exit). Nothing we can do at this point.
64+
}
6065
});
6166
6267
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,12 @@ export async function createInstantiator(options, swift) {
340340
return;
341341
}
342342
state.hasReleased = true;
343-
state.deinit(state.pointer);
343+
try {
344+
state.deinit(state.pointer);
345+
} catch {
346+
// The release call may fail if the Wasm instance has already been torn down
347+
// (e.g. during process exit). Nothing we can do at this point.
348+
}
344349
});
345350

346351
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ export async function createInstantiator(options, swift) {
277277
return;
278278
}
279279
state.hasReleased = true;
280-
state.deinit(state.pointer);
280+
try {
281+
state.deinit(state.pointer);
282+
} catch {
283+
// The release call may fail if the Wasm instance has already been torn down
284+
// (e.g. during process exit). Nothing we can do at this point.
285+
}
281286
});
282287

283288
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ export async function createInstantiator(options, swift) {
235235
return;
236236
}
237237
state.hasReleased = true;
238-
state.deinit(state.pointer);
238+
try {
239+
state.deinit(state.pointer);
240+
} catch {
241+
// The release call may fail if the Wasm instance has already been torn down
242+
// (e.g. during process exit). Nothing we can do at this point.
243+
}
239244
});
240245

241246
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,12 @@ export async function createInstantiator(options, swift) {
972972
return;
973973
}
974974
state.hasReleased = true;
975-
state.deinit(state.pointer);
975+
try {
976+
state.deinit(state.pointer);
977+
} catch {
978+
// The release call may fail if the Wasm instance has already been torn down
979+
// (e.g. during process exit). Nothing we can do at this point.
980+
}
976981
});
977982

978983
/// Represents a Swift heap object like a class instance or an actor instance.

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/EnumNamespace.Global.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ export async function createInstantiator(options, swift) {
261261
return;
262262
}
263263
state.hasReleased = true;
264-
state.deinit(state.pointer);
264+
try {
265+
state.deinit(state.pointer);
266+
} catch {
267+
// The release call may fail if the Wasm instance has already been torn down
268+
// (e.g. during process exit). Nothing we can do at this point.
269+
}
265270
});
266271

267272
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ export async function createInstantiator(options, swift) {
242242
return;
243243
}
244244
state.hasReleased = true;
245-
state.deinit(state.pointer);
245+
try {
246+
state.deinit(state.pointer);
247+
} catch {
248+
// The release call may fail if the Wasm instance has already been torn down
249+
// (e.g. during process exit). Nothing we can do at this point.
250+
}
246251
});
247252

248253
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ export async function createInstantiator(options, swift) {
336336
return;
337337
}
338338
state.hasReleased = true;
339-
state.deinit(state.pointer);
339+
try {
340+
state.deinit(state.pointer);
341+
} catch {
342+
// The release call may fail if the Wasm instance has already been torn down
343+
// (e.g. during process exit). Nothing we can do at this point.
344+
}
340345
});
341346

342347
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ export async function createInstantiator(options, swift) {
209209
return;
210210
}
211211
state.hasReleased = true;
212-
state.deinit(state.pointer);
212+
try {
213+
state.deinit(state.pointer);
214+
} catch {
215+
// The release call may fail if the Wasm instance has already been torn down
216+
// (e.g. during process exit). Nothing we can do at this point.
217+
}
213218
});
214219

215220
/// Represents a Swift heap object like a class instance or an actor instance.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ export async function createInstantiator(options, swift) {
217217
return;
218218
}
219219
state.hasReleased = true;
220-
state.deinit(state.pointer);
220+
try {
221+
state.deinit(state.pointer);
222+
} catch {
223+
// The release call may fail if the Wasm instance has already been torn down
224+
// (e.g. during process exit). Nothing we can do at this point.
225+
}
221226
});
222227

223228
/// Represents a Swift heap object like a class instance or an actor instance.

0 commit comments

Comments
 (0)