diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-18 19:45:32 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-18 22:59:15 +0300 |
commit | e00ca102833ad4394f091da2a236dd110d20b350 (patch) | |
tree | b3ebdc2d499db51d5d91f9c2749b7e04d6b36e8b /Userland | |
parent | e65aeee67d6ac291e8b3346199ea32e7d502462a (diff) | |
download | serenity-e00ca102833ad4394f091da2a236dd110d20b350.zip |
LibJS: Convert ListFormat AOs to ThrowCompletionOr
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp | 8 |
3 files changed, 13 insertions, 17 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp index 0ae0de1d88..0d18ae9608 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.cpp @@ -265,20 +265,20 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_ } // 13.1.5 StringListFromIterable ( iterable ), https://tc39.es/ecma402/#sec-createstringlistfromiterable -Vector<String> string_list_from_iterable(GlobalObject& global_object, Value iterable) +ThrowCompletionOr<Vector<String>> string_list_from_iterable(GlobalObject& global_object, Value iterable) { auto& vm = global_object.vm(); // 1. If iterable is undefined, then if (iterable.is_undefined()) { // a. Return a new empty List. - return {}; + return Vector<String> {}; } // 2. Let iteratorRecord be ? GetIterator(iterable). auto* iterator_record = get_iterator(global_object, iterable); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // 3. Let list be a new empty List. Vector<String> list; @@ -290,24 +290,24 @@ Vector<String> string_list_from_iterable(GlobalObject& global_object, Value iter do { // a. Set next to ? IteratorStep(iteratorRecord). next = iterator_step(global_object, *iterator_record); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // b. If next is not false, then if (next != nullptr) { // i. Let nextValue be ? IteratorValue(next). auto next_value = iterator_value(global_object, *next); - if (vm.exception()) - return {}; + if (auto* exception = vm.exception()) + return throw_completion(exception->value()); // ii. If Type(nextValue) is not String, then if (!next_value.is_string()) { // 1. Let error be ThrowCompletion(a newly created TypeError object). - vm.throw_exception<TypeError>(global_object, ErrorType::NotAString, next_value); + auto completion = vm.throw_completion<TypeError>(global_object, ErrorType::NotAString, next_value); // 2. Return ? IteratorClose(iteratorRecord, error). iterator_close(*iterator_record); - return {}; + return completion; } // iii. Append nextValue to the end of the List list. diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h index 64a2654672..0eeb62957d 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormat.h @@ -60,6 +60,6 @@ Vector<PatternPartition> deconstruct_pattern(StringView pattern, Placeables plac Vector<PatternPartition> create_parts_from_list(ListFormat const& list_format, Vector<String> const& list); String format_list(ListFormat const& list_format, Vector<String> const& list); Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_format, Vector<String> const& list); -Vector<String> string_list_from_iterable(GlobalObject& global_object, Value iterable); +ThrowCompletionOr<Vector<String>> string_list_from_iterable(GlobalObject& global_object, Value iterable); } diff --git a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp index 3be67ae1f9..2ef8359e2b 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/ListFormatPrototype.cpp @@ -45,9 +45,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format) return {}; // 3. Let stringList be ? StringListFromIterable(list). - auto string_list = string_list_from_iterable(global_object, list); - if (vm.exception()) - return {}; + auto string_list = TRY_OR_DISCARD(string_list_from_iterable(global_object, list)); // 4. Return FormatList(lf, stringList). auto formatted = format_list(*list_format, string_list); @@ -66,9 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts) return {}; // 3. Let stringList be ? StringListFromIterable(list). - auto string_list = string_list_from_iterable(global_object, list); - if (vm.exception()) - return {}; + auto string_list = TRY_OR_DISCARD(string_list_from_iterable(global_object, list)); // 4. Return FormatListToParts(lf, stringList). return format_list_to_parts(global_object, *list_format, string_list); |