Reviewers: Michael Starzinger,

Description:
Change nonsensical SmartMove no-op behavior to match SimpleMove

The previous behavior, which caused Array.prototype.unshift() (with no args)
to have side-effects, is not spec-compliant nor web-compatible.

This is a baby step towards getting rid of SmartMove; it isolates the test
change in this patch, instead of lumping it in confusingly with all the
other test updates necessary for moving away from SmartMove.

Please review this at https://codereview.chromium.org/666883009/

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

Affected files (+13, -15 lines):
  M src/array.js
  M test/mjsunit/array-unshift.js


Index: src/array.js
diff --git a/src/array.js b/src/array.js
index 9e83d979e09b5f31c034cc457a32d62d809e0b15..585d1da8427507f0ef0ea3cb12470d3c9bc21488 100644
--- a/src/array.js
+++ b/src/array.js
@@ -234,6 +234,8 @@ function SmartSlice(array, start_i, del_count, len, deleted_elements) { // This function implements the optimized splice implementation that can use
 // special array operations to handle sparse arrays in a sensible fashion.
 function SmartMove(array, start_i, del_count, len, num_additional_args) {
+  // Bail out if no moving is necessary.
+  if (num_additional_args === del_count) return;
   // Move data to new array.
   var new_array = new InternalArray(len - del_count + num_additional_args);
   var indices = %GetArrayKeys(array, len);
Index: test/mjsunit/array-unshift.js
diff --git a/test/mjsunit/array-unshift.js b/test/mjsunit/array-unshift.js
index 0eb299a0cee2a145396c2e7036d2237667c256c7..50aab4f52a4b58a316053604c719d4465c48be9a 100644
--- a/test/mjsunit/array-unshift.js
+++ b/test/mjsunit/array-unshift.js
@@ -37,9 +37,7 @@
 })();


-// Check that unshift with no args has a side-effect of
-// filling the holes with elements from the prototype
-// (if present, of course)
+// Check that unshift with no args has no side-effects.
 (function() {
   var len = 3;
   var array = new Array(len);
@@ -65,15 +63,15 @@
   assertTrue(delete Array.prototype[0]);
   assertTrue(delete Array.prototype[2]);

-  // unshift makes array own 0 and 2...
-  assertTrue(array.hasOwnProperty(0));
+  // array still owns nothing...
+  assertFalse(array.hasOwnProperty(0));
   assertFalse(array.hasOwnProperty(1));
-  assertTrue(array.hasOwnProperty(2));
+  assertFalse(array.hasOwnProperty(2));

   // ... so they are not affected be delete.
-  assertEquals(array[0], at0);
+  assertEquals(array[0], undefined);
   assertEquals(array[1], undefined);
-  assertEquals(array[2], at2);
+  assertEquals(array[2], undefined);
 })();


@@ -115,9 +113,7 @@
   assertTrue(delete Array.prototype[7]);
 })();

-// Check that unshift with no args has a side-effect of
-// filling the holes with elements from the prototype
-// (if present, of course)
+// Check that unshift with no args has no side-effects.
 (function() {
   var len = 3;
   var array = new Array(len);
@@ -142,12 +138,12 @@

   assertEquals(len, array.unshift());

-  // unshift makes array own 0 and 2...
-  assertTrue(array.hasOwnProperty(0));
+  // array still owns nothing.
+  assertFalse(array.hasOwnProperty(0));
   assertFalse(array.hasOwnProperty(1));
-  assertTrue(array.hasOwnProperty(2));
+  assertFalse(array.hasOwnProperty(2));

-  // ... so they are not affected be delete.
+  // ... but still sees values from array_proto.
   assertEquals(array[0], at0);
   assertEquals(array[1], undefined);
   assertEquals(array[2], at2);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to