From f86e24169966df3bee3abcbddb19bb184505f36b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Jun 2021 11:46:08 +0200 Subject: [PATCH] LibJS: Object.getOwnPropertyNames() should enumerate String's .length We were incorrectly aborting property name enumeration after generating names for all the indexable properties in the underlying string. --- Userland/Libraries/LibJS/Runtime/Object.cpp | 2 -- .../Tests/builtins/Object/Object.getOwnPropertyNames.js | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index 22a35e17d7..2bf1f05785 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -299,8 +299,6 @@ MarkedValueList Object::get_own_properties(PropertyKind kind, bool only_enumerab if (vm().exception()) return MarkedValueList { heap() }; } - - return properties; } if (return_type != GetOwnPropertyReturnType::SymbolOnly) { diff --git a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js index da7bccbeba..45d537b47b 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Object/Object.getOwnPropertyNames.js @@ -12,3 +12,8 @@ test("use with object with symbol keys", () => { let names = Object.getOwnPropertyNames({ foo: 1, [Symbol("bar")]: 2, baz: 3 }); expect(names).toEqual(["foo", "baz"]); }); + +test("use with String object", () => { + let names = Object.getOwnPropertyNames(new String("foo")); + expect(names).toEqual(["0", "1", "2", "length"]); +});