OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 Dart_MessageNotifyCallback message_notify_callback) { | 758 Dart_MessageNotifyCallback message_notify_callback) { |
759 Isolate* isolate = Isolate::Current(); | 759 Isolate* isolate = Isolate::Current(); |
760 CHECK_ISOLATE(isolate); | 760 CHECK_ISOLATE(isolate); |
761 isolate->set_message_notify_callback(message_notify_callback); | 761 isolate->set_message_notify_callback(message_notify_callback); |
762 } | 762 } |
763 | 763 |
764 | 764 |
765 DART_EXPORT Dart_Handle Dart_RunLoop() { | 765 DART_EXPORT Dart_Handle Dart_RunLoop() { |
766 Isolate* isolate = Isolate::Current(); | 766 Isolate* isolate = Isolate::Current(); |
767 DARTSCOPE(isolate); | 767 DARTSCOPE(isolate); |
768 const Object& obj = Object::Handle(isolate->StandardRunLoop()); | 768 { |
| 769 SetIsolateScope set_scope(NULL); |
| 770 isolate->message_handler()->RunBlocking(Dart::thread_pool(), NULL, NULL); |
| 771 } |
| 772 const Object& obj = Object::Handle(isolate->object_store()->sticky_error()); |
| 773 isolate->object_store()->clear_sticky_error(); |
769 if (obj.IsError()) { | 774 if (obj.IsError()) { |
770 return Api::NewLocalHandle(obj); | 775 return Api::NewLocalHandle(obj); |
771 } | 776 } |
772 ASSERT(obj.IsNull()); | 777 ASSERT(obj.IsNull()); |
773 return Api::Success(); | 778 return Api::Success(); |
774 } | 779 } |
775 | 780 |
776 | 781 |
777 static RawInstance* DeserializeMessage(void* data) { | |
778 // Create a snapshot object using the buffer. | |
779 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | |
780 ASSERT(snapshot->IsMessageSnapshot()); | |
781 | |
782 // Read object back from the snapshot. | |
783 SnapshotReader reader(snapshot, Isolate::Current()); | |
784 Instance& instance = Instance::Handle(); | |
785 instance ^= reader.ReadObject(); | |
786 return instance.raw(); | |
787 } | |
788 | |
789 | |
790 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 782 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
791 Isolate* isolate = Isolate::Current(); | 783 Isolate* isolate = Isolate::Current(); |
792 // Process all OOB messages and at most one normal message. | 784 CHECK_ISOLATE(isolate); |
793 Message* message = NULL; | 785 if (!isolate->message_handler()->HandleNextMessage()) { |
794 Message::Priority priority = Message::kNormalPriority; | 786 Zone zone(isolate); |
795 do { | 787 HANDLESCOPE(isolate); |
796 DARTSCOPE(isolate); | 788 const Error& error = |
797 // TODO(turnidge): This code is duplicated elsewhere. Consolidate. | 789 Error::Handle(isolate->object_store()->sticky_error()); |
798 message = isolate->message_handler()->queue()->DequeueNoWait(); | 790 ASSERT(!error.IsNull()); |
799 if (message == NULL) { | 791 return Api::NewLocalHandle(error); |
800 break; | 792 } |
801 } | |
802 const Instance& msg = | |
803 Instance::Handle(DeserializeMessage(message->data())); | |
804 priority = message->priority(); | |
805 if (priority == Message::kOOBPriority) { | |
806 // For now the only OOB messages are Mirrors messages. | |
807 const Object& result = Object::Handle( | |
808 DartLibraryCalls::HandleMirrorsMessage( | |
809 message->dest_port(), message->reply_port(), msg)); | |
810 delete message; | |
811 if (result.IsError()) { | |
812 // TODO(turnidge): Propagating the error is probably wrong here. | |
813 return Api::NewLocalHandle(result); | |
814 } | |
815 ASSERT(result.IsNull()); | |
816 } else { | |
817 const Object& result = Object::Handle( | |
818 DartLibraryCalls::HandleMessage( | |
819 message->dest_port(), message->reply_port(), msg)); | |
820 delete message; | |
821 if (result.IsError()) { | |
822 return Api::NewLocalHandle(result); | |
823 } | |
824 ASSERT(result.IsNull()); | |
825 } | |
826 } while (priority >= Message::kOOBPriority); | |
827 return Api::Success(); | 793 return Api::Success(); |
828 } | 794 } |
829 | 795 |
830 | 796 |
831 DART_EXPORT bool Dart_HasLivePorts() { | 797 DART_EXPORT bool Dart_HasLivePorts() { |
832 Isolate* isolate = Isolate::Current(); | 798 Isolate* isolate = Isolate::Current(); |
833 ASSERT(isolate); | 799 ASSERT(isolate); |
834 return isolate->message_handler()->HasLivePorts(); | 800 return isolate->message_handler()->HasLivePorts(); |
835 } | 801 } |
836 | 802 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 if (handler == NULL) { | 856 if (handler == NULL) { |
891 OS::PrintErr("%s expects argument 'handler' to be non-null.", CURRENT_FUNC); | 857 OS::PrintErr("%s expects argument 'handler' to be non-null.", CURRENT_FUNC); |
892 return kIllegalPort; | 858 return kIllegalPort; |
893 } | 859 } |
894 // Start the native port without a current isolate. | 860 // Start the native port without a current isolate. |
895 IsolateSaver saver(Isolate::Current()); | 861 IsolateSaver saver(Isolate::Current()); |
896 Isolate::SetCurrent(NULL); | 862 Isolate::SetCurrent(NULL); |
897 | 863 |
898 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler); | 864 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler); |
899 Dart_Port port_id = PortMap::CreatePort(nmh); | 865 Dart_Port port_id = PortMap::CreatePort(nmh); |
900 nmh->StartWorker(); | 866 nmh->Run(Dart::thread_pool(), NULL, NULL); |
901 return port_id; | 867 return port_id; |
902 } | 868 } |
903 | 869 |
904 | 870 |
905 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { | 871 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { |
906 // Close the native port without a current isolate. | 872 // Close the native port without a current isolate. |
907 IsolateSaver saver(Isolate::Current()); | 873 IsolateSaver saver(Isolate::Current()); |
908 Isolate::SetCurrent(NULL); | 874 Isolate::SetCurrent(NULL); |
909 | 875 |
910 // TODO(turnidge): Check that the port is native before trying to close. | 876 // TODO(turnidge): Check that the port is native before trying to close. |
(...skipping 2347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3258 *buffer = NULL; | 3224 *buffer = NULL; |
3259 } | 3225 } |
3260 delete debug_region; | 3226 delete debug_region; |
3261 } else { | 3227 } else { |
3262 *buffer = NULL; | 3228 *buffer = NULL; |
3263 *buffer_size = 0; | 3229 *buffer_size = 0; |
3264 } | 3230 } |
3265 } | 3231 } |
3266 | 3232 |
3267 } // namespace dart | 3233 } // namespace dart |
OLD | NEW |