Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.test.reflective_tests; | 5 library analyzer.test.reflective_tests; |
| 6 | 6 |
| 7 @MirrorsUsed(metaTargets: 'ReflectiveTest') | 7 @MirrorsUsed(metaTargets: 'ReflectiveTest') |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 solo_test(memberName, () { | 66 solo_test(memberName, () { |
| 67 return _runFailingTest(classMirror, symbol); | 67 return _runFailingTest(classMirror, symbol); |
| 68 }); | 68 }); |
| 69 } | 69 } |
| 70 }); | 70 }); |
| 71 }); | 71 }); |
| 72 } | 72 } |
| 73 | 73 |
| 74 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { | 74 Future _invokeSymbolIfExists(InstanceMirror instanceMirror, Symbol symbol) { |
| 75 var invocationResult = null; | 75 var invocationResult = null; |
| 76 InstanceMirror closure; | |
| 76 try { | 77 try { |
| 77 invocationResult = instanceMirror.invoke(symbol, []).reflectee; | 78 closure = instanceMirror.getField(symbol); |
|
Jennifer Messerly
2016/01/19 23:53:54
Basically, we get the tearoff:
https://api.dartlan
| |
| 78 } on NoSuchMethodError {} | 79 } on NoSuchMethodError {} |
| 79 if (invocationResult is Future) { | 80 |
| 80 return invocationResult; | 81 if (closure is ClosureMirror) { |
| 81 } else { | 82 invocationResult = closure.apply([]).reflectee; |
| 82 return new Future.value(invocationResult); | |
| 83 } | 83 } |
| 84 return new Future.value(invocationResult); | |
| 84 } | 85 } |
| 85 | 86 |
| 86 /** | 87 /** |
| 87 * Run a test that is expected to fail, and confirm that it fails. | 88 * Run a test that is expected to fail, and confirm that it fails. |
| 88 * | 89 * |
| 89 * This properly handles the following cases: | 90 * This properly handles the following cases: |
| 90 * - The test fails by throwing an exception | 91 * - The test fails by throwing an exception |
| 91 * - The test returns a future which completes with an error. | 92 * - The test returns a future which completes with an error. |
| 92 * | 93 * |
| 93 * However, it does not handle the case where the test creates an asynchronous | 94 * However, it does not handle the case where the test creates an asynchronous |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 112 */ | 113 */ |
| 113 class ReflectiveTest { | 114 class ReflectiveTest { |
| 114 const ReflectiveTest(); | 115 const ReflectiveTest(); |
| 115 } | 116 } |
| 116 | 117 |
| 117 /** | 118 /** |
| 118 * A marker annotation used to instruct dart2js to keep reflection information | 119 * A marker annotation used to instruct dart2js to keep reflection information |
| 119 * for the annotated classes. | 120 * for the annotated classes. |
| 120 */ | 121 */ |
| 121 const ReflectiveTest reflectiveTest = const ReflectiveTest(); | 122 const ReflectiveTest reflectiveTest = const ReflectiveTest(); |
| OLD | NEW |