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

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

Issue 10704259: Added getField/setField to ObjectMirror. For InstanceMirrors, this get/sets (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
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 // These values are allowed to be passed directly over the wire. 7 // These values are allowed to be passed directly over the wire.
8 bool isSimpleValue(var value) { 8 bool isSimpleValue(var value) {
9 return (value === null || value is num || value is String || value is bool); 9 return (value === null || value is num || value is String || value is bool);
10 } 10 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); 118 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
119 try { 119 try {
120 completer.complete( 120 completer.complete(
121 _invoke(this, memberName, positionalArguments)); 121 _invoke(this, memberName, positionalArguments));
122 } catch (var exception) { 122 } catch (var exception) {
123 completer.completeException(exception); 123 completer.completeException(exception);
124 } 124 }
125 return completer.future; 125 return completer.future;
126 } 126 }
127 127
128 Future<InstanceMirror> getField(String fieldName)
129 {
130 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
131 try {
132 completer.complete(
turnidge 2012/07/17 23:59:33 Can this fit on one line?
133 _getField(this, fieldName));
134 } catch (var exception) {
135 completer.completeException(exception);
136 }
137 return completer.future;
138 }
139
140 Future<InstanceMirror> setField(String fieldName, Object arg)
141 {
142 if (arg is Mirror) {
143 if (arg is! InstanceMirror) {
144 throw new MirrorException(
145 'argument ($arg) was not an InstanceMirror');
146 }
147 } else if (!isSimpleValue(arg)) {
148 throw new MirrorException(
149 'argument ($arg) was not a simple value');
turnidge 2012/07/17 23:59:33 Maybe make a helper function for arg checking to a
150 }
151
152 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
153 try {
154 completer.complete(
turnidge 2012/07/17 23:59:33 Can this fit on one line?
155 _setField(this, fieldName, arg));
156 } catch (var exception) {
157 completer.completeException(exception);
158 }
159 return completer.future;
160 }
161
128 static _invoke(ref, memberName, positionalArguments) 162 static _invoke(ref, memberName, positionalArguments)
129 native 'LocalObjectMirrorImpl_invoke'; 163 native 'LocalObjectMirrorImpl_invoke';
164
165 static _getField(ref, fieldName)
166 native 'LocalObjectMirrorImpl_getField';
167
168 static _setField(ref, fieldName, value)
169 native 'LocalObjectMirrorImpl_setField';
130 } 170 }
131 171
132 // Prints a string as it might appear in dart program text. 172 // Prints a string as it might appear in dart program text.
133 // TODO(turnidge): Consider truncating. 173 // TODO(turnidge): Consider truncating.
134 String _dartEscape(String str) { 174 String _dartEscape(String str) {
135 bool isNice(int code) { 175 bool isNice(int code) {
136 return (code >= 32 && code <= 126); 176 return (code >= 32 && code <= 126);
137 } 177 }
138 178
139 StringBuffer buf = new StringBuffer(); 179 StringBuffer buf = new StringBuffer();
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 537
498 // Creates a new local InstanceMirror 538 // Creates a new local InstanceMirror
499 static InstanceMirror makeLocalInstanceMirror(Object reflectee) 539 static InstanceMirror makeLocalInstanceMirror(Object reflectee)
500 native 'Mirrors_makeLocalInstanceMirror'; 540 native 'Mirrors_makeLocalInstanceMirror';
501 541
502 // Creates a new local mirror for some Object. 542 // Creates a new local mirror for some Object.
503 static InstanceMirror mirrorOf(Object reflectee) { 543 static InstanceMirror mirrorOf(Object reflectee) {
504 return makeLocalInstanceMirror(reflectee); 544 return makeLocalInstanceMirror(reflectee);
505 } 545 }
506 } 546 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698