| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // |
| 64 // TODO(turnidge): Make this function return an error handle directly |
| 65 // rather than returning an error string. The current behavior can |
| 66 // cause compilation errors to appear to be api errors. |
| 63 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { | 67 const char* CheckIsolateState(Isolate* isolate, bool generating_snapshot) { |
| 64 bool success = true; | 68 bool success = true; |
| 65 if (!ClassFinalizer::AllClassesFinalized()) { | 69 if (!ClassFinalizer::AllClassesFinalized()) { |
| 66 success = (generating_snapshot) ? | 70 success = (generating_snapshot) ? |
| 67 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : | 71 ClassFinalizer::FinalizePendingClassesForSnapshotCreation() : |
| 68 ClassFinalizer::FinalizePendingClasses(); | 72 ClassFinalizer::FinalizePendingClasses(); |
| 69 } | 73 } |
| 70 if (success) { | 74 if (success) { |
| 71 success = isolate->object_store()->PreallocateObjects(); | 75 success = isolate->object_store()->PreallocateObjects(); |
| 72 if (success) { | 76 if (success) { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 260 |
| 257 | 261 |
| 258 // --- Handles --- | 262 // --- Handles --- |
| 259 | 263 |
| 260 | 264 |
| 261 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 265 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 262 return RawObject::IsErrorClassId(Api::ClassId(handle)); | 266 return RawObject::IsErrorClassId(Api::ClassId(handle)); |
| 263 } | 267 } |
| 264 | 268 |
| 265 | 269 |
| 270 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
| 271 return Api::ClassId(object) == kApiError; |
| 272 } |
| 273 |
| 274 |
| 275 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { |
| 276 return Api::ClassId(object) == kUnhandledException; |
| 277 } |
| 278 |
| 279 |
| 280 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { |
| 281 return Api::ClassId(object) == kLanguageError; |
| 282 } |
| 283 |
| 284 |
| 285 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
| 286 return Api::ClassId(object) == kUnwindError; |
| 287 } |
| 288 |
| 289 |
| 266 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 290 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 267 Isolate* isolate = Isolate::Current(); | 291 Isolate* isolate = Isolate::Current(); |
| 268 DARTSCOPE(isolate); | 292 DARTSCOPE(isolate); |
| 269 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 293 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 270 if (obj.IsError()) { | 294 if (obj.IsError()) { |
| 271 Error& error = Error::Handle(isolate); | 295 Error& error = Error::Handle(isolate); |
| 272 error ^= obj.raw(); | 296 error ^= obj.raw(); |
| 273 const char* str = error.ToErrorCString(); | 297 const char* str = error.ToErrorCString(); |
| 274 intptr_t len = strlen(str) + 1; | 298 intptr_t len = strlen(str) + 1; |
| 275 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); | 299 char* str_copy = reinterpret_cast<char*>(Api::Allocate(isolate, len)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 error ^= obj.raw(); | 338 error ^= obj.raw(); |
| 315 return Api::NewHandle(isolate, error.stacktrace()); | 339 return Api::NewHandle(isolate, error.stacktrace()); |
| 316 } else if (obj.IsError()) { | 340 } else if (obj.IsError()) { |
| 317 return Api::NewError("This error is not an unhandled exception error."); | 341 return Api::NewError("This error is not an unhandled exception error."); |
| 318 } else { | 342 } else { |
| 319 return Api::NewError("Can only get stacktraces from error handles."); | 343 return Api::NewError("Can only get stacktraces from error handles."); |
| 320 } | 344 } |
| 321 } | 345 } |
| 322 | 346 |
| 323 | 347 |
| 348 // Deprecated. |
| 349 // TODO(turnidge): Remove all uses and delete. |
| 350 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 351 Isolate* isolate = Isolate::Current(); |
| 352 DARTSCOPE(isolate); |
| 353 |
| 354 va_list args; |
| 355 va_start(args, format); |
| 356 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 357 va_end(args); |
| 358 |
| 359 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 360 va_list args2; |
| 361 va_start(args2, format); |
| 362 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 363 va_end(args2); |
| 364 |
| 365 const String& message = String::Handle(isolate, String::New(buffer)); |
| 366 return Api::NewHandle(isolate, ApiError::New(message)); |
| 367 } |
| 368 |
| 369 |
| 324 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 370 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 325 // fix this but not sure if it available on all of our builds. | 371 // fix this but not sure if it available on all of our builds. |
| 326 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 372 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
| 327 Isolate* isolate = Isolate::Current(); | 373 Isolate* isolate = Isolate::Current(); |
| 328 DARTSCOPE(isolate); | 374 DARTSCOPE(isolate); |
| 329 | 375 |
| 330 va_list args; | 376 va_list args; |
| 331 va_start(args, format); | 377 va_start(args, format); |
| 332 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 378 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 333 va_end(args); | 379 va_end(args); |
| 334 | 380 |
| 335 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 381 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 336 va_list args2; | 382 va_list args2; |
| 337 va_start(args2, format); | 383 va_start(args2, format); |
| 338 OS::VSNPrint(buffer, (len + 1), format, args2); | 384 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 339 va_end(args2); | 385 va_end(args2); |
| 340 | 386 |
| 341 const String& message = String::Handle(isolate, String::New(buffer)); | 387 const String& message = String::Handle(isolate, String::New(buffer)); |
| 342 return Api::NewHandle(isolate, ApiError::New(message)); | 388 return Api::NewHandle(isolate, ApiError::New(message)); |
| 343 } | 389 } |
| 344 | 390 |
| 345 | 391 |
| 392 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 393 Isolate* isolate = Isolate::Current(); |
| 394 DARTSCOPE(isolate); |
| 395 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); |
| 396 if (obj.IsNull()) { |
| 397 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 398 } |
| 399 const Instance& stacktrace = Instance::Handle(isolate); |
| 400 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); |
| 401 } |
| 402 |
| 403 |
| 346 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 404 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 347 Isolate* isolate = Isolate::Current(); | 405 Isolate* isolate = Isolate::Current(); |
| 348 CHECK_ISOLATE(isolate); | 406 CHECK_ISOLATE(isolate); |
| 349 const Object& error = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 407 const Object& error = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 350 if (!error.IsError()) { | 408 if (!error.IsError()) { |
| 351 return Api::NewError( | 409 return Api::NewError( |
| 352 "%s expects argument 'handle' to be an error handle. " | 410 "%s expects argument 'handle' to be an error handle. " |
| 353 "Did you forget to check Dart_IsError first?", | 411 "Did you forget to check Dart_IsError first?", |
| 354 CURRENT_FUNC); | 412 CURRENT_FUNC); |
| 355 } | 413 } |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 } | 1163 } |
| 1106 const Type& type = Type::Handle(isolate, Type::NewNonParameterizedType(cls)); | 1164 const Type& type = Type::Handle(isolate, Type::NewNonParameterizedType(cls)); |
| 1107 Error& malformed_type_error = Error::Handle(isolate); | 1165 Error& malformed_type_error = Error::Handle(isolate); |
| 1108 *value = instance.IsInstanceOf( | 1166 *value = instance.IsInstanceOf( |
| 1109 type, TypeArguments::Handle(isolate), &malformed_type_error); | 1167 type, TypeArguments::Handle(isolate), &malformed_type_error); |
| 1110 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. | 1168 ASSERT(malformed_type_error.IsNull()); // Type was created here from a class. |
| 1111 return Api::Success(isolate); | 1169 return Api::Success(isolate); |
| 1112 } | 1170 } |
| 1113 | 1171 |
| 1114 | 1172 |
| 1173 // --- Instances ---- |
| 1174 |
| 1175 |
| 1176 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
| 1177 Isolate* isolate = Isolate::Current(); |
| 1178 DARTSCOPE(isolate); |
| 1179 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1180 return obj.IsInstance(); |
| 1181 } |
| 1182 |
| 1183 |
| 1184 // TODO(turnidge): Technically, null has a class. Should we allow it? |
| 1185 DART_EXPORT Dart_Handle Dart_InstanceGetClass(Dart_Handle instance) { |
| 1186 Isolate* isolate = Isolate::Current(); |
| 1187 DARTSCOPE(isolate); |
| 1188 const Instance& obj = Api::UnwrapInstanceHandle(isolate, instance); |
| 1189 if (obj.IsNull()) { |
| 1190 RETURN_TYPE_ERROR(isolate, instance, Instance); |
| 1191 } |
| 1192 return Api::NewHandle(isolate, obj.clazz()); |
| 1193 } |
| 1194 |
| 1195 |
| 1115 // --- Numbers ---- | 1196 // --- Numbers ---- |
| 1116 | 1197 |
| 1117 | 1198 |
| 1118 // TODO(iposva): The argument should be an instance. | |
| 1119 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1199 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
| 1120 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1200 return RawObject::IsNumberClassId(Api::ClassId(object)); |
| 1121 } | 1201 } |
| 1122 | 1202 |
| 1123 | 1203 |
| 1124 // --- Integers ---- | 1204 // --- Integers ---- |
| 1125 | 1205 |
| 1126 | 1206 |
| 1127 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1207 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 1128 return RawObject::IsIntegerClassId(Api::ClassId(object)); | 1208 return RawObject::IsIntegerClassId(Api::ClassId(object)); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 type& array = type::Handle(isolate); \ | 1750 type& array = type::Handle(isolate); \ |
| 1671 array ^= obj.raw(); \ | 1751 array ^= obj.raw(); \ |
| 1672 *len = array.Length(); \ | 1752 *len = array.Length(); \ |
| 1673 return Api::Success(isolate); \ | 1753 return Api::Success(isolate); \ |
| 1674 | 1754 |
| 1675 | 1755 |
| 1676 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1756 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 1677 Isolate* isolate = Isolate::Current(); | 1757 Isolate* isolate = Isolate::Current(); |
| 1678 DARTSCOPE(isolate); | 1758 DARTSCOPE(isolate); |
| 1679 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1759 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1760 if (obj.IsError()) { |
| 1761 // Pass through errors. |
| 1762 return list; |
| 1763 } |
| 1680 if (obj.IsByteArray()) { | 1764 if (obj.IsByteArray()) { |
| 1681 GET_LIST_LENGTH(isolate, ByteArray, obj, len); | 1765 GET_LIST_LENGTH(isolate, ByteArray, obj, len); |
| 1682 } | 1766 } |
| 1683 if (obj.IsArray()) { | 1767 if (obj.IsArray()) { |
| 1684 GET_LIST_LENGTH(isolate, Array, obj, len); | 1768 GET_LIST_LENGTH(isolate, Array, obj, len); |
| 1685 } | 1769 } |
| 1686 if (obj.IsGrowableObjectArray()) { | 1770 if (obj.IsGrowableObjectArray()) { |
| 1687 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); | 1771 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); |
| 1688 } | 1772 } |
| 1689 // Now check and handle a dart object that implements the List interface. | 1773 // Now check and handle a dart object that implements the List interface. |
| 1690 const Instance& instance = | 1774 const Instance& instance = |
| 1691 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1775 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1692 if (instance.IsNull()) { | 1776 if (instance.IsNull()) { |
| 1693 return Api::NewError("Object does not implement the List inteface"); | 1777 return Api::NewError("Object does not implement the List interface"); |
| 1694 } | 1778 } |
| 1695 String& name = String::Handle(isolate, String::New("length")); | 1779 String& name = String::Handle(isolate, String::New("length")); |
| 1696 name = Field::GetterName(name); | 1780 name = Field::GetterName(name); |
| 1697 const Function& function = | 1781 const Function& function = |
| 1698 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1782 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
| 1699 if (function.IsNull()) { | 1783 if (function.IsNull()) { |
| 1700 return Api::NewError("List object does not have a 'length' field."); | 1784 return Api::NewError("List object does not have a 'length' field."); |
| 1701 } | 1785 } |
| 1702 | 1786 |
| 1703 GrowableArray<const Object*> args(0); | 1787 GrowableArray<const Object*> args(0); |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { | 2364 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { |
| 2281 Isolate* isolate = Isolate::Current(); | 2365 Isolate* isolate = Isolate::Current(); |
| 2282 DARTSCOPE(isolate); | 2366 DARTSCOPE(isolate); |
| 2283 const Closure& obj = | 2367 const Closure& obj = |
| 2284 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object)); | 2368 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object)); |
| 2285 const Integer& smrck = Integer::Handle(isolate, Integer::New(value)); | 2369 const Integer& smrck = Integer::Handle(isolate, Integer::New(value)); |
| 2286 obj.set_smrck(smrck); | 2370 obj.set_smrck(smrck); |
| 2287 } | 2371 } |
| 2288 | 2372 |
| 2289 | 2373 |
| 2374 // --- Classes and Interfaces --- |
| 2375 |
| 2376 |
| 2377 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { |
| 2378 Isolate* isolate = Isolate::Current(); |
| 2379 DARTSCOPE(isolate); |
| 2380 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 2381 if (obj.IsClass()) { |
| 2382 Class& cls = Class::Handle(isolate); |
| 2383 cls ^= obj.raw(); |
| 2384 return !cls.is_interface(); |
| 2385 } |
| 2386 return false; |
| 2387 } |
| 2388 |
| 2389 |
| 2390 DART_EXPORT bool Dart_IsInterface(Dart_Handle handle) { |
| 2391 Isolate* isolate = Isolate::Current(); |
| 2392 DARTSCOPE(isolate); |
| 2393 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 2394 if (obj.IsClass()) { |
| 2395 Class& cls = Class::Handle(isolate); |
| 2396 cls ^= obj.raw(); |
| 2397 return cls.is_interface(); |
| 2398 } |
| 2399 return false; |
| 2400 } |
| 2401 |
| 2402 |
| 2403 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { |
| 2404 Isolate* isolate = Isolate::Current(); |
| 2405 DARTSCOPE(isolate); |
| 2406 Class& cls = Class::Handle(isolate); |
| 2407 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); |
| 2408 if (cls.IsNull()) { |
| 2409 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2410 } |
| 2411 return Api::NewHandle(isolate, cls.Name()); |
| 2412 } |
| 2413 |
| 2414 |
| 2415 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { |
| 2416 Isolate* isolate = Isolate::Current(); |
| 2417 DARTSCOPE(isolate); |
| 2418 Class& cls = Class::Handle(isolate); |
| 2419 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); |
| 2420 if (cls.IsNull()) { |
| 2421 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2422 } |
| 2423 return Api::NewHandle(isolate, cls.library()); |
| 2424 } |
| 2425 |
| 2426 |
| 2427 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { |
| 2428 Isolate* isolate = Isolate::Current(); |
| 2429 DARTSCOPE(isolate); |
| 2430 Class& cls = Class::Handle(isolate); |
| 2431 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); |
| 2432 if (cls.IsNull()) { |
| 2433 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2434 } |
| 2435 |
| 2436 // Finalize all classes. |
| 2437 const char* msg = CheckIsolateState(isolate); |
| 2438 if (msg != NULL) { |
| 2439 return Api::NewError(msg); |
| 2440 } |
| 2441 |
| 2442 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { |
| 2443 return Api::NewHandle(isolate, cls.FactoryClass()); |
| 2444 } |
| 2445 return Api::Null(isolate); |
| 2446 } |
| 2447 |
| 2448 |
| 2449 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, |
| 2450 intptr_t* count) { |
| 2451 Isolate* isolate = Isolate::Current(); |
| 2452 DARTSCOPE(isolate); |
| 2453 Class& cls = Class::Handle(isolate); |
| 2454 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); |
| 2455 if (cls.IsNull()) { |
| 2456 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2457 } |
| 2458 |
| 2459 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); |
| 2460 if (interface_types.IsNull()) { |
| 2461 *count = 0; |
| 2462 } else { |
| 2463 *count = interface_types.Length(); |
| 2464 } |
| 2465 return Api::Success(isolate); |
| 2466 } |
| 2467 |
| 2468 |
| 2469 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, |
| 2470 intptr_t index) { |
| 2471 Isolate* isolate = Isolate::Current(); |
| 2472 DARTSCOPE(isolate); |
| 2473 Class& cls = Class::Handle(isolate); |
| 2474 cls ^= Api::UnwrapClassHandle(isolate, clazz).raw(); |
| 2475 if (cls.IsNull()) { |
| 2476 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 2477 } |
| 2478 |
| 2479 // Finalize all classes. |
| 2480 const char* msg = CheckIsolateState(isolate); |
| 2481 if (msg != NULL) { |
| 2482 return Api::NewError(msg); |
| 2483 } |
| 2484 |
| 2485 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); |
| 2486 if (index < 0 || index >= interface_types.Length()) { |
| 2487 return Api::NewError("%s: argument 'index' out of bounds.", CURRENT_FUNC); |
| 2488 } |
| 2489 Type& interface_type = Type::Handle(isolate); |
| 2490 interface_type ^= interface_types.At(index); |
| 2491 if (interface_type.HasResolvedTypeClass()) { |
| 2492 return Api::NewHandle(isolate, interface_type.type_class()); |
| 2493 } |
| 2494 const String& type_name = |
| 2495 String::Handle(isolate, interface_type.TypeClassName()); |
| 2496 return Api::NewError("%s: internal error: found unresolved type class '%s'.", |
| 2497 CURRENT_FUNC, type_name.ToCString()); |
| 2498 } |
| 2499 |
| 2500 |
| 2290 // --- Constructors, Methods, and Fields --- | 2501 // --- Constructors, Methods, and Fields --- |
| 2291 | 2502 |
| 2292 | 2503 |
| 2293 static RawObject* ResolveConstructor(const char* current_func, | 2504 static RawObject* ResolveConstructor(const char* current_func, |
| 2294 const Class& cls, | 2505 const Class& cls, |
| 2295 const String& class_name, | 2506 const String& class_name, |
| 2296 const String& dotted_name, | 2507 const String& dotted_name, |
| 2297 int num_args) { | 2508 int num_args) { |
| 2298 // The constructor must be present in the interface. | 2509 // The constructor must be present in the interface. |
| 2299 String& constr_name = String::Handle(String::Concat(class_name, dotted_name)); | 2510 String& constr_name = String::Handle(String::Concat(class_name, dotted_name)); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2438 args.Add(&TypeArguments::Handle(isolate)); | 2649 args.Add(&TypeArguments::Handle(isolate)); |
| 2439 } | 2650 } |
| 2440 for (int i = 0; i < number_of_arguments; i++) { | 2651 for (int i = 0; i < number_of_arguments; i++) { |
| 2441 const Object& arg = | 2652 const Object& arg = |
| 2442 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2653 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
| 2443 if (!arg.IsNull() && !arg.IsInstance()) { | 2654 if (!arg.IsNull() && !arg.IsInstance()) { |
| 2444 if (arg.IsError()) { | 2655 if (arg.IsError()) { |
| 2445 return Api::NewHandle(isolate, arg.raw()); | 2656 return Api::NewHandle(isolate, arg.raw()); |
| 2446 } else { | 2657 } else { |
| 2447 return Api::NewError( | 2658 return Api::NewError( |
| 2448 "%s expects argument %d to be an instance of Object.", | 2659 "%s expects arguments[%d] to be an Instance handle.", |
| 2449 CURRENT_FUNC, i); | 2660 CURRENT_FUNC, i); |
| 2450 } | 2661 } |
| 2451 } | 2662 } |
| 2452 args.Add(&arg); | 2663 args.Add(&arg); |
| 2453 } | 2664 } |
| 2454 | 2665 |
| 2455 // Invoke the constructor and return the new object. | 2666 // Invoke the constructor and return the new object. |
| 2456 const Array& kNoArgNames = Array::Handle(isolate); | 2667 const Array& kNoArgNames = Array::Handle(isolate); |
| 2457 result = DartEntry::InvokeStatic(constructor, args, kNoArgNames); | 2668 result = DartEntry::InvokeStatic(constructor, args, kNoArgNames); |
| 2458 if (result.IsError()) { | 2669 if (result.IsError()) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2488 // Check for malformed arguments in the arguments list. | 2699 // Check for malformed arguments in the arguments list. |
| 2489 GrowableArray<const Object*> args(number_of_arguments); | 2700 GrowableArray<const Object*> args(number_of_arguments); |
| 2490 for (int i = 0; i < number_of_arguments; i++) { | 2701 for (int i = 0; i < number_of_arguments; i++) { |
| 2491 const Object& arg = | 2702 const Object& arg = |
| 2492 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2703 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
| 2493 if (!arg.IsNull() && !arg.IsInstance()) { | 2704 if (!arg.IsNull() && !arg.IsInstance()) { |
| 2494 if (arg.IsError()) { | 2705 if (arg.IsError()) { |
| 2495 return Api::NewHandle(isolate, arg.raw()); | 2706 return Api::NewHandle(isolate, arg.raw()); |
| 2496 } else { | 2707 } else { |
| 2497 return Api::NewError( | 2708 return Api::NewError( |
| 2498 "%s expects argument %d to be an instance of Object.", | 2709 "%s expects arguments[%d] to be an Instance handle.", |
| 2499 CURRENT_FUNC, i); | 2710 CURRENT_FUNC, i); |
| 2500 } | 2711 } |
| 2501 } | 2712 } |
| 2502 args.Add(&arg); | 2713 args.Add(&arg); |
| 2503 } | 2714 } |
| 2504 | 2715 |
| 2505 const Array& kNoArgNames = Array::Handle(isolate); | 2716 const Array& kNoArgNames = Array::Handle(isolate); |
| 2506 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 2717 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 2507 if (obj.IsError()) { | 2718 if (obj.IsError()) { |
| 2508 return target; | 2719 return target; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3242 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3453 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3243 if (lib.IsNull()) { | 3454 if (lib.IsNull()) { |
| 3244 RETURN_TYPE_ERROR(isolate, library, Library); | 3455 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3245 } | 3456 } |
| 3246 const String& url = String::Handle(isolate, lib.url()); | 3457 const String& url = String::Handle(isolate, lib.url()); |
| 3247 ASSERT(!url.IsNull()); | 3458 ASSERT(!url.IsNull()); |
| 3248 return Api::NewHandle(isolate, url.raw()); | 3459 return Api::NewHandle(isolate, url.raw()); |
| 3249 } | 3460 } |
| 3250 | 3461 |
| 3251 | 3462 |
| 3463 DART_EXPORT Dart_Handle Dart_LibraryGetClassNames(Dart_Handle library) { |
| 3464 Isolate* isolate = Isolate::Current(); |
| 3465 DARTSCOPE(isolate); |
| 3466 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3467 if (lib.IsNull()) { |
| 3468 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3469 } |
| 3470 |
| 3471 const GrowableObjectArray& names = |
| 3472 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); |
| 3473 ClassDictionaryIterator it(lib); |
| 3474 Class& cls = Class::Handle(); |
| 3475 String& name = String::Handle(); |
| 3476 while (it.HasNext()) { |
| 3477 cls = it.GetNextClass(); |
| 3478 name = cls.Name(); |
| 3479 names.Add(name); |
| 3480 } |
| 3481 return Api::NewHandle(isolate, Array::MakeArray(names)); |
| 3482 } |
| 3483 |
| 3484 |
| 3252 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 3485 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
| 3253 Isolate* isolate = Isolate::Current(); | 3486 Isolate* isolate = Isolate::Current(); |
| 3254 DARTSCOPE(isolate); | 3487 DARTSCOPE(isolate); |
| 3255 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 3488 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 3256 if (url_str.IsNull()) { | 3489 if (url_str.IsNull()) { |
| 3257 RETURN_TYPE_ERROR(isolate, url, String); | 3490 RETURN_TYPE_ERROR(isolate, url, String); |
| 3258 } | 3491 } |
| 3259 const Library& library = | 3492 const Library& library = |
| 3260 Library::Handle(isolate, Library::LookupLibrary(url_str)); | 3493 Library::Handle(isolate, Library::LookupLibrary(url_str)); |
| 3261 if (library.IsNull()) { | 3494 if (library.IsNull()) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3399 *buffer_size = 0; | 3632 *buffer_size = 0; |
| 3400 } | 3633 } |
| 3401 } | 3634 } |
| 3402 | 3635 |
| 3403 | 3636 |
| 3404 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { | 3637 DART_EXPORT void Dart_InitFlowGraphPrinting(FileWriterFunction function) { |
| 3405 Dart::set_flow_graph_writer(function); | 3638 Dart::set_flow_graph_writer(function); |
| 3406 } | 3639 } |
| 3407 | 3640 |
| 3408 } // namespace dart | 3641 } // namespace dart |
| OLD | NEW |