| 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 /// Test that the @MirrorsUsed annotation suppress hints and that only | 5 /// Test that the @MirrorsUsed annotation suppress hints and that only |
| 6 /// requested elements are retained for reflection. | 6 /// requested elements are retained for reflection. |
| 7 library dart2js.test.mirrors_used_test; | 7 library dart2js.test.mirrors_used_test; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 Expect.isFalse( | 94 Expect.isFalse( |
| 95 compiler.backend.isNeededForReflection(member), '$member'); | 95 compiler.backend.isNeededForReflection(member), '$member'); |
| 96 } | 96 } |
| 97 }); | 97 }); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // There should at least be one metadata constant: | 100 // There should at least be one metadata constant: |
| 101 // 1. The constructed constant for 'MirrorsUsed'. | 101 // 1. The constructed constant for 'MirrorsUsed'. |
| 102 Expect.isTrue(compiler.backend.metadataConstants.length >= 1); | 102 Expect.isTrue(compiler.backend.metadataConstants.length >= 1); |
| 103 | 103 |
| 104 Set<Constant> compiledConstants = |
| 105 compiler.backend.constants.compiledConstants; |
| 104 // Make sure that most of the metadata constants aren't included in the | 106 // Make sure that most of the metadata constants aren't included in the |
| 105 // generated code. | 107 // generated code. |
| 106 for (var dependency in compiler.backend.metadataConstants) { | 108 for (var dependency in compiler.backend.metadataConstants) { |
| 107 Constant constant = dependency.constant; | 109 Constant constant = dependency.constant; |
| 108 Expect.isFalse( | 110 Expect.isFalse(compiledConstants.contains(constant), '$constant'); |
| 109 compiler.constantHandler.compiledConstants.contains(constant), | |
| 110 '$constant'); | |
| 111 } | 111 } |
| 112 | 112 |
| 113 // The type literal 'Foo' is both used as metadata, and as a plain value in | 113 // The type literal 'Foo' is both used as metadata, and as a plain value in |
| 114 // the program. Make sure that it isn't duplicated. | 114 // the program. Make sure that it isn't duplicated. |
| 115 int fooConstantCount = 0; | 115 int fooConstantCount = 0; |
| 116 for (Constant constant in compiler.constantHandler.compiledConstants) { | 116 for (Constant constant in compiledConstants) { |
| 117 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { | 117 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { |
| 118 fooConstantCount++; | 118 fooConstantCount++; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 Expect.equals( | 121 Expect.equals( |
| 122 1, fooConstantCount, | 122 1, fooConstantCount, |
| 123 "The type literal 'Foo' is duplicated or missing."); | 123 "The type literal 'Foo' is duplicated or missing."); |
| 124 })); | 124 })); |
| 125 } | 125 } |
| 126 | 126 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 150 library lib; | 150 library lib; |
| 151 | 151 |
| 152 import 'dart:mirrors'; | 152 import 'dart:mirrors'; |
| 153 | 153 |
| 154 useReflect(type) { | 154 useReflect(type) { |
| 155 print(new Symbol('Foo')); | 155 print(new Symbol('Foo')); |
| 156 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 156 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 157 } | 157 } |
| 158 """, | 158 """, |
| 159 }; | 159 }; |
| OLD | NEW |