Revision: 4026
Author: [email protected]
Date: Thu Mar 4 13:29:33 2010
Log: Fix a special case (zero length result array).
Review URL: http://codereview.chromium.org/669075
http://code.google.com/p/v8/source/detail?r=4026
Modified:
/branches/bleeding_edge/src/builtins.cc
/branches/bleeding_edge/test/mjsunit/array-slice.js
/branches/bleeding_edge/test/mjsunit/array-splice.js
=======================================
--- /branches/bleeding_edge/src/builtins.cc Thu Mar 4 06:03:08 2010
+++ /branches/bleeding_edge/src/builtins.cc Thu Mar 4 13:29:33 2010
@@ -249,6 +249,16 @@
if (result->IsFailure()) return result;
return result;
}
+
+
+static Object* AllocateEmptyJSArray() {
+ Object* result = AllocateJSArray();
+ if (result->IsFailure()) return result;
+ JSArray* result_array = JSArray::cast(result);
+ result_array->set_length(Smi::FromInt(0));
+ result_array->set_elements(Heap::empty_fixed_array());
+ return result_array;
+}
static void CopyElements(AssertNoAllocation* no_gc,
@@ -535,8 +545,8 @@
// Calculate the length of result array.
int result_len = final - k;
- if (result_len < 0) {
- result_len = 0;
+ if (result_len <= 0) {
+ return AllocateEmptyJSArray();
}
Object* result = AllocateJSArray();
@@ -606,6 +616,9 @@
}
}
int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart);
+ if (actualDeleteCount == 0) {
+ return AllocateEmptyJSArray();
+ }
// Allocate result array.
Object* result = AllocateJSArray();
=======================================
--- /branches/bleeding_edge/test/mjsunit/array-slice.js Tue Feb 16 04:14:23
2010
+++ /branches/bleeding_edge/test/mjsunit/array-slice.js Thu Mar 4 13:29:33
2010
@@ -36,6 +36,17 @@
})();
+// Check various variants of empty array's slicing.
+(function() {
+ for (var i = 0; i < 7; i++) {
+ assertEquals([], [].slice(0, 0));
+ assertEquals([], [].slice(1, 0));
+ assertEquals([], [].slice(0, 1));
+ assertEquals([], [].slice(-1, 0));
+ }
+})();
+
+
// Check various forms of arguments omission.
(function() {
var array = new Array(7);
=======================================
--- /branches/bleeding_edge/test/mjsunit/array-splice.js Mon Mar 1
07:33:30 2010
+++ /branches/bleeding_edge/test/mjsunit/array-splice.js Thu Mar 4
13:29:33 2010
@@ -42,6 +42,17 @@
})();
+// Check various variants of empty array's splicing.
+(function() {
+ for (var i = 0; i < 7; i++) {
+ assertEquals([], [].splice(0, 0));
+ assertEquals([], [].splice(1, 0));
+ assertEquals([], [].splice(0, 1));
+ assertEquals([], [].splice(-1, 0));
+ }
+})();
+
+
// Check various forms of arguments omission.
(function() {
var array;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev