From 143465b23afd1297c72c6258a3595ed9b104fa64 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 3 Jan 2022 21:54:44 +0100 Subject: [PATCH] LibJS: Propagate errors from TypedArray for_each_item{,_from_last} calls Another mistake uncovered by moving away from manual exception checks and relying on correct completion types instead :^) --- .../LibJS/Runtime/TypedArrayPrototype.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 336b9c5e806..d4f3b1d4cd8 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -201,13 +201,13 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::at) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::every) { auto result = true; - for_each_item(vm, global_object, "every", [&](auto, auto, auto callback_result) { + TRY(for_each_item(vm, global_object, "every", [&](auto, auto, auto callback_result) { if (!callback_result.to_boolean()) { result = false; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return Value(result); } @@ -261,13 +261,13 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::fill) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find) { auto result = js_undefined(); - for_each_item(vm, global_object, "find", [&](auto, auto value, auto callback_result) { + TRY(for_each_item(vm, global_object, "find", [&](auto, auto value, auto callback_result) { if (callback_result.to_boolean()) { result = value; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return result; } @@ -275,13 +275,13 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_index) { auto result_index = -1; - for_each_item(vm, global_object, "findIndex", [&](auto index, auto, auto callback_result) { + TRY(for_each_item(vm, global_object, "findIndex", [&](auto index, auto, auto callback_result) { if (callback_result.to_boolean()) { result_index = index; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return Value(result_index); } @@ -289,13 +289,13 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_index) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_last) { auto result = js_undefined(); - for_each_item_from_last(vm, global_object, "findLast", [&](auto, auto value, auto callback_result) { + TRY(for_each_item_from_last(vm, global_object, "findLast", [&](auto, auto value, auto callback_result) { if (callback_result.to_boolean()) { result = value; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return result; } @@ -303,22 +303,22 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_last) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::find_last_index) { auto result_index = -1; - for_each_item_from_last(vm, global_object, "findLastIndex", [&](auto index, auto, auto callback_result) { + TRY(for_each_item_from_last(vm, global_object, "findLastIndex", [&](auto index, auto, auto callback_result) { if (callback_result.to_boolean()) { result_index = index; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return Value(result_index); } // 23.2.3.13 %TypedArray%.prototype.forEach ( callbackfn [ , thisArg ] ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.foreach JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::for_each) { - for_each_item(vm, global_object, "forEach", [](auto, auto, auto) { + TRY(for_each_item(vm, global_object, "forEach", [](auto, auto, auto) { return IterationDecision::Continue; - }); + })); return js_undefined(); } @@ -510,13 +510,13 @@ JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::reduce_right) JS_DEFINE_NATIVE_FUNCTION(TypedArrayPrototype::some) { auto result = false; - for_each_item(vm, global_object, "some", [&](auto, auto, auto callback_result) { + TRY(for_each_item(vm, global_object, "some", [&](auto, auto, auto callback_result) { if (callback_result.to_boolean()) { result = true; return IterationDecision::Break; } return IterationDecision::Continue; - }); + })); return Value(result); }