Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 1 addition & 3 deletions site/source/docs/api_reference/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ Other methods

.. js:function:: Module.instantiateWasm

When targeting WebAssembly, Module.instantiateWasm is an optional user-implemented callback function that the Emscripten runtime calls to perform the WebAssembly instantiation action. The callback function will be called with two parameters, ``imports`` and ``successCallback``. ``imports`` is a JS object which contains all the function imports that need to be passed to the WebAssembly Module when instantiating, and once instantiated, this callback function should call ``successCallback()`` with the generated WebAssembly Instance object.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put Module.instantiateWasm in double backticks here?

Also, can you wrap these lines at 80 columns?


The instantiation can be performed either synchronously or asynchronously. The return value of this function should contain the ``exports`` object of the instantiated WebAssembly Module, or an empty dictionary object ``{}`` if the instantiation is performed asynchronously, or ``false`` if instantiation failed.
When targeting WebAssembly, Module.instantiateWasm is an optional user-implemented callback function that the Emscripten runtime calls to perform the WebAssembly instantiation action. The callback function will be called with three parameters, ``imports``, ``successCallback`` and ``errorCallback``. ``imports`` is a JS object which contains all the function imports that need to be passed to the WebAssembly Module when instantiating. Once instantiated, this callback function should call ``successCallback(instance, module)`` with the generated WebAssembly Instance and Module objects. The instantiation can be performed either synchronously or asynchronously. If an error occurs during instantiation, the callback function should call ``errorCallback(error)``.

Overriding the WebAssembly instantiation procedure via this function is useful when you have other custom asynchronous startup actions or downloads that can be performed in parallel to WebAssembly compilation. Implementing this callback allows performing all of these in parallel. See the file ``test/manual_wasm_instantiate.html`` and the test ``browser.test_manual_wasm_instantiate`` for an example of how this construct works in action.

Expand Down
8 changes: 4 additions & 4 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ function getWasmImports() {
var info = getWasmImports();

#if expectToReceiveOnModule('instantiateWasm')
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback
// User shell pages can write their own Module.instantiateWasm = function(imports, successCallback, errorCallback) callback
// to manually instantiate the Wasm module themselves. This allows pages to
// run the instantiation parallel to any other async startup actions they are
// performing.
Expand All @@ -989,10 +989,10 @@ function getWasmImports() {
#if ASSERTIONS
try {
#endif
Module['instantiateWasm'](info, (mod, inst) => {
receiveInstance(mod, inst);
Module['instantiateWasm'](info, (inst, mod) => {
receiveInstance(inst, mod);
resolve(mod.exports);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this needs to be inst.exports

});
}, reject);
#if ASSERTIONS
} catch(e) {
err(`Module.instantiateWasm callback failed with error: ${e}`);
Expand Down