Fix Array.{splice,slice} to set proper ElementsKind of result

TEST=mjsunit/elements-kind.js

Review URL: http://codereview.chromium.org/8430036

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9882 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f2787a42
......@@ -772,6 +772,13 @@ BUILTIN(ArraySlice) {
// 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 @@ BUILTIN(ArraySplice) {
// 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;
......
......@@ -326,5 +326,15 @@ if (support_smi_only_arrays) {
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();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment