Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 | 439 |
| 440 // | 440 // |
| 441 // Accessors::FunctionPrototype | 441 // Accessors::FunctionPrototype |
| 442 // | 442 // |
| 443 | 443 |
| 444 | 444 |
| 445 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { | 445 MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { |
| 446 bool found_it = false; | 446 bool found_it = false; |
| 447 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 447 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
| 448 if (!found_it) return Heap::undefined_value(); | 448 if (!found_it) return Heap::undefined_value(); |
| 449 while (!function->should_have_prototype()) { | |
| 450 found_it = false; | |
| 451 function = FindInPrototypeChain<JSFunction>(object->GetPrototype(), | |
| 452 &found_it); | |
| 453 ASSERT(found_it); // There has to be one because we hit the getter | |
|
Mads Ager (chromium)
2011/02/22 12:24:31
Period at end of comment. Maybe move the comment t
| |
| 454 } | |
| 455 | |
| 449 if (!function->has_prototype()) { | 456 if (!function->has_prototype()) { |
| 450 if (!function->should_have_prototype()) return Heap::undefined_value(); | |
| 451 Object* prototype; | 457 Object* prototype; |
| 452 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function); | 458 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function); |
| 453 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 459 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
| 454 } | 460 } |
| 455 Object* result; | 461 Object* result; |
| 456 { MaybeObject* maybe_result = function->SetPrototype(prototype); | 462 { MaybeObject* maybe_result = function->SetPrototype(prototype); |
| 457 if (!maybe_result->ToObject(&result)) return maybe_result; | 463 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 458 } | 464 } |
| 459 } | 465 } |
| 460 return function->prototype(); | 466 return function->prototype(); |
| 461 } | 467 } |
| 462 | 468 |
| 463 | 469 |
| 464 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, | 470 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
| 465 Object* value, | 471 Object* value, |
| 466 void*) { | 472 void*) { |
| 467 bool found_it = false; | 473 bool found_it = false; |
| 468 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 474 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
| 469 if (!found_it) return Heap::undefined_value(); | 475 if (!found_it) return Heap::undefined_value(); |
| 476 if (!function->should_have_prototype()) { | |
| 477 // Since we hit this accessor, object will have no prototype property. | |
| 478 return object->SetLocalPropertyIgnoreAttributes(Heap::prototype_symbol(), | |
| 479 value, | |
| 480 NONE); | |
| 481 } | |
| 482 | |
| 470 if (function->has_initial_map()) { | 483 if (function->has_initial_map()) { |
| 471 // If the function has allocated the initial map | 484 // If the function has allocated the initial map |
| 472 // replace it with a copy containing the new prototype. | 485 // replace it with a copy containing the new prototype. |
| 473 Object* new_map; | 486 Object* new_map; |
| 474 { MaybeObject* maybe_new_map = | 487 { MaybeObject* maybe_new_map = |
| 475 function->initial_map()->CopyDropTransitions(); | 488 function->initial_map()->CopyDropTransitions(); |
| 476 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; | 489 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; |
| 477 } | 490 } |
| 478 function->set_initial_map(Map::cast(new_map)); | 491 function->set_initial_map(Map::cast(new_map)); |
| 479 } | 492 } |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 } | 897 } |
| 885 | 898 |
| 886 | 899 |
| 887 const AccessorDescriptor Accessors::ObjectPrototype = { | 900 const AccessorDescriptor Accessors::ObjectPrototype = { |
| 888 ObjectGetPrototype, | 901 ObjectGetPrototype, |
| 889 ObjectSetPrototype, | 902 ObjectSetPrototype, |
| 890 0 | 903 0 |
| 891 }; | 904 }; |
| 892 | 905 |
| 893 } } // namespace v8::internal | 906 } } // namespace v8::internal |
| OLD | NEW |