Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2957 | 2957 |
| 2958 MaybeHandle<Object> JSObject::SetElementWithCallbackSetterInPrototypes( | 2958 MaybeHandle<Object> JSObject::SetElementWithCallbackSetterInPrototypes( |
| 2959 Handle<JSObject> object, | 2959 Handle<JSObject> object, |
| 2960 uint32_t index, | 2960 uint32_t index, |
| 2961 Handle<Object> value, | 2961 Handle<Object> value, |
| 2962 bool* found, | 2962 bool* found, |
| 2963 StrictMode strict_mode) { | 2963 StrictMode strict_mode) { |
| 2964 Isolate *isolate = object->GetIsolate(); | 2964 Isolate *isolate = object->GetIsolate(); |
| 2965 for (Handle<Object> proto = handle(object->GetPrototype(), isolate); | 2965 for (Handle<Object> proto = handle(object->GetPrototype(), isolate); |
| 2966 !proto->IsNull(); | 2966 !proto->IsNull(); |
| 2967 proto = handle(proto->GetPrototype(isolate), isolate)) { | 2967 proto = Object::GetPrototype(isolate, proto)) { |
| 2968 if (proto->IsJSProxy()) { | 2968 if (proto->IsJSProxy()) { |
| 2969 return JSProxy::SetPropertyViaPrototypesWithHandler( | 2969 return JSProxy::SetPropertyViaPrototypesWithHandler( |
| 2970 Handle<JSProxy>::cast(proto), | 2970 Handle<JSProxy>::cast(proto), |
| 2971 object, | 2971 object, |
| 2972 isolate->factory()->Uint32ToString(index), // name | 2972 isolate->factory()->Uint32ToString(index), // name |
| 2973 value, | 2973 value, |
| 2974 NONE, | 2974 NONE, |
| 2975 strict_mode, | 2975 strict_mode, |
| 2976 found); | 2976 found); |
| 2977 } | 2977 } |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3426 LocalLookupRealNamedProperty(name, result); | 3426 LocalLookupRealNamedProperty(name, result); |
| 3427 if (result->IsFound()) return; | 3427 if (result->IsFound()) return; |
| 3428 | 3428 |
| 3429 LookupRealNamedPropertyInPrototypes(name, result); | 3429 LookupRealNamedPropertyInPrototypes(name, result); |
| 3430 } | 3430 } |
| 3431 | 3431 |
| 3432 | 3432 |
| 3433 void JSObject::LookupRealNamedPropertyInPrototypes(Name* name, | 3433 void JSObject::LookupRealNamedPropertyInPrototypes(Name* name, |
| 3434 LookupResult* result) { | 3434 LookupResult* result) { |
| 3435 Isolate* isolate = GetIsolate(); | 3435 Isolate* isolate = GetIsolate(); |
| 3436 Heap* heap = isolate->heap(); | 3436 DisallowHeapAllocation no_alloc; |
| 3437 for (Object* pt = GetPrototype(); | 3437 for (Handle<Object> pt = handle(GetPrototype(), isolate); |
|
Yang
2014/04/15 13:10:48
No need to handlify. Especially since none of the
| |
| 3438 pt != heap->null_value(); | 3438 !pt->IsNull(); |
| 3439 pt = pt->GetPrototype(isolate)) { | 3439 pt = Object::GetPrototype(isolate, pt)) { |
| 3440 if (pt->IsJSProxy()) { | 3440 if (pt->IsJSProxy()) { |
| 3441 return result->HandlerResult(JSProxy::cast(pt)); | 3441 return result->HandlerResult(JSProxy::cast(*pt)); |
| 3442 } | 3442 } |
| 3443 JSObject::cast(pt)->LocalLookupRealNamedProperty(name, result); | 3443 JSObject::cast(*pt)->LocalLookupRealNamedProperty(name, result); |
| 3444 ASSERT(!(result->IsFound() && result->type() == INTERCEPTOR)); | 3444 ASSERT(!(result->IsFound() && result->type() == INTERCEPTOR)); |
| 3445 if (result->IsFound()) return; | 3445 if (result->IsFound()) return; |
| 3446 } | 3446 } |
| 3447 result->NotFound(); | 3447 result->NotFound(); |
| 3448 } | 3448 } |
| 3449 | 3449 |
| 3450 | 3450 |
| 3451 // We only need to deal with CALLBACKS and INTERCEPTORS | 3451 // We only need to deal with CALLBACKS and INTERCEPTORS |
| 3452 MaybeHandle<Object> JSObject::SetPropertyWithFailedAccessCheck( | 3452 MaybeHandle<Object> JSObject::SetPropertyWithFailedAccessCheck( |
| 3453 Handle<JSObject> object, | 3453 Handle<JSObject> object, |
| (...skipping 2967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6421 } | 6421 } |
| 6422 if (callback_obj->IsAccessorPair()) { | 6422 if (callback_obj->IsAccessorPair()) { |
| 6423 return !AccessorPair::cast(callback_obj)->prohibits_overwriting(); | 6423 return !AccessorPair::cast(callback_obj)->prohibits_overwriting(); |
| 6424 } | 6424 } |
| 6425 } | 6425 } |
| 6426 return true; | 6426 return true; |
| 6427 } | 6427 } |
| 6428 | 6428 |
| 6429 | 6429 |
| 6430 bool Map::DictionaryElementsInPrototypeChainOnly() { | 6430 bool Map::DictionaryElementsInPrototypeChainOnly() { |
| 6431 Heap* heap = GetHeap(); | 6431 Isolate* isolate = GetIsolate(); |
| 6432 HandleScope scope(isolate); | |
| 6433 DisallowHeapAllocation no_alloc; | |
|
Yang
2014/04/15 13:10:48
No need to handlify.
| |
| 6432 | 6434 |
| 6433 if (IsDictionaryElementsKind(elements_kind())) { | 6435 if (IsDictionaryElementsKind(elements_kind())) { |
| 6434 return false; | 6436 return false; |
| 6435 } | 6437 } |
| 6436 | 6438 |
| 6437 for (Object* prototype = this->prototype(); | 6439 for (Handle<Object> prototype(this->prototype(), isolate); |
| 6438 prototype != heap->null_value(); | 6440 !prototype->IsNull(); |
| 6439 prototype = prototype->GetPrototype(GetIsolate())) { | 6441 prototype = Object::GetPrototype(isolate, prototype)) { |
| 6440 if (prototype->IsJSProxy()) { | 6442 if (prototype->IsJSProxy()) { |
| 6441 // Be conservative, don't walk into proxies. | 6443 // Be conservative, don't walk into proxies. |
| 6442 return true; | 6444 return true; |
| 6443 } | 6445 } |
| 6444 | 6446 |
| 6445 if (IsDictionaryElementsKind( | 6447 if (IsDictionaryElementsKind( |
| 6446 JSObject::cast(prototype)->map()->elements_kind())) { | 6448 JSObject::cast(*prototype)->map()->elements_kind())) { |
| 6447 return true; | 6449 return true; |
| 6448 } | 6450 } |
| 6449 } | 6451 } |
| 6450 | 6452 |
| 6451 return false; | 6453 return false; |
| 6452 } | 6454 } |
| 6453 | 6455 |
| 6454 | 6456 |
| 6455 void JSObject::SetElementCallback(Handle<JSObject> object, | 6457 void JSObject::SetElementCallback(Handle<JSObject> object, |
| 6456 uint32_t index, | 6458 uint32_t index, |
| (...skipping 5527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11984 Handle<Object> error = isolate->factory()->NewTypeError( | 11986 Handle<Object> error = isolate->factory()->NewTypeError( |
| 11985 "non_extensible_proto", HandleVector(args, ARRAY_SIZE(args))); | 11987 "non_extensible_proto", HandleVector(args, ARRAY_SIZE(args))); |
| 11986 isolate->Throw(*error); | 11988 isolate->Throw(*error); |
| 11987 return Handle<Object>(); | 11989 return Handle<Object>(); |
| 11988 } | 11990 } |
| 11989 | 11991 |
| 11990 // Before we can set the prototype we need to be sure | 11992 // Before we can set the prototype we need to be sure |
| 11991 // prototype cycles are prevented. | 11993 // prototype cycles are prevented. |
| 11992 // It is sufficient to validate that the receiver is not in the new prototype | 11994 // It is sufficient to validate that the receiver is not in the new prototype |
| 11993 // chain. | 11995 // chain. |
| 11994 for (Object* pt = *value; | 11996 for (Handle<Object> pt = value; |
| 11995 pt != heap->null_value(); | 11997 !pt->IsNull(); |
| 11996 pt = pt->GetPrototype(isolate)) { | 11998 pt = Object::GetPrototype(isolate, pt)) { |
| 11997 if (JSReceiver::cast(pt) == *object) { | 11999 if (JSReceiver::cast(*pt) == *object) { |
|
Yang
2014/04/15 13:10:48
you could use
if (pt.is_identical_to(object)) { ..
| |
| 11998 // Cycle detected. | 12000 // Cycle detected. |
| 11999 Handle<Object> error = isolate->factory()->NewError( | 12001 Handle<Object> error = isolate->factory()->NewError( |
| 12000 "cyclic_proto", HandleVector<Object>(NULL, 0)); | 12002 "cyclic_proto", HandleVector<Object>(NULL, 0)); |
| 12001 isolate->Throw(*error); | 12003 isolate->Throw(*error); |
| 12002 return Handle<Object>(); | 12004 return Handle<Object>(); |
| 12003 } | 12005 } |
| 12004 } | 12006 } |
| 12005 | 12007 |
| 12006 bool dictionary_elements_in_chain = | 12008 bool dictionary_elements_in_chain = |
| 12007 object->map()->DictionaryElementsInPrototypeChainOnly(); | 12009 object->map()->DictionaryElementsInPrototypeChainOnly(); |
| 12008 Handle<JSObject> real_receiver = object; | 12010 Handle<JSObject> real_receiver = object; |
| 12009 | 12011 |
| 12010 if (skip_hidden_prototypes) { | 12012 if (skip_hidden_prototypes) { |
| 12011 // Find the first object in the chain whose prototype object is not | 12013 // Find the first object in the chain whose prototype object is not |
| 12012 // hidden and set the new prototype on that object. | 12014 // hidden and set the new prototype on that object. |
| 12013 Object* current_proto = real_receiver->GetPrototype(); | 12015 Handle<Object> current_proto(real_receiver->GetPrototype(), isolate); |
| 12014 while (current_proto->IsJSObject() && | 12016 while (current_proto->IsJSObject() && |
| 12015 JSObject::cast(current_proto)->map()->is_hidden_prototype()) { | 12017 JSObject::cast(*current_proto)->map()->is_hidden_prototype()) { |
| 12016 real_receiver = handle(JSObject::cast(current_proto), isolate); | 12018 real_receiver = handle(JSObject::cast(*current_proto)); |
| 12017 current_proto = current_proto->GetPrototype(isolate); | 12019 current_proto = Object::GetPrototype(isolate, current_proto); |
| 12018 } | 12020 } |
| 12019 } | 12021 } |
| 12020 | 12022 |
| 12021 // Set the new prototype of the object. | 12023 // Set the new prototype of the object. |
| 12022 Handle<Map> map(real_receiver->map()); | 12024 Handle<Map> map(real_receiver->map()); |
| 12023 | 12025 |
| 12024 // Nothing to do if prototype is already set. | 12026 // Nothing to do if prototype is already set. |
| 12025 if (map->prototype() == *value) return value; | 12027 if (map->prototype() == *value) return value; |
| 12026 | 12028 |
| 12027 if (value->IsJSObject()) { | 12029 if (value->IsJSObject()) { |
| (...skipping 4577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16605 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16607 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16606 static const char* error_messages_[] = { | 16608 static const char* error_messages_[] = { |
| 16607 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16609 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16608 }; | 16610 }; |
| 16609 #undef ERROR_MESSAGES_TEXTS | 16611 #undef ERROR_MESSAGES_TEXTS |
| 16610 return error_messages_[reason]; | 16612 return error_messages_[reason]; |
| 16611 } | 16613 } |
| 16612 | 16614 |
| 16613 | 16615 |
| 16614 } } // namespace v8::internal | 16616 } } // namespace v8::internal |
| OLD | NEW |