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

Side by Side Diff: src/objects.cc

Issue 11820004: Object.observe: don't unnecessarily emit oldValue for reconfigurations of data properties (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 11 months 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 3168 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 case NONEXISTENT: 3179 case NONEXISTENT:
3180 UNREACHABLE(); 3180 UNREACHABLE();
3181 } 3181 }
3182 3182
3183 Handle<Object> hresult; 3183 Handle<Object> hresult;
3184 if (!result->ToHandle(&hresult, isolate)) return result; 3184 if (!result->ToHandle(&hresult, isolate)) return result;
3185 3185
3186 if (is_observed) { 3186 if (is_observed) {
3187 if (lookup.IsTransition()) { 3187 if (lookup.IsTransition()) {
3188 EnqueueChangeRecord(self, "new", name, old_value); 3188 EnqueueChangeRecord(self, "new", name, old_value);
3189 } else if (old_value->IsTheHole()) {
rossberg 2013/01/17 16:57:44 Is this extra branch actually needed? It seems lik
adamk 2013/01/22 22:30:10 I think I pulled this out to avoid an unnecessary
rossberg 2013/01/28 13:30:43 Yeah, the fewer code paths the better, but I don't
3190 EnqueueChangeRecord(self, "reconfigured", name, old_value);
3189 } else { 3191 } else {
3190 LookupResult new_lookup(isolate); 3192 LookupResult new_lookup(isolate);
3191 self->LocalLookup(*name, &new_lookup, true); 3193 self->LocalLookup(*name, &new_lookup, true);
3192 if (old_value->IsTheHole() || 3194 bool value_changed = new_lookup.IsDataProperty() &&
3193 new_lookup.GetAttributes() != old_attributes) { 3195 !old_value->SameValue(*Object::GetProperty(self, name));
3196 if (new_lookup.GetAttributes() != old_attributes) {
3197 if (!value_changed) old_value = isolate->factory()->the_hole_value();
3194 EnqueueChangeRecord(self, "reconfigured", name, old_value); 3198 EnqueueChangeRecord(self, "reconfigured", name, old_value);
3195 } else if (new_lookup.IsDataProperty() && 3199 } else if (value_changed) {
3196 !Object::GetProperty(self, name)->SameValue(*old_value)) {
3197 EnqueueChangeRecord(self, "updated", name, old_value); 3200 EnqueueChangeRecord(self, "updated", name, old_value);
3198 } 3201 }
3199 } 3202 }
3200 } 3203 }
3201 3204
3202 return *hresult; 3205 return *hresult;
3203 } 3206 }
3204 3207
3205 3208
3206 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( 3209 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor(
(...skipping 7042 matching lines...) Expand 10 before | Expand all | Expand 10 after
10249 10252
10250 Handle<String> name = isolate->factory()->Uint32ToString(index); 10253 Handle<String> name = isolate->factory()->Uint32ToString(index);
10251 PropertyAttributes new_attributes = self->GetLocalElementAttribute(index); 10254 PropertyAttributes new_attributes = self->GetLocalElementAttribute(index);
10252 if (old_attributes == ABSENT) { 10255 if (old_attributes == ABSENT) {
10253 EnqueueChangeRecord(self, "new", name, old_value); 10256 EnqueueChangeRecord(self, "new", name, old_value);
10254 if (self->IsJSArray() && 10257 if (self->IsJSArray() &&
10255 !old_length->SameValue(Handle<JSArray>::cast(self)->length())) { 10258 !old_length->SameValue(Handle<JSArray>::cast(self)->length())) {
10256 EnqueueChangeRecord( 10259 EnqueueChangeRecord(
10257 self, "updated", isolate->factory()->length_symbol(), old_length); 10260 self, "updated", isolate->factory()->length_symbol(), old_length);
10258 } 10261 }
10259 } else if (old_attributes != new_attributes || old_value->IsTheHole()) { 10262 } else if (old_value->IsTheHole()) {
rossberg 2013/01/17 16:57:44 Similarly here.
10260 EnqueueChangeRecord(self, "reconfigured", name, old_value); 10263 EnqueueChangeRecord(self, "reconfigured", name, old_value);
10261 } else if (!old_value->SameValue(*Object::GetElement(self, index))) { 10264 } else {
10262 EnqueueChangeRecord(self, "updated", name, old_value); 10265 bool value_changed =
10266 !old_value->SameValue(*Object::GetElement(self, index));
10267 if (old_attributes != new_attributes) {
10268 if (!value_changed) old_value = isolate->factory()->the_hole_value();
10269 EnqueueChangeRecord(self, "reconfigured", name, old_value);
10270 } else if (value_changed) {
10271 EnqueueChangeRecord(self, "updated", name, old_value);
10272 }
10263 } 10273 }
10264 10274
10265 return *hresult; 10275 return *hresult;
10266 } 10276 }
10267 10277
10268 10278
10269 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index, 10279 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index,
10270 Object* value, 10280 Object* value,
10271 PropertyAttributes attr, 10281 PropertyAttributes attr,
10272 StrictModeFlag strict_mode, 10282 StrictModeFlag strict_mode,
(...skipping 3452 matching lines...) Expand 10 before | Expand all | Expand 10 after
13725 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13735 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13726 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13736 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13727 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13737 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13728 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13738 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13729 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13739 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13730 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13740 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13731 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13741 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13732 } 13742 }
13733 13743
13734 } } // namespace v8::internal 13744 } } // 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