| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return it->GetDataValue(); | 133 return it->GetDataValue(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 break; | 136 break; |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 return it->factory()->undefined_value(); | 139 return it->factory()->undefined_value(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 Handle<Object> JSObject::GetDataProperty(Handle<JSObject> object, |
| 144 Handle<Name> key) { |
| 145 LookupIterator it(object, key, LookupIterator::CHECK_DERIVED_PROPERTY); |
| 146 for (; it.IsFound(); it.Next()) { |
| 147 switch (it.state()) { |
| 148 case LookupIterator::NOT_FOUND: |
| 149 case LookupIterator::ACCESS_CHECK: |
| 150 case LookupIterator::INTERCEPTOR: |
| 151 UNREACHABLE(); |
| 152 case LookupIterator::JSPROXY: |
| 153 return it.isolate()->factory()->undefined_value(); |
| 154 case LookupIterator::PROPERTY: |
| 155 if (!it.HasProperty()) continue; |
| 156 switch (it.property_kind()) { |
| 157 case LookupIterator::DATA: |
| 158 return it.GetDataValue(); |
| 159 case LookupIterator::ACCESSOR: |
| 160 // TODO(verwaest): For now this doesn't call into |
| 161 // ExecutableAccessorInfo, since clients don't need it. Update once |
| 162 // relevant. |
| 163 return it.isolate()->factory()->undefined_value(); |
| 164 } |
| 165 } |
| 166 } |
| 167 return it.isolate()->factory()->undefined_value(); |
| 168 } |
| 169 |
| 170 |
| 143 bool Object::ToInt32(int32_t* value) { | 171 bool Object::ToInt32(int32_t* value) { |
| 144 if (IsSmi()) { | 172 if (IsSmi()) { |
| 145 *value = Smi::cast(this)->value(); | 173 *value = Smi::cast(this)->value(); |
| 146 return true; | 174 return true; |
| 147 } | 175 } |
| 148 if (IsHeapNumber()) { | 176 if (IsHeapNumber()) { |
| 149 double num = HeapNumber::cast(this)->value(); | 177 double num = HeapNumber::cast(this)->value(); |
| 150 if (FastI2D(FastD2I(num)) == num) { | 178 if (FastI2D(FastD2I(num)) == num) { |
| 151 *value = FastD2I(num); | 179 *value = FastD2I(num); |
| 152 return true; | 180 return true; |
| (...skipping 3258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3411 value = PropertyCell::cast(value)->value(); | 3439 value = PropertyCell::cast(value)->value(); |
| 3412 } | 3440 } |
| 3413 result->DictionaryResult(this, entry); | 3441 result->DictionaryResult(this, entry); |
| 3414 return; | 3442 return; |
| 3415 } | 3443 } |
| 3416 | 3444 |
| 3417 result->NotFound(); | 3445 result->NotFound(); |
| 3418 } | 3446 } |
| 3419 | 3447 |
| 3420 | 3448 |
| 3421 void JSObject::LookupRealNamedProperty(Handle<Name> name, | |
| 3422 LookupResult* result) { | |
| 3423 DisallowHeapAllocation no_gc; | |
| 3424 LookupOwnRealNamedProperty(name, result); | |
| 3425 if (result->IsFound()) return; | |
| 3426 | |
| 3427 LookupRealNamedPropertyInPrototypes(name, result); | |
| 3428 } | |
| 3429 | |
| 3430 | |
| 3431 void JSObject::LookupRealNamedPropertyInPrototypes(Handle<Name> name, | |
| 3432 LookupResult* result) { | |
| 3433 if (name->IsOwn()) { | |
| 3434 result->NotFound(); | |
| 3435 return; | |
| 3436 } | |
| 3437 | |
| 3438 DisallowHeapAllocation no_gc; | |
| 3439 Isolate* isolate = GetIsolate(); | |
| 3440 for (PrototypeIterator iter(isolate, this); !iter.IsAtEnd(); iter.Advance()) { | |
| 3441 if (iter.GetCurrent()->IsJSProxy()) { | |
| 3442 return result->HandlerResult(JSProxy::cast(iter.GetCurrent())); | |
| 3443 } | |
| 3444 JSObject::cast(iter.GetCurrent())->LookupOwnRealNamedProperty(name, result); | |
| 3445 DCHECK(!(result->IsFound() && result->type() == INTERCEPTOR)); | |
| 3446 if (result->IsFound()) return; | |
| 3447 } | |
| 3448 result->NotFound(); | |
| 3449 } | |
| 3450 | |
| 3451 | |
| 3452 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy, | 3449 Maybe<bool> JSProxy::HasPropertyWithHandler(Handle<JSProxy> proxy, |
| 3453 Handle<Name> name) { | 3450 Handle<Name> name) { |
| 3454 Isolate* isolate = proxy->GetIsolate(); | 3451 Isolate* isolate = proxy->GetIsolate(); |
| 3455 | 3452 |
| 3456 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 3453 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
| 3457 if (name->IsSymbol()) return maybe(false); | 3454 if (name->IsSymbol()) return maybe(false); |
| 3458 | 3455 |
| 3459 Handle<Object> args[] = { name }; | 3456 Handle<Object> args[] = { name }; |
| 3460 Handle<Object> result; | 3457 Handle<Object> result; |
| 3461 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | 3458 ASSIGN_RETURN_ON_EXCEPTION_VALUE( |
| (...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5657 AllocationSiteUsageContext* site_context, | 5654 AllocationSiteUsageContext* site_context, |
| 5658 DeepCopyHints hints) { | 5655 DeepCopyHints hints) { |
| 5659 JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, true, hints); | 5656 JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, true, hints); |
| 5660 MaybeHandle<JSObject> copy = v.StructureWalk(object); | 5657 MaybeHandle<JSObject> copy = v.StructureWalk(object); |
| 5661 Handle<JSObject> for_assert; | 5658 Handle<JSObject> for_assert; |
| 5662 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); | 5659 DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object)); |
| 5663 return copy; | 5660 return copy; |
| 5664 } | 5661 } |
| 5665 | 5662 |
| 5666 | 5663 |
| 5667 Handle<Object> JSObject::GetDataProperty(Handle<JSObject> object, | |
| 5668 Handle<Name> key) { | |
| 5669 Isolate* isolate = object->GetIsolate(); | |
| 5670 LookupResult lookup(isolate); | |
| 5671 { | |
| 5672 DisallowHeapAllocation no_allocation; | |
| 5673 object->LookupRealNamedProperty(key, &lookup); | |
| 5674 } | |
| 5675 Handle<Object> result = isolate->factory()->undefined_value(); | |
| 5676 if (lookup.IsFound() && !lookup.IsTransition()) { | |
| 5677 switch (lookup.type()) { | |
| 5678 case NORMAL: | |
| 5679 result = GetNormalizedProperty( | |
| 5680 Handle<JSObject>(lookup.holder(), isolate), &lookup); | |
| 5681 break; | |
| 5682 case FIELD: | |
| 5683 result = FastPropertyAt(Handle<JSObject>(lookup.holder(), isolate), | |
| 5684 lookup.representation(), | |
| 5685 lookup.GetFieldIndex()); | |
| 5686 break; | |
| 5687 case CONSTANT: | |
| 5688 result = Handle<Object>(lookup.GetConstant(), isolate); | |
| 5689 break; | |
| 5690 case CALLBACKS: | |
| 5691 case HANDLER: | |
| 5692 case INTERCEPTOR: | |
| 5693 break; | |
| 5694 case NONEXISTENT: | |
| 5695 UNREACHABLE(); | |
| 5696 } | |
| 5697 } | |
| 5698 return result; | |
| 5699 } | |
| 5700 | |
| 5701 | |
| 5702 // Tests for the fast common case for property enumeration: | 5664 // Tests for the fast common case for property enumeration: |
| 5703 // - This object and all prototypes has an enum cache (which means that | 5665 // - This object and all prototypes has an enum cache (which means that |
| 5704 // it is no proxy, has no interceptors and needs no access checks). | 5666 // it is no proxy, has no interceptors and needs no access checks). |
| 5705 // - This object has no elements. | 5667 // - This object has no elements. |
| 5706 // - No prototype has enumerable properties/elements. | 5668 // - No prototype has enumerable properties/elements. |
| 5707 bool JSReceiver::IsSimpleEnum() { | 5669 bool JSReceiver::IsSimpleEnum() { |
| 5708 for (PrototypeIterator iter(GetIsolate(), this, | 5670 for (PrototypeIterator iter(GetIsolate(), this, |
| 5709 PrototypeIterator::START_AT_RECEIVER); | 5671 PrototypeIterator::START_AT_RECEIVER); |
| 5710 !iter.IsAtEnd(); iter.Advance()) { | 5672 !iter.IsAtEnd(); iter.Advance()) { |
| 5711 if (!iter.GetCurrent()->IsJSObject()) return false; | 5673 if (!iter.GetCurrent()->IsJSObject()) return false; |
| (...skipping 10932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16644 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16606 #define ERROR_MESSAGES_TEXTS(C, T) T, |
| 16645 static const char* error_messages_[] = { | 16607 static const char* error_messages_[] = { |
| 16646 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16608 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
| 16647 }; | 16609 }; |
| 16648 #undef ERROR_MESSAGES_TEXTS | 16610 #undef ERROR_MESSAGES_TEXTS |
| 16649 return error_messages_[reason]; | 16611 return error_messages_[reason]; |
| 16650 } | 16612 } |
| 16651 | 16613 |
| 16652 | 16614 |
| 16653 } } // namespace v8::internal | 16615 } } // namespace v8::internal |
| OLD | NEW |