summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-09-15 23:11:02 +0100
committerLinus Groh <mail@linusgroh.de>2021-09-16 22:34:24 +0100
commitf2b5ddd167d891abacb2fe1b871fc98c9eea4f7b (patch)
treef9763c48f9d83a8b0910a838de702eb4eb00dc46 /Userland/Libraries/LibJS
parent683e31e1ff6bab4743171312acc0919d968931bd (diff)
downloadserenity-f2b5ddd167d891abacb2fe1b871fc98c9eea4f7b.zip
LibJS: Convert iterable_to_list_of_type() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp21
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp4
3 files changed, 13 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
index bba238bc0d..95017e567a 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp
@@ -9,6 +9,7 @@
#include <AK/DateTimeLexer.h>
#include <AK/TypeCasts.h>
#include <AK/Variant.h>
+#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/PropertyName.h>
#include <LibJS/Runtime/Temporal/AbstractOperations.h>
@@ -34,15 +35,15 @@ static Optional<OptionType> to_option_type(Value value)
}
// 13.1 IterableToListOfType ( items, elementTypes ), https://tc39.es/proposal-temporal/#sec-iterabletolistoftype
-MarkedValueList iterable_to_list_of_type(GlobalObject& global_object, Value items, Vector<OptionType> const& element_types)
+ThrowCompletionOr<MarkedValueList> iterable_to_list_of_type(GlobalObject& global_object, Value items, Vector<OptionType> const& element_types)
{
auto& vm = global_object.vm();
auto& heap = global_object.heap();
// 1. Let iteratorRecord be ? GetIterator(items, sync).
auto iterator_record = get_iterator(global_object, items, IteratorHint::Sync);
- if (vm.exception())
- return MarkedValueList { heap };
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// 2. Let values be a new empty List.
MarkedValueList values(heap);
@@ -53,23 +54,23 @@ MarkedValueList iterable_to_list_of_type(GlobalObject& global_object, Value item
while (next) {
// a. Set next to ? IteratorStep(iteratorRecord).
auto* iterator_result = iterator_step(global_object, *iterator_record);
- if (vm.exception())
- return MarkedValueList { heap };
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
next = iterator_result;
// b. If next is not false, then
if (next) {
// i. Let nextValue be ? IteratorValue(next).
auto next_value = iterator_value(global_object, *iterator_result);
- if (vm.exception())
- return MarkedValueList { heap };
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
// ii. If Type(nextValue) is not an element of elementTypes, then
if (auto type = to_option_type(next_value); !type.has_value() || !element_types.contains_slow(*type)) {
// 1. Let completion be ThrowCompletion(a newly created TypeError object).
- vm.throw_exception<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
+ auto completion = vm.throw_completion<TypeError>(global_object, ErrorType::FixmeAddAnErrorString);
// 2. Return ? IteratorClose(iteratorRecord, completion).
iterator_close(*iterator_record);
- return MarkedValueList { heap };
+ return completion;
}
// iii. Append nextValue to the end of the List values.
values.append(next_value);
@@ -77,7 +78,7 @@ MarkedValueList iterable_to_list_of_type(GlobalObject& global_object, Value item
}
// 5. Return values.
- return values;
+ return { move(values) };
}
// 13.2 GetOptionsObject ( options ), https://tc39.es/proposal-temporal/#sec-getoptionsobject
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
index 3e65418028..62fb5880a6 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/AbstractOperations.h
@@ -84,7 +84,7 @@ struct SecondsStringPrecision {
u32 increment;
};
-MarkedValueList iterable_to_list_of_type(GlobalObject&, Value items, Vector<OptionType> const& element_types);
+ThrowCompletionOr<MarkedValueList> iterable_to_list_of_type(GlobalObject&, Value items, Vector<OptionType> const& element_types);
Object* get_options_object(GlobalObject&, Value options);
Value get_option(GlobalObject&, Object const& options, PropertyName const& property, Vector<OptionType> const& types, Vector<StringView> const& values, Value fallback);
template<typename NumberType>
diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
index b0ff02bac3..1a343543c9 100644
--- a/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Temporal/Calendar.cpp
@@ -110,9 +110,7 @@ Vector<String> calendar_fields(GlobalObject& global_object, Object& calendar, Ve
}
// 4. Return ? IterableToListOfType(fieldsArray, ยซ String ยป).
- auto list = iterable_to_list_of_type(global_object, fields_array, { OptionType::String });
- if (vm.exception())
- return {};
+ auto list = TRY_OR_DISCARD(iterable_to_list_of_type(global_object, fields_array, { OptionType::String }));
Vector<String> result;
for (auto& value : list)