mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
LibJS: Convert ArrayIteratorPrototype functions to ThrowCompletionOr
This commit is contained in:
parent
d1d4ee699b
commit
719d1b48ac
2 changed files with 8 additions and 10 deletions
|
@ -24,7 +24,7 @@ void ArrayIteratorPrototype::initialize(GlobalObject& global_object)
|
|||
auto& vm = this->vm();
|
||||
Object::initialize(global_object);
|
||||
|
||||
define_old_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
|
||||
define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable);
|
||||
|
||||
// 23.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Array Iterator"), Attribute::Configurable);
|
||||
|
@ -36,9 +36,9 @@ ArrayIteratorPrototype::~ArrayIteratorPrototype()
|
|||
|
||||
// 23.1.5.2.1 %ArrayIteratorPrototype%.next ( ), https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
|
||||
// FIXME: This seems to be CreateArrayIterator (https://tc39.es/ecma262/#sec-createarrayiterator) instead of %ArrayIteratorPrototype%.next.
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
||||
JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
||||
{
|
||||
auto* iterator = TRY_OR_DISCARD(typed_this_value(global_object));
|
||||
auto* iterator = TRY(typed_this_value(global_object));
|
||||
auto target_array = iterator->array();
|
||||
if (target_array.is_undefined())
|
||||
return create_iterator_result_object(global_object, js_undefined(), true);
|
||||
|
@ -53,14 +53,12 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
|||
if (array.is_typed_array()) {
|
||||
auto& typed_array = static_cast<TypedArrayBase&>(array);
|
||||
|
||||
if (typed_array.viewed_array_buffer()->is_detached()) {
|
||||
vm.throw_exception<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
||||
return {};
|
||||
}
|
||||
if (typed_array.viewed_array_buffer()->is_detached())
|
||||
return vm.throw_completion<TypeError>(global_object, ErrorType::DetachedArrayBuffer);
|
||||
|
||||
length = typed_array.array_length();
|
||||
} else {
|
||||
length = TRY_OR_DISCARD(length_of_array_like(global_object, array));
|
||||
length = TRY(length_of_array_like(global_object, array));
|
||||
}
|
||||
|
||||
if (index >= length) {
|
||||
|
@ -72,7 +70,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
|
|||
if (iteration_kind == Object::PropertyKind::Key)
|
||||
return create_iterator_result_object(global_object, Value(static_cast<i32>(index)), false);
|
||||
|
||||
auto value = TRY_OR_DISCARD(array.get(index));
|
||||
auto value = TRY(array.get(index));
|
||||
|
||||
if (iteration_kind == Object::PropertyKind::Value)
|
||||
return create_iterator_result_object(global_object, value, false);
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
virtual ~ArrayIteratorPrototype() override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(next);
|
||||
JS_DECLARE_NATIVE_FUNCTION(next);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue