mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:07:46 +00:00
LibJS: Add %TypedArray%.prototype.find
This commit is contained in:
parent
65ca2d98af
commit
61a8c19556
3 changed files with 124 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@ private:
|
|||
|
||||
JS_DECLARE_NATIVE_FUNCTION(at);
|
||||
JS_DECLARE_NATIVE_FUNCTION(every);
|
||||
JS_DECLARE_NATIVE_FUNCTION(find);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue