Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 } | 126 } |
| 127 if (heap_object->IsHeapNumber()) { | 127 if (heap_object->IsHeapNumber()) { |
| 128 return HeapNumber::cast(this)->HeapNumberToBoolean(); | 128 return HeapNumber::cast(this)->HeapNumberToBoolean(); |
| 129 } | 129 } |
| 130 return heap_object->GetHeap()->true_value(); | 130 return heap_object->GetHeap()->true_value(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 | 133 |
| 134 void Object::Lookup(String* name, LookupResult* result) { | 134 void Object::Lookup(String* name, LookupResult* result) { |
| 135 Object* holder = NULL; | 135 Object* holder = NULL; |
| 136 if (IsSmi()) { | 136 if (IsSmi()) { |
|
Kevin Millikin (Chromium)
2011/05/13 08:08:30
Not your code, but this looks clumsy. Isn't
Isol
rossberg
2011/05/13 09:21:53
I guess so. I simplified that code.
| |
| 137 Heap* heap = Isolate::Current()->heap(); | 137 Heap* heap = Isolate::Current()->heap(); |
| 138 Context* global_context = heap->isolate()->context()->global_context(); | 138 Context* global_context = heap->isolate()->context()->global_context(); |
| 139 holder = global_context->number_function()->instance_prototype(); | 139 holder = global_context->number_function()->instance_prototype(); |
| 140 } else { | 140 } else { |
| 141 HeapObject* heap_object = HeapObject::cast(this); | 141 HeapObject* heap_object = HeapObject::cast(this); |
| 142 if (heap_object->IsJSObject()) { | 142 if (heap_object->IsJSObject()) { |
| 143 return JSObject::cast(this)->Lookup(name, result); | 143 return JSObject::cast(this)->Lookup(name, result); |
| 144 } | 144 } |
| 145 Heap* heap = heap_object->GetHeap(); | 145 Heap* heap = heap_object->GetHeap(); |
| 146 if (heap_object->IsString()) { | 146 if (heap_object->IsString()) { |
| 147 Context* global_context = heap->isolate()->context()->global_context(); | 147 Context* global_context = heap->isolate()->context()->global_context(); |
| 148 holder = global_context->string_function()->instance_prototype(); | 148 holder = global_context->string_function()->instance_prototype(); |
| 149 } else if (heap_object->IsHeapNumber()) { | 149 } else if (heap_object->IsHeapNumber()) { |
| 150 Context* global_context = heap->isolate()->context()->global_context(); | 150 Context* global_context = heap->isolate()->context()->global_context(); |
| 151 holder = global_context->number_function()->instance_prototype(); | 151 holder = global_context->number_function()->instance_prototype(); |
| 152 } else if (heap_object->IsBoolean()) { | 152 } else if (heap_object->IsBoolean()) { |
| 153 Context* global_context = heap->isolate()->context()->global_context(); | 153 Context* global_context = heap->isolate()->context()->global_context(); |
| 154 holder = global_context->boolean_function()->instance_prototype(); | 154 holder = global_context->boolean_function()->instance_prototype(); |
| 155 } else if (heap_object->IsJSProxy()) { | |
| 156 return result->NotFound(); // For now... | |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 ASSERT(holder != NULL); // Cannot handle null or undefined. | 159 ASSERT(holder != NULL); // Cannot handle null or undefined. |
| 158 JSObject::cast(holder)->Lookup(name, result); | 160 JSObject::cast(holder)->Lookup(name, result); |
| 159 } | 161 } |
| 160 | 162 |
| 161 | 163 |
| 162 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver, | 164 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver, |
| 163 String* name, | 165 String* name, |
| 164 PropertyAttributes* attributes) { | 166 PropertyAttributes* attributes) { |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 MaybeObject* Object::GetProperty(Object* receiver, | 489 MaybeObject* Object::GetProperty(Object* receiver, |
| 488 LookupResult* result, | 490 LookupResult* result, |
| 489 String* name, | 491 String* name, |
| 490 PropertyAttributes* attributes) { | 492 PropertyAttributes* attributes) { |
| 491 // Make sure that the top context does not change when doing | 493 // Make sure that the top context does not change when doing |
| 492 // callbacks or interceptor calls. | 494 // callbacks or interceptor calls. |
| 493 AssertNoContextChange ncc; | 495 AssertNoContextChange ncc; |
| 494 Heap* heap = name->GetHeap(); | 496 Heap* heap = name->GetHeap(); |
| 495 | 497 |
| 496 // Traverse the prototype chain from the current object (this) to | 498 // Traverse the prototype chain from the current object (this) to |
| 497 // the holder and check for access rights. This avoid traversing the | 499 // the holder and check for access rights. This avoids traversing the |
| 498 // objects more than once in case of interceptors, because the | 500 // objects more than once in case of interceptors, because the |
| 499 // holder will always be the interceptor holder and the search may | 501 // holder will always be the interceptor holder and the search may |
| 500 // only continue with a current object just after the interceptor | 502 // only continue with a current object just after the interceptor |
| 501 // holder in the prototype chain. | 503 // holder in the prototype chain. |
| 502 Object* last = result->IsProperty() ? result->holder() : heap->null_value(); | 504 Object* last = result->IsProperty() ? result->holder() : heap->null_value(); |
| 505 ASSERT(this != this->GetPrototype()); | |
| 503 for (Object* current = this; true; current = current->GetPrototype()) { | 506 for (Object* current = this; true; current = current->GetPrototype()) { |
| 504 if (current->IsAccessCheckNeeded()) { | 507 if (current->IsAccessCheckNeeded()) { |
| 505 // Check if we're allowed to read from the current object. Note | 508 // Check if we're allowed to read from the current object. Note |
| 506 // that even though we may not actually end up loading the named | 509 // that even though we may not actually end up loading the named |
| 507 // property from the current object, we still check that we have | 510 // property from the current object, we still check that we have |
| 508 // access to it. | 511 // access to it. |
| 509 JSObject* checked = JSObject::cast(current); | 512 JSObject* checked = JSObject::cast(current); |
| 510 if (!heap->isolate()->MayNamedAccess(checked, name, v8::ACCESS_GET)) { | 513 if (!heap->isolate()->MayNamedAccess(checked, name, v8::ACCESS_GET)) { |
| 511 return checked->GetPropertyWithFailedAccessCheck(receiver, | 514 return checked->GetPropertyWithFailedAccessCheck(receiver, |
| 512 result, | 515 result, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 Heap* heap = heap_object->GetHeap(); | 571 Heap* heap = heap_object->GetHeap(); |
| 569 Isolate* isolate = heap->isolate(); | 572 Isolate* isolate = heap->isolate(); |
| 570 | 573 |
| 571 Context* global_context = isolate->context()->global_context(); | 574 Context* global_context = isolate->context()->global_context(); |
| 572 if (heap_object->IsString()) { | 575 if (heap_object->IsString()) { |
| 573 holder = global_context->string_function()->instance_prototype(); | 576 holder = global_context->string_function()->instance_prototype(); |
| 574 } else if (heap_object->IsHeapNumber()) { | 577 } else if (heap_object->IsHeapNumber()) { |
| 575 holder = global_context->number_function()->instance_prototype(); | 578 holder = global_context->number_function()->instance_prototype(); |
| 576 } else if (heap_object->IsBoolean()) { | 579 } else if (heap_object->IsBoolean()) { |
| 577 holder = global_context->boolean_function()->instance_prototype(); | 580 holder = global_context->boolean_function()->instance_prototype(); |
| 581 } else if (heap_object->IsJSProxy()) { | |
| 582 return heap->undefined_value(); // For now... | |
| 578 } else { | 583 } else { |
| 579 // Undefined and null have no indexed properties. | 584 // Undefined and null have no indexed properties. |
| 580 ASSERT(heap_object->IsUndefined() || heap_object->IsNull()); | 585 ASSERT(heap_object->IsUndefined() || heap_object->IsNull()); |
| 581 return heap->undefined_value(); | 586 return heap->undefined_value(); |
| 582 } | 587 } |
| 583 } | 588 } |
| 584 | 589 |
| 585 return JSObject::cast(holder)->GetElementWithReceiver(receiver, index); | 590 return JSObject::cast(holder)->GetElementWithReceiver(receiver, index); |
| 586 } | 591 } |
| 587 | 592 |
| 588 | 593 |
| 589 Object* Object::GetPrototype() { | 594 Object* Object::GetPrototype() { |
| 590 if (IsSmi()) { | 595 if (IsSmi()) { |
| 591 Heap* heap = Isolate::Current()->heap(); | 596 Heap* heap = Isolate::Current()->heap(); |
| 592 Context* context = heap->isolate()->context()->global_context(); | 597 Context* context = heap->isolate()->context()->global_context(); |
| 593 return context->number_function()->instance_prototype(); | 598 return context->number_function()->instance_prototype(); |
| 594 } | 599 } |
| 595 | 600 |
| 596 HeapObject* heap_object = HeapObject::cast(this); | 601 HeapObject* heap_object = HeapObject::cast(this); |
| 597 | 602 |
| 598 // The object is either a number, a string, a boolean, or a real JS object. | 603 // The object is either a number, a string, a boolean, |
| 599 if (heap_object->IsJSObject()) { | 604 // a real JS object, or a Harmony proxy. |
| 600 return JSObject::cast(this)->map()->prototype(); | 605 if (heap_object->IsJSObject() || heap_object->IsJSProxy()) { |
| 606 return heap_object->map()->prototype(); | |
| 601 } | 607 } |
| 602 Heap* heap = heap_object->GetHeap(); | 608 Heap* heap = heap_object->GetHeap(); |
| 603 Context* context = heap->isolate()->context()->global_context(); | 609 Context* context = heap->isolate()->context()->global_context(); |
| 604 | 610 |
| 605 if (heap_object->IsHeapNumber()) { | 611 if (heap_object->IsHeapNumber()) { |
| 606 return context->number_function()->instance_prototype(); | 612 return context->number_function()->instance_prototype(); |
| 607 } | 613 } |
| 608 if (heap_object->IsString()) { | 614 if (heap_object->IsString()) { |
| 609 return context->string_function()->instance_prototype(); | 615 return context->string_function()->instance_prototype(); |
| 610 } | 616 } |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 case JS_MESSAGE_OBJECT_TYPE: | 1153 case JS_MESSAGE_OBJECT_TYPE: |
| 1148 JSObject::BodyDescriptor::IterateBody(this, object_size, v); | 1154 JSObject::BodyDescriptor::IterateBody(this, object_size, v); |
| 1149 break; | 1155 break; |
| 1150 case JS_FUNCTION_TYPE: | 1156 case JS_FUNCTION_TYPE: |
| 1151 reinterpret_cast<JSFunction*>(this) | 1157 reinterpret_cast<JSFunction*>(this) |
| 1152 ->JSFunctionIterateBody(object_size, v); | 1158 ->JSFunctionIterateBody(object_size, v); |
| 1153 break; | 1159 break; |
| 1154 case ODDBALL_TYPE: | 1160 case ODDBALL_TYPE: |
| 1155 Oddball::BodyDescriptor::IterateBody(this, v); | 1161 Oddball::BodyDescriptor::IterateBody(this, v); |
| 1156 break; | 1162 break; |
| 1163 case JS_PROXY_TYPE: | |
| 1164 JSProxy::BodyDescriptor::IterateBody(this, v); | |
| 1165 break; | |
| 1157 case PROXY_TYPE: | 1166 case PROXY_TYPE: |
| 1158 reinterpret_cast<Proxy*>(this)->ProxyIterateBody(v); | 1167 reinterpret_cast<Proxy*>(this)->ProxyIterateBody(v); |
| 1159 break; | 1168 break; |
| 1160 case MAP_TYPE: | 1169 case MAP_TYPE: |
| 1161 Map::BodyDescriptor::IterateBody(this, v); | 1170 Map::BodyDescriptor::IterateBody(this, v); |
| 1162 break; | 1171 break; |
| 1163 case CODE_TYPE: | 1172 case CODE_TYPE: |
| 1164 reinterpret_cast<Code*>(this)->CodeIterateBody(v); | 1173 reinterpret_cast<Code*>(this)->CodeIterateBody(v); |
| 1165 break; | 1174 break; |
| 1166 case JS_GLOBAL_PROPERTY_CELL_TYPE: | 1175 case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| (...skipping 9254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10421 if (break_point_objects()->IsUndefined()) return 0; | 10430 if (break_point_objects()->IsUndefined()) return 0; |
| 10422 // Single beak point. | 10431 // Single beak point. |
| 10423 if (!break_point_objects()->IsFixedArray()) return 1; | 10432 if (!break_point_objects()->IsFixedArray()) return 1; |
| 10424 // Multiple break points. | 10433 // Multiple break points. |
| 10425 return FixedArray::cast(break_point_objects())->length(); | 10434 return FixedArray::cast(break_point_objects())->length(); |
| 10426 } | 10435 } |
| 10427 #endif | 10436 #endif |
| 10428 | 10437 |
| 10429 | 10438 |
| 10430 } } // namespace v8::internal | 10439 } } // namespace v8::internal |
| OLD | NEW |