host.html raw

   1  <!DOCTYPE html>
   2  <html>
   3  <head><meta charset="utf-8"><title>moxie wasm host</title></head>
   4  <body>
   5  <script type="module">
   6    // Minimal host page: loads a Moxie wasm module through jsruntime/loader.mjs
   7    // and captures its stdout. The module's putchar writes one byte per
   8    // fd_write call, so bytes are accumulated into lines here.
   9    const log = [];
  10    let line = '';
  11    window.__logs = log;
  12    window.__done = false;
  13    window.__error = null;
  14    const errors = [];
  15    window.__consoleErrors = errors;
  16    console.log = (...a) => { for (const x of a) line += String(x); };
  17    console.error = (...a) => { errors.push(a.map(String).join(' ')); };
  18    window.addEventListener('error', e => { window.__error = String(e.message); });
  19    try {
  20      const { load } = await import('/jsruntime/loader.mjs');
  21      await load('/app.wasm');
  22    } catch (e) {
  23      window.__error = String((e && e.stack) || e);
  24    }
  25    if (line) log.push(line);
  26    window.__done = true;
  27  </script>
  28  </body>
  29  </html>
  30