| 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 // Test that everything reachable from a [MirrorSystem] can be accessed. | 5 // Test that everything reachable from a [MirrorSystem] can be accessed. |
| 6 | 6 |
| 7 library test.mirrors.reader; | 7 library test.mirrors.reader; |
| 8 | 8 |
| 9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
| 10 import 'package:expect/expect.dart'; |
| 10 import 'mirrors_reader.dart'; | 11 import 'mirrors_reader.dart'; |
| 11 | 12 |
| 12 class RuntimeMirrorsReader extends MirrorsReader { | 13 class RuntimeMirrorsReader extends MirrorsReader { |
| 14 final MirrorSystem mirrorSystem; |
| 13 final String mirrorSystemType; | 15 final String mirrorSystemType; |
| 14 | 16 |
| 15 RuntimeMirrorsReader(MirrorSystem mirrorSystem, | 17 RuntimeMirrorsReader(MirrorSystem mirrorSystem, |
| 16 {bool verbose: false, bool includeStackTrace: false}) | 18 {bool verbose: false, bool includeStackTrace: false}) |
| 17 : this.mirrorSystemType = '${mirrorSystem.runtimeType}', | 19 : this.mirrorSystem = mirrorSystem, |
| 20 this.mirrorSystemType = '${mirrorSystem.runtimeType}', |
| 18 super(verbose: verbose, includeStackTrace: includeStackTrace); | 21 super(verbose: verbose, includeStackTrace: includeStackTrace); |
| 19 | 22 |
| 23 visitLibraryMirror(LibraryMirror mirror) { |
| 24 super.visitLibraryMirror(mirror); |
| 25 Expect.equals(mirror, mirrorSystem.libraries[mirror.uri]); |
| 26 } |
| 27 |
| 28 visitClassMirror(ClassMirror mirror) { |
| 29 super.visitClassMirror(mirror); |
| 30 Expect.isNotNull(mirror.owner); |
| 31 } |
| 32 |
| 20 bool allowUnsupported(var receiver, String tag, UnsupportedError exception) { | 33 bool allowUnsupported(var receiver, String tag, UnsupportedError exception) { |
| 21 if (mirrorSystemType == '_LocalMirrorSystem') { | 34 if (mirrorSystemType == '_LocalMirrorSystem') { |
| 22 // VM mirror system. | 35 // VM mirror system. |
| 23 } else if (mirrorSystemType == 'JsMirrorSystem') { | 36 } else if (mirrorSystemType == 'JsMirrorSystem') { |
| 24 // Dart2js runtime mirror system. | 37 // Dart2js runtime mirror system. |
| 25 if (tag.endsWith('.metadata')) { | 38 if (tag.endsWith('.metadata')) { |
| 26 return true;// Issue 10905. | 39 return true;// Issue 10905. |
| 27 } | 40 } |
| 28 } | 41 } |
| 29 return false; | 42 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 48 } | 61 } |
| 49 } | 62 } |
| 50 | 63 |
| 51 void main([List<String> arguments = const <String>[]]) { | 64 void main([List<String> arguments = const <String>[]]) { |
| 52 MirrorSystem mirrors = currentMirrorSystem(); | 65 MirrorSystem mirrors = currentMirrorSystem(); |
| 53 MirrorsReader reader = new RuntimeMirrorsReader(mirrors, | 66 MirrorsReader reader = new RuntimeMirrorsReader(mirrors, |
| 54 verbose: arguments.contains('-v'), | 67 verbose: arguments.contains('-v'), |
| 55 includeStackTrace: arguments.contains('-s')); | 68 includeStackTrace: arguments.contains('-s')); |
| 56 reader.checkMirrorSystem(mirrors); | 69 reader.checkMirrorSystem(mirrors); |
| 57 } | 70 } |
| OLD | NEW |