GeezerVison is showing developer.mozilla.org — WebAssembly - WebAssembly | MDN
WebAssembly
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.
* Some parts of this feature may have varying levels of support.
The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality.
Unlike most other global objects, WebAssembly is not a constructor (it is not a function object). You can compare it to Math, which is also a namespace object for mathematical constants and functions, or to Intl which is the namespace object for internationalization constructors and other language-sensitive functions.
The primary uses for the WebAssembly object are:
WebAssembly.JSTag
-
A built-in WebAssembly.Tag representing exceptions thrown in the JavaScript host — it allows exceptions thrown in JavaScript to be handled from inside a Wasm module.
The following example (see our instantiate-streaming.html demo on GitHub, and view it live also) directly streams a Wasm module from an underlying source then compiles and instantiates it, the promise fulfilling with a ResultObject. Because the instantiateStreaming() function accepts a promise for a Response object, you can directly pass it a fetch() call, and it will pass the response into the function when it fulfills.
js const importObject = {
my_namespace: { imported_func: (arg) => console.log(arg) },
};
WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
(obj) => obj.instance.exports.exported_func(),
);
The ResultObject's .instance property is then accessed, and the contained exported function invoked.
|