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

Side by Side Diff: src/objects.cc

Issue 6932068: A first skeleton for introducing Harmony proxies (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Addressed Kevin's comments. Created 9 years, 7 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
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()) {
137 Heap* heap = Isolate::Current()->heap(); 137 Context* global_context = Isolate::Current()->context()->global_context();
138 Context* global_context = heap->isolate()->context()->global_context();
139 holder = global_context->number_function()->instance_prototype(); 138 holder = global_context->number_function()->instance_prototype();
140 } else { 139 } else {
141 HeapObject* heap_object = HeapObject::cast(this); 140 HeapObject* heap_object = HeapObject::cast(this);
142 if (heap_object->IsJSObject()) { 141 if (heap_object->IsJSObject()) {
143 return JSObject::cast(this)->Lookup(name, result); 142 return JSObject::cast(this)->Lookup(name, result);
144 } 143 }
145 Heap* heap = heap_object->GetHeap(); 144 Context* global_context = Isolate::Current()->context()->global_context();
146 if (heap_object->IsString()) { 145 if (heap_object->IsString()) {
147 Context* global_context = heap->isolate()->context()->global_context();
148 holder = global_context->string_function()->instance_prototype(); 146 holder = global_context->string_function()->instance_prototype();
149 } else if (heap_object->IsHeapNumber()) { 147 } else if (heap_object->IsHeapNumber()) {
150 Context* global_context = heap->isolate()->context()->global_context();
151 holder = global_context->number_function()->instance_prototype(); 148 holder = global_context->number_function()->instance_prototype();
152 } else if (heap_object->IsBoolean()) { 149 } else if (heap_object->IsBoolean()) {
153 Context* global_context = heap->isolate()->context()->global_context();
154 holder = global_context->boolean_function()->instance_prototype(); 150 holder = global_context->boolean_function()->instance_prototype();
151 } else if (heap_object->IsJSProxy()) {
152 return result->NotFound(); // For now...
155 } 153 }
156 } 154 }
157 ASSERT(holder != NULL); // Cannot handle null or undefined. 155 ASSERT(holder != NULL); // Cannot handle null or undefined.
158 JSObject::cast(holder)->Lookup(name, result); 156 JSObject::cast(holder)->Lookup(name, result);
159 } 157 }
160 158
161 159
162 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver, 160 MaybeObject* Object::GetPropertyWithReceiver(Object* receiver,
163 String* name, 161 String* name,
164 PropertyAttributes* attributes) { 162 PropertyAttributes* attributes) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 MaybeObject* Object::GetProperty(Object* receiver, 485 MaybeObject* Object::GetProperty(Object* receiver,
488 LookupResult* result, 486 LookupResult* result,
489 String* name, 487 String* name,
490 PropertyAttributes* attributes) { 488 PropertyAttributes* attributes) {
491 // Make sure that the top context does not change when doing 489 // Make sure that the top context does not change when doing
492 // callbacks or interceptor calls. 490 // callbacks or interceptor calls.
493 AssertNoContextChange ncc; 491 AssertNoContextChange ncc;
494 Heap* heap = name->GetHeap(); 492 Heap* heap = name->GetHeap();
495 493
496 // Traverse the prototype chain from the current object (this) to 494 // Traverse the prototype chain from the current object (this) to
497 // the holder and check for access rights. This avoid traversing the 495 // the holder and check for access rights. This avoids traversing the
498 // objects more than once in case of interceptors, because the 496 // objects more than once in case of interceptors, because the
499 // holder will always be the interceptor holder and the search may 497 // holder will always be the interceptor holder and the search may
500 // only continue with a current object just after the interceptor 498 // only continue with a current object just after the interceptor
501 // holder in the prototype chain. 499 // holder in the prototype chain.
502 Object* last = result->IsProperty() ? result->holder() : heap->null_value(); 500 Object* last = result->IsProperty() ? result->holder() : heap->null_value();
501 ASSERT(this != this->GetPrototype());
503 for (Object* current = this; true; current = current->GetPrototype()) { 502 for (Object* current = this; true; current = current->GetPrototype()) {
504 if (current->IsAccessCheckNeeded()) { 503 if (current->IsAccessCheckNeeded()) {
505 // Check if we're allowed to read from the current object. Note 504 // 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 505 // that even though we may not actually end up loading the named
507 // property from the current object, we still check that we have 506 // property from the current object, we still check that we have
508 // access to it. 507 // access to it.
509 JSObject* checked = JSObject::cast(current); 508 JSObject* checked = JSObject::cast(current);
510 if (!heap->isolate()->MayNamedAccess(checked, name, v8::ACCESS_GET)) { 509 if (!heap->isolate()->MayNamedAccess(checked, name, v8::ACCESS_GET)) {
511 return checked->GetPropertyWithFailedAccessCheck(receiver, 510 return checked->GetPropertyWithFailedAccessCheck(receiver,
512 result, 511 result,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 Heap* heap = heap_object->GetHeap(); 567 Heap* heap = heap_object->GetHeap();
569 Isolate* isolate = heap->isolate(); 568 Isolate* isolate = heap->isolate();
570 569
571 Context* global_context = isolate->context()->global_context(); 570 Context* global_context = isolate->context()->global_context();
572 if (heap_object->IsString()) { 571 if (heap_object->IsString()) {
573 holder = global_context->string_function()->instance_prototype(); 572 holder = global_context->string_function()->instance_prototype();
574 } else if (heap_object->IsHeapNumber()) { 573 } else if (heap_object->IsHeapNumber()) {
575 holder = global_context->number_function()->instance_prototype(); 574 holder = global_context->number_function()->instance_prototype();
576 } else if (heap_object->IsBoolean()) { 575 } else if (heap_object->IsBoolean()) {
577 holder = global_context->boolean_function()->instance_prototype(); 576 holder = global_context->boolean_function()->instance_prototype();
577 } else if (heap_object->IsJSProxy()) {
578 return heap->undefined_value(); // For now...
578 } else { 579 } else {
579 // Undefined and null have no indexed properties. 580 // Undefined and null have no indexed properties.
580 ASSERT(heap_object->IsUndefined() || heap_object->IsNull()); 581 ASSERT(heap_object->IsUndefined() || heap_object->IsNull());
581 return heap->undefined_value(); 582 return heap->undefined_value();
582 } 583 }
583 } 584 }
584 585
585 return JSObject::cast(holder)->GetElementWithReceiver(receiver, index); 586 return JSObject::cast(holder)->GetElementWithReceiver(receiver, index);
586 } 587 }
587 588
588 589
589 Object* Object::GetPrototype() { 590 Object* Object::GetPrototype() {
590 if (IsSmi()) { 591 if (IsSmi()) {
591 Heap* heap = Isolate::Current()->heap(); 592 Heap* heap = Isolate::Current()->heap();
592 Context* context = heap->isolate()->context()->global_context(); 593 Context* context = heap->isolate()->context()->global_context();
593 return context->number_function()->instance_prototype(); 594 return context->number_function()->instance_prototype();
594 } 595 }
595 596
596 HeapObject* heap_object = HeapObject::cast(this); 597 HeapObject* heap_object = HeapObject::cast(this);
597 598
598 // The object is either a number, a string, a boolean, or a real JS object. 599 // The object is either a number, a string, a boolean,
599 if (heap_object->IsJSObject()) { 600 // a real JS object, or a Harmony proxy.
600 return JSObject::cast(this)->map()->prototype(); 601 if (heap_object->IsJSObject() || heap_object->IsJSProxy()) {
602 return heap_object->map()->prototype();
601 } 603 }
602 Heap* heap = heap_object->GetHeap(); 604 Heap* heap = heap_object->GetHeap();
603 Context* context = heap->isolate()->context()->global_context(); 605 Context* context = heap->isolate()->context()->global_context();
604 606
605 if (heap_object->IsHeapNumber()) { 607 if (heap_object->IsHeapNumber()) {
606 return context->number_function()->instance_prototype(); 608 return context->number_function()->instance_prototype();
607 } 609 }
608 if (heap_object->IsString()) { 610 if (heap_object->IsString()) {
609 return context->string_function()->instance_prototype(); 611 return context->string_function()->instance_prototype();
610 } 612 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 case JS_MESSAGE_OBJECT_TYPE: 1149 case JS_MESSAGE_OBJECT_TYPE:
1148 JSObject::BodyDescriptor::IterateBody(this, object_size, v); 1150 JSObject::BodyDescriptor::IterateBody(this, object_size, v);
1149 break; 1151 break;
1150 case JS_FUNCTION_TYPE: 1152 case JS_FUNCTION_TYPE:
1151 reinterpret_cast<JSFunction*>(this) 1153 reinterpret_cast<JSFunction*>(this)
1152 ->JSFunctionIterateBody(object_size, v); 1154 ->JSFunctionIterateBody(object_size, v);
1153 break; 1155 break;
1154 case ODDBALL_TYPE: 1156 case ODDBALL_TYPE:
1155 Oddball::BodyDescriptor::IterateBody(this, v); 1157 Oddball::BodyDescriptor::IterateBody(this, v);
1156 break; 1158 break;
1159 case JS_PROXY_TYPE:
1160 JSProxy::BodyDescriptor::IterateBody(this, v);
1161 break;
1157 case PROXY_TYPE: 1162 case PROXY_TYPE:
1158 reinterpret_cast<Proxy*>(this)->ProxyIterateBody(v); 1163 reinterpret_cast<Proxy*>(this)->ProxyIterateBody(v);
1159 break; 1164 break;
1160 case MAP_TYPE: 1165 case MAP_TYPE:
1161 Map::BodyDescriptor::IterateBody(this, v); 1166 Map::BodyDescriptor::IterateBody(this, v);
1162 break; 1167 break;
1163 case CODE_TYPE: 1168 case CODE_TYPE:
1164 reinterpret_cast<Code*>(this)->CodeIterateBody(v); 1169 reinterpret_cast<Code*>(this)->CodeIterateBody(v);
1165 break; 1170 break;
1166 case JS_GLOBAL_PROPERTY_CELL_TYPE: 1171 case JS_GLOBAL_PROPERTY_CELL_TYPE:
(...skipping 9255 matching lines...) Expand 10 before | Expand all | Expand 10 after
10422 if (break_point_objects()->IsUndefined()) return 0; 10427 if (break_point_objects()->IsUndefined()) return 0;
10423 // Single beak point. 10428 // Single beak point.
10424 if (!break_point_objects()->IsFixedArray()) return 1; 10429 if (!break_point_objects()->IsFixedArray()) return 1;
10425 // Multiple break points. 10430 // Multiple break points.
10426 return FixedArray::cast(break_point_objects())->length(); 10431 return FixedArray::cast(break_point_objects())->length();
10427 } 10432 }
10428 #endif 10433 #endif
10429 10434
10430 10435
10431 } } // namespace v8::internal 10436 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698