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

Unified Diff: src/objects.cc

Issue 11369135: Object.observe: notify when element addition causes array growth (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: After review Created 8 years, 1 month 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/harmony/object-observe.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 570f6fbae4f7c0269db737c7e03ac6a33c0865df..fd6f4041d8e4f36c0d392addbc6e96c0b6f30f89 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10307,6 +10307,7 @@ MaybeObject* JSObject::SetElement(uint32_t index,
// From here on, everything has to be handlified.
Handle<String> name;
Handle<Object> old_value(isolate->heap()->the_hole_value());
+ Handle<Object> old_array_length;
PropertyAttributes old_attributes = ABSENT;
bool preexists = false;
if (FLAG_harmony_observation && map()->is_observed()) {
@@ -10316,6 +10317,9 @@ MaybeObject* JSObject::SetElement(uint32_t index,
old_attributes = self->GetLocalPropertyAttribute(*name);
// TODO(observe): only read & set old_value if we have a data property
old_value = Object::GetElement(self, index);
+ } else if (self->IsJSArray()) {
+ // Store old array length in case adding an element grows the array.
+ old_array_length = handle(Handle<JSArray>::cast(self)->length());
}
}
@@ -10333,11 +10337,17 @@ MaybeObject* JSObject::SetElement(uint32_t index,
PropertyAttributes new_attributes = self->GetLocalPropertyAttribute(*name);
if (!preexists) {
EnqueueChangeRecord(self, "new", name, old_value);
+ if (self->IsJSArray() &&
+ !old_array_length->SameValue(Handle<JSArray>::cast(self)->length())) {
+ EnqueueChangeRecord(self, "updated",
+ isolate->factory()->length_symbol(),
+ old_array_length);
+ }
} else if (new_attributes != old_attributes || old_value->IsTheHole()) {
EnqueueChangeRecord(self, "reconfigured", name, old_value);
} else {
- Handle<Object> newValue = Object::GetElement(self, index);
- if (!newValue->SameValue(*old_value))
+ Handle<Object> new_value = Object::GetElement(self, index);
+ if (!new_value->SameValue(*old_value))
EnqueueChangeRecord(self, "updated", name, old_value);
}
}
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698