| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // --- Handles --- | 285 // --- Handles --- |
| 286 | 286 |
| 287 | 287 |
| 288 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 288 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 289 DARTSCOPE(Isolate::Current()); | 289 DARTSCOPE(Isolate::Current()); |
| 290 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 290 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 291 return obj.IsError(); | 291 return obj.IsError(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 | 294 |
| 295 static const char* MakeUnhandledExceptionCString( | |
| 296 const UnhandledException& uhe) { | |
| 297 const Instance& exception = Instance::Handle(uhe.exception()); | |
| 298 Object& strtmp = Object::Handle(DartLibraryCalls::ToString(exception)); | |
| 299 const char* exc_str = | |
| 300 "<Received error while converting exception to string>"; | |
| 301 if (!strtmp.IsError()) { | |
| 302 exc_str = strtmp.ToCString(); | |
| 303 } | |
| 304 | |
| 305 const Instance& stack = Instance::Handle(uhe.stacktrace()); | |
| 306 strtmp = DartLibraryCalls::ToString(stack); | |
| 307 const char* stack_str = | |
| 308 "<Received error while converting stack trace to string>"; | |
| 309 if (!strtmp.IsError()) { | |
| 310 stack_str = strtmp.ToCString(); | |
| 311 } | |
| 312 | |
| 313 const char* format = "Unhandled exception:\n%s\n%s"; | |
| 314 int len = (strlen(exc_str) + strlen(stack_str) + strlen(format) | |
| 315 - 4 // Two '%s' | |
| 316 + 1); // '\0' | |
| 317 char* buffer = reinterpret_cast<char*>(Api::Allocate(len)); | |
| 318 OS::SNPrint(buffer, len, format, exc_str, stack_str); | |
| 319 return buffer; | |
| 320 } | |
| 321 | |
| 322 | |
| 323 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 295 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 324 DARTSCOPE(Isolate::Current()); | 296 DARTSCOPE(Isolate::Current()); |
| 325 | |
| 326 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 297 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 327 if (!obj.IsError()) { | 298 if (obj.IsError()) { |
| 299 Error& error = Error::Handle(); |
| 300 error ^= obj.raw(); |
| 301 const char* str = error.ToErrorCString(); |
| 302 intptr_t len = strlen(str) + 1; |
| 303 char* str_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 304 strncpy(str_copy, str, len); |
| 305 return str_copy; |
| 306 } else { |
| 328 return ""; | 307 return ""; |
| 329 } | 308 } |
| 330 if (obj.IsApiError()) { | |
| 331 ApiError& error = ApiError::Handle(); | |
| 332 error ^= obj.raw(); | |
| 333 const String& message = String::Handle(error.message()); | |
| 334 const char* msg = message.ToCString(); | |
| 335 intptr_t len = strlen(msg) + 1; | |
| 336 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | |
| 337 strncpy(msg_copy, msg, len); | |
| 338 return msg_copy; | |
| 339 } else if (obj.IsLanguageError()) { | |
| 340 LanguageError& error = LanguageError::Handle(); | |
| 341 error ^= obj.raw(); | |
| 342 const String& message = String::Handle(error.message()); | |
| 343 const char* msg = message.ToCString(); | |
| 344 intptr_t len = strlen(msg) + 1; | |
| 345 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | |
| 346 strncpy(msg_copy, msg, len); | |
| 347 return msg_copy; | |
| 348 } else if (obj.IsUnhandledException()) { | |
| 349 UnhandledException& error = UnhandledException::Handle(); | |
| 350 error ^= obj.raw(); | |
| 351 return MakeUnhandledExceptionCString(error); | |
| 352 } else if (obj.IsUnwindError()) { | |
| 353 UNIMPLEMENTED(); | |
| 354 return "<unimplemented>;"; | |
| 355 } else { | |
| 356 return "<Internal error in Dart_GetError: unexpected error type>"; | |
| 357 } | |
| 358 } | 309 } |
| 359 | 310 |
| 360 | 311 |
| 361 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 312 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
| 362 DARTSCOPE(Isolate::Current()); | 313 DARTSCOPE(Isolate::Current()); |
| 363 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 314 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 364 return obj.IsUnhandledException(); | 315 return obj.IsUnhandledException(); |
| 365 } | 316 } |
| 366 | 317 |
| 367 | 318 |
| (...skipping 2134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2502 } | 2453 } |
| 2503 delete debug_region; | 2454 delete debug_region; |
| 2504 } else { | 2455 } else { |
| 2505 *buffer = NULL; | 2456 *buffer = NULL; |
| 2506 *buffer_size = 0; | 2457 *buffer_size = 0; |
| 2507 } | 2458 } |
| 2508 } | 2459 } |
| 2509 | 2460 |
| 2510 | 2461 |
| 2511 } // namespace dart | 2462 } // namespace dart |
| OLD | NEW |