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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 | 776 |
777 | 777 |
778 const AccessorDescriptor Accessors::FunctionCaller = { | 778 const AccessorDescriptor Accessors::FunctionCaller = { |
779 FunctionGetCaller, | 779 FunctionGetCaller, |
780 ReadOnlySetAccessor, | 780 ReadOnlySetAccessor, |
781 0 | 781 0 |
782 }; | 782 }; |
783 | 783 |
784 | 784 |
785 // | 785 // |
786 // Accessors::ObjectPrototype | |
787 // | |
788 | |
789 | |
790 static inline Object* GetPrototypeSkipHiddenPrototypes(Isolate* isolate, | |
791 Object* receiver) { | |
792 Object* current = receiver->GetPrototype(isolate); | |
793 while (current->IsJSObject() && | |
794 JSObject::cast(current)->map()->is_hidden_prototype()) { | |
795 current = current->GetPrototype(isolate); | |
796 } | |
797 return current; | |
798 } | |
799 | |
800 | |
801 MaybeObject* Accessors::ObjectGetPrototype(Object* receiver, void*) { | |
802 return GetPrototypeSkipHiddenPrototypes(Isolate::Current(), receiver); | |
803 } | |
804 | |
805 | |
806 MaybeObject* Accessors::ObjectSetPrototype(JSObject* receiver_raw, | |
807 Object* value_raw, | |
808 void*) { | |
809 const bool kSkipHiddenPrototypes = true; | |
810 // To be consistent with other Set functions, return the value. | |
811 if (!(FLAG_harmony_observation && receiver_raw->map()->is_observed())) | |
812 return receiver_raw->SetPrototype(value_raw, kSkipHiddenPrototypes); | |
813 | |
814 Isolate* isolate = receiver_raw->GetIsolate(); | |
815 HandleScope scope(isolate); | |
816 Handle<JSObject> receiver(receiver_raw); | |
817 Handle<Object> value(value_raw, isolate); | |
818 Handle<Object> old_value(GetPrototypeSkipHiddenPrototypes(isolate, *receiver), | |
819 isolate); | |
820 | |
821 MaybeObject* result = receiver->SetPrototype(*value, kSkipHiddenPrototypes); | |
822 Handle<Object> hresult; | |
823 if (!result->ToHandle(&hresult, isolate)) return result; | |
824 | |
825 Handle<Object> new_value(GetPrototypeSkipHiddenPrototypes(isolate, *receiver), | |
826 isolate); | |
827 if (!new_value->SameValue(*old_value)) { | |
828 JSObject::EnqueueChangeRecord(receiver, "prototype", | |
829 isolate->factory()->proto_string(), | |
830 old_value); | |
831 } | |
832 return *hresult; | |
833 } | |
834 | |
835 | |
836 const AccessorDescriptor Accessors::ObjectPrototype = { | |
837 ObjectGetPrototype, | |
838 ObjectSetPrototype, | |
839 0 | |
840 }; | |
841 | |
842 | |
843 // | |
844 // Accessors::MakeModuleExport | 786 // Accessors::MakeModuleExport |
845 // | 787 // |
846 | 788 |
847 static v8::Handle<v8::Value> ModuleGetExport( | 789 static v8::Handle<v8::Value> ModuleGetExport( |
848 v8::Local<v8::String> property, | 790 v8::Local<v8::String> property, |
849 const v8::AccessorInfo& info) { | 791 const v8::AccessorInfo& info) { |
850 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | 792 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
851 Context* context = Context::cast(instance->context()); | 793 Context* context = Context::cast(instance->context()); |
852 ASSERT(context->IsModuleContext()); | 794 ASSERT(context->IsModuleContext()); |
853 int slot = info.Data()->Int32Value(); | 795 int slot = info.Data()->Int32Value(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 info->set_data(Smi::FromInt(index)); | 840 info->set_data(Smi::FromInt(index)); |
899 Handle<Object> getter = v8::FromCData(&ModuleGetExport); | 841 Handle<Object> getter = v8::FromCData(&ModuleGetExport); |
900 Handle<Object> setter = v8::FromCData(&ModuleSetExport); | 842 Handle<Object> setter = v8::FromCData(&ModuleSetExport); |
901 info->set_getter(*getter); | 843 info->set_getter(*getter); |
902 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 844 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
903 return info; | 845 return info; |
904 } | 846 } |
905 | 847 |
906 | 848 |
907 } } // namespace v8::internal | 849 } } // namespace v8::internal |
OLD | NEW |