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 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 } | 962 } |
963 | 963 |
964 | 964 |
965 // --- F u n c t i o n T e m p l a t e --- | 965 // --- F u n c t i o n T e m p l a t e --- |
966 static void InitializeFunctionTemplate( | 966 static void InitializeFunctionTemplate( |
967 i::Handle<i::FunctionTemplateInfo> info) { | 967 i::Handle<i::FunctionTemplateInfo> info) { |
968 InitializeTemplate(info, Consts::FUNCTION_TEMPLATE); | 968 InitializeTemplate(info, Consts::FUNCTION_TEMPLATE); |
969 info->set_flag(0); | 969 info->set_flag(0); |
970 } | 970 } |
971 | 971 |
972 static Local<ObjectTemplate> ObjectTemplateNew( | |
973 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, | |
974 bool do_not_cache); | |
972 | 975 |
973 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { | 976 Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { |
974 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); | 977 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); |
975 ENTER_V8(i_isolate); | 978 ENTER_V8(i_isolate); |
976 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), | 979 i::Handle<i::Object> result(Utils::OpenHandle(this)->prototype_template(), |
977 i_isolate); | 980 i_isolate); |
978 if (result->IsUndefined()) { | 981 if (result->IsUndefined()) { |
979 v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(i_isolate); | 982 // Do not cache prototype objects. |
980 result = Utils::OpenHandle(*ObjectTemplate::New(isolate)); | 983 result = Utils::OpenHandle( |
984 *ObjectTemplateNew(i_isolate, Local<FunctionTemplate>(), true)); | |
981 Utils::OpenHandle(this)->set_prototype_template(*result); | 985 Utils::OpenHandle(this)->set_prototype_template(*result); |
982 } | 986 } |
983 return ToApiHandle<ObjectTemplate>(result); | 987 return ToApiHandle<ObjectTemplate>(result); |
984 } | 988 } |
985 | 989 |
986 | 990 |
987 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info, | 991 static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info, |
988 const char* func) { | 992 const char* func) { |
989 Utils::ApiCheck(!info->instantiated(), func, | 993 Utils::ApiCheck(!info->instantiated(), func, |
990 "FunctionTemplate already instantiated"); | 994 "FunctionTemplate already instantiated"); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1220 Local<ObjectTemplate> ObjectTemplate::New( | 1224 Local<ObjectTemplate> ObjectTemplate::New( |
1221 Isolate* isolate, v8::Local<FunctionTemplate> constructor) { | 1225 Isolate* isolate, v8::Local<FunctionTemplate> constructor) { |
1222 return New(reinterpret_cast<i::Isolate*>(isolate), constructor); | 1226 return New(reinterpret_cast<i::Isolate*>(isolate), constructor); |
1223 } | 1227 } |
1224 | 1228 |
1225 | 1229 |
1226 Local<ObjectTemplate> ObjectTemplate::New() { | 1230 Local<ObjectTemplate> ObjectTemplate::New() { |
1227 return New(i::Isolate::Current(), Local<FunctionTemplate>()); | 1231 return New(i::Isolate::Current(), Local<FunctionTemplate>()); |
1228 } | 1232 } |
1229 | 1233 |
1230 | 1234 static Local<ObjectTemplate> ObjectTemplateNew( |
1231 Local<ObjectTemplate> ObjectTemplate::New( | 1235 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, |
1232 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { | 1236 bool do_not_cache) { |
1233 // Changes to the environment cannot be captured in the snapshot. Expect no | 1237 // Changes to the environment cannot be captured in the snapshot. Expect no |
1234 // object templates when the isolate is created for serialization. | 1238 // object templates when the isolate is created for serialization. |
1235 DCHECK(!isolate->serializer_enabled()); | 1239 DCHECK(!isolate->serializer_enabled()); |
1236 LOG_API(isolate, "ObjectTemplate::New"); | 1240 LOG_API(isolate, "ObjectTemplate::New"); |
1237 ENTER_V8(isolate); | 1241 ENTER_V8(isolate); |
1238 i::Handle<i::Struct> struct_obj = | 1242 i::Handle<i::Struct> struct_obj = |
1239 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); | 1243 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
1240 i::Handle<i::ObjectTemplateInfo> obj = | 1244 i::Handle<i::ObjectTemplateInfo> obj = |
1241 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); | 1245 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
1242 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 1246 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
1247 int next_serial_number = 0; | |
1248 if (!do_not_cache) { | |
1249 next_serial_number = isolate->next_serial_number() + 1; | |
1250 isolate->set_next_serial_number(next_serial_number); | |
1251 } | |
1252 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | |
1243 if (!constructor.IsEmpty()) | 1253 if (!constructor.IsEmpty()) |
1244 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 1254 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
1245 obj->set_internal_field_count(i::Smi::FromInt(0)); | 1255 obj->set_internal_field_count(i::Smi::FromInt(0)); |
1246 return Utils::ToLocal(obj); | 1256 return Utils::ToLocal(obj); |
1247 } | 1257 } |
1248 | 1258 |
1259 Local<ObjectTemplate> ObjectTemplate::New( | |
1260 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { | |
1261 return ObjectTemplateNew(isolate, constructor, false); | |
1262 } | |
1249 | 1263 |
1250 // Ensure that the object template has a constructor. If no | 1264 // Ensure that the object template has a constructor. If no |
1251 // constructor is available we create one. | 1265 // constructor is available we create one. |
1252 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( | 1266 static i::Handle<i::FunctionTemplateInfo> EnsureConstructor( |
1253 i::Isolate* isolate, | 1267 i::Isolate* isolate, |
1254 ObjectTemplate* object_template) { | 1268 ObjectTemplate* object_template) { |
1255 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); | 1269 i::Object* obj = Utils::OpenHandle(object_template)->constructor(); |
1256 if (!obj ->IsUndefined()) { | 1270 if (!obj ->IsUndefined()) { |
1257 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); | 1271 i::FunctionTemplateInfo* info = i::FunctionTemplateInfo::cast(obj); |
1258 return i::Handle<i::FunctionTemplateInfo>(info, isolate); | 1272 return i::Handle<i::FunctionTemplateInfo>(info, isolate); |
(...skipping 11 matching lines...) Expand all Loading... | |
1270 i::Isolate* isolate, | 1284 i::Isolate* isolate, |
1271 Template* template_obj) { | 1285 Template* template_obj) { |
1272 return Utils::OpenHandle(template_obj); | 1286 return Utils::OpenHandle(template_obj); |
1273 } | 1287 } |
1274 | 1288 |
1275 | 1289 |
1276 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor | 1290 // TODO(dcarney): remove this with ObjectTemplate::SetAccessor |
1277 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( | 1291 static inline i::Handle<i::TemplateInfo> GetTemplateInfo( |
1278 i::Isolate* isolate, | 1292 i::Isolate* isolate, |
1279 ObjectTemplate* object_template) { | 1293 ObjectTemplate* object_template) { |
1280 EnsureConstructor(isolate, object_template); | 1294 // EnsureConstructor(isolate, object_template); |
Toon Verwaest
2016/01/29 14:37:45
You can now get rid of this function I presume, gi
Igor Sheludko
2016/02/01 20:43:55
Done.
| |
1281 return Utils::OpenHandle(object_template); | 1295 return Utils::OpenHandle(object_template); |
1282 } | 1296 } |
1283 | 1297 |
1284 template <typename Getter, typename Setter, typename Data, typename Template> | 1298 template <typename Getter, typename Setter, typename Data, typename Template> |
1285 static bool TemplateSetAccessor(Template* template_obj, v8::Local<Name> name, | 1299 static bool TemplateSetAccessor(Template* template_obj, v8::Local<Name> name, |
1286 Getter getter, Setter setter, Data data, | 1300 Getter getter, Setter setter, Data data, |
1287 AccessControl settings, | 1301 AccessControl settings, |
1288 PropertyAttribute attribute, | 1302 PropertyAttribute attribute, |
1289 v8::Local<AccessorSignature> signature, | 1303 v8::Local<AccessorSignature> signature, |
1290 bool is_special_data_property) { | 1304 bool is_special_data_property) { |
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3299 double Value::NumberValue() const { | 3313 double Value::NumberValue() const { |
3300 auto obj = Utils::OpenHandle(this); | 3314 auto obj = Utils::OpenHandle(this); |
3301 if (obj->IsNumber()) return obj->Number(); | 3315 if (obj->IsNumber()) return obj->Number(); |
3302 return NumberValue(ContextFromHeapObject(obj)) | 3316 return NumberValue(ContextFromHeapObject(obj)) |
3303 .FromMaybe(std::numeric_limits<double>::quiet_NaN()); | 3317 .FromMaybe(std::numeric_limits<double>::quiet_NaN()); |
3304 } | 3318 } |
3305 | 3319 |
3306 | 3320 |
3307 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { | 3321 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { |
3308 auto obj = Utils::OpenHandle(this); | 3322 auto obj = Utils::OpenHandle(this); |
3323 if (obj->IsNumber()) { | |
3324 return Just(NumberToInt64(*obj)); | |
3325 } | |
3326 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); | |
3309 i::Handle<i::Object> num; | 3327 i::Handle<i::Object> num; |
3310 if (obj->IsNumber()) { | 3328 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num); |
3311 num = obj; | 3329 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); |
3312 } else { | 3330 return Just(NumberToInt64(*num)); |
3313 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); | |
3314 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num); | |
3315 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); | |
3316 } | |
3317 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value()) | |
3318 : static_cast<int64_t>(num->Number())); | |
3319 } | 3331 } |
3320 | 3332 |
3321 | 3333 |
3322 int64_t Value::IntegerValue() const { | 3334 int64_t Value::IntegerValue() const { |
3323 auto obj = Utils::OpenHandle(this); | 3335 auto obj = Utils::OpenHandle(this); |
3324 if (obj->IsNumber()) { | 3336 if (obj->IsNumber()) { |
3325 if (obj->IsSmi()) { | 3337 if (obj->IsSmi()) { |
3326 return i::Smi::cast(*obj)->value(); | 3338 return i::Smi::cast(*obj)->value(); |
3327 } else { | 3339 } else { |
3328 return static_cast<int64_t>(obj->Number()); | 3340 return static_cast<int64_t>(obj->Number()); |
(...skipping 5224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8553 Address callback_address = | 8565 Address callback_address = |
8554 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8566 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8555 VMState<EXTERNAL> state(isolate); | 8567 VMState<EXTERNAL> state(isolate); |
8556 ExternalCallbackScope call_scope(isolate, callback_address); | 8568 ExternalCallbackScope call_scope(isolate, callback_address); |
8557 callback(info); | 8569 callback(info); |
8558 } | 8570 } |
8559 | 8571 |
8560 | 8572 |
8561 } // namespace internal | 8573 } // namespace internal |
8562 } // namespace v8 | 8574 } // namespace v8 |
OLD | NEW |