| 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..1bd087a0f7877290acff6968baf6cacaae09975d
|
| --- /dev/null
|
| +++ b/Source/bindings/dart/DartServiceInternal.cpp
|
| @@ -0,0 +1,87 @@
|
| +// 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, 15481): Expose these methods to the embedder API so
|
| +// this file can be removed.
|
| +#include "bindings/dart/DartServiceInternal.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);
|
| +}
|
| +
|
| +}
|
|
|