| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Each #include line has NOLINT because we cannot include "config.h" in |
| 6 // this file because it conflicts with Dart VM internals. |
| 7 |
| 8 // TODO(johnmccutchan, 15481): Expose these methods to the embedder API so |
| 9 // this file can be removed. |
| 10 #include "bindings/dart/DartServiceInternal.h" // NOLINT. |
| 11 |
| 12 // Map from Dartium to Dart VM. |
| 13 #if defined(_DEBUG) |
| 14 #define DEBUG |
| 15 #endif |
| 16 |
| 17 #include "vm/dart_api_impl.h" // NOLINT. |
| 18 #include "vm/dart_api_state.h" // NOLINT. |
| 19 #include "vm/dart_entry.h" // NOLINT. |
| 20 #include "vm/isolate.h" // NOLINT. |
| 21 #include "vm/message.h" // NOLINT. |
| 22 #include "vm/native_arguments.h" // NOLINT. |
| 23 #include "vm/native_entry.h" // NOLINT. |
| 24 #include "vm/object.h" // NOLINT. |
| 25 #include "vm/port.h" // NOLINT. |
| 26 #include "vm/snapshot.h" // NOLINT. |
| 27 |
| 28 |
| 29 namespace WebCore { |
| 30 |
| 31 |
| 32 Dart_Port DartServiceInternal::GetPortIdFromPort(Dart_Handle port) |
| 33 { |
| 34 using namespace dart; |
| 35 Isolate* isolate = Isolate::Current(); |
| 36 DARTSCOPE(isolate); |
| 37 Instance& instance = Instance::Handle(); |
| 38 instance ^= Api::UnwrapHandle(port); |
| 39 const Object& idObj = Object::Handle(DartLibraryCalls::PortGetId(instance)); |
| 40 if (idObj.IsError()) { |
| 41 return ILLEGAL_PORT; |
| 42 } |
| 43 Integer& id = Integer::Handle(); |
| 44 id ^= idObj.raw(); |
| 45 return static_cast<Dart_Port>(id.AsInt64Value()); |
| 46 } |
| 47 |
| 48 |
| 49 static uint8_t* allocator(uint8_t* ptr, intptr_t oldSize, intptr_t newSize) |
| 50 { |
| 51 void* newPtr = realloc(reinterpret_cast<void*>(ptr), newSize); |
| 52 return reinterpret_cast<uint8_t*>(newPtr); |
| 53 } |
| 54 |
| 55 |
| 56 static bool DartSendServiceMessage(Dart_Handle targetPort, Dart_Handle replyPort
, Dart_Handle message) |
| 57 { |
| 58 using namespace dart; |
| 59 Isolate* isolate = Isolate::Current(); |
| 60 DARTSCOPE(isolate); |
| 61 Dart_Port spId = DartServiceInternal::GetPortIdFromPort(targetPort); |
| 62 if (spId == ILLEGAL_PORT) { |
| 63 return false; |
| 64 } |
| 65 Dart_Port rpId = DartServiceInternal::GetPortIdFromPort(replyPort); |
| 66 if (rpId == ILLEGAL_PORT) { |
| 67 return false; |
| 68 } |
| 69 |
| 70 // Serialize message. |
| 71 Object& msg = Object::Handle(Api::UnwrapHandle(message)); |
| 72 uint8_t* data = 0; |
| 73 MessageWriter writer(&data, &allocator); |
| 74 writer.WriteMessage(msg); |
| 75 |
| 76 PortMap::PostMessage(new Message(spId, rpId, data, writer.BytesWritten(), Me
ssage::kOOBPriority)); |
| 77 return true; |
| 78 } |
| 79 |
| 80 |
| 81 void DartServiceInternal::PostOOB(Dart_Handle targetPort, Dart_Handle replyPort,
Dart_Handle message) |
| 82 { |
| 83 bool r = DartSendServiceMessage(targetPort, replyPort, message); |
| 84 ASSERT(r); |
| 85 } |
| 86 |
| 87 } |
| OLD | NEW |