OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 } | 847 } |
848 | 848 |
849 | 849 |
850 Local<AccessorSignature> AccessorSignature::New( | 850 Local<AccessorSignature> AccessorSignature::New( |
851 Isolate* isolate, | 851 Isolate* isolate, |
852 Handle<FunctionTemplate> receiver) { | 852 Handle<FunctionTemplate> receiver) { |
853 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 853 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
854 } | 854 } |
855 | 855 |
856 | 856 |
857 template<typename Operation> | |
858 static Local<Operation> NewDescriptor( | |
859 Isolate* isolate, | |
860 const i::DeclaredAccessorDescriptorData& data, | |
861 Data* previous_descriptor) { | |
862 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
863 i::Handle<i::DeclaredAccessorDescriptor> previous = | |
864 i::Handle<i::DeclaredAccessorDescriptor>(); | |
865 if (previous_descriptor != NULL) { | |
866 previous = Utils::OpenHandle( | |
867 static_cast<DeclaredAccessorDescriptor*>(previous_descriptor)); | |
868 } | |
869 i::Handle<i::DeclaredAccessorDescriptor> descriptor = | |
870 i::DeclaredAccessorDescriptor::Create(internal_isolate, data, previous); | |
871 return Utils::Convert<i::DeclaredAccessorDescriptor, Operation>(descriptor); | |
872 } | |
873 | |
874 | |
875 Local<RawOperationDescriptor> | |
876 ObjectOperationDescriptor::NewInternalFieldDereference( | |
877 Isolate* isolate, | |
878 int internal_field) { | |
879 i::DeclaredAccessorDescriptorData data; | |
880 data.type = i::kDescriptorObjectDereference; | |
881 data.object_dereference_descriptor.internal_field = internal_field; | |
882 return NewDescriptor<RawOperationDescriptor>(isolate, data, NULL); | |
883 } | |
884 | |
885 | |
886 Local<RawOperationDescriptor> RawOperationDescriptor::NewRawShift( | |
887 Isolate* isolate, | |
888 int16_t byte_offset) { | |
889 i::DeclaredAccessorDescriptorData data; | |
890 data.type = i::kDescriptorPointerShift; | |
891 data.pointer_shift_descriptor.byte_offset = byte_offset; | |
892 return NewDescriptor<RawOperationDescriptor>(isolate, data, this); | |
893 } | |
894 | |
895 | |
896 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewHandleDereference( | |
897 Isolate* isolate) { | |
898 i::DeclaredAccessorDescriptorData data; | |
899 data.type = i::kDescriptorReturnObject; | |
900 return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); | |
901 } | |
902 | |
903 | |
904 Local<RawOperationDescriptor> RawOperationDescriptor::NewRawDereference( | |
905 Isolate* isolate) { | |
906 i::DeclaredAccessorDescriptorData data; | |
907 data.type = i::kDescriptorPointerDereference; | |
908 return NewDescriptor<RawOperationDescriptor>(isolate, data, this); | |
909 } | |
910 | |
911 | |
912 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPointerCompare( | |
913 Isolate* isolate, | |
914 void* compare_value) { | |
915 i::DeclaredAccessorDescriptorData data; | |
916 data.type = i::kDescriptorPointerCompare; | |
917 data.pointer_compare_descriptor.compare_value = compare_value; | |
918 return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); | |
919 } | |
920 | |
921 | |
922 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewPrimitiveValue( | |
923 Isolate* isolate, | |
924 DeclaredAccessorDescriptorDataType data_type, | |
925 uint8_t bool_offset) { | |
926 i::DeclaredAccessorDescriptorData data; | |
927 data.type = i::kDescriptorPrimitiveValue; | |
928 data.primitive_value_descriptor.data_type = data_type; | |
929 data.primitive_value_descriptor.bool_offset = bool_offset; | |
930 return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, this); | |
931 } | |
932 | |
933 | |
934 template<typename T> | |
935 static Local<DeclaredAccessorDescriptor> NewBitmaskCompare( | |
936 Isolate* isolate, | |
937 T bitmask, | |
938 T compare_value, | |
939 RawOperationDescriptor* operation) { | |
940 i::DeclaredAccessorDescriptorData data; | |
941 data.type = i::kDescriptorBitmaskCompare; | |
942 data.bitmask_compare_descriptor.bitmask = bitmask; | |
943 data.bitmask_compare_descriptor.compare_value = compare_value; | |
944 data.bitmask_compare_descriptor.size = sizeof(T); | |
945 return NewDescriptor<DeclaredAccessorDescriptor>(isolate, data, operation); | |
946 } | |
947 | |
948 | |
949 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare8( | |
950 Isolate* isolate, | |
951 uint8_t bitmask, | |
952 uint8_t compare_value) { | |
953 return NewBitmaskCompare(isolate, bitmask, compare_value, this); | |
954 } | |
955 | |
956 | |
957 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare16( | |
958 Isolate* isolate, | |
959 uint16_t bitmask, | |
960 uint16_t compare_value) { | |
961 return NewBitmaskCompare(isolate, bitmask, compare_value, this); | |
962 } | |
963 | |
964 | |
965 Local<DeclaredAccessorDescriptor> RawOperationDescriptor::NewBitmaskCompare32( | |
966 Isolate* isolate, | |
967 uint32_t bitmask, | |
968 uint32_t compare_value) { | |
969 return NewBitmaskCompare(isolate, bitmask, compare_value, this); | |
970 } | |
971 | |
972 | |
973 Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { | 857 Local<TypeSwitch> TypeSwitch::New(Handle<FunctionTemplate> type) { |
974 Handle<FunctionTemplate> types[1] = { type }; | 858 Handle<FunctionTemplate> types[1] = { type }; |
975 return TypeSwitch::New(1, types); | 859 return TypeSwitch::New(1, types); |
976 } | 860 } |
977 | 861 |
978 | 862 |
979 Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { | 863 Local<TypeSwitch> TypeSwitch::New(int argc, Handle<FunctionTemplate> types[]) { |
980 i::Isolate* isolate = i::Isolate::Current(); | 864 i::Isolate* isolate = i::Isolate::Current(); |
981 LOG_API(isolate, "TypeSwitch::New"); | 865 LOG_API(isolate, "TypeSwitch::New"); |
982 ENTER_V8(isolate); | 866 ENTER_V8(isolate); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 SET_FIELD_WRAPPED(obj, set_getter, getter); | 945 SET_FIELD_WRAPPED(obj, set_getter, getter); |
1062 SET_FIELD_WRAPPED(obj, set_setter, setter); | 946 SET_FIELD_WRAPPED(obj, set_setter, setter); |
1063 if (data.IsEmpty()) { | 947 if (data.IsEmpty()) { |
1064 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 948 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1065 } | 949 } |
1066 obj->set_data(*Utils::OpenHandle(*data)); | 950 obj->set_data(*Utils::OpenHandle(*data)); |
1067 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); | 951 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); |
1068 } | 952 } |
1069 | 953 |
1070 | 954 |
1071 static i::Handle<i::AccessorInfo> MakeAccessorInfo( | |
1072 v8::Handle<Name> name, | |
1073 v8::Handle<v8::DeclaredAccessorDescriptor> descriptor, | |
1074 void* setter_ignored, | |
1075 void* data_ignored, | |
1076 v8::AccessControl settings, | |
1077 v8::PropertyAttribute attributes, | |
1078 v8::Handle<AccessorSignature> signature) { | |
1079 i::Isolate* isolate = Utils::OpenHandle(*name)->GetIsolate(); | |
1080 if (descriptor.IsEmpty()) return i::Handle<i::DeclaredAccessorInfo>(); | |
1081 i::Handle<i::DeclaredAccessorInfo> obj = | |
1082 isolate->factory()->NewDeclaredAccessorInfo(); | |
1083 obj->set_descriptor(*Utils::OpenHandle(*descriptor)); | |
1084 return SetAccessorInfoProperties(obj, name, settings, attributes, signature); | |
1085 } | |
1086 | |
1087 | |
1088 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { | 955 Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { |
1089 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true); | 956 i::Handle<i::FunctionTemplateInfo> handle = Utils::OpenHandle(this, true); |
1090 if (!Utils::ApiCheck(!handle.is_null(), | 957 if (!Utils::ApiCheck(!handle.is_null(), |
1091 "v8::FunctionTemplate::InstanceTemplate()", | 958 "v8::FunctionTemplate::InstanceTemplate()", |
1092 "Reading from empty handle")) { | 959 "Reading from empty handle")) { |
1093 return Local<ObjectTemplate>(); | 960 return Local<ObjectTemplate>(); |
1094 } | 961 } |
1095 i::Isolate* isolate = handle->GetIsolate(); | 962 i::Isolate* isolate = handle->GetIsolate(); |
1096 ENTER_V8(isolate); | 963 ENTER_V8(isolate); |
1097 if (handle->instance_template()->IsUndefined()) { | 964 if (handle->instance_template()->IsUndefined()) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 i::HandleScope scope(isolate); | 1104 i::HandleScope scope(isolate); |
1238 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( | 1105 i::Handle<i::AccessorInfo> obj = MakeAccessorInfo( |
1239 name, getter, setter, data, settings, attribute, signature); | 1106 name, getter, setter, data, settings, attribute, signature); |
1240 if (obj.is_null()) return false; | 1107 if (obj.is_null()) return false; |
1241 i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj); | 1108 i::Handle<i::TemplateInfo> info = GetTemplateInfo(isolate, template_obj); |
1242 AddPropertyToTemplate(info, obj); | 1109 AddPropertyToTemplate(info, obj); |
1243 return true; | 1110 return true; |
1244 } | 1111 } |
1245 | 1112 |
1246 | 1113 |
1247 bool Template::SetDeclaredAccessor( | |
1248 Local<Name> name, | |
1249 Local<DeclaredAccessorDescriptor> descriptor, | |
1250 PropertyAttribute attribute, | |
1251 Local<AccessorSignature> signature, | |
1252 AccessControl settings) { | |
1253 void* null = NULL; | |
1254 return TemplateSetAccessor( | |
1255 this, name, descriptor, null, null, settings, attribute, signature); | |
1256 } | |
1257 | |
1258 | |
1259 void Template::SetNativeDataProperty(v8::Local<String> name, | 1114 void Template::SetNativeDataProperty(v8::Local<String> name, |
1260 AccessorGetterCallback getter, | 1115 AccessorGetterCallback getter, |
1261 AccessorSetterCallback setter, | 1116 AccessorSetterCallback setter, |
1262 v8::Handle<Value> data, | 1117 v8::Handle<Value> data, |
1263 PropertyAttribute attribute, | 1118 PropertyAttribute attribute, |
1264 v8::Local<AccessorSignature> signature, | 1119 v8::Local<AccessorSignature> signature, |
1265 AccessControl settings) { | 1120 AccessControl settings) { |
1266 TemplateSetAccessor( | 1121 TemplateSetAccessor( |
1267 this, name, getter, setter, data, settings, attribute, signature); | 1122 this, name, getter, setter, data, settings, attribute, signature); |
1268 } | 1123 } |
(...skipping 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3623 AccessorNameGetterCallback getter, | 3478 AccessorNameGetterCallback getter, |
3624 AccessorNameSetterCallback setter, | 3479 AccessorNameSetterCallback setter, |
3625 v8::Handle<Value> data, | 3480 v8::Handle<Value> data, |
3626 AccessControl settings, | 3481 AccessControl settings, |
3627 PropertyAttribute attributes) { | 3482 PropertyAttribute attributes) { |
3628 return ObjectSetAccessor( | 3483 return ObjectSetAccessor( |
3629 this, name, getter, setter, data, settings, attributes); | 3484 this, name, getter, setter, data, settings, attributes); |
3630 } | 3485 } |
3631 | 3486 |
3632 | 3487 |
3633 bool Object::SetDeclaredAccessor(Local<Name> name, | |
3634 Local<DeclaredAccessorDescriptor> descriptor, | |
3635 PropertyAttribute attributes, | |
3636 AccessControl settings) { | |
3637 void* null = NULL; | |
3638 return ObjectSetAccessor( | |
3639 this, name, descriptor, null, null, settings, attributes); | |
3640 } | |
3641 | |
3642 | |
3643 void Object::SetAccessorProperty(Local<Name> name, | 3488 void Object::SetAccessorProperty(Local<Name> name, |
3644 Local<Function> getter, | 3489 Local<Function> getter, |
3645 Handle<Function> setter, | 3490 Handle<Function> setter, |
3646 PropertyAttribute attribute, | 3491 PropertyAttribute attribute, |
3647 AccessControl settings) { | 3492 AccessControl settings) { |
3648 // TODO(verwaest): Remove |settings|. | 3493 // TODO(verwaest): Remove |settings|. |
3649 DCHECK_EQ(v8::DEFAULT, settings); | 3494 DCHECK_EQ(v8::DEFAULT, settings); |
3650 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3495 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3651 ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return); | 3496 ON_BAILOUT(isolate, "v8::Object::SetAccessorProperty()", return); |
3652 ENTER_V8(isolate); | 3497 ENTER_V8(isolate); |
(...skipping 4109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7762 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 7607 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
7763 Address callback_address = | 7608 Address callback_address = |
7764 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 7609 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
7765 VMState<EXTERNAL> state(isolate); | 7610 VMState<EXTERNAL> state(isolate); |
7766 ExternalCallbackScope call_scope(isolate, callback_address); | 7611 ExternalCallbackScope call_scope(isolate, callback_address); |
7767 callback(info); | 7612 callback(info); |
7768 } | 7613 } |
7769 | 7614 |
7770 | 7615 |
7771 } } // namespace v8::internal | 7616 } } // namespace v8::internal |
OLD | NEW |