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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/harmony/object-observe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10289 matching lines...) Expand 10 before | Expand all | Expand 10 after
10300 SeededNumberDictionary* dictionary; 10300 SeededNumberDictionary* dictionary;
10301 MaybeObject* maybe_object = NormalizeElements(); 10301 MaybeObject* maybe_object = NormalizeElements();
10302 if (!maybe_object->To(&dictionary)) return maybe_object; 10302 if (!maybe_object->To(&dictionary)) return maybe_object;
10303 // Make sure that we never go back to fast case. 10303 // Make sure that we never go back to fast case.
10304 dictionary->set_requires_slow_elements(); 10304 dictionary->set_requires_slow_elements();
10305 } 10305 }
10306 10306
10307 // From here on, everything has to be handlified. 10307 // From here on, everything has to be handlified.
10308 Handle<String> name; 10308 Handle<String> name;
10309 Handle<Object> old_value(isolate->heap()->the_hole_value()); 10309 Handle<Object> old_value(isolate->heap()->the_hole_value());
10310 Handle<Object> old_array_length;
10310 PropertyAttributes old_attributes = ABSENT; 10311 PropertyAttributes old_attributes = ABSENT;
10311 bool preexists = false; 10312 bool preexists = false;
10312 if (FLAG_harmony_observation && map()->is_observed()) { 10313 if (FLAG_harmony_observation && map()->is_observed()) {
10313 name = isolate->factory()->Uint32ToString(index); 10314 name = isolate->factory()->Uint32ToString(index);
10314 preexists = self->HasLocalElement(index); 10315 preexists = self->HasLocalElement(index);
10315 if (preexists) { 10316 if (preexists) {
10316 old_attributes = self->GetLocalPropertyAttribute(*name); 10317 old_attributes = self->GetLocalPropertyAttribute(*name);
10317 // TODO(observe): only read & set old_value if we have a data property 10318 // TODO(observe): only read & set old_value if we have a data property
10318 old_value = Object::GetElement(self, index); 10319 old_value = Object::GetElement(self, index);
10319 } 10320 }
10321 // Store the old array length in case adding an element will grow the array.
10322 if (!preexists && self->IsJSArray())
rossberg 2012/11/08 16:50:20 Maybe make that an "else if (self->IsJSArray())"
adamk 2012/11/08 17:08:18 Done.
10323 old_array_length = handle(Handle<JSArray>::cast(self)->length());
10320 } 10324 }
10321 10325
10322 // Check for lookup interceptor 10326 // Check for lookup interceptor
10323 MaybeObject* result = self->HasIndexedInterceptor() 10327 MaybeObject* result = self->HasIndexedInterceptor()
10324 ? self->SetElementWithInterceptor( 10328 ? self->SetElementWithInterceptor(
10325 index, *value, attributes, strict_mode, check_prototype, set_mode) 10329 index, *value, attributes, strict_mode, check_prototype, set_mode)
10326 : self->SetElementWithoutInterceptor( 10330 : self->SetElementWithoutInterceptor(
10327 index, *value, attributes, strict_mode, check_prototype, set_mode); 10331 index, *value, attributes, strict_mode, check_prototype, set_mode);
10328 10332
10329 Handle<Object> hresult; 10333 Handle<Object> hresult;
10330 if (!result->ToHandle(&hresult)) return result; 10334 if (!result->ToHandle(&hresult)) return result;
10331 10335
10332 if (FLAG_harmony_observation && map()->is_observed()) { 10336 if (FLAG_harmony_observation && map()->is_observed()) {
10333 PropertyAttributes new_attributes = self->GetLocalPropertyAttribute(*name); 10337 PropertyAttributes new_attributes = self->GetLocalPropertyAttribute(*name);
10334 if (!preexists) { 10338 if (!preexists) {
10339 if (self->IsJSArray() &&
10340 !old_array_length->SameValue(Handle<JSArray>::cast(self)->length())) {
10341 EnqueueChangeRecord(self, "updated",
10342 isolate->factory()->length_symbol(),
10343 old_array_length);
10344 }
10335 EnqueueChangeRecord(self, "new", name, old_value); 10345 EnqueueChangeRecord(self, "new", name, old_value);
10336 } else if (new_attributes != old_attributes || old_value->IsTheHole()) { 10346 } else if (new_attributes != old_attributes || old_value->IsTheHole()) {
10337 EnqueueChangeRecord(self, "reconfigured", name, old_value); 10347 EnqueueChangeRecord(self, "reconfigured", name, old_value);
10338 } else { 10348 } else {
10339 Handle<Object> newValue = Object::GetElement(self, index); 10349 Handle<Object> newValue = Object::GetElement(self, index);
rossberg 2012/11/08 16:50:20 Not your change, but while you're at it, can you a
adamk 2012/11/08 17:08:18 Fixed.
10340 if (!newValue->SameValue(*old_value)) 10350 if (!newValue->SameValue(*old_value))
10341 EnqueueChangeRecord(self, "updated", name, old_value); 10351 EnqueueChangeRecord(self, "updated", name, old_value);
10342 } 10352 }
10343 } 10353 }
10344 10354
10345 return *hresult; 10355 return *hresult;
10346 } 10356 }
10347 10357
10348 10358
10349 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index, 10359 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index,
(...skipping 3497 matching lines...) Expand 10 before | Expand all | Expand 10 after
13847 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13857 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13848 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13858 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13849 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13859 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13850 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13860 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13851 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13861 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13852 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13862 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13853 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13863 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13854 } 13864 }
13855 13865
13856 } } // namespace v8::internal 13866 } } // namespace v8::internal
OLDNEW
« 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