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