Revision: 24854
Author:   [email protected]
Date:     Thu Oct 23 17:46:34 2014 UTC
Log:      Change SmartMove no-op behavior to match SimpleMove (and ES6 spec)

The previous behavior, which caused Array.prototype.unshift() (with no args)
to have side-effects, no longer matches the spec (ES6 changed the no-arg behavior
in April 2014). The new SmartMove behavior is also compatible with current
versions of Firefox.

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.

[email protected]

Review URL: https://codereview.chromium.org/666883009
https://code.google.com/p/v8/source/detail?r=24854

Modified:
 /branches/bleeding_edge/src/array.js
 /branches/bleeding_edge/test/mjsunit/array-unshift.js

=======================================
--- /branches/bleeding_edge/src/array.js        Wed Oct 22 13:13:19 2014 UTC
+++ /branches/bleeding_edge/src/array.js        Thu Oct 23 17:46:34 2014 UTC
@@ -234,6 +234,8 @@
// 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);
=======================================
--- /branches/bleeding_edge/test/mjsunit/array-unshift.js Wed Oct 15 23:53:02 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/array-unshift.js Thu Oct 23 17:46:34 2014 UTC
@@ -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