LibJS: Fix Object.getOwnPropertyDescriptor() attributes for numeric property

We were getting the attributes of the existing value and then
immediately assigned the default attributes instead.
This commit is contained in:
Linus Groh 2021-04-20 18:42:10 +02:00
parent 09f8d52b00
commit 614bad86bc
Notes: sideshowbarker 2024-07-18 19:19:54 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -387,7 +387,6 @@ Optional<PropertyDescriptor> Object::get_own_property_descriptor(const PropertyN
return {}; return {};
value = existing_value.value().value; value = existing_value.value().value;
attributes = existing_value.value().attributes; attributes = existing_value.value().attributes;
attributes = default_attributes;
} else { } else {
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())

View file

@ -46,11 +46,13 @@ test("setter property", () => {
test("defined property", () => { test("defined property", () => {
let o = {}; let o = {};
Object.defineProperty(o, "foo", { const attributes = {
enumerable: false, enumerable: false,
writable: true, writable: true,
value: 10, value: 10,
}); };
Object.defineProperty(o, "foo", attributes);
Object.defineProperty(o, 1, attributes);
expect(o).not.toHaveConfigurableProperty("foo"); expect(o).not.toHaveConfigurableProperty("foo");
expect(o).not.toHaveEnumerableProperty("foo"); expect(o).not.toHaveEnumerableProperty("foo");
@ -58,4 +60,11 @@ test("defined property", () => {
expect(o).toHaveValueProperty("foo", 10); expect(o).toHaveValueProperty("foo", 10);
expect(o).not.toHaveGetterProperty("foo"); expect(o).not.toHaveGetterProperty("foo");
expect(o).not.toHaveSetterProperty("foo"); expect(o).not.toHaveSetterProperty("foo");
expect(o).not.toHaveConfigurableProperty(1);
expect(o).not.toHaveEnumerableProperty(1);
expect(o).toHaveWritableProperty(1);
expect(o).toHaveValueProperty(1, 10);
expect(o).not.toHaveGetterProperty(1);
expect(o).not.toHaveSetterProperty(1);
}); });