| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); | 252 ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); |
| 253 api_native_key_ = Thread::CreateThreadLocal(); | 253 api_native_key_ = Thread::CreateThreadLocal(); |
| 254 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); | 254 ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); |
| 255 } | 255 } |
| 256 | 256 |
| 257 | 257 |
| 258 // --- Handles --- | 258 // --- Handles --- |
| 259 | 259 |
| 260 | 260 |
| 261 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 261 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 262 return RawObject::IsErrorClassIndex(Api::ClassIndex(handle)); | 262 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 | 265 |
| 266 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 266 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 267 Isolate* isolate = Isolate::Current(); | 267 Isolate* isolate = Isolate::Current(); |
| 268 DARTSCOPE(isolate); | 268 DARTSCOPE(isolate); |
| 269 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 269 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 270 if (obj.IsError()) { | 270 if (obj.IsError()) { |
| 271 Error& error = Error::Handle(isolate); | 271 Error& error = Error::Handle(isolate); |
| 272 error ^= obj.raw(); | 272 error ^= obj.raw(); |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1040 |
| 1041 | 1041 |
| 1042 DART_EXPORT Dart_Handle Dart_Null() { | 1042 DART_EXPORT Dart_Handle Dart_Null() { |
| 1043 Isolate* isolate = Isolate::Current(); | 1043 Isolate* isolate = Isolate::Current(); |
| 1044 CHECK_ISOLATE_SCOPE(isolate); | 1044 CHECK_ISOLATE_SCOPE(isolate); |
| 1045 return Api::Null(isolate); | 1045 return Api::Null(isolate); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 | 1048 |
| 1049 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1049 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
| 1050 return Api::ClassIndex(object) == kNullClassIndex; | 1050 return Api::ClassId(object) == kNullClassId; |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 | 1053 |
| 1054 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1054 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
| 1055 bool* value) { | 1055 bool* value) { |
| 1056 Isolate* isolate = Isolate::Current(); | 1056 Isolate* isolate = Isolate::Current(); |
| 1057 DARTSCOPE(isolate); | 1057 DARTSCOPE(isolate); |
| 1058 const Instance& expected = | 1058 const Instance& expected = |
| 1059 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); | 1059 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); |
| 1060 const Instance& actual = | 1060 const Instance& actual = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. | 1110 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. |
| 1111 return Api::Success(isolate); | 1111 return Api::Success(isolate); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 | 1114 |
| 1115 // --- Numbers ---- | 1115 // --- Numbers ---- |
| 1116 | 1116 |
| 1117 | 1117 |
| 1118 // TODO(iposva): The argument should be an instance. | 1118 // TODO(iposva): The argument should be an instance. |
| 1119 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1119 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
| 1120 return RawObject::IsNumberClassIndex(Api::ClassIndex(object)); | 1120 return RawObject::IsNumberClassId(Api::ClassId(object)); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 | 1123 |
| 1124 // --- Integers ---- | 1124 // --- Integers ---- |
| 1125 | 1125 |
| 1126 | 1126 |
| 1127 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1127 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 1128 return RawObject::IsIntegerClassIndex(Api::ClassIndex(object)); | 1128 return RawObject::IsIntegerClassId(Api::ClassId(object)); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 | 1131 |
| 1132 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 1132 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 1133 bool* fits) { | 1133 bool* fits) { |
| 1134 // Fast path for Smis and Mints. | 1134 // Fast path for Smis and Mints. |
| 1135 Isolate* isolate = Isolate::Current(); | 1135 Isolate* isolate = Isolate::Current(); |
| 1136 CHECK_ISOLATE(isolate); | 1136 CHECK_ISOLATE(isolate); |
| 1137 intptr_t class_index = Api::ClassIndex(integer); | 1137 intptr_t class_index = Api::ClassId(integer); |
| 1138 if (class_index == kSmi || class_index == kMint) { | 1138 if (class_index == kSmi || class_index == kMint) { |
| 1139 *fits = true; | 1139 *fits = true; |
| 1140 return Api::Success(isolate); | 1140 return Api::Success(isolate); |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 DARTSCOPE_NOCHECKS(isolate); | 1143 DARTSCOPE_NOCHECKS(isolate); |
| 1144 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1144 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1145 if (int_obj.IsNull()) { | 1145 if (int_obj.IsNull()) { |
| 1146 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1146 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1147 } | 1147 } |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 | 1311 |
| 1312 | 1312 |
| 1313 DART_EXPORT Dart_Handle Dart_False() { | 1313 DART_EXPORT Dart_Handle Dart_False() { |
| 1314 Isolate* isolate = Isolate::Current(); | 1314 Isolate* isolate = Isolate::Current(); |
| 1315 CHECK_ISOLATE_SCOPE(isolate); | 1315 CHECK_ISOLATE_SCOPE(isolate); |
| 1316 return Api::False(isolate); | 1316 return Api::False(isolate); |
| 1317 } | 1317 } |
| 1318 | 1318 |
| 1319 | 1319 |
| 1320 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 1320 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
| 1321 return Api::ClassIndex(object) == kBool; | 1321 return Api::ClassId(object) == kBool; |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 | 1324 |
| 1325 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { | 1325 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { |
| 1326 Isolate* isolate = Isolate::Current(); | 1326 Isolate* isolate = Isolate::Current(); |
| 1327 CHECK_ISOLATE_SCOPE(isolate); | 1327 CHECK_ISOLATE_SCOPE(isolate); |
| 1328 return value ? Api::True(isolate) : Api::False(isolate); | 1328 return value ? Api::True(isolate) : Api::False(isolate); |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 | 1331 |
| 1332 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, | 1332 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, |
| 1333 bool* value) { | 1333 bool* value) { |
| 1334 Isolate* isolate = Isolate::Current(); | 1334 Isolate* isolate = Isolate::Current(); |
| 1335 DARTSCOPE(isolate); | 1335 DARTSCOPE(isolate); |
| 1336 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); | 1336 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); |
| 1337 if (obj.IsNull()) { | 1337 if (obj.IsNull()) { |
| 1338 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); | 1338 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); |
| 1339 } | 1339 } |
| 1340 *value = obj.value(); | 1340 *value = obj.value(); |
| 1341 return Api::Success(isolate); | 1341 return Api::Success(isolate); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 | 1344 |
| 1345 // --- Doubles --- | 1345 // --- Doubles --- |
| 1346 | 1346 |
| 1347 | 1347 |
| 1348 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1348 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
| 1349 return Api::ClassIndex(object) == kDouble; | 1349 return Api::ClassId(object) == kDouble; |
| 1350 } | 1350 } |
| 1351 | 1351 |
| 1352 | 1352 |
| 1353 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 1353 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
| 1354 Isolate* isolate = Isolate::Current(); | 1354 Isolate* isolate = Isolate::Current(); |
| 1355 DARTSCOPE(isolate); | 1355 DARTSCOPE(isolate); |
| 1356 return Api::NewHandle(isolate, Double::New(value)); | 1356 return Api::NewHandle(isolate, Double::New(value)); |
| 1357 } | 1357 } |
| 1358 | 1358 |
| 1359 | 1359 |
| 1360 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 1360 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
| 1361 double* value) { | 1361 double* value) { |
| 1362 Isolate* isolate = Isolate::Current(); | 1362 Isolate* isolate = Isolate::Current(); |
| 1363 DARTSCOPE(isolate); | 1363 DARTSCOPE(isolate); |
| 1364 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); | 1364 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); |
| 1365 if (obj.IsNull()) { | 1365 if (obj.IsNull()) { |
| 1366 RETURN_TYPE_ERROR(isolate, double_obj, Double); | 1366 RETURN_TYPE_ERROR(isolate, double_obj, Double); |
| 1367 } | 1367 } |
| 1368 *value = obj.value(); | 1368 *value = obj.value(); |
| 1369 return Api::Success(isolate); | 1369 return Api::Success(isolate); |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 | 1372 |
| 1373 // --- Strings --- | 1373 // --- Strings --- |
| 1374 | 1374 |
| 1375 | 1375 |
| 1376 DART_EXPORT bool Dart_IsString(Dart_Handle object) { | 1376 DART_EXPORT bool Dart_IsString(Dart_Handle object) { |
| 1377 return RawObject::IsStringClassIndex(Api::ClassIndex(object)); | 1377 return RawObject::IsStringClassId(Api::ClassId(object)); |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 | 1380 |
| 1381 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { | 1381 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { |
| 1382 return RawObject::IsOneByteStringClassIndex(Api::ClassIndex(object)); | 1382 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); |
| 1383 } | 1383 } |
| 1384 | 1384 |
| 1385 | 1385 |
| 1386 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { | 1386 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { |
| 1387 return RawObject::IsTwoByteStringClassIndex(Api::ClassIndex(object)); | 1387 return RawObject::IsTwoByteStringClassId(Api::ClassId(object)); |
| 1388 } | 1388 } |
| 1389 | 1389 |
| 1390 | 1390 |
| 1391 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 1391 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
| 1392 Isolate* isolate = Isolate::Current(); | 1392 Isolate* isolate = Isolate::Current(); |
| 1393 DARTSCOPE(isolate); | 1393 DARTSCOPE(isolate); |
| 1394 const String& str_obj = Api::UnwrapStringHandle(isolate, str); | 1394 const String& str_obj = Api::UnwrapStringHandle(isolate, str); |
| 1395 if (str_obj.IsNull()) { | 1395 if (str_obj.IsNull()) { |
| 1396 RETURN_TYPE_ERROR(isolate, str, String); | 1396 RETURN_TYPE_ERROR(isolate, str, String); |
| 1397 } | 1397 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1425 | 1425 |
| 1426 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1426 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
| 1427 intptr_t length) { | 1427 intptr_t length) { |
| 1428 Isolate* isolate = Isolate::Current(); | 1428 Isolate* isolate = Isolate::Current(); |
| 1429 DARTSCOPE(isolate); | 1429 DARTSCOPE(isolate); |
| 1430 return Api::NewHandle(isolate, String::New(codepoints, length)); | 1430 return Api::NewHandle(isolate, String::New(codepoints, length)); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 | 1433 |
| 1434 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1434 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1435 return RawObject::IsExternalStringClassIndex(Api::ClassIndex(object)); | 1435 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 1436 } | 1436 } |
| 1437 | 1437 |
| 1438 | 1438 |
| 1439 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1439 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| 1440 void** peer) { | 1440 void** peer) { |
| 1441 Isolate* isolate = Isolate::Current(); | 1441 Isolate* isolate = Isolate::Current(); |
| 1442 DARTSCOPE(isolate); | 1442 DARTSCOPE(isolate); |
| 1443 const String& str = Api::UnwrapStringHandle(isolate, object); | 1443 const String& str = Api::UnwrapStringHandle(isolate, object); |
| 1444 if (str.IsNull()) { | 1444 if (str.IsNull()) { |
| 1445 RETURN_TYPE_ERROR(isolate, object, String); | 1445 RETURN_TYPE_ERROR(isolate, object, String); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 &malformed_type_error)) { | 1641 &malformed_type_error)) { |
| 1642 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 1642 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
| 1643 return instance.raw(); | 1643 return instance.raw(); |
| 1644 } | 1644 } |
| 1645 } | 1645 } |
| 1646 return Instance::null(); | 1646 return Instance::null(); |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 | 1649 |
| 1650 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1650 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 1651 if (RawObject::IsBuiltinListClassIndex(Api::ClassIndex(object))) { | 1651 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { |
| 1652 return true; | 1652 return true; |
| 1653 } | 1653 } |
| 1654 | 1654 |
| 1655 Isolate* isolate = Isolate::Current(); | 1655 Isolate* isolate = Isolate::Current(); |
| 1656 DARTSCOPE(isolate); | 1656 DARTSCOPE(isolate); |
| 1657 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1657 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1658 return GetListInstance(isolate, obj) != Instance::null(); | 1658 return GetListInstance(isolate, obj) != Instance::null(); |
| 1659 } | 1659 } |
| 1660 | 1660 |
| 1661 | 1661 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 } | 1993 } |
| 1994 } | 1994 } |
| 1995 return Api::NewError("Object does not implement the 'List' interface"); | 1995 return Api::NewError("Object does not implement the 'List' interface"); |
| 1996 } | 1996 } |
| 1997 | 1997 |
| 1998 | 1998 |
| 1999 // --- Byte Arrays --- | 1999 // --- Byte Arrays --- |
| 2000 | 2000 |
| 2001 | 2001 |
| 2002 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { | 2002 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { |
| 2003 return RawObject::IsByteArrayClassIndex(Api::ClassIndex(object)); | 2003 return RawObject::IsByteArrayClassId(Api::ClassId(object)); |
| 2004 } | 2004 } |
| 2005 | 2005 |
| 2006 | 2006 |
| 2007 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 2007 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| 2008 Isolate* isolate = Isolate::Current(); | 2008 Isolate* isolate = Isolate::Current(); |
| 2009 DARTSCOPE(isolate); | 2009 DARTSCOPE(isolate); |
| 2010 return Api::NewHandle(isolate, Uint8Array::New(length)); | 2010 return Api::NewHandle(isolate, Uint8Array::New(length)); |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 | 2013 |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3186 const char* msg = CheckIsolateState(isolate); | 3186 const char* msg = CheckIsolateState(isolate); |
| 3187 if (msg != NULL) { | 3187 if (msg != NULL) { |
| 3188 return Api::NewError(msg); | 3188 return Api::NewError(msg); |
| 3189 } | 3189 } |
| 3190 CompileAll(isolate, &result); | 3190 CompileAll(isolate, &result); |
| 3191 return result; | 3191 return result; |
| 3192 } | 3192 } |
| 3193 | 3193 |
| 3194 | 3194 |
| 3195 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 3195 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 3196 return Api::ClassIndex(object) == kLibrary; | 3196 return Api::ClassId(object) == kLibrary; |
| 3197 } | 3197 } |
| 3198 | 3198 |
| 3199 | 3199 |
| 3200 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, | 3200 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, |
| 3201 Dart_Handle class_name) { | 3201 Dart_Handle class_name) { |
| 3202 Isolate* isolate = Isolate::Current(); | 3202 Isolate* isolate = Isolate::Current(); |
| 3203 DARTSCOPE(isolate); | 3203 DARTSCOPE(isolate); |
| 3204 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3204 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3205 if (lib.IsNull()) { | 3205 if (lib.IsNull()) { |
| 3206 RETURN_TYPE_ERROR(isolate, library, Library); | 3206 RETURN_TYPE_ERROR(isolate, library, Library); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3392 *buffer = NULL; | 3392 *buffer = NULL; |
| 3393 } | 3393 } |
| 3394 delete debug_region; | 3394 delete debug_region; |
| 3395 } else { | 3395 } else { |
| 3396 *buffer = NULL; | 3396 *buffer = NULL; |
| 3397 *buffer_size = 0; | 3397 *buffer_size = 0; |
| 3398 } | 3398 } |
| 3399 } | 3399 } |
| 3400 | 3400 |
| 3401 } // namespace dart | 3401 } // namespace dart |
| OLD | NEW |