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

Side by Side Diff: src/objects.cc

Issue 11338048: Handle Object.observe notifications for setting Array.length (Closed) Base URL: git@github.com:rafaelw/v8@master
Patch Set: Merged with trunk 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
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 1699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 result = AddSlowProperty(name, value, attributes); 1710 result = AddSlowProperty(name, value, attributes);
1711 } 1711 }
1712 } else { 1712 } else {
1713 result = AddSlowProperty(name, value, attributes); 1713 result = AddSlowProperty(name, value, attributes);
1714 } 1714 }
1715 1715
1716 Handle<Object> hresult; 1716 Handle<Object> hresult;
1717 if (!result->ToHandle(&hresult)) return result; 1717 if (!result->ToHandle(&hresult)) return result;
1718 1718
1719 if (FLAG_harmony_observation && map()->is_observed()) { 1719 if (FLAG_harmony_observation && map()->is_observed()) {
1720 this->EnqueueChangeRecord( 1720 EnqueueChangeRecord(handle(this), "new", handle(name),
1721 "new", handle(name), handle(heap->the_hole_value())); 1721 handle(heap->the_hole_value()));
1722 } 1722 }
1723 1723
1724 return *hresult; 1724 return *hresult;
1725 } 1725 }
1726 1726
1727 1727
1728 void JSObject::EnqueueChangeRecord( 1728 void JSObject::EnqueueChangeRecord(Handle<JSObject> object,
1729 const char* type_str, Handle<String> name, Handle<Object> old_value) { 1729 const char* type_str,
1730 Isolate* isolate = GetIsolate(); 1730 Handle<String> name,
1731 Handle<Object> old_value) {
1732 Isolate* isolate = object->GetIsolate();
1731 HandleScope scope; 1733 HandleScope scope;
1732 Handle<String> type = isolate->factory()->LookupAsciiSymbol(type_str); 1734 Handle<String> type = isolate->factory()->LookupAsciiSymbol(type_str);
1733 Handle<JSObject> object(this);
1734 Handle<Object> args[] = { type, object, name, old_value }; 1735 Handle<Object> args[] = { type, object, name, old_value };
1735 bool threw; 1736 bool threw;
1736 Execution::Call(Handle<JSFunction>(isolate->observers_notify_change()), 1737 Execution::Call(Handle<JSFunction>(isolate->observers_notify_change()),
1737 Handle<Object>(isolate->heap()->undefined_value()), 1738 Handle<Object>(isolate->heap()->undefined_value()),
1738 old_value->IsTheHole() ? 3 : 4, args, 1739 old_value->IsTheHole() ? 3 : 4, args,
1739 &threw); 1740 &threw);
1740 ASSERT(!threw); 1741 ASSERT(!threw);
1741 } 1742 }
1742 1743
1743 1744
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 case HANDLER: 2978 case HANDLER:
2978 case NONEXISTENT: 2979 case NONEXISTENT:
2979 UNREACHABLE(); 2980 UNREACHABLE();
2980 } 2981 }
2981 2982
2982 Handle<Object> hresult; 2983 Handle<Object> hresult;
2983 if (!result->ToHandle(&hresult)) return result; 2984 if (!result->ToHandle(&hresult)) return result;
2984 2985
2985 if (FLAG_harmony_observation && map()->is_observed()) { 2986 if (FLAG_harmony_observation && map()->is_observed()) {
2986 if (lookup->IsTransition()) { 2987 if (lookup->IsTransition()) {
2987 self->EnqueueChangeRecord("new", name, old_value); 2988 EnqueueChangeRecord(self, "new", name, old_value);
2988 } else { 2989 } else {
2989 LookupResult new_lookup(self->GetIsolate()); 2990 LookupResult new_lookup(self->GetIsolate());
2990 self->LocalLookup(*name, &new_lookup); 2991 self->LocalLookup(*name, &new_lookup);
2991 ASSERT(!new_lookup.GetLazyValue()->IsTheHole()); 2992 ASSERT(!new_lookup.GetLazyValue()->IsTheHole());
2992 if (!new_lookup.GetLazyValue()->SameValue(*old_value)) { 2993 if (!new_lookup.GetLazyValue()->SameValue(*old_value)) {
2993 self->EnqueueChangeRecord("updated", name, old_value); 2994 EnqueueChangeRecord(self, "updated", name, old_value);
2994 } 2995 }
2995 } 2996 }
2996 } 2997 }
2997 2998
2998 return *hresult; 2999 return *hresult;
2999 } 3000 }
3000 3001
3001 3002
3002 // Set a real local property, even if it is READ_ONLY. If the property is not 3003 // Set a real local property, even if it is READ_ONLY. If the property is not
3003 // present, add it with attributes NONE. This code is an exact clone of 3004 // present, add it with attributes NONE. This code is an exact clone of
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3125 case HANDLER: 3126 case HANDLER:
3126 case NONEXISTENT: 3127 case NONEXISTENT:
3127 UNREACHABLE(); 3128 UNREACHABLE();
3128 } 3129 }
3129 3130
3130 Handle<Object> hresult; 3131 Handle<Object> hresult;
3131 if (!result->ToHandle(&hresult)) return result; 3132 if (!result->ToHandle(&hresult)) return result;
3132 3133
3133 if (FLAG_harmony_observation && map()->is_observed()) { 3134 if (FLAG_harmony_observation && map()->is_observed()) {
3134 if (lookup.IsTransition()) { 3135 if (lookup.IsTransition()) {
3135 self->EnqueueChangeRecord("new", name, old_value); 3136 EnqueueChangeRecord(self, "new", name, old_value);
3136 } else { 3137 } else {
3137 LookupResult new_lookup(isolate); 3138 LookupResult new_lookup(isolate);
3138 self->LocalLookup(*name, &new_lookup); 3139 self->LocalLookup(*name, &new_lookup);
3139 ASSERT(!new_lookup.GetLazyValue()->IsTheHole()); 3140 ASSERT(!new_lookup.GetLazyValue()->IsTheHole());
3140 if (old_value->IsTheHole() || 3141 if (old_value->IsTheHole() ||
3141 new_lookup.GetAttributes() != old_attributes) { 3142 new_lookup.GetAttributes() != old_attributes) {
3142 self->EnqueueChangeRecord("reconfigured", name, old_value); 3143 EnqueueChangeRecord(self, "reconfigured", name, old_value);
3143 } else if (!new_lookup.GetLazyValue()->SameValue(*old_value)) { 3144 } else if (!new_lookup.GetLazyValue()->SameValue(*old_value)) {
3144 self->EnqueueChangeRecord("updated", name, old_value); 3145 EnqueueChangeRecord(self, "updated", name, old_value);
3145 } 3146 }
3146 } 3147 }
3147 } 3148 }
3148 3149
3149 return *hresult; 3150 return *hresult;
3150 } 3151 }
3151 3152
3152 3153
3153 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor( 3154 PropertyAttributes JSObject::GetPropertyAttributePostInterceptor(
3154 JSObject* receiver, 3155 JSObject* receiver,
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
4131 result = self->DeleteElementWithInterceptor(index); 4132 result = self->DeleteElementWithInterceptor(index);
4132 } else { 4133 } else {
4133 result = self->GetElementsAccessor()->Delete(*self, index, mode); 4134 result = self->GetElementsAccessor()->Delete(*self, index, mode);
4134 } 4135 }
4135 4136
4136 Handle<Object> hresult; 4137 Handle<Object> hresult;
4137 if (!result->ToHandle(&hresult)) return result; 4138 if (!result->ToHandle(&hresult)) return result;
4138 4139
4139 if (FLAG_harmony_observation && map()->is_observed()) { 4140 if (FLAG_harmony_observation && map()->is_observed()) {
4140 if (preexists && !self->HasLocalElement(index)) 4141 if (preexists && !self->HasLocalElement(index))
4141 self->EnqueueChangeRecord("deleted", name, old_value); 4142 EnqueueChangeRecord(self, "deleted", name, old_value);
4142 } 4143 }
4143 4144
4144 return *hresult; 4145 return *hresult;
4145 } 4146 }
4146 4147
4147 4148
4148 Handle<Object> JSObject::DeleteProperty(Handle<JSObject> obj, 4149 Handle<Object> JSObject::DeleteProperty(Handle<JSObject> obj,
4149 Handle<String> prop) { 4150 Handle<String> prop) {
4150 CALL_HEAP_FUNCTION(obj->GetIsolate(), 4151 CALL_HEAP_FUNCTION(obj->GetIsolate(),
4151 obj->DeleteProperty(*prop, JSObject::NORMAL_DELETION), 4152 obj->DeleteProperty(*prop, JSObject::NORMAL_DELETION),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
4218 if (!result->To(&obj)) return result; 4219 if (!result->To(&obj)) return result;
4219 // Make sure the properties are normalized before removing the entry. 4220 // Make sure the properties are normalized before removing the entry.
4220 result = self->DeleteNormalizedProperty(*hname, mode); 4221 result = self->DeleteNormalizedProperty(*hname, mode);
4221 } 4222 }
4222 4223
4223 Handle<Object> hresult; 4224 Handle<Object> hresult;
4224 if (!result->ToHandle(&hresult)) return result; 4225 if (!result->ToHandle(&hresult)) return result;
4225 4226
4226 if (FLAG_harmony_observation && map()->is_observed()) { 4227 if (FLAG_harmony_observation && map()->is_observed()) {
4227 if (!self->HasLocalProperty(*hname)) 4228 if (!self->HasLocalProperty(*hname))
4228 self->EnqueueChangeRecord("deleted", hname, old_value); 4229 EnqueueChangeRecord(self, "deleted", hname, old_value);
4229 } 4230 }
4230 4231
4231 return *hresult; 4232 return *hresult;
4232 } 4233 }
4233 4234
4234 4235
4235 MaybeObject* JSReceiver::DeleteElement(uint32_t index, DeleteMode mode) { 4236 MaybeObject* JSReceiver::DeleteElement(uint32_t index, DeleteMode mode) {
4236 if (IsJSProxy()) { 4237 if (IsJSProxy()) {
4237 return JSProxy::cast(this)->DeleteElementWithHandler(index, mode); 4238 return JSProxy::cast(this)->DeleteElementWithHandler(index, mode);
4238 } 4239 }
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
4885 4886
4886 MaybeObject* result = is_element ? 4887 MaybeObject* result = is_element ?
4887 self->DefineElementAccessor(index, *getter, *setter, attributes) : 4888 self->DefineElementAccessor(index, *getter, *setter, attributes) :
4888 self->DefinePropertyAccessor(*name, *getter, *setter, attributes); 4889 self->DefinePropertyAccessor(*name, *getter, *setter, attributes);
4889 4890
4890 Handle<Object> hresult; 4891 Handle<Object> hresult;
4891 if (!result->ToHandle(&hresult)) return result; 4892 if (!result->ToHandle(&hresult)) return result;
4892 4893
4893 if (FLAG_harmony_observation && map()->is_observed()) { 4894 if (FLAG_harmony_observation && map()->is_observed()) {
4894 const char* type = preexists ? "reconfigured" : "new"; 4895 const char* type = preexists ? "reconfigured" : "new";
4895 self->EnqueueChangeRecord(type, name, old_value); 4896 EnqueueChangeRecord(self, type, name, old_value);
4896 } 4897 }
4897 4898
4898 return *hresult; 4899 return *hresult;
4899 } 4900 }
4900 4901
4901 4902
4902 static MaybeObject* TryAccessorTransition(JSObject* self, 4903 static MaybeObject* TryAccessorTransition(JSObject* self,
4903 Map* transitioned_map, 4904 Map* transitioned_map,
4904 int target_descriptor, 4905 int target_descriptor,
4905 AccessorComponent component, 4906 AccessorComponent component,
(...skipping 5404 matching lines...) Expand 10 before | Expand all | Expand 10 after
10310 index, *value, attributes, strict_mode, check_prototype, set_mode) 10311 index, *value, attributes, strict_mode, check_prototype, set_mode)
10311 : self->SetElementWithoutInterceptor( 10312 : self->SetElementWithoutInterceptor(
10312 index, *value, attributes, strict_mode, check_prototype, set_mode); 10313 index, *value, attributes, strict_mode, check_prototype, set_mode);
10313 10314
10314 Handle<Object> hresult; 10315 Handle<Object> hresult;
10315 if (!result->ToHandle(&hresult)) return result; 10316 if (!result->ToHandle(&hresult)) return result;
10316 10317
10317 if (FLAG_harmony_observation && map()->is_observed()) { 10318 if (FLAG_harmony_observation && map()->is_observed()) {
10318 PropertyAttributes new_attributes = self->GetLocalPropertyAttribute(*name); 10319 PropertyAttributes new_attributes = self->GetLocalPropertyAttribute(*name);
10319 if (!preexists) { 10320 if (!preexists) {
10320 self->EnqueueChangeRecord("new", name, old_value); 10321 EnqueueChangeRecord(self, "new", name, old_value);
10321 } else if (new_attributes != old_attributes || old_value->IsTheHole()) { 10322 } else if (new_attributes != old_attributes || old_value->IsTheHole()) {
10322 self->EnqueueChangeRecord("reconfigured", name, old_value); 10323 EnqueueChangeRecord(self, "reconfigured", name, old_value);
10323 } else { 10324 } else {
10324 Handle<Object> newValue = Object::GetElement(self, index); 10325 Handle<Object> newValue = Object::GetElement(self, index);
10325 if (!newValue->SameValue(*old_value)) 10326 if (!newValue->SameValue(*old_value))
10326 self->EnqueueChangeRecord("updated", name, old_value); 10327 EnqueueChangeRecord(self, "updated", name, old_value);
10327 } 10328 }
10328 } 10329 }
10329 10330
10330 return *hresult; 10331 return *hresult;
10331 } 10332 }
10332 10333
10333 10334
10334 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index, 10335 MaybeObject* JSObject::SetElementWithoutInterceptor(uint32_t index,
10335 Object* value, 10336 Object* value,
10336 PropertyAttributes attr, 10337 PropertyAttributes attr,
(...skipping 3495 matching lines...) Expand 10 before | Expand all | Expand 10 after
13832 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); 13833 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER);
13833 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); 13834 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER);
13834 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); 13835 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER);
13835 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); 13836 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER);
13836 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); 13837 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER);
13837 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); 13838 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER);
13838 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); 13839 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER);
13839 } 13840 }
13840 13841
13841 } } // namespace v8::internal 13842 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698