OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "lib/stacktrace.h" | 9 #include "lib/stacktrace.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 *value = static_cast<uint64_t>(arg_value); | 262 *value = static_cast<uint64_t>(arg_value); |
263 return true; | 263 return true; |
264 } | 264 } |
265 Thread* thread = arguments->thread(); | 265 Thread* thread = arguments->thread(); |
266 ASSERT(thread == Thread::Current()); | 266 ASSERT(thread == Thread::Current()); |
267 REUSABLE_OBJECT_HANDLESCOPE(thread); | 267 REUSABLE_OBJECT_HANDLESCOPE(thread); |
268 Object& obj = thread->ObjectHandle(); | 268 Object& obj = thread->ObjectHandle(); |
269 obj = arguments->NativeArgAt(arg_index); | 269 obj = arguments->NativeArgAt(arg_index); |
270 intptr_t cid = obj.GetClassId(); | 270 intptr_t cid = obj.GetClassId(); |
271 if (cid == kBigintCid) { | 271 if (cid == kBigintCid) { |
| 272 ASSERT(!Bigint::IsDisabled()); |
272 const Bigint& bigint = Bigint::Cast(obj); | 273 const Bigint& bigint = Bigint::Cast(obj); |
273 if (bigint.FitsIntoUint64()) { | 274 if (bigint.FitsIntoUint64()) { |
274 *value = bigint.AsUint64Value(); | 275 *value = bigint.AsUint64Value(); |
275 return true; | 276 return true; |
276 } | 277 } |
277 } | 278 } |
278 return false; | 279 return false; |
279 } | 280 } |
280 | 281 |
281 static bool GetNativeDoubleArgument(NativeArguments* arguments, | 282 static bool GetNativeDoubleArgument(NativeArguments* arguments, |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 // Slow path for Mints and Bigints. | 2006 // Slow path for Mints and Bigints. |
2006 DARTSCOPE(thread); | 2007 DARTSCOPE(thread); |
2007 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2008 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
2008 if (int_obj.IsNull()) { | 2009 if (int_obj.IsNull()) { |
2009 RETURN_TYPE_ERROR(Z, integer, Integer); | 2010 RETURN_TYPE_ERROR(Z, integer, Integer); |
2010 } | 2011 } |
2011 ASSERT(!int_obj.IsSmi()); | 2012 ASSERT(!int_obj.IsSmi()); |
2012 if (int_obj.IsMint()) { | 2013 if (int_obj.IsMint()) { |
2013 *fits = !int_obj.IsNegative(); | 2014 *fits = !int_obj.IsNegative(); |
2014 } else { | 2015 } else { |
| 2016 ASSERT(!Bigint::IsDisabled()); |
2015 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); | 2017 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); |
2016 } | 2018 } |
2017 return Api::Success(); | 2019 return Api::Success(); |
2018 } | 2020 } |
2019 | 2021 |
2020 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 2022 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
2021 // Fast path for Smis. | 2023 // Fast path for Smis. |
2022 Thread* thread = Thread::Current(); | 2024 Thread* thread = Thread::Current(); |
2023 Isolate* isolate = thread->isolate(); | 2025 Isolate* isolate = thread->isolate(); |
2024 CHECK_ISOLATE(isolate); | 2026 CHECK_ISOLATE(isolate); |
2025 API_TIMELINE_DURATION; | 2027 API_TIMELINE_DURATION; |
2026 if (Smi::IsValid(value)) { | 2028 if (Smi::IsValid(value)) { |
2027 NOHANDLESCOPE(thread); | 2029 NOHANDLESCOPE(thread); |
2028 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); | 2030 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); |
2029 } | 2031 } |
2030 // Slow path for Mints and Bigints. | 2032 // Slow path for Mints and Bigints. |
2031 DARTSCOPE(thread); | 2033 DARTSCOPE(thread); |
2032 CHECK_CALLBACK_STATE(thread); | 2034 CHECK_CALLBACK_STATE(thread); |
2033 return Api::NewHandle(thread, Integer::New(value)); | 2035 return Api::NewHandle(thread, Integer::New(value)); |
2034 } | 2036 } |
2035 | 2037 |
2036 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 2038 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
2037 DARTSCOPE(Thread::Current()); | 2039 DARTSCOPE(Thread::Current()); |
2038 CHECK_CALLBACK_STATE(T); | 2040 CHECK_CALLBACK_STATE(T); |
2039 API_TIMELINE_DURATION; | 2041 API_TIMELINE_DURATION; |
2040 return Api::NewHandle(T, Integer::NewFromUint64(value)); | 2042 RawInteger* integer = Integer::NewFromUint64(value); |
| 2043 if (integer == Integer::null()) { |
| 2044 return Api::NewError("%s: Cannot create Dart integer from value %" Pu64, |
| 2045 CURRENT_FUNC, value); |
| 2046 } |
| 2047 return Api::NewHandle(T, integer); |
2041 } | 2048 } |
2042 | 2049 |
2043 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2050 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
2044 DARTSCOPE(Thread::Current()); | 2051 DARTSCOPE(Thread::Current()); |
2045 CHECK_CALLBACK_STATE(T); | 2052 CHECK_CALLBACK_STATE(T); |
2046 API_TIMELINE_DURATION; | 2053 API_TIMELINE_DURATION; |
2047 const String& str_obj = String::Handle(Z, String::New(str)); | 2054 const String& str_obj = String::Handle(Z, String::New(str)); |
2048 return Api::NewHandle(T, Integer::New(str_obj)); | 2055 RawInteger* integer = Integer::New(str_obj); |
| 2056 if (integer == Integer::null()) { |
| 2057 return Api::NewError("%s: Cannot create Dart integer from string %s", |
| 2058 CURRENT_FUNC, str); |
| 2059 } |
| 2060 return Api::NewHandle(T, integer); |
2049 } | 2061 } |
2050 | 2062 |
2051 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2063 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
2052 int64_t* value) { | 2064 int64_t* value) { |
2053 // Fast path for Smis. | 2065 // Fast path for Smis. |
2054 Thread* thread = Thread::Current(); | 2066 Thread* thread = Thread::Current(); |
2055 Isolate* isolate = thread->isolate(); | 2067 Isolate* isolate = thread->isolate(); |
2056 CHECK_ISOLATE(isolate); | 2068 CHECK_ISOLATE(isolate); |
2057 if (Api::IsSmi(integer)) { | 2069 if (Api::IsSmi(integer)) { |
2058 *value = Api::SmiValue(integer); | 2070 *value = Api::SmiValue(integer); |
2059 return Api::Success(); | 2071 return Api::Success(); |
2060 } | 2072 } |
2061 // Slow path for Mints and Bigints. | 2073 // Slow path for Mints and Bigints. |
2062 DARTSCOPE(thread); | 2074 DARTSCOPE(thread); |
2063 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2075 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
2064 if (int_obj.IsNull()) { | 2076 if (int_obj.IsNull()) { |
2065 RETURN_TYPE_ERROR(Z, integer, Integer); | 2077 RETURN_TYPE_ERROR(Z, integer, Integer); |
2066 } | 2078 } |
2067 ASSERT(!int_obj.IsSmi()); | 2079 ASSERT(!int_obj.IsSmi()); |
2068 if (int_obj.IsMint()) { | 2080 if (int_obj.IsMint()) { |
2069 *value = int_obj.AsInt64Value(); | 2081 *value = int_obj.AsInt64Value(); |
2070 return Api::Success(); | 2082 return Api::Success(); |
2071 } else { | 2083 } else { |
| 2084 ASSERT(!Bigint::IsDisabled()); |
2072 const Bigint& bigint = Bigint::Cast(int_obj); | 2085 const Bigint& bigint = Bigint::Cast(int_obj); |
2073 if (bigint.FitsIntoInt64()) { | 2086 if (bigint.FitsIntoInt64()) { |
2074 *value = bigint.AsInt64Value(); | 2087 *value = bigint.AsInt64Value(); |
2075 return Api::Success(); | 2088 return Api::Success(); |
2076 } | 2089 } |
2077 } | 2090 } |
2078 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 2091 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
2079 CURRENT_FUNC, int_obj.ToCString()); | 2092 CURRENT_FUNC, int_obj.ToCString()); |
2080 } | 2093 } |
2081 | 2094 |
(...skipping 17 matching lines...) Expand all Loading... |
2099 RETURN_TYPE_ERROR(Z, integer, Integer); | 2112 RETURN_TYPE_ERROR(Z, integer, Integer); |
2100 } | 2113 } |
2101 if (int_obj.IsSmi()) { | 2114 if (int_obj.IsSmi()) { |
2102 ASSERT(int_obj.IsNegative()); | 2115 ASSERT(int_obj.IsNegative()); |
2103 } else if (int_obj.IsMint()) { | 2116 } else if (int_obj.IsMint()) { |
2104 if (!int_obj.IsNegative()) { | 2117 if (!int_obj.IsNegative()) { |
2105 *value = int_obj.AsInt64Value(); | 2118 *value = int_obj.AsInt64Value(); |
2106 return Api::Success(); | 2119 return Api::Success(); |
2107 } | 2120 } |
2108 } else { | 2121 } else { |
| 2122 ASSERT(!Bigint::IsDisabled()); |
2109 const Bigint& bigint = Bigint::Cast(int_obj); | 2123 const Bigint& bigint = Bigint::Cast(int_obj); |
2110 if (bigint.FitsIntoUint64()) { | 2124 if (bigint.FitsIntoUint64()) { |
2111 *value = bigint.AsUint64Value(); | 2125 *value = bigint.AsUint64Value(); |
2112 return Api::Success(); | 2126 return Api::Success(); |
2113 } | 2127 } |
2114 } | 2128 } |
2115 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 2129 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
2116 CURRENT_FUNC, int_obj.ToCString()); | 2130 CURRENT_FUNC, int_obj.ToCString()); |
2117 } | 2131 } |
2118 | 2132 |
(...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6656 #endif | 6670 #endif |
6657 } | 6671 } |
6658 | 6672 |
6659 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { | 6673 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { |
6660 #ifndef PRODUCT | 6674 #ifndef PRODUCT |
6661 Profiler::DumpStackTrace(context); | 6675 Profiler::DumpStackTrace(context); |
6662 #endif | 6676 #endif |
6663 } | 6677 } |
6664 | 6678 |
6665 } // namespace dart | 6679 } // namespace dart |
OLD | NEW |