<!doctype html>
<title>WASM Test</title>
<script>
fetch('https://cdn.rawgit.com/guybedford/wasm-intro/f61eb0d0/1-loading-wasm-fn/test.wasm')
.then(res => {
if (res.ok)
return res.arrayBuffer();
throw new Error(`Unable to fetch WASM.`);
})
.then(bytes => {
return WebAssembly.compile(bytes);
})
.then(module => {
return WebAssembly.instantiate(module);
})
.then(instance => {
window.wasmSqrt = instance.exports.sqrt;
});
</script>
(module
(export "sqrt" (func $sqrt))
(func $sqrt
(param $num f32)
(result f32)
(f32.sqrt (get_local $num))
)
)