mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibJS: Port iterator_next() to NonnullGCPtr
This commit is contained in:
parent
b110258848
commit
e54536421a
Notes:
sideshowbarker
2024-07-17 08:38:37 +09:00
4 changed files with 12 additions and 12 deletions
|
@ -277,16 +277,16 @@ ThrowCompletionOr<void> IteratorToArray::execute_impl(Bytecode::Interpreter& int
|
|||
size_t index = 0;
|
||||
|
||||
while (true) {
|
||||
auto* iterator_result = TRY(iterator_next(vm, iterator));
|
||||
auto iterator_result = TRY(iterator_next(vm, iterator));
|
||||
|
||||
auto complete = TRY(iterator_complete(vm, *iterator_result));
|
||||
auto complete = TRY(iterator_complete(vm, iterator_result));
|
||||
|
||||
if (complete) {
|
||||
interpreter.accumulator() = array;
|
||||
return {};
|
||||
}
|
||||
|
||||
auto value = TRY(iterator_value(vm, *iterator_result));
|
||||
auto value = TRY(iterator_value(vm, iterator_result));
|
||||
|
||||
MUST(array->create_data_property_or_throw(index, value));
|
||||
index++;
|
||||
|
|
|
@ -87,12 +87,12 @@ JS_DEFINE_NATIVE_FUNCTION(AsyncFromSyncIteratorPrototype::next)
|
|||
// 6. Else,
|
||||
// a. Let result be Completion(IteratorNext(syncIteratorRecord)).
|
||||
// 7. IfAbruptRejectPromise(result, promiseCapability).
|
||||
auto* result = TRY_OR_REJECT(vm, promise_capability,
|
||||
auto result = TRY_OR_REJECT(vm, promise_capability,
|
||||
(vm.argument_count() > 0 ? iterator_next(vm, sync_iterator_record, vm.argument(0))
|
||||
: iterator_next(vm, sync_iterator_record)));
|
||||
|
||||
// 8. Return AsyncFromSyncIteratorContinuation(result, promiseCapability).
|
||||
return async_from_sync_iterator_continuation(vm, *result, promise_capability);
|
||||
return async_from_sync_iterator_continuation(vm, result, promise_capability);
|
||||
}
|
||||
|
||||
// 27.1.4.2.2 %AsyncFromSyncIteratorPrototype%.return ( [ value ] ), https://tc39.es/ecma262/#sec-%asyncfromsynciteratorprototype%.return
|
||||
|
|
|
@ -68,7 +68,7 @@ ThrowCompletionOr<Iterator> get_iterator(VM& vm, Value value, IteratorHint hint,
|
|||
}
|
||||
|
||||
// 7.4.3 IteratorNext ( iteratorRecord [ , value ] ), https://tc39.es/ecma262/#sec-iteratornext
|
||||
ThrowCompletionOr<Object*> iterator_next(VM& vm, Iterator const& iterator_record, Optional<Value> value)
|
||||
ThrowCompletionOr<NonnullGCPtr<Object>> iterator_next(VM& vm, Iterator const& iterator_record, Optional<Value> value)
|
||||
{
|
||||
Value result;
|
||||
|
||||
|
@ -86,7 +86,7 @@ ThrowCompletionOr<Object*> iterator_next(VM& vm, Iterator const& iterator_record
|
|||
return vm.throw_completion<TypeError>(ErrorType::IterableNextBadReturn);
|
||||
|
||||
// 4. Return result.
|
||||
return &result.as_object();
|
||||
return result.as_object();
|
||||
}
|
||||
|
||||
// 7.4.4 IteratorComplete ( iterResult ), https://tc39.es/ecma262/#sec-iteratorcomplete
|
||||
|
@ -107,17 +107,17 @@ ThrowCompletionOr<Value> iterator_value(VM& vm, Object& iterator_result)
|
|||
ThrowCompletionOr<Object*> iterator_step(VM& vm, Iterator const& iterator_record)
|
||||
{
|
||||
// 1. Let result be ? IteratorNext(iteratorRecord).
|
||||
auto* result = TRY(iterator_next(vm, iterator_record));
|
||||
auto result = TRY(iterator_next(vm, iterator_record));
|
||||
|
||||
// 2. Let done be ? IteratorComplete(result).
|
||||
auto done = TRY(iterator_complete(vm, *result));
|
||||
auto done = TRY(iterator_complete(vm, result));
|
||||
|
||||
// 3. If done is true, return false.
|
||||
if (done)
|
||||
return nullptr;
|
||||
|
||||
// 4. Return result.
|
||||
return result;
|
||||
return result.ptr();
|
||||
}
|
||||
|
||||
// 7.4.7 IteratorClose ( iteratorRecord, completion ), https://tc39.es/ecma262/#sec-iteratorclose
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -23,7 +23,7 @@ enum class IteratorHint {
|
|||
};
|
||||
|
||||
ThrowCompletionOr<Iterator> get_iterator(VM&, Value, IteratorHint = IteratorHint::Sync, Optional<Value> method = {});
|
||||
ThrowCompletionOr<Object*> iterator_next(VM&, Iterator const&, Optional<Value> = {});
|
||||
ThrowCompletionOr<NonnullGCPtr<Object>> iterator_next(VM&, Iterator const&, Optional<Value> = {});
|
||||
ThrowCompletionOr<Object*> iterator_step(VM&, Iterator const&);
|
||||
ThrowCompletionOr<bool> iterator_complete(VM&, Object& iterator_result);
|
||||
ThrowCompletionOr<Value> iterator_value(VM&, Object& iterator_result);
|
||||
|
|
Loading…
Add table
Reference in a new issue