Show HN: Does your browser supports WebAssembly?
wasm.joway.io
wasm.joway.io
var supported = (() => {
try {
if (
typeof WebAssembly === "object" &&
typeof WebAssembly.instantiate === "function"
) {
const module = new WebAssembly.Module(
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)
);
if (module instanceof WebAssembly.Module)
return (
new WebAssembly.Instance(module) instanceof WebAssembly.Instance
);
}
} catch (e) { }
return false;
})();
Edit: is it maybe to save one from having to think about leaking anything, i.e. wrap everything in (() => { ... })(); and call it a day?Unless something else took a reference to it the GC will get it after the main script has run.
But I think there are two reasons to write like that:
1. It avoids multiple assignments, which could make codes cleaner.
2. My website is too simple so maybe there is no enough reason to do such "optimization". But if we are talking about a big project, this initialized global variable could make other codes which required to check if the wasm feature enabled easier and just need to calculate the status one time.
Thanks for fixing that.
btw it use only WebAssembly.validate which much faster and synchronous: