1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 18:55:07 +00:00

LibJS: Port iterator_step() to GCPtr

This commit is contained in:
Linus Groh 2023-04-15 16:23:03 +02:00
parent e54536421a
commit aff1ec6014
12 changed files with 19 additions and 19 deletions

View file

@ -1521,7 +1521,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge
sequence_generator.append(R"~~~( sequence_generator.append(R"~~~(
for (;;) { for (;;) {
auto* next@recursion_depth@ = TRY(JS::iterator_step(vm, iterator@recursion_depth@)); auto next@recursion_depth@ = TRY(JS::iterator_step(vm, iterator@recursion_depth@));
if (!next@recursion_depth@) if (!next@recursion_depth@)
break; break;

View file

@ -191,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
auto property_key = PropertyKey { k }; auto property_key = PropertyKey { k };
// iii. Let next be ? IteratorStep(iteratorRecord). // iii. Let next be ? IteratorStep(iteratorRecord).
auto* next = TRY(iterator_step(vm, iterator)); auto next = TRY(iterator_step(vm, iterator));
// iv. If next is false, then // iv. If next is false, then
if (!next) { if (!next) {

View file

@ -254,7 +254,7 @@ ThrowCompletionOr<Vector<String>> string_list_from_iterable(VM& vm, Value iterab
Vector<String> list; Vector<String> list;
// 4. Let next be true. // 4. Let next be true.
Object* next = nullptr; GCPtr<Object> next;
// 5. Repeat, while next is not false, // 5. Repeat, while next is not false,
do { do {

View file

@ -104,7 +104,7 @@ ThrowCompletionOr<Value> iterator_value(VM& vm, Object& iterator_result)
} }
// 7.4.6 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep // 7.4.6 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep
ThrowCompletionOr<Object*> iterator_step(VM& vm, Iterator const& iterator_record) ThrowCompletionOr<GCPtr<Object>> iterator_step(VM& vm, Iterator const& iterator_record)
{ {
// 1. Let result be ? IteratorNext(iteratorRecord). // 1. Let result be ? IteratorNext(iteratorRecord).
auto result = TRY(iterator_next(vm, iterator_record)); auto result = TRY(iterator_next(vm, iterator_record));
@ -117,7 +117,7 @@ ThrowCompletionOr<Object*> iterator_step(VM& vm, Iterator const& iterator_record
return nullptr; return nullptr;
// 4. Return result. // 4. Return result.
return result.ptr(); return result;
} }
// 7.4.7 IteratorClose ( iteratorRecord, completion ), https://tc39.es/ecma262/#sec-iteratorclose // 7.4.7 IteratorClose ( iteratorRecord, completion ), https://tc39.es/ecma262/#sec-iteratorclose
@ -222,7 +222,7 @@ Completion get_iterator_values(VM& vm, Value iterable, IteratorValueCallback cal
auto iterator_record = TRY(get_iterator(vm, iterable, IteratorHint::Sync, move(method))); auto iterator_record = TRY(get_iterator(vm, iterable, IteratorHint::Sync, move(method)));
while (true) { while (true) {
auto* next_object = TRY(iterator_step(vm, iterator_record)); auto next_object = TRY(iterator_step(vm, iterator_record));
if (!next_object) if (!next_object)
return {}; return {};

View file

@ -24,7 +24,7 @@ enum class IteratorHint {
ThrowCompletionOr<Iterator> get_iterator(VM&, Value, IteratorHint = IteratorHint::Sync, Optional<Value> method = {}); ThrowCompletionOr<Iterator> get_iterator(VM&, Value, IteratorHint = IteratorHint::Sync, Optional<Value> method = {});
ThrowCompletionOr<NonnullGCPtr<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<GCPtr<Object>> iterator_step(VM&, Iterator const&);
ThrowCompletionOr<bool> iterator_complete(VM&, Object& iterator_result); ThrowCompletionOr<bool> iterator_complete(VM&, Object& iterator_result);
ThrowCompletionOr<Value> iterator_value(VM&, Object& iterator_result); ThrowCompletionOr<Value> iterator_value(VM&, Object& iterator_result);
Completion iterator_close(VM&, Iterator const&, Completion); Completion iterator_close(VM&, Iterator const&, Completion);

View file

@ -64,7 +64,7 @@ static ThrowCompletionOr<Value> perform_promise_common(VM& vm, Iterator& iterato
iterator_record.done = true; iterator_record.done = true;
return next_or_error.release_error(); return next_or_error.release_error();
} }
auto* next = next_or_error.release_value(); auto next = next_or_error.release_value();
// d. If next is false, then // d. If next is false, then
if (!next) { if (!next) {

View file

@ -290,7 +290,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::union_)
// 7. Repeat, while next is not false, // 7. Repeat, while next is not false,
while (next) { while (next) {
// a. Set next to ? IteratorStep(keysIter). // a. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// b. If next is not false, then // b. If next is not false, then
@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::intersection)
// c. Repeat, while next is not false, // c. Repeat, while next is not false,
while (next) { while (next) {
// i. Set next to ? IteratorStep(keysIter). // i. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// ii. If next is not false, then // ii. If next is not false, then
@ -436,7 +436,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::difference)
// c. Repeat, while next is not false, // c. Repeat, while next is not false,
while (next) { while (next) {
// i. Set next to ? IteratorStep(keysIter). // i. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// ii. If next is not false, then // ii. If next is not false, then
@ -486,7 +486,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::symmetric_difference)
// 7. Repeat, while next is not false, // 7. Repeat, while next is not false,
while (next) { while (next) {
// a. Set next to ? IteratorStep(keysIter). // a. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// b. If next is not false, then // b. If next is not false, then
@ -576,7 +576,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::is_superset_of)
// 8. Repeat, while next is not false, // 8. Repeat, while next is not false,
while (next) { while (next) {
// a. Set next to ? IteratorStep(keysIter). // a. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// b. If next is not false, then // b. If next is not false, then
@ -630,7 +630,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::is_disjoint_from)
// c. Repeat, while next is not false, // c. Repeat, while next is not false,
while (next) { while (next) {
// i. Set next to ? IteratorStep(keysIter). // i. Set next to ? IteratorStep(keysIter).
auto* iterator_result = TRY(iterator_step(vm, keys_iterator)); auto iterator_result = TRY(iterator_step(vm, keys_iterator));
next = iterator_result; next = iterator_result;
// ii. If next is not false, then // ii. If next is not false, then

View file

@ -52,7 +52,7 @@ ThrowCompletionOr<MarkedVector<Value>> iterable_to_list_of_type(VM& vm, Value it
// 4. Repeat, while next is not false, // 4. Repeat, while next is not false,
while (next) { while (next) {
// a. Set next to ? IteratorStep(iteratorRecord). // a. Set next to ? IteratorStep(iteratorRecord).
auto* iterator_result = TRY(iterator_step(vm, iterator_record)); auto iterator_result = TRY(iterator_step(vm, iterator_record));
next = iterator_result; next = iterator_result;
// b. If next is not false, then // b. If next is not false, then

View file

@ -543,7 +543,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields)
// 7. Repeat, while next is not false, // 7. Repeat, while next is not false,
while (true) { while (true) {
// a. Set next to ? IteratorStep(iteratorRecord). // a. Set next to ? IteratorStep(iteratorRecord).
auto* next = TRY(iterator_step(vm, iterator_record)); auto next = TRY(iterator_step(vm, iterator_record));
// b. If next is not false, then // b. If next is not false, then
if (!next) if (!next)

View file

@ -526,7 +526,7 @@ ThrowCompletionOr<MarkedVector<Instant*>> get_possible_instants_for(VM& vm, Valu
auto list = MarkedVector<Instant*> { vm.heap() }; auto list = MarkedVector<Instant*> { vm.heap() };
// 5. Let next be true. // 5. Let next be true.
Object* next = nullptr; GCPtr<Object> next;
// 6. Repeat, while next is not false, // 6. Repeat, while next is not false,
do { do {

View file

@ -468,7 +468,7 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const
// 3. Let n be 0. // 3. Let n be 0.
// 4. Repeat, // 4. Repeat,
while (true) { while (true) {
ThrowCompletionOr<Object*> next { nullptr }; ThrowCompletionOr<GCPtr<Object>> next { nullptr };
// a. If iteratorRecord.[[Done]] is false, then // a. If iteratorRecord.[[Done]] is false, then
if (!iterator_record.done) { if (!iterator_record.done) {

View file

@ -74,7 +74,7 @@ static JS::ThrowCompletionOr<Vector<String>> convert_value_to_sequence_of_string
// 3. Repeat // 3. Repeat
for (;;) { for (;;) {
// 1. Let next be ? IteratorStep(iter). // 1. Let next be ? IteratorStep(iter).
auto* next = TRY(JS::iterator_step(vm, iterator)); auto next = TRY(JS::iterator_step(vm, iterator));
// 2. If next is false, then return an IDL sequence value of type sequence<T> of length i, where the value of the element at index j is Sj. // 2. If next is false, then return an IDL sequence value of type sequence<T> of length i, where the value of the element at index j is Sj.
if (!next) if (!next)