4

When I call an exported function of a WebAssembly module instance, how do Javascript and WebAssembly interact?

instance = WebAssembly.instantiate(bytes)
result = instance.exports.myFunction()

What happens if the .wasm instance enters an infinite loop? Will control eventually be transferred back to the Javascript function that invoked it?

1 Answer 1

5

WebAssembly and JavaScript execute on the same thread. When a JS function invokes an exported wasm function, it yields execution. It only resumes when the wasm function returns. If the wasm function is an infinite loop, your JS code will not be re-entered.

Sign up to request clarification or add additional context in comments.

2 Comments

Does WebAssembly execution block all other asynchronous Javascript functions until it is terminated?
When WebAssembly is being executed, asynchronous JS calls will continue to execute (e.g. webworkers, HTTP requests), but any callbacks / return handlers will not be invoked until the WebAssembly function returns.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.