Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: Source/bindings/dart/DartServiceInternal.cpp

Issue 104433004: Enable VM service inside Dartium Renderer processes (Closed) Base URL: svn://svn.chromium.org/multivm/branches/1650/blink
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "bindings/dart/DartServiceInternal.h" // NOLINT.
9 #include "bindings/dart/DartService.h" // NOLINT.
10
11 // Map from Dartium to Dart VM.
12 #if defined(_DEBUG)
13 #define DEBUG
14 #endif
15
Jacob 2013/12/04 20:39:52 add a TODO and bug to get this file moved over to
Cutch 2013/12/04 21:20:50 Done.
16 #include "vm/dart_api_impl.h" // NOLINT.
17 #include "vm/dart_api_state.h" // NOLINT.
18 #include "vm/dart_entry.h" // NOLINT.
19 #include "vm/isolate.h" // NOLINT.
20 #include "vm/message.h" // NOLINT.
21 #include "vm/native_arguments.h" // NOLINT.
22 #include "vm/native_entry.h" // NOLINT.
23 #include "vm/object.h" // NOLINT.
24 #include "vm/port.h" // NOLINT.
25 #include "vm/snapshot.h" // NOLINT.
26
27
28 namespace WebCore {
29
30
31 Dart_Port DartServiceInternal::GetPortIdFromPort(Dart_Handle port)
32 {
33 using namespace dart;
34 Isolate* isolate = Isolate::Current();
35 DARTSCOPE(isolate);
36 Instance& instance = Instance::Handle();
37 instance ^= Api::UnwrapHandle(port);
38 const Object& idObj = Object::Handle(DartLibraryCalls::PortGetId(instance));
39 if (idObj.IsError()) {
40 return ILLEGAL_PORT;
41 }
42 Integer& id = Integer::Handle();
43 id ^= idObj.raw();
44 return static_cast<Dart_Port>(id.AsInt64Value());
45 }
46
47
48 static uint8_t* allocator(uint8_t* ptr, intptr_t oldSize, intptr_t newSize)
49 {
50 void* newPtr = realloc(reinterpret_cast<void*>(ptr), newSize);
51 return reinterpret_cast<uint8_t*>(newPtr);
52 }
53
54
55 static bool DartSendServiceMessage(Dart_Handle targetPort, Dart_Handle replyPort , Dart_Handle message)
56 {
57 using namespace dart;
58 Isolate* isolate = Isolate::Current();
59 DARTSCOPE(isolate);
60 Dart_Port spId = DartServiceInternal::GetPortIdFromPort(targetPort);
61 if (spId == ILLEGAL_PORT) {
62 return false;
63 }
64 Dart_Port rpId = DartServiceInternal::GetPortIdFromPort(replyPort);
65 if (rpId == ILLEGAL_PORT) {
66 return false;
67 }
68
69 // Serialize message.
70 Object& msg = Object::Handle(Api::UnwrapHandle(message));
71 uint8_t* data = 0;
72 MessageWriter writer(&data, &allocator);
73 writer.WriteMessage(msg);
74
75 PortMap::PostMessage(new Message(spId, rpId, data, writer.BytesWritten(), Me ssage::kOOBPriority));
76 return true;
77 }
78
79
80 void DartServiceInternal::PostOOB(Dart_Handle targetPort, Dart_Handle replyPort, Dart_Handle message)
81 {
82 bool r = DartSendServiceMessage(targetPort, replyPort, message);
83 ASSERT(r);
84 }
85
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698