diff options
author | Timothy Flynn <trflynn89@pm.me> | 2021-10-20 13:36:14 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-10-21 00:26:45 +0100 |
commit | ec54a7b5b09f7f86c99c247477b29267a274991b (patch) | |
tree | 3da224b62570ae2a232a63b29cc9086d9757fbbb /Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp | |
parent | 04b4307b3d57a4c48abfa19a22d4745b23760d78 (diff) | |
download | serenity-ec54a7b5b09f7f86c99c247477b29267a274991b.zip |
LibJS: Implement IteratorClose with Completions and align to the spec
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 32bc5740cb..670b4bea60 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -123,9 +123,8 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayConstructor::from) size_t k = 0; while (true) { if (k >= MAX_ARRAY_LIKE_INDEX) { - vm.throw_exception<TypeError>(global_object, ErrorType::ArrayMaxSize); - iterator_close(*iterator); - return {}; + auto error = vm.throw_completion<TypeError>(global_object, ErrorType::ArrayMaxSize); + return TRY_OR_DISCARD(iterator_close(*iterator, move(error))); } auto* next = TRY_OR_DISCARD(iterator_step(global_object, *iterator)); @@ -139,20 +138,16 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(ArrayConstructor::from) Value mapped_value; if (map_fn) { auto mapped_value_or_error = vm.call(*map_fn, this_arg, next_value, Value(k)); - if (mapped_value_or_error.is_error()) { - iterator_close(*iterator); - return {}; - } + if (mapped_value_or_error.is_error()) + return TRY_OR_DISCARD(iterator_close(*iterator, mapped_value_or_error.release_error())); mapped_value = mapped_value_or_error.release_value(); } else { mapped_value = next_value; } auto result_or_error = array_object.create_data_property_or_throw(k, mapped_value); - if (result_or_error.is_error()) { - iterator_close(*iterator); - return {}; - } + if (result_or_error.is_error()) + return TRY_OR_DISCARD(iterator_close(*iterator, result_or_error.release_error())); ++k; } |