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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 10175011: Rework mirrors implementation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/mirrors_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 class _IsolateMirrorImpl implements IsolateMirror { 7 class _IsolateMirrorImpl implements IsolateMirror {
8 _IsolateMirrorImpl(this.port, this.debugName) {} 8 _IsolateMirrorImpl(this.port, this.debugName) {}
9 9
10 final SendPort port; 10 final SendPort port;
11 final String debugName; 11 final String debugName;
12 12
13 static buildCommand(List command) { 13 static _make(SendPort port, String debugName) {
14 command.add('isolateMirrorOf'); 14 return new _IsolateMirrorImpl(port, debugName);
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 } 15 }
25 } 16 }
26 17
27 class _Mirrors { 18 class _Mirrors {
28 static Future<IsolateMirror> isolateMirrorOf(SendPort port) { 19 static Future<IsolateMirror> isolateMirrorOf(SendPort port) {
29 Completer<IsolateMirror> completer = new Completer<IsolateMirror>(); 20 Completer<IsolateMirror> completer = new Completer<IsolateMirror>();
30 List command = new List(); 21 String request = '{ "command": "isolateMirrorOf" }';
31 _IsolateMirrorImpl.buildCommand(command);
32 ReceivePort rp = new ReceivePort(); 22 ReceivePort rp = new ReceivePort();
33 if (!send(port, command, rp.toSendPort())) { 23 if (!send(port, request, rp.toSendPort())) {
34 throw new Exception("Unable to send mirror request to port $port"); 24 throw new Exception("Unable to send mirror request to port $port");
35 } 25 }
36 rp.receive((message, _) { 26 rp.receive((message, _) {
37 rp.close(); 27 rp.close();
38 completer.complete(_IsolateMirrorImpl.processResponse(port, message)); 28 completer.complete(_Mirrors.processResponse(
29 port, "isolateMirrorOf", message));
39 }); 30 });
40 return completer.future; 31 return completer.future;
41 } 32 }
42 33
43 static void processCommand(var message, SendPort replyTo) { 34 static bool send(SendPort port, String request, SendPort replyTo)
44 Map response = new Map(); 35 native "Mirrors_send";
45 if (message[0] == 'isolateMirrorOf') {
46 _IsolateMirrorImpl.buildResponse(response);
47 } else {
48 response['ok'] = false;
49 }
50 replyTo.send(response);
51 }
52 36
53 static bool send(SendPort port, Object message, SendPort replyTo) 37 static processResponse(SendPort port, String command, String response)
54 native "Mirrors_send"; 38 native "Mirrors_processResponse";
55 } 39 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/mirrors_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698