mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibJS: Make Object.getOwnPropertyDescriptor() work with string indexed property
E.g. for "0" we have to contruct a PropertyName with Type::Number so it looks in the indexed properties as expected.
This commit is contained in:
parent
614bad86bc
commit
7af1d2c170
2 changed files with 23 additions and 0 deletions
|
@ -388,6 +388,11 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN
|
||||||
value = existing_value.value().value;
|
value = existing_value.value().value;
|
||||||
attributes = existing_value.value().attributes;
|
attributes = existing_value.value().attributes;
|
||||||
} else {
|
} else {
|
||||||
|
if (property_name.is_string()) {
|
||||||
|
i32 property_index = property_name.as_string().to_int().value_or(-1);
|
||||||
|
if (property_index >= 0)
|
||||||
|
return get_own_property_descriptor(property_index);
|
||||||
|
}
|
||||||
auto metadata = shape().lookup(property_name.to_string_or_symbol());
|
auto metadata = shape().lookup(property_name.to_string_or_symbol());
|
||||||
if (!metadata.has_value())
|
if (!metadata.has_value())
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -43,6 +43,24 @@ test("setter property", () => {
|
||||||
expect(o).toHaveSetterProperty("foo");
|
expect(o).toHaveSetterProperty("foo");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("indexed property", () => {
|
||||||
|
let o = { 0: "foo" };
|
||||||
|
|
||||||
|
expect(o).toHaveConfigurableProperty(0);
|
||||||
|
expect(o).toHaveEnumerableProperty(0);
|
||||||
|
expect(o).toHaveWritableProperty(0);
|
||||||
|
expect(o).toHaveValueProperty(0, "foo");
|
||||||
|
expect(o).not.toHaveGetterProperty(0);
|
||||||
|
expect(o).not.toHaveSetterProperty(0);
|
||||||
|
|
||||||
|
expect(o).toHaveConfigurableProperty("0");
|
||||||
|
expect(o).toHaveEnumerableProperty("0");
|
||||||
|
expect(o).toHaveWritableProperty("0");
|
||||||
|
expect(o).toHaveValueProperty("0", "foo");
|
||||||
|
expect(o).not.toHaveGetterProperty("0");
|
||||||
|
expect(o).not.toHaveSetterProperty("0");
|
||||||
|
});
|
||||||
|
|
||||||
test("defined property", () => {
|
test("defined property", () => {
|
||||||
let o = {};
|
let o = {};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue