diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 4d08481de0..2eace27df2 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -479,7 +479,7 @@ Value ForInStatement::execute(Interpreter& interpreter, GlobalObject& global_obj return {}; auto* object = rhs_result.to_object(global_object); while (object) { - auto property_names = object->get_own_properties(Object::PropertyKind::Key, true); + auto property_names = object->get_enumerable_own_property_names(Object::PropertyKind::Key); for (auto& property_name : property_names.as_object().indexed_properties()) { interpreter.vm().set_variable(variable_name, property_name.value_and_attributes(object).value, global_object, has_declaration); if (interpreter.exception()) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index aff9e0e86b..ba9e56be2f 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Linus Groh * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -262,6 +263,12 @@ Value Object::get_own_properties(PropertyKind kind, bool only_enumerable_propert return properties_array; } +// 7.3.23 EnumerableOwnPropertyNames, https://tc39.es/ecma262/#sec-enumerableownpropertynames +Value Object::get_enumerable_own_property_names(PropertyKind kind) const +{ + return get_own_properties(kind, true, Object::GetOwnPropertyReturnType::StringOnly); +} + Optional Object::get_own_property_descriptor(const PropertyName& property_name) const { VERIFY(property_name.is_valid()); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index e1f5c8dd94..b5b6ba57ad 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2021, Linus Groh * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -96,6 +97,7 @@ public: Value get_own_property(const PropertyName&, Value receiver) const; Value get_own_properties(PropertyKind, bool only_enumerable_properties = false, GetOwnPropertyReturnType = GetOwnPropertyReturnType::StringOnly) const; + Value get_enumerable_own_property_names(PropertyKind) const; virtual Optional get_own_property_descriptor(const PropertyName&) const; Value get_own_property_descriptor_object(const PropertyName&) const; diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 88793ed56d..2551b10d3c 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -209,7 +209,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) if (vm.exception()) return {}; - return obj_arg->get_own_properties(PropertyKind::Key, true); + return obj_arg->get_enumerable_own_property_names(PropertyKind::Key); } JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) @@ -222,7 +222,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) if (vm.exception()) return {}; - return obj_arg->get_own_properties(PropertyKind::Value, true); + return obj_arg->get_enumerable_own_property_names(PropertyKind::Value); } JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) @@ -235,7 +235,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) if (vm.exception()) return {}; - return obj_arg->get_own_properties(PropertyKind::KeyAndValue, true); + return obj_arg->get_enumerable_own_property_names(PropertyKind::KeyAndValue); } }