Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1663613002: Dart_SetReturnValue now accepts and propagates error handles. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "lib/stacktrace.h" 10 #include "lib/stacktrace.h"
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 (*callback)(isolate->init_callback_data(), object, peer); 726 (*callback)(isolate->init_callback_data(), object, peer);
727 ApiState* state = isolate->api_state(); 727 ApiState* state = isolate->api_state();
728 ASSERT(state != NULL); 728 ASSERT(state != NULL);
729 state->weak_persistent_handles().FreeHandle(handle); 729 state->weak_persistent_handles().FreeHandle(handle);
730 } 730 }
731 731
732 732
733 // --- Handles --- 733 // --- Handles ---
734 734
735 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { 735 DART_EXPORT bool Dart_IsError(Dart_Handle handle) {
736 return RawObject::IsErrorClassId(Api::ClassId(handle)); 736 return Api::IsError(handle);
737 } 737 }
738 738
739 739
740 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { 740 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) {
741 return Api::ClassId(object) == kApiErrorCid; 741 return Api::ClassId(object) == kApiErrorCid;
742 } 742 }
743 743
744 744
745 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { 745 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) {
746 return Api::ClassId(object) == kUnhandledExceptionCid; 746 return Api::ClassId(object) == kUnhandledExceptionCid;
(...skipping 3655 matching lines...) Expand 10 before | Expand all | Expand 10 after
4402 4402
4403 4403
4404 // --- Exceptions ---- 4404 // --- Exceptions ----
4405 4405
4406 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 4406 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
4407 Thread* thread = Thread::Current(); 4407 Thread* thread = Thread::Current();
4408 Zone* zone = thread->zone(); 4408 Zone* zone = thread->zone();
4409 Isolate* isolate = thread->isolate(); 4409 Isolate* isolate = thread->isolate();
4410 CHECK_ISOLATE(isolate); 4410 CHECK_ISOLATE(isolate);
4411 CHECK_CALLBACK_STATE(thread); 4411 CHECK_CALLBACK_STATE(thread);
4412 if (Api::IsError(exception)) {
4413 Dart_PropagateError(exception);
4414 }
4415
4412 { 4416 {
4413 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); 4417 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
4414 if (excp.IsNull()) { 4418 if (excp.IsNull()) {
4415 RETURN_TYPE_ERROR(zone, exception, Instance); 4419 RETURN_TYPE_ERROR(zone, exception, Instance);
4416 } 4420 }
4417 } 4421 }
4418 if (thread->top_exit_frame_info() == 0) { 4422 if (thread->top_exit_frame_info() == 0) {
4419 // There are no dart frames on the stack so it would be illegal to 4423 // There are no dart frames on the stack so it would be illegal to
4420 // throw an exception here. 4424 // throw an exception here.
4421 return Api::NewError("No Dart frames on stack, cannot throw exception"); 4425 return Api::NewError("No Dart frames on stack, cannot throw exception");
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4823 " type Double.", CURRENT_FUNC, index); 4827 " type Double.", CURRENT_FUNC, index);
4824 } 4828 }
4825 return Api::Success(); 4829 return Api::Success();
4826 } 4830 }
4827 4831
4828 4832
4829 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, 4833 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args,
4830 Dart_Handle retval) { 4834 Dart_Handle retval) {
4831 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4835 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4832 ASSERT(arguments->thread()->isolate() == Isolate::Current()); 4836 ASSERT(arguments->thread()->isolate() == Isolate::Current());
4833 if ((retval != Api::Null()) && (!Api::IsInstance(retval))) { 4837 if ((retval != Api::Null()) &&
4838 !Api::IsInstance(retval) &&
4839 !Api::IsError(retval)) {
4834 // Print the current stack trace to make the problematic caller 4840 // Print the current stack trace to make the problematic caller
4835 // easier to find. 4841 // easier to find.
4836 const Stacktrace& stacktrace = GetCurrentStacktrace(0); 4842 const Stacktrace& stacktrace = GetCurrentStacktrace(0);
4837 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); 4843 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString());
4838 4844
4839 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); 4845 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval));
4840 FATAL1("Return value check failed: saw '%s' expected a dart Instance.", 4846 FATAL1("Return value check failed: saw '%s' expected a dart Instance or "
4841 ret_obj.ToCString()); 4847 "an Error.", ret_obj.ToCString());
4842 } 4848 }
4843 ASSERT(retval != 0); 4849 ASSERT(retval != 0);
4844 Api::SetReturnValue(arguments, retval); 4850 Api::SetReturnValue(arguments, retval);
4845 } 4851 }
4846 4852
4847 4853
4848 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, 4854 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args,
4849 Dart_WeakPersistentHandle rval) { 4855 Dart_WeakPersistentHandle rval) {
4850 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); 4856 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args);
4851 #if defined(DEBUG) 4857 #if defined(DEBUG)
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
6012 return Api::Success(); 6018 return Api::Success();
6013 } 6019 }
6014 #endif // DART_PRECOMPILED_RUNTIME 6020 #endif // DART_PRECOMPILED_RUNTIME
6015 6021
6016 6022
6017 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { 6023 DART_EXPORT bool Dart_IsRunningPrecompiledCode() {
6018 return Dart::IsRunningPrecompiledCode(); 6024 return Dart::IsRunningPrecompiledCode();
6019 } 6025 }
6020 6026
6021 } // namespace dart 6027 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698