Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: tests/compiler/dart2js_native/browser_compat_2_test.dart

Issue 2990083002: dart2js_native tests: Migrate 'native STRING' to JS-calls - part 2/2 (Closed)
Patch Set: remove defunct comments Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "native_testing.dart";
6 6
7 // Test for dartNativeDispatchHooksTransformer 7 // Test for dartNativeDispatchHooksTransformer
8 // - uncached, instance, leaf and interior caching modes. 8 // - uncached, instance, leaf and interior caching modes.
9 // - composition of getTag. 9 // - composition of getTag.
10 10
(...skipping 18 matching lines...) Expand all
29 } 29 }
30 30
31 makeT1A() native; 31 makeT1A() native;
32 makeT1B() native; 32 makeT1B() native;
33 makeT1C() native; 33 makeT1C() native;
34 makeT1D() native; 34 makeT1D() native;
35 35
36 int getTagCallCount() native; 36 int getTagCallCount() native;
37 void clearTagCallCount() native; 37 void clearTagCallCount() native;
38 38
39 void setup() native r''' 39 void setup() {
40 JS('', r'''
41 (function(){
40 function T1A() { this.v = "a"; } 42 function T1A() { this.v = "a"; }
41 function T1B() { this.v = "b"; } 43 function T1B() { this.v = "b"; }
42 function T1C() { this.v = "c"; } 44 function T1C() { this.v = "c"; }
43 function T1D() { this.v = "d"; } 45 function T1D() { this.v = "d"; }
44 46
45 // T1B, T1C and T1D extend T1A in the implementation but not the declared types. 47 // T1B, T1C and T1D extend T1A in the implementation but not the declared types.
46 // T1A must not be leaf-cached otherwise we will pick up the interceptor for T1A 48 // T1A must not be leaf-cached otherwise we will pick up the interceptor for T1A
47 // when looking for the dispatch record for an uncached or not-yet-cached T1B, 49 // when looking for the dispatch record for an uncached or not-yet-cached T1B,
48 // T1C or T1D. 50 // T1C or T1D.
49 T1B.prototype.__proto__ = T1A.prototype; 51 T1B.prototype.__proto__ = T1A.prototype;
50 T1C.prototype.__proto__ = T1A.prototype; 52 T1C.prototype.__proto__ = T1A.prototype;
51 T1D.prototype.__proto__ = T1A.prototype; 53 T1D.prototype.__proto__ = T1A.prototype;
52 54
53 // All classes share one implementation of native method 'foo'. 55 // All classes share one implementation of native method 'foo'.
54 T1A.prototype.foo = function() { return this.v + this.name(); } 56 T1A.prototype.foo = function() { return this.v + this.name(); };
55 T1A.prototype.name = function() { return "A"; } 57 T1A.prototype.name = function() { return "A"; };
56 T1B.prototype.name = function() { return "B"; } 58 T1B.prototype.name = function() { return "B"; };
57 T1C.prototype.name = function() { return "C"; } 59 T1C.prototype.name = function() { return "C"; };
58 T1D.prototype.name = function() { return "D"; } 60 T1D.prototype.name = function() { return "D"; };
59 61
60 makeT1A = function(){return new T1A;}; 62 makeT1A = function(){return new T1A()};
61 makeT1B = function(){return new T1B;}; 63 makeT1B = function(){return new T1B()};
62 makeT1C = function(){return new T1C;}; 64 makeT1C = function(){return new T1C()};
63 makeT1D = function(){return new T1D;}; 65 makeT1D = function(){return new T1D()};
64 66
65 self.nativeConstructor(T1A); 67 self.nativeConstructor(T1A);
66 self.nativeConstructor(T1B); 68 self.nativeConstructor(T1B);
67 self.nativeConstructor(T1C); 69 self.nativeConstructor(T1C);
68 self.nativeConstructor(T1D); 70 self.nativeConstructor(T1D);
69 71
70 var getTagCount = 0; 72 var getTagCount = 0;
71 getTagCallCount = function() { return getTagCount; } 73 getTagCallCount = function() { return getTagCount; };
72 clearTagCallCount = function() { getTagCount = 0; } 74 clearTagCallCount = function() { getTagCount = 0; };
73 75
74 function transformer1(hooks) { 76 function transformer1(hooks) {
75 var getTag = hooks.getTag; 77 var getTag = hooks.getTag;
76 78
77 function getTagNew(obj) { 79 function getTagNew(obj) {
78 var tag = getTag(obj); 80 var tag = getTag(obj);
79 // Dependency to test composition, rename T1D -> Dep -> -T1D. 81 // Dependency to test composition, rename T1D -> Dep -> -T1D.
80 if (tag == "T1D") return "Dep"; 82 if (tag == "T1D") return "Dep";
81 return tag; 83 return tag;
82 } 84 }
(...skipping 11 matching lines...) Expand all
94 if (tag == "T1B") return "~T1B"; // Uncached 96 if (tag == "T1B") return "~T1B"; // Uncached
95 if (tag == "T1C") return "!T1C"; // Instance cached 97 if (tag == "T1C") return "!T1C"; // Instance cached
96 if (tag == "Dep") return "-T1D"; // Leaf cached on prototype 98 if (tag == "Dep") return "-T1D"; // Leaf cached on prototype
97 return tag; 99 return tag;
98 } 100 }
99 101
100 hooks.getTag = getTagNew; 102 hooks.getTag = getTagNew;
101 } 103 }
102 104
103 dartNativeDispatchHooksTransformer = [transformer1, transformer2]; 105 dartNativeDispatchHooksTransformer = [transformer1, transformer2];
104 '''; 106 })()''');
107 }
105 108
106 main() { 109 main() {
107 nativeTesting(); 110 nativeTesting();
108 setup(); 111 setup();
109 112
110 var t1a = makeT1A(); 113 var t1a = makeT1A();
111 var t1b = makeT1B(); 114 var t1b = makeT1B();
112 var t1c = makeT1C(); 115 var t1c = makeT1C();
113 var t1d = makeT1D(); 116 var t1d = makeT1D();
114 117
(...skipping 25 matching lines...) Expand all
140 '2 = 1 fresh instance + 1 uncached (+ 2 proto cached)'); 143 '2 = 1 fresh instance + 1 uncached (+ 2 proto cached)');
141 144
142 clearTagCallCount(); 145 clearTagCallCount();
143 Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A'); 146 Expect.equals("aA", confuse(t1a).foo(), 't1a is T1A');
144 Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B'); 147 Expect.equals("bB", confuse(t1b).foo(), 't1b is T1B');
145 Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C'); 148 Expect.equals("cC", confuse(t1c).foo(), 't1c is T1C');
146 Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D'); 149 Expect.equals("dD", confuse(t1d).foo(), 't1d is T1D');
147 Expect.equals(1, getTagCallCount(), 150 Expect.equals(1, getTagCallCount(),
148 '1 = 2 proto cached + 1 instance cached + 1 uncached'); 151 '1 = 2 proto cached + 1 instance cached + 1 uncached');
149 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698