// 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);
})();
-// 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);
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);
})();
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);
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);