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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 | 988 |
989 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { | 989 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { |
990 auto info = Utils::OpenHandle(this); | 990 auto info = Utils::OpenHandle(this); |
991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); | 991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); |
992 i::Isolate* isolate = info->GetIsolate(); | 992 i::Isolate* isolate = info->GetIsolate(); |
993 ENTER_V8(isolate); | 993 ENTER_V8(isolate); |
994 info->set_parent_template(*Utils::OpenHandle(*value)); | 994 info->set_parent_template(*Utils::OpenHandle(*value)); |
995 } | 995 } |
996 | 996 |
997 | 997 |
| 998 template <typename CodeOrCallback> |
| 999 static bool IsEmpty(CodeOrCallback callback); |
| 1000 |
| 1001 |
| 1002 template <> |
| 1003 bool IsEmpty(FunctionCallback callback) { |
| 1004 return callback == 0; |
| 1005 } |
| 1006 |
| 1007 |
| 1008 #ifdef V8_FAST_ACCESSORS |
| 1009 template <> |
| 1010 bool IsEmpty(v8::Local<Value> callback) { |
| 1011 return callback.IsEmpty(); |
| 1012 } |
| 1013 #endif |
| 1014 |
| 1015 |
| 1016 template <typename CodeOrCallback> |
998 static Local<FunctionTemplate> FunctionTemplateNew( | 1017 static Local<FunctionTemplate> FunctionTemplateNew( |
999 i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, | 1018 i::Isolate* isolate, CodeOrCallback callback, v8::Local<Value> data, |
1000 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1019 v8::Local<Signature> signature, int length, bool do_not_cache) { |
1001 i::Handle<i::Struct> struct_obj = | 1020 i::Handle<i::Struct> struct_obj = |
1002 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1021 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
1003 i::Handle<i::FunctionTemplateInfo> obj = | 1022 i::Handle<i::FunctionTemplateInfo> obj = |
1004 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1023 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
1005 InitializeFunctionTemplate(obj); | 1024 InitializeFunctionTemplate(obj); |
1006 obj->set_do_not_cache(do_not_cache); | 1025 obj->set_do_not_cache(do_not_cache); |
1007 int next_serial_number = 0; | 1026 int next_serial_number = 0; |
1008 if (!do_not_cache) { | 1027 if (!do_not_cache) { |
1009 next_serial_number = isolate->next_serial_number() + 1; | 1028 next_serial_number = isolate->next_serial_number() + 1; |
1010 isolate->set_next_serial_number(next_serial_number); | 1029 isolate->set_next_serial_number(next_serial_number); |
1011 } | 1030 } |
1012 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1031 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
1013 if (callback != 0) { | 1032 if (!IsEmpty(callback)) { |
1014 if (data.IsEmpty()) { | 1033 if (data.IsEmpty()) { |
1015 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1034 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1016 } | 1035 } |
1017 Utils::ToLocal(obj)->SetCallHandler(callback, data); | 1036 Utils::ToLocal(obj)->SetCallHandler(callback, data); |
1018 } | 1037 } |
1019 obj->set_length(length); | 1038 obj->set_length(length); |
1020 obj->set_undetectable(false); | 1039 obj->set_undetectable(false); |
1021 obj->set_needs_access_check(false); | 1040 obj->set_needs_access_check(false); |
1022 obj->set_accept_any_receiver(true); | 1041 obj->set_accept_any_receiver(true); |
1023 if (!signature.IsEmpty()) | 1042 if (!signature.IsEmpty()) |
1024 obj->set_signature(*Utils::OpenHandle(*signature)); | 1043 obj->set_signature(*Utils::OpenHandle(*signature)); |
1025 return Utils::ToLocal(obj); | 1044 return Utils::ToLocal(obj); |
1026 } | 1045 } |
1027 | 1046 |
| 1047 |
1028 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, | 1048 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
1029 FunctionCallback callback, | 1049 FunctionCallback callback, |
1030 v8::Local<Value> data, | 1050 v8::Local<Value> data, |
1031 v8::Local<Signature> signature, | 1051 v8::Local<Signature> signature, |
1032 int length) { | 1052 int length) { |
1033 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1053 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
1034 // Changes to the environment cannot be captured in the snapshot. Expect no | 1054 // Changes to the environment cannot be captured in the snapshot. Expect no |
1035 // function templates when the isolate is created for serialization. | 1055 // function templates when the isolate is created for serialization. |
1036 DCHECK(!i_isolate->serializer_enabled()); | 1056 DCHECK(!i_isolate->serializer_enabled()); |
1037 LOG_API(i_isolate, "FunctionTemplate::New"); | 1057 LOG_API(i_isolate, "FunctionTemplate::New"); |
1038 ENTER_V8(i_isolate); | 1058 ENTER_V8(i_isolate); |
1039 return FunctionTemplateNew( | 1059 return FunctionTemplateNew( |
1040 i_isolate, callback, data, signature, length, false); | 1060 i_isolate, callback, data, signature, length, false); |
1041 } | 1061 } |
1042 | 1062 |
1043 | 1063 |
| 1064 #ifdef V8_FAST_ACCESSORS |
| 1065 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
| 1066 v8::Local<Value> code, |
| 1067 v8::Local<Value> data, |
| 1068 v8::Local<Signature> signature, |
| 1069 int length) { |
| 1070 // TODO(vogelheim): 'code' should have a more specific type than Local<Value>. |
| 1071 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1072 DCHECK(!i_isolate->serializer_enabled()); |
| 1073 LOG_API(i_isolate, "FunctionTemplate::New"); |
| 1074 ENTER_V8(i_isolate); |
| 1075 return FunctionTemplateNew(i_isolate, code, data, signature, length, false); |
| 1076 } |
| 1077 #endif |
| 1078 |
| 1079 |
1044 Local<Signature> Signature::New(Isolate* isolate, | 1080 Local<Signature> Signature::New(Isolate* isolate, |
1045 Local<FunctionTemplate> receiver) { | 1081 Local<FunctionTemplate> receiver) { |
1046 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1082 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
1047 } | 1083 } |
1048 | 1084 |
1049 | 1085 |
1050 Local<AccessorSignature> AccessorSignature::New( | 1086 Local<AccessorSignature> AccessorSignature::New( |
1051 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1087 Isolate* isolate, Local<FunctionTemplate> receiver) { |
1052 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1088 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
1053 } | 1089 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 i::Handle<i::CallHandlerInfo>::cast(struct_obj); | 1143 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
1108 SET_FIELD_WRAPPED(obj, set_callback, callback); | 1144 SET_FIELD_WRAPPED(obj, set_callback, callback); |
1109 if (data.IsEmpty()) { | 1145 if (data.IsEmpty()) { |
1110 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1146 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
1111 } | 1147 } |
1112 obj->set_data(*Utils::OpenHandle(*data)); | 1148 obj->set_data(*Utils::OpenHandle(*data)); |
1113 info->set_call_code(*obj); | 1149 info->set_call_code(*obj); |
1114 } | 1150 } |
1115 | 1151 |
1116 | 1152 |
| 1153 #ifdef V8_FAST_ACCESSORS |
| 1154 void FunctionTemplate::SetCallHandler(v8::Local<Value> code, |
| 1155 v8::Local<Value> data) { |
| 1156 auto info = Utils::OpenHandle(this); |
| 1157 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
| 1158 i::Isolate* isolate = info->GetIsolate(); |
| 1159 ENTER_V8(isolate); |
| 1160 i::HandleScope scope(isolate); |
| 1161 i::Handle<i::Struct> struct_obj = |
| 1162 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
| 1163 i::Handle<i::CallHandlerInfo> obj = |
| 1164 i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
| 1165 i::Handle<i::Object> callback = Utils::OpenHandle(*code); |
| 1166 CHECK(callback->IsCode()); |
| 1167 obj->set_callback(*callback); |
| 1168 if (data.IsEmpty()) { |
| 1169 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1170 } |
| 1171 obj->set_data(*Utils::OpenHandle(*data)); |
| 1172 info->set_call_code(*obj); |
| 1173 } |
| 1174 #endif |
| 1175 |
| 1176 |
1117 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1177 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
1118 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, | 1178 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, |
1119 v8::AccessControl settings, v8::PropertyAttribute attributes, | 1179 v8::AccessControl settings, v8::PropertyAttribute attributes, |
1120 v8::Local<AccessorSignature> signature) { | 1180 v8::Local<AccessorSignature> signature) { |
1121 obj->set_name(*Utils::OpenHandle(*name)); | 1181 obj->set_name(*Utils::OpenHandle(*name)); |
1122 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); | 1182 if (settings & ALL_CAN_READ) obj->set_all_can_read(true); |
1123 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); | 1183 if (settings & ALL_CAN_WRITE) obj->set_all_can_write(true); |
1124 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); | 1184 obj->set_property_attributes(static_cast<PropertyAttributes>(attributes)); |
1125 if (!signature.IsEmpty()) { | 1185 if (!signature.IsEmpty()) { |
1126 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); | 1186 obj->set_expected_receiver_type(*Utils::OpenHandle(*signature)); |
(...skipping 7373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8500 Address callback_address = | 8560 Address callback_address = |
8501 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8561 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8502 VMState<EXTERNAL> state(isolate); | 8562 VMState<EXTERNAL> state(isolate); |
8503 ExternalCallbackScope call_scope(isolate, callback_address); | 8563 ExternalCallbackScope call_scope(isolate, callback_address); |
8504 callback(info); | 8564 callback(info); |
8505 } | 8565 } |
8506 | 8566 |
8507 | 8567 |
8508 } // namespace internal | 8568 } // namespace internal |
8509 } // namespace v8 | 8569 } // namespace v8 |
OLD | NEW |