Reviewers: Lasse Reichstein, antonm,

Description:
Follow Safari and Firefox in returning empty array from array splice
with no arguments.


Please review this at http://codereview.chromium.org/3277005/show

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/array.js
  M     src/builtins.cc
  M     test/mjsunit/array-splice.js
  M     test/mjsunit/third_party/array-splice-webkit.js


Index: src/array.js
===================================================================
--- src/array.js        (revision 5365)
+++ src/array.js        (working copy)
@@ -566,12 +566,11 @@
 function ArraySplice(start, delete_count) {
   var num_arguments = %_ArgumentsLength();

-  // SpiderMonkey and JSC return undefined in the case where no
+  // SpiderMonkey and JSC return an empty array 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;
+  if (num_arguments == 0) return new $Array();

   var len = TO_UINT32(this.length);
   var start_i = TO_INTEGER(start);
Index: src/builtins.cc
===================================================================
--- src/builtins.cc     (revision 5365)
+++ src/builtins.cc     (working copy)
@@ -663,13 +663,13 @@

   int n_arguments = args.length() - 1;

-  // SpiderMonkey and JSC return undefined in the case where no
+  // SpiderMonkey and JSC return and empty array 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 (n_arguments == 0) {
-    return Heap::undefined_value();
+    // No handle scope needed since we return directly.
+    return *Factory::NewJSArray(0);
   }

   int relative_start = 0;
Index: test/mjsunit/array-splice.js
===================================================================
--- test/mjsunit/array-splice.js        (revision 5365)
+++ test/mjsunit/array-splice.js        (working copy)
@@ -67,13 +67,13 @@
 (function() {
   var array;
   for (var i = 0; i < 7; i++) {
-    // SpiderMonkey and JSC return undefined in the case where no
+    // SpiderMonkey and JSC return a new empty array 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: test/mjsunit/third_party/array-splice-webkit.js
===================================================================
--- test/mjsunit/third_party/array-splice-webkit.js     (revision 5365)
+++ test/mjsunit/third_party/array-splice-webkit.js     (working copy)
@@ -38,7 +38,7 @@
 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);


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to