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