| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| 11 #include "vm/class_finalizer.h" | 11 #include "vm/class_finalizer.h" |
| 12 #include "vm/compiler.h" | 12 #include "vm/compiler.h" |
| 13 #include "vm/dart.h" | 13 #include "vm/dart.h" |
| 14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
| 15 #include "vm/dart_api_message.h" | 15 #include "vm/dart_api_message.h" |
| 16 #include "vm/dart_api_state.h" | 16 #include "vm/dart_api_state.h" |
| 17 #include "vm/dart_entry.h" | 17 #include "vm/dart_entry.h" |
| 18 #include "vm/debugger.h" |
| 18 #include "vm/debuginfo.h" | 19 #include "vm/debuginfo.h" |
| 19 #include "vm/exceptions.h" | 20 #include "vm/exceptions.h" |
| 20 #include "vm/flags.h" | 21 #include "vm/flags.h" |
| 21 #include "vm/growable_array.h" | 22 #include "vm/growable_array.h" |
| 22 #include "vm/message.h" | 23 #include "vm/message.h" |
| 23 #include "vm/message_handler.h" | 24 #include "vm/message_handler.h" |
| 24 #include "vm/native_entry.h" | 25 #include "vm/native_entry.h" |
| 25 #include "vm/object.h" | 26 #include "vm/object.h" |
| 26 #include "vm/object_store.h" | 27 #include "vm/object_store.h" |
| 27 #include "vm/port.h" | 28 #include "vm/port.h" |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 const UnhandledException& error = UnhandledException::Cast(obj); | 369 const UnhandledException& error = UnhandledException::Cast(obj); |
| 369 return Api::NewHandle(isolate, error.exception()); | 370 return Api::NewHandle(isolate, error.exception()); |
| 370 } else if (obj.IsError()) { | 371 } else if (obj.IsError()) { |
| 371 return Api::NewError("This error is not an unhandled exception error."); | 372 return Api::NewError("This error is not an unhandled exception error."); |
| 372 } else { | 373 } else { |
| 373 return Api::NewError("Can only get exceptions from error handles."); | 374 return Api::NewError("Can only get exceptions from error handles."); |
| 374 } | 375 } |
| 375 } | 376 } |
| 376 | 377 |
| 377 | 378 |
| 378 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 379 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace( |
| 380 Dart_Handle handle, |
| 381 Dart_ExceptionStackTrace *trace) { |
| 379 Isolate* isolate = Isolate::Current(); | 382 Isolate* isolate = Isolate::Current(); |
| 380 DARTSCOPE(isolate); | 383 DARTSCOPE(isolate); |
| 381 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 384 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 382 if (obj.IsUnhandledException()) { | 385 if (obj.IsUnhandledException()) { |
| 383 const UnhandledException& error = UnhandledException::Cast(obj); | 386 const UnhandledException& error = UnhandledException::Cast(obj); |
| 384 return Api::NewHandle(isolate, error.stacktrace()); | 387 Stacktrace& dart_stacktrace = Stacktrace::Handle(isolate); |
| 388 dart_stacktrace ^= error.stacktrace(); |
| 389 if (dart_stacktrace.IsNull()) { |
| 390 *trace = NULL; |
| 391 } else { |
| 392 ExceptionStackTrace* cpp_stacktrace = |
| 393 dart_stacktrace.BuildExceptionStackTrace(); |
| 394 *trace = reinterpret_cast<Dart_ExceptionStackTrace>(cpp_stacktrace); |
| 395 } |
| 396 return Api::Success(); |
| 385 } else if (obj.IsError()) { | 397 } else if (obj.IsError()) { |
| 386 return Api::NewError("This error is not an unhandled exception error."); | 398 return Api::NewError("This error is not an unhandled exception error."); |
| 387 } else { | 399 } else { |
| 388 return Api::NewError("Can only get stacktraces from error handles."); | 400 return Api::NewError("Can only get stacktraces from error handles."); |
| 389 } | 401 } |
| 390 } | 402 } |
| 403 DART_EXPORT Dart_Handle Dart_CurrentStacktrace( |
| 404 Dart_ExceptionStackTrace *trace) { |
| 405 Isolate* isolate = Isolate::Current(); |
| 406 DARTSCOPE(isolate); |
| 407 ExceptionStackTrace* cpp_stacktrace = |
| 408 isolate->debugger()->BuildExceptionStackTrace(); |
| 409 *trace = reinterpret_cast<Dart_ExceptionStackTrace>(cpp_stacktrace); |
| 410 return Api::Success(); |
| 411 } |
| 412 |
| 413 |
| 414 DART_EXPORT Dart_Handle Dart_StacktraceLength(Dart_ExceptionStackTrace trace, |
| 415 intptr_t* length) { |
| 416 Isolate* isolate = Isolate::Current(); |
| 417 DARTSCOPE(isolate); |
| 418 if (trace == NULL) { |
| 419 return Api::NewError("%s expects argument 'trace' to be non-null.", |
| 420 CURRENT_FUNC); |
| 421 } |
| 422 ExceptionStackTrace *stack_trace = |
| 423 reinterpret_cast<ExceptionStackTrace*>(trace); |
| 424 if (length == NULL) { |
| 425 return Api::NewError("%s expects argument 'length' to be non-null.", |
| 426 CURRENT_FUNC); |
| 427 } |
| 428 *length = stack_trace->Length(); |
| 429 return Api::Success(); |
| 430 } |
| 431 |
| 432 |
| 433 DART_EXPORT Dart_Handle Dart_StacktraceFrameInfo( |
| 434 Dart_ExceptionStackTrace trace, |
| 435 intptr_t frame_index, |
| 436 Dart_Handle* function_name, |
| 437 Dart_Handle* script_url, |
| 438 intptr_t* line_number, |
| 439 intptr_t* col_number) { |
| 440 Isolate* isolate = Isolate::Current(); |
| 441 DARTSCOPE(isolate); |
| 442 if (trace == NULL) { |
| 443 return Api::NewError("%s expects argument 'trace' to be non-null.", |
| 444 CURRENT_FUNC); |
| 445 } |
| 446 ExceptionStackTrace *stack_trace = |
| 447 reinterpret_cast<ExceptionStackTrace*>(trace); |
| 448 if (frame_index < 0 || frame_index >= stack_trace->Length()) { |
| 449 return Api::NewError( |
| 450 "%s: frame index was out of bounds (%" Pd ")", |
| 451 CURRENT_FUNC, frame_index); |
| 452 } |
| 453 ExceptionStackFrame *frame = stack_trace->FrameAt(frame_index); |
| 454 if (function_name != NULL) { |
| 455 *function_name = Api::NewHandle(isolate, frame->function_name()); |
| 456 } |
| 457 if (script_url != NULL) { |
| 458 *script_url = Api::NewHandle(isolate, frame->script_uri()); |
| 459 } |
| 460 if (line_number != NULL) { |
| 461 *line_number = frame->line_number(); |
| 462 } |
| 463 if (col_number != NULL) { |
| 464 *col_number = frame->column_number(); |
| 465 } |
| 466 return Api::Success(); |
| 467 } |
| 391 | 468 |
| 392 | 469 |
| 393 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 470 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 394 // fix this but not sure if it available on all of our builds. | 471 // fix this but not sure if it available on all of our builds. |
| 395 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { | 472 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
| 396 Isolate* isolate = Isolate::Current(); | 473 Isolate* isolate = Isolate::Current(); |
| 397 DARTSCOPE(isolate); | 474 DARTSCOPE(isolate); |
| 398 CHECK_CALLBACK_STATE(isolate); | 475 CHECK_CALLBACK_STATE(isolate); |
| 399 | 476 |
| 400 const String& message = String::Handle(isolate, String::New(error)); | 477 const String& message = String::Handle(isolate, String::New(error)); |
| (...skipping 4027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4428 } | 4505 } |
| 4429 { | 4506 { |
| 4430 NoGCScope no_gc; | 4507 NoGCScope no_gc; |
| 4431 RawObject* raw_obj = obj.raw(); | 4508 RawObject* raw_obj = obj.raw(); |
| 4432 isolate->heap()->SetPeer(raw_obj, peer); | 4509 isolate->heap()->SetPeer(raw_obj, peer); |
| 4433 } | 4510 } |
| 4434 return Api::Success(); | 4511 return Api::Success(); |
| 4435 } | 4512 } |
| 4436 | 4513 |
| 4437 } // namespace dart | 4514 } // namespace dart |
| OLD | NEW |