Truly independent web browser
LibJS: Invalidate stable shapes when reifying lazy function properties
Shannon Boothf38601b211cb
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rsindex 520aeeed65c..2cfa747c90b 100644--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs@@ -412,6 +412,8 @@ impl EcmascriptFunctionObject {self.set_flag(ecmascript_function_flags::HAS_LAZY_LENGTH_AND_NAME, false);let old_shape = self.shape();+ // NB: Rebuilding the shape bypasses transitions away from the old one and moves existing property offsets.+ old_shape.mark_unstable(vm);let realm = old_shape.realm();let mut shape = match self.kind() {FunctionKind::Normal => realm.normal_function_shape(),diff --git a/Tests/LibJS/Runtime/jit/function-lazy-properties.js b/Tests/LibJS/Runtime/jit/function-lazy-properties.jsnew file mode 100644index 00000000000..916d005df9a--- /dev/null+++ b/Tests/LibJS/Runtime/jit/function-lazy-properties.js@@ -0,0 +1,43 @@+const triggers = {+ defineName: object => Object.defineProperty(object, "name", { value: "renamed" }),+ deleteLength: object => delete object.length,+ becomePrototype: object => Object.setPrototypeOf({}, object),+ ownKeys: object => Reflect.ownKeys(object),+ getOwnName: object => Object.getOwnPropertyDescriptor(object, "name"),+};++const factories = {+ normal: () => new Function(""),+ arrow: () => () => {},+ async: () => async function () {},+};++for (const [kind, make] of Object.entries(factories)) {+ for (const [name, trigger] of Object.entries(triggers)) {+ test(`${kind} function reifies lazy properties during a call: ${name}`, () => {+ const victim = make();+ // Give each test a fresh shape, so earlier tests cannot have made it unstable.+ victim[Symbol()] = 0;+ victim.a = 10;+ victim.b = 20;+ let armed = false;+ const poke = object => {+ if (armed) trigger(object);+ };+ const read = new Function(+ "poke",+ "object",+ "const first = object.b; poke(object); return first + object.b;"+ );+ jit.prepare(read);+ for (let i = 0; i < 50; ++i) read(poke, victim);+ expect(jit.compile(read)).toBe(jit.enabled);++ armed = true;+ expect(read(poke, victim)).toBe(40);+ expect(victim.a).toBe(10);+ expect(victim.b).toBe(20);+ expect(read(poke, victim)).toBe(40);+ });+ }+}