Chromium Code Reviews| Index: Source/bindings/dart/DartServiceInternal.cpp |
| diff --git a/Source/bindings/dart/DartServiceInternal.cpp b/Source/bindings/dart/DartServiceInternal.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f692a939a22b0d7bbc2cbadd0af31e8c9631665 |
| --- /dev/null |
| +++ b/Source/bindings/dart/DartServiceInternal.cpp |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Each #include line has NOLINT because we cannot include "config.h" in |
| +// this file because it conflicts with Dart VM internals. |
| + |
| +// TODO(johnmccutchan): Expose these methods to the embedder API so |
|
Jacob
2013/12/05 19:31:31
Match Webkit style for TODO
add a bug #.
Cutch
2013/12/05 22:48:15
Done.
|
| +// this file can be removed. |
| +#include "bindings/dart/DartServiceInternal.h" // NOLINT. |
| +#include "bindings/dart/DartService.h" // NOLINT. |
| + |
| +// Map from Dartium to Dart VM. |
| +#if defined(_DEBUG) |
| +#define DEBUG |
| +#endif |
| + |
| +#include "vm/dart_api_impl.h" // NOLINT. |
| +#include "vm/dart_api_state.h" // NOLINT. |
| +#include "vm/dart_entry.h" // NOLINT. |
| +#include "vm/isolate.h" // NOLINT. |
| +#include "vm/message.h" // NOLINT. |
| +#include "vm/native_arguments.h" // NOLINT. |
| +#include "vm/native_entry.h" // NOLINT. |
| +#include "vm/object.h" // NOLINT. |
| +#include "vm/port.h" // NOLINT. |
| +#include "vm/snapshot.h" // NOLINT. |
| + |
| + |
| +namespace WebCore { |
| + |
| + |
| +Dart_Port DartServiceInternal::GetPortIdFromPort(Dart_Handle port) |
| +{ |
| + using namespace dart; |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Instance& instance = Instance::Handle(); |
| + instance ^= Api::UnwrapHandle(port); |
| + const Object& idObj = Object::Handle(DartLibraryCalls::PortGetId(instance)); |
| + if (idObj.IsError()) { |
| + return ILLEGAL_PORT; |
| + } |
| + Integer& id = Integer::Handle(); |
| + id ^= idObj.raw(); |
| + return static_cast<Dart_Port>(id.AsInt64Value()); |
| +} |
| + |
| + |
| +static uint8_t* allocator(uint8_t* ptr, intptr_t oldSize, intptr_t newSize) |
| +{ |
| + void* newPtr = realloc(reinterpret_cast<void*>(ptr), newSize); |
| + return reinterpret_cast<uint8_t*>(newPtr); |
| +} |
| + |
| + |
| +static bool DartSendServiceMessage(Dart_Handle targetPort, Dart_Handle replyPort, Dart_Handle message) |
| +{ |
| + using namespace dart; |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Dart_Port spId = DartServiceInternal::GetPortIdFromPort(targetPort); |
| + if (spId == ILLEGAL_PORT) { |
| + return false; |
| + } |
| + Dart_Port rpId = DartServiceInternal::GetPortIdFromPort(replyPort); |
| + if (rpId == ILLEGAL_PORT) { |
| + return false; |
| + } |
| + |
| + // Serialize message. |
| + Object& msg = Object::Handle(Api::UnwrapHandle(message)); |
| + uint8_t* data = 0; |
| + MessageWriter writer(&data, &allocator); |
| + writer.WriteMessage(msg); |
| + |
| + PortMap::PostMessage(new Message(spId, rpId, data, writer.BytesWritten(), Message::kOOBPriority)); |
| + return true; |
| +} |
| + |
| + |
| +void DartServiceInternal::PostOOB(Dart_Handle targetPort, Dart_Handle replyPort, Dart_Handle message) |
| +{ |
| + bool r = DartSendServiceMessage(targetPort, replyPort, message); |
| + ASSERT(r); |
| +} |
| + |
| +} |