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 import "dart:collection"; | 7 import "dart:collection"; |
8 | 8 |
9 final emptyList = new UnmodifiableListView([]); | 9 final emptyList = new UnmodifiableListView([]); |
10 final emptyMap = new _UnmodifiableMapView({}); | 10 final emptyMap = new _UnmodifiableMapView({}); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 if (numNamedArguments > 0) { | 348 if (numNamedArguments > 0) { |
349 namedArguments.forEach((name, value) { | 349 namedArguments.forEach((name, value) { |
350 arguments[argumentIndex++] = value; | 350 arguments[argumentIndex++] = value; |
351 names[nameIndex++] = _n(name); | 351 names[nameIndex++] = _n(name); |
352 }); | 352 }); |
353 } | 353 } |
354 | 354 |
355 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); | 355 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); |
356 } | 356 } |
357 | 357 |
| 358 static Map _getFieldClosures = new Map.identity(); |
| 359 static Map _setFieldClosures = new Map.identity(); |
| 360 |
| 361 InstanceMirror getField(Symbol memberName) { |
| 362 var f = _getFieldClosures[memberName]; |
| 363 if (f == null) { |
| 364 f = _makeGetter(_n(memberName), _ScratchClass); |
| 365 _getFieldClosures[memberName] = f; |
| 366 } |
| 367 return reflect(f(_reflectee)); |
| 368 } |
| 369 |
| 370 InstanceMirror setField(Symbol memberName, value) { |
| 371 var f = _setFieldClosures[memberName]; |
| 372 if (f == null) { |
| 373 f = _makeSetter(_n(memberName), _ScratchClass); |
| 374 _setFieldClosures[memberName] = f; |
| 375 } |
| 376 return reflect(f(_reflectee, value)); |
| 377 } |
| 378 |
| 379 static _makeGetter(selector, scratchClass) |
| 380 native "Mirrors_makeGetter"; |
| 381 |
| 382 static _makeSetter(selector, scratchClass) |
| 383 native "Mirrors_makeSetter"; |
| 384 |
358 _invoke(reflectee, functionName, arguments, argumentNames) | 385 _invoke(reflectee, functionName, arguments, argumentNames) |
359 native 'InstanceMirror_invoke'; | 386 native 'InstanceMirror_invoke'; |
360 | 387 |
361 _invokeGetter(reflectee, getterName) | 388 _invokeGetter(reflectee, getterName) |
362 native 'InstanceMirror_invokeGetter'; | 389 native 'InstanceMirror_invokeGetter'; |
363 | 390 |
364 _invokeSetter(reflectee, setterName, value) | 391 _invokeSetter(reflectee, setterName, value) |
365 native 'InstanceMirror_invokeSetter'; | 392 native 'InstanceMirror_invokeSetter'; |
366 | 393 |
367 static _computeType(reflectee) | 394 static _computeType(reflectee) |
368 native 'InstanceMirror_computeType'; | 395 native 'InstanceMirror_computeType'; |
369 } | 396 } |
370 | 397 |
| 398 class _ScratchClass {} |
| 399 |
371 class _LocalClosureMirror extends _LocalInstanceMirror | 400 class _LocalClosureMirror extends _LocalInstanceMirror |
372 implements ClosureMirror { | 401 implements ClosureMirror { |
373 _LocalClosureMirror(reflectee) : super(reflectee); | 402 _LocalClosureMirror(reflectee) : super(reflectee); |
374 | 403 |
375 MethodMirror _function; | 404 MethodMirror _function; |
376 MethodMirror get function { | 405 MethodMirror get function { |
377 if (_function == null) { | 406 if (_function == null) { |
378 _function = _computeFunction(reflectee); | 407 _function = _computeFunction(reflectee); |
379 } | 408 } |
380 return _function; | 409 return _function; |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 if (typeMirror == null) { | 1521 if (typeMirror == null) { |
1493 typeMirror = makeLocalTypeMirror(key); | 1522 typeMirror = makeLocalTypeMirror(key); |
1494 _instanitationCache[key] = typeMirror; | 1523 _instanitationCache[key] = typeMirror; |
1495 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1524 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1496 _declarationCache[key] = typeMirror; | 1525 _declarationCache[key] = typeMirror; |
1497 } | 1526 } |
1498 } | 1527 } |
1499 return typeMirror; | 1528 return typeMirror; |
1500 } | 1529 } |
1501 } | 1530 } |
OLD | NEW |