Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: src/builtins.cc

Issue 669075: Fix a special case (zero length result array). (Closed)
Patch Set: Addressing Vitaly's concerns Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/array-slice.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index b51de33d923581d9dd7a8e529fe719a6d15a476f..50f36e56e6b7ee3f27a06e7082d58db1143eede6 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -251,6 +251,16 @@ static Object* AllocateJSArray() {
}
+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,
FixedArray* dst,
int dst_index,
@@ -535,8 +545,8 @@ BUILTIN(ArraySlice) {
// 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 @@ BUILTIN(ArraySplice) {
}
}
int actualDeleteCount = Min(Max(deleteCount, 0), len - actualStart);
+ if (actualDeleteCount == 0) {
+ return AllocateEmptyJSArray();
+ }
// Allocate result array.
Object* result = AllocateJSArray();
« no previous file with comments | « no previous file | test/mjsunit/array-slice.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698