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_native_api.h" | 5 #include "include/dart_native_api.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_api_message.h" | 9 #include "vm/dart_api_message.h" |
10 #include "vm/dart_api_state.h" | 10 #include "vm/dart_api_state.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 if (name == NULL) { | 41 if (name == NULL) { |
42 name = "<UnnamedNativePort>"; | 42 name = "<UnnamedNativePort>"; |
43 } | 43 } |
44 if (handler == NULL) { | 44 if (handler == NULL) { |
45 OS::PrintErr("%s expects argument 'handler' to be non-null.\n", | 45 OS::PrintErr("%s expects argument 'handler' to be non-null.\n", |
46 CURRENT_FUNC); | 46 CURRENT_FUNC); |
47 return ILLEGAL_PORT; | 47 return ILLEGAL_PORT; |
48 } | 48 } |
49 // Start the native port without a current isolate. | 49 // Start the native port without a current isolate. |
50 IsolateSaver saver(Isolate::Current()); | 50 IsolateSaver saver(Isolate::Current()); |
51 Isolate::SetCurrent(NULL); | 51 Thread::ExitIsolate(); |
52 | 52 |
53 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler); | 53 NativeMessageHandler* nmh = new NativeMessageHandler(name, handler); |
54 Dart_Port port_id = PortMap::CreatePort(nmh); | 54 Dart_Port port_id = PortMap::CreatePort(nmh); |
55 nmh->Run(Dart::thread_pool(), NULL, NULL, 0); | 55 nmh->Run(Dart::thread_pool(), NULL, NULL, 0); |
56 return port_id; | 56 return port_id; |
57 } | 57 } |
58 | 58 |
59 | 59 |
60 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { | 60 DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id) { |
61 // Close the native port without a current isolate. | 61 // Close the native port without a current isolate. |
62 IsolateSaver saver(Isolate::Current()); | 62 IsolateSaver saver(Isolate::Current()); |
63 Isolate::SetCurrent(NULL); | 63 Thread::ExitIsolate(); |
64 | 64 |
65 // TODO(turnidge): Check that the port is native before trying to close. | 65 // TODO(turnidge): Check that the port is native before trying to close. |
66 return PortMap::ClosePort(native_port_id); | 66 return PortMap::ClosePort(native_port_id); |
67 } | 67 } |
68 | 68 |
69 | 69 |
70 // --- Verification tools --- | 70 // --- Verification tools --- |
71 | 71 |
72 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 72 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
73 ASSERT(isolate != NULL); | 73 ASSERT(isolate != NULL); |
(...skipping 12 matching lines...) Expand all Loading... |
86 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); | 86 Dart_Handle result = Api::CheckAndFinalizePendingClasses(isolate); |
87 if (::Dart_IsError(result)) { | 87 if (::Dart_IsError(result)) { |
88 return result; | 88 return result; |
89 } | 89 } |
90 CHECK_CALLBACK_STATE(isolate); | 90 CHECK_CALLBACK_STATE(isolate); |
91 CompileAll(isolate, &result); | 91 CompileAll(isolate, &result); |
92 return result; | 92 return result; |
93 } | 93 } |
94 | 94 |
95 } // namespace dart | 95 } // namespace dart |
OLD | NEW |