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

Side by Side Diff: src/objects.cc

Issue 200363002: Handlify callers of Object::GetElement. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 9 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 | « src/objects.h ('k') | src/objects-inl.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 return *result; 486 return *result;
487 } 487 }
488 488
489 489
490 Handle<Object> Object::GetProperty(Handle<Object> object, 490 Handle<Object> Object::GetProperty(Handle<Object> object,
491 Handle<Name> name) { 491 Handle<Name> name) {
492 // TODO(rossberg): The index test should not be here but in the GetProperty 492 // TODO(rossberg): The index test should not be here but in the GetProperty
493 // method (or somewhere else entirely). Needs more global clean-up. 493 // method (or somewhere else entirely). Needs more global clean-up.
494 uint32_t index; 494 uint32_t index;
495 Isolate* isolate = name->GetIsolate(); 495 Isolate* isolate = name->GetIsolate();
496 if (name->AsArrayIndex(&index)) 496 if (name->AsArrayIndex(&index)) return GetElement(isolate, object, index);
497 return GetElement(isolate, object, index);
498 CALL_HEAP_FUNCTION(isolate, object->GetProperty(*name), Object); 497 CALL_HEAP_FUNCTION(isolate, object->GetProperty(*name), Object);
499 } 498 }
500 499
501 500
502 Handle<Object> Object::GetElement(Isolate* isolate,
503 Handle<Object> object,
504 uint32_t index) {
505 CALL_HEAP_FUNCTION(isolate, object->GetElement(isolate, index), Object);
506 }
507
508
509 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver, 501 MaybeObject* JSProxy::GetElementWithHandler(Object* receiver,
510 uint32_t index) { 502 uint32_t index) {
511 String* name; 503 String* name;
512 MaybeObject* maybe = GetHeap()->Uint32ToString(index); 504 MaybeObject* maybe = GetHeap()->Uint32ToString(index);
513 if (!maybe->To<String>(&name)) return maybe; 505 if (!maybe->To<String>(&name)) return maybe;
514 return GetPropertyWithHandler(receiver, name); 506 return GetPropertyWithHandler(receiver, name);
515 } 507 }
516 508
517 509
518 Handle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy, 510 Handle<Object> JSProxy::SetElementWithHandler(Handle<JSProxy> proxy,
(...skipping 3550 matching lines...) Expand 10 before | Expand all | Expand 10 after
4069 } else { 4061 } else {
4070 return value; 4062 return value;
4071 } 4063 }
4072 } 4064 }
4073 4065
4074 Handle<Object> old_value = isolate->factory()->the_hole_value(); 4066 Handle<Object> old_value = isolate->factory()->the_hole_value();
4075 bool is_observed = object->map()->is_observed() && 4067 bool is_observed = object->map()->is_observed() &&
4076 *name != isolate->heap()->hidden_string(); 4068 *name != isolate->heap()->hidden_string();
4077 if (is_observed && lookup->IsDataProperty()) { 4069 if (is_observed && lookup->IsDataProperty()) {
4078 old_value = Object::GetProperty(object, name); 4070 old_value = Object::GetProperty(object, name);
4071 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
4079 } 4072 }
4080 4073
4081 // This is a real property that is not read-only, or it is a 4074 // This is a real property that is not read-only, or it is a
4082 // transition or null descriptor and there are no setters in the prototypes. 4075 // transition or null descriptor and there are no setters in the prototypes.
4083 Handle<Object> result = value; 4076 Handle<Object> result = value;
4084 switch (lookup->type()) { 4077 switch (lookup->type()) {
4085 case NORMAL: 4078 case NORMAL:
4086 SetNormalizedProperty(handle(lookup->holder()), lookup, value); 4079 SetNormalizedProperty(handle(lookup->holder()), lookup, value);
4087 break; 4080 break;
4088 case FIELD: 4081 case FIELD:
(...skipping 25 matching lines...) Expand all
4114 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>()); 4107 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, result, Handle<Object>());
4115 4108
4116 if (is_observed) { 4109 if (is_observed) {
4117 if (lookup->IsTransition()) { 4110 if (lookup->IsTransition()) {
4118 EnqueueChangeRecord(object, "add", name, old_value); 4111 EnqueueChangeRecord(object, "add", name, old_value);
4119 } else { 4112 } else {
4120 LookupResult new_lookup(isolate); 4113 LookupResult new_lookup(isolate);
4121 object->LocalLookup(*name, &new_lookup, true); 4114 object->LocalLookup(*name, &new_lookup, true);
4122 if (new_lookup.IsDataProperty()) { 4115 if (new_lookup.IsDataProperty()) {
4123 Handle<Object> new_value = Object::GetProperty(object, name); 4116 Handle<Object> new_value = Object::GetProperty(object, name);
4117 CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
4124 if (!new_value->SameValue(*old_value)) { 4118 if (!new_value->SameValue(*old_value)) {
4125 EnqueueChangeRecord(object, "update", name, old_value); 4119 EnqueueChangeRecord(object, "update", name, old_value);
4126 } 4120 }
4127 } 4121 }
4128 } 4122 }
4129 } 4123 }
4130 4124
4131 return result; 4125 return result;
4132 } 4126 }
4133 4127
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4190 // Neither properties nor transitions found. 4184 // Neither properties nor transitions found.
4191 return AddProperty(object, name, value, attributes, SLOPPY, 4185 return AddProperty(object, name, value, attributes, SLOPPY,
4192 MAY_BE_STORE_FROM_KEYED, extensibility_check, value_type, mode, flag); 4186 MAY_BE_STORE_FROM_KEYED, extensibility_check, value_type, mode, flag);
4193 } 4187 }
4194 4188
4195 Handle<Object> old_value = isolate->factory()->the_hole_value(); 4189 Handle<Object> old_value = isolate->factory()->the_hole_value();
4196 PropertyAttributes old_attributes = ABSENT; 4190 PropertyAttributes old_attributes = ABSENT;
4197 bool is_observed = object->map()->is_observed() && 4191 bool is_observed = object->map()->is_observed() &&
4198 *name != isolate->heap()->hidden_string(); 4192 *name != isolate->heap()->hidden_string();
4199 if (is_observed && lookup.IsProperty()) { 4193 if (is_observed && lookup.IsProperty()) {
4200 if (lookup.IsDataProperty()) old_value = 4194 if (lookup.IsDataProperty()) {
4201 Object::GetProperty(object, name); 4195 old_value = Object::GetProperty(object, name);
4196 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
4197 }
4202 old_attributes = lookup.GetAttributes(); 4198 old_attributes = lookup.GetAttributes();
4203 } 4199 }
4204 4200
4205 // Check of IsReadOnly removed from here in clone. 4201 // Check of IsReadOnly removed from here in clone.
4206 switch (lookup.type()) { 4202 switch (lookup.type()) {
4207 case NORMAL: 4203 case NORMAL:
4208 ReplaceSlowProperty(object, name, value, attributes); 4204 ReplaceSlowProperty(object, name, value, attributes);
4209 break; 4205 break;
4210 case FIELD: 4206 case FIELD:
4211 SetPropertyToFieldWithAttributes(&lookup, name, value, attributes); 4207 SetPropertyToFieldWithAttributes(&lookup, name, value, attributes);
(...skipping 24 matching lines...) Expand all
4236 if (lookup.IsTransition()) { 4232 if (lookup.IsTransition()) {
4237 EnqueueChangeRecord(object, "add", name, old_value); 4233 EnqueueChangeRecord(object, "add", name, old_value);
4238 } else if (old_value->IsTheHole()) { 4234 } else if (old_value->IsTheHole()) {
4239 EnqueueChangeRecord(object, "reconfigure", name, old_value); 4235 EnqueueChangeRecord(object, "reconfigure", name, old_value);
4240 } else { 4236 } else {
4241 LookupResult new_lookup(isolate); 4237 LookupResult new_lookup(isolate);
4242 object->LocalLookup(*name, &new_lookup, true); 4238 object->LocalLookup(*name, &new_lookup, true);
4243 bool value_changed = false; 4239 bool value_changed = false;
4244 if (new_lookup.IsDataProperty()) { 4240 if (new_lookup.IsDataProperty()) {
4245 Handle<Object> new_value = Object::GetProperty(object, name); 4241 Handle<Object> new_value = Object::GetProperty(object, name);
4242 CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
4246 value_changed = !old_value->SameValue(*new_value); 4243 value_changed = !old_value->SameValue(*new_value);
4247 } 4244 }
4248 if (new_lookup.GetAttributes() != old_attributes) { 4245 if (new_lookup.GetAttributes() != old_attributes) {
4249 if (!value_changed) old_value = isolate->factory()->the_hole_value(); 4246 if (!value_changed) old_value = isolate->factory()->the_hole_value();
4250 EnqueueChangeRecord(object, "reconfigure", name, old_value); 4247 EnqueueChangeRecord(object, "reconfigure", name, old_value);
4251 } else if (value_changed) { 4248 } else if (value_changed) {
4252 EnqueueChangeRecord(object, "update", name, old_value); 4249 EnqueueChangeRecord(object, "update", name, old_value);
4253 } 4250 }
4254 } 4251 }
4255 } 4252 }
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
5190 if (proto->IsNull()) return factory->false_value(); 5187 if (proto->IsNull()) return factory->false_value();
5191 ASSERT(proto->IsJSGlobalObject()); 5188 ASSERT(proto->IsJSGlobalObject());
5192 return DeleteElement(Handle<JSObject>::cast(proto), index, mode); 5189 return DeleteElement(Handle<JSObject>::cast(proto), index, mode);
5193 } 5190 }
5194 5191
5195 Handle<Object> old_value; 5192 Handle<Object> old_value;
5196 bool should_enqueue_change_record = false; 5193 bool should_enqueue_change_record = false;
5197 if (object->map()->is_observed()) { 5194 if (object->map()->is_observed()) {
5198 should_enqueue_change_record = HasLocalElement(object, index); 5195 should_enqueue_change_record = HasLocalElement(object, index);
5199 if (should_enqueue_change_record) { 5196 if (should_enqueue_change_record) {
5200 old_value = object->GetLocalElementAccessorPair(index) != NULL 5197 if (object->GetLocalElementAccessorPair(index) != NULL) {
5201 ? Handle<Object>::cast(factory->the_hole_value()) 5198 old_value = Handle<Object>::cast(factory->the_hole_value());
5202 : Object::GetElement(isolate, object, index); 5199 } else {
5200 old_value = Object::GetElement(isolate, object, index);
5201 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
5202 }
5203 } 5203 }
5204 } 5204 }
5205 5205
5206 // Skip interceptor if forcing deletion. 5206 // Skip interceptor if forcing deletion.
5207 Handle<Object> result; 5207 Handle<Object> result;
5208 if (object->HasIndexedInterceptor() && mode != FORCE_DELETION) { 5208 if (object->HasIndexedInterceptor() && mode != FORCE_DELETION) {
5209 result = DeleteElementWithInterceptor(object, index); 5209 result = DeleteElementWithInterceptor(object, index);
5210 } else { 5210 } else {
5211 result = AccessorDelete(object, index, mode); 5211 result = AccessorDelete(object, index, mode);
5212 } 5212 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5262 return Handle<Object>(); 5262 return Handle<Object>();
5263 } 5263 }
5264 return isolate->factory()->false_value(); 5264 return isolate->factory()->false_value();
5265 } 5265 }
5266 5266
5267 Handle<Object> old_value = isolate->factory()->the_hole_value(); 5267 Handle<Object> old_value = isolate->factory()->the_hole_value();
5268 bool is_observed = object->map()->is_observed() && 5268 bool is_observed = object->map()->is_observed() &&
5269 *name != isolate->heap()->hidden_string(); 5269 *name != isolate->heap()->hidden_string();
5270 if (is_observed && lookup.IsDataProperty()) { 5270 if (is_observed && lookup.IsDataProperty()) {
5271 old_value = Object::GetProperty(object, name); 5271 old_value = Object::GetProperty(object, name);
5272 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
5272 } 5273 }
5273 Handle<Object> result; 5274 Handle<Object> result;
5274 5275
5275 // Check for interceptor. 5276 // Check for interceptor.
5276 if (lookup.IsInterceptor()) { 5277 if (lookup.IsInterceptor()) {
5277 // Skip interceptor if forcing a deletion. 5278 // Skip interceptor if forcing a deletion.
5278 if (mode == FORCE_DELETION) { 5279 if (mode == FORCE_DELETION) {
5279 result = DeletePropertyPostInterceptor(object, name, mode); 5280 result = DeletePropertyPostInterceptor(object, name, mode);
5280 } else { 5281 } else {
5281 result = DeletePropertyWithInterceptor(object, name); 5282 result = DeletePropertyWithInterceptor(object, name);
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
6360 6361
6361 Handle<Object> old_value = isolate->factory()->the_hole_value(); 6362 Handle<Object> old_value = isolate->factory()->the_hole_value();
6362 bool is_observed = object->map()->is_observed() && 6363 bool is_observed = object->map()->is_observed() &&
6363 *name != isolate->heap()->hidden_string(); 6364 *name != isolate->heap()->hidden_string();
6364 bool preexists = false; 6365 bool preexists = false;
6365 if (is_observed) { 6366 if (is_observed) {
6366 if (is_element) { 6367 if (is_element) {
6367 preexists = HasLocalElement(object, index); 6368 preexists = HasLocalElement(object, index);
6368 if (preexists && object->GetLocalElementAccessorPair(index) == NULL) { 6369 if (preexists && object->GetLocalElementAccessorPair(index) == NULL) {
6369 old_value = Object::GetElement(isolate, object, index); 6370 old_value = Object::GetElement(isolate, object, index);
6371 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
6370 } 6372 }
6371 } else { 6373 } else {
6372 LookupResult lookup(isolate); 6374 LookupResult lookup(isolate);
6373 object->LocalLookup(*name, &lookup, true); 6375 object->LocalLookup(*name, &lookup, true);
6374 preexists = lookup.IsProperty(); 6376 preexists = lookup.IsProperty();
6375 if (preexists && lookup.IsDataProperty()) { 6377 if (preexists && lookup.IsDataProperty()) {
6376 old_value = Object::GetProperty(object, name); 6378 old_value = Object::GetProperty(object, name);
6379 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
6377 } 6380 }
6378 } 6381 }
6379 } 6382 }
6380 6383
6381 if (is_element) { 6384 if (is_element) {
6382 DefineElementAccessor( 6385 DefineElementAccessor(
6383 object, index, getter, setter, attributes, access_control); 6386 object, index, getter, setter, attributes, access_control);
6384 } else { 6387 } else {
6385 DefinePropertyAccessor( 6388 DefinePropertyAccessor(
6386 object, name, getter, setter, attributes, access_control); 6389 object, name, getter, setter, attributes, access_control);
(...skipping 4967 matching lines...) Expand 10 before | Expand all | Expand 10 after
11354 // no further old values need be collected. 11357 // no further old values need be collected.
11355 static bool GetOldValue(Isolate* isolate, 11358 static bool GetOldValue(Isolate* isolate,
11356 Handle<JSObject> object, 11359 Handle<JSObject> object,
11357 uint32_t index, 11360 uint32_t index,
11358 List<Handle<Object> >* old_values, 11361 List<Handle<Object> >* old_values,
11359 List<uint32_t>* indices) { 11362 List<uint32_t>* indices) {
11360 PropertyAttributes attributes = 11363 PropertyAttributes attributes =
11361 JSReceiver::GetLocalElementAttribute(object, index); 11364 JSReceiver::GetLocalElementAttribute(object, index);
11362 ASSERT(attributes != ABSENT); 11365 ASSERT(attributes != ABSENT);
11363 if (attributes == DONT_DELETE) return false; 11366 if (attributes == DONT_DELETE) return false;
11364 old_values->Add(object->GetLocalElementAccessorPair(index) == NULL 11367 Handle<Object> value;
11365 ? Object::GetElement(isolate, object, index) 11368 if (object->GetLocalElementAccessorPair(index) != NULL) {
11366 : Handle<Object>::cast(isolate->factory()->the_hole_value())); 11369 value = Handle<Object>::cast(isolate->factory()->the_hole_value());
11370 } else {
11371 value = Object::GetElement(isolate, object, index);
11372 CHECK_NOT_EMPTY_HANDLE(isolate, value);
11373 }
11374 old_values->Add(value);
11367 indices->Add(index); 11375 indices->Add(index);
11368 return true; 11376 return true;
11369 } 11377 }
11370 11378
11371 static void EnqueueSpliceRecord(Handle<JSArray> object, 11379 static void EnqueueSpliceRecord(Handle<JSArray> object,
11372 uint32_t index, 11380 uint32_t index,
11373 Handle<JSArray> deleted, 11381 Handle<JSArray> deleted,
11374 uint32_t add_count) { 11382 uint32_t add_count) {
11375 Isolate* isolate = object->GetIsolate(); 11383 Isolate* isolate = object->GetIsolate();
11376 HandleScope scope(isolate); 11384 HandleScope scope(isolate);
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
12561 set_mode); 12569 set_mode);
12562 } 12570 }
12563 12571
12564 PropertyAttributes old_attributes = 12572 PropertyAttributes old_attributes =
12565 JSReceiver::GetLocalElementAttribute(object, index); 12573 JSReceiver::GetLocalElementAttribute(object, index);
12566 Handle<Object> old_value = isolate->factory()->the_hole_value(); 12574 Handle<Object> old_value = isolate->factory()->the_hole_value();
12567 Handle<Object> old_length_handle; 12575 Handle<Object> old_length_handle;
12568 Handle<Object> new_length_handle; 12576 Handle<Object> new_length_handle;
12569 12577
12570 if (old_attributes != ABSENT) { 12578 if (old_attributes != ABSENT) {
12571 if (object->GetLocalElementAccessorPair(index) == NULL) 12579 if (object->GetLocalElementAccessorPair(index) == NULL) {
12572 old_value = Object::GetElement(isolate, object, index); 12580 old_value = Object::GetElement(isolate, object, index);
12581 CHECK_NOT_EMPTY_HANDLE(isolate, old_value);
12582 }
12573 } else if (object->IsJSArray()) { 12583 } else if (object->IsJSArray()) {
12574 // Store old array length in case adding an element grows the array. 12584 // Store old array length in case adding an element grows the array.
12575 old_length_handle = handle(Handle<JSArray>::cast(object)->length(), 12585 old_length_handle = handle(Handle<JSArray>::cast(object)->length(),
12576 isolate); 12586 isolate);
12577 } 12587 }
12578 12588
12579 // Check for lookup interceptor 12589 // Check for lookup interceptor
12580 Handle<Object> result = object->HasIndexedInterceptor() 12590 Handle<Object> result = object->HasIndexedInterceptor()
12581 ? SetElementWithInterceptor(object, index, value, attributes, strict_mode, 12591 ? SetElementWithInterceptor(object, index, value, attributes, strict_mode,
12582 check_prototype, 12592 check_prototype,
(...skipping 25 matching lines...) Expand all
12608 Handle<JSArray> deleted = isolate->factory()->NewJSArray(0); 12618 Handle<JSArray> deleted = isolate->factory()->NewJSArray(0);
12609 EnqueueSpliceRecord(Handle<JSArray>::cast(object), old_length, deleted, 12619 EnqueueSpliceRecord(Handle<JSArray>::cast(object), old_length, deleted,
12610 new_length - old_length); 12620 new_length - old_length);
12611 } else { 12621 } else {
12612 EnqueueChangeRecord(object, "add", name, old_value); 12622 EnqueueChangeRecord(object, "add", name, old_value);
12613 } 12623 }
12614 } else if (old_value->IsTheHole()) { 12624 } else if (old_value->IsTheHole()) {
12615 EnqueueChangeRecord(object, "reconfigure", name, old_value); 12625 EnqueueChangeRecord(object, "reconfigure", name, old_value);
12616 } else { 12626 } else {
12617 Handle<Object> new_value = Object::GetElement(isolate, object, index); 12627 Handle<Object> new_value = Object::GetElement(isolate, object, index);
12628 CHECK_NOT_EMPTY_HANDLE(isolate, new_value);
12618 bool value_changed = !old_value->SameValue(*new_value); 12629 bool value_changed = !old_value->SameValue(*new_value);
12619 if (old_attributes != new_attributes) { 12630 if (old_attributes != new_attributes) {
12620 if (!value_changed) old_value = isolate->factory()->the_hole_value(); 12631 if (!value_changed) old_value = isolate->factory()->the_hole_value();
12621 EnqueueChangeRecord(object, "reconfigure", name, old_value); 12632 EnqueueChangeRecord(object, "reconfigure", name, old_value);
12622 } else if (value_changed) { 12633 } else if (value_changed) {
12623 EnqueueChangeRecord(object, "update", name, old_value); 12634 EnqueueChangeRecord(object, "update", name, old_value);
12624 } 12635 }
12625 } 12636 }
12626 12637
12627 return result; 12638 return result;
(...skipping 3852 matching lines...) Expand 10 before | Expand all | Expand 10 after
16480 #define ERROR_MESSAGES_TEXTS(C, T) T, 16491 #define ERROR_MESSAGES_TEXTS(C, T) T,
16481 static const char* error_messages_[] = { 16492 static const char* error_messages_[] = {
16482 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16493 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16483 }; 16494 };
16484 #undef ERROR_MESSAGES_TEXTS 16495 #undef ERROR_MESSAGES_TEXTS
16485 return error_messages_[reason]; 16496 return error_messages_[reason];
16486 } 16497 }
16487 16498
16488 16499
16489 } } // namespace v8::internal 16500 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698