Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; | 205 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; |
| 206 } else { | 206 } else { |
| 207 return "InstanceMirror on <$_reflectee>"; | 207 return "InstanceMirror on <$_reflectee>"; |
| 208 } | 208 } |
| 209 } else { | 209 } else { |
| 210 return "InstanceMirror on instance of '${getClass().simpleName}'"; | 210 return "InstanceMirror on instance of '${getClass().simpleName}'"; |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl | |
| 216 implements InstanceMirror { | |
|
Ivan Posva
2012/07/23 23:57:20
Should implement ClosureMirror here.
| |
| 217 _LocalClosureMirrorImpl(ref, | |
| 218 klass, | |
| 219 reflectee) : super(ref, klass, reflectee) {} | |
| 220 | |
| 221 MethodMirror _function; | |
| 222 MethodMirror function() => _function; | |
| 223 | |
| 224 String source() { | |
| 225 throw "asYetUnimplemented"; | |
|
Ivan Posva
2012/07/23 23:57:20
See other uses of "throw new NotImplementedExcepti
| |
| 226 } | |
| 227 | |
| 228 Future<ObjectMirror> apply(List<Object> positionalArguments, | |
| 229 [Map<String,Object> namedArguments]) { | |
| 230 if (namedArguments !== null) { | |
| 231 throw new NotImplementedException('named arguments not implemented'); | |
| 232 } | |
| 233 // Walk the arguments and make sure they are legal. | |
| 234 for (int i = 0; i < positionalArguments.length; i++) { | |
| 235 var arg = positionalArguments[i]; | |
| 236 if (arg is Mirror) { | |
| 237 if (arg is! InstanceMirror) { | |
| 238 throw new MirrorException( | |
| 239 'positional argument $i ($arg) was not an InstanceMirror'); | |
| 240 } | |
| 241 } else if (!isSimpleValue(arg)) { | |
| 242 throw new MirrorException( | |
| 243 'positional argument $i ($arg) was not a simple value'); | |
| 244 } | |
| 245 } | |
| 246 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | |
| 247 try { | |
| 248 completer.complete( | |
| 249 _apply(this, positionalArguments)); | |
| 250 } catch (var exception) { | |
| 251 completer.completeException(exception); | |
| 252 } | |
| 253 return completer.future; | |
| 254 } | |
| 255 | |
| 256 Future<ObjectMirror> findInContext(String name) { | |
| 257 throw "asYetUnimplemented"; | |
| 258 } | |
| 259 | |
| 260 static _apply(ref, positionalArguments) | |
|
Ivan Posva
2012/07/23 23:57:20
Why is this native method marked as a static metho
rmacnak
2012/07/24 01:14:00
Consistency with ObjectMirror's _invoke.
On 2012/
| |
| 261 native 'LocalClosureMirrorImpl_apply'; | |
| 262 } | |
| 263 | |
| 215 class _LazyInterfaceMirror { | 264 class _LazyInterfaceMirror { |
| 216 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} | 265 _LazyInterfaceMirror(this.libraryName, this.interfaceName) {} |
| 217 | 266 |
| 218 InterfaceMirror resolve(MirrorSystem mirrors) { | 267 InterfaceMirror resolve(MirrorSystem mirrors) { |
| 219 if (libraryName === null) { | 268 if (libraryName === null) { |
| 220 if (interfaceName == 'Dynamic') { | 269 if (interfaceName == 'Dynamic') { |
| 221 return mirrors._dynamicMirror(); | 270 return mirrors._dynamicMirror(); |
| 222 } else if (interfaceName == 'void') { | 271 } else if (interfaceName == 'void') { |
| 223 return mirrors._dynamicMirror(); | 272 return mirrors._dynamicMirror(); |
| 224 } else { | 273 } else { |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 | 546 |
| 498 // Creates a new local InstanceMirror | 547 // Creates a new local InstanceMirror |
| 499 static InstanceMirror makeLocalInstanceMirror(Object reflectee) | 548 static InstanceMirror makeLocalInstanceMirror(Object reflectee) |
| 500 native 'Mirrors_makeLocalInstanceMirror'; | 549 native 'Mirrors_makeLocalInstanceMirror'; |
| 501 | 550 |
| 502 // Creates a new local mirror for some Object. | 551 // Creates a new local mirror for some Object. |
| 503 static InstanceMirror mirrorOf(Object reflectee) { | 552 static InstanceMirror mirrorOf(Object reflectee) { |
| 504 return makeLocalInstanceMirror(reflectee); | 553 return makeLocalInstanceMirror(reflectee); |
| 505 } | 554 } |
| 506 } | 555 } |
| OLD | NEW |