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

Side by Side Diff: vm/dart_api_impl.cc

Issue 10386060: Speed up the Dart_IsBlah functions by checking the class index. This (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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
OLDNEW
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
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
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
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 ASSERT(kError + 5 == kInstance); // There are 4 subtypes of Error.
Ivan Posva 2012/05/09 23:28:16 This is brittle in case we delete one of the error
turnidge 2012/05/10 17:49:38 I have moved all of these predicates to raw_object
263 DARTSCOPE(isolate); 263 intptr_t class_index = Api::ClassIndex(handle);
264 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 264 return (class_index >= kError && class_index < kInstance);
265 return obj.IsError();
266 } 265 }
267 266
268 267
269 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { 268 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) {
270 Isolate* isolate = Isolate::Current(); 269 Isolate* isolate = Isolate::Current();
271 DARTSCOPE(isolate); 270 DARTSCOPE(isolate);
272 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 271 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
273 if (obj.IsError()) { 272 if (obj.IsError()) {
274 Error& error = Error::Handle(isolate); 273 Error& error = Error::Handle(isolate);
275 error ^= obj.raw(); 274 error ^= obj.raw();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 ASSERT(state != NULL); 366 ASSERT(state != NULL);
368 state->UnwindScopes(isolate->top_exit_frame_info()); 367 state->UnwindScopes(isolate->top_exit_frame_info());
369 Exceptions::PropagateError(error); 368 Exceptions::PropagateError(error);
370 UNREACHABLE(); 369 UNREACHABLE();
371 370
372 return Api::NewError("Cannot reach here. Internal error."); 371 return Api::NewError("Cannot reach here. Internal error.");
373 } 372 }
374 373
375 374
376 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, 375 DART_EXPORT void _Dart_ReportErrorHandle(const char* file,
377 int line, 376 int line,
378 const char* handle, 377 const char* handle,
379 const char* message) { 378 const char* message) {
380 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", 379 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n",
381 file, line, handle, message); 380 file, line, handle, message);
382 OS::Abort(); 381 OS::Abort();
383 } 382 }
384 383
385 384
386 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { 385 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) {
387 Isolate* isolate = Isolate::Current(); 386 Isolate* isolate = Isolate::Current();
388 DARTSCOPE(isolate); 387 DARTSCOPE(isolate);
389 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 388 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 1002
1004 1003
1005 DART_EXPORT Dart_Handle Dart_Null() { 1004 DART_EXPORT Dart_Handle Dart_Null() {
1006 Isolate* isolate = Isolate::Current(); 1005 Isolate* isolate = Isolate::Current();
1007 CHECK_ISOLATE_SCOPE(isolate); 1006 CHECK_ISOLATE_SCOPE(isolate);
1008 return Api::Null(isolate); 1007 return Api::Null(isolate);
1009 } 1008 }
1010 1009
1011 1010
1012 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { 1011 DART_EXPORT bool Dart_IsNull(Dart_Handle object) {
1013 Isolate* isolate = Isolate::Current(); 1012 ASSERT(kNullClassIndex + 1 == kDynamicClassIndex); // No subtypes.
1014 DARTSCOPE(isolate); 1013 return Api::ClassIndex(object) == kNullClassIndex;
1015 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1016 return obj.IsNull();
1017 } 1014 }
1018 1015
1019 1016
1020 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, 1017 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2,
1021 bool* value) { 1018 bool* value) {
1022 Isolate* isolate = Isolate::Current(); 1019 Isolate* isolate = Isolate::Current();
1023 DARTSCOPE(isolate); 1020 DARTSCOPE(isolate);
1024 const Instance& expected = 1021 const Instance& expected =
1025 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); 1022 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1));
1026 const Instance& actual = 1023 const Instance& actual =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. 1073 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class.
1077 return Api::Success(isolate); 1074 return Api::Success(isolate);
1078 } 1075 }
1079 1076
1080 1077
1081 // --- Numbers ---- 1078 // --- Numbers ----
1082 1079
1083 1080
1084 // TODO(iposva): The argument should be an instance. 1081 // TODO(iposva): The argument should be an instance.
1085 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { 1082 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) {
1086 Isolate* isolate = Isolate::Current(); 1083 ASSERT(kNumber + 6 == kString); // There are 5 subtypes of Number.
Ivan Posva 2012/05/09 23:28:16 ditto.
1087 DARTSCOPE(isolate); 1084 intptr_t class_index = Api::ClassIndex(object);
1088 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1085 return (class_index >= kNumber && class_index < kString);
1089 return obj.IsNumber();
1090 } 1086 }
1091 1087
1092 1088
1093 // --- Integers ---- 1089 // --- Integers ----
1094 1090
1095 1091
1096 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { 1092 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
1097 // Fast path for Smis. 1093 ASSERT(kInteger + 4 == kDouble); // There are 3 subtypes of Integer.
Ivan Posva 2012/05/09 23:28:16 ditto.
1098 if (Api::IsSmi(object)) { 1094 intptr_t class_index = Api::ClassIndex(object);
1099 return true; 1095 return (class_index >= kInteger && class_index < kDouble);
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 } 1096 }
1107 1097
1108 1098
1109 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, 1099 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
1110 bool* fits) { 1100 bool* fits) {
1111 // Fast path for Smis. 1101 // Fast path for Smis and Mints.
1112 Isolate* isolate = Isolate::Current(); 1102 Isolate* isolate = Isolate::Current();
1113 CHECK_ISOLATE(isolate); 1103 CHECK_ISOLATE(isolate);
1114 if (Api::IsSmi(integer)) { 1104 intptr_t class_index = Api::ClassIndex(integer);
1105 if (class_index == kSmi || class_index == kMint) {
1115 *fits = true; 1106 *fits = true;
1116 return Api::Success(isolate); 1107 return Api::Success(isolate);
1117 } 1108 }
1118 1109
1119 DARTSCOPE_NOCHECKS(isolate); 1110 DARTSCOPE_NOCHECKS(isolate);
1120 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); 1111 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
1121 if (int_obj.IsNull()) { 1112 if (int_obj.IsNull()) {
1122 RETURN_TYPE_ERROR(isolate, integer, Integer); 1113 RETURN_TYPE_ERROR(isolate, integer, Integer);
1123 } 1114 }
1124 if (int_obj.IsSmi() || int_obj.IsMint()) { 1115 ASSERT(int_obj.IsBigint());
1125 *fits = true;
1126 } else {
1127 ASSERT(int_obj.IsBigint());
1128 #if defined(DEBUG) 1116 #if defined(DEBUG)
1129 Bigint& bigint = Bigint::Handle(isolate); 1117 Bigint& bigint = Bigint::Handle(isolate);
1130 bigint ^= int_obj.raw(); 1118 bigint ^= int_obj.raw();
1131 ASSERT(!BigintOperations::FitsIntoMint(bigint)); 1119 ASSERT(!BigintOperations::FitsIntoMint(bigint));
1132 #endif 1120 #endif
1133 *fits = false; 1121 *fits = false;
1134 }
1135 return Api::Success(isolate); 1122 return Api::Success(isolate);
1136 } 1123 }
1137 1124
1138 1125
1139 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, 1126 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
1140 bool* fits) { 1127 bool* fits) {
1141 // Fast path for Smis. 1128 // Fast path for Smis.
1142 Isolate* isolate = Isolate::Current(); 1129 Isolate* isolate = Isolate::Current();
1143 CHECK_ISOLATE(isolate); 1130 CHECK_ISOLATE(isolate);
1144 if (Api::IsSmi(integer)) { 1131 if (Api::IsSmi(integer)) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 1278
1292 1279
1293 DART_EXPORT Dart_Handle Dart_False() { 1280 DART_EXPORT Dart_Handle Dart_False() {
1294 Isolate* isolate = Isolate::Current(); 1281 Isolate* isolate = Isolate::Current();
1295 CHECK_ISOLATE_SCOPE(isolate); 1282 CHECK_ISOLATE_SCOPE(isolate);
1296 return Api::False(isolate); 1283 return Api::False(isolate);
1297 } 1284 }
1298 1285
1299 1286
1300 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { 1287 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) {
1301 Isolate* isolate = Isolate::Current(); 1288 ASSERT(kBool + 1 == kArray); // No subtypes.
turnidge 2012/05/10 17:49:38 I dropped the asserts for types with no subtypes.
1302 DARTSCOPE(isolate); 1289 return Api::ClassIndex(object) == kBool;
1303 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1304 return obj.IsBool();
1305 } 1290 }
1306 1291
1307 1292
1308 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { 1293 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) {
1309 Isolate* isolate = Isolate::Current(); 1294 Isolate* isolate = Isolate::Current();
1310 CHECK_ISOLATE_SCOPE(isolate); 1295 CHECK_ISOLATE_SCOPE(isolate);
1311 return value ? Api::True(isolate) : Api::False(isolate); 1296 return value ? Api::True(isolate) : Api::False(isolate);
1312 } 1297 }
1313 1298
1314 1299
1315 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, 1300 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj,
1316 bool* value) { 1301 bool* value) {
1317 Isolate* isolate = Isolate::Current(); 1302 Isolate* isolate = Isolate::Current();
1318 DARTSCOPE(isolate); 1303 DARTSCOPE(isolate);
1319 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj); 1304 const Bool& obj = Api::UnwrapBoolHandle(isolate, boolean_obj);
1320 if (obj.IsNull()) { 1305 if (obj.IsNull()) {
1321 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool); 1306 RETURN_TYPE_ERROR(isolate, boolean_obj, Bool);
1322 } 1307 }
1323 *value = obj.value(); 1308 *value = obj.value();
1324 return Api::Success(isolate); 1309 return Api::Success(isolate);
1325 } 1310 }
1326 1311
1327 1312
1328 // --- Doubles --- 1313 // --- Doubles ---
1329 1314
1330 1315
1331 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { 1316 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) {
1332 Isolate* isolate = Isolate::Current(); 1317 ASSERT(kDouble + 1 == kString); // No subtypes.
1333 DARTSCOPE(isolate); 1318 return Api::ClassIndex(object) == kDouble;
1334 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1335 return obj.IsDouble();
1336 } 1319 }
1337 1320
1338 1321
1339 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { 1322 DART_EXPORT Dart_Handle Dart_NewDouble(double value) {
1340 Isolate* isolate = Isolate::Current(); 1323 Isolate* isolate = Isolate::Current();
1341 DARTSCOPE(isolate); 1324 DARTSCOPE(isolate);
1342 return Api::NewHandle(isolate, Double::New(value)); 1325 return Api::NewHandle(isolate, Double::New(value));
1343 } 1326 }
1344 1327
1345 1328
1346 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, 1329 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj,
1347 double* value) { 1330 double* value) {
1348 Isolate* isolate = Isolate::Current(); 1331 Isolate* isolate = Isolate::Current();
1349 DARTSCOPE(isolate); 1332 DARTSCOPE(isolate);
1350 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); 1333 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj);
1351 if (obj.IsNull()) { 1334 if (obj.IsNull()) {
1352 RETURN_TYPE_ERROR(isolate, double_obj, Double); 1335 RETURN_TYPE_ERROR(isolate, double_obj, Double);
1353 } 1336 }
1354 *value = obj.value(); 1337 *value = obj.value();
1355 return Api::Success(isolate); 1338 return Api::Success(isolate);
1356 } 1339 }
1357 1340
1358 1341
1359 // --- Strings --- 1342 // --- Strings ---
1360 1343
1361 1344
1362 DART_EXPORT bool Dart_IsString(Dart_Handle object) { 1345 DART_EXPORT bool Dart_IsString(Dart_Handle object) {
1363 Isolate* isolate = Isolate::Current(); 1346 ASSERT(kString + 7 == kBool); // There are 6 subtypes of String.
Ivan Posva 2012/05/09 23:28:16 ditto.
1364 DARTSCOPE(isolate); 1347 intptr_t class_index = Api::ClassIndex(object);
1365 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1348 return (class_index >= kString && class_index < kBool);
1366 return obj.IsString();
1367 } 1349 }
1368 1350
1369 1351
1370 DART_EXPORT bool Dart_IsString8(Dart_Handle object) { 1352 DART_EXPORT bool Dart_IsString8(Dart_Handle object) {
1371 Isolate* isolate = Isolate::Current(); 1353 intptr_t class_index = Api::ClassIndex(object);
1372 DARTSCOPE(isolate); 1354 return (class_index == kOneByteString ||
1373 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1355 class_index == kExternalOneByteString);
1374 return obj.IsOneByteString() || obj.IsExternalOneByteString();
1375 } 1356 }
1376 1357
1377 1358
1378 DART_EXPORT bool Dart_IsString16(Dart_Handle object) { 1359 DART_EXPORT bool Dart_IsString16(Dart_Handle object) {
1379 Isolate* isolate = Isolate::Current(); 1360 intptr_t class_index = Api::ClassIndex(object);
1380 DARTSCOPE(isolate); 1361 return (class_index == kOneByteString ||
1381 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1362 class_index == kTwoByteString ||
1382 return (obj.IsOneByteString() || obj.IsExternalOneByteString() || 1363 class_index == kExternalOneByteString ||
1383 obj.IsTwoByteString() || obj.IsExternalTwoByteString()); 1364 class_index == kExternalTwoByteString);
1384 } 1365 }
1385 1366
1386 1367
1387 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { 1368 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) {
1388 Isolate* isolate = Isolate::Current(); 1369 Isolate* isolate = Isolate::Current();
1389 DARTSCOPE(isolate); 1370 DARTSCOPE(isolate);
1390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str)); 1371 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str));
1391 if (obj.IsString()) { 1372 if (obj.IsString()) {
1392 String& string_obj = String::Handle(isolate); 1373 String& string_obj = String::Handle(isolate);
1393 string_obj ^= obj.raw(); 1374 string_obj ^= obj.raw();
(...skipping 29 matching lines...) Expand all
1423 1404
1424 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, 1405 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints,
1425 intptr_t length) { 1406 intptr_t length) {
1426 Isolate* isolate = Isolate::Current(); 1407 Isolate* isolate = Isolate::Current();
1427 DARTSCOPE(isolate); 1408 DARTSCOPE(isolate);
1428 return Api::NewHandle(isolate, String::New(codepoints, length)); 1409 return Api::NewHandle(isolate, String::New(codepoints, length));
1429 } 1410 }
1430 1411
1431 1412
1432 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { 1413 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) {
1433 Isolate* isolate = Isolate::Current(); 1414 intptr_t class_index = Api::ClassIndex(object);
1434 DARTSCOPE(isolate); 1415 return (class_index == kExternalOneByteString ||
1435 const String& str = Api::UnwrapStringHandle(isolate, object); 1416 class_index == kExternalTwoByteString ||
1436 if (str.IsNull()) { 1417 class_index == kExternalFourByteString);
1437 return false;
1438 }
1439 return str.IsExternal();
1440 } 1418 }
1441 1419
1442 1420
1443 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, 1421 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object,
1444 void** peer) { 1422 void** peer) {
1445 Isolate* isolate = Isolate::Current(); 1423 Isolate* isolate = Isolate::Current();
1446 DARTSCOPE(isolate); 1424 DARTSCOPE(isolate);
1447 const String& str = Api::UnwrapStringHandle(isolate, object); 1425 const String& str = Api::UnwrapStringHandle(isolate, object);
1448 if (str.IsNull()) { 1426 if (str.IsNull()) {
1449 RETURN_TYPE_ERROR(isolate, object, String); 1427 RETURN_TYPE_ERROR(isolate, object, String);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 &malformed_type_error)) { 1634 &malformed_type_error)) {
1657 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. 1635 ASSERT(malformed_type_error.IsNull()); // Type is a raw List.
1658 return instance.raw(); 1636 return instance.raw();
1659 } 1637 }
1660 } 1638 }
1661 return Instance::null(); 1639 return Instance::null();
1662 } 1640 }
1663 1641
1664 1642
1665 DART_EXPORT bool Dart_IsList(Dart_Handle object) { 1643 DART_EXPORT bool Dart_IsList(Dart_Handle object) {
1644 ASSERT(kArray + 2 == kGrowableObjectArray); // There is 1 subtype of Array.
Ivan Posva 2012/05/09 23:28:16 ditto.
1645 ASSERT(kGrowableObjectArray + 1 == kByteArray); // No subtypes.
1646 intptr_t class_index = Api::ClassIndex(object);
1647 if (class_index >= kArray && class_index < kByteArray) {
1648 return true;
1649 }
1650
1666 Isolate* isolate = Isolate::Current(); 1651 Isolate* isolate = Isolate::Current();
1667 DARTSCOPE(isolate); 1652 DARTSCOPE(isolate);
1668 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 1653 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
1669 return (obj.IsArray() || obj.IsGrowableObjectArray() || 1654 return GetListInstance(isolate, obj) != Instance::null();
1670 (GetListInstance(isolate, obj) != Instance::null()));
1671 } 1655 }
1672 1656
1673 1657
1674 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { 1658 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) {
1675 Isolate* isolate = Isolate::Current(); 1659 Isolate* isolate = Isolate::Current();
1676 DARTSCOPE(isolate); 1660 DARTSCOPE(isolate);
1677 return Api::NewHandle(isolate, Array::New(length)); 1661 return Api::NewHandle(isolate, Array::New(length));
1678 } 1662 }
1679 1663
1680 1664
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 } 1989 }
2006 } 1990 }
2007 return Api::NewError("Object does not implement the 'List' interface"); 1991 return Api::NewError("Object does not implement the 'List' interface");
2008 } 1992 }
2009 1993
2010 1994
2011 // --- Byte Arrays --- 1995 // --- Byte Arrays ---
2012 1996
2013 1997
2014 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { 1998 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) {
2015 Isolate* isolate = Isolate::Current(); 1999 ASSERT(kByteArray + 21 == kClosure); // There are 20 subtypes of ByteArray
Ivan Posva 2012/05/09 23:28:16 ditto.
2016 DARTSCOPE(isolate); 2000 intptr_t class_index = Api::ClassIndex(object);
2017 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 2001 return (class_index >= kByteArray && class_index <= kClosure);
2018 return obj.IsByteArray();
2019 } 2002 }
2020 2003
2021 2004
2022 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { 2005 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) {
2023 Isolate* isolate = Isolate::Current(); 2006 Isolate* isolate = Isolate::Current();
2024 DARTSCOPE(isolate); 2007 DARTSCOPE(isolate);
2025 return Api::NewHandle(isolate, Uint8Array::New(length)); 2008 return Api::NewHandle(isolate, Uint8Array::New(length));
2026 } 2009 }
2027 2010
2028 2011
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 intptr_t byte_offset, 2219 intptr_t byte_offset,
2237 double value) { 2220 double value) {
2238 return ByteArraySetAt(array, byte_offset, value); 2221 return ByteArraySetAt(array, byte_offset, value);
2239 } 2222 }
2240 2223
2241 2224
2242 // --- Closures --- 2225 // --- Closures ---
2243 2226
2244 2227
2245 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 2228 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
2229 // We can't use a fast class index check here because there are many
2230 // different signature classes for closures.
2246 Isolate* isolate = Isolate::Current(); 2231 Isolate* isolate = Isolate::Current();
2247 DARTSCOPE(isolate); 2232 DARTSCOPE(isolate);
2248 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 2233 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
2249 return obj.IsClosure(); 2234 return obj.IsClosure();
2250 } 2235 }
2251 2236
2252 2237
2253 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 2238 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
2254 int number_of_arguments, 2239 int number_of_arguments,
2255 Dart_Handle* arguments) { 2240 Dart_Handle* arguments) {
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 const char* msg = CheckIsolateState(isolate); 3104 const char* msg = CheckIsolateState(isolate);
3120 if (msg != NULL) { 3105 if (msg != NULL) {
3121 return Api::NewError(msg); 3106 return Api::NewError(msg);
3122 } 3107 }
3123 CompileAll(isolate, &result); 3108 CompileAll(isolate, &result);
3124 return result; 3109 return result;
3125 } 3110 }
3126 3111
3127 3112
3128 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 3113 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
3129 Isolate* isolate = Isolate::Current(); 3114 ASSERT(kLibrary + 1 == kLibraryPrefix); // No subtypes.
3130 DARTSCOPE(isolate); 3115 return Api::ClassIndex(object) == kLibrary;
3131 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
3132 return obj.IsLibrary();
3133 } 3116 }
3134 3117
3135 3118
3136 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { 3119 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) {
3137 Isolate* isolate = Isolate::Current(); 3120 Isolate* isolate = Isolate::Current();
3138 DARTSCOPE(isolate); 3121 DARTSCOPE(isolate);
3139 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); 3122 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name));
3140 if (param.IsNull() || !param.IsString()) { 3123 if (param.IsNull() || !param.IsString()) {
3141 return Api::NewError("Invalid class name specified"); 3124 return Api::NewError("Invalid class name specified");
3142 } 3125 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3322 *buffer = NULL; 3305 *buffer = NULL;
3323 } 3306 }
3324 delete debug_region; 3307 delete debug_region;
3325 } else { 3308 } else {
3326 *buffer = NULL; 3309 *buffer = NULL;
3327 *buffer_size = 0; 3310 *buffer_size = 0;
3328 } 3311 }
3329 } 3312 }
3330 3313
3331 } // namespace dart 3314 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698