Truly independent web browser
LibWeb: Give WebAssembly GC objects a non-extensible shape
Shannon Boothe1f592ca1b64
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_assembly/gc_object.rs b/Libraries/LibWeb/Bindings/Rust/src/web_assembly/gc_object.rsindex 2d5dcb39b00..fe15aaf3ce1 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_assembly/gc_object.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_assembly/gc_object.rs@@ -166,6 +166,8 @@ pub(crate) fn create_exported_gc_object(vm: &Vm, reference: u64) -> Gc<Object> {)}.upcast::<Object>();+ // NB: [[IsExtensible]] is always false, which caches of property additions rely on the shape to tell.+ object.set_non_extensible(vm);// 5. Set map[objectaddr] to object.set_host_object(cell, object);diff --git a/Tests/LibWeb/Text/expected/Wasm/WebAssembly-gc-objects-and-cached-additions.txt b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-gc-objects-and-cached-additions.txtnew file mode 100644index 00000000000..a9ac31e6725--- /dev/null+++ b/Tests/LibWeb/Text/expected/Wasm/WebAssembly-gc-objects-and-cached-additions.txt@@ -0,0 +1,3 @@+named: TypeError+keyed: TypeError+extensible: false, own keys: 0, x: 1diff --git a/Tests/LibWeb/Text/input/Wasm/WebAssembly-gc-objects-and-cached-additions.html b/Tests/LibWeb/Text/input/Wasm/WebAssembly-gc-objects-and-cached-additions.htmlnew file mode 100644index 00000000000..e534bccfc71--- /dev/null+++ b/Tests/LibWeb/Text/input/Wasm/WebAssembly-gc-objects-and-cached-additions.html@@ -0,0 +1,74 @@+<!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>