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 "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2024 NOHANDLESCOPE(isolate); | 2024 NOHANDLESCOPE(isolate); |
2025 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); | 2025 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); |
2026 } | 2026 } |
2027 // Slow path for Mints and Bigints. | 2027 // Slow path for Mints and Bigints. |
2028 DARTSCOPE(isolate); | 2028 DARTSCOPE(isolate); |
2029 CHECK_CALLBACK_STATE(isolate); | 2029 CHECK_CALLBACK_STATE(isolate); |
2030 return Api::NewHandle(isolate, Integer::New(value)); | 2030 return Api::NewHandle(isolate, Integer::New(value)); |
2031 } | 2031 } |
2032 | 2032 |
2033 | 2033 |
| 2034 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
| 2035 Isolate* isolate = Isolate::Current(); |
| 2036 DARTSCOPE(isolate); |
| 2037 CHECK_CALLBACK_STATE(isolate); |
| 2038 return Api::NewHandle(isolate, Integer::NewFromUint64(value)); |
| 2039 } |
| 2040 |
| 2041 |
2034 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2042 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
2035 Isolate* isolate = Isolate::Current(); | 2043 Isolate* isolate = Isolate::Current(); |
2036 DARTSCOPE(isolate); | 2044 DARTSCOPE(isolate); |
2037 CHECK_CALLBACK_STATE(isolate); | 2045 CHECK_CALLBACK_STATE(isolate); |
2038 const String& str_obj = String::Handle(isolate, String::New(str)); | 2046 const String& str_obj = String::Handle(isolate, String::New(str)); |
2039 return Api::NewHandle(isolate, Integer::New(str_obj)); | 2047 return Api::NewHandle(isolate, Integer::New(str_obj)); |
2040 } | 2048 } |
2041 | 2049 |
2042 | 2050 |
2043 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2051 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2082 *value = smi_value; | 2090 *value = smi_value; |
2083 return Api::Success(); | 2091 return Api::Success(); |
2084 } | 2092 } |
2085 } | 2093 } |
2086 // Slow path for Mints and Bigints. | 2094 // Slow path for Mints and Bigints. |
2087 DARTSCOPE(isolate); | 2095 DARTSCOPE(isolate); |
2088 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 2096 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
2089 if (int_obj.IsNull()) { | 2097 if (int_obj.IsNull()) { |
2090 RETURN_TYPE_ERROR(isolate, integer, Integer); | 2098 RETURN_TYPE_ERROR(isolate, integer, Integer); |
2091 } | 2099 } |
2092 ASSERT(!int_obj.IsSmi()); | 2100 if (int_obj.IsSmi()) { |
2093 if (int_obj.IsMint() && !int_obj.IsNegative()) { | 2101 ASSERT(int_obj.IsNegative()); |
| 2102 } else if (int_obj.IsMint() && !int_obj.IsNegative()) { |
2094 *value = int_obj.AsInt64Value(); | 2103 *value = int_obj.AsInt64Value(); |
2095 return Api::Success(); | 2104 return Api::Success(); |
2096 } else { | 2105 } else { |
2097 const Bigint& bigint = Bigint::Cast(int_obj); | 2106 const Bigint& bigint = Bigint::Cast(int_obj); |
2098 if (bigint.FitsIntoUint64()) { | 2107 if (bigint.FitsIntoUint64()) { |
2099 *value = bigint.AsUint64Value(); | 2108 *value = bigint.AsUint64Value(); |
2100 return Api::Success(); | 2109 return Api::Success(); |
2101 } | 2110 } |
2102 } | 2111 } |
2103 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 2112 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
(...skipping 3441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5545 | 5554 |
5546 | 5555 |
5547 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5556 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5548 const char* name, | 5557 const char* name, |
5549 Dart_ServiceRequestCallback callback, | 5558 Dart_ServiceRequestCallback callback, |
5550 void* user_data) { | 5559 void* user_data) { |
5551 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5560 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5552 } | 5561 } |
5553 | 5562 |
5554 } // namespace dart | 5563 } // namespace dart |
OLD | NEW |