Follow Safari and Firefox in returning empty array from array splice
authorager@chromium.org <ager@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 30 Aug 2010 18:08:50 +0000 (18:08 +0000)
committerager@chromium.org <ager@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 30 Aug 2010 18:08:50 +0000 (18:08 +0000)
with no arguments.

Review URL: http://codereview.chromium.org/3277005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5375 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/array.js
src/builtins.cc
test/mjsunit/array-splice.js
test/mjsunit/third_party/array-splice-webkit.js

index dfa7301..e12df64 100644 (file)
@@ -566,13 +566,6 @@ function ArraySlice(start, end) {
 function ArraySplice(start, delete_count) {
   var num_arguments = %_ArgumentsLength();
 
-  // SpiderMonkey and JSC return undefined in the case where no
-  // arguments are given instead of using the implicit undefined
-  // arguments.  This does not follow ECMA-262, but we do the same for
-  // compatibility.
-  // TraceMonkey follows ECMA-262 though.
-  if (num_arguments == 0) return;
-
   var len = TO_UINT32(this.length);
   var start_i = TO_INTEGER(start);
 
index a64bf4e..a2ff909 100644 (file)
@@ -663,13 +663,10 @@ BUILTIN(ArraySplice) {
 
   int n_arguments = args.length() - 1;
 
-  // SpiderMonkey and JSC return undefined in the case where no
-  // arguments are given instead of using the implicit undefined
-  // arguments.  This does not follow ECMA-262, but we do the same for
-  // compatibility.
-  // TraceMonkey follows ECMA-262 though.
+  // Return empty array when no arguments are supplied.
   if (n_arguments == 0) {
-    return Heap::undefined_value();
+    // No handle scope needed since we return directly.
+    return *Factory::NewJSArray(0);
   }
 
   int relative_start = 0;
index 88c4876..68dd9b2 100644 (file)
 (function() {
   var array;
   for (var i = 0; i < 7; i++) {
-    // SpiderMonkey and JSC return undefined in the case where no
-    // arguments are given instead of using the implicit undefined
-    // arguments.  This does not follow ECMA-262, but we do the same for
-    // compatibility.
-    // TraceMonkey follows ECMA-262 though.
     array = [1, 2, 3]
-    assertEquals(undefined, array.splice());
+    assertEquals([], array.splice());
     assertEquals([1, 2, 3], array);
 
     // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is
index b676a7c..974ac55 100644 (file)
@@ -38,7 +38,7 @@ assertArrayEquals(['a','b'], arr.splice(0));
 assertArrayEquals([], arr)
 
 arr = ['a','b','c','d'];
-assertEquals(undefined, arr.splice())
+assertEquals([], arr.splice())
 assertArrayEquals(['a','b','c','d'], arr);
 assertArrayEquals(['a','b','c','d'], arr.splice(undefined))
 assertArrayEquals([], arr);