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/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 | 1604 |
1605 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | 1605 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
1606 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 1606 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
1607 return reinterpret_cast<uint8_t*>(new_ptr); | 1607 return reinterpret_cast<uint8_t*>(new_ptr); |
1608 } | 1608 } |
1609 | 1609 |
1610 | 1610 |
1611 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 1611 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
1612 Isolate* isolate = Isolate::Current(); | 1612 Isolate* isolate = Isolate::Current(); |
1613 DARTSCOPE(isolate); | 1613 DARTSCOPE(isolate); |
| 1614 if (port_id == ILLEGAL_PORT) { |
| 1615 return false; |
| 1616 } |
1614 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 1617 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
1615 uint8_t* data = NULL; | 1618 uint8_t* data = NULL; |
1616 MessageWriter writer(&data, &allocator, false); | 1619 MessageWriter writer(&data, &allocator, false); |
1617 writer.WriteMessage(object); | 1620 writer.WriteMessage(object); |
1618 intptr_t len = writer.BytesWritten(); | 1621 intptr_t len = writer.BytesWritten(); |
1619 return PortMap::PostMessage(new Message( | 1622 return PortMap::PostMessage(new Message( |
1620 port_id, data, len, Message::kNormalPriority)); | 1623 port_id, data, len, Message::kNormalPriority)); |
1621 } | 1624 } |
1622 | 1625 |
1623 | 1626 |
1624 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1627 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
1625 Isolate* isolate = Isolate::Current(); | 1628 Isolate* isolate = Isolate::Current(); |
1626 DARTSCOPE(isolate); | 1629 DARTSCOPE(isolate); |
1627 CHECK_CALLBACK_STATE(isolate); | 1630 CHECK_CALLBACK_STATE(isolate); |
| 1631 if (port_id == ILLEGAL_PORT) { |
| 1632 return Api::NewError("%s: illegal port_id %" Pd64 ".", |
| 1633 CURRENT_FUNC, |
| 1634 port_id); |
| 1635 } |
1628 return Api::NewHandle(isolate, SendPort::New(port_id)); | 1636 return Api::NewHandle(isolate, SendPort::New(port_id)); |
1629 } | 1637 } |
1630 | 1638 |
1631 | 1639 |
1632 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1640 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1633 Dart_Port* port_id) { | 1641 Dart_Port* port_id) { |
1634 Isolate* isolate = Isolate::Current(); | 1642 Isolate* isolate = Isolate::Current(); |
1635 DARTSCOPE(isolate); | 1643 DARTSCOPE(isolate); |
1636 CHECK_CALLBACK_STATE(isolate); | 1644 CHECK_CALLBACK_STATE(isolate); |
1637 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); | 1645 const SendPort& send_port = Api::UnwrapSendPortHandle(isolate, port); |
(...skipping 3899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5537 | 5545 |
5538 | 5546 |
5539 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5547 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5540 const char* name, | 5548 const char* name, |
5541 Dart_ServiceRequestCallback callback, | 5549 Dart_ServiceRequestCallback callback, |
5542 void* user_data) { | 5550 void* user_data) { |
5543 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5551 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5544 } | 5552 } |
5545 | 5553 |
5546 } // namespace dart | 5554 } // namespace dart |
OLD | NEW |