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

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

Issue 1410643008: Get rid of deprecated methods accessing mutator_thread_ instead of current thread (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/exceptions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 { 846 {
847 const Object& obj = Object::Handle(thread->zone(), 847 const Object& obj = Object::Handle(thread->zone(),
848 Api::UnwrapHandle(handle)); 848 Api::UnwrapHandle(handle));
849 if (!obj.IsError()) { 849 if (!obj.IsError()) {
850 return Api::NewError( 850 return Api::NewError(
851 "%s expects argument 'handle' to be an error handle. " 851 "%s expects argument 'handle' to be an error handle. "
852 "Did you forget to check Dart_IsError first?", 852 "Did you forget to check Dart_IsError first?",
853 CURRENT_FUNC); 853 CURRENT_FUNC);
854 } 854 }
855 } 855 }
856 if (isolate->top_exit_frame_info() == 0) { 856 if (thread->top_exit_frame_info() == 0) {
857 // There are no dart frames on the stack so it would be illegal to 857 // There are no dart frames on the stack so it would be illegal to
858 // propagate an error here. 858 // propagate an error here.
859 return Api::NewError("No Dart frames on stack, cannot propagate error."); 859 return Api::NewError("No Dart frames on stack, cannot propagate error.");
860 } 860 }
861 861
862 // Unwind all the API scopes till the exit frame before propagating. 862 // Unwind all the API scopes till the exit frame before propagating.
863 ApiState* state = isolate->api_state(); 863 ApiState* state = isolate->api_state();
864 ASSERT(state != NULL); 864 ASSERT(state != NULL);
865 const Error* error; 865 const Error* error;
866 { 866 {
867 // We need to preserve the error object across the destruction of zones 867 // We need to preserve the error object across the destruction of zones
868 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure 868 // when the ApiScopes are unwound. By using NoSafepointScope, we can ensure
869 // that GC won't touch the raw error object before creating a valid 869 // that GC won't touch the raw error object before creating a valid
870 // handle for it in the surviving zone. 870 // handle for it in the surviving zone.
871 NoSafepointScope no_safepoint; 871 NoSafepointScope no_safepoint;
872 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw(); 872 RawError* raw_error = Api::UnwrapErrorHandle(thread->zone(), handle).raw();
873 state->UnwindScopes(isolate->top_exit_frame_info()); 873 state->UnwindScopes(thread->top_exit_frame_info());
874 // Note that thread's zone is different here than at the beginning of this 874 // Note that thread's zone is different here than at the beginning of this
875 // function. 875 // function.
876 error = &Error::Handle(thread->zone(), raw_error); 876 error = &Error::Handle(thread->zone(), raw_error);
877 } 877 }
878 Exceptions::PropagateError(*error); 878 Exceptions::PropagateError(*error);
879 UNREACHABLE(); 879 UNREACHABLE();
880 return Api::NewError("Cannot reach here. Internal error."); 880 return Api::NewError("Cannot reach here. Internal error.");
881 } 881 }
882 882
883 883
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 Instance& exception = Instance::Handle(zone); 2877 Instance& exception = Instance::Handle(zone);
2878 exception = Instance::New(cls); 2878 exception = Instance::New(cls);
2879 const Array& args = Array::Handle(zone, Array::New(3)); 2879 const Array& args = Array::Handle(zone, Array::New(3));
2880 args.SetAt(0, exception); 2880 args.SetAt(0, exception);
2881 args.SetAt(1, Smi::Handle(zone, Smi::New(Function::kCtorPhaseAll))); 2881 args.SetAt(1, Smi::Handle(zone, Smi::New(Function::kCtorPhaseAll)));
2882 args.SetAt(2, String::Handle(String::New(exception_message))); 2882 args.SetAt(2, String::Handle(String::New(exception_message)));
2883 result = DartEntry::InvokeFunction(constructor, args); 2883 result = DartEntry::InvokeFunction(constructor, args);
2884 if (result.IsError()) return result.raw(); 2884 if (result.IsError()) return result.raw();
2885 ASSERT(result.IsNull()); 2885 ASSERT(result.IsNull());
2886 2886
2887 if (isolate->top_exit_frame_info() == 0) { 2887 if (thread->top_exit_frame_info() == 0) {
2888 // There are no dart frames on the stack so it would be illegal to 2888 // There are no dart frames on the stack so it would be illegal to
2889 // throw an exception here. 2889 // throw an exception here.
2890 const String& message = String::Handle( 2890 const String& message = String::Handle(
2891 String::New("No Dart frames on stack, cannot throw exception")); 2891 String::New("No Dart frames on stack, cannot throw exception"));
2892 return ApiError::New(message); 2892 return ApiError::New(message);
2893 } 2893 }
2894 // Unwind all the API scopes till the exit frame before throwing an 2894 // Unwind all the API scopes till the exit frame before throwing an
2895 // exception. 2895 // exception.
2896 ApiState* state = isolate->api_state(); 2896 ApiState* state = isolate->api_state();
2897 ASSERT(state != NULL); 2897 ASSERT(state != NULL);
2898 const Instance* saved_exception; 2898 const Instance* saved_exception;
2899 { 2899 {
2900 NoSafepointScope no_safepoint; 2900 NoSafepointScope no_safepoint;
2901 RawInstance* raw_exception = exception.raw(); 2901 RawInstance* raw_exception = exception.raw();
2902 state->UnwindScopes(isolate->top_exit_frame_info()); 2902 state->UnwindScopes(thread->top_exit_frame_info());
2903 saved_exception = &Instance::Handle(raw_exception); 2903 saved_exception = &Instance::Handle(raw_exception);
2904 } 2904 }
2905 Exceptions::Throw(thread, *saved_exception); 2905 Exceptions::Throw(thread, *saved_exception);
2906 const String& message = String::Handle( 2906 const String& message = String::Handle(
2907 String::New("Exception was not thrown, internal error")); 2907 String::New("Exception was not thrown, internal error"));
2908 return ApiError::New(message); 2908 return ApiError::New(message);
2909 } 2909 }
2910 2910
2911 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. 2911 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling.
2912 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ 2912 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
4513 Zone* zone = thread->zone(); 4513 Zone* zone = thread->zone();
4514 Isolate* isolate = thread->isolate(); 4514 Isolate* isolate = thread->isolate();
4515 CHECK_ISOLATE(isolate); 4515 CHECK_ISOLATE(isolate);
4516 CHECK_CALLBACK_STATE(thread); 4516 CHECK_CALLBACK_STATE(thread);
4517 { 4517 {
4518 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); 4518 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
4519 if (excp.IsNull()) { 4519 if (excp.IsNull()) {
4520 RETURN_TYPE_ERROR(zone, exception, Instance); 4520 RETURN_TYPE_ERROR(zone, exception, Instance);
4521 } 4521 }
4522 } 4522 }
4523 if (isolate->top_exit_frame_info() == 0) { 4523 if (thread->top_exit_frame_info() == 0) {
4524 // There are no dart frames on the stack so it would be illegal to 4524 // There are no dart frames on the stack so it would be illegal to
4525 // throw an exception here. 4525 // throw an exception here.
4526 return Api::NewError("No Dart frames on stack, cannot throw exception"); 4526 return Api::NewError("No Dart frames on stack, cannot throw exception");
4527 } 4527 }
4528 4528
4529 // Unwind all the API scopes till the exit frame before throwing an 4529 // Unwind all the API scopes till the exit frame before throwing an
4530 // exception. 4530 // exception.
4531 ApiState* state = isolate->api_state(); 4531 ApiState* state = isolate->api_state();
4532 ASSERT(state != NULL); 4532 ASSERT(state != NULL);
4533 const Instance* saved_exception; 4533 const Instance* saved_exception;
4534 { 4534 {
4535 NoSafepointScope no_safepoint; 4535 NoSafepointScope no_safepoint;
4536 RawInstance* raw_exception = 4536 RawInstance* raw_exception =
4537 Api::UnwrapInstanceHandle(zone, exception).raw(); 4537 Api::UnwrapInstanceHandle(zone, exception).raw();
4538 state->UnwindScopes(isolate->top_exit_frame_info()); 4538 state->UnwindScopes(thread->top_exit_frame_info());
4539 saved_exception = &Instance::Handle(raw_exception); 4539 saved_exception = &Instance::Handle(raw_exception);
4540 } 4540 }
4541 Exceptions::Throw(thread, *saved_exception); 4541 Exceptions::Throw(thread, *saved_exception);
4542 return Api::NewError("Exception was not thrown, internal error"); 4542 return Api::NewError("Exception was not thrown, internal error");
4543 } 4543 }
4544 4544
4545 4545
4546 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 4546 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
4547 Dart_Handle stacktrace) { 4547 Dart_Handle stacktrace) {
4548 Thread* thread = Thread::Current(); 4548 Thread* thread = Thread::Current();
4549 Zone* zone = thread->zone(); 4549 Zone* zone = thread->zone();
4550 Isolate* isolate = thread->isolate(); 4550 Isolate* isolate = thread->isolate();
4551 CHECK_ISOLATE(isolate); 4551 CHECK_ISOLATE(isolate);
4552 CHECK_CALLBACK_STATE(thread); 4552 CHECK_CALLBACK_STATE(thread);
4553 { 4553 {
4554 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); 4554 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception);
4555 if (excp.IsNull()) { 4555 if (excp.IsNull()) {
4556 RETURN_TYPE_ERROR(zone, exception, Instance); 4556 RETURN_TYPE_ERROR(zone, exception, Instance);
4557 } 4557 }
4558 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace); 4558 const Instance& stk = Api::UnwrapInstanceHandle(zone, stacktrace);
4559 if (stk.IsNull()) { 4559 if (stk.IsNull()) {
4560 RETURN_TYPE_ERROR(zone, stacktrace, Instance); 4560 RETURN_TYPE_ERROR(zone, stacktrace, Instance);
4561 } 4561 }
4562 } 4562 }
4563 if (isolate->top_exit_frame_info() == 0) { 4563 if (thread->top_exit_frame_info() == 0) {
4564 // There are no dart frames on the stack so it would be illegal to 4564 // There are no dart frames on the stack so it would be illegal to
4565 // throw an exception here. 4565 // throw an exception here.
4566 return Api::NewError("No Dart frames on stack, cannot throw exception"); 4566 return Api::NewError("No Dart frames on stack, cannot throw exception");
4567 } 4567 }
4568 4568
4569 // Unwind all the API scopes till the exit frame before throwing an 4569 // Unwind all the API scopes till the exit frame before throwing an
4570 // exception. 4570 // exception.
4571 ApiState* state = isolate->api_state(); 4571 ApiState* state = isolate->api_state();
4572 ASSERT(state != NULL); 4572 ASSERT(state != NULL);
4573 const Instance* saved_exception; 4573 const Instance* saved_exception;
4574 const Stacktrace* saved_stacktrace; 4574 const Stacktrace* saved_stacktrace;
4575 { 4575 {
4576 NoSafepointScope no_safepoint; 4576 NoSafepointScope no_safepoint;
4577 RawInstance* raw_exception = 4577 RawInstance* raw_exception =
4578 Api::UnwrapInstanceHandle(zone, exception).raw(); 4578 Api::UnwrapInstanceHandle(zone, exception).raw();
4579 RawStacktrace* raw_stacktrace = 4579 RawStacktrace* raw_stacktrace =
4580 Api::UnwrapStacktraceHandle(zone, stacktrace).raw(); 4580 Api::UnwrapStacktraceHandle(zone, stacktrace).raw();
4581 state->UnwindScopes(isolate->top_exit_frame_info()); 4581 state->UnwindScopes(thread->top_exit_frame_info());
4582 saved_exception = &Instance::Handle(raw_exception); 4582 saved_exception = &Instance::Handle(raw_exception);
4583 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace); 4583 saved_stacktrace = &Stacktrace::Handle(raw_stacktrace);
4584 } 4584 }
4585 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); 4585 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace);
4586 return Api::NewError("Exception was not re thrown, internal error"); 4586 return Api::NewError("Exception was not re thrown, internal error");
4587 } 4587 }
4588 4588
4589 4589
4590 // --- Native fields and functions --- 4590 // --- Native fields and functions ---
4591 4591
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
4961 (isolate->api_state()->IsValidWeakPersistentHandle(rval) || 4961 (isolate->api_state()->IsValidWeakPersistentHandle(rval) ||
4962 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval))); 4962 isolate->api_state()->IsValidPrologueWeakPersistentHandle(rval)));
4963 #endif 4963 #endif
4964 Api::SetWeakHandleReturnValue(arguments, rval); 4964 Api::SetWeakHandleReturnValue(arguments, rval);
4965 } 4965 }
4966 4966
4967 4967
4968 // --- Environment --- 4968 // --- Environment ---
4969 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { 4969 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) {
4970 Isolate* isolate = thread->isolate(); 4970 Isolate* isolate = thread->isolate();
4971 Scope api_scope(isolate); 4971 Scope api_scope(thread);
4972 Dart_EnvironmentCallback callback = isolate->environment_callback(); 4972 Dart_EnvironmentCallback callback = isolate->environment_callback();
4973 String& result = String::Handle(thread->zone()); 4973 String& result = String::Handle(thread->zone());
4974 if (callback != NULL) { 4974 if (callback != NULL) {
4975 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw())); 4975 Dart_Handle response = callback(Api::NewHandle(isolate, name.raw()));
4976 if (::Dart_IsString(response)) { 4976 if (::Dart_IsString(response)) {
4977 result ^= Api::UnwrapHandle(response); 4977 result ^= Api::UnwrapHandle(response);
4978 } else if (::Dart_IsError(response)) { 4978 } else if (::Dart_IsError(response)) {
4979 const Object& error = Object::Handle( 4979 const Object& error = Object::Handle(
4980 thread->zone(), Api::UnwrapHandle(response)); 4980 thread->zone(), Api::UnwrapHandle(response));
4981 Exceptions::ThrowArgumentError( 4981 Exceptions::ThrowArgumentError(
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
6088 ApiReallocate); 6088 ApiReallocate);
6089 writer.WriteFullSnapshot(); 6089 writer.WriteFullSnapshot();
6090 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); 6090 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize();
6091 *isolate_snapshot_size = writer.IsolateSnapshotSize(); 6091 *isolate_snapshot_size = writer.IsolateSnapshotSize();
6092 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); 6092 *instructions_snapshot_size = writer.InstructionsSnapshotSize();
6093 6093
6094 return Api::Success(); 6094 return Api::Success();
6095 } 6095 }
6096 6096
6097 } // namespace dart 6097 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/exceptions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698