| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library jsinterop.world_test; | 5 library jsinterop.world_test; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:compiler/src/common.dart'; | 9 import 'package:compiler/src/common.dart'; |
| 10 import 'package:compiler/src/elements/elements.dart' show Element, ClassElement; | 10 import 'package:compiler/src/elements/elements.dart' show Element, ClassElement; |
| 11 import 'package:compiler/src/js_backend/js_backend.dart'; | 11 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 12 import 'package:compiler/src/world.dart'; | 12 import 'package:compiler/src/world.dart'; |
| 13 import '../type_test_helper.dart'; | 13 import '../type_test_helper.dart'; |
| 14 | 14 |
| 15 void main() { | 15 void main() { |
| 16 asyncTest(() async { | 16 asyncTest(() async { |
| 17 await testClasses(); | 17 await testClasses(); |
| 18 }); | 18 }); |
| 19 } | 19 } |
| 20 | 20 |
| 21 testClasses() async { | 21 testClasses() async { |
| 22 test(String mainSource, | 22 test(String mainSource, |
| 23 {List<String> directlyInstantiated: const <String>[], | 23 {List<String> directlyInstantiated: const <String>[], |
| 24 List<String> abstractlyInstantiated: const <String>[], |
| 24 List<String> indirectlyInstantiated: const <String>[]}) async { | 25 List<String> indirectlyInstantiated: const <String>[]}) async { |
| 25 TypeEnvironment env = await TypeEnvironment.create( | 26 TypeEnvironment env = await TypeEnvironment.create( |
| 26 r""" | 27 r""" |
| 27 @JS() | 28 @JS() |
| 28 class A { | 29 class A { |
| 29 get foo; | 30 get foo; |
| 30 | 31 |
| 31 external A(var foo); | 32 external A(var foo); |
| 32 } | 33 } |
| 33 | 34 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 for (String name in classEnvironment.keys) { | 114 for (String name in classEnvironment.keys) { |
| 114 ClassElement cls = classEnvironment[name]; | 115 ClassElement cls = classEnvironment[name]; |
| 115 bool isInstantiated = false; | 116 bool isInstantiated = false; |
| 116 if (directlyInstantiated.contains(name)) { | 117 if (directlyInstantiated.contains(name)) { |
| 117 isInstantiated = true; | 118 isInstantiated = true; |
| 118 Expect.isTrue( | 119 Expect.isTrue( |
| 119 world.isDirectlyInstantiated(cls), | 120 world.isDirectlyInstantiated(cls), |
| 120 "Expected $name to be directly instantiated in `${mainSource}`:" | 121 "Expected $name to be directly instantiated in `${mainSource}`:" |
| 121 "\n${world.dump(cls)}"); | 122 "\n${world.dump(cls)}"); |
| 122 } | 123 } |
| 124 if (abstractlyInstantiated.contains(name)) { |
| 125 isInstantiated = true; |
| 126 Expect.isTrue( |
| 127 world.isAbstractlyInstantiated(cls), |
| 128 "Expected $name to be abstractly instantiated in `${mainSource}`:" |
| 129 "\n${world.dump(cls)}"); |
| 130 } |
| 123 if (indirectlyInstantiated.contains(name)) { | 131 if (indirectlyInstantiated.contains(name)) { |
| 124 isInstantiated = true; | 132 isInstantiated = true; |
| 125 Expect.isTrue( | 133 Expect.isTrue( |
| 126 world.isIndirectlyInstantiated(cls), | 134 world.isIndirectlyInstantiated(cls), |
| 127 "Expected $name to be indirectly instantiated in `${mainSource}`:" | 135 "Expected $name to be indirectly instantiated in `${mainSource}`:" |
| 128 "\n${world.dump(cls)}"); | 136 "\n${world.dump(cls)}"); |
| 129 } | 137 } |
| 130 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) { | 138 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) { |
| 131 Expect.isFalse( | 139 Expect.isFalse( |
| 132 world.isInstantiated(cls), | 140 world.isInstantiated(cls), |
| 133 "Expected $name to be uninstantiated in `${mainSource}`:" | 141 "Expected $name to be uninstantiated in `${mainSource}`:" |
| 134 "\n${world.dump(cls)}"); | 142 "\n${world.dump(cls)}"); |
| 135 } | 143 } |
| 136 } | 144 } |
| 137 } | 145 } |
| 138 | 146 |
| 139 await test('main() {}'); | 147 await test('main() {}'); |
| 140 | 148 |
| 141 await test('main() => newA();', | 149 await test('main() => newA();', |
| 142 directlyInstantiated: ['A', 'B', 'C', 'D'], | 150 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 143 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 151 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 144 | 152 |
| 145 await test('main() => newB();', | 153 await test('main() => newB();', |
| 146 directlyInstantiated: ['A', 'B', 'C', 'D'], | 154 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 147 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 155 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 148 | 156 |
| 149 await test('main() => newC();', | 157 await test('main() => newC();', |
| 150 directlyInstantiated: ['A', 'B', 'C', 'D'], | 158 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 151 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 159 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 152 | 160 |
| 153 await test('main() => newD();', | 161 await test('main() => newD();', |
| 154 directlyInstantiated: ['A', 'B', 'C', 'D'], | 162 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 155 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 163 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 156 | 164 |
| 157 await test('main() => newE();', directlyInstantiated: ['E']); | 165 await test('main() => newE();', directlyInstantiated: ['E']); |
| 158 | 166 |
| 159 await test('main() => newF();', directlyInstantiated: ['F']); | 167 await test('main() => newF();', directlyInstantiated: ['F']); |
| 160 | 168 |
| 161 await test('main() => [newD(), newE()];', | 169 await test('main() => [newD(), newE()];', |
| 162 directlyInstantiated: ['A', 'B', 'C', 'D', 'E'], | 170 directlyInstantiated: ['E'], |
| 171 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 163 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 172 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 164 } | 173 } |
| OLD | NEW |