Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
| index ef99695a4e31dfa328a75b49db5f2b66df15b2d8..fe121b45e6321948bd5f0591e15ea22f77bdc0f3 100644 |
| --- a/runtime/vm/dart_api_impl.cc |
| +++ b/runtime/vm/dart_api_impl.cc |
| @@ -200,7 +200,7 @@ Dart_Handle Api::NewError(const char* format, ...) { |
| intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| va_end(args); |
| - char* buffer = zone.Alloc<char>(len + 1); |
| + char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| va_list args2; |
| va_start(args2, format); |
| OS::VSNPrint(buffer, (len + 1), format, args2); |
| @@ -410,7 +410,7 @@ DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| va_end(args); |
| - char* buffer = zone.Alloc<char>(len + 1); |
| + char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| va_list args2; |
| va_start(args2, format); |
| OS::VSNPrint(buffer, (len + 1), format, args2); |
| @@ -432,7 +432,7 @@ DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
| intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| va_end(args); |
| - char* buffer = zone.Alloc<char>(len + 1); |
| + char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| va_list args2; |
| va_start(args2, format); |
| OS::VSNPrint(buffer, (len + 1), format, args2); |
| @@ -457,13 +457,14 @@ DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| Isolate* isolate = Isolate::Current(); |
| - CHECK_ISOLATE(isolate); |
| - const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| - if (!obj.IsError()) { |
| - return Api::NewError( |
| - "%s expects argument 'handle' to be an error handle. " |
| - "Did you forget to check Dart_IsError first?", |
| - CURRENT_FUNC); |
| + { |
| + const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
|
Ivan Posva
2012/10/15 20:32:17
How about adding a comment explaining that we are
Tom Ball
2012/10/15 21:48:47
Done.
|
| + if (!obj.IsError()) { |
| + return Api::NewError( |
| + "%s expects argument 'handle' to be an error handle. " |
| + "Did you forget to check Dart_IsError first?", |
| + CURRENT_FUNC); |
| + } |
| } |
| if (isolate->top_exit_frame_info() == 0) { |
| // There are no dart frames on the stack so it would be illegal to |
| @@ -474,10 +475,15 @@ DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| // Unwind all the API scopes till the exit frame before propagating. |
| ApiState* state = isolate->api_state(); |
| ASSERT(state != NULL); |
| - state->UnwindScopes(isolate->top_exit_frame_info()); |
| - Exceptions::PropagateError(Error::Cast(obj)); |
| + Object* error; |
|
Ivan Posva
2012/10/15 20:32:17
How about Error*?Then you can avoid the cast below
Tom Ball
2012/10/15 21:48:47
Done.
|
| + { |
| + NoGCScope no_gc; |
|
Ivan Posva
2012/10/15 20:32:17
// We need to preserve the error object across the
Tom Ball
2012/10/15 21:48:47
Done.
|
| + RawObject* raw_obj = Api::UnwrapHandle(handle); |
| + state->UnwindScopes(isolate->top_exit_frame_info()); |
| + error = &Object::Handle(raw_obj); |
| + } |
| + Exceptions::PropagateError(Error::Cast(*error)); |
| UNREACHABLE(); |
| - |
| return Api::NewError("Cannot reach here. Internal error."); |
| } |
| @@ -1142,7 +1148,7 @@ DART_EXPORT void Dart_ExitScope() { |
| DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { |
| - ApiZone* zone; |
| + Zone* zone; |
| Isolate* isolate = Isolate::Current(); |
| if (isolate != NULL) { |
| ApiState* state = isolate->api_state(); |
| @@ -3897,10 +3903,12 @@ DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
| DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| Isolate* isolate = Isolate::Current(); |
| - DARTSCOPE(isolate); |
| - const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| - if (excp.IsNull()) { |
| - RETURN_TYPE_ERROR(isolate, exception, Instance); |
| + CHECK_ISOLATE(isolate); |
| + { |
| + const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| + if (excp.IsNull()) { |
| + RETURN_TYPE_ERROR(isolate, exception, Instance); |
| + } |
| } |
| if (isolate->top_exit_frame_info() == 0) { |
| // There are no dart frames on the stack so it would be illegal to |
| @@ -3911,7 +3919,15 @@ DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| // exception. |
| ApiState* state = isolate->api_state(); |
| ASSERT(state != NULL); |
| - state->UnwindScopes(isolate->top_exit_frame_info()); |
| + Object* exc; |
| + { |
| + NoGCScope no_gc; |
| + RawObject* raw_obj = Api::UnwrapHandle(exception); |
| + state->UnwindScopes(isolate->top_exit_frame_info()); |
| + exc = &Object::Handle(raw_obj); |
| + } |
| + Exceptions::PropagateError(Error::Cast(*exc)); |
|
Ivan Posva
2012/10/15 20:32:17
?
Tom Ball
2012/10/15 21:48:47
Removed.
|
| + const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
|
Ivan Posva
2012/10/15 20:32:17
The exception handle is very likely invalid at thi
Tom Ball
2012/10/15 21:48:47
Fixed reference.
|
| Exceptions::Throw(excp); |
| return Api::NewError("Exception was not thrown, internal error"); |
| } |
| @@ -3921,14 +3937,15 @@ DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| Dart_Handle stacktrace) { |
| Isolate* isolate = Isolate::Current(); |
| CHECK_ISOLATE(isolate); |
| - DARTSCOPE(isolate); |
| - const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| - if (excp.IsNull()) { |
| - RETURN_TYPE_ERROR(isolate, exception, Instance); |
| - } |
| - const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); |
| - if (stk.IsNull()) { |
| - RETURN_TYPE_ERROR(isolate, stacktrace, Instance); |
| + { |
| + const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| + if (excp.IsNull()) { |
| + RETURN_TYPE_ERROR(isolate, exception, Instance); |
| + } |
| + const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); |
| + if (stk.IsNull()) { |
| + RETURN_TYPE_ERROR(isolate, stacktrace, Instance); |
| + } |
| } |
| if (isolate->top_exit_frame_info() == 0) { |
| // There are no dart frames on the stack so it would be illegal to |
| @@ -3939,7 +3956,18 @@ DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| // exception. |
| ApiState* state = isolate->api_state(); |
| ASSERT(state != NULL); |
| - state->UnwindScopes(isolate->top_exit_frame_info()); |
| + Object* exc; |
| + Object* stk_trace; |
| + { |
| + NoGCScope no_gc; |
| + RawObject* raw_exception = Api::UnwrapHandle(exception); |
| + RawObject* raw_stacktrace = Api::UnwrapHandle(stacktrace); |
| + state->UnwindScopes(isolate->top_exit_frame_info()); |
| + exc = &Object::Handle(raw_exception); |
| + stk_trace = &Object::Handle(raw_stacktrace); |
| + } |
| + const Instance& excp = Instance::Cast(*const_cast<Object*>(exc)); |
| + const Instance& stk = Instance::Cast(*const_cast<Object*>(stk_trace)); |
| Exceptions::ReThrow(excp, stk); |
| return Api::NewError("Exception was not re thrown, internal error"); |
| } |
| @@ -4423,7 +4451,7 @@ DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { |
| pprof_symbol_generator->WriteToMemory(debug_region); |
| *buffer_size = debug_region->size(); |
| if (*buffer_size != 0) { |
| - ApiZone* zone = Api::TopScope(isolate)->zone(); |
| + Zone* zone = Api::TopScope(isolate)->zone(); |
| *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); |
| memmove(*buffer, debug_region->data(), *buffer_size); |
| } else { |