OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Ensure that objects handled specially by dart2js can be reflected on. |
| 6 |
| 7 library test.intercepted_object_test; |
| 8 |
| 9 import 'dart:mirrors'; |
| 10 |
| 11 import 'stringify.dart' show stringify, expect; |
| 12 |
| 13 import 'intercepted_class_test.dart' show checkClassMirrorMethods; |
| 14 |
| 15 checkImplements(object, String name) { |
| 16 ClassMirror cls = reflect(object).type; |
| 17 checkClassMirrorMethods(cls); |
| 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; |
| 22 } |
| 23 |
| 24 List<ClassMirror> superinterfaces = cls.superinterfaces; |
| 25 String symName = 's($name)'; |
| 26 for (ClassMirror superinterface in superinterfaces) { |
| 27 print(superinterface.simpleName); |
| 28 if (symName == stringify(superinterface.simpleName)) { |
| 29 checkClassMirrorMethods(superinterface); |
| 30 return; |
| 31 } |
| 32 } |
| 33 |
| 34 // A class implements itself, even if not explicitly declared. |
| 35 if (symName == stringify(cls.simpleName)) { |
| 36 checkClassMirrorMethods(cls); |
| 37 return; |
| 38 } |
| 39 |
| 40 // TODO(floitsch): use correct fail |
| 41 expect(name, "super interface not found"); |
| 42 } |
| 43 |
| 44 main() { |
| 45 checkImplements('', 'String'); |
| 46 checkImplements(1, 'int'); |
| 47 checkImplements(1.5, 'double'); |
| 48 checkImplements(true, 'bool'); |
| 49 checkImplements(false, 'bool'); |
| 50 checkImplements([], 'List'); |
| 51 } |
OLD | NEW |