1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:17:35 +00:00

LibJS: Add %TypedArray%.prototype.find

This commit is contained in:
Luke 2021-06-18 03:57:53 +01:00 committed by Linus Groh
parent 65ca2d98af
commit 61a8c19556
3 changed files with 124 additions and 0 deletions

View file

@ -27,6 +27,7 @@ void TypedArrayPrototype::initialize(GlobalObject& object)
define_native_accessor(vm.names.byteOffset, byte_offset_getter, nullptr, Attribute::Configurable);
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);
}
TypedArrayPrototype::~TypedArrayPrototype()
@ -139,6 +140,20 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::every)
return Value(result);
}
// 23.2.3.10 %TypedArray%.prototype.find ( predicate [ , thisArg ] ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.find
JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find)
{
auto result = js_undefined();
for_each_item(vm, global_object, "find", [&](auto, auto value, auto callback_result) {
if (callback_result.to_boolean()) {
result = value;
return IterationDecision::Break;
}
return IterationDecision::Continue;
});
return result;
}
// 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

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