OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 Object* result; | 458 Object* result; |
459 { MaybeObject* maybe_result = function->SetPrototype(prototype); | 459 { MaybeObject* maybe_result = function->SetPrototype(prototype); |
460 if (!maybe_result->ToObject(&result)) return maybe_result; | 460 if (!maybe_result->ToObject(&result)) return maybe_result; |
461 } | 461 } |
462 } | 462 } |
463 return function->prototype(); | 463 return function->prototype(); |
464 } | 464 } |
465 | 465 |
466 | 466 |
467 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, | 467 MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
468 Object* value, | 468 Object* value_raw, |
469 void*) { | 469 void*) { |
470 Heap* heap = object->GetHeap(); | 470 Isolate* isolate = object->GetIsolate(); |
471 JSFunction* function = FindInstanceOf<JSFunction>(object); | 471 Heap* heap = isolate->heap(); |
472 if (function == NULL) return heap->undefined_value(); | 472 JSFunction* function_raw = FindInstanceOf<JSFunction>(object); |
473 if (!function->should_have_prototype()) { | 473 if (function_raw == NULL) return heap->undefined_value(); |
| 474 if (!function_raw->should_have_prototype()) { |
474 // Since we hit this accessor, object will have no prototype property. | 475 // Since we hit this accessor, object will have no prototype property. |
475 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(), | 476 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(), |
476 value, | 477 value_raw, |
477 NONE); | 478 NONE); |
478 } | 479 } |
479 | 480 |
480 Object* prototype; | 481 HandleScope scope(isolate); |
481 { MaybeObject* maybe_prototype = function->SetPrototype(value); | 482 Handle<JSFunction> function(function_raw, isolate); |
482 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; | 483 Handle<Object> value(value_raw, isolate); |
| 484 |
| 485 Handle<Object> old_value; |
| 486 bool is_observed = |
| 487 FLAG_harmony_observation && |
| 488 *function == object && |
| 489 function->map()->is_observed(); |
| 490 if (is_observed) { |
| 491 if (function->has_prototype()) |
| 492 old_value = handle(function->prototype(), isolate); |
| 493 else |
| 494 old_value = isolate->factory()->NewFunctionPrototype(function); |
483 } | 495 } |
484 ASSERT(function->prototype() == value); | 496 |
485 return function; | 497 Handle<Object> result; |
| 498 MaybeObject* maybe_result = function->SetPrototype(*value); |
| 499 if (!maybe_result->ToHandle(&result, isolate)) return maybe_result; |
| 500 ASSERT(function->prototype() == *value); |
| 501 |
| 502 if (is_observed && !old_value->SameValue(*value)) { |
| 503 JSObject::EnqueueChangeRecord( |
| 504 function, "updated", isolate->factory()->prototype_symbol(), old_value); |
| 505 } |
| 506 |
| 507 return *function; |
486 } | 508 } |
487 | 509 |
488 | 510 |
489 const AccessorDescriptor Accessors::FunctionPrototype = { | 511 const AccessorDescriptor Accessors::FunctionPrototype = { |
490 FunctionGetPrototype, | 512 FunctionGetPrototype, |
491 FunctionSetPrototype, | 513 FunctionSetPrototype, |
492 0 | 514 0 |
493 }; | 515 }; |
494 | 516 |
495 | 517 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 info->set_data(Smi::FromInt(index)); | 888 info->set_data(Smi::FromInt(index)); |
867 Handle<Object> getter = v8::FromCData(&ModuleGetExport); | 889 Handle<Object> getter = v8::FromCData(&ModuleGetExport); |
868 Handle<Object> setter = v8::FromCData(&ModuleSetExport); | 890 Handle<Object> setter = v8::FromCData(&ModuleSetExport); |
869 info->set_getter(*getter); | 891 info->set_getter(*getter); |
870 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 892 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
871 return info; | 893 return info; |
872 } | 894 } |
873 | 895 |
874 | 896 |
875 } } // namespace v8::internal | 897 } } // namespace v8::internal |
OLD | NEW |