| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 1269 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 1270 bool* fits) { | 1270 bool* fits) { |
| 1271 // Fast path for Smis and Mints. | 1271 // Fast path for Smis and Mints. |
| 1272 Isolate* isolate = Isolate::Current(); | 1272 Isolate* isolate = Isolate::Current(); |
| 1273 CHECK_ISOLATE(isolate); | 1273 CHECK_ISOLATE(isolate); |
| 1274 intptr_t class_id = Api::ClassId(integer); | 1274 intptr_t class_id = Api::ClassId(integer); |
| 1275 if (class_id == kSmiCid || class_id == kMintCid) { | 1275 if (class_id == kSmiCid || class_id == kMintCid) { |
| 1276 *fits = true; | 1276 *fits = true; |
| 1277 return Api::Success(isolate); | 1277 return Api::Success(isolate); |
| 1278 } | 1278 } |
| 1279 | 1279 // Slow path for Mints and Bigints. |
| 1280 DARTSCOPE_NOCHECKS(isolate); | 1280 DARTSCOPE_NOCHECKS(isolate); |
| 1281 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1281 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1282 if (int_obj.IsNull()) { | 1282 if (int_obj.IsNull()) { |
| 1283 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1283 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1284 } | 1284 } |
| 1285 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); | 1285 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); |
| 1286 *fits = false; | 1286 *fits = false; |
| 1287 return Api::Success(isolate); | 1287 return Api::Success(isolate); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 | 1290 |
| 1291 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 1291 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
| 1292 bool* fits) { | 1292 bool* fits) { |
| 1293 // Fast path for Smis. | 1293 // Fast path for Smis. |
| 1294 Isolate* isolate = Isolate::Current(); | 1294 Isolate* isolate = Isolate::Current(); |
| 1295 CHECK_ISOLATE(isolate); | 1295 CHECK_ISOLATE(isolate); |
| 1296 if (Api::IsSmi(integer)) { | 1296 if (Api::IsSmi(integer)) { |
| 1297 *fits = (Api::SmiValue(integer) >= 0); | 1297 *fits = (Api::SmiValue(integer) >= 0); |
| 1298 return Api::Success(isolate); | 1298 return Api::Success(isolate); |
| 1299 } | 1299 } |
| 1300 | 1300 // Slow path for Mints and Bigints. |
| 1301 DARTSCOPE_NOCHECKS(isolate); | 1301 DARTSCOPE_NOCHECKS(isolate); |
| 1302 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1302 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1303 if (int_obj.IsNull()) { | 1303 if (int_obj.IsNull()) { |
| 1304 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1304 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1305 } | 1305 } |
| 1306 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1306 ASSERT(!int_obj.IsSmi()); |
| 1307 if (int_obj.IsMint()) { |
| 1307 *fits = !int_obj.IsNegative(); | 1308 *fits = !int_obj.IsNegative(); |
| 1308 } else { | 1309 } else { |
| 1309 *fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj)); | 1310 *fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj)); |
| 1310 } | 1311 } |
| 1311 return Api::Success(isolate); | 1312 return Api::Success(isolate); |
| 1312 } | 1313 } |
| 1313 | 1314 |
| 1314 | 1315 |
| 1315 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 1316 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
| 1316 // Fast path for Smis. | 1317 // Fast path for Smis. |
| 1317 Isolate* isolate = Isolate::Current(); | 1318 Isolate* isolate = Isolate::Current(); |
| 1318 CHECK_ISOLATE(isolate); | 1319 CHECK_ISOLATE(isolate); |
| 1319 if (Smi::IsValid64(value)) { | 1320 if (Smi::IsValid64(value)) { |
| 1320 NOHANDLESCOPE(isolate); | 1321 NOHANDLESCOPE(isolate); |
| 1321 return Api::NewHandle(isolate, Smi::New(value)); | 1322 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); |
| 1322 } | 1323 } |
| 1323 | 1324 // Slow path for Mints and Bigints. |
| 1324 DARTSCOPE_NOCHECKS(isolate); | 1325 DARTSCOPE_NOCHECKS(isolate); |
| 1325 return Api::NewHandle(isolate, Integer::New(value)); | 1326 return Api::NewHandle(isolate, Integer::New(value)); |
| 1326 } | 1327 } |
| 1327 | 1328 |
| 1328 | 1329 |
| 1329 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 1330 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
| 1330 Isolate* isolate = Isolate::Current(); | 1331 Isolate* isolate = Isolate::Current(); |
| 1331 DARTSCOPE(isolate); | 1332 DARTSCOPE(isolate); |
| 1332 const String& str_obj = String::Handle(isolate, String::New(str)); | 1333 const String& str_obj = String::Handle(isolate, String::New(str)); |
| 1333 return Api::NewHandle(isolate, Integer::New(str_obj)); | 1334 return Api::NewHandle(isolate, Integer::New(str_obj)); |
| 1334 } | 1335 } |
| 1335 | 1336 |
| 1336 | 1337 |
| 1337 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 1338 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
| 1338 int64_t* value) { | 1339 int64_t* value) { |
| 1339 // Fast path for Smis. | 1340 // Fast path for Smis. |
| 1340 Isolate* isolate = Isolate::Current(); | 1341 Isolate* isolate = Isolate::Current(); |
| 1341 CHECK_ISOLATE(isolate); | 1342 CHECK_ISOLATE(isolate); |
| 1342 if (Api::IsSmi(integer)) { | 1343 if (Api::IsSmi(integer)) { |
| 1343 *value = Api::SmiValue(integer); | 1344 *value = Api::SmiValue(integer); |
| 1344 return Api::Success(isolate); | 1345 return Api::Success(isolate); |
| 1345 } | 1346 } |
| 1346 | 1347 // Slow path for Mints and Bigints. |
| 1347 DARTSCOPE_NOCHECKS(isolate); | 1348 DARTSCOPE_NOCHECKS(isolate); |
| 1348 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1349 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1349 if (int_obj.IsNull()) { | 1350 if (int_obj.IsNull()) { |
| 1350 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1351 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1351 } | 1352 } |
| 1352 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1353 ASSERT(!int_obj.IsSmi()); |
| 1354 if (int_obj.IsMint()) { |
| 1353 *value = int_obj.AsInt64Value(); | 1355 *value = int_obj.AsInt64Value(); |
| 1354 return Api::Success(isolate); | 1356 return Api::Success(isolate); |
| 1355 } else { | 1357 } else { |
| 1356 const Bigint& bigint = Bigint::Cast(int_obj); | 1358 const Bigint& bigint = Bigint::Cast(int_obj); |
| 1357 if (BigintOperations::FitsIntoMint(bigint)) { | 1359 if (BigintOperations::FitsIntoMint(bigint)) { |
| 1358 *value = BigintOperations::ToMint(bigint); | 1360 *value = BigintOperations::ToMint(bigint); |
| 1359 return Api::Success(isolate); | 1361 return Api::Success(isolate); |
| 1360 } | 1362 } |
| 1361 } | 1363 } |
| 1362 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 1364 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
| 1363 CURRENT_FUNC, int_obj.ToCString()); | 1365 CURRENT_FUNC, int_obj.ToCString()); |
| 1364 } | 1366 } |
| 1365 | 1367 |
| 1366 | 1368 |
| 1367 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, | 1369 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
| 1368 uint64_t* value) { | 1370 uint64_t* value) { |
| 1369 // Fast path for Smis. | 1371 // Fast path for Smis. |
| 1370 Isolate* isolate = Isolate::Current(); | 1372 Isolate* isolate = Isolate::Current(); |
| 1371 CHECK_ISOLATE(isolate); | 1373 CHECK_ISOLATE(isolate); |
| 1372 if (Api::IsSmi(integer)) { | 1374 if (Api::IsSmi(integer)) { |
| 1373 intptr_t smi_value = Api::SmiValue(integer); | 1375 intptr_t smi_value = Api::SmiValue(integer); |
| 1374 if (smi_value >= 0) { | 1376 if (smi_value >= 0) { |
| 1375 *value = smi_value; | 1377 *value = smi_value; |
| 1376 return Api::Success(isolate); | 1378 return Api::Success(isolate); |
| 1377 } | 1379 } |
| 1378 } | 1380 } |
| 1379 | 1381 // Slow path for Mints and Bigints. |
| 1380 DARTSCOPE_NOCHECKS(isolate); | 1382 DARTSCOPE_NOCHECKS(isolate); |
| 1381 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1383 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1382 if (int_obj.IsNull()) { | 1384 if (int_obj.IsNull()) { |
| 1383 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1385 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1384 } | 1386 } |
| 1385 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1387 ASSERT(!int_obj.IsSmi()); |
| 1386 if (!int_obj.IsNegative()) { | 1388 if (int_obj.IsMint() && !int_obj.IsNegative()) { |
| 1387 *value = int_obj.AsInt64Value(); | 1389 *value = int_obj.AsInt64Value(); |
| 1388 return Api::Success(isolate); | 1390 return Api::Success(isolate); |
| 1389 } | |
| 1390 } else { | 1391 } else { |
| 1391 const Bigint& bigint = Bigint::Cast(int_obj); | 1392 const Bigint& bigint = Bigint::Cast(int_obj); |
| 1392 if (BigintOperations::FitsIntoUint64(bigint)) { | 1393 if (BigintOperations::FitsIntoUint64(bigint)) { |
| 1393 *value = BigintOperations::ToUint64(bigint); | 1394 *value = BigintOperations::ToUint64(bigint); |
| 1394 return Api::Success(isolate); | 1395 return Api::Success(isolate); |
| 1395 } | 1396 } |
| 1396 } | 1397 } |
| 1397 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 1398 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
| 1398 CURRENT_FUNC, int_obj.ToCString()); | 1399 CURRENT_FUNC, int_obj.ToCString()); |
| 1399 } | 1400 } |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1832 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1833 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
| 1833 if (function.IsNull()) { | 1834 if (function.IsNull()) { |
| 1834 return Api::NewError("List object does not have a 'length' field."); | 1835 return Api::NewError("List object does not have a 'length' field."); |
| 1835 } | 1836 } |
| 1836 | 1837 |
| 1837 GrowableArray<const Object*> args(0); | 1838 GrowableArray<const Object*> args(0); |
| 1838 const Array& kNoArgumentNames = Array::Handle(isolate); | 1839 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1839 const Object& retval = Object::Handle( | 1840 const Object& retval = Object::Handle( |
| 1840 isolate, | 1841 isolate, |
| 1841 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1842 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
| 1842 if (retval.IsSmi() || retval.IsMint()) { | 1843 if (retval.IsSmi()) { |
| 1843 *len = Integer::Cast(retval).AsInt64Value(); | 1844 *len = Smi::Cast(retval).Value(); |
| 1844 return Api::Success(isolate); | 1845 return Api::Success(isolate); |
| 1845 } else if (retval.IsBigint()) { | 1846 } else if (retval.IsMint() || retval.IsBigint()) { |
| 1846 const Bigint& bigint = Bigint::Cast(retval); | 1847 if (retval.IsMint()) { |
| 1847 if (BigintOperations::FitsIntoMint(bigint)) { | 1848 int64_t mint_value = Mint::Cast(retval).value(); |
| 1848 *len = BigintOperations::ToMint(bigint); | 1849 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { |
| 1849 return Api::Success(isolate); | 1850 *len = static_cast<intptr_t>(mint_value); |
| 1851 } |
| 1850 } else { | 1852 } else { |
| 1851 return Api::NewError("Length of List object is greater than the " | 1853 // Check for a non-canonical Mint range value. |
| 1852 "maximum value that 'len' parameter can hold"); | 1854 ASSERT(retval.IsBigint()); |
| 1855 const Bigint& bigint = Bigint::Handle(); |
| 1856 if (BigintOperations::FitsIntoMint(bigint)) { |
| 1857 int64_t bigint_value = bigint.AsInt64Value(); |
| 1858 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { |
| 1859 *len = static_cast<intptr_t>(bigint_value); |
| 1860 } |
| 1861 } |
| 1853 } | 1862 } |
| 1863 return Api::NewError("Length of List object is greater than the " |
| 1864 "maximum value that 'len' parameter can hold"); |
| 1854 } else if (retval.IsError()) { | 1865 } else if (retval.IsError()) { |
| 1855 return Api::NewHandle(isolate, retval.raw()); | 1866 return Api::NewHandle(isolate, retval.raw()); |
| 1856 } else { | 1867 } else { |
| 1857 return Api::NewError("Length of List object is not an integer"); | 1868 return Api::NewError("Length of List object is not an integer"); |
| 1858 } | 1869 } |
| 1859 } | 1870 } |
| 1860 | 1871 |
| 1861 | 1872 |
| 1862 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ | 1873 #define GET_LIST_ELEMENT(isolate, type, obj, index) \ |
| 1863 const type& array_obj = type::Cast(obj); \ | 1874 const type& array_obj = type::Cast(obj); \ |
| (...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4438 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4449 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
| 4439 Dart::set_perf_events_writer(function); | 4450 Dart::set_perf_events_writer(function); |
| 4440 } | 4451 } |
| 4441 | 4452 |
| 4442 | 4453 |
| 4443 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4454 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
| 4444 Dart::set_flow_graph_writer(function); | 4455 Dart::set_flow_graph_writer(function); |
| 4445 } | 4456 } |
| 4446 | 4457 |
| 4447 } // namespace dart | 4458 } // namespace dart |
| OLD | NEW |