| 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 import "native_testing.dart"; | 5 import "dart:_js_helper"; | 
|  | 6 import "package:expect/expect.dart"; | 
| 6 | 7 | 
| 7 // Test for dartNativeDispatchHooksTransformer | 8 // Test for dartNativeDispatchHooksTransformer | 
| 8 //  - uncached, instance, leaf and interior caching modes. | 9 //  - uncached, instance, leaf and interior caching modes. | 
| 9 //  - composition of getTag. | 10 //  - composition of getTag. | 
| 10 | 11 | 
| 11 @Native("T1A") | 12 @Native("T1A") | 
| 12 class T1A { | 13 class T1A { | 
| 13   foo() native ; | 14   foo() native ; | 
| 14 } | 15 } | 
| 15 | 16 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 55 T1A.prototype.name = function() { return "A"; } | 56 T1A.prototype.name = function() { return "A"; } | 
| 56 T1B.prototype.name = function() { return "B"; } | 57 T1B.prototype.name = function() { return "B"; } | 
| 57 T1C.prototype.name = function() { return "C"; } | 58 T1C.prototype.name = function() { return "C"; } | 
| 58 T1D.prototype.name = function() { return "D"; } | 59 T1D.prototype.name = function() { return "D"; } | 
| 59 | 60 | 
| 60 makeT1A = function(){return new T1A;}; | 61 makeT1A = function(){return new T1A;}; | 
| 61 makeT1B = function(){return new T1B;}; | 62 makeT1B = function(){return new T1B;}; | 
| 62 makeT1C = function(){return new T1C;}; | 63 makeT1C = function(){return new T1C;}; | 
| 63 makeT1D = function(){return new T1D;}; | 64 makeT1D = function(){return new T1D;}; | 
| 64 | 65 | 
| 65 self.nativeConstructor(T1A); |  | 
| 66 self.nativeConstructor(T1B); |  | 
| 67 self.nativeConstructor(T1C); |  | 
| 68 self.nativeConstructor(T1D); |  | 
| 69 |  | 
| 70 var getTagCount = 0; | 66 var getTagCount = 0; | 
| 71 getTagCallCount = function() { return getTagCount; } | 67 getTagCallCount = function() { return getTagCount; } | 
| 72 clearTagCallCount = function() { getTagCount = 0; } | 68 clearTagCallCount = function() { getTagCount = 0; } | 
| 73 | 69 | 
| 74 function transformer1(hooks) { | 70 function transformer1(hooks) { | 
| 75   var getTag = hooks.getTag; | 71   var getTag = hooks.getTag; | 
| 76 | 72 | 
| 77   function getTagNew(obj) { | 73   function getTagNew(obj) { | 
| 78     var tag = getTag(obj); | 74     var tag = getTag(obj); | 
| 79     // Dependency to test composition, rename T1D -> Dep -> -T1D. | 75     // Dependency to test composition, rename T1D -> Dep -> -T1D. | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 96     if (tag == "Dep") return "-T1D";  // Leaf cached on prototype | 92     if (tag == "Dep") return "-T1D";  // Leaf cached on prototype | 
| 97     return tag; | 93     return tag; | 
| 98   } | 94   } | 
| 99 | 95 | 
| 100   hooks.getTag = getTagNew; | 96   hooks.getTag = getTagNew; | 
| 101 } | 97 } | 
| 102 | 98 | 
| 103 dartNativeDispatchHooksTransformer = [transformer1, transformer2]; | 99 dartNativeDispatchHooksTransformer = [transformer1, transformer2]; | 
| 104 '''; | 100 '''; | 
| 105 | 101 | 
|  | 102 var inscrutable; | 
|  | 103 | 
| 106 main() { | 104 main() { | 
| 107   nativeTesting(); |  | 
| 108   setup(); | 105   setup(); | 
|  | 106   inscrutable = (x) => x; | 
| 109 | 107 | 
| 110   var t1a = makeT1A(); | 108   var t1a = makeT1A(); | 
| 111   var t1b = makeT1B(); | 109   var t1b = makeT1B(); | 
| 112   var t1c = makeT1C(); | 110   var t1c = makeT1C(); | 
| 113   var t1d = makeT1D(); | 111   var t1d = makeT1D(); | 
| 114 | 112 | 
| 115   clearTagCallCount(); | 113   clearTagCallCount(); | 
| 116   Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A'); | 114   Expect.equals("aA", inscrutable(t1a).foo(), 't1a is T1A'); | 
| 117   Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B'); | 115   Expect.equals("bB", inscrutable(t1b).foo(), 't1b is T1B'); | 
| 118   Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C'); | 116   Expect.equals("cC", inscrutable(t1c).foo(), 't1c is T1C'); | 
| 119   Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D'); | 117   Expect.equals("dD", inscrutable(t1d).foo(), 't1d is T1D'); | 
| 120   Expect.equals(4, getTagCallCount(), '4 fresh instances / types'); | 118   Expect.equals(4, getTagCallCount(), '4 fresh instances / types'); | 
| 121 | 119 | 
| 122   clearTagCallCount(); | 120   clearTagCallCount(); | 
| 123   Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A'); | 121   Expect.equals("aA", inscrutable(t1a).foo(), 't1a is T1A'); | 
| 124   Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B'); | 122   Expect.equals("bB", inscrutable(t1b).foo(), 't1b is T1B'); | 
| 125   Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C'); | 123   Expect.equals("cC", inscrutable(t1c).foo(), 't1c is T1C'); | 
| 126   Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D'); | 124   Expect.equals("dD", inscrutable(t1d).foo(), 't1d is T1D'); | 
| 127   Expect.equals(1, getTagCallCount(), '1 = 1 uncached + (3 cached)'); | 125   Expect.equals(1, getTagCallCount(), '1 = 1 uncached + (3 cached)'); | 
| 128 | 126 | 
| 129   t1a = makeT1A(); | 127   t1a = makeT1A(); | 
| 130   t1b = makeT1B(); | 128   t1b = makeT1B(); | 
| 131   t1c = makeT1C(); | 129   t1c = makeT1C(); | 
| 132   t1d = makeT1D(); | 130   t1d = makeT1D(); | 
| 133 | 131 | 
| 134   clearTagCallCount(); | 132   clearTagCallCount(); | 
| 135   Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A'); | 133   Expect.equals("aA", inscrutable(t1a).foo(), 't1a is T1A'); | 
| 136   Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B'); | 134   Expect.equals("bB", inscrutable(t1b).foo(), 't1b is T1B'); | 
| 137   Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C'); | 135   Expect.equals("cC", inscrutable(t1c).foo(), 't1c is T1C'); | 
| 138   Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D'); | 136   Expect.equals("dD", inscrutable(t1d).foo(), 't1d is T1D'); | 
| 139   Expect.equals(2, getTagCallCount(), | 137   Expect.equals(2, getTagCallCount(), | 
| 140       '2 = 1 fresh instance + 1 uncached (+ 2 proto cached)'); | 138       '2 = 1 fresh instance + 1 uncached (+ 2 proto cached)'); | 
| 141 | 139 | 
| 142   clearTagCallCount(); | 140   clearTagCallCount(); | 
| 143   Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A'); | 141   Expect.equals("aA", inscrutable(t1a).foo(), 't1a is T1A'); | 
| 144   Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B'); | 142   Expect.equals("bB", inscrutable(t1b).foo(), 't1b is T1B'); | 
| 145   Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C'); | 143   Expect.equals("cC", inscrutable(t1c).foo(), 't1c is T1C'); | 
| 146   Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D'); | 144   Expect.equals("dD", inscrutable(t1d).foo(), 't1d is T1D'); | 
| 147   Expect.equals(1, getTagCallCount(), | 145   Expect.equals(1, getTagCallCount(), | 
| 148       '1 = 2 proto cached + 1 instance cached + 1 uncached'); | 146       '1 = 2 proto cached + 1 instance cached + 1 uncached'); | 
| 149 } | 147 } | 
| OLD | NEW | 
|---|