summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-09-21 21:59:49 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-09-21 23:28:38 +0300
commite90e4ac1e25e85e8f0034dd92c20a7aedd09e598 (patch)
tree0994832090b2c89b7f28a4c2c54a960a675b1732 /Userland/Libraries
parent02a88c5063ef967f65a95afde6db132800c472a4 (diff)
downloadserenity-e90e4ac1e25e85e8f0034dd92c20a7aedd09e598.zip
LibJS: Convert length_of_array_like to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/AbstractOperations.h2
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp125
-rw-r--r--Userland/Libraries/LibJS/Runtime/JSONObject.cpp12
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/StringConstructor.cpp2
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArray.cpp5
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp4
11 files changed, 55 insertions, 126 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
index d268a970e9..d8bac17cf6 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp
@@ -42,13 +42,16 @@ ThrowCompletionOr<Value> require_object_coercible(GlobalObject& global_object, V
}
// 7.3.18 LengthOfArrayLike ( obj ), https://tc39.es/ecma262/#sec-lengthofarraylike
-size_t length_of_array_like(GlobalObject& global_object, Object const& object)
+ThrowCompletionOr<size_t> length_of_array_like(GlobalObject& global_object, Object const& object)
{
auto& vm = global_object.vm();
auto result = object.get(vm.names.length);
- if (vm.exception())
- return {};
- return result.to_length(global_object);
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
+ auto length = result.to_length(global_object);
+ if (auto* exception = vm.exception())
+ return throw_completion(exception->value());
+ return length;
}
// 7.3.19 CreateListFromArrayLike ( obj [ , elementTypes ] ), https://tc39.es/ecma262/#sec-createlistfromarraylike
@@ -66,9 +69,7 @@ ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject& glo
auto& array_like = value.as_object();
// 3. Let len be ? LengthOfArrayLike(obj).
- auto length = length_of_array_like(global_object, array_like);
- if (auto* exception = vm.exception())
- return throw_completion(exception->value());
+ auto length = TRY(length_of_array_like(global_object, array_like));
// 4. Let list be a new empty List.
auto list = MarkedValueList { heap };
diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
index e185d6f25b..2fff8e266e 100644
--- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
+++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h
@@ -20,7 +20,7 @@ Environment& get_this_environment(VM&);
Object* get_super_constructor(VM&);
ThrowCompletionOr<Reference> make_super_property_reference(GlobalObject&, Value actual_this, StringOrSymbol const& property_key, bool strict);
ThrowCompletionOr<Value> require_object_coercible(GlobalObject&, Value);
-size_t length_of_array_like(GlobalObject&, Object const&);
+ThrowCompletionOr<size_t> length_of_array_like(GlobalObject&, Object const&);
ThrowCompletionOr<MarkedValueList> create_list_from_array_like(GlobalObject&, Value, Function<ThrowCompletionOr<void>(Value)> = {});
ThrowCompletionOr<FunctionObject*> species_constructor(GlobalObject&, Object const&, FunctionObject& default_constructor);
ThrowCompletionOr<Realm*> get_function_realm(GlobalObject&, FunctionObject const&);
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
index dc381a93ab..52bcaa3343 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp
@@ -172,9 +172,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayConstructor::from)
auto* array_like = items.to_object(global_object);
- auto length = length_of_array_like(global_object, *array_like);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *array_like));
Value array;
if (constructor.is_constructor()) {
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
index 2b5af520c9..164f4f1d07 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp
@@ -63,9 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next)
length = typed_array.array_length();
} else {
- length = length_of_array_like(global_object, array);
- if (vm.exception())
- return {};
+ length = TRY_OR_DISCARD(length_of_array_like(global_object, array));
}
if (index >= length) {
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
index 668ac59ef9..c732d4e8ed 100644
--- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp
@@ -171,9 +171,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::filter)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -243,9 +241,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::for_each)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -296,9 +292,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::map)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -353,9 +347,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto argument_count = vm.argument_count();
auto new_length = length + argument_count;
if (new_length > MAX_ARRAY_LIKE_INDEX) {
@@ -380,9 +372,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto arg_count = vm.argument_count();
size_t new_length = length + arg_count;
if (arg_count > 0) {
@@ -431,9 +421,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::pop)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
if (length == 0) {
this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes);
return js_undefined();
@@ -457,9 +445,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
if (length == 0) {
this_object->set(vm.names.length, Value(0), Object::ShouldThrowExceptions::Yes);
if (vm.exception())
@@ -528,9 +514,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::to_locale_string)
s_array_join_seen_objects.remove(this_object);
};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
String separator = ","; // NOTE: This is implementation-specific.
StringBuilder builder;
@@ -570,9 +554,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::join)
s_array_join_seen_objects.remove(this_object);
};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
String separator = ",";
if (!vm.argument(0).is_undefined()) {
separator = vm.argument(0).to_string(global_object);
@@ -637,9 +619,10 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::concat)
VERIFY(arg.is_object());
Object& obj = arg.as_object();
size_t k = 0;
- auto length = length_of_array_like(global_object, obj);
- if (vm.exception())
+ auto length_or_error = length_of_array_like(global_object, obj);
+ if (length_or_error.is_error())
return;
+ auto length = length_or_error.release_value();
if (n + length > MAX_ARRAY_LIKE_INDEX) {
vm.throw_exception<TypeError>(global_object, ErrorType::ArrayMaxSize);
@@ -696,9 +679,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::slice)
if (!this_object)
return {};
- auto initial_length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto initial_length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto relative_start = vm.argument(0).to_integer_or_infinity(global_object);
if (vm.exception())
@@ -779,9 +760,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::index_of)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If len is 0, return -1𝔽.
if (length == 0)
@@ -861,9 +840,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -961,9 +938,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reduce_right)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -1057,9 +1032,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto middle = length / 2;
for (size_t lower = 0; lower < middle; ++lower) {
@@ -1233,9 +1206,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::sort)
if (vm.exception())
return {};
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
MarkedValueList items(vm.heap());
for (size_t k = 0; k < length; ++k) {
@@ -1291,9 +1262,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::last_index_of)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If len is 0, return -1𝔽.
if (length == 0)
@@ -1364,9 +1333,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::includes)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
if (length == 0)
return Value(false);
u64 from_index = 0;
@@ -1408,9 +1375,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (!predicate.is_function()) {
@@ -1457,9 +1422,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_index)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (!predicate.is_function()) {
@@ -1506,9 +1469,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (!predicate.is_function()) {
@@ -1555,9 +1516,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::find_last_index)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
if (!predicate.is_function()) {
@@ -1604,9 +1563,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::some)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -1661,9 +1618,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::every)
return {};
// 2. Let len be ? LengthOfArrayLike(O).
- auto length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (!callback_function.is_function()) {
@@ -1713,9 +1668,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice)
if (!this_object)
return {};
- auto initial_length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto initial_length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto relative_start = vm.argument(0).to_integer_or_infinity(global_object);
if (vm.exception())
@@ -1846,9 +1799,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::fill)
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
double relative_start = 0;
double relative_end = length;
@@ -1950,9 +1901,7 @@ static size_t flatten_into_array(GlobalObject& global_object, Object& new_array,
return {};
}
- auto length = length_of_array_like(global_object, value.as_object());
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, value.as_object()));
target_index = flatten_into_array(global_object, new_array, value.as_object(), length, target_index, depth - 1);
if (vm.exception())
return {};
@@ -1980,9 +1929,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat)
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
double depth = 1;
if (!vm.argument(0).is_undefined()) {
@@ -2014,9 +1961,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::flat_map)
return {};
// 2. Let sourceLen be ? LengthOfArrayLike(O).
- auto source_length = length_of_array_like(global_object, *object);
- if (vm.exception())
- return {};
+ auto source_length = TRY_OR_DISCARD(length_of_array_like(global_object, *object));
// 3. If ! IsCallable(mapperFunction) is false, throw a TypeError exception.
if (!mapper_function.is_function()) {
@@ -2044,9 +1989,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::copy_within)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto relative_target = vm.argument(0).to_integer_or_infinity(global_object);
if (vm.exception())
@@ -2128,9 +2071,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::at)
auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object)
return {};
- auto length = length_of_array_like(global_object, *this_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *this_object));
auto relative_index = vm.argument(0).to_integer_or_infinity(global_object);
if (vm.exception())
return {};
diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
index 961cebd862..887d7b0faf 100644
--- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
+++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp
@@ -59,9 +59,7 @@ String JSONObject::stringify_impl(GlobalObject& global_object, Value value, Valu
return {};
if (is_array) {
auto& replacer_object = replacer.as_object();
- auto replacer_length = length_of_array_like(global_object, replacer_object);
- if (vm.exception())
- return {};
+ auto replacer_length = TRY_OR_DISCARD(length_of_array_like(global_object, replacer_object));
Vector<String> list;
for (size_t i = 0; i < replacer_length; ++i) {
auto replacer_value = replacer_object.get(i);
@@ -313,9 +311,7 @@ String JSONObject::serialize_json_array(GlobalObject& global_object, StringifySt
state.indent = String::formatted("{}{}", state.indent, state.gap);
Vector<String> property_strings;
- auto length = length_of_array_like(global_object, object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, object));
// Optimization
property_strings.ensure_capacity(length);
@@ -499,9 +495,7 @@ Value JSONObject::internalize_json_property(GlobalObject& global_object, Object*
};
if (is_array) {
- auto length = length_of_array_like(global_object, value_object);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, value_object));
for (size_t i = 0; i < length; ++i) {
process_property(i);
if (vm.exception())
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index 9bf56c5025..c20ec59a91 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -629,7 +629,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace)
for (auto& result_value : results) {
auto& result = result_value.as_object();
- size_t result_length = length_of_array_like(global_object, result);
+ size_t result_length = TRY_OR_DISCARD(length_of_array_like(global_object, result));
size_t n_captures = result_length == 0 ? 0 : result_length - 1;
auto matched_value = result.get(0);
@@ -864,7 +864,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
auto* result_object = result.to_object(global_object);
if (!result_object)
return {};
- auto number_of_captures = length_of_array_like(global_object, *result_object);
+ auto number_of_captures = TRY_OR_DISCARD(length_of_array_like(global_object, *result_object));
if (vm.exception())
return {};
if (number_of_captures > 0)
diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
index 908e55e9b8..cbac0b8d0d 100644
--- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp
@@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::raw)
if (vm.exception())
return {};
- auto literal_segments = length_of_array_like(global_object, *raw);
+ auto literal_segments = TRY_OR_DISCARD(length_of_array_like(global_object, *raw));
if (vm.exception())
return {};
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
index c19c5f711b..38bb7f8837 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp
@@ -165,9 +165,10 @@ template<typename T>
static void initialize_typed_array_from_array_like(GlobalObject& global_object, TypedArray<T>& typed_array, const Object& array_like)
{
auto& vm = global_object.vm();
- auto length = length_of_array_like(global_object, array_like);
- if (vm.exception())
+ auto length_or_error = length_of_array_like(global_object, array_like);
+ if (length_or_error.is_error())
return;
+ auto length = length_or_error.release_value();
// Enforce 2GB "Excessive Length" limit
if (length > NumericLimits<i32>::max() / sizeof(T)) {
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
index e02b623d48..f2f09b50f2 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp
@@ -110,9 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayConstructor::from)
}
auto array_like = source.to_object(global_object);
- auto length = length_of_array_like(global_object, *array_like);
- if (vm.exception())
- return {};
+ auto length = TRY_OR_DISCARD(length_of_array_like(global_object, *array_like));
MarkedValueList arguments(vm.heap());
arguments.empend(length);
diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
index f2f4d9860b..6ad432e772 100644
--- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp
@@ -810,9 +810,7 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::set)
if (vm.exception())
return {};
- auto source_length = length_of_array_like(global_object, *src);
- if (vm.exception())
- return {};
+ auto source_length = TRY_OR_DISCARD(length_of_array_like(global_object, *src));
if (isinf(target_offset)) {
vm.throw_exception<JS::RangeError>(global_object, "Invalid target offset");