From d955b212b5b54da302f0f958c125477be3fd4012 Mon Sep 17 00:00:00 2001 From: "ager@chromium.org" Date: Mon, 30 Aug 2010 18:08:50 +0000 Subject: [PATCH] Follow Safari and Firefox in returning empty array from array splice 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 | 7 ------- src/builtins.cc | 9 +++------ test/mjsunit/array-splice.js | 7 +------ test/mjsunit/third_party/array-splice-webkit.js | 2 +- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/array.js b/src/array.js index dfa7301..e12df64 100644 --- a/src/array.js +++ b/src/array.js @@ -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); diff --git a/src/builtins.cc b/src/builtins.cc index a64bf4e..a2ff909 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -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; diff --git a/test/mjsunit/array-splice.js b/test/mjsunit/array-splice.js index 88c4876..68dd9b2 100644 --- a/test/mjsunit/array-splice.js +++ b/test/mjsunit/array-splice.js @@ -67,13 +67,8 @@ (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 diff --git a/test/mjsunit/third_party/array-splice-webkit.js b/test/mjsunit/third_party/array-splice-webkit.js index b676a7c..974ac55 100644 --- a/test/mjsunit/third_party/array-splice-webkit.js +++ b/test/mjsunit/third_party/array-splice-webkit.js @@ -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); -- 2.7.4