Commit d955b212 authored by ager@chromium.org's avatar ager@chromium.org

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
parent e9461cc5
...@@ -566,13 +566,6 @@ function ArraySlice(start, end) { ...@@ -566,13 +566,6 @@ function ArraySlice(start, end) {
function ArraySplice(start, delete_count) { function ArraySplice(start, delete_count) {
var num_arguments = %_ArgumentsLength(); 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 len = TO_UINT32(this.length);
var start_i = TO_INTEGER(start); var start_i = TO_INTEGER(start);
......
...@@ -663,13 +663,10 @@ BUILTIN(ArraySplice) { ...@@ -663,13 +663,10 @@ BUILTIN(ArraySplice) {
int n_arguments = args.length() - 1; int n_arguments = args.length() - 1;
// SpiderMonkey and JSC return undefined in the case where no // Return empty array when no arguments are supplied.
// 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) { if (n_arguments == 0) {
return Heap::undefined_value(); // No handle scope needed since we return directly.
return *Factory::NewJSArray(0);
} }
int relative_start = 0; int relative_start = 0;
......
...@@ -67,13 +67,8 @@ ...@@ -67,13 +67,8 @@
(function() { (function() {
var array; var array;
for (var i = 0; i < 7; i++) { 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] array = [1, 2, 3]
assertEquals(undefined, array.splice()); assertEquals([], array.splice());
assertEquals([1, 2, 3], array); assertEquals([1, 2, 3], array);
// SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is
......
...@@ -38,7 +38,7 @@ assertArrayEquals(['a','b'], arr.splice(0)); ...@@ -38,7 +38,7 @@ assertArrayEquals(['a','b'], arr.splice(0));
assertArrayEquals([], arr) assertArrayEquals([], arr)
arr = ['a','b','c','d']; arr = ['a','b','c','d'];
assertEquals(undefined, arr.splice()) assertEquals([], arr.splice())
assertArrayEquals(['a','b','c','d'], arr); assertArrayEquals(['a','b','c','d'], arr);
assertArrayEquals(['a','b','c','d'], arr.splice(undefined)) assertArrayEquals(['a','b','c','d'], arr.splice(undefined))
assertArrayEquals([], arr); assertArrayEquals([], arr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment