From f6749f9dbf1b4b9234b36a147951916e322929a0 Mon Sep 17 00:00:00 2001 From: Halid Odat Date: Tue, 24 Aug 2021 12:56:24 +0200 Subject: [PATCH] Implement `Object.values()` (#1508) --- boa/src/builtins/object/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/boa/src/builtins/object/mod.rs b/boa/src/builtins/object/mod.rs index 0399e7e321..e2ea0adf57 100644 --- a/boa/src/builtins/object/mod.rs +++ b/boa/src/builtins/object/mod.rs @@ -64,6 +64,7 @@ impl BuiltIn for Object { .static_method(Self::assign, "assign", 2) .static_method(Self::is, "is", 2) .static_method(Self::keys, "keys", 1) + .static_method(Self::values, "values", 1) .static_method(Self::entries, "entries", 1) .static_method( Self::get_own_property_descriptor, @@ -613,6 +614,31 @@ impl Object { Ok(result.into()) } + /// `Object.values( target )` + /// + /// More information: + /// - [ECMAScript reference][spec] + /// - [MDN documentation][mdn] + /// + /// [spec]: https://tc39.es/ecma262/#sec-object.values + /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values + pub fn values(_: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { + // 1. Let obj be ? ToObject(target). + let obj = args + .get(0) + .cloned() + .unwrap_or_default() + .to_object(context)?; + + // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, value). + let name_list = obj.enumerable_own_property_names(PropertyNameKind::Value, context)?; + + // 3. Return CreateArrayFromList(nameList). + let result = Array::create_array_from_list(name_list, context); + + Ok(result.into()) + } + /// `Object.entries( target )` /// /// This method returns an array of a given object's own enumerable string-keyed property [key, value] pairs.