Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 2977143002: Revert "Option to truncate integers to 64 bits, part 2" (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/bigint_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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());
273 const Bigint& bigint = Bigint::Cast(obj); 272 const Bigint& bigint = Bigint::Cast(obj);
274 if (bigint.FitsIntoUint64()) { 273 if (bigint.FitsIntoUint64()) {
275 *value = bigint.AsUint64Value(); 274 *value = bigint.AsUint64Value();
276 return true; 275 return true;
277 } 276 }
278 } 277 }
279 return false; 278 return false;
280 } 279 }
281 280
282 static bool GetNativeDoubleArgument(NativeArguments* arguments, 281 static bool GetNativeDoubleArgument(NativeArguments* arguments,
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 // Slow path for Mints and Bigints. 2005 // Slow path for Mints and Bigints.
2007 DARTSCOPE(thread); 2006 DARTSCOPE(thread);
2008 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 2007 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2009 if (int_obj.IsNull()) { 2008 if (int_obj.IsNull()) {
2010 RETURN_TYPE_ERROR(Z, integer, Integer); 2009 RETURN_TYPE_ERROR(Z, integer, Integer);
2011 } 2010 }
2012 ASSERT(!int_obj.IsSmi()); 2011 ASSERT(!int_obj.IsSmi());
2013 if (int_obj.IsMint()) { 2012 if (int_obj.IsMint()) {
2014 *fits = !int_obj.IsNegative(); 2013 *fits = !int_obj.IsNegative();
2015 } else { 2014 } else {
2016 ASSERT(!Bigint::IsDisabled());
2017 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); 2015 *fits = Bigint::Cast(int_obj).FitsIntoUint64();
2018 } 2016 }
2019 return Api::Success(); 2017 return Api::Success();
2020 } 2018 }
2021 2019
2022 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { 2020 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
2023 // Fast path for Smis. 2021 // Fast path for Smis.
2024 Thread* thread = Thread::Current(); 2022 Thread* thread = Thread::Current();
2025 Isolate* isolate = thread->isolate(); 2023 Isolate* isolate = thread->isolate();
2026 CHECK_ISOLATE(isolate); 2024 CHECK_ISOLATE(isolate);
2027 API_TIMELINE_DURATION; 2025 API_TIMELINE_DURATION;
2028 if (Smi::IsValid(value)) { 2026 if (Smi::IsValid(value)) {
2029 NOHANDLESCOPE(thread); 2027 NOHANDLESCOPE(thread);
2030 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); 2028 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value)));
2031 } 2029 }
2032 // Slow path for Mints and Bigints. 2030 // Slow path for Mints and Bigints.
2033 DARTSCOPE(thread); 2031 DARTSCOPE(thread);
2034 CHECK_CALLBACK_STATE(thread); 2032 CHECK_CALLBACK_STATE(thread);
2035 return Api::NewHandle(thread, Integer::New(value)); 2033 return Api::NewHandle(thread, Integer::New(value));
2036 } 2034 }
2037 2035
2038 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { 2036 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) {
2039 DARTSCOPE(Thread::Current()); 2037 DARTSCOPE(Thread::Current());
2040 CHECK_CALLBACK_STATE(T); 2038 CHECK_CALLBACK_STATE(T);
2041 API_TIMELINE_DURATION; 2039 API_TIMELINE_DURATION;
2042 RawInteger* integer = Integer::NewFromUint64(value); 2040 return Api::NewHandle(T, 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);
2048 } 2041 }
2049 2042
2050 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { 2043 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
2051 DARTSCOPE(Thread::Current()); 2044 DARTSCOPE(Thread::Current());
2052 CHECK_CALLBACK_STATE(T); 2045 CHECK_CALLBACK_STATE(T);
2053 API_TIMELINE_DURATION; 2046 API_TIMELINE_DURATION;
2054 const String& str_obj = String::Handle(Z, String::New(str)); 2047 const String& str_obj = String::Handle(Z, String::New(str));
2055 RawInteger* integer = Integer::New(str_obj); 2048 return Api::NewHandle(T, 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);
2061 } 2049 }
2062 2050
2063 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, 2051 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
2064 int64_t* value) { 2052 int64_t* value) {
2065 // Fast path for Smis. 2053 // Fast path for Smis.
2066 Thread* thread = Thread::Current(); 2054 Thread* thread = Thread::Current();
2067 Isolate* isolate = thread->isolate(); 2055 Isolate* isolate = thread->isolate();
2068 CHECK_ISOLATE(isolate); 2056 CHECK_ISOLATE(isolate);
2069 if (Api::IsSmi(integer)) { 2057 if (Api::IsSmi(integer)) {
2070 *value = Api::SmiValue(integer); 2058 *value = Api::SmiValue(integer);
2071 return Api::Success(); 2059 return Api::Success();
2072 } 2060 }
2073 // Slow path for Mints and Bigints. 2061 // Slow path for Mints and Bigints.
2074 DARTSCOPE(thread); 2062 DARTSCOPE(thread);
2075 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); 2063 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer);
2076 if (int_obj.IsNull()) { 2064 if (int_obj.IsNull()) {
2077 RETURN_TYPE_ERROR(Z, integer, Integer); 2065 RETURN_TYPE_ERROR(Z, integer, Integer);
2078 } 2066 }
2079 ASSERT(!int_obj.IsSmi()); 2067 ASSERT(!int_obj.IsSmi());
2080 if (int_obj.IsMint()) { 2068 if (int_obj.IsMint()) {
2081 *value = int_obj.AsInt64Value(); 2069 *value = int_obj.AsInt64Value();
2082 return Api::Success(); 2070 return Api::Success();
2083 } else { 2071 } else {
2084 ASSERT(!Bigint::IsDisabled());
2085 const Bigint& bigint = Bigint::Cast(int_obj); 2072 const Bigint& bigint = Bigint::Cast(int_obj);
2086 if (bigint.FitsIntoInt64()) { 2073 if (bigint.FitsIntoInt64()) {
2087 *value = bigint.AsInt64Value(); 2074 *value = bigint.AsInt64Value();
2088 return Api::Success(); 2075 return Api::Success();
2089 } 2076 }
2090 } 2077 }
2091 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", 2078 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.",
2092 CURRENT_FUNC, int_obj.ToCString()); 2079 CURRENT_FUNC, int_obj.ToCString());
2093 } 2080 }
2094 2081
(...skipping 17 matching lines...) Expand all
2112 RETURN_TYPE_ERROR(Z, integer, Integer); 2099 RETURN_TYPE_ERROR(Z, integer, Integer);
2113 } 2100 }
2114 if (int_obj.IsSmi()) { 2101 if (int_obj.IsSmi()) {
2115 ASSERT(int_obj.IsNegative()); 2102 ASSERT(int_obj.IsNegative());
2116 } else if (int_obj.IsMint()) { 2103 } else if (int_obj.IsMint()) {
2117 if (!int_obj.IsNegative()) { 2104 if (!int_obj.IsNegative()) {
2118 *value = int_obj.AsInt64Value(); 2105 *value = int_obj.AsInt64Value();
2119 return Api::Success(); 2106 return Api::Success();
2120 } 2107 }
2121 } else { 2108 } else {
2122 ASSERT(!Bigint::IsDisabled());
2123 const Bigint& bigint = Bigint::Cast(int_obj); 2109 const Bigint& bigint = Bigint::Cast(int_obj);
2124 if (bigint.FitsIntoUint64()) { 2110 if (bigint.FitsIntoUint64()) {
2125 *value = bigint.AsUint64Value(); 2111 *value = bigint.AsUint64Value();
2126 return Api::Success(); 2112 return Api::Success();
2127 } 2113 }
2128 } 2114 }
2129 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", 2115 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.",
2130 CURRENT_FUNC, int_obj.ToCString()); 2116 CURRENT_FUNC, int_obj.ToCString());
2131 } 2117 }
2132 2118
(...skipping 4537 matching lines...) Expand 10 before | Expand all | Expand 10 after
6670 #endif 6656 #endif
6671 } 6657 }
6672 6658
6673 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { 6659 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) {
6674 #ifndef PRODUCT 6660 #ifndef PRODUCT
6675 Profiler::DumpStackTrace(context); 6661 Profiler::DumpStackTrace(context);
6676 #endif 6662 #endif
6677 } 6663 }
6678 6664
6679 } // namespace dart 6665 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bigint_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698