| 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 // FIXME(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 Blink to Dart VM. | |
| 13 #ifndef NDEBUG | |
| 14 #define DEBUG | |
| 15 #endif | |
| 16 | |
| 17 // Stop WebCorePrefixMac.h from killing the build. | |
| 18 #if defined(new) | |
| 19 #undef new | |
| 20 #endif | |
| 21 | |
| 22 #if defined(delete) | |
| 23 #undef delete | |
| 24 #endif | |
| 25 | |
| 26 // Stop WinUser.h from renaming PostMessage to PostMessageW | |
| 27 #ifdef PostMessage | |
| 28 #undef PostMessage | |
| 29 #endif | |
| 30 | |
| 31 #include "vm/dart_api_impl.h" // NOLINT. | |
| 32 #include "vm/dart_api_state.h" // NOLINT. | |
| 33 #include "vm/dart_entry.h" // NOLINT. | |
| 34 #include "vm/isolate.h" // NOLINT. | |
| 35 #include "vm/message.h" // NOLINT. | |
| 36 #include "vm/native_arguments.h" // NOLINT. | |
| 37 #include "vm/native_entry.h" // NOLINT. | |
| 38 #include "vm/object.h" // NOLINT. | |
| 39 #include "vm/port.h" // NOLINT. | |
| 40 #include "vm/snapshot.h" // NOLINT. | |
| 41 | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 | |
| 46 Dart_Port DartServiceInternal::GetPortIdFromPort(Dart_Handle port) | |
| 47 { | |
| 48 using namespace dart; | |
| 49 Isolate* isolate = Isolate::Current(); | |
| 50 DARTSCOPE(isolate); | |
| 51 Instance& instance = Instance::Handle(); | |
| 52 instance ^= Api::UnwrapHandle(port); | |
| 53 const Object& idObj = Object::Handle(DartLibraryCalls::PortGetId(instance)); | |
| 54 if (idObj.IsError()) { | |
| 55 return ILLEGAL_PORT; | |
| 56 } | |
| 57 Integer& id = Integer::Handle(); | |
| 58 id ^= idObj.raw(); | |
| 59 return static_cast<Dart_Port>(id.AsInt64Value()); | |
| 60 } | |
| 61 | |
| 62 | |
| 63 static uint8_t* allocator(uint8_t* ptr, intptr_t oldSize, intptr_t newSize) | |
| 64 { | |
| 65 void* newPtr = realloc(reinterpret_cast<void*>(ptr), newSize); | |
| 66 return reinterpret_cast<uint8_t*>(newPtr); | |
| 67 } | |
| 68 | |
| 69 | |
| 70 static bool DartSendServiceMessage(Dart_Handle targetPort, Dart_Handle message) | |
| 71 { | |
| 72 using namespace dart; | |
| 73 Isolate* isolate = Isolate::Current(); | |
| 74 DARTSCOPE(isolate); | |
| 75 Dart_Port spId = DartServiceInternal::GetPortIdFromPort(targetPort); | |
| 76 if (spId == ILLEGAL_PORT) { | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 // Serialize message. | |
| 81 Object& msg = Object::Handle(Api::UnwrapHandle(message)); | |
| 82 uint8_t* data = 0; | |
| 83 MessageWriter writer(&data, &allocator); | |
| 84 writer.WriteMessage(msg); | |
| 85 | |
| 86 PortMap::PostMessage(new Message(spId, data, writer.BytesWritten(), Message:
:kOOBPriority)); | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 | |
| 91 void DartServiceInternal::PostOOB(Dart_Handle targetPort, Dart_Handle message) | |
| 92 { | |
| 93 bool r = DartSendServiceMessage(targetPort, message); | |
| 94 ASSERT(r); | |
| 95 } | |
| 96 | |
| 97 } | |
| OLD | NEW |