From 301214dd39102675004efd4bc5f98e62233bbd92 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Thu, 17 Mar 2016 14:48:39 -0700 Subject: [PATCH] Fix List splice method to be spec compatible If the second argument is omitted, then all objects after the provided index should be removed. This is the same behavior as Array.prototype.splice. --- src/js_list.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js_list.cpp b/src/js_list.cpp index 4a8ca1b0..7acbdadf 100644 --- a/src/js_list.cpp +++ b/src/js_list.cpp @@ -174,14 +174,20 @@ JSValueRef ListSplice(JSContextRef ctx, JSObjectRef function, JSObjectRef thisOb List *list = RJSGetInternal(thisObject); size_t size = list->size(); - RJSValidateArgumentCountIsAtLeast(argumentCount, 2); + RJSValidateArgumentCountIsAtLeast(argumentCount, 1); long index = std::min(RJSValidatedValueToNumber(ctx, arguments[0]), size); if (index < 0) { index = std::max(size + index, 0); } - long remove = std::max(RJSValidatedValueToNumber(ctx, arguments[1]), 0); - remove = std::min(remove, size - index); + long remove; + if (argumentCount < 2) { + remove = size - index; + } + else { + remove = std::max(RJSValidatedValueToNumber(ctx, arguments[1]), 0); + remove = std::min(remove, size - index); + } std::vector removedObjects(remove); for (size_t i = 0; i < remove; i++) {