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

Unified Diff: runtime/lib/mirrors_impl.dart

Issue 9420038: Heartbeat implementation of dart:mirrors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 months 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 side-by-side diff with in-line comments
Download patch
Index: runtime/lib/mirrors_impl.dart
===================================================================
--- runtime/lib/mirrors_impl.dart (revision 0)
+++ runtime/lib/mirrors_impl.dart (revision 0)
@@ -0,0 +1,57 @@
+// 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.
+
+// VM-specific implementation of the dart:mirrors library.
+
+class _IsolateMirrorImpl implements IsolateMirror {
+ _IsolateMirrorImpl(this.port, this.debugName) {}
+
+ final SendPort port;
+ final String debugName;
+
+ static buildCommand(List command) {
+ command.add('isolateMirrorOf');
+ }
+
+ static buildResponse(Map response) native "IsolateMirrorImpl_buildResponse";
+
+ static processResponse(SendPort port, Map response) {
+ if (response['ok']) {
+ return new _IsolateMirrorImpl(port, response['debugName']);
+ }
+ return null;
+ }
+}
+
+class _Mirrors {
+ static Future<IsolateMirror> isolateMirrorOf(SendPort port) {
+ Completer<IsolateMirror> completer = new Completer<IsolateMirror>();
+ List command = new List();
+ _IsolateMirrorImpl.buildCommand(command);
+ call(port, command).receive((message, _) {
+ completer.complete(_IsolateMirrorImpl.processResponse(port, message));
+ });
+ return completer.future;
+ }
+
+ static void processCommand(message, replyTo) {
siva 2012/02/18 01:25:55 What is our convention with respect to parameters
turnidge 2012/03/07 20:00:14 Don't know. It seems like I should add types wher
siva 2012/03/08 22:24:02 I think the convention agreed upon (though not str
+ Map response = new Map();
+ if (message[0] == 'isolateMirrorOf') {
+ _IsolateMirrorImpl.buildResponse(response);
+ } else {
+ response['ok'] = false;
+ }
+ replyTo.send(response);
+ }
+
+ static ReceivePort call(port, message) {
+ ReceivePort rp = new ReceivePort.singleShot();
+ if (!send(port, message, rp.toSendPort())) {
+ throw new Exception("Unable to send mirror request to port $port");
+ }
+ return rp;
+ }
+
+ static bool send(port, message, replyTo) native "Mirrors_send";
+}

Powered by Google App Engine
This is Rietveld 408576698