OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Ensure that objects handled specially by dart2js can be reflected on. | 5 // Ensure that objects handled specially by dart2js can be reflected on. |
6 | 6 |
7 library test.intercepted_object_test; | 7 library test.intercepted_object_test; |
8 | 8 |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
11 import 'stringify.dart' show stringify, expect; | 11 import 'stringify.dart' show stringify, expect; |
12 | 12 |
13 import 'intercepted_class_test.dart' show checkClassMirrorMethods; | 13 import 'intercepted_class_test.dart' show checkClassMirrorMethods; |
14 | 14 |
15 checkImplements(object, String name) { | 15 checkImplements(object, String name) { |
16 ClassMirror cls = reflect(object).type; | 16 ClassMirror cls = reflect(object).type; |
17 checkClassMirrorMethods(cls); | 17 checkClassMirrorMethods(cls); |
18 | 18 |
19 // The VM implements List via a mixin, so check for that. | |
20 if (cls.superinterfaces.isEmpty && object is List) { | |
21 cls = cls.superclass.superclass.mixin; | |
Ivan Posva
2014/11/18 07:24:18
This is similar hard coding as was removed in othe
Florian Schneider
2014/11/18 10:20:19
Yes, but it is just a test which can easily be ada
| |
22 } | |
23 | |
19 List<ClassMirror> superinterfaces = cls.superinterfaces; | 24 List<ClassMirror> superinterfaces = cls.superinterfaces; |
20 String symName = 's($name)'; | 25 String symName = 's($name)'; |
21 for (ClassMirror superinterface in superinterfaces) { | 26 for (ClassMirror superinterface in superinterfaces) { |
22 print(superinterface.simpleName); | 27 print(superinterface.simpleName); |
23 if (symName == stringify(superinterface.simpleName)) { | 28 if (symName == stringify(superinterface.simpleName)) { |
24 checkClassMirrorMethods(superinterface); | 29 checkClassMirrorMethods(superinterface); |
25 return; | 30 return; |
26 } | 31 } |
27 } | 32 } |
28 | 33 |
29 // A class implements itself, even if not explicitly declared. | 34 // A class implements itself, even if not explicitly declared. |
30 if (symName == stringify(cls.simpleName)) { | 35 if (symName == stringify(cls.simpleName)) { |
31 checkClassMirrorMethods(cls); | 36 checkClassMirrorMethods(cls); |
32 return; | 37 return; |
33 } | 38 } |
34 | 39 |
35 // TODO(floitsch): use correct fail | 40 // TODO(floitsch): use correct fail |
36 expect(name, "super interface not found"); | 41 expect(name, "super interface not found"); |
37 } | 42 } |
38 | 43 |
39 main() { | 44 main() { |
40 checkImplements('', 'String'); | 45 checkImplements('', 'String'); |
41 checkImplements(1, 'int'); | 46 checkImplements(1, 'int'); |
42 checkImplements(1.5, 'double'); | 47 checkImplements(1.5, 'double'); |
43 checkImplements(true, 'bool'); | 48 checkImplements(true, 'bool'); |
44 checkImplements(false, 'bool'); | 49 checkImplements(false, 'bool'); |
45 checkImplements([], 'List'); | 50 checkImplements([], 'List'); |
46 } | 51 } |
OLD | NEW |