Bläddra i källkod

LibJS: Simplify Array.prototype.splice()

This is an editorial change in the ECMA-262 spec.

See: https://github.com/tc39/ecma262/commit/193211a
Linus Groh 3 år sedan
förälder
incheckning
85c16452f9
1 ändrade filer med 3 tillägg och 8 borttagningar
  1. 3 8
      Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp

+ 3 - 8
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 {