Chromium Code Reviews| 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" |
| (...skipping 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 intptr_t len = writer.BytesWritten(); | 1224 intptr_t len = writer.BytesWritten(); |
| 1225 return PortMap::PostMessage(new Message( | 1225 return PortMap::PostMessage(new Message( |
| 1226 port_id, data, len, Message::kNormalPriority)); | 1226 port_id, data, len, Message::kNormalPriority)); |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 | 1229 |
| 1230 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1230 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
| 1231 Isolate* isolate = Isolate::Current(); | 1231 Isolate* isolate = Isolate::Current(); |
| 1232 DARTSCOPE(isolate); | 1232 DARTSCOPE(isolate); |
| 1233 CHECK_CALLBACK_STATE(isolate); | 1233 CHECK_CALLBACK_STATE(isolate); |
| 1234 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 1234 return Api::NewHandle(isolate, SendPort::New(port_id)); |
| 1235 } | 1235 } |
| 1236 | 1236 |
| 1237 | 1237 |
| 1238 DART_EXPORT Dart_Handle Dart_PortGetId(Dart_Handle port, Dart_Port* port_id) { | 1238 DART_EXPORT Dart_Handle Dart_ReceivePortGetId(Dart_Handle port, |
| 1239 Dart_Port* port_id) { | |
| 1239 Isolate* isolate = Isolate::Current(); | 1240 Isolate* isolate = Isolate::Current(); |
| 1240 DARTSCOPE(isolate); | 1241 DARTSCOPE(isolate); |
| 1241 CHECK_CALLBACK_STATE(isolate); | 1242 CHECK_CALLBACK_STATE(isolate); |
| 1242 const Instance& port_instance = Api::UnwrapInstanceHandle(isolate, port); | 1243 const ReceivePort& receive_port = Api::UnwrapReceivePortHandle(isolate, port); |
| 1243 if (port_instance.IsNull()) { | 1244 if (receive_port.IsNull()) { |
| 1244 RETURN_TYPE_ERROR(isolate, port, Instance); | 1245 RETURN_TYPE_ERROR(isolate, port, ReceivePort); |
| 1245 } | 1246 } |
|
siva
2014/04/23 00:20:31
Missing check:
if (port_id == NULL) {
RETURN_NU
Ivan Posva
2014/04/23 19:43:35
Done.
| |
| 1246 if (!DartLibraryCalls::IsSendPort(port_instance) && | 1247 *port_id = static_cast<Dart_Port>(receive_port.Id()); |
| 1247 !DartLibraryCalls::IsReceivePort(port_instance)) { | 1248 ASSERT(*port_id != 0); |
|
siva
2014/04/23 00:20:31
Maybe this assert needs to be inside 'Id()' ?
Ivan Posva
2014/04/23 19:43:35
ASSERT was unnecessary.
| |
| 1248 return Api::NewError("expected an instance of RawReceivePort or SendPort."); | |
| 1249 } | |
| 1250 const Object& idObj = Object::Handle( | |
| 1251 DartLibraryCalls::PortGetId(port_instance)); | |
| 1252 ASSERT(idObj.IsInteger()); | |
| 1253 const Integer& id = Integer::Cast(idObj); | |
| 1254 *port_id = static_cast<Dart_Port>(id.AsInt64Value()); | |
| 1255 return Api::Success(); | 1249 return Api::Success(); |
| 1256 } | 1250 } |
| 1257 | 1251 |
| 1258 | 1252 |
| 1259 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 1253 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
| 1260 Isolate* isolate = Isolate::Current(); | 1254 Isolate* isolate = Isolate::Current(); |
| 1261 DARTSCOPE(isolate); | 1255 DARTSCOPE(isolate); |
| 1262 CHECK_CALLBACK_STATE(isolate); | 1256 CHECK_CALLBACK_STATE(isolate); |
| 1263 | 1257 |
| 1264 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); | 1258 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1283 } | 1277 } |
| 1284 | 1278 |
| 1285 | 1279 |
| 1286 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1280 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
| 1287 Isolate* isolate = Isolate::Current(); | 1281 Isolate* isolate = Isolate::Current(); |
| 1288 CHECK_ISOLATE(isolate); | 1282 CHECK_ISOLATE(isolate); |
| 1289 return isolate->main_port(); | 1283 return isolate->main_port(); |
| 1290 } | 1284 } |
| 1291 | 1285 |
| 1292 | 1286 |
| 1293 DART_EXPORT Dart_Handle Dart_PostMessage(Dart_Handle send_port, | 1287 DART_EXPORT Dart_Handle Dart_PostMessage(Dart_Handle port, |
| 1294 Dart_Handle object) { | 1288 Dart_Handle object) { |
| 1295 Isolate* isolate = Isolate::Current(); | 1289 Isolate* isolate = Isolate::Current(); |
| 1296 DARTSCOPE(isolate); | 1290 DARTSCOPE(isolate); |
| 1297 Instance& port_instance = Instance::Handle(); | 1291 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); |
| 1298 port_instance ^= Api::UnwrapHandle(send_port); | 1292 if (send_port.IsNull()) { |
| 1299 if (!DartLibraryCalls::IsSendPort(port_instance)) { | 1293 RETURN_TYPE_ERROR(isolate, port, SendPort); |
| 1300 return Api::NewError("send_port is not a SendPort."); | |
| 1301 } | 1294 } |
| 1302 const Object& idObj = Object::Handle( | 1295 Dart_Port port_id = static_cast<Dart_Port>(send_port.Id()); |
| 1303 DartLibraryCalls::PortGetId(port_instance)); | |
| 1304 ASSERT(!idObj.IsError()); | |
| 1305 Integer& id = Integer::Handle(); | |
| 1306 id ^= idObj.raw(); | |
| 1307 Dart_Port port = static_cast<Dart_Port>(id.AsInt64Value()); | |
| 1308 uint8_t* data = NULL; | 1296 uint8_t* data = NULL; |
| 1309 MessageWriter writer(&data, &allocator); | 1297 MessageWriter writer(&data, &allocator); |
| 1310 Object& msg_object = Object::Handle(Api::UnwrapHandle(object)); | 1298 Object& msg_object = Object::Handle(Api::UnwrapHandle(object)); |
| 1311 writer.WriteMessage(msg_object); | 1299 writer.WriteMessage(msg_object); |
| 1312 intptr_t len = writer.BytesWritten(); | 1300 intptr_t len = writer.BytesWritten(); |
| 1313 bool r = PortMap::PostMessage( | 1301 bool r = PortMap::PostMessage( |
| 1314 new Message(port, data, len, Message::kNormalPriority)); | 1302 new Message(port_id, data, len, Message::kNormalPriority)); |
| 1315 if (r) { | 1303 if (r) { |
| 1316 return Api::Success(); | 1304 return Api::Success(); |
| 1317 } | 1305 } |
| 1318 return Api::NewError("Dart_PostMessage failed."); | 1306 return Api::NewError("Dart_PostMessage failed."); |
| 1319 } | 1307 } |
| 1320 | 1308 |
| 1321 // --- Scopes ---- | 1309 // --- Scopes ---- |
| 1322 | 1310 |
| 1323 DART_EXPORT void Dart_EnterScope() { | 1311 DART_EXPORT void Dart_EnterScope() { |
| 1324 Isolate* isolate = Isolate::Current(); | 1312 Isolate* isolate = Isolate::Current(); |
| (...skipping 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4712 | 4700 |
| 4713 | 4701 |
| 4714 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 4702 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 4715 const char* name, | 4703 const char* name, |
| 4716 Dart_ServiceRequestCallback callback, | 4704 Dart_ServiceRequestCallback callback, |
| 4717 void* user_data) { | 4705 void* user_data) { |
| 4718 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 4706 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 4719 } | 4707 } |
| 4720 | 4708 |
| 4721 } // namespace dart | 4709 } // namespace dart |
| OLD | NEW |