1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:47:45 +00:00

LibJS: Add %TypedArray%.prototype.findIndex

This commit is contained in:
Luke 2021-06-18 03:58:59 +01:00 committed by Linus Groh
parent 61a8c19556
commit 91af985718
3 changed files with 124 additions and 0 deletions

View file

@ -28,6 +28,7 @@ void TypedArrayPrototype::initialize(GlobalObject& object)
define_native_function(vm.names.at, at, 1, attr);
define_native_function(vm.names.every, every, 1, attr);
define_native_function(vm.names.find, find, 1, attr);
define_native_function(vm.names.findIndex, find_index, 1, attr);
}
TypedArrayPrototype::~TypedArrayPrototype()
@ -154,6 +155,20 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find)
return result;
}
// 23.2.3.11 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.findindex
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_index)
{
auto result_index = -1;
for_each_item(vm, global_object, "findIndex", [&](auto index, auto, auto callback_result) {
if (callback_result.to_boolean()) {
result_index = index;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return Value(result_index);
}
// 23.2.3.1 get %TypedArray%.prototype.buffer, https://tc39.es/ecma262/#sec-get-%typedarray%.prototype.buffer
JS_DEFINE_NATIVE_GETTER(TypedArrayPrototype::buffer_getter)
{

View file

@ -27,6 +27,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(at);
JS_DECLARE_NATIVE_FUNCTION(every);
JS_DECLARE_NATIVE_FUNCTION(find);
JS_DECLARE_NATIVE_FUNCTION(find_index);
};
}