~fd/cane-lang

1f6a5999395e0fb91ff8346906e0ad9ab01a4721 — Ersei Saggi 10 months ago 8971919
Add WASM check
1 files changed, 22 insertions(+), 0 deletions(-)

M cane-wasm/index.html
M cane-wasm/index.html => cane-wasm/index.html +22 -0
@@ 50,6 50,28 @@ arg1 arg2 arg3 (space separated)</textarea
    >
    <pre id="output">Output</pre>
    <script type="module">
      // https://stackoverflow.com/a/47880734
      const 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
      })()

      if (!supported) {
        alert('WebAssembly not supported! This playground will not function.')
      }
      import init, { interpreter } from './pkg/cane_wasm.js'
      window.writeOut = function writeOut(text) {
        document.getElementById('output').innerText += text