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

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

Issue 14845021: Cleanups: addressed your comments from https://codereview.chromium.org/14962008/ (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/object.h » ('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 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 if (class_id == kSmiCid || class_id == kMintCid) { 1319 if (class_id == kSmiCid || class_id == kMintCid) {
1320 *fits = true; 1320 *fits = true;
1321 return Api::Success(isolate); 1321 return Api::Success(isolate);
1322 } 1322 }
1323 // Slow path for Mints and Bigints. 1323 // Slow path for Mints and Bigints.
1324 DARTSCOPE(isolate); 1324 DARTSCOPE(isolate);
1325 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 1325 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
1326 if (int_obj.IsNull()) { 1326 if (int_obj.IsNull()) {
1327 RETURN_TYPE_ERROR(isolate, integer, Integer); 1327 RETURN_TYPE_ERROR(isolate, integer, Integer);
1328 } 1328 }
1329 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); 1329 ASSERT(!BigintOperations::FitsIntoInt64(Bigint::Cast(int_obj)));
1330 *fits = false; 1330 *fits = false;
1331 return Api::Success(isolate); 1331 return Api::Success(isolate);
1332 } 1332 }
1333 1333
1334 1334
1335 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, 1335 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
1336 bool* fits) { 1336 bool* fits) {
1337 // Fast path for Smis. 1337 // Fast path for Smis.
1338 Isolate* isolate = Isolate::Current(); 1338 Isolate* isolate = Isolate::Current();
1339 CHECK_ISOLATE(isolate); 1339 CHECK_ISOLATE(isolate);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 1395 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
1396 if (int_obj.IsNull()) { 1396 if (int_obj.IsNull()) {
1397 RETURN_TYPE_ERROR(isolate, integer, Integer); 1397 RETURN_TYPE_ERROR(isolate, integer, Integer);
1398 } 1398 }
1399 ASSERT(!int_obj.IsSmi()); 1399 ASSERT(!int_obj.IsSmi());
1400 if (int_obj.IsMint()) { 1400 if (int_obj.IsMint()) {
1401 *value = int_obj.AsInt64Value(); 1401 *value = int_obj.AsInt64Value();
1402 return Api::Success(isolate); 1402 return Api::Success(isolate);
1403 } else { 1403 } else {
1404 const Bigint& bigint = Bigint::Cast(int_obj); 1404 const Bigint& bigint = Bigint::Cast(int_obj);
1405 if (BigintOperations::FitsIntoMint(bigint)) { 1405 if (BigintOperations::FitsIntoInt64(bigint)) {
1406 *value = BigintOperations::ToMint(bigint); 1406 *value = BigintOperations::ToInt64(bigint);
1407 return Api::Success(isolate); 1407 return Api::Success(isolate);
1408 } 1408 }
1409 } 1409 }
1410 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", 1410 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.",
1411 CURRENT_FUNC, int_obj.ToCString()); 1411 CURRENT_FUNC, int_obj.ToCString());
1412 } 1412 }
1413 1413
1414 1414
1415 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, 1415 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
1416 uint64_t* value) { 1416 uint64_t* value) {
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 } else if (retval.IsMint() || retval.IsBigint()) { 1942 } else if (retval.IsMint() || retval.IsBigint()) {
1943 if (retval.IsMint()) { 1943 if (retval.IsMint()) {
1944 int64_t mint_value = Mint::Cast(retval).value(); 1944 int64_t mint_value = Mint::Cast(retval).value();
1945 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { 1945 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) {
1946 *len = static_cast<intptr_t>(mint_value); 1946 *len = static_cast<intptr_t>(mint_value);
1947 } 1947 }
1948 } else { 1948 } else {
1949 // Check for a non-canonical Mint range value. 1949 // Check for a non-canonical Mint range value.
1950 ASSERT(retval.IsBigint()); 1950 ASSERT(retval.IsBigint());
1951 const Bigint& bigint = Bigint::Handle(); 1951 const Bigint& bigint = Bigint::Handle();
1952 if (BigintOperations::FitsIntoMint(bigint)) { 1952 if (BigintOperations::FitsIntoInt64(bigint)) {
1953 int64_t bigint_value = bigint.AsInt64Value(); 1953 int64_t bigint_value = bigint.AsInt64Value();
1954 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { 1954 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) {
1955 *len = static_cast<intptr_t>(bigint_value); 1955 *len = static_cast<intptr_t>(bigint_value);
1956 } 1956 }
1957 } 1957 }
1958 } 1958 }
1959 return Api::NewError("Length of List object is greater than the " 1959 return Api::NewError("Length of List object is greater than the "
1960 "maximum value that 'len' parameter can hold"); 1960 "maximum value that 'len' parameter can hold");
1961 } else if (retval.IsError()) { 1961 } else if (retval.IsError()) {
1962 return Api::NewHandle(isolate, retval.raw()); 1962 return Api::NewHandle(isolate, retval.raw());
(...skipping 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after
4870 } 4870 }
4871 { 4871 {
4872 NoGCScope no_gc; 4872 NoGCScope no_gc;
4873 RawObject* raw_obj = obj.raw(); 4873 RawObject* raw_obj = obj.raw();
4874 isolate->heap()->SetPeer(raw_obj, peer); 4874 isolate->heap()->SetPeer(raw_obj, peer);
4875 } 4875 }
4876 return Api::Success(isolate); 4876 return Api::Success(isolate);
4877 } 4877 }
4878 4878
4879 } // namespace dart 4879 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698