| 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 24 matching lines...) Expand all Loading... |
| 35 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; | 35 ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; |
| 36 | 36 |
| 37 const char* CanonicalFunction(const char* func) { | 37 const char* CanonicalFunction(const char* func) { |
| 38 if (strncmp(func, "dart::", 6) == 0) { | 38 if (strncmp(func, "dart::", 6) == 0) { |
| 39 return func + 6; | 39 return func + 6; |
| 40 } else { | 40 } else { |
| 41 return func; | 41 return func; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 #define RETURN_TYPE_ERROR(isolate, dart_handle, Type) \ | 45 #define RETURN_TYPE_ERROR(isolate, dart_handle, Type) \ |
| 46 do { \ | 46 do { \ |
| 47 const Object& tmp = \ | 47 const Object& tmp = \ |
| 48 Object::Handle(isolate, Api::UnwrapHandle((dart_handle))); \ | 48 Object::Handle(isolate, Api::UnwrapHandle((dart_handle))); \ |
| 49 if (tmp.IsNull()) { \ | 49 if (tmp.IsNull()) { \ |
| 50 return Api::NewError("%s expects argument '%s' to be non-null.", \ | 50 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
| 51 CURRENT_FUNC, #dart_handle); \ | 51 CURRENT_FUNC, #dart_handle); \ |
| 52 } else if (tmp.IsError()) { \ | 52 } else if (tmp.IsError()) { \ |
| 53 return dart_handle; \ | 53 return dart_handle; \ |
| 54 } else { \ | 54 } else { \ |
| 55 return Api::NewError("%s expects argument '%s' to be of type %s.", \ | 55 return Api::NewError("%s expects argument '%s' to be of type %s.", \ |
| 56 CURRENT_FUNC, #dart_handle, #Type); \ | 56 CURRENT_FUNC, #dart_handle, #Type); \ |
| 57 } \ | 57 } \ |
| 58 } while (0) | 58 } while (0) |
| 59 | 59 |
| 60 | 60 |
| 61 // Return error if isolate is in an inconsistent state. | 61 // Return error if isolate is in an inconsistent state. |
| 62 // Return NULL when no error condition exists. | 62 // Return NULL when no error condition exists. |
| 63 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { | 63 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { |
| 64 bool success = true; | 64 bool success = true; |
| 65 if (!ClassFinalizer::AllClassesFinalized()) { | 65 if (!ClassFinalizer::AllClassesFinalized()) { |
| 66 success = (generating_snapshot) ? | 66 success = (generating_snapshot) ? |
| 67 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : | 67 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 state->IsValidWeakPersistentHandle(object) || | 113 state->IsValidWeakPersistentHandle(object) || |
| 114 state->IsValidPersistentHandle(object) || | 114 state->IsValidPersistentHandle(object) || |
| 115 state->IsValidLocalHandle(object)); | 115 state->IsValidLocalHandle(object)); |
| 116 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 116 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
| 117 PersistentHandle::raw_offset() == 0 && | 117 PersistentHandle::raw_offset() == 0 && |
| 118 LocalHandle::raw_offset() == 0); | 118 LocalHandle::raw_offset() == 0); |
| 119 #endif | 119 #endif |
| 120 return *(reinterpret_cast<RawObject**>(object)); | 120 return *(reinterpret_cast<RawObject**>(object)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 #define DEFINE_UNWRAP(Type) \ | 123 #define DEFINE_UNWRAP(Type) \ |
| 124 const Type& Api::Unwrap##Type##Handle(Isolate* iso, \ | 124 const Type& Api::Unwrap##Type##Handle(Isolate* iso, \ |
| 125 Dart_Handle dart_handle) { \ | 125 Dart_Handle dart_handle) { \ |
| 126 const Object& tmp = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ | 126 const Object& tmp = Object::Handle(iso, Api::UnwrapHandle(dart_handle)); \ |
| 127 Type& typed_handle = Type::Handle(iso); \ | 127 Type& typed_handle = Type::Handle(iso); \ |
| 128 if (tmp.Is##Type()) { \ | 128 if (tmp.Is##Type()) { \ |
| 129 typed_handle ^= tmp.raw(); \ | 129 typed_handle ^= tmp.raw(); \ |
| 130 } \ | 130 } \ |
| 131 return typed_handle; \ | 131 return typed_handle; \ |
| 132 } | 132 } |
| 133 CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP) | 133 CLASS_LIST_NO_OBJECT(DEFINE_UNWRAP) |
| 134 #undef DEFINE_UNWRAP | 134 #undef DEFINE_UNWRAP |
| 135 | 135 |
| 136 | 136 |
| 137 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, | 137 LocalHandle* Api::UnwrapAsLocalHandle(const ApiState& state, |
| 138 Dart_Handle object) { | 138 Dart_Handle object) { |
| 139 ASSERT(state.IsValidLocalHandle(object)); | 139 ASSERT(state.IsValidLocalHandle(object)); |
| 140 return reinterpret_cast<LocalHandle*>(object); | 140 return reinterpret_cast<LocalHandle*>(object); |
| 141 } | 141 } |
| (...skipping 110 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 Isolate* isolate = Isolate::Current(); | 262 return RawObject::IsErrorClassIndex(Api::ClassIndex(handle)); |
| 263 DARTSCOPE(isolate); | |
| 264 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | |
| 265 return obj.IsError(); | |
| 266 } | 263 } |
| 267 | 264 |
| 268 | 265 |
| 269 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 266 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 270 Isolate* isolate = Isolate::Current(); | 267 Isolate* isolate = Isolate::Current(); |
| 271 DARTSCOPE(isolate); | 268 DARTSCOPE(isolate); |
| 272 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 269 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 273 if (obj.IsError()) { | 270 if (obj.IsError()) { |
| 274 Error& error = Error::Handle(isolate); | 271 Error& error = Error::Handle(isolate); |
| 275 error ^= obj.raw(); | 272 error ^= obj.raw(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 ASSERT(state != NULL); | 364 ASSERT(state != NULL); |
| 368 state->UnwindScopes(isolate->top_exit_frame_info()); | 365 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 369 Exceptions::PropagateError(error); | 366 Exceptions::PropagateError(error); |
| 370 UNREACHABLE(); | 367 UNREACHABLE(); |
| 371 | 368 |
| 372 return Api::NewError("Cannot reach here. Internal error."); | 369 return Api::NewError("Cannot reach here. Internal error."); |
| 373 } | 370 } |
| 374 | 371 |
| 375 | 372 |
| 376 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 373 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
| 377 int line, | 374 int line, |
| 378 const char* handle, | 375 const char* handle, |
| 379 const char* message) { | 376 const char* message) { |
| 380 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 377 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
| 381 file, line, handle, message); | 378 file, line, handle, message); |
| 382 OS::Abort(); | 379 OS::Abort(); |
| 383 } | 380 } |
| 384 | 381 |
| 385 | 382 |
| 386 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 383 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 387 Isolate* isolate = Isolate::Current(); | 384 Isolate* isolate = Isolate::Current(); |
| 388 DARTSCOPE(isolate); | 385 DARTSCOPE(isolate); |
| 389 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 386 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 1000 |
| 1004 | 1001 |
| 1005 DART_EXPORT Dart_Handle Dart_Null() { | 1002 DART_EXPORT Dart_Handle Dart_Null() { |
| 1006 Isolate* isolate = Isolate::Current(); | 1003 Isolate* isolate = Isolate::Current(); |
| 1007 CHECK_ISOLATE_SCOPE(isolate); | 1004 CHECK_ISOLATE_SCOPE(isolate); |
| 1008 return Api::Null(isolate); | 1005 return Api::Null(isolate); |
| 1009 } | 1006 } |
| 1010 | 1007 |
| 1011 | 1008 |
| 1012 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1009 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
| 1013 Isolate* isolate = Isolate::Current(); | 1010 return Api::ClassIndex(object) == kNullClassIndex; |
| 1014 DARTSCOPE(isolate); | |
| 1015 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1016 return obj.IsNull(); | |
| 1017 } | 1011 } |
| 1018 | 1012 |
| 1019 | 1013 |
| 1020 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1014 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
| 1021 bool* value) { | 1015 bool* value) { |
| 1022 Isolate* isolate = Isolate::Current(); | 1016 Isolate* isolate = Isolate::Current(); |
| 1023 DARTSCOPE(isolate); | 1017 DARTSCOPE(isolate); |
| 1024 const Instance& expected = | 1018 const Instance& expected = |
| 1025 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); | 1019 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); |
| 1026 const Instance& actual = | 1020 const Instance& actual = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. | 1070 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. |
| 1077 return Api::Success(isolate); | 1071 return Api::Success(isolate); |
| 1078 } | 1072 } |
| 1079 | 1073 |
| 1080 | 1074 |
| 1081 // --- Numbers ---- | 1075 // --- Numbers ---- |
| 1082 | 1076 |
| 1083 | 1077 |
| 1084 // TODO(iposva): The argument should be an instance. | 1078 // TODO(iposva): The argument should be an instance. |
| 1085 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1079 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
| 1086 Isolate* isolate = Isolate::Current(); | 1080 return RawObject::IsNumberClassIndex(Api::ClassIndex(object)); |
| 1087 DARTSCOPE(isolate); | |
| 1088 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1089 return obj.IsNumber(); | |
| 1090 } | 1081 } |
| 1091 | 1082 |
| 1092 | 1083 |
| 1093 // --- Integers ---- | 1084 // --- Integers ---- |
| 1094 | 1085 |
| 1095 | 1086 |
| 1096 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1087 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 1097 // Fast path for Smis. | 1088 return RawObject::IsIntegerClassIndex(Api::ClassIndex(object)); |
| 1098 if (Api::IsSmi(object)) { | |
| 1099 return true; | |
| 1100 } | |
| 1101 | |
| 1102 Isolate* isolate = Isolate::Current(); | |
| 1103 DARTSCOPE(isolate); | |
| 1104 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1105 return obj.IsInteger(); | |
| 1106 } | 1089 } |
| 1107 | 1090 |
| 1108 | 1091 |
| 1109 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 1092 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 1110 bool* fits) { | 1093 bool* fits) { |
| 1111 // Fast path for Smis. | 1094 // Fast path for Smis and Mints. |
| 1112 Isolate* isolate = Isolate::Current(); | 1095 Isolate* isolate = Isolate::Current(); |
| 1113 CHECK_ISOLATE(isolate); | 1096 CHECK_ISOLATE(isolate); |
| 1114 if (Api::IsSmi(integer)) { | 1097 intptr_t class_index = Api::ClassIndex(integer); |
| 1098 if (class_index == kSmi || class_index == kMint) { |
| 1115 *fits = true; | 1099 *fits = true; |
| 1116 return Api::Success(isolate); | 1100 return Api::Success(isolate); |
| 1117 } | 1101 } |
| 1118 | 1102 |
| 1119 DARTSCOPE_NOCHECKS(isolate); | 1103 DARTSCOPE_NOCHECKS(isolate); |
| 1120 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1104 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1121 if (int_obj.IsNull()) { | 1105 if (int_obj.IsNull()) { |
| 1122 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1106 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1123 } | 1107 } |
| 1124 if (int_obj.IsSmi() || int_obj.IsMint()) { | 1108 ASSERT(int_obj.IsBigint()); |
| 1125 *fits = true; | |
| 1126 } else { | |
| 1127 ASSERT(int_obj.IsBigint()); | |
| 1128 #if defined(DEBUG) | 1109 #if defined(DEBUG) |
| 1129 Bigint& bigint = Bigint::Handle(isolate); | 1110 Bigint& bigint = Bigint::Handle(isolate); |
| 1130 bigint ^= int_obj.raw(); | 1111 bigint ^= int_obj.raw(); |
| 1131 ASSERT(!BigintOperations::FitsIntoMint(bigint)); | 1112 ASSERT(!BigintOperations::FitsIntoMint(bigint)); |
| 1132 #endif | 1113 #endif |
| 1133 *fits = false; | 1114 *fits = false; |
| 1134 } | |
| 1135 return Api::Success(isolate); | 1115 return Api::Success(isolate); |
| 1136 } | 1116 } |
| 1137 | 1117 |
| 1138 | 1118 |
| 1139 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 1119 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
| 1140 bool* fits) { | 1120 bool* fits) { |
| 1141 // Fast path for Smis. | 1121 // Fast path for Smis. |
| 1142 Isolate* isolate = Isolate::Current(); | 1122 Isolate* isolate = Isolate::Current(); |
| 1143 CHECK_ISOLATE(isolate); | 1123 CHECK_ISOLATE(isolate); |
| 1144 if (Api::IsSmi(integer)) { | 1124 if (Api::IsSmi(integer)) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 | 1271 |
| 1292 | 1272 |
| 1293 DART_EXPORT Dart_Handle Dart_False() { | 1273 DART_EXPORT Dart_Handle Dart_False() { |
| 1294 Isolate* isolate = Isolate::Current(); | 1274 Isolate* isolate = Isolate::Current(); |
| 1295 CHECK_ISOLATE_SCOPE(isolate); | 1275 CHECK_ISOLATE_SCOPE(isolate); |
| 1296 return Api::False(isolate); | 1276 return Api::False(isolate); |
| 1297 } | 1277 } |
| 1298 | 1278 |
| 1299 | 1279 |
| 1300 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 1280 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
| 1301 Isolate* isolate = Isolate::Current(); | 1281 return Api::ClassIndex(object) == kBool; |
| 1302 DARTSCOPE(isolate); | |
| 1303 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1304 return obj.IsBool(); | |
| 1305 } | 1282 } |
| 1306 | 1283 |
| 1307 | 1284 |
| 1308 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { | 1285 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { |
| 1309 Isolate* isolate = Isolate::Current(); | 1286 Isolate* isolate = Isolate::Current(); |
| 1310 CHECK_ISOLATE_SCOPE(isolate); | 1287 CHECK_ISOLATE_SCOPE(isolate); |
| 1311 return value ? Api::True(isolate) : Api::False(isolate); | 1288 return value ? Api::True(isolate) : Api::False(isolate); |
| 1312 } | 1289 } |
| 1313 | 1290 |
| 1314 | 1291 |
| 1315 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, | 1292 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, |
| 1316 bool* value) { | 1293 bool* value) { |
| 1317 Isolate* isolate = Isolate::Current(); | 1294 Isolate* isolate = Isolate::Current(); |
| 1318 DARTSCOPE(isolate); | 1295 DARTSCOPE(isolate); |
| 1319 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); | 1296 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); |
| 1320 if (obj.IsNull()) { | 1297 if (obj.IsNull()) { |
| 1321 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); | 1298 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); |
| 1322 } | 1299 } |
| 1323 *value = obj.value(); | 1300 *value = obj.value(); |
| 1324 return Api::Success(isolate); | 1301 return Api::Success(isolate); |
| 1325 } | 1302 } |
| 1326 | 1303 |
| 1327 | 1304 |
| 1328 // --- Doubles --- | 1305 // --- Doubles --- |
| 1329 | 1306 |
| 1330 | 1307 |
| 1331 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1308 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
| 1332 Isolate* isolate = Isolate::Current(); | 1309 return Api::ClassIndex(object) == kDouble; |
| 1333 DARTSCOPE(isolate); | |
| 1334 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1335 return obj.IsDouble(); | |
| 1336 } | 1310 } |
| 1337 | 1311 |
| 1338 | 1312 |
| 1339 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 1313 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
| 1340 Isolate* isolate = Isolate::Current(); | 1314 Isolate* isolate = Isolate::Current(); |
| 1341 DARTSCOPE(isolate); | 1315 DARTSCOPE(isolate); |
| 1342 return Api::NewHandle(isolate, Double::New(value)); | 1316 return Api::NewHandle(isolate, Double::New(value)); |
| 1343 } | 1317 } |
| 1344 | 1318 |
| 1345 | 1319 |
| 1346 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 1320 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
| 1347 double* value) { | 1321 double* value) { |
| 1348 Isolate* isolate = Isolate::Current(); | 1322 Isolate* isolate = Isolate::Current(); |
| 1349 DARTSCOPE(isolate); | 1323 DARTSCOPE(isolate); |
| 1350 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); | 1324 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); |
| 1351 if (obj.IsNull()) { | 1325 if (obj.IsNull()) { |
| 1352 RETURN_TYPE_ERROR(isolate, double_obj, Double); | 1326 RETURN_TYPE_ERROR(isolate, double_obj, Double); |
| 1353 } | 1327 } |
| 1354 *value = obj.value(); | 1328 *value = obj.value(); |
| 1355 return Api::Success(isolate); | 1329 return Api::Success(isolate); |
| 1356 } | 1330 } |
| 1357 | 1331 |
| 1358 | 1332 |
| 1359 // --- Strings --- | 1333 // --- Strings --- |
| 1360 | 1334 |
| 1361 | 1335 |
| 1362 DART_EXPORT bool Dart_IsString(Dart_Handle object) { | 1336 DART_EXPORT bool Dart_IsString(Dart_Handle object) { |
| 1363 Isolate* isolate = Isolate::Current(); | 1337 return RawObject::IsStringClassIndex(Api::ClassIndex(object)); |
| 1364 DARTSCOPE(isolate); | |
| 1365 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1366 return obj.IsString(); | |
| 1367 } | 1338 } |
| 1368 | 1339 |
| 1369 | 1340 |
| 1370 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { | 1341 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { |
| 1371 Isolate* isolate = Isolate::Current(); | 1342 return RawObject::IsOneByteStringClassIndex(Api::ClassIndex(object)); |
| 1372 DARTSCOPE(isolate); | |
| 1373 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1374 return obj.IsOneByteString() || obj.IsExternalOneByteString(); | |
| 1375 } | 1343 } |
| 1376 | 1344 |
| 1377 | 1345 |
| 1378 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { | 1346 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { |
| 1379 Isolate* isolate = Isolate::Current(); | 1347 return RawObject::IsTwoByteStringClassIndex(Api::ClassIndex(object)); |
| 1380 DARTSCOPE(isolate); | |
| 1381 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 1382 return (obj.IsOneByteString() || obj.IsExternalOneByteString() || | |
| 1383 obj.IsTwoByteString() || obj.IsExternalTwoByteString()); | |
| 1384 } | 1348 } |
| 1385 | 1349 |
| 1386 | 1350 |
| 1387 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 1351 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
| 1388 Isolate* isolate = Isolate::Current(); | 1352 Isolate* isolate = Isolate::Current(); |
| 1389 DARTSCOPE(isolate); | 1353 DARTSCOPE(isolate); |
| 1390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str)); | 1354 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str)); |
| 1391 if (obj.IsString()) { | 1355 if (obj.IsString()) { |
| 1392 String& string_obj = String::Handle(isolate); | 1356 String& string_obj = String::Handle(isolate); |
| 1393 string_obj ^= obj.raw(); | 1357 string_obj ^= obj.raw(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1423 | 1387 |
| 1424 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1388 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
| 1425 intptr_t length) { | 1389 intptr_t length) { |
| 1426 Isolate* isolate = Isolate::Current(); | 1390 Isolate* isolate = Isolate::Current(); |
| 1427 DARTSCOPE(isolate); | 1391 DARTSCOPE(isolate); |
| 1428 return Api::NewHandle(isolate, String::New(codepoints, length)); | 1392 return Api::NewHandle(isolate, String::New(codepoints, length)); |
| 1429 } | 1393 } |
| 1430 | 1394 |
| 1431 | 1395 |
| 1432 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1396 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1433 Isolate* isolate = Isolate::Current(); | 1397 return RawObject::IsExternalStringClassIndex(Api::ClassIndex(object)); |
| 1434 DARTSCOPE(isolate); | |
| 1435 const String& str = Api::UnwrapStringHandle(isolate, object); | |
| 1436 if (str.IsNull()) { | |
| 1437 return false; | |
| 1438 } | |
| 1439 return str.IsExternal(); | |
| 1440 } | 1398 } |
| 1441 | 1399 |
| 1442 | 1400 |
| 1443 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1401 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| 1444 void** peer) { | 1402 void** peer) { |
| 1445 Isolate* isolate = Isolate::Current(); | 1403 Isolate* isolate = Isolate::Current(); |
| 1446 DARTSCOPE(isolate); | 1404 DARTSCOPE(isolate); |
| 1447 const String& str = Api::UnwrapStringHandle(isolate, object); | 1405 const String& str = Api::UnwrapStringHandle(isolate, object); |
| 1448 if (str.IsNull()) { | 1406 if (str.IsNull()) { |
| 1449 RETURN_TYPE_ERROR(isolate, object, String); | 1407 RETURN_TYPE_ERROR(isolate, object, String); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1656 &malformed_type_error)) { | 1614 &malformed_type_error)) { |
| 1657 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 1615 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
| 1658 return instance.raw(); | 1616 return instance.raw(); |
| 1659 } | 1617 } |
| 1660 } | 1618 } |
| 1661 return Instance::null(); | 1619 return Instance::null(); |
| 1662 } | 1620 } |
| 1663 | 1621 |
| 1664 | 1622 |
| 1665 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1623 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 1624 if (RawObject::IsBuiltinListClassIndex(Api::ClassIndex(object))) { |
| 1625 return true; |
| 1626 } |
| 1627 |
| 1666 Isolate* isolate = Isolate::Current(); | 1628 Isolate* isolate = Isolate::Current(); |
| 1667 DARTSCOPE(isolate); | 1629 DARTSCOPE(isolate); |
| 1668 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1630 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1669 return (obj.IsArray() || obj.IsGrowableObjectArray() || | 1631 return GetListInstance(isolate, obj) != Instance::null(); |
| 1670 (GetListInstance(isolate, obj) != Instance::null())); | |
| 1671 } | 1632 } |
| 1672 | 1633 |
| 1673 | 1634 |
| 1674 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1635 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 1675 Isolate* isolate = Isolate::Current(); | 1636 Isolate* isolate = Isolate::Current(); |
| 1676 DARTSCOPE(isolate); | 1637 DARTSCOPE(isolate); |
| 1677 return Api::NewHandle(isolate, Array::New(length)); | 1638 return Api::NewHandle(isolate, Array::New(length)); |
| 1678 } | 1639 } |
| 1679 | 1640 |
| 1680 | 1641 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2005 } | 1966 } |
| 2006 } | 1967 } |
| 2007 return Api::NewError("Object does not implement the 'List' interface"); | 1968 return Api::NewError("Object does not implement the 'List' interface"); |
| 2008 } | 1969 } |
| 2009 | 1970 |
| 2010 | 1971 |
| 2011 // --- Byte Arrays --- | 1972 // --- Byte Arrays --- |
| 2012 | 1973 |
| 2013 | 1974 |
| 2014 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { | 1975 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { |
| 2015 Isolate* isolate = Isolate::Current(); | 1976 return RawObject::IsByteArrayClassIndex(Api::ClassIndex(object)); |
| 2016 DARTSCOPE(isolate); | |
| 2017 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 2018 return obj.IsByteArray(); | |
| 2019 } | 1977 } |
| 2020 | 1978 |
| 2021 | 1979 |
| 2022 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 1980 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| 2023 Isolate* isolate = Isolate::Current(); | 1981 Isolate* isolate = Isolate::Current(); |
| 2024 DARTSCOPE(isolate); | 1982 DARTSCOPE(isolate); |
| 2025 return Api::NewHandle(isolate, Uint8Array::New(length)); | 1983 return Api::NewHandle(isolate, Uint8Array::New(length)); |
| 2026 } | 1984 } |
| 2027 | 1985 |
| 2028 | 1986 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2236 intptr_t byte_offset, | 2194 intptr_t byte_offset, |
| 2237 double value) { | 2195 double value) { |
| 2238 return ByteArraySetAt(array, byte_offset, value); | 2196 return ByteArraySetAt(array, byte_offset, value); |
| 2239 } | 2197 } |
| 2240 | 2198 |
| 2241 | 2199 |
| 2242 // --- Closures --- | 2200 // --- Closures --- |
| 2243 | 2201 |
| 2244 | 2202 |
| 2245 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 2203 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 2204 // We can't use a fast class index check here because there are many |
| 2205 // different signature classes for closures. |
| 2246 Isolate* isolate = Isolate::Current(); | 2206 Isolate* isolate = Isolate::Current(); |
| 2247 DARTSCOPE(isolate); | 2207 DARTSCOPE(isolate); |
| 2248 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 2208 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 2249 return obj.IsClosure(); | 2209 return obj.IsClosure(); |
| 2250 } | 2210 } |
| 2251 | 2211 |
| 2252 | 2212 |
| 2253 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 2213 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 2254 int number_of_arguments, | 2214 int number_of_arguments, |
| 2255 Dart_Handle* arguments) { | 2215 Dart_Handle* arguments) { |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3126 const char* msg = CheckIsolateState(isolate); | 3086 const char* msg = CheckIsolateState(isolate); |
| 3127 if (msg != NULL) { | 3087 if (msg != NULL) { |
| 3128 return Api::NewError(msg); | 3088 return Api::NewError(msg); |
| 3129 } | 3089 } |
| 3130 CompileAll(isolate, &result); | 3090 CompileAll(isolate, &result); |
| 3131 return result; | 3091 return result; |
| 3132 } | 3092 } |
| 3133 | 3093 |
| 3134 | 3094 |
| 3135 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 3095 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 3136 Isolate* isolate = Isolate::Current(); | 3096 return Api::ClassIndex(object) == kLibrary; |
| 3137 DARTSCOPE(isolate); | |
| 3138 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 3139 return obj.IsLibrary(); | |
| 3140 } | 3097 } |
| 3141 | 3098 |
| 3142 | 3099 |
| 3143 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { | 3100 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { |
| 3144 Isolate* isolate = Isolate::Current(); | 3101 Isolate* isolate = Isolate::Current(); |
| 3145 DARTSCOPE(isolate); | 3102 DARTSCOPE(isolate); |
| 3146 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 3103 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); |
| 3147 if (param.IsNull() || !param.IsString()) { | 3104 if (param.IsNull() || !param.IsString()) { |
| 3148 return Api::NewError("Invalid class name specified"); | 3105 return Api::NewError("Invalid class name specified"); |
| 3149 } | 3106 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3329 *buffer = NULL; | 3286 *buffer = NULL; |
| 3330 } | 3287 } |
| 3331 delete debug_region; | 3288 delete debug_region; |
| 3332 } else { | 3289 } else { |
| 3333 *buffer = NULL; | 3290 *buffer = NULL; |
| 3334 *buffer_size = 0; | 3291 *buffer_size = 0; |
| 3335 } | 3292 } |
| 3336 } | 3293 } |
| 3337 | 3294 |
| 3338 } // namespace dart | 3295 } // namespace dart |
| OLD | NEW |