From aff1ec6014019b96992942a0610011a0c586033c Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 15 Apr 2023 16:23:03 +0200 Subject: [PATCH] LibJS: Port iterator_step() to GCPtr --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 2 +- .../Libraries/LibJS/Runtime/ArrayConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp | 2 +- .../Libraries/LibJS/Runtime/IteratorOperations.cpp | 6 +++--- .../Libraries/LibJS/Runtime/IteratorOperations.h | 2 +- .../Libraries/LibJS/Runtime/PromiseConstructor.cpp | 2 +- Userland/Libraries/LibJS/Runtime/SetPrototype.cpp | 12 ++++++------ .../LibJS/Runtime/Temporal/AbstractOperations.cpp | 2 +- .../LibJS/Runtime/Temporal/CalendarPrototype.cpp | 2 +- .../Libraries/LibJS/Runtime/Temporal/TimeZone.cpp | 2 +- Userland/Libraries/LibJS/Runtime/VM.cpp | 2 +- .../HTML/CustomElements/CustomElementRegistry.cpp | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 78c225c928..17169c822e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -1521,7 +1521,7 @@ void IDL::ParameterizedType::generate_sequence_from_iterable(SourceGenerator& ge sequence_generator.append(R"~~~( 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@) break; diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 4c96722975..c51dff3020 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -191,7 +191,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from) auto property_key = PropertyKey { k }; // 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 if (!next) { diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index f915196b57..1b16be66a4 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -254,7 +254,7 @@ ThrowCompletionOr> string_list_from_iterable(VM& vm, Value iterab Vector list; // 4. Let next be true. - Object* next = nullptr; + GCPtr next; // 5. Repeat, while next is not false, do { diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index c93f052f6d..237eb78c1e 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -104,7 +104,7 @@ ThrowCompletionOr iterator_value(VM& vm, Object& iterator_result) } // 7.4.6 IteratorStep ( iteratorRecord ), https://tc39.es/ecma262/#sec-iteratorstep -ThrowCompletionOr iterator_step(VM& vm, Iterator const& iterator_record) +ThrowCompletionOr> iterator_step(VM& vm, Iterator const& iterator_record) { // 1. Let result be ? IteratorNext(iteratorRecord). auto result = TRY(iterator_next(vm, iterator_record)); @@ -117,7 +117,7 @@ ThrowCompletionOr iterator_step(VM& vm, Iterator const& iterator_record return nullptr; // 4. Return result. - return result.ptr(); + return result; } // 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))); while (true) { - auto* next_object = TRY(iterator_step(vm, iterator_record)); + auto next_object = TRY(iterator_step(vm, iterator_record)); if (!next_object) return {}; diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h index b8808975ae..921f40aa2f 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.h +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.h @@ -24,7 +24,7 @@ enum class IteratorHint { ThrowCompletionOr get_iterator(VM&, Value, IteratorHint = IteratorHint::Sync, Optional method = {}); ThrowCompletionOr> iterator_next(VM&, Iterator const&, Optional = {}); -ThrowCompletionOr iterator_step(VM&, Iterator const&); +ThrowCompletionOr> iterator_step(VM&, Iterator const&); ThrowCompletionOr iterator_complete(VM&, Object& iterator_result); ThrowCompletionOr iterator_value(VM&, Object& iterator_result); Completion iterator_close(VM&, Iterator const&, Completion); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index a3e119f318..c3f87536da 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -64,7 +64,7 @@ static ThrowCompletionOr perform_promise_common(VM& vm, Iterator& iterato iterator_record.done = true; 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 if (!next) { diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index d970270c46..d65d29395b 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -290,7 +290,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::union_) // 7. Repeat, while next is not false, while (next) { // 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; // b. If next is not false, then @@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::intersection) // c. Repeat, while next is not false, while (next) { // 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; // ii. If next is not false, then @@ -436,7 +436,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetPrototype::difference) // c. Repeat, while next is not false, while (next) { // 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; // 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, while (next) { // 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; // 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, while (next) { // 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; // 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, while (next) { // 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; // ii. If next is not false, then diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index bb64f9c511..82e279c65d 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -52,7 +52,7 @@ ThrowCompletionOr> iterable_to_list_of_type(VM& vm, Value it // 4. Repeat, while next is not false, while (next) { // 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; // b. If next is not false, then diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp index 0631cdbf16..5edcf64f7b 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/CalendarPrototype.cpp @@ -543,7 +543,7 @@ JS_DEFINE_NATIVE_FUNCTION(CalendarPrototype::fields) // 7. Repeat, while next is not false, while (true) { // 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 if (!next) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp index f5f438f136..bc3ace1f53 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/TimeZone.cpp @@ -526,7 +526,7 @@ ThrowCompletionOr> get_possible_instants_for(VM& vm, Valu auto list = MarkedVector { vm.heap() }; // 5. Let next be true. - Object* next = nullptr; + GCPtr next; // 6. Repeat, while next is not false, do { diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 08b7994b32..8c328cab8d 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -468,7 +468,7 @@ ThrowCompletionOr VM::iterator_binding_initialization(BindingPattern const // 3. Let n be 0. // 4. Repeat, while (true) { - ThrowCompletionOr next { nullptr }; + ThrowCompletionOr> next { nullptr }; // a. If iteratorRecord.[[Done]] is false, then if (!iterator_record.done) { diff --git a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp index c2ff582485..4549bba8bc 100644 --- a/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp +++ b/Userland/Libraries/LibWeb/HTML/CustomElements/CustomElementRegistry.cpp @@ -74,7 +74,7 @@ static JS::ThrowCompletionOr> convert_value_to_sequence_of_string // 3. Repeat for (;;) { // 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 of length i, where the value of the element at index j is Sj. if (!next)