Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ public struct BridgeJSLink {
}
"""

// Both the FinalizationRegistry callback and release() wrap state.deinit() in try/catch
// because either can fire during process shutdown after the Wasm instance is already torn
// down. Calling into Wasm at that point throws RuntimeError (memory access / table index
// out of bounds). There's nothing to do but swallow it - the process is exiting anyway.
let swiftHeapObjectClassJs = """
const swiftHeapObjectFinalizationRegistry = (typeof FinalizationRegistry === "undefined") ? { register: () => {}, unregister: () => {} } : new FinalizationRegistry((state) => {
if (state.hasReleased) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -77,7 +83,9 @@ public struct BridgeJSLink {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -361,7 +363,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Item extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -298,7 +300,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class DefaultGreeter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -256,7 +258,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Box extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -993,7 +995,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class User extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -282,7 +284,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Converter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -263,7 +265,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Converter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -357,7 +359,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class JSValueHolder extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -230,7 +232,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class GlobalClass extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -238,7 +240,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class GlobalClass extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -230,7 +232,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class PrivateClass extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -238,7 +240,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Greeter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -238,7 +240,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Greeter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -490,7 +492,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Greeter extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -230,7 +232,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class PropertyHolder extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -589,7 +591,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class Helper extends SwiftHeapObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ export async function createInstantiator(options, swift) {
return;
}
state.hasReleased = true;
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
});

/// Represents a Swift heap object like a class instance or an actor instance.
Expand All @@ -276,7 +278,9 @@ export async function createInstantiator(options, swift) {
}
state.hasReleased = true;
swiftHeapObjectFinalizationRegistry.unregister(state);
state.deinit(state.pointer);
try {
state.deinit(state.pointer);
} catch {}
}
}
class MathUtils extends SwiftHeapObject {
Expand Down
Loading
Loading