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 'package:expect/expect.dart'; |
11 import 'mirrors_reader.dart'; | 11 import 'mirrors_reader.dart'; |
12 | 12 |
13 class RuntimeMirrorsReader extends MirrorsReader { | 13 class RuntimeMirrorsReader extends MirrorsReader { |
14 final MirrorSystem mirrorSystem; | 14 final MirrorSystem mirrorSystem; |
15 final String mirrorSystemType; | 15 final String mirrorSystemType; |
16 | 16 |
17 RuntimeMirrorsReader(MirrorSystem mirrorSystem, | 17 RuntimeMirrorsReader(MirrorSystem mirrorSystem, |
18 {bool verbose: false, bool includeStackTrace: false}) | 18 {bool verbose: false, bool includeStackTrace: false}) |
19 : this.mirrorSystem = mirrorSystem, | 19 : this.mirrorSystem = mirrorSystem, |
20 this.mirrorSystemType = '${mirrorSystem.runtimeType}', | 20 this.mirrorSystemType = '${mirrorSystem.runtimeType}', |
21 super(verbose: verbose, includeStackTrace: includeStackTrace); | 21 super(verbose: verbose, includeStackTrace: includeStackTrace); |
22 | 22 |
23 visitLibraryMirror(LibraryMirror mirror) { | 23 visitLibraryMirror(LibraryMirror mirror) { |
24 super.visitLibraryMirror(mirror); | 24 super.visitLibraryMirror(mirror); |
25 Expect.equals(mirror, mirrorSystem.libraries[mirror.uri]); | 25 Expect.equals(mirror, mirrorSystem.libraries[mirror.uri]); |
26 } | 26 } |
27 | 27 |
28 visitClassMirror(ClassMirror mirror) { | 28 visitClassMirror(ClassMirror mirror) { |
29 super.visitClassMirror(mirror); | 29 super.visitClassMirror(mirror); |
30 Expect.isNotNull(mirror.owner); | 30 Expect.isNotNull(mirror.owner); |
31 } | 31 } |
32 | 32 |
33 bool allowUnsupported(var receiver, String tag, UnsupportedError exception) { | 33 bool allowUnsupported(var receiver, String tag, UnsupportedError exception) { |
34 if (mirrorSystemType == '_LocalMirrorSystem') { | 34 if (mirrorSystemType == '_LocalMirrorSystem') { |
35 // VM mirror system. | 35 // VM mirror system. |
36 if (tag.endsWith('location')) { | 36 if (tag.endsWith('location')) { |
37 return receiver is ParameterMirror; | 37 return receiver is ParameterMirror; |
38 } | 38 } |
39 } else if (mirrorSystemType == 'JsMirrorSystem') { | 39 } else if (mirrorSystemType == 'JsMirrorSystem') { |
40 // Dart2js runtime mirror system. | 40 // Dart2js runtime mirror system. |
41 if (tag.endsWith('.metadata')) { | 41 if (tag.endsWith('.metadata')) { |
42 return true;// Issue 10905. | 42 return true; // Issue 10905. |
43 } | 43 } |
44 } | 44 } |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 bool expectUnsupported(var receiver, String tag, UnsupportedError exception) { | 48 bool expectUnsupported(var receiver, String tag, UnsupportedError exception) { |
49 // [DeclarationMirror.location] is intentionally not supported in runtime | 49 // [DeclarationMirror.location] is intentionally not supported in runtime |
50 // mirrors. | 50 // mirrors. |
51 | 51 |
52 if (mirrorSystemType == '_LocalMirrorSystem') { | 52 if (mirrorSystemType == '_LocalMirrorSystem') { |
53 // VM mirror system. | 53 // VM mirror system. |
54 } else if (mirrorSystemType == 'JsMirrorSystem') { | 54 } else if (mirrorSystemType == 'JsMirrorSystem') { |
55 // Dart2js runtime mirror system. | 55 // Dart2js runtime mirror system. |
56 if (receiver is DeclarationMirror && tag == 'location') { | 56 if (receiver is DeclarationMirror && tag == 'location') { |
57 return true; | 57 return true; |
58 } | 58 } |
59 } | 59 } |
60 return false; | 60 return false; |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void main([List<String> arguments = const <String>[]]) { | 64 void main([List<String> arguments = const <String>[]]) { |
65 MirrorSystem mirrors = currentMirrorSystem(); | 65 MirrorSystem mirrors = currentMirrorSystem(); |
66 MirrorsReader reader = new RuntimeMirrorsReader(mirrors, | 66 MirrorsReader reader = new RuntimeMirrorsReader(mirrors, |
67 verbose: arguments.contains('-v'), | 67 verbose: arguments.contains('-v'), |
68 includeStackTrace: arguments.contains('-s')); | 68 includeStackTrace: arguments.contains('-s')); |
69 reader.checkMirrorSystem(mirrors); | 69 reader.checkMirrorSystem(mirrors); |
70 } | 70 } |
OLD | NEW |