From 614bad86bc02e8ee03387deb81aaa60714d8d8de Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Tue, 20 Apr 2021 18:42:10 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibJS/Runtime/Object.cpp | 1 - .../Object/Object.getOwnPropertyDescriptor.js | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 921f10f1fe5..79e303618b5 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -387,7 +387,6 @@ Optional Object::get_own_property_descriptor(const PropertyN return {}; value = existing_value.value().value; attributes = existing_value.value().attributes; - attributes = default_attributes; } else { auto metadata = shape().lookup(property_name.to_string_or_symbol()); if (!metadata.has_value()) diff --git a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js index 3b69241d9d1..d854c8c75d5 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyDescriptor.js @@ -46,11 +46,13 @@ test("setter property", () => { test("defined property", () => { let o = {}; - Object.defineProperty(o, "foo", { + const attributes = { enumerable: false, writable: true, value: 10, - }); + }; + Object.defineProperty(o, "foo", attributes); + Object.defineProperty(o, 1, attributes); expect(o).not.toHaveConfigurableProperty("foo"); expect(o).not.toHaveEnumerableProperty("foo"); @@ -58,4 +60,11 @@ test("defined property", () => { expect(o).toHaveValueProperty("foo", 10); expect(o).not.toHaveGetterProperty("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); });