Commit 6fa98719 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Make (Object.)observed Arrays use SafeRemoveArrayHoles during sort

R=adamk,rossberg
BUG=

Review URL: https://codereview.chromium.org/15837006

Patch from Rafael Weinstein <rafaelw@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14847 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c06dc9d0
......@@ -1110,11 +1110,13 @@ function ArraySort(comparefn) {
max_prototype_element = CopyFromPrototype(this, length);
}
var num_non_undefined = %RemoveArrayHoles(this, length);
var num_non_undefined = %IsObserved(this) ?
-1 : %RemoveArrayHoles(this, length);
if (num_non_undefined == -1) {
// There were indexed accessors in the array. Move array holes and
// undefineds to the end using a Javascript function that is safe
// in the presence of accessors.
// The array is observed, or there were indexed accessors in the array.
// Move array holes and undefineds to the end using a Javascript function
// that is safe in the presence of accessors and is observable.
num_non_undefined = SafeRemoveArrayHoles(this);
}
......
......@@ -13758,12 +13758,13 @@ MaybeObject* JSObject::PrepareSlowElementsForSort(uint32_t limit) {
MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) {
Heap* heap = GetHeap();
ASSERT(!map()->is_observed());
if (HasDictionaryElements()) {
// Convert to fast elements containing only the existing properties.
// Ordering is irrelevant, since we are going to sort anyway.
SeededNumberDictionary* dict = element_dictionary();
if (IsJSArray() || dict->requires_slow_elements() ||
dict->max_number_key() >= limit || map()->is_observed()) {
dict->max_number_key() >= limit) {
return PrepareSlowElementsForSort(limit);
}
// Convert to fast elements.
......
......@@ -1142,6 +1142,22 @@ observer.assertCallbackRecords([
{ object: array, name: '2', type: 'updated', oldValue: 3 },
]);
// Sort
reset();
var array = [3, 2, 1];
Object.observe(array, observer.callback);
array.sort();
assertEquals(1, array[0]);
assertEquals(2, array[1]);
assertEquals(3, array[2]);
Object.deliverChangeRecords(observer.callback);
observer.assertCallbackRecords([
{ object: array, name: '1', type: 'updated', oldValue: 2 },
{ object: array, name: '0', type: 'updated', oldValue: 3 },
{ object: array, name: '2', type: 'updated', oldValue: 1 },
{ object: array, name: '1', type: 'updated', oldValue: 3 },
{ object: array, name: '0', type: 'updated', oldValue: 2 },
]);
//
// === PLAIN OBJECTS ===
......
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