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 25 matching lines...) Expand all Loading... |
36 Thread::EnterIsolate(saved_isolate_); | 36 Thread::EnterIsolate(saved_isolate_); |
37 } | 37 } |
38 } | 38 } |
39 private: | 39 private: |
40 Isolate* saved_isolate_; | 40 Isolate* saved_isolate_; |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | 42 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
43 }; | 43 }; |
44 | 44 |
45 | 45 |
46 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 46 static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) { |
47 uint8_t* buffer = NULL; | 47 uint8_t* buffer = NULL; |
48 ApiMessageWriter writer(&buffer, allocator); | 48 ApiMessageWriter writer(&buffer, allocator); |
49 bool success = writer.WriteCMessage(message); | 49 bool success = writer.WriteCMessage(message); |
50 | 50 |
51 if (!success) return success; | 51 if (!success) return success; |
52 | 52 |
53 // Post the message at the given port. | 53 // Post the message at the given port. |
54 return PortMap::PostMessage(new Message( | 54 return PortMap::PostMessage(new Message( |
55 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); | 55 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); |
56 } | 56 } |
57 | 57 |
58 | 58 |
| 59 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
| 60 return PostCObjectHelper(port_id, message); |
| 61 } |
| 62 |
| 63 |
59 DART_EXPORT bool Dart_PostInteger(Dart_Port port_id, int64_t message) { | 64 DART_EXPORT bool Dart_PostInteger(Dart_Port port_id, int64_t message) { |
60 if (Smi::IsValid(message)) { | 65 if (Smi::IsValid(message)) { |
61 return PortMap::PostMessage(new Message( | 66 return PortMap::PostMessage(new Message( |
62 port_id, Smi::New(message), Message::kNormalPriority)); | 67 port_id, Smi::New(message), Message::kNormalPriority)); |
63 } | 68 } |
64 Dart_CObject cobj; | 69 Dart_CObject cobj; |
65 cobj.type = Dart_CObject_kInt64; | 70 cobj.type = Dart_CObject_kInt64; |
66 cobj.value.as_int64 = message; | 71 cobj.value.as_int64 = message; |
67 return Dart_PostCObject(port_id, &cobj); | 72 return PostCObjectHelper(port_id, &cobj); |
68 } | 73 } |
69 | 74 |
70 | 75 |
71 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, | 76 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
72 Dart_NativeMessageHandler handler, | 77 Dart_NativeMessageHandler handler, |
73 bool handle_concurrently) { | 78 bool handle_concurrently) { |
74 if (name == NULL) { | 79 if (name == NULL) { |
75 name = "<UnnamedNativePort>"; | 80 name = "<UnnamedNativePort>"; |
76 } | 81 } |
77 if (handler == NULL) { | 82 if (handler == NULL) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 121 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
117 if (::Dart_IsError(result)) { | 122 if (::Dart_IsError(result)) { |
118 return result; | 123 return result; |
119 } | 124 } |
120 CHECK_CALLBACK_STATE(T); | 125 CHECK_CALLBACK_STATE(T); |
121 CompileAll(T, &result); | 126 CompileAll(T, &result); |
122 return result; | 127 return result; |
123 } | 128 } |
124 | 129 |
125 } // namespace dart | 130 } // namespace dart |
OLD | NEW |