| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/api.h" | 9 #include "src/api.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 5774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5785 for (int i = 0; i < number_of_own_descriptors; i++) { | 5785 for (int i = 0; i < number_of_own_descriptors; i++) { |
| 5786 if (descs->GetType(i) == FIELD) { | 5786 if (descs->GetType(i) == FIELD) { |
| 5787 int current_index = descs->GetFieldIndex(i); | 5787 int current_index = descs->GetFieldIndex(i); |
| 5788 if (current_index > max_index) max_index = current_index; | 5788 if (current_index > max_index) max_index = current_index; |
| 5789 } | 5789 } |
| 5790 } | 5790 } |
| 5791 return max_index + 1; | 5791 return max_index + 1; |
| 5792 } | 5792 } |
| 5793 | 5793 |
| 5794 | 5794 |
| 5795 void JSReceiver::LookupOwn( | 5795 void JSReceiver::LookupOwn(Handle<Name> name, LookupResult* result) { |
| 5796 Handle<Name> name, LookupResult* result, bool search_hidden_prototypes) { | |
| 5797 DisallowHeapAllocation no_gc; | 5796 DisallowHeapAllocation no_gc; |
| 5798 DCHECK(name->IsName()); | 5797 DCHECK(name->IsName()); |
| 5799 | 5798 |
| 5800 if (IsJSGlobalProxy()) { | 5799 if (IsJSGlobalProxy()) { |
| 5801 PrototypeIterator iter(GetIsolate(), this); | 5800 PrototypeIterator iter(GetIsolate(), this); |
| 5802 if (iter.IsAtEnd()) return result->NotFound(); | 5801 if (iter.IsAtEnd()) return result->NotFound(); |
| 5803 DCHECK(iter.GetCurrent()->IsJSGlobalObject()); | 5802 DCHECK(iter.GetCurrent()->IsJSGlobalObject()); |
| 5804 return JSReceiver::cast(iter.GetCurrent()) | 5803 return JSReceiver::cast(iter.GetCurrent())->LookupOwn(name, result); |
| 5805 ->LookupOwn(name, result, search_hidden_prototypes); | |
| 5806 } | 5804 } |
| 5807 | 5805 |
| 5808 if (IsJSProxy()) { | 5806 if (IsJSProxy()) { |
| 5809 result->HandlerResult(JSProxy::cast(this)); | 5807 result->HandlerResult(JSProxy::cast(this)); |
| 5810 return; | 5808 return; |
| 5811 } | 5809 } |
| 5812 | 5810 |
| 5813 // Do not use inline caching if the object is a non-global object | 5811 // Do not use inline caching if the object is a non-global object |
| 5814 // that requires access checks. | 5812 // that requires access checks. |
| 5815 if (IsAccessCheckNeeded()) { | 5813 if (IsAccessCheckNeeded()) { |
| 5816 result->DisallowCaching(); | 5814 result->DisallowCaching(); |
| 5817 } | 5815 } |
| 5818 | 5816 |
| 5819 JSObject* js_object = JSObject::cast(this); | 5817 JSObject* js_object = JSObject::cast(this); |
| 5820 | 5818 |
| 5821 // Check for lookup interceptor except when bootstrapping. | 5819 // Check for lookup interceptor except when bootstrapping. |
| 5822 if (js_object->HasNamedInterceptor() && | 5820 if (js_object->HasNamedInterceptor() && |
| 5823 !GetIsolate()->bootstrapper()->IsActive()) { | 5821 !GetIsolate()->bootstrapper()->IsActive()) { |
| 5824 result->InterceptorResult(js_object); | 5822 result->InterceptorResult(js_object); |
| 5825 return; | 5823 return; |
| 5826 } | 5824 } |
| 5827 | 5825 |
| 5828 js_object->LookupOwnRealNamedProperty(name, result); | 5826 js_object->LookupOwnRealNamedProperty(name, result); |
| 5829 if (result->IsFound() || name->IsOwn() || !search_hidden_prototypes) return; | |
| 5830 | |
| 5831 PrototypeIterator iter(GetIsolate(), js_object); | |
| 5832 if (!iter.GetCurrent()->IsJSReceiver()) return; | |
| 5833 JSReceiver* receiver = JSReceiver::cast(iter.GetCurrent()); | |
| 5834 if (receiver->map()->is_hidden_prototype()) { | |
| 5835 receiver->LookupOwn(name, result, search_hidden_prototypes); | |
| 5836 } | |
| 5837 } | 5827 } |
| 5838 | 5828 |
| 5839 | 5829 |
| 5840 void JSReceiver::Lookup(Handle<Name> name, LookupResult* result) { | 5830 void JSReceiver::Lookup(Handle<Name> name, LookupResult* result) { |
| 5841 DisallowHeapAllocation no_gc; | 5831 DisallowHeapAllocation no_gc; |
| 5842 // Ecma-262 3rd 8.6.2.4 | 5832 // Ecma-262 3rd 8.6.2.4 |
| 5843 for (PrototypeIterator iter(GetIsolate(), this, | 5833 for (PrototypeIterator iter(GetIsolate(), this, |
| 5844 PrototypeIterator::START_AT_RECEIVER); | 5834 PrototypeIterator::START_AT_RECEIVER); |
| 5845 !iter.IsAtEnd(); iter.Advance()) { | 5835 !iter.IsAtEnd(); iter.Advance()) { |
| 5846 JSReceiver::cast(iter.GetCurrent())->LookupOwn(name, result, false); | 5836 JSReceiver::cast(iter.GetCurrent())->LookupOwn(name, result); |
| 5847 if (result->IsFound()) return; | 5837 if (result->IsFound()) return; |
| 5848 if (name->IsOwn()) { | 5838 if (name->IsOwn()) { |
| 5849 result->NotFound(); | 5839 result->NotFound(); |
| 5850 return; | 5840 return; |
| 5851 } | 5841 } |
| 5852 } | 5842 } |
| 5853 result->NotFound(); | 5843 result->NotFound(); |
| 5854 } | 5844 } |
| 5855 | 5845 |
| 5856 | 5846 |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6362 if (!maybe.has_value) { | 6352 if (!maybe.has_value) { |
| 6363 DCHECK(false); | 6353 DCHECK(false); |
| 6364 return isolate->factory()->undefined_value(); | 6354 return isolate->factory()->undefined_value(); |
| 6365 } | 6355 } |
| 6366 preexists = maybe.value; | 6356 preexists = maybe.value; |
| 6367 if (preexists && GetOwnElementAccessorPair(object, index).is_null()) { | 6357 if (preexists && GetOwnElementAccessorPair(object, index).is_null()) { |
| 6368 old_value = | 6358 old_value = |
| 6369 Object::GetElement(isolate, object, index).ToHandleChecked(); | 6359 Object::GetElement(isolate, object, index).ToHandleChecked(); |
| 6370 } | 6360 } |
| 6371 } else { | 6361 } else { |
| 6372 LookupResult lookup(isolate); | 6362 LookupIterator it(object, name, |
| 6373 object->LookupOwn(name, &lookup, true); | 6363 LookupIterator::CHECK_HIDDEN_SKIP_INTERCEPTOR); |
| 6374 preexists = lookup.IsProperty(); | 6364 CHECK(GetPropertyAttributes(&it).has_value); |
| 6375 if (preexists && lookup.IsDataProperty()) { | 6365 preexists = it.IsFound(); |
| 6376 old_value = | 6366 if (preexists && (it.property_kind() == LookupIterator::DATA || |
| 6377 Object::GetPropertyOrElement(object, name).ToHandleChecked(); | 6367 it.GetAccessors()->IsAccessorInfo())) { |
| 6368 old_value = GetProperty(&it).ToHandleChecked(); |
| 6378 } | 6369 } |
| 6379 } | 6370 } |
| 6380 } | 6371 } |
| 6381 | 6372 |
| 6382 if (is_element) { | 6373 if (is_element) { |
| 6383 DefineElementAccessor(object, index, getter, setter, attributes); | 6374 DefineElementAccessor(object, index, getter, setter, attributes); |
| 6384 } else { | 6375 } else { |
| 6385 DefinePropertyAccessor(object, name, getter, setter, attributes); | 6376 DefinePropertyAccessor(object, name, getter, setter, attributes); |
| 6386 } | 6377 } |
| 6387 | 6378 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6557 case DICTIONARY_ELEMENTS: | 6548 case DICTIONARY_ELEMENTS: |
| 6558 break; | 6549 break; |
| 6559 case SLOPPY_ARGUMENTS_ELEMENTS: | 6550 case SLOPPY_ARGUMENTS_ELEMENTS: |
| 6560 UNIMPLEMENTED(); | 6551 UNIMPLEMENTED(); |
| 6561 break; | 6552 break; |
| 6562 } | 6553 } |
| 6563 | 6554 |
| 6564 SetElementCallback(object, index, info, info->property_attributes()); | 6555 SetElementCallback(object, index, info, info->property_attributes()); |
| 6565 } else { | 6556 } else { |
| 6566 // Lookup the name. | 6557 // Lookup the name. |
| 6567 LookupResult result(isolate); | 6558 LookupIterator it(object, name, |
| 6568 object->LookupOwn(name, &result, true); | 6559 LookupIterator::CHECK_HIDDEN_SKIP_INTERCEPTOR); |
| 6560 CHECK(GetPropertyAttributes(&it).has_value); |
| 6569 // ES5 forbids turning a property into an accessor if it's not | 6561 // ES5 forbids turning a property into an accessor if it's not |
| 6570 // configurable (that is IsDontDelete in ES3 and v8), see 8.6.1 (Table 5). | 6562 // configurable. See 8.6.1 (Table 5). |
| 6571 if (result.IsFound() && (result.IsReadOnly() || result.IsDontDelete())) { | 6563 if (it.IsFound() && (it.IsReadOnly() || !it.IsConfigurable())) { |
| 6572 return factory->undefined_value(); | 6564 return factory->undefined_value(); |
| 6573 } | 6565 } |
| 6574 | 6566 |
| 6575 SetPropertyCallback(object, name, info, info->property_attributes()); | 6567 SetPropertyCallback(object, name, info, info->property_attributes()); |
| 6576 } | 6568 } |
| 6577 | 6569 |
| 6578 return object; | 6570 return object; |
| 6579 } | 6571 } |
| 6580 | 6572 |
| 6581 | 6573 |
| (...skipping 10073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16655 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16647 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16656 static const char* error_messages_[] = { | 16648 static const char* error_messages_[] = { |
| 16657 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16649 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16658 }; | 16650 }; |
| 16659 #undef ERROR_MESSAGES_TEXTS | 16651 #undef ERROR_MESSAGES_TEXTS |
| 16660 return error_messages_[reason]; | 16652 return error_messages_[reason]; |
| 16661 } | 16653 } |
| 16662 | 16654 |
| 16663 | 16655 |
| 16664 } } // namespace v8::internal | 16656 } } // namespace v8::internal |
| OLD | NEW |