installFunction

abstract fun installFunction(funcSignature: JsString, function: JsFunction): WasmPointer(source)

Expects a JS function and signature, exactly as for wasm.jsFuncToWasm(). It uses that function to create a WASM-exported function, installs that function to the next available slot of wasm.functionTable(), and returns the function's index in that table (which acts as a pointer to that function). The returned pointer can be passed to wasm.uninstallFunction() to uninstall it and free up the table slot for reuse.

As a special case, if the passed-in function is a WASM-exported function then the signature argument is ignored and func is installed as-is, without requiring re-compilation/re-wrapping.

This function will propagate an exception if WebAssembly.Table.grow() throws or wasm.jsFuncToWasm() throws. The former case can happen in an Emscripten-compiled environment when building without Emscripten's -sALLOW_TABLE_GROWTH flag.