ladybird/Libraries/LibJS/Tests/regress/inline-caching.js
Aliaksandr Kalenik c3b0eabf18 LibJS: Capture PrototypeChainValidity before executing internal_get()
- Capture PrototypeChainValidity before invoking `internal_get()`. A
  getter may mutate the prototype chain (e.g., delete itself). Capturing
  earlier ensures such mutations invalidate the cached entry and prevent
  stale GetById hits.
- When caching, take PrototypeChainValidity from the base object
  (receiver), not from the prototype where the property was found.
  Otherwise, changes to an intermediate prototype between the base
  object and the cached prototype object go unnoticed, leading to
  incorrect cache hits.
2025-09-18 15:56:20 +02:00

34 lines
804 B
JavaScript

test("Accessor removal during getter execution should bust GetById cache", () => {
function f(obj, expected) {
expect(obj.hm).toBe(expected);
}
const proto = {
get hm() {
delete proto.hm;
return 123;
},
};
const obj = Object.create(proto);
f(obj, 123);
f(obj, undefined);
});
test("Overriding an inherited getter with a data property on an intermediate prototype invalidates prototype-chain cache", () => {
function f(obj, expected) {
expect(obj.hm).toBe(expected);
}
const proto = {};
proto.__proto__ = {
get hm() {
return 123;
},
};
const obj = Object.create(proto);
f(obj, 123);
Object.defineProperty(proto, "hm", { value: 321 });
f(obj, 321);
});