From 85c16452f985034b0c682a00a87ec208ae453a94 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 30 Apr 2022 22:44:00 +0200 Subject: [PATCH] LibJS: Simplify Array.prototype.splice() This is an editorial change in the ECMA-262 spec. See: https://github.com/tc39/ecma262/commit/193211a --- Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index de18653012..756540e90e 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -1389,9 +1389,8 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) for (u64 i = 0; i < actual_delete_count; ++i) { auto from = actual_start + i; - bool from_present = TRY(this_object->has_property(from)); - if (from_present) { + if (TRY(this_object->has_property(from))) { auto from_value = TRY(this_object->get(from)); TRY(removed_elements->create_data_property_or_throw(i, from_value)); @@ -1405,9 +1404,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) auto to = i + insert_count; u64 from = i + actual_delete_count; - auto from_present = TRY(this_object->has_property(from)); - - if (from_present) { + if (TRY(this_object->has_property(from))) { auto from_value = TRY(this_object->get(from)); TRY(this_object->set(to, from_value, Object::ShouldThrowExceptions::Yes)); } else { @@ -1420,11 +1417,9 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) } else if (insert_count > actual_delete_count) { for (u64 i = initial_length - actual_delete_count; i > actual_start; --i) { u64 from_index = i + actual_delete_count - 1; - auto from_present = TRY(this_object->has_property(from_index)); - auto to = i + insert_count - 1; - if (from_present) { + if (TRY(this_object->has_property(from_index))) { auto from_value = TRY(this_object->get(from_index)); TRY(this_object->set(to, from_value, Object::ShouldThrowExceptions::Yes)); } else {