OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012, 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 #include "vm/bootstrap_natives.h" | |
6 | |
7 #include "vm/dart_entry.h" | |
8 #include "vm/exceptions.h" | |
9 #include "vm/message.h" | |
10 #include "vm/port.h" | |
11 | |
12 namespace dart { | |
13 | |
14 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { | |
15 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | |
16 return reinterpret_cast<uint8_t*>(new_ptr); | |
17 } | |
18 | |
19 | |
20 DEFINE_NATIVE_ENTRY(Mirrors_send, 3) { | |
21 GET_NATIVE_ARGUMENT(Instance, port, arguments->At(0)); | |
22 GET_NATIVE_ARGUMENT(Instance, message, arguments->At(1)); | |
23 GET_NATIVE_ARGUMENT(Instance, replyTo, arguments->At(2)); | |
24 Object& result = Object::Handle(); | |
25 Integer& value = Integer::Handle(); | |
26 | |
27 // Get the send port id. | |
28 result = DartLibraryCalls::PortGetId(port); | |
29 if (result.IsError()) { | |
30 Exceptions::PropagateError(result); | |
31 } | |
siva
2012/02/18 01:25:55
Integer& value = Integer::Handle();
over here ins
turnidge
2012/03/07 20:00:14
Are you suggesting this to save a handle allocatio
siva
2012/03/08 22:24:02
In that case should you just be asserting that res
turnidge
2012/03/08 22:50:51
On reflection, I was wrong when I said never.
Thi
| |
32 value ^= result.raw(); | |
33 int64_t send_port_id = value.AsInt64Value(); | |
34 | |
35 // Get the reply port id. | |
36 result = DartLibraryCalls::PortGetId(replyTo); | |
37 if (result.IsError()) { | |
38 Exceptions::PropagateError(result); | |
39 } | |
40 value ^= result.raw(); | |
41 int64_t reply_port_id = value.AsInt64Value(); | |
42 | |
43 // Construct the message. | |
44 uint8_t* data = NULL; | |
45 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); | |
46 writer.WriteObject(message.raw()); | |
siva
2012/02/18 01:25:55
Can message be any random object or be restricted
turnidge
2012/03/07 20:00:14
My thought was that message would be a pretty vani
siva
2012/03/08 22:24:02
Ok in that case this is another place I need to re
| |
47 writer.FinalizeBuffer(); | |
48 | |
49 // Post the message. | |
50 bool retval = PortMap::PostMessage(new Message( | |
51 send_port_id, reply_port_id, data, Message::kOOBPriority)); | |
52 const Bool& retval_obj = Bool::Handle(Bool::Get(retval)); | |
53 arguments->SetReturn(retval_obj); | |
54 } | |
55 | |
56 | |
57 DEFINE_NATIVE_ENTRY(IsolateMirrorImpl_buildResponse, 1) { | |
58 GET_NATIVE_ARGUMENT(Instance, map, arguments->At(0)); | |
59 String& key = String::Handle(); | |
60 Instance& value = Instance::Handle(); | |
61 Object& result = Object::Handle(); | |
62 | |
63 key = String::New("debugName"); | |
64 value = String::New(isolate->name()); | |
65 result = DartLibraryCalls::MapSetAt(map, key, value); | |
66 if (result.IsError()) { | |
67 // TODO(turnidge): Prevent mirror operations from crashing other isolates? | |
68 Exceptions::PropagateError(result); | |
69 } | |
70 | |
71 key = String::New("ok"); | |
72 value = Bool::True(); | |
73 result = DartLibraryCalls::MapSetAt(map, key, value); | |
74 if (result.IsError()) { | |
75 Exceptions::PropagateError(result); | |
76 } | |
77 } | |
78 | |
79 } // namespace dart | |
OLD | NEW |