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 2919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2930 RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number); | 2930 RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number); |
2931 } | 2931 } |
2932 | 2932 |
2933 | 2933 |
2934 MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const { | 2934 MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const { |
2935 auto obj = Utils::OpenHandle(this); | 2935 auto obj = Utils::OpenHandle(this); |
2936 if (obj->IsSmi()) return ToApiHandle<Integer>(obj); | 2936 if (obj->IsSmi()) return ToApiHandle<Integer>(obj); |
2937 PREPARE_FOR_EXECUTION(context, "ToInteger", Integer); | 2937 PREPARE_FOR_EXECUTION(context, "ToInteger", Integer); |
2938 Local<Integer> result; | 2938 Local<Integer> result; |
2939 has_pending_exception = | 2939 has_pending_exception = |
2940 !ToLocal<Integer>(i::Execution::ToInteger(isolate, obj), &result); | 2940 !ToLocal<Integer>(i::Object::ToInteger(isolate, obj), &result); |
2941 RETURN_ON_FAILED_EXECUTION(Integer); | 2941 RETURN_ON_FAILED_EXECUTION(Integer); |
2942 RETURN_ESCAPED(result); | 2942 RETURN_ESCAPED(result); |
2943 } | 2943 } |
2944 | 2944 |
2945 | 2945 |
2946 Local<Integer> Value::ToInteger(Isolate* isolate) const { | 2946 Local<Integer> Value::ToInteger(Isolate* isolate) const { |
2947 RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer); | 2947 RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer); |
2948 } | 2948 } |
2949 | 2949 |
2950 | 2950 |
2951 MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const { | 2951 MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const { |
2952 auto obj = Utils::OpenHandle(this); | 2952 auto obj = Utils::OpenHandle(this); |
2953 if (obj->IsSmi()) return ToApiHandle<Int32>(obj); | 2953 if (obj->IsSmi()) return ToApiHandle<Int32>(obj); |
2954 Local<Int32> result; | 2954 Local<Int32> result; |
2955 PREPARE_FOR_EXECUTION(context, "ToInt32", Int32); | 2955 PREPARE_FOR_EXECUTION(context, "ToInt32", Int32); |
2956 has_pending_exception = | 2956 has_pending_exception = |
2957 !ToLocal<Int32>(i::Execution::ToInt32(isolate, obj), &result); | 2957 !ToLocal<Int32>(i::Object::ToInt32(isolate, obj), &result); |
2958 RETURN_ON_FAILED_EXECUTION(Int32); | 2958 RETURN_ON_FAILED_EXECUTION(Int32); |
2959 RETURN_ESCAPED(result); | 2959 RETURN_ESCAPED(result); |
2960 } | 2960 } |
2961 | 2961 |
2962 | 2962 |
2963 Local<Int32> Value::ToInt32(Isolate* isolate) const { | 2963 Local<Int32> Value::ToInt32(Isolate* isolate) const { |
2964 RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32); | 2964 RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32); |
2965 } | 2965 } |
2966 | 2966 |
2967 | 2967 |
2968 MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const { | 2968 MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const { |
2969 auto obj = Utils::OpenHandle(this); | 2969 auto obj = Utils::OpenHandle(this); |
2970 if (obj->IsSmi()) return ToApiHandle<Uint32>(obj); | 2970 if (obj->IsSmi()) return ToApiHandle<Uint32>(obj); |
2971 Local<Uint32> result; | 2971 Local<Uint32> result; |
2972 PREPARE_FOR_EXECUTION(context, "ToUInt32", Uint32); | 2972 PREPARE_FOR_EXECUTION(context, "ToUint32", Uint32); |
2973 has_pending_exception = | 2973 has_pending_exception = |
2974 !ToLocal<Uint32>(i::Execution::ToUint32(isolate, obj), &result); | 2974 !ToLocal<Uint32>(i::Object::ToUint32(isolate, obj), &result); |
2975 RETURN_ON_FAILED_EXECUTION(Uint32); | 2975 RETURN_ON_FAILED_EXECUTION(Uint32); |
2976 RETURN_ESCAPED(result); | 2976 RETURN_ESCAPED(result); |
2977 } | 2977 } |
2978 | 2978 |
2979 | 2979 |
2980 Local<Uint32> Value::ToUint32(Isolate* isolate) const { | 2980 Local<Uint32> Value::ToUint32(Isolate* isolate) const { |
2981 RETURN_TO_LOCAL_UNCHECKED(ToUint32(isolate->GetCurrentContext()), Uint32); | 2981 RETURN_TO_LOCAL_UNCHECKED(ToUint32(isolate->GetCurrentContext()), Uint32); |
2982 } | 2982 } |
2983 | 2983 |
2984 | 2984 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3258 } | 3258 } |
3259 | 3259 |
3260 | 3260 |
3261 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { | 3261 Maybe<int64_t> Value::IntegerValue(Local<Context> context) const { |
3262 auto obj = Utils::OpenHandle(this); | 3262 auto obj = Utils::OpenHandle(this); |
3263 i::Handle<i::Object> num; | 3263 i::Handle<i::Object> num; |
3264 if (obj->IsNumber()) { | 3264 if (obj->IsNumber()) { |
3265 num = obj; | 3265 num = obj; |
3266 } else { | 3266 } else { |
3267 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); | 3267 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "IntegerValue", int64_t); |
3268 has_pending_exception = | 3268 has_pending_exception = !i::Object::ToInteger(isolate, obj).ToHandle(&num); |
3269 !i::Execution::ToInteger(isolate, obj).ToHandle(&num); | |
3270 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); | 3269 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int64_t); |
3271 } | 3270 } |
3272 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value()) | 3271 return Just(num->IsSmi() ? static_cast<int64_t>(i::Smi::cast(*num)->value()) |
3273 : static_cast<int64_t>(num->Number())); | 3272 : static_cast<int64_t>(num->Number())); |
3274 } | 3273 } |
3275 | 3274 |
3276 | 3275 |
3277 int64_t Value::IntegerValue() const { | 3276 int64_t Value::IntegerValue() const { |
3278 auto obj = Utils::OpenHandle(this); | 3277 auto obj = Utils::OpenHandle(this); |
3279 if (obj->IsNumber()) { | 3278 if (obj->IsNumber()) { |
3280 if (obj->IsSmi()) { | 3279 if (obj->IsSmi()) { |
3281 return i::Smi::cast(*obj)->value(); | 3280 return i::Smi::cast(*obj)->value(); |
3282 } else { | 3281 } else { |
3283 return static_cast<int64_t>(obj->Number()); | 3282 return static_cast<int64_t>(obj->Number()); |
3284 } | 3283 } |
3285 } | 3284 } |
3286 return IntegerValue(ContextFromHeapObject(obj)).FromMaybe(0); | 3285 return IntegerValue(ContextFromHeapObject(obj)).FromMaybe(0); |
3287 } | 3286 } |
3288 | 3287 |
3289 | 3288 |
3290 Maybe<int32_t> Value::Int32Value(Local<Context> context) const { | 3289 Maybe<int32_t> Value::Int32Value(Local<Context> context) const { |
3291 auto obj = Utils::OpenHandle(this); | 3290 auto obj = Utils::OpenHandle(this); |
3292 if (obj->IsNumber()) return Just(NumberToInt32(*obj)); | 3291 if (obj->IsNumber()) return Just(NumberToInt32(*obj)); |
3293 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Int32Value", int32_t); | 3292 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Int32Value", int32_t); |
3294 i::Handle<i::Object> num; | 3293 i::Handle<i::Object> num; |
3295 has_pending_exception = !i::Execution::ToInt32(isolate, obj).ToHandle(&num); | 3294 has_pending_exception = !i::Object::ToInt32(isolate, obj).ToHandle(&num); |
3296 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t); | 3295 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int32_t); |
3297 return Just(num->IsSmi() ? i::Smi::cast(*num)->value() | 3296 return Just(num->IsSmi() ? i::Smi::cast(*num)->value() |
3298 : static_cast<int32_t>(num->Number())); | 3297 : static_cast<int32_t>(num->Number())); |
3299 } | 3298 } |
3300 | 3299 |
3301 | 3300 |
3302 int32_t Value::Int32Value() const { | 3301 int32_t Value::Int32Value() const { |
3303 auto obj = Utils::OpenHandle(this); | 3302 auto obj = Utils::OpenHandle(this); |
3304 if (obj->IsNumber()) return NumberToInt32(*obj); | 3303 if (obj->IsNumber()) return NumberToInt32(*obj); |
3305 return Int32Value(ContextFromHeapObject(obj)).FromMaybe(0); | 3304 return Int32Value(ContextFromHeapObject(obj)).FromMaybe(0); |
3306 } | 3305 } |
3307 | 3306 |
3308 | 3307 |
3309 Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const { | 3308 Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const { |
3310 auto obj = Utils::OpenHandle(this); | 3309 auto obj = Utils::OpenHandle(this); |
3311 if (obj->IsNumber()) return Just(NumberToUint32(*obj)); | 3310 if (obj->IsNumber()) return Just(NumberToUint32(*obj)); |
3312 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Uint32Value", uint32_t); | 3311 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "Uint32Value", uint32_t); |
3313 i::Handle<i::Object> num; | 3312 i::Handle<i::Object> num; |
3314 has_pending_exception = !i::Execution::ToUint32(isolate, obj).ToHandle(&num); | 3313 has_pending_exception = !i::Object::ToUint32(isolate, obj).ToHandle(&num); |
3315 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(uint32_t); | 3314 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(uint32_t); |
3316 return Just(num->IsSmi() ? static_cast<uint32_t>(i::Smi::cast(*num)->value()) | 3315 return Just(num->IsSmi() ? static_cast<uint32_t>(i::Smi::cast(*num)->value()) |
3317 : static_cast<uint32_t>(num->Number())); | 3316 : static_cast<uint32_t>(num->Number())); |
3318 } | 3317 } |
3319 | 3318 |
3320 | 3319 |
3321 uint32_t Value::Uint32Value() const { | 3320 uint32_t Value::Uint32Value() const { |
3322 auto obj = Utils::OpenHandle(this); | 3321 auto obj = Utils::OpenHandle(this); |
3323 if (obj->IsNumber()) return NumberToUint32(*obj); | 3322 if (obj->IsNumber()) return NumberToUint32(*obj); |
3324 return Uint32Value(ContextFromHeapObject(obj)).FromMaybe(0); | 3323 return Uint32Value(ContextFromHeapObject(obj)).FromMaybe(0); |
(...skipping 5035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8360 Address callback_address = | 8359 Address callback_address = |
8361 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8360 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8362 VMState<EXTERNAL> state(isolate); | 8361 VMState<EXTERNAL> state(isolate); |
8363 ExternalCallbackScope call_scope(isolate, callback_address); | 8362 ExternalCallbackScope call_scope(isolate, callback_address); |
8364 callback(info); | 8363 callback(info); |
8365 } | 8364 } |
8366 | 8365 |
8367 | 8366 |
8368 } // namespace internal | 8367 } // namespace internal |
8369 } // namespace v8 | 8368 } // namespace v8 |
OLD | NEW |