| 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 if (obj.IsNull()) { | 450 if (obj.IsNull()) { |
| 451 RETURN_TYPE_ERROR(isolate, exception, Instance); | 451 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 452 } | 452 } |
| 453 const Instance& stacktrace = Instance::Handle(isolate); | 453 const Instance& stacktrace = Instance::Handle(isolate); |
| 454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); | 454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); |
| 455 } | 455 } |
| 456 | 456 |
| 457 | 457 |
| 458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 459 Isolate* isolate = Isolate::Current(); | 459 Isolate* isolate = Isolate::Current(); |
| 460 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 460 { |
| 461 if (!obj.IsError()) { | 461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 462 return Api::NewError( | 462 if (!obj.IsError()) { |
| 463 "%s expects argument 'handle' to be an error handle. " | 463 return Api::NewError( |
| 464 "Did you forget to check Dart_IsError first?", | 464 "%s expects argument 'handle' to be an error handle. " |
| 465 CURRENT_FUNC); | 465 "Did you forget to check Dart_IsError first?", |
| 466 CURRENT_FUNC); |
| 467 } |
| 466 } | 468 } |
| 467 if (isolate->top_exit_frame_info() == 0) { | 469 if (isolate->top_exit_frame_info() == 0) { |
| 468 // There are no dart frames on the stack so it would be illegal to | 470 // There are no dart frames on the stack so it would be illegal to |
| 469 // propagate an error here. | 471 // propagate an error here. |
| 470 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 472 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
| 471 } | 473 } |
| 472 | 474 |
| 473 // Unwind all the API scopes till the exit frame before propagating. | 475 // Unwind all the API scopes till the exit frame before propagating. |
| 474 ApiState* state = isolate->api_state(); | 476 ApiState* state = isolate->api_state(); |
| 475 ASSERT(state != NULL); | 477 ASSERT(state != NULL); |
| 476 const Error* error; | 478 const Error* error; |
| 477 { | 479 { |
| 478 // We need to preserve the error object across the destruction of zones | 480 // We need to preserve the error object across the destruction of zones |
| 479 // when the ApiScopes are unwound. By using NoGCScope, we can ensure | 481 // when the ApiScopes are unwound. By using NoGCScope, we can ensure |
| 480 // that GC won't touch the raw error object before creating a valid | 482 // that GC won't touch the raw error object before creating a valid |
| 481 // handle for it in the surviving zone. | 483 // handle for it in the surviving zone. |
| 482 NoGCScope no_gc; | 484 NoGCScope no_gc; |
| 483 RawError* raw_error = static_cast<RawError*>(Api::UnwrapHandle(handle)); | 485 RawError* raw_error = Api::UnwrapErrorHandle(isolate, handle).raw(); |
| 484 state->UnwindScopes(isolate->top_exit_frame_info()); | 486 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 485 error = &Error::Handle(isolate, raw_error); | 487 error = &Error::Handle(isolate, raw_error); |
| 486 } | 488 } |
| 487 Exceptions::PropagateError(*error); | 489 Exceptions::PropagateError(*error); |
| 488 UNREACHABLE(); | 490 UNREACHABLE(); |
| 489 return Api::NewError("Cannot reach here. Internal error."); | 491 return Api::NewError("Cannot reach here. Internal error."); |
| 490 } | 492 } |
| 491 | 493 |
| 492 | 494 |
| 493 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 495 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
| (...skipping 3425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3919 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3921 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3920 } | 3922 } |
| 3921 // Unwind all the API scopes till the exit frame before throwing an | 3923 // Unwind all the API scopes till the exit frame before throwing an |
| 3922 // exception. | 3924 // exception. |
| 3923 ApiState* state = isolate->api_state(); | 3925 ApiState* state = isolate->api_state(); |
| 3924 ASSERT(state != NULL); | 3926 ASSERT(state != NULL); |
| 3925 const Instance* saved_exception; | 3927 const Instance* saved_exception; |
| 3926 { | 3928 { |
| 3927 NoGCScope no_gc; | 3929 NoGCScope no_gc; |
| 3928 RawInstance* raw_exception = | 3930 RawInstance* raw_exception = |
| 3929 static_cast<RawInstance*>(Api::UnwrapHandle(exception)); | 3931 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| 3930 state->UnwindScopes(isolate->top_exit_frame_info()); | 3932 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3931 saved_exception = &Instance::Handle(raw_exception); | 3933 saved_exception = &Instance::Handle(raw_exception); |
| 3932 } | 3934 } |
| 3933 Exceptions::Throw(*saved_exception); | 3935 Exceptions::Throw(*saved_exception); |
| 3934 return Api::NewError("Exception was not thrown, internal error"); | 3936 return Api::NewError("Exception was not thrown, internal error"); |
| 3935 } | 3937 } |
| 3936 | 3938 |
| 3937 | 3939 |
| 3938 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 3940 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 3939 Dart_Handle stacktrace) { | 3941 Dart_Handle stacktrace) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3956 } | 3958 } |
| 3957 // Unwind all the API scopes till the exit frame before throwing an | 3959 // Unwind all the API scopes till the exit frame before throwing an |
| 3958 // exception. | 3960 // exception. |
| 3959 ApiState* state = isolate->api_state(); | 3961 ApiState* state = isolate->api_state(); |
| 3960 ASSERT(state != NULL); | 3962 ASSERT(state != NULL); |
| 3961 const Instance* saved_exception; | 3963 const Instance* saved_exception; |
| 3962 const Instance* saved_stacktrace; | 3964 const Instance* saved_stacktrace; |
| 3963 { | 3965 { |
| 3964 NoGCScope no_gc; | 3966 NoGCScope no_gc; |
| 3965 RawInstance* raw_exception = | 3967 RawInstance* raw_exception = |
| 3966 static_cast<RawInstance*>(Api::UnwrapHandle(exception)); | 3968 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| 3967 RawInstance* raw_stacktrace = | 3969 RawInstance* raw_stacktrace = |
| 3968 static_cast<RawInstance*>(Api::UnwrapHandle(stacktrace)); | 3970 Api::UnwrapInstanceHandle(isolate, stacktrace).raw(); |
| 3969 state->UnwindScopes(isolate->top_exit_frame_info()); | 3971 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3970 saved_exception = &Instance::Handle(raw_exception); | 3972 saved_exception = &Instance::Handle(raw_exception); |
| 3971 saved_stacktrace = &Instance::Handle(raw_stacktrace); | 3973 saved_stacktrace = &Instance::Handle(raw_stacktrace); |
| 3972 } | 3974 } |
| 3973 Exceptions::ReThrow(*saved_exception, *saved_stacktrace); | 3975 Exceptions::ReThrow(*saved_exception, *saved_stacktrace); |
| 3974 return Api::NewError("Exception was not re thrown, internal error"); | 3976 return Api::NewError("Exception was not re thrown, internal error"); |
| 3975 } | 3977 } |
| 3976 | 3978 |
| 3977 | 3979 |
| 3978 // --- Native functions --- | 3980 // --- Native functions --- |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4507 } | 4509 } |
| 4508 { | 4510 { |
| 4509 NoGCScope no_gc; | 4511 NoGCScope no_gc; |
| 4510 RawObject* raw_obj = obj.raw(); | 4512 RawObject* raw_obj = obj.raw(); |
| 4511 isolate->heap()->SetPeer(raw_obj, peer); | 4513 isolate->heap()->SetPeer(raw_obj, peer); |
| 4512 } | 4514 } |
| 4513 return Api::Success(isolate); | 4515 return Api::Success(isolate); |
| 4514 } | 4516 } |
| 4515 | 4517 |
| 4516 } // namespace dart | 4518 } // namespace dart |
| OLD | NEW |