Skip to content

Truly independent web browser

2.2 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<script>
    // (module
    //   (import "m" "tag" (tag $thrown (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)))
    //   (import "m" "throws" (func $throws))
    //   (func $callThrows (call $throws))
    //   (func (export "catchFromCaller") (result i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
    //     (block $handler (result i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
    //       (try_table (catch $thrown $handler) (call $callThrows))
    //       (unreachable))))
    const bytes = new Uint8Array([
        0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x2a, 0x03, 0x60, 0x10, 0x7f, 0x7f, 0x7f,
        0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x60, 0x00,
        0x00, 0x60, 0x00, 0x10, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
        0x7f, 0x7f, 0x7f, 0x7f, 0x02, 0x15, 0x02, 0x01, 0x6d, 0x03, 0x74, 0x61, 0x67, 0x04, 0x00, 0x00,
        0x01, 0x6d, 0x06, 0x74, 0x68, 0x72, 0x6f, 0x77, 0x73, 0x00, 0x01, 0x03, 0x03, 0x02, 0x01, 0x02,
        0x07, 0x13, 0x01, 0x0f, 0x63, 0x61, 0x74, 0x63, 0x68, 0x46, 0x72, 0x6f, 0x6d, 0x43, 0x61, 0x6c,
        0x6c, 0x65, 0x72, 0x00, 0x02, 0x0a, 0x16, 0x02, 0x04, 0x00, 0x10, 0x00, 0x0b, 0x0f, 0x00, 0x02,
        0x02, 0x1f, 0x40, 0x01, 0x00, 0x00, 0x00, 0x10, 0x01, 0x0b, 0x00, 0x0b, 0x0b, 0x00, 0x35, 0x04,
        0x6e, 0x61, 0x6d, 0x65, 0x01, 0x15, 0x02, 0x00, 0x06, 0x74, 0x68, 0x72, 0x6f, 0x77, 0x73, 0x01,
        0x0a, 0x63, 0x61, 0x6c, 0x6c, 0x54, 0x68, 0x72, 0x6f, 0x77, 0x73, 0x03, 0x0c, 0x01, 0x02, 0x01,
        0x00, 0x07, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x0b, 0x09, 0x01, 0x00, 0x06, 0x74, 0x68,
        0x72, 0x6f, 0x77, 0x6e,
    ]);

    test(() => {
        const tag = new WebAssembly.Tag({ parameters: Array(16).fill("i32") });
        const values = Array.from({ length: 16 }, (_, index) => index);
        const exports = new WebAssembly.Instance(new WebAssembly.Module(bytes), {
            m: { tag, throws: () => { throw new WebAssembly.Exception(tag, values); } },
        }).exports;

        println(`values received by the handler: ${exports.catchFromCaller().join(", ")}`);
    });
</script>