Skip to content

Truly independent web browser

4.0 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<script>
    // (module
    //   (type $point (struct (field i32)))
    //   (import "m" "tag" (tag $imported (param i32)))
    //   (import "m" "throws" (func $throws))
    //   (tag $own (export "own") (param i32 i64))
    //   (export "imported" (tag $imported))
    //   (func (export "throwOwn") (param i32 i64) (throw $own (local.get 0) (local.get 1)))
    //   (func (export "callThrows") (call $throws))
    //   (func (export "catchImported") (result i32)
    //     (block $handler (result i32)
    //       (try_table (catch $imported $handler) (call $throws))
    //       (i32.const -1)))
    //   (func (export "makePoint") (param i32) (result (ref $point)) (struct.new $point (local.get 0)))
    //   (func (export "pointX") (param (ref $point)) (result i32) (struct.get $point 0 (local.get 0)))
    //   (func (export "identity") (param anyref) (result anyref) (local.get 0)))
    const bytes = new Uint8Array([
        0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x26, 0x08, 0x5f, 0x01, 0x7f, 0x00, 0x60,
        0x01, 0x7f, 0x00, 0x60, 0x00, 0x00, 0x60, 0x02, 0x7f, 0x7e, 0x00, 0x60, 0x00, 0x01, 0x7f, 0x60,
        0x01, 0x7f, 0x01, 0x64, 0x00, 0x60, 0x01, 0x64, 0x00, 0x01, 0x7f, 0x60, 0x01, 0x6e, 0x01, 0x6e,
        0x02, 0x15, 0x02, 0x01, 0x6d, 0x03, 0x74, 0x61, 0x67, 0x04, 0x00, 0x01, 0x01, 0x6d, 0x06, 0x74,
        0x68, 0x72, 0x6f, 0x77, 0x73, 0x00, 0x02, 0x03, 0x07, 0x06, 0x03, 0x02, 0x04, 0x05, 0x06, 0x07,
        0x0d, 0x03, 0x01, 0x00, 0x03, 0x07, 0x5a, 0x08, 0x03, 0x6f, 0x77, 0x6e, 0x04, 0x01, 0x08, 0x69,
        0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x04, 0x00, 0x08, 0x74, 0x68, 0x72, 0x6f, 0x77, 0x4f,
        0x77, 0x6e, 0x00, 0x01, 0x0a, 0x63, 0x61, 0x6c, 0x6c, 0x54, 0x68, 0x72, 0x6f, 0x77, 0x73, 0x00,
        0x02, 0x0d, 0x63, 0x61, 0x74, 0x63, 0x68, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x00,
        0x03, 0x09, 0x6d, 0x61, 0x6b, 0x65, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x00, 0x04, 0x06, 0x70, 0x6f,
        0x69, 0x6e, 0x74, 0x58, 0x00, 0x05, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x00,
        0x06, 0x0a, 0x36, 0x06, 0x08, 0x00, 0x20, 0x00, 0x20, 0x01, 0x08, 0x01, 0x0b, 0x04, 0x00, 0x10,
        0x00, 0x0b, 0x10, 0x00, 0x02, 0x7f, 0x1f, 0x40, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0b, 0x41,
        0x7f, 0x0b, 0x0b, 0x07, 0x00, 0x20, 0x00, 0xfb, 0x00, 0x00, 0x0b, 0x08, 0x00, 0x20, 0x00, 0xfb,
        0x02, 0x00, 0x00, 0x0b, 0x04, 0x00, 0x20, 0x00, 0x0b, 0x00, 0x3a, 0x04, 0x6e, 0x61, 0x6d, 0x65,
        0x01, 0x09, 0x01, 0x00, 0x06, 0x74, 0x68, 0x72, 0x6f, 0x77, 0x73, 0x03, 0x0c, 0x01, 0x03, 0x01,
        0x00, 0x07, 0x68, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x04, 0x08, 0x01, 0x00, 0x05, 0x70, 0x6f,
        0x69, 0x6e, 0x74, 0x0b, 0x10, 0x02, 0x00, 0x08, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64,
        0x01, 0x03, 0x6f, 0x77, 0x6e,
    ]);

    test(() => {
        const exports = new WebAssembly.Instance(new WebAssembly.Module(bytes), {
            m: { tag: new WebAssembly.Tag({ parameters: ["i32"] }), throws: () => {} },
        }).exports;
        const point = exports.makePoint(1);

        // Sites whose caches saw additions to objects without a prototype, as Exported GC Objects are.
        function add(object) {
            "use strict";
            object.foo = 1;
        }
        function addByKey(object, key) {
            "use strict";
            object[key] = 1;
        }
        for (let i = 0; i < 20; ++i) {
            add(Object.create(null));
            addByKey(Object.create(null), "bar");
        }

        for (const [name, assign] of [
            ["named", () => add(point)],
            ["keyed", () => addByKey(point, "bar")],
        ]) {
            try {
                assign();
                println(`${name}: no exception`);
            } catch (exception) {
                println(`${name}: ${exception.name}`);
            }
        }
        println(`extensible: ${Object.isExtensible(point)}, own keys: ${Reflect.ownKeys(point).length}, x: ${exports.pointX(point)}`);
    });
</script>