Reviewers: Mads Ager,

Message:
Mads,

may you have a look?

Description:
ArraySplice builtin should return empty array and not alter receiver if invoked
with no arguments.

Please review this at http://codereview.chromium.org/6357025/

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

Affected files:
  M src/array.js
  M test/mjsunit/array-splice.js


Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 0d7a7cbc85e1f89a490d229fa759d047b3966fa6..86738ff33f3e69386c38c9b2aabd163d63f48904 100644
--- a/src/array.js
+++ b/src/array.js
@@ -592,6 +592,8 @@ function ArraySlice(start, end) {
 function ArraySplice(start, delete_count) {
   var num_arguments = %_ArgumentsLength();

+  if (num_arguments == 0) return [];
+
   var len = TO_UINT32(this.length);
   var start_i = TO_INTEGER(start);

Index: test/mjsunit/array-splice.js
diff --git a/test/mjsunit/array-splice.js b/test/mjsunit/array-splice.js
index 68dd9b2baff02029217610be99ac62e9c4f2463c..0e307b5d3d8a28b4055a76ec49b9d1f4ac71ecae 100644
--- a/test/mjsunit/array-splice.js
+++ b/test/mjsunit/array-splice.js
@@ -339,6 +339,20 @@
 })();


+// Check the case of JS builtin .splice()
+(function() {
+  for (var i = 0; i < 7; i++) {
+    var array = [1, 2, 3, 4];
+    Array.prototype[3] = 'foo';  // To force JS builtin.
+
+    var spliced = array.splice();
+
+    assertEquals([], spliced);
+    assertEquals([1, 2, 3, 4], array);
+  }
+})();
+
+
 // Check the behaviour when approaching maximal values for length.
 (function() {
   for (var i = 0; i < 7; i++) {


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

Reply via email to