| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library MirrorsTest; | |
| 6 | |
| 7 import 'dart:mirrors'; | |
| 8 import 'package:expect/expect.dart'; | |
| 9 | |
| 10 bool isNSMContainingFieldName(e, String fieldName, bool isSetter) { | |
| 11 print(e); | |
| 12 if (e is! NoSuchMethodError) return false; | |
| 13 String needle = fieldName; | |
| 14 if (isSetter) needle += "="; | |
| 15 return "$e".contains(needle) && ! "$e".contains(needle + "="); | |
| 16 } | |
| 17 | |
| 18 class A {} | |
| 19 | |
| 20 main() { | |
| 21 var mirrors = currentMirrorSystem(); | |
| 22 var libMirror = mirrors.findLibrary(#MirrorsTest); | |
| 23 Expect.throws(() => libMirror.invoke(#foo, []), | |
| 24 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 25 Expect.throws(() => libMirror.getField(#foo), | |
| 26 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 27 Expect.throws(() => libMirror.setField(#foo, null), /// vm: ok | |
| 28 (e) => isNSMContainingFieldName(e, "foo", true)); /// vm: contin
ued | |
| 29 | |
| 30 var classMirror = reflect(A); | |
| 31 Expect.throws(() => classMirror.invoke(#foo, []), | |
| 32 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 33 Expect.throws(() => classMirror.getField(#foo), | |
| 34 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 35 Expect.throws(() => classMirror.setField(#foo, null), | |
| 36 (e) => isNSMContainingFieldName(e, "foo", true)); | |
| 37 | |
| 38 var instanceMirror = reflect(new A()); | |
| 39 Expect.throws(() => instanceMirror.invoke(#foo, []), | |
| 40 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 41 Expect.throws(() => instanceMirror.getField(#foo), | |
| 42 (e) => isNSMContainingFieldName(e, "foo", false)); | |
| 43 Expect.throws(() => instanceMirror.setField(#foo, null), | |
| 44 (e) => isNSMContainingFieldName(e, "foo", true)); | |
| 45 | |
| 46 } | |
| OLD | NEW |