1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

LibJS: Implement Array.prototype.entries

This commit is contained in:
davidot 2021-06-13 17:54:24 +02:00 committed by Linus Groh
parent 910b803d8d
commit 417f752306
3 changed files with 56 additions and 0 deletions

View file

@ -64,6 +64,7 @@ void ArrayPrototype::initialize(GlobalObject& global_object)
define_native_function(vm.names.flatMap, flat_map, 1, attr);
define_native_function(vm.names.at, at, 1, attr);
define_native_function(vm.names.keys, keys, 0, attr);
define_native_function(vm.names.entries, entries, 0, attr);
// Use define_property here instead of define_native_function so that
// Object.is(Array.prototype[Symbol.iterator], Array.prototype.values)
@ -1264,6 +1265,16 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::values)
return ArrayIterator::create(global_object, this_object, Object::PropertyKind::Value);
}
// 23.1.3.16 Array.prototype.entries ( ), https://tc39.es/ecma262/#sec-array.prototype.entries
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::entries)
{
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
return ArrayIterator::create(global_object, this_object, Object::PropertyKind::KeyAndValue);
}
// 23.1.3.16 Array.prototype.keys ( ), https://tc39.es/ecma262/#sec-array.prototype.keys
JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::keys)
{

View file

@ -50,6 +50,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(flat_map);
JS_DECLARE_NATIVE_FUNCTION(at);
JS_DECLARE_NATIVE_FUNCTION(keys);
JS_DECLARE_NATIVE_FUNCTION(entries);
};
}