
Show HN: Does your browser supports WebAssembly? - joway
https://wasm.joway.io/
======
_Microft
I'm not up-to-date regarding JS programming, so: why is this solved as it is,
i.e. as anonymous function that is immediately called? First idea would be to
prevent leaking anything into a global context but this shouldn't be an issue
here. Can anyone explain?

    
    
        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?

~~~
joway
Hi, actually, the function is referenced from
[https://stackoverflow.com/questions/47879864/how-can-i-
check...](https://stackoverflow.com/questions/47879864/how-can-i-check-if-a-
browser-supports-webassembly) . :(

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.

------
ggreer
It just seems to display a blank blue page on browsers that don’t support
WebAssembly. I tested on Safari 9 and the Nintendo 3DS browser.

~~~
joway
hi, ggreer, I fixed some browser compatibility issues. Could you try it again?
Thanks!

~~~
ggreer
Now it shows a red screen with the message, “Your browser does NOT support
WebAssembly!”

Thanks for fixing that.

------
TACIXAT
Could you save some of this data and show a table of what has been checked?
Guess I could just check caniuse.

~~~
tta
[https://developer.mozilla.org/en-
US/docs/WebAssembly#Browser...](https://developer.mozilla.org/en-
US/docs/WebAssembly#Browser_compatibility)

------
maxgraey
if you want not only check supporting WebAssembly but also support by version,
which post-MVP feature currently support in your browser like simd, threads,
multi-values and etc check this package:

btw it use only WebAssembly.validate which much faster and synchronous:

[https://www.npmjs.com/package/wasm-check](https://www.npmjs.com/package/wasm-
check)

