Revision: 9882
Author: [email protected]
Date: Fri Nov 4 05:47:58 2011
Log: Fix Array.{splice,slice} to set proper ElementsKind of result
TEST=mjsunit/elements-kind.js
Review URL: http://codereview.chromium.org/8430036
http://code.google.com/p/v8/source/detail?r=9882
Modified:
/branches/bleeding_edge/src/builtins.cc
/branches/bleeding_edge/test/mjsunit/elements-kind.js
=======================================
--- /branches/bleeding_edge/src/builtins.cc Wed Oct 19 05:10:18 2011
+++ /branches/bleeding_edge/src/builtins.cc Fri Nov 4 05:47:58 2011
@@ -772,6 +772,13 @@
// Set the length.
result_array->set_length(Smi::FromInt(result_len));
+
+ // Set the ElementsKind.
+ ElementsKind elements_kind = JSObject::cast(receiver)->GetElementsKind();
+ if (result_array->GetElementsKind() != elements_kind) {
+ MaybeObject* maybe =
result_array->TransitionElementsKind(elements_kind);
+ if (maybe->IsFailure()) return maybe;
+ }
return result_array;
}
@@ -865,6 +872,13 @@
// Set the length.
result_array->set_length(Smi::FromInt(actual_delete_count));
+
+ // Set the ElementsKind.
+ ElementsKind elements_kind = array->GetElementsKind();
+ if (result_array->GetElementsKind() != elements_kind) {
+ MaybeObject* maybe =
result_array->TransitionElementsKind(elements_kind);
+ if (maybe->IsFailure()) return maybe;
+ }
}
int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
=======================================
--- /branches/bleeding_edge/test/mjsunit/elements-kind.js Fri Nov 4
05:31:44 2011
+++ /branches/bleeding_edge/test/mjsunit/elements-kind.js Fri Nov 4
05:47:58 2011
@@ -325,6 +325,16 @@
assertKind(elements_kind.fast_smi_only, a);
assertEquals([1, 2, 3, 4, 5], a);
}
+
+// Test that Array.splice() and Array.slice() return correct ElementsKinds.
+if (support_smi_only_arrays) {
+ var a = ["foo", "bar"];
+ assertKind(elements_kind.fast, a);
+ var b = a.splice(0, 1);
+ assertKind(elements_kind.fast, b);
+ var c = a.slice(0, 1);
+ assertKind(elements_kind.fast, c);
+}
// Throw away type information in the ICs for next stress run.
gc();
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev