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 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 intptr_t len = (length); \ | 73 intptr_t len = (length); \ |
74 intptr_t max = (max_elements); \ | 74 intptr_t max = (max_elements); \ |
75 if (len < 0 || len > max) { \ | 75 if (len < 0 || len > max) { \ |
76 return Api::NewError( \ | 76 return Api::NewError( \ |
77 "%s expects argument '%s' to be in the range [0..%"Pd"].", \ | 77 "%s expects argument '%s' to be in the range [0..%"Pd"].", \ |
78 CURRENT_FUNC, #length, max); \ | 78 CURRENT_FUNC, #length, max); \ |
79 } \ | 79 } \ |
80 } while (0) | 80 } while (0) |
81 | 81 |
82 | 82 |
83 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { | |
84 *handle = Api::NewHandle( | |
85 isolate, Isolate::Current()->object_store()->sticky_error()); | |
86 } | |
87 | |
88 | |
89 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { | 83 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
90 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); | 84 LocalHandles* local_handles = Api::TopScope(isolate)->local_handles(); |
91 ASSERT(local_handles != NULL); | 85 ASSERT(local_handles != NULL); |
92 LocalHandle* ref = local_handles->AllocateHandle(); | 86 LocalHandle* ref = local_handles->AllocateHandle(); |
93 ref->set_raw(raw); | 87 ref->set_raw(raw); |
94 return reinterpret_cast<Dart_Handle>(ref); | 88 return reinterpret_cast<Dart_Handle>(ref); |
95 } | 89 } |
96 | 90 |
97 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 91 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
98 #if defined(DEBUG) | 92 #if defined(DEBUG) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ASSERT(state.IsValidPrologueWeakPersistentHandle(object)); | 146 ASSERT(state.IsValidPrologueWeakPersistentHandle(object)); |
153 return reinterpret_cast<FinalizablePersistentHandle*>(object); | 147 return reinterpret_cast<FinalizablePersistentHandle*>(object); |
154 } | 148 } |
155 | 149 |
156 | 150 |
157 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { | 151 Dart_Handle Api::CheckIsolateState(Isolate* isolate) { |
158 if (ClassFinalizer::FinalizePendingClasses() && | 152 if (ClassFinalizer::FinalizePendingClasses() && |
159 isolate->object_store()->PreallocateObjects()) { | 153 isolate->object_store()->PreallocateObjects()) { |
160 return Api::Success(isolate); | 154 return Api::Success(isolate); |
161 } | 155 } |
162 const Object& obj = Object::Handle(isolate->object_store()->sticky_error()); | 156 ASSERT(isolate->object_store()->sticky_error() != Object::null()); |
163 ASSERT(obj.IsError()); | 157 return Api::NewHandle(isolate, isolate->object_store()->sticky_error()); |
164 return Api::NewHandle(isolate, obj.raw()); | |
165 } | 158 } |
166 | 159 |
167 | 160 |
168 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 161 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
169 return reinterpret_cast<Dart_Isolate>(isolate); | 162 return reinterpret_cast<Dart_Isolate>(isolate); |
170 } | 163 } |
171 | 164 |
172 | 165 |
173 Dart_Handle Api::Success(Isolate* isolate) { | 166 Dart_Handle Api::Success(Isolate* isolate) { |
174 ASSERT(isolate != NULL); | 167 ASSERT(isolate != NULL); |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); | 958 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); |
966 ASSERT(data->monitor != NULL); | 959 ASSERT(data->monitor != NULL); |
967 MonitorLocker ml(data->monitor); | 960 MonitorLocker ml(data->monitor); |
968 data->done = true; | 961 data->done = true; |
969 ml.Notify(); | 962 ml.Notify(); |
970 } | 963 } |
971 | 964 |
972 | 965 |
973 DART_EXPORT Dart_Handle Dart_RunLoop() { | 966 DART_EXPORT Dart_Handle Dart_RunLoop() { |
974 Isolate* isolate = Isolate::Current(); | 967 Isolate* isolate = Isolate::Current(); |
975 | 968 CHECK_ISOLATE_SCOPE(isolate); |
976 DARTSCOPE(isolate); | |
977 CHECK_CALLBACK_STATE(isolate); | 969 CHECK_CALLBACK_STATE(isolate); |
978 Monitor monitor; | 970 Monitor monitor; |
979 MonitorLocker ml(&monitor); | 971 MonitorLocker ml(&monitor); |
980 { | 972 { |
981 SwitchIsolateScope switch_scope(NULL); | 973 SwitchIsolateScope switch_scope(NULL); |
982 | 974 |
983 RunLoopData data; | 975 RunLoopData data; |
984 data.monitor = &monitor; | 976 data.monitor = &monitor; |
985 data.done = false; | 977 data.done = false; |
986 isolate->message_handler()->Run( | 978 isolate->message_handler()->Run( |
987 Dart::thread_pool(), | 979 Dart::thread_pool(), |
988 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); | 980 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); |
989 while (!data.done) { | 981 while (!data.done) { |
990 ml.Wait(); | 982 ml.Wait(); |
991 } | 983 } |
992 } | 984 } |
993 const Object& obj = Object::Handle(isolate->object_store()->sticky_error()); | 985 if (isolate->object_store()->sticky_error() != Object::null()) { |
994 isolate->object_store()->clear_sticky_error(); | 986 Dart_Handle error = Api::NewHandle(isolate, |
995 if (obj.IsError()) { | 987 isolate->object_store()->sticky_error()); |
996 return Api::NewHandle(isolate, obj.raw()); | 988 isolate->object_store()->clear_sticky_error(); |
| 989 return error; |
997 } | 990 } |
998 ASSERT(obj.IsNull()); | |
999 if (FLAG_print_class_table) { | 991 if (FLAG_print_class_table) { |
1000 isolate->class_table()->Print(); | 992 isolate->class_table()->Print(); |
1001 } | 993 } |
1002 return Api::Success(isolate); | 994 return Api::Success(isolate); |
1003 } | 995 } |
1004 | 996 |
1005 | 997 |
1006 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 998 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
1007 Isolate* isolate = Isolate::Current(); | 999 Isolate* isolate = Isolate::Current(); |
1008 CHECK_ISOLATE(isolate); | 1000 CHECK_ISOLATE_SCOPE(isolate); |
| 1001 CHECK_CALLBACK_STATE(isolate); |
1009 if (!isolate->message_handler()->HandleNextMessage()) { | 1002 if (!isolate->message_handler()->HandleNextMessage()) { |
1010 Dart_Handle error = | 1003 Dart_Handle error = Api::NewHandle(isolate, |
1011 Api::NewHandle(isolate, isolate->object_store()->sticky_error()); | 1004 isolate->object_store()->sticky_error()); |
1012 isolate->object_store()->clear_sticky_error(); | 1005 isolate->object_store()->clear_sticky_error(); |
1013 return error; | 1006 return error; |
1014 } | 1007 } |
1015 return Api::Success(isolate); | 1008 return Api::Success(isolate); |
1016 } | 1009 } |
1017 | 1010 |
1018 | 1011 |
1019 DART_EXPORT bool Dart_HasLivePorts() { | 1012 DART_EXPORT bool Dart_HasLivePorts() { |
1020 Isolate* isolate = Isolate::Current(); | 1013 Isolate* isolate = Isolate::Current(); |
1021 ASSERT(isolate); | 1014 ASSERT(isolate); |
(...skipping 3793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4815 } | 4808 } |
4816 { | 4809 { |
4817 NoGCScope no_gc; | 4810 NoGCScope no_gc; |
4818 RawObject* raw_obj = obj.raw(); | 4811 RawObject* raw_obj = obj.raw(); |
4819 isolate->heap()->SetPeer(raw_obj, peer); | 4812 isolate->heap()->SetPeer(raw_obj, peer); |
4820 } | 4813 } |
4821 return Api::Success(isolate); | 4814 return Api::Success(isolate); |
4822 } | 4815 } |
4823 | 4816 |
4824 } // namespace dart | 4817 } // namespace dart |
OLD | NEW |