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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 return receiver->SetPrototype(value, skip_hidden_prototypes); | 795 return receiver->SetPrototype(value, skip_hidden_prototypes); |
796 } | 796 } |
797 | 797 |
798 | 798 |
799 const AccessorDescriptor Accessors::ObjectPrototype = { | 799 const AccessorDescriptor Accessors::ObjectPrototype = { |
800 ObjectGetPrototype, | 800 ObjectGetPrototype, |
801 ObjectSetPrototype, | 801 ObjectSetPrototype, |
802 0 | 802 0 |
803 }; | 803 }; |
804 | 804 |
805 | |
806 // | |
807 // Accessors::MakeModuleExport | |
808 // | |
809 | |
810 static v8::Handle<v8::Value> ModuleGetExport( | |
811 v8::Local<v8::String> property, | |
812 const v8::AccessorInfo& info) { | |
813 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | |
814 Context* context = Context::cast(instance->context()); | |
815 ASSERT(context->IsModuleContext()); | |
816 int slot = info.Data()->Int32Value(); | |
817 Object* value = context->get(slot); | |
818 if (value->IsTheHole()) { | |
819 Handle<String> name = v8::Utils::OpenHandle(*property); | |
820 Isolate* isolate = instance->GetIsolate(); | |
821 isolate->ScheduleThrow( | |
822 *isolate->factory()->NewReferenceError("not_defined", | |
823 HandleVector(&name, 1))); | |
824 return v8::Handle<v8::Value>(); | |
825 } | |
826 return v8::Utils::ToLocal(Handle<Object>(value)); | |
827 } | |
828 | |
829 | |
830 static void ModuleSetExport( | |
831 v8::Local<v8::String> property, | |
832 v8::Local<v8::Value> value, | |
833 const v8::AccessorInfo& info) { | |
834 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | |
835 Context* context = Context::cast(instance->context()); | |
836 ASSERT(context->IsModuleContext()); | |
837 int slot = info.Data()->Int32Value(); | |
838 Object* old_value = context->get(slot); | |
839 if (old_value->IsTheHole()) { | |
840 Handle<String> name = v8::Utils::OpenHandle(*property); | |
841 Isolate* isolate = instance->GetIsolate(); | |
842 isolate->ScheduleThrow( | |
843 *isolate->factory()->NewReferenceError("not_defined", | |
844 HandleVector(&name, 1))); | |
845 return; | |
846 } | |
847 context->set(slot, *v8::Utils::OpenHandle(*value)); | |
848 } | |
849 | |
850 | |
851 Handle<AccessorInfo> Accessors::MakeModuleExport( | |
852 Handle<String> name, | |
853 int index, | |
854 PropertyAttributes attributes) { | |
855 Factory* factory = Isolate::Current()->factory(); | |
Michael Starzinger
2012/07/06 10:53:22
Use name->GetIsolate() instead.
rossberg
2012/07/06 15:39:28
Done.
| |
856 Handle<AccessorInfo> info = factory->NewAccessorInfo(); | |
857 info->set_property_attributes(attributes); | |
858 info->set_all_can_read(true); | |
859 info->set_all_can_write(true); | |
860 info->set_name(*name); | |
861 info->set_data(Smi::FromInt(index)); | |
862 v8::AccessorGetter getter = &ModuleGetExport; | |
863 v8::AccessorSetter setter = &ModuleSetExport; | |
864 info->set_getter(*v8::FromCData(getter)); | |
865 if (!(attributes & ReadOnly)) info->set_setter(*v8::FromCData(setter)); | |
866 return info; | |
867 } | |
868 | |
869 | |
805 } } // namespace v8::internal | 870 } } // namespace v8::internal |
OLD | NEW |