| 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' |
| 11 show ClassElement, PublicName; |
| 11 import 'package:compiler/src/js_backend/js_backend.dart'; | 12 import 'package:compiler/src/js_backend/js_backend.dart'; |
| 13 import 'package:compiler/src/universe/selector.dart'; |
| 12 import 'package:compiler/src/world.dart'; | 14 import 'package:compiler/src/world.dart'; |
| 13 import '../type_test_helper.dart'; | 15 import '../type_test_helper.dart'; |
| 14 | 16 |
| 15 void main() { | 17 void main() { |
| 16 asyncTest(() async { | 18 asyncTest(() async { |
| 17 await testClasses(); | 19 await testClasses(); |
| 18 }); | 20 }); |
| 19 } | 21 } |
| 20 | 22 |
| 21 testClasses() async { | 23 testClasses() async { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 registerClass(backend.helpers.jsInterceptorClass); | 97 registerClass(backend.helpers.jsInterceptorClass); |
| 96 ClassElement JavaScriptObject = | 98 ClassElement JavaScriptObject = |
| 97 registerClass(backend.helpers.jsJavaScriptObjectClass); | 99 registerClass(backend.helpers.jsJavaScriptObjectClass); |
| 98 ClassElement A = registerClass(env.getElement('A')); | 100 ClassElement A = registerClass(env.getElement('A')); |
| 99 ClassElement B = registerClass(env.getElement('B')); | 101 ClassElement B = registerClass(env.getElement('B')); |
| 100 ClassElement C = registerClass(env.getElement('C')); | 102 ClassElement C = registerClass(env.getElement('C')); |
| 101 ClassElement D = registerClass(env.getElement('D')); | 103 ClassElement D = registerClass(env.getElement('D')); |
| 102 ClassElement E = registerClass(env.getElement('E')); | 104 ClassElement E = registerClass(env.getElement('E')); |
| 103 ClassElement F = registerClass(env.getElement('F')); | 105 ClassElement F = registerClass(env.getElement('F')); |
| 104 | 106 |
| 107 Selector nonExisting = new Selector.getter(const PublicName('nonExisting')); |
| 108 |
| 105 Expect.equals(Interceptor.superclass, Object_); | 109 Expect.equals(Interceptor.superclass, Object_); |
| 106 Expect.equals(JavaScriptObject.superclass, Interceptor); | 110 Expect.equals(JavaScriptObject.superclass, Interceptor); |
| 107 | 111 |
| 108 Expect.equals(A.superclass, JavaScriptObject); | 112 Expect.equals(A.superclass, JavaScriptObject); |
| 109 Expect.equals(B.superclass, JavaScriptObject); | 113 Expect.equals(B.superclass, JavaScriptObject); |
| 110 Expect.equals(C.superclass, JavaScriptObject); | 114 Expect.equals(C.superclass, JavaScriptObject); |
| 111 Expect.equals(D.superclass, JavaScriptObject); | 115 Expect.equals(D.superclass, JavaScriptObject); |
| 112 Expect.equals(E.superclass, Object_); | 116 Expect.equals(E.superclass, Object_); |
| 113 Expect.equals(F.superclass, Object_); | 117 Expect.equals(F.superclass, Object_); |
| 114 | 118 |
| 115 for (String name in classEnvironment.keys) { | 119 for (String name in classEnvironment.keys) { |
| 116 ClassElement cls = classEnvironment[name]; | 120 ClassElement cls = classEnvironment[name]; |
| 117 bool isInstantiated = false; | 121 bool isInstantiated = false; |
| 118 if (directlyInstantiated.contains(name)) { | 122 if (directlyInstantiated.contains(name)) { |
| 119 isInstantiated = true; | 123 isInstantiated = true; |
| 120 Expect.isTrue( | 124 Expect.isTrue( |
| 121 world.isDirectlyInstantiated(cls), | 125 world.isDirectlyInstantiated(cls), |
| 122 "Expected $name to be directly instantiated in `${mainSource}`:" | 126 "Expected $name to be directly instantiated in `${mainSource}`:" |
| 123 "\n${world.dump(cls)}"); | 127 "\n${world.dump(cls)}"); |
| 124 } | 128 } |
| 125 if (abstractlyInstantiated.contains(name)) { | 129 if (abstractlyInstantiated.contains(name)) { |
| 126 isInstantiated = true; | 130 isInstantiated = true; |
| 127 Expect.isTrue( | 131 Expect.isTrue( |
| 128 world.isAbstractlyInstantiated(cls), | 132 world.isAbstractlyInstantiated(cls), |
| 129 "Expected $name to be abstractly instantiated in `${mainSource}`:" | 133 "Expected $name to be abstractly instantiated in `${mainSource}`:" |
| 130 "\n${world.dump(cls)}"); | 134 "\n${world.dump(cls)}"); |
| 135 Expect.isTrue( |
| 136 world.needsNoSuchMethod(cls, nonExisting, ClassQuery.EXACT), |
| 137 "Expected $name to need noSuchMethod for $nonExisting."); |
| 138 Expect.isTrue( |
| 139 world.needsNoSuchMethod(cls, nonExisting, ClassQuery.SUBCLASS), |
| 140 "Expected $name to need noSuchMethod for $nonExisting."); |
| 141 Expect.isTrue( |
| 142 world.needsNoSuchMethod(cls, nonExisting, ClassQuery.SUBTYPE), |
| 143 "Expected $name to need noSuchMethod for $nonExisting."); |
| 131 } | 144 } |
| 132 if (indirectlyInstantiated.contains(name)) { | 145 if (indirectlyInstantiated.contains(name)) { |
| 133 isInstantiated = true; | 146 isInstantiated = true; |
| 134 Expect.isTrue( | 147 Expect.isTrue( |
| 135 world.isIndirectlyInstantiated(cls), | 148 world.isIndirectlyInstantiated(cls), |
| 136 "Expected $name to be indirectly instantiated in `${mainSource}`:" | 149 "Expected $name to be indirectly instantiated in `${mainSource}`:" |
| 137 "\n${world.dump(cls)}"); | 150 "\n${world.dump(cls)}"); |
| 138 } | 151 } |
| 139 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) { | 152 if (!isInstantiated && (name != 'Object' && name != 'Interceptor')) { |
| 140 Expect.isFalse( | 153 Expect.isFalse( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 165 | 178 |
| 166 await test('main() => newE();', directlyInstantiated: ['E']); | 179 await test('main() => newE();', directlyInstantiated: ['E']); |
| 167 | 180 |
| 168 await test('main() => newF();', directlyInstantiated: ['F']); | 181 await test('main() => newF();', directlyInstantiated: ['F']); |
| 169 | 182 |
| 170 await test('main() => [newD(), newE()];', | 183 await test('main() => [newD(), newE()];', |
| 171 directlyInstantiated: ['E'], | 184 directlyInstantiated: ['E'], |
| 172 abstractlyInstantiated: ['A', 'B', 'C', 'D'], | 185 abstractlyInstantiated: ['A', 'B', 'C', 'D'], |
| 173 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); | 186 indirectlyInstantiated: ['Object', 'Interceptor', 'JavaScriptObject']); |
| 174 } | 187 } |
| OLD | NEW |