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 |
| 25 // Get the send port id. |
| 26 Object& result = Object::Handle(); |
| 27 result = DartLibraryCalls::PortGetId(port); |
| 28 if (result.IsError()) { |
| 29 Exceptions::PropagateError(result); |
| 30 } |
| 31 |
| 32 Integer& value = Integer::Handle(); |
| 33 value ^= result.raw(); |
| 34 int64_t send_port_id = value.AsInt64Value(); |
| 35 |
| 36 // Get the reply port id. |
| 37 result = DartLibraryCalls::PortGetId(replyTo); |
| 38 if (result.IsError()) { |
| 39 Exceptions::PropagateError(result); |
| 40 } |
| 41 value ^= result.raw(); |
| 42 int64_t reply_port_id = value.AsInt64Value(); |
| 43 |
| 44 // Construct the message. |
| 45 uint8_t* data = NULL; |
| 46 SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); |
| 47 writer.WriteObject(message.raw()); |
| 48 writer.FinalizeBuffer(); |
| 49 |
| 50 // Post the message. |
| 51 bool retval = PortMap::PostMessage(new Message( |
| 52 send_port_id, reply_port_id, data, Message::kOOBPriority)); |
| 53 const Bool& retval_obj = Bool::Handle(Bool::Get(retval)); |
| 54 arguments->SetReturn(retval_obj); |
| 55 } |
| 56 |
| 57 |
| 58 DEFINE_NATIVE_ENTRY(IsolateMirrorImpl_buildResponse, 1) { |
| 59 GET_NATIVE_ARGUMENT(Instance, map, arguments->At(0)); |
| 60 String& key = String::Handle(); |
| 61 Instance& value = Instance::Handle(); |
| 62 Object& result = Object::Handle(); |
| 63 |
| 64 key = String::New("debugName"); |
| 65 value = String::New(isolate->name()); |
| 66 result = DartLibraryCalls::MapSetAt(map, key, value); |
| 67 if (result.IsError()) { |
| 68 // TODO(turnidge): Prevent mirror operations from crashing other isolates? |
| 69 Exceptions::PropagateError(result); |
| 70 } |
| 71 |
| 72 key = String::New("ok"); |
| 73 value = Bool::True(); |
| 74 result = DartLibraryCalls::MapSetAt(map, key, value); |
| 75 if (result.IsError()) { |
| 76 Exceptions::PropagateError(result); |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace dart |
OLD | NEW |