Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| =================================================================== |
| --- runtime/lib/mirrors.cc (revision 0) |
| +++ runtime/lib/mirrors.cc (revision 0) |
| @@ -0,0 +1,79 @@ |
| +// Copyright (c) 2012, 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. |
| + |
| +#include "vm/bootstrap_natives.h" |
| + |
| +#include "vm/dart_entry.h" |
| +#include "vm/exceptions.h" |
| +#include "vm/message.h" |
| +#include "vm/port.h" |
| + |
| +namespace dart { |
| + |
| +static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { |
| + void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| + return reinterpret_cast<uint8_t*>(new_ptr); |
| +} |
| + |
| + |
| +DEFINE_NATIVE_ENTRY(Mirrors_send, 3) { |
| + GET_NATIVE_ARGUMENT(Instance, port, arguments->At(0)); |
| + GET_NATIVE_ARGUMENT(Instance, message, arguments->At(1)); |
| + GET_NATIVE_ARGUMENT(Instance, replyTo, arguments->At(2)); |
| + Object& result = Object::Handle(); |
| + Integer& value = Integer::Handle(); |
| + |
| + // Get the send port id. |
| + result = DartLibraryCalls::PortGetId(port); |
| + if (result.IsError()) { |
| + Exceptions::PropagateError(result); |
| + } |
|
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
|
| + value ^= result.raw(); |
| + int64_t send_port_id = value.AsInt64Value(); |
| + |
| + // Get the reply port id. |
| + result = DartLibraryCalls::PortGetId(replyTo); |
| + if (result.IsError()) { |
| + Exceptions::PropagateError(result); |
| + } |
| + value ^= result.raw(); |
| + int64_t reply_port_id = value.AsInt64Value(); |
| + |
| + // Construct the message. |
| + uint8_t* data = NULL; |
| + SnapshotWriter writer(Snapshot::kMessage, &data, &allocator); |
| + 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
|
| + writer.FinalizeBuffer(); |
| + |
| + // Post the message. |
| + bool retval = PortMap::PostMessage(new Message( |
| + send_port_id, reply_port_id, data, Message::kOOBPriority)); |
| + const Bool& retval_obj = Bool::Handle(Bool::Get(retval)); |
| + arguments->SetReturn(retval_obj); |
| +} |
| + |
| + |
| +DEFINE_NATIVE_ENTRY(IsolateMirrorImpl_buildResponse, 1) { |
| + GET_NATIVE_ARGUMENT(Instance, map, arguments->At(0)); |
| + String& key = String::Handle(); |
| + Instance& value = Instance::Handle(); |
| + Object& result = Object::Handle(); |
| + |
| + key = String::New("debugName"); |
| + value = String::New(isolate->name()); |
| + result = DartLibraryCalls::MapSetAt(map, key, value); |
| + if (result.IsError()) { |
| + // TODO(turnidge): Prevent mirror operations from crashing other isolates? |
| + Exceptions::PropagateError(result); |
| + } |
| + |
| + key = String::New("ok"); |
| + value = Bool::True(); |
| + result = DartLibraryCalls::MapSetAt(map, key, value); |
| + if (result.IsError()) { |
| + Exceptions::PropagateError(result); |
| + } |
| +} |
| + |
| +} // namespace dart |