Skip to content

Commit 9aad68d

Browse files
BridgeJS: Provide default implementation for BridgeJS functions
This is a workaround for the issue that reference to imported bjs wasm functions can't be eliminated in debug builds, even if they are not reachable at runtime without explicit BridgeJS usage.
1 parent 177be43 commit 9aad68d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Plugins/PackageToJS/Templates/instantiate.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ async function createInstantiator(options, swift) {
2727
* @param {WebAssembly.Imports} importObject
2828
* @param {unknown} importsContext
2929
*/
30-
addImports: (importObject, importsContext) => {},
30+
addImports: (importObject, importsContext) => {
31+
// Provide a default implementation for BridgeJS functions that are not
32+
// used at runtime without BridgeJS but required to instantiate the module.
33+
const unexpectedBjsCall = () => { throw new Error("Unexpected call to BridgeJS function") }
34+
importObject["bjs"] = {
35+
swift_js_return_string: unexpectedBjsCall,
36+
swift_js_init_memory: unexpectedBjsCall,
37+
swift_js_make_js_string: unexpectedBjsCall,
38+
swift_js_init_memory_with_result: unexpectedBjsCall,
39+
swift_js_throw: unexpectedBjsCall,
40+
swift_js_retain: unexpectedBjsCall,
41+
swift_js_release: unexpectedBjsCall,
42+
}
43+
},
3144
/** @param {WebAssembly.Instance} instance */
3245
setInstance: (instance) => {},
3346
/** @param {WebAssembly.Instance} instance */

0 commit comments

Comments
 (0)