1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:38:10 +00:00

LibJS: Fix crash in Object.{freeze,seal}() with indexed properties

This was failing to take two things into account:

- When constructing a PropertyName from a value, it won't automatically
  convert to Type::Number for something like string "0", even though
  that's how things work internally, since indexed properties are stored
  separately. This will be improved in a future patch, it's a footgun
  and should happen automatically.
- Those can't be looked up on the shape, we have to go through the
  indexed properties instead.

Additionally it now operates on the shape or indexed properties directly
as define_property() was overly strict and would throw if a property was
already non-configurable.

Fixes #6469.
This commit is contained in:
Linus Groh 2021-04-20 09:08:40 +02:00
parent 085816645f
commit ac3e7ef791
3 changed files with 72 additions and 5 deletions

View file

@ -47,4 +47,29 @@ describe("normal behavior", () => {
o.foo = "baz";
expect(o.foo).toBe("baz");
});
// #6469
test("works with indexed properties", () => {
const a = ["foo"];
expect(a[0]).toBe("foo");
Object.seal(a);
a[0] = "bar";
a[1] = "baz";
expect(a[0]).toBe("bar");
expect(a[1]).toBeUndefined();
});
test("works with properties that are already non-configurable", () => {
const o = {};
Object.defineProperty(o, "foo", {
value: "bar",
configurable: false,
writable: true,
enumerable: true,
});
expect(o.foo).toBe("bar");
Object.seal(o);
o.foo = "baz";
expect(o.foo).toBe("baz");
});
});