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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 if (!function->has_prototype()) { | 449 if (!function->has_prototype()) { |
450 if (!function->should_have_prototype()) return Heap::undefined_value(); | 450 if (!function->should_have_prototype()) { |
Mads Ager (chromium)
2011/02/22 10:17:07
Can we simplify this? How about moving this before
Rico
2011/02/22 12:22:44
Done.
| |
451 // Check if there is a 'prototype' property. | |
452 LookupResult result; | |
453 Handle<String> proto_name = | |
Mads Ager (chromium)
2011/02/22 10:17:07
This code does not use handles. You can use Heap::
Rico
2011/02/22 12:22:44
Done.
| |
454 Factory::NewStringFromAscii(CStrVector("prototype")); | |
455 function->Lookup(*proto_name, &result); | |
456 | |
457 if (result.IsProperty()) { | |
458 if (result.holder()->IsJSFunction()) { | |
459 JSFunction* jsfunction = JSFunction::cast(result.holder()); | |
460 if (jsfunction->has_prototype()) return jsfunction->prototype(); | |
461 } | |
462 } | |
463 // There was no prototype in the prototype chain, return undefined. | |
464 return Heap::undefined_value(); | |
465 } | |
451 Object* prototype; | 466 Object* prototype; |
452 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function); | 467 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function); |
453 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 468 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
454 } | 469 } |
455 Object* result; | 470 Object* result; |
456 { MaybeObject* maybe_result = function->SetPrototype(prototype); | 471 { MaybeObject* maybe_result = function->SetPrototype(prototype); |
457 if (!maybe_result->ToObject(&result)) return maybe_result; | 472 if (!maybe_result->ToObject(&result)) return maybe_result; |
458 } | 473 } |
459 } | 474 } |
460 return function->prototype(); | 475 return function->prototype(); |
461 } | 476 } |
462 | 477 |
463 | 478 |
464 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, | 479 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
465 Object* value, | 480 Object* value, |
466 void*) { | 481 void*) { |
467 bool found_it = false; | 482 bool found_it = false; |
468 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); | 483 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
469 if (!found_it) return Heap::undefined_value(); | 484 if (!found_it) return Heap::undefined_value(); |
485 if (!function->should_have_prototype()) { | |
486 return object->SetLocalPropertyIgnoreAttributes( | |
Mads Ager (chromium)
2011/02/22 10:17:07
Please add a comment stating that object does not
Rico
2011/02/22 12:22:44
Done.
| |
487 *Factory::NewStringFromAscii(CStrVector("prototype")), | |
Mads Ager (chromium)
2011/02/22 10:17:07
Heap::prototype_symbol()
Rico
2011/02/22 12:22:44
Done.
| |
488 value, | |
489 NONE); | |
490 } | |
491 | |
470 if (function->has_initial_map()) { | 492 if (function->has_initial_map()) { |
471 // If the function has allocated the initial map | 493 // If the function has allocated the initial map |
472 // replace it with a copy containing the new prototype. | 494 // replace it with a copy containing the new prototype. |
473 Object* new_map; | 495 Object* new_map; |
474 { MaybeObject* maybe_new_map = | 496 { MaybeObject* maybe_new_map = |
475 function->initial_map()->CopyDropTransitions(); | 497 function->initial_map()->CopyDropTransitions(); |
476 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; | 498 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; |
477 } | 499 } |
478 function->set_initial_map(Map::cast(new_map)); | 500 function->set_initial_map(Map::cast(new_map)); |
479 } | 501 } |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 } | 906 } |
885 | 907 |
886 | 908 |
887 const AccessorDescriptor Accessors::ObjectPrototype = { | 909 const AccessorDescriptor Accessors::ObjectPrototype = { |
888 ObjectGetPrototype, | 910 ObjectGetPrototype, |
889 ObjectSetPrototype, | 911 ObjectSetPrototype, |
890 0 | 912 0 |
891 }; | 913 }; |
892 | 914 |
893 } } // namespace v8::internal | 915 } } // namespace v8::internal |
OLD | NEW |