| 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 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 templ->set_serial_number(i::Smi::kZero); | 1078 templ->set_serial_number(i::Smi::kZero); |
| 1079 if (templ->IsFunctionTemplateInfo()) { | 1079 if (templ->IsFunctionTemplateInfo()) { |
| 1080 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true); | 1080 i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true); |
| 1081 } | 1081 } |
| 1082 } | 1082 } |
| 1083 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), | 1083 i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name), |
| 1084 value_obj, | 1084 value_obj, |
| 1085 static_cast<i::PropertyAttributes>(attribute)); | 1085 static_cast<i::PropertyAttributes>(attribute)); |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 void Template::SetPrivate(v8::Local<Private> name, v8::Local<Data> value, |
| 1089 v8::PropertyAttribute attribute) { |
| 1090 Set(Utils::ToLocal(Utils::OpenHandle(reinterpret_cast<Name*>(*name))), value, |
| 1091 attribute); |
| 1092 } |
| 1088 | 1093 |
| 1089 void Template::SetAccessorProperty( | 1094 void Template::SetAccessorProperty( |
| 1090 v8::Local<v8::Name> name, | 1095 v8::Local<v8::Name> name, |
| 1091 v8::Local<FunctionTemplate> getter, | 1096 v8::Local<FunctionTemplate> getter, |
| 1092 v8::Local<FunctionTemplate> setter, | 1097 v8::Local<FunctionTemplate> setter, |
| 1093 v8::PropertyAttribute attribute, | 1098 v8::PropertyAttribute attribute, |
| 1094 v8::AccessControl access_control) { | 1099 v8::AccessControl access_control) { |
| 1095 // TODO(verwaest): Remove |access_control|. | 1100 // TODO(verwaest): Remove |access_control|. |
| 1096 DCHECK_EQ(v8::DEFAULT, access_control); | 1101 DCHECK_EQ(v8::DEFAULT, access_control); |
| 1097 auto templ = Utils::OpenHandle(this); | 1102 auto templ = Utils::OpenHandle(this); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 | 1146 |
| 1142 | 1147 |
| 1143 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { | 1148 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { |
| 1144 auto info = Utils::OpenHandle(this); | 1149 auto info = Utils::OpenHandle(this); |
| 1145 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); | 1150 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); |
| 1146 i::Isolate* isolate = info->GetIsolate(); | 1151 i::Isolate* isolate = info->GetIsolate(); |
| 1147 ENTER_V8(isolate); | 1152 ENTER_V8(isolate); |
| 1148 info->set_parent_template(*Utils::OpenHandle(*value)); | 1153 info->set_parent_template(*Utils::OpenHandle(*value)); |
| 1149 } | 1154 } |
| 1150 | 1155 |
| 1151 | |
| 1152 static Local<FunctionTemplate> FunctionTemplateNew( | 1156 static Local<FunctionTemplate> FunctionTemplateNew( |
| 1153 i::Isolate* isolate, FunctionCallback callback, | 1157 i::Isolate* isolate, FunctionCallback callback, |
| 1154 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1158 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
| 1155 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1159 v8::Local<Signature> signature, int length, bool do_not_cache, |
| 1160 v8::Local<Private> cache_property = v8::Local<Private>()) { |
| 1156 i::Handle<i::Struct> struct_obj = | 1161 i::Handle<i::Struct> struct_obj = |
| 1157 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1162 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
| 1158 i::Handle<i::FunctionTemplateInfo> obj = | 1163 i::Handle<i::FunctionTemplateInfo> obj = |
| 1159 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1164 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 1160 InitializeFunctionTemplate(obj); | 1165 InitializeFunctionTemplate(obj); |
| 1161 obj->set_do_not_cache(do_not_cache); | 1166 obj->set_do_not_cache(do_not_cache); |
| 1162 int next_serial_number = 0; | 1167 int next_serial_number = 0; |
| 1163 if (!do_not_cache) { | 1168 if (!do_not_cache) { |
| 1164 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); | 1169 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); |
| 1165 } | 1170 } |
| 1166 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1171 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| 1167 if (callback != 0) { | 1172 if (callback != 0) { |
| 1168 if (data.IsEmpty()) { | 1173 if (data.IsEmpty()) { |
| 1169 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1174 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1170 } | 1175 } |
| 1171 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); | 1176 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); |
| 1172 } | 1177 } |
| 1173 obj->set_length(length); | 1178 obj->set_length(length); |
| 1174 obj->set_undetectable(false); | 1179 obj->set_undetectable(false); |
| 1175 obj->set_needs_access_check(false); | 1180 obj->set_needs_access_check(false); |
| 1176 obj->set_accept_any_receiver(true); | 1181 obj->set_accept_any_receiver(true); |
| 1177 if (!signature.IsEmpty()) | 1182 if (!signature.IsEmpty()) |
| 1178 obj->set_signature(*Utils::OpenHandle(*signature)); | 1183 obj->set_signature(*Utils::OpenHandle(*signature)); |
| 1184 obj->set_cache_property(cache_property.IsEmpty() |
| 1185 ? isolate->heap()->the_hole_value() |
| 1186 : *Utils::OpenHandle(*cache_property)); |
| 1179 return Utils::ToLocal(obj); | 1187 return Utils::ToLocal(obj); |
| 1180 } | 1188 } |
| 1181 | 1189 |
| 1182 Local<FunctionTemplate> FunctionTemplate::New( | 1190 Local<FunctionTemplate> FunctionTemplate::New( |
| 1183 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, | 1191 Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, |
| 1184 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) { | 1192 v8::Local<Signature> signature, int length, ConstructorBehavior behavior) { |
| 1185 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1193 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1186 // Changes to the environment cannot be captured in the snapshot. Expect no | 1194 // Changes to the environment cannot be captured in the snapshot. Expect no |
| 1187 // function templates when the isolate is created for serialization. | 1195 // function templates when the isolate is created for serialization. |
| 1188 LOG_API(i_isolate, FunctionTemplate, New); | 1196 LOG_API(i_isolate, FunctionTemplate, New); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1213 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1221 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
| 1214 v8::Local<Signature> signature, int length) { | 1222 v8::Local<Signature> signature, int length) { |
| 1215 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1223 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1216 DCHECK(!i_isolate->serializer_enabled()); | 1224 DCHECK(!i_isolate->serializer_enabled()); |
| 1217 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler); | 1225 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler); |
| 1218 ENTER_V8(i_isolate); | 1226 ENTER_V8(i_isolate); |
| 1219 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, | 1227 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature, |
| 1220 length, false); | 1228 length, false); |
| 1221 } | 1229 } |
| 1222 | 1230 |
| 1231 Local<FunctionTemplate> FunctionTemplate::NewWithCache( |
| 1232 Isolate* isolate, FunctionCallback callback, Local<Private> cache_property, |
| 1233 Local<Value> data, Local<Signature> signature, int length) { |
| 1234 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1235 DCHECK(!i_isolate->serializer_enabled()); |
| 1236 LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler); |
| 1237 ENTER_V8(i_isolate); |
| 1238 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, |
| 1239 length, false, cache_property); |
| 1240 } |
| 1223 | 1241 |
| 1224 Local<Signature> Signature::New(Isolate* isolate, | 1242 Local<Signature> Signature::New(Isolate* isolate, |
| 1225 Local<FunctionTemplate> receiver) { | 1243 Local<FunctionTemplate> receiver) { |
| 1226 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1244 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1227 } | 1245 } |
| 1228 | 1246 |
| 1229 | 1247 |
| 1230 Local<AccessorSignature> AccessorSignature::New( | 1248 Local<AccessorSignature> AccessorSignature::New( |
| 1231 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1249 Isolate* isolate, Local<FunctionTemplate> receiver) { |
| 1232 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1250 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
| (...skipping 8213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9446 Address callback_address = | 9464 Address callback_address = |
| 9447 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9465 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9448 VMState<EXTERNAL> state(isolate); | 9466 VMState<EXTERNAL> state(isolate); |
| 9449 ExternalCallbackScope call_scope(isolate, callback_address); | 9467 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9450 callback(info); | 9468 callback(info); |
| 9451 } | 9469 } |
| 9452 | 9470 |
| 9453 | 9471 |
| 9454 } // namespace internal | 9472 } // namespace internal |
| 9455 } // namespace v8 | 9473 } // namespace v8 |
| OLD | NEW |