Skip to content

Truly independent web browser

1.3 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<iframe id="frame"></iframe>
<script>
    test(() => {
        // (module (func (export "add") (param i32 i32) (result i32) local.get 0 local.get 1 i32.add))
        const adderBytes = new Uint8Array([
            0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03,
            0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20,
            0x00, 0x20, 0x01, 0x6a, 0x0b,
        ]);

        const frameWindow = document.getElementById("frame").contentWindow;
        const instance = new frameWindow.WebAssembly.Instance(new frameWindow.WebAssembly.Module(adderBytes));
        const exportsGetter = Object.getOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports").get;

        const exports = exportsGetter.call(instance);
        println(`name and length: ${exports.add.name} ${exports.add.length}`);
        println(`call: ${exports.add(20, 22)}`);
        println(`prototype is the instance realm's Function.prototype: ${Object.getPrototypeOf(exports.add) === frameWindow.Function.prototype}`);
        println(`same exports as in the instance realm: ${instance.exports === exports}`);
    });
</script>