Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index 99fd8e21f0a6dfd0ba2019289caf06c770f241a0..9fad170949b68b6d52c604dc0bd68e81780cc7f7 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -1990,6 +1990,52 @@ void JSObject::EnqueueChangeRecord(Handle<JSObject> object, |
| ASSERT(!threw); |
| } |
|
adamk
2013/05/24 00:15:30
v8 style nit: need two blank lines between functio
rafaelw
2013/05/24 19:11:43
Done.
|
| +void JSObject::EnqueueSpliceRecord(Handle<JSArray> object, |
| + uint32_t index, |
| + Handle<JSArray> deleted, |
| + uint32_t delete_count, |
|
adamk
2013/05/24 00:15:30
I know we discussed this before, but can you avoid
rafaelw
2013/05/24 19:11:43
I've put a todo to go back and remove it. There ar
|
| + uint32_t add_count) { |
| + Isolate* isolate = object->GetIsolate(); |
| + HandleScope scope(isolate); |
| + Handle<Object> index_object = isolate->factory()->NewNumberFromUint(index); |
| + Handle<Object> delete_count_object = |
| + isolate->factory()->NewNumberFromUint(delete_count); |
| + Handle<Object> add_count_object = |
| + isolate->factory()->NewNumberFromUint(add_count); |
| + |
| + Handle<Object> args[] = |
| + { object, index_object, deleted, delete_count_object, add_count_object }; |
| + |
| + bool threw; |
| + Execution::Call(Handle<JSFunction>(isolate->observers_enqueue_splice()), |
| + isolate->factory()->undefined_value(), 5, args, |
|
adamk
2013/05/24 00:15:30
I'd use ARRAY_SIZE(args) here, and below.
rafaelw
2013/05/24 19:11:43
Done.
|
| + &threw); |
| + ASSERT(!threw); |
| +} |
| + |
|
adamk
2013/05/24 00:15:30
same whitespace nit, and so on below
rafaelw
2013/05/24 19:11:43
Done.
|
| +void JSObject::BeginPerformSplice(Handle<JSArray> object) { |
| + Isolate* isolate = object->GetIsolate(); |
| + HandleScope scope(isolate); |
| + Handle<Object> args[] = { object }; |
| + |
| + bool threw; |
| + Execution::Call(Handle<JSFunction>(isolate->observers_begin_perform_splice()), |
| + isolate->factory()->undefined_value(), 1, args, |
| + &threw); |
| + ASSERT(!threw); |
| +} |
| + |
| +void JSObject::EndPerformSplice(Handle<JSArray> object) { |
| + Isolate* isolate = object->GetIsolate(); |
| + HandleScope scope(isolate); |
| + Handle<Object> args[] = { object }; |
| + |
| + bool threw; |
| + Execution::Call(Handle<JSFunction>(isolate->observers_end_perform_splice()), |
| + isolate->factory()->undefined_value(), 1, args, |
| + &threw); |
| + ASSERT(!threw); |
| +} |
| void JSObject::DeliverChangeRecords(Isolate* isolate) { |
| ASSERT(isolate->observer_delivery_pending()); |
| @@ -10899,14 +10945,14 @@ static bool GetOldValue(Isolate* isolate, |
| Handle<JSObject> object, |
| uint32_t index, |
| List<Handle<Object> >* old_values, |
| - List<Handle<String> >* indices) { |
| + List<uint32_t>* indices) { |
| PropertyAttributes attributes = object->GetLocalElementAttribute(index); |
| ASSERT(attributes != ABSENT); |
| if (attributes == DONT_DELETE) return false; |
| old_values->Add(object->GetLocalElementAccessorPair(index) == NULL |
| ? Object::GetElement(object, index) |
| : Handle<Object>::cast(isolate->factory()->the_hole_value())); |
| - indices->Add(isolate->factory()->Uint32ToString(index)); |
| + indices->Add(index); |
| return true; |
| } |
| @@ -10920,7 +10966,7 @@ MaybeObject* JSArray::SetElementsLength(Object* len) { |
| Isolate* isolate = GetIsolate(); |
| HandleScope scope(isolate); |
| Handle<JSArray> self(this); |
| - List<Handle<String> > indices; |
| + List<uint32_t> indices; |
| List<Handle<Object> > old_values; |
| Handle<Object> old_length_handle(self->length(), isolate); |
| Handle<Object> new_length_handle(len, isolate); |
| @@ -10960,15 +11006,34 @@ MaybeObject* JSArray::SetElementsLength(Object* len) { |
| if (!result->ToHandle(&hresult, isolate)) return result; |
| CHECK(self->length()->ToArrayIndex(&new_length)); |
| - if (old_length != new_length) { |
| - for (int i = 0; i < indices.length(); ++i) { |
| - JSObject::EnqueueChangeRecord( |
| - self, "deleted", indices[i], old_values[i]); |
| - } |
| + if (old_length == new_length) |
| + return *hresult; |
|
adamk
2013/05/24 00:15:30
v8 style puts this on the previous line
rafaelw
2013/05/24 19:11:43
Done.
|
| + |
| + JSObject::BeginPerformSplice(self); |
| + |
| + for (int i = 0; i < indices.length(); ++i) { |
| JSObject::EnqueueChangeRecord( |
| - self, "updated", isolate->factory()->length_string(), |
| - old_length_handle); |
| + self, "deleted", isolate->factory()->Uint32ToString(indices[i]), |
| + old_values[i]); |
| } |
| + JSObject::EnqueueChangeRecord( |
| + self, "updated", isolate->factory()->length_string(), |
| + old_length_handle); |
| + |
| + JSObject::EndPerformSplice(self); |
| + |
| + uint32_t index = new_length > old_length ? old_length : new_length; |
|
adamk
2013/05/24 00:15:30
this would be slightly more readable as min(old_le
rafaelw
2013/05/24 19:11:43
Done.
|
| + uint32_t add_count = new_length > old_length ? new_length - old_length : 0; |
| + uint32_t delete_count = new_length < old_length ? old_length - new_length : 0; |
| + Handle<JSArray> deleted = isolate->factory()->NewJSArray(0); |
| + if (delete_count) { |
| + for (int i = 0; i < indices.length(); ++i) |
|
adamk
2013/05/24 00:15:30
Note that these indices are in descending order du
rafaelw
2013/05/24 19:11:43
Done.
|
| + JSObject::SetElement(deleted, indices[i] - index, old_values[i], |
| + NONE, kNonStrictMode); |
| + } |
| + |
| + JSObject::EnqueueSpliceRecord(self, index, deleted, delete_count, add_count); |
| + |
| return *hresult; |
| } |
| @@ -11993,14 +12058,18 @@ MaybeObject* JSObject::SetElement(uint32_t index, |
| Handle<Object> value(value_raw, isolate); |
| PropertyAttributes old_attributes = self->GetLocalElementAttribute(index); |
| Handle<Object> old_value = isolate->factory()->the_hole_value(); |
| - Handle<Object> old_length; |
| + Handle<Object> old_length_handle; |
| + Handle<Object> new_length_handle; |
| + uint32_t old_length = 0; |
| + uint32_t new_length = 0; |
| if (old_attributes != ABSENT) { |
| if (self->GetLocalElementAccessorPair(index) == NULL) |
| old_value = Object::GetElement(self, index); |
| } else if (self->IsJSArray()) { |
| // Store old array length in case adding an element grows the array. |
| - old_length = handle(Handle<JSArray>::cast(self)->length(), isolate); |
| + old_length_handle = handle(Handle<JSArray>::cast(self)->length(), isolate); |
| + CHECK(old_length_handle->ToArrayIndex(&old_length)); |
| } |
| // Check for lookup interceptor |
| @@ -12016,11 +12085,27 @@ MaybeObject* JSObject::SetElement(uint32_t index, |
| Handle<String> name = isolate->factory()->Uint32ToString(index); |
| PropertyAttributes new_attributes = self->GetLocalElementAttribute(index); |
| if (old_attributes == ABSENT) { |
| - EnqueueChangeRecord(self, "new", name, old_value); |
| + bool array_extended = false; |
| if (self->IsJSArray() && |
| - !old_length->SameValue(Handle<JSArray>::cast(self)->length())) { |
| - EnqueueChangeRecord( |
| - self, "updated", isolate->factory()->length_string(), old_length); |
| + !old_length_handle->SameValue(Handle<JSArray>::cast(self)->length())) { |
| + array_extended = true; |
| + new_length_handle = handle(Handle<JSArray>::cast(self)->length(), |
| + isolate); |
| + CHECK(new_length_handle->ToArrayIndex(&new_length)); |
|
adamk
2013/05/24 00:15:30
We should really find a better way to avoid droppi
|
| + JSObject::BeginPerformSplice(Handle<JSArray>::cast(self)); |
| + } |
| + |
| + EnqueueChangeRecord(self, "new", name, old_value); |
| + if (array_extended) { |
| + EnqueueChangeRecord(self, "updated", isolate->factory()->length_string(), |
| + old_length_handle); |
| + |
| + JSObject::EndPerformSplice(Handle<JSArray>::cast(self)); |
| + Handle<JSArray> deleted = isolate->factory()->NewJSArray(0); |
| + JSObject::EnqueueSpliceRecord(Handle<JSArray>::cast(self), old_length, |
| + deleted, |
| + 0, |
| + new_length - old_length); |
| } |
| } else if (old_value->IsTheHole()) { |
| EnqueueChangeRecord(self, "reconfigured", name, old_value); |