Chromium Code Reviews| 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 // VM-specific implementation of the dart:mirrors library. | |
| 6 | |
| 7 class _IsolateMirrorImpl implements IsolateMirror { | |
| 8 _IsolateMirrorImpl(this.port, this.debugName) {} | |
| 9 | |
| 10 final SendPort port; | |
| 11 final String debugName; | |
| 12 | |
| 13 static buildCommand(List command) { | |
| 14 command.add('isolateMirrorOf'); | |
| 15 } | |
| 16 | |
| 17 static buildResponse(Map response) native "IsolateMirrorImpl_buildResponse"; | |
| 18 | |
| 19 static processResponse(SendPort port, Map response) { | |
| 20 if (response['ok']) { | |
| 21 return new _IsolateMirrorImpl(port, response['debugName']); | |
| 22 } | |
| 23 return null; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 class _Mirrors { | |
| 28 static Future<IsolateMirror> isolateMirrorOf(SendPort port) { | |
| 29 Completer<IsolateMirror> completer = new Completer<IsolateMirror>(); | |
| 30 List command = new List(); | |
| 31 _IsolateMirrorImpl.buildCommand(command); | |
| 32 call(port, command).receive((message, _) { | |
| 33 completer.complete(_IsolateMirrorImpl.processResponse(port, message)); | |
| 34 }); | |
| 35 return completer.future; | |
| 36 } | |
| 37 | |
| 38 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
| |
| 39 Map response = new Map(); | |
| 40 if (message[0] == 'isolateMirrorOf') { | |
| 41 _IsolateMirrorImpl.buildResponse(response); | |
| 42 } else { | |
| 43 response['ok'] = false; | |
| 44 } | |
| 45 replyTo.send(response); | |
| 46 } | |
| 47 | |
| 48 static ReceivePort call(port, message) { | |
| 49 ReceivePort rp = new ReceivePort.singleShot(); | |
| 50 if (!send(port, message, rp.toSendPort())) { | |
| 51 throw new Exception("Unable to send mirror request to port $port"); | |
| 52 } | |
| 53 return rp; | |
| 54 } | |
| 55 | |
| 56 static bool send(port, message, replyTo) native "Mirrors_send"; | |
| 57 } | |
| OLD | NEW |