| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:async'; | 5 import 'dart:async'; | 
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; | 
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; | 
| 8 import "package:compiler/src/dart2jslib.dart"; | 8 import "package:compiler/src/dart2jslib.dart"; | 
| 9 import "package:compiler/src/elements/elements.dart"; | 9 import "package:compiler/src/elements/elements.dart"; | 
| 10 import "package:compiler/src/tree/tree.dart"; | 10 import "package:compiler/src/tree/tree.dart"; | 
| 11 import "package:compiler/src/types/types.dart"; |  | 
| 12 import "mock_compiler.dart"; | 11 import "mock_compiler.dart"; | 
| 13 import "mock_libraries.dart"; | 12 import "mock_libraries.dart"; | 
| 14 import 'package:compiler/src/elements/modelx.dart'; | 13 import 'package:compiler/src/elements/modelx.dart'; | 
| 15 | 14 | 
| 16 Future<Compiler> applyPatch(String script, String patch, | 15 Future<Compiler> applyPatch(String script, String patch, | 
| 17                             {bool analyzeAll: false, | 16                             {bool analyzeAll: false, | 
| 18                              bool analyzeOnly: false, | 17                              bool analyzeOnly: false, | 
| 19                              bool runCompiler: false, | 18                              bool runCompiler: false, | 
| 20                              String main: "", | 19                              String main: "", | 
| 21                              String patchVersion}) { | 20                              String patchVersion}) { | 
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 862            checkHasBody: true, expectIsRegular: true); | 861            checkHasBody: true, expectIsRegular: true); | 
| 863 | 862 | 
| 864     ensure(compiler, "clear", cls.lookupLocalMember, | 863     ensure(compiler, "clear", cls.lookupLocalMember, | 
| 865            checkHasBody: true, expectIsPatched: true); | 864            checkHasBody: true, expectIsPatched: true); | 
| 866 | 865 | 
| 867     compiler.phase = Compiler.PHASE_DONE_RESOLVING; | 866     compiler.phase = Compiler.PHASE_DONE_RESOLVING; | 
| 868 | 867 | 
| 869     // Check that a method just in the patch class is a target for a | 868     // Check that a method just in the patch class is a target for a | 
| 870     // typed selector. | 869     // typed selector. | 
| 871     Selector selector = new Selector.call('method', compiler.coreLibrary, 0); | 870     Selector selector = new Selector.call('method', compiler.coreLibrary, 0); | 
| 872     TypeMask typeMask = new TypeMask.exact(cls, world); | 871     TypedSelector typedSelector = new TypedSelector.exact(cls, selector, world); | 
| 873     FunctionElement method = cls.implementation.lookupLocalMember('method'); | 872     FunctionElement method = cls.implementation.lookupLocalMember('method'); | 
| 874     method.computeType(compiler); | 873     method.computeSignature(compiler); | 
| 875     Expect.isTrue(selector.applies(method, world)); | 874     Expect.isTrue(selector.applies(method, world)); | 
| 876     Expect.isTrue(typeMask.canHit(method, selector, world)); | 875     Expect.isTrue(typedSelector.applies(method, world)); | 
| 877 | 876 | 
| 878     // Check that the declaration method in the declaration class is a target | 877     // Check that the declaration method in the declaration class is a target | 
| 879     // for a typed selector. | 878     // for a typed selector. | 
| 880     selector = new Selector.call('clear', compiler.coreLibrary, 0); | 879     selector = new Selector.call('clear', compiler.coreLibrary, 0); | 
| 881     typeMask = new TypeMask.exact(cls, world); | 880     typedSelector = new TypedSelector.exact(cls, selector, world); | 
| 882     method = cls.lookupLocalMember('clear'); | 881     method = cls.lookupLocalMember('clear'); | 
| 883     method.computeType(compiler); | 882     method.computeSignature(compiler); | 
| 884     Expect.isTrue(selector.applies(method, world)); | 883     Expect.isTrue(selector.applies(method, world)); | 
| 885     Expect.isTrue(typeMask.canHit(method, selector, world)); | 884     Expect.isTrue(typedSelector.applies(method, world)); | 
| 886 | 885 | 
| 887     // Check that the declaration method in the declaration class is a target | 886     // Check that the declaration method in the declaration class is a target | 
| 888     // for a typed selector on a subclass. | 887     // for a typed selector on a subclass. | 
| 889     cls = ensure(compiler, "B", compiler.coreLibrary.find); | 888     cls = ensure(compiler, "B", compiler.coreLibrary.find); | 
| 890     cls.ensureResolved(compiler); | 889     cls.ensureResolved(compiler); | 
| 891     typeMask = new TypeMask.exact(cls, world); | 890     typedSelector = new TypedSelector.exact(cls, selector, world); | 
| 892     Expect.isTrue(selector.applies(method, world)); | 891     Expect.isTrue(selector.applies(method, world)); | 
| 893     Expect.isTrue(typeMask.canHit(method, selector, world)); | 892     Expect.isTrue(typedSelector.applies(method, world)); | 
| 894   })); | 893   })); | 
| 895 } | 894 } | 
| 896 | 895 | 
| 897 void testAnalyzeAllInjectedMembers() { | 896 void testAnalyzeAllInjectedMembers() { | 
| 898   void expect(String patchText, [expectedWarnings]) { | 897   void expect(String patchText, [expectedWarnings]) { | 
| 899     if (expectedWarnings == null) expectedWarnings = []; | 898     if (expectedWarnings == null) expectedWarnings = []; | 
| 900     if (expectedWarnings is! List) { | 899     if (expectedWarnings is! List) { | 
| 901       expectedWarnings = <MessageKind>[expectedWarnings]; | 900       expectedWarnings = <MessageKind>[expectedWarnings]; | 
| 902     } | 901     } | 
| 903 | 902 | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 947       B.patchTarget() : super(); | 946       B.patchTarget() : super(); | 
| 948       factory B.reflectBack() = B.originTarget; | 947       factory B.reflectBack() = B.originTarget; | 
| 949     } | 948     } | 
| 950     """; | 949     """; | 
| 951 | 950 | 
| 952   asyncTest(() => applyPatch(origin, patch, analyzeAll: true, | 951   asyncTest(() => applyPatch(origin, patch, analyzeAll: true, | 
| 953                  analyzeOnly: true, runCompiler: true).then((compiler) { | 952                  analyzeOnly: true, runCompiler: true).then((compiler) { | 
| 954     ClassElement clsA = compiler.coreLibrary.find("A"); | 953     ClassElement clsA = compiler.coreLibrary.find("A"); | 
| 955     ClassElement clsB = compiler.coreLibrary.find("B"); | 954     ClassElement clsB = compiler.coreLibrary.find("B"); | 
| 956 | 955 | 
| 957     ConstructorElement forward = clsA.lookupConstructor("forward"); | 956     Selector forwardCall = new Selector.callConstructor("forward", | 
|  | 957         compiler.coreLibrary); | 
|  | 958     ConstructorElement forward = clsA.lookupConstructor(forwardCall); | 
| 958     ConstructorElement target = forward.effectiveTarget; | 959     ConstructorElement target = forward.effectiveTarget; | 
| 959     Expect.isTrue(target.isPatch); | 960     Expect.isTrue(target.isPatch); | 
| 960     Expect.equals("patchTarget", target.name); | 961     Expect.equals("patchTarget", target.name); | 
| 961 | 962 | 
| 962     ConstructorElement forwardTwo = clsA.lookupConstructor("forwardTwo"); | 963     Selector forwardTwoCall = new Selector.callConstructor("forwardTwo", | 
|  | 964         compiler.coreLibrary); | 
|  | 965     ConstructorElement forwardTwo = clsA.lookupConstructor(forwardTwoCall); | 
| 963     target = forwardTwo.effectiveTarget; | 966     target = forwardTwo.effectiveTarget; | 
| 964     Expect.isFalse(forwardTwo.isErroneous); | 967     Expect.isFalse(forwardTwo.isErroneous); | 
| 965     Expect.isFalse(target.isPatch); | 968     Expect.isFalse(target.isPatch); | 
| 966     Expect.equals("originTarget", target.name); | 969     Expect.equals("originTarget", target.name); | 
| 967   })); | 970   })); | 
| 968 } | 971 } | 
| 969 | 972 | 
| 970 void testTypecheckPatchedMembers() { | 973 void testTypecheckPatchedMembers() { | 
| 971   String originText = "external void method();"; | 974   String originText = "external void method();"; | 
| 972   String patchText = """ | 975   String patchText = """ | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1015   testPatchNoSetter(); | 1018   testPatchNoSetter(); | 
| 1016   testPatchNonFunction(); | 1019   testPatchNonFunction(); | 
| 1017 | 1020 | 
| 1018   testPatchAndSelector(); | 1021   testPatchAndSelector(); | 
| 1019 | 1022 | 
| 1020   testEffectiveTarget(); /// bug: ok | 1023   testEffectiveTarget(); /// bug: ok | 
| 1021 | 1024 | 
| 1022   testAnalyzeAllInjectedMembers(); | 1025   testAnalyzeAllInjectedMembers(); | 
| 1023   testTypecheckPatchedMembers(); | 1026   testTypecheckPatchedMembers(); | 
| 1024 } | 1027 } | 
| OLD | NEW | 
|---|