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 #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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
11 #include "vm/class_finalizer.h" | 11 #include "vm/class_finalizer.h" |
12 #include "vm/compiler.h" | 12 #include "vm/compiler.h" |
13 #include "vm/dart.h" | 13 #include "vm/dart.h" |
14 #include "vm/dart_api_impl.h" | 14 #include "vm/dart_api_impl.h" |
15 #include "vm/dart_api_message.h" | 15 #include "vm/dart_api_message.h" |
16 #include "vm/dart_api_state.h" | 16 #include "vm/dart_api_state.h" |
17 #include "vm/dart_entry.h" | 17 #include "vm/dart_entry.h" |
18 #include "vm/debuginfo.h" | 18 #include "vm/debuginfo.h" |
19 #include "vm/exceptions.h" | 19 #include "vm/exceptions.h" |
20 #include "vm/flags.h" | 20 #include "vm/flags.h" |
21 #include "vm/growable_array.h" | 21 #include "vm/growable_array.h" |
22 #include "vm/message.h" | 22 #include "vm/message.h" |
23 #include "vm/message_handler.h" | 23 #include "vm/message_handler.h" |
24 #include "vm/native_entry.h" | 24 #include "vm/native_entry.h" |
25 #include "vm/object.h" | 25 #include "vm/object.h" |
26 #include "vm/object_store.h" | 26 #include "vm/object_store.h" |
27 #include "vm/port.h" | 27 #include "vm/port.h" |
28 #include "vm/resolver.h" | 28 #include "vm/resolver.h" |
29 #include "vm/reusable_handles.h" | 29 #include "vm/reusable_handles.h" |
| 30 #include "vm/service.h" |
30 #include "vm/stack_frame.h" | 31 #include "vm/stack_frame.h" |
31 #include "vm/symbols.h" | 32 #include "vm/symbols.h" |
32 #include "vm/timer.h" | 33 #include "vm/timer.h" |
33 #include "vm/unicode.h" | 34 #include "vm/unicode.h" |
34 #include "vm/verifier.h" | 35 #include "vm/verifier.h" |
35 #include "vm/version.h" | 36 #include "vm/version.h" |
36 | 37 |
37 namespace dart { | 38 namespace dart { |
38 | 39 |
39 DECLARE_FLAG(bool, print_class_table); | 40 DECLARE_FLAG(bool, print_class_table); |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 | 787 |
787 DART_EXPORT bool Dart_Initialize( | 788 DART_EXPORT bool Dart_Initialize( |
788 Dart_IsolateCreateCallback create, | 789 Dart_IsolateCreateCallback create, |
789 Dart_IsolateInterruptCallback interrupt, | 790 Dart_IsolateInterruptCallback interrupt, |
790 Dart_IsolateUnhandledExceptionCallback unhandled, | 791 Dart_IsolateUnhandledExceptionCallback unhandled, |
791 Dart_IsolateShutdownCallback shutdown, | 792 Dart_IsolateShutdownCallback shutdown, |
792 Dart_FileOpenCallback file_open, | 793 Dart_FileOpenCallback file_open, |
793 Dart_FileReadCallback file_read, | 794 Dart_FileReadCallback file_read, |
794 Dart_FileWriteCallback file_write, | 795 Dart_FileWriteCallback file_write, |
795 Dart_FileCloseCallback file_close, | 796 Dart_FileCloseCallback file_close, |
796 Dart_EntropySource entropy_source) { | 797 Dart_EntropySource entropy_source, |
| 798 Dart_ServiceIsolateCreateCalback service_create) { |
797 const char* err_msg = Dart::InitOnce(create, interrupt, unhandled, shutdown, | 799 const char* err_msg = Dart::InitOnce(create, interrupt, unhandled, shutdown, |
798 file_open, file_read, file_write, | 800 file_open, file_read, file_write, |
799 file_close, entropy_source); | 801 file_close, entropy_source, |
| 802 service_create); |
800 if (err_msg != NULL) { | 803 if (err_msg != NULL) { |
801 OS::PrintErr("Dart_Initialize: %s\n", err_msg); | 804 OS::PrintErr("Dart_Initialize: %s\n", err_msg); |
802 return false; | 805 return false; |
803 } | 806 } |
804 return true; | 807 return true; |
805 } | 808 } |
806 | 809 |
807 | 810 |
808 DART_EXPORT bool Dart_Cleanup() { | 811 DART_EXPORT bool Dart_Cleanup() { |
809 CHECK_NO_ISOLATE(Isolate::Current()); | 812 CHECK_NO_ISOLATE(Isolate::Current()); |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1165 } |
1163 | 1166 |
1164 | 1167 |
1165 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1168 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
1166 Isolate* isolate = Isolate::Current(); | 1169 Isolate* isolate = Isolate::Current(); |
1167 CHECK_ISOLATE(isolate); | 1170 CHECK_ISOLATE(isolate); |
1168 return isolate->main_port(); | 1171 return isolate->main_port(); |
1169 } | 1172 } |
1170 | 1173 |
1171 | 1174 |
| 1175 DART_EXPORT Dart_Handle Dart_PostMessage(Dart_Handle send_port, |
| 1176 Dart_Handle object) { |
| 1177 Isolate* isolate = Isolate::Current(); |
| 1178 DARTSCOPE(isolate); |
| 1179 Instance& port_instance = Instance::Handle(); |
| 1180 port_instance ^= Api::UnwrapHandle(send_port); |
| 1181 if (!DartLibraryCalls::IsSendPort(port_instance)) { |
| 1182 return Api::NewError("send_port is not a SendPort."); |
| 1183 } |
| 1184 const Object& idObj = Object::Handle( |
| 1185 DartLibraryCalls::PortGetId(port_instance)); |
| 1186 ASSERT(!idObj.IsError()); |
| 1187 Integer& id = Integer::Handle(); |
| 1188 id ^= idObj.raw(); |
| 1189 Dart_Port port = static_cast<Dart_Port>(id.AsInt64Value()); |
| 1190 if (Dart_Post(port, object)) { |
| 1191 return Api::Success(); |
| 1192 } |
| 1193 return Api::NewError("Dart_Post failed."); |
| 1194 } |
| 1195 |
1172 // --- Scopes ---- | 1196 // --- Scopes ---- |
1173 | 1197 |
1174 DART_EXPORT void Dart_EnterScope() { | 1198 DART_EXPORT void Dart_EnterScope() { |
1175 Isolate* isolate = Isolate::Current(); | 1199 Isolate* isolate = Isolate::Current(); |
1176 CHECK_ISOLATE(isolate); | 1200 CHECK_ISOLATE(isolate); |
1177 ApiState* state = isolate->api_state(); | 1201 ApiState* state = isolate->api_state(); |
1178 ASSERT(state != NULL); | 1202 ASSERT(state != NULL); |
1179 ApiLocalScope* new_scope = state->reusable_scope(); | 1203 ApiLocalScope* new_scope = state->reusable_scope(); |
1180 if (new_scope == NULL) { | 1204 if (new_scope == NULL) { |
1181 new_scope = new ApiLocalScope(state->top_scope(), | 1205 new_scope = new ApiLocalScope(state->top_scope(), |
(...skipping 3306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4488 return Api::NewError(msg, CURRENT_FUNC); | 4512 return Api::NewError(msg, CURRENT_FUNC); |
4489 } | 4513 } |
4490 { | 4514 { |
4491 NoGCScope no_gc; | 4515 NoGCScope no_gc; |
4492 RawObject* raw_obj = obj.raw(); | 4516 RawObject* raw_obj = obj.raw(); |
4493 isolate->heap()->SetPeer(raw_obj, peer); | 4517 isolate->heap()->SetPeer(raw_obj, peer); |
4494 } | 4518 } |
4495 return Api::Success(); | 4519 return Api::Success(); |
4496 } | 4520 } |
4497 | 4521 |
| 4522 |
| 4523 // --- Service support --- |
| 4524 |
| 4525 DART_EXPORT Dart_Isolate Dart_GetServiceIsolate(void* callback_data) { |
| 4526 return Api::CastIsolate(Service::GetServiceIsolate(callback_data)); |
| 4527 } |
| 4528 |
4498 } // namespace dart | 4529 } // namespace dart |
OLD | NEW |