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 19 matching lines...) Expand all Loading... |
30 ASSERT(current_isolate == Isolate::Current()); | 30 ASSERT(current_isolate == Isolate::Current()); |
31 Dart_ExitIsolate(); | 31 Dart_ExitIsolate(); |
32 } | 32 } |
33 } | 33 } |
34 ~IsolateSaver() { | 34 ~IsolateSaver() { |
35 if (saved_isolate_ != NULL) { | 35 if (saved_isolate_ != NULL) { |
36 Dart_Isolate I = reinterpret_cast<Dart_Isolate>(saved_isolate_); | 36 Dart_Isolate I = reinterpret_cast<Dart_Isolate>(saved_isolate_); |
37 Dart_EnterIsolate(I); | 37 Dart_EnterIsolate(I); |
38 } | 38 } |
39 } | 39 } |
| 40 |
40 private: | 41 private: |
41 Isolate* saved_isolate_; | 42 Isolate* saved_isolate_; |
42 | 43 |
43 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | 44 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
44 }; | 45 }; |
45 | 46 |
46 | 47 |
47 static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) { | 48 static bool PostCObjectHelper(Dart_Port port_id, Dart_CObject* message) { |
48 uint8_t* buffer = NULL; | 49 uint8_t* buffer = NULL; |
49 ApiMessageWriter writer(&buffer, allocator); | 50 ApiMessageWriter writer(&buffer, allocator); |
50 bool success = writer.WriteCMessage(message); | 51 bool success = writer.WriteCMessage(message); |
51 | 52 |
52 if (!success) return success; | 53 if (!success) return success; |
53 | 54 |
54 // Post the message at the given port. | 55 // Post the message at the given port. |
55 return PortMap::PostMessage(new Message( | 56 return PortMap::PostMessage(new Message( |
56 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); | 57 port_id, buffer, writer.BytesWritten(), Message::kNormalPriority)); |
57 } | 58 } |
58 | 59 |
59 | 60 |
60 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { | 61 DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject* message) { |
61 return PostCObjectHelper(port_id, message); | 62 return PostCObjectHelper(port_id, message); |
62 } | 63 } |
63 | 64 |
64 | 65 |
65 DART_EXPORT bool Dart_PostInteger(Dart_Port port_id, int64_t message) { | 66 DART_EXPORT bool Dart_PostInteger(Dart_Port port_id, int64_t message) { |
66 if (Smi::IsValid(message)) { | 67 if (Smi::IsValid(message)) { |
67 return PortMap::PostMessage(new Message( | 68 return PortMap::PostMessage( |
68 port_id, Smi::New(message), Message::kNormalPriority)); | 69 new Message(port_id, Smi::New(message), Message::kNormalPriority)); |
69 } | 70 } |
70 Dart_CObject cobj; | 71 Dart_CObject cobj; |
71 cobj.type = Dart_CObject_kInt64; | 72 cobj.type = Dart_CObject_kInt64; |
72 cobj.value.as_int64 = message; | 73 cobj.value.as_int64 = message; |
73 return PostCObjectHelper(port_id, &cobj); | 74 return PostCObjectHelper(port_id, &cobj); |
74 } | 75 } |
75 | 76 |
76 | 77 |
77 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, | 78 DART_EXPORT Dart_Port Dart_NewNativePort(const char* name, |
78 Dart_NativeMessageHandler handler, | 79 Dart_NativeMessageHandler handler, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 return result; | 126 return result; |
126 } | 127 } |
127 CHECK_CALLBACK_STATE(T); | 128 CHECK_CALLBACK_STATE(T); |
128 CompileAll(T, &result); | 129 CompileAll(T, &result); |
129 return result; | 130 return result; |
130 } | 131 } |
131 | 132 |
132 | 133 |
133 static void ParseAll(Thread* thread, Dart_Handle* result) { | 134 static void ParseAll(Thread* thread, Dart_Handle* result) { |
134 ASSERT(thread != NULL); | 135 ASSERT(thread != NULL); |
135 const Error& error = Error::Handle(thread->zone(), | 136 const Error& error = Error::Handle(thread->zone(), Library::ParseAll(thread)); |
136 Library::ParseAll(thread)); | |
137 if (error.IsNull()) { | 137 if (error.IsNull()) { |
138 *result = Api::Success(); | 138 *result = Api::Success(); |
139 } else { | 139 } else { |
140 *result = Api::NewHandle(thread, error.raw()); | 140 *result = Api::NewHandle(thread, error.raw()); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 DART_EXPORT Dart_Handle Dart_ParseAll() { | 145 DART_EXPORT Dart_Handle Dart_ParseAll() { |
146 DARTSCOPE(Thread::Current()); | 146 DARTSCOPE(Thread::Current()); |
147 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 147 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
148 if (::Dart_IsError(result)) { | 148 if (::Dart_IsError(result)) { |
149 return result; | 149 return result; |
150 } | 150 } |
151 CHECK_CALLBACK_STATE(T); | 151 CHECK_CALLBACK_STATE(T); |
152 ParseAll(T, &result); | 152 ParseAll(T, &result); |
153 return result; | 153 return result; |
154 } | 154 } |
155 | 155 |
156 } // namespace dart | 156 } // namespace dart |
OLD | NEW |