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

Side by Side Diff: pkg/dev_compiler/test/codegen_expected/sunflower/sunflower.js

Issue 3009733002: fix how DDC finds its undefined constant (Closed)
Patch Set: rebase and rebuild JS files Created 3 years, 3 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 define(['dart_sdk'], function(dart_sdk) { 1 define(['dart_sdk'], function(dart_sdk) {
2 'use strict'; 2 'use strict';
3 const core = dart_sdk.core; 3 const core = dart_sdk.core;
4 const html = dart_sdk.html; 4 const html = dart_sdk.html;
5 const math = dart_sdk.math; 5 const math = dart_sdk.math;
6 const dart = dart_sdk.dart; 6 const dart = dart_sdk.dart;
7 const dartx = dart_sdk.dartx; 7 const dartx = dart_sdk.dartx;
8 const sunflower = Object.create(null); 8 const sunflower = Object.create(null);
9 const circle = Object.create(null); 9 const circle = Object.create(null);
10 const painter = Object.create(null); 10 const painter = Object.create(null);
11 const $getContext = dartx.getContext;
12 const $addEventListener = dartx.addEventListener;
13 const $text = dartx.text;
14 const $arc = dartx.arc;
15 const $fill = dartx.fill;
11 let StringToElement = () => (StringToElement = dart.constFn(dart.fnType(html.E lement, [core.String])))(); 16 let StringToElement = () => (StringToElement = dart.constFn(dart.fnType(html.E lement, [core.String])))();
12 let EventTovoid = () => (EventTovoid = dart.constFn(dart.fnType(dart.void, [ht ml.Event])))(); 17 let EventTovoid = () => (EventTovoid = dart.constFn(dart.fnType(dart.void, [ht ml.Event])))();
13 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.fnType(dart.void, []))) (); 18 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.fnType(dart.void, []))) ();
14 dart.defineLazy(sunflower, { 19 dart.defineLazy(sunflower, {
15 get SEED_RADIUS() { 20 get SEED_RADIUS() {
16 return 2; 21 return 2;
17 }, 22 },
18 get SCALE_FACTOR() { 23 get SCALE_FACTOR() {
19 return 4; 24 return 4;
20 }, 25 },
21 get MAX_D() { 26 get MAX_D() {
22 return 300; 27 return 300;
23 }, 28 },
24 get centerX() { 29 get centerX() {
25 return sunflower.MAX_D / 2; 30 return sunflower.MAX_D / 2;
26 }, 31 },
27 get centerY() { 32 get centerY() {
28 return sunflower.centerX; 33 return sunflower.centerX;
29 } 34 }
30 }); 35 });
31 sunflower.querySelector = function(selector) { 36 sunflower.querySelector = function(selector) {
32 return html.document.querySelector(selector); 37 return html.document.querySelector(selector);
33 }; 38 };
34 dart.fn(sunflower.querySelector, StringToElement()); 39 dart.fn(sunflower.querySelector, StringToElement());
35 dart.defineLazy(sunflower, { 40 dart.defineLazy(sunflower, {
36 get canvas() { 41 get canvas() {
37 return html.CanvasElement.as(sunflower.querySelector("#canvas")); 42 return html.CanvasElement.as(sunflower.querySelector("#canvas"));
38 }, 43 },
39 get context() { 44 get context() {
40 return html.CanvasRenderingContext2D.as(sunflower.canvas[dartx.getContext] ('2d')); 45 return html.CanvasRenderingContext2D.as(sunflower.canvas[$getContext]('2d' ));
41 }, 46 },
42 get slider() { 47 get slider() {
43 return html.InputElement.as(sunflower.querySelector("#slider")); 48 return html.InputElement.as(sunflower.querySelector("#slider"));
44 }, 49 },
45 get notes() { 50 get notes() {
46 return sunflower.querySelector("#notes"); 51 return sunflower.querySelector("#notes");
47 }, 52 },
48 get PHI() { 53 get PHI() {
49 return (math.sqrt(5) + 1) / 2; 54 return (math.sqrt(5) + 1) / 2;
50 }, 55 },
51 get seeds() { 56 get seeds() {
52 return 0; 57 return 0;
53 }, 58 },
54 set seeds(_) {} 59 set seeds(_) {}
55 }); 60 });
56 sunflower.main = function() { 61 sunflower.main = function() {
57 sunflower.slider[dartx.addEventListener]('change', dart.fn(e => sunflower.dr aw(), EventTovoid())); 62 sunflower.slider[$addEventListener]('change', dart.fn(e => sunflower.draw(), EventTovoid()));
58 sunflower.draw(); 63 sunflower.draw();
59 }; 64 };
60 dart.fn(sunflower.main, VoidTovoid()); 65 dart.fn(sunflower.main, VoidTovoid());
61 sunflower.draw = function() { 66 sunflower.draw = function() {
62 sunflower.seeds = core.int.parse(sunflower.slider.value); 67 sunflower.seeds = core.int.parse(sunflower.slider.value);
63 sunflower.context.clearRect(0, 0, sunflower.MAX_D, sunflower.MAX_D); 68 sunflower.context.clearRect(0, 0, sunflower.MAX_D, sunflower.MAX_D);
64 for (let i = 0; i < dart.notNull(sunflower.seeds); i++) { 69 for (let i = 0; i < dart.notNull(sunflower.seeds); i++) {
65 let theta = i * painter.TAU / dart.notNull(sunflower.PHI); 70 let theta = i * painter.TAU / dart.notNull(sunflower.PHI);
66 let r = math.sqrt(i) * sunflower.SCALE_FACTOR; 71 let r = math.sqrt(i) * sunflower.SCALE_FACTOR;
67 let x = sunflower.centerX + r * math.cos(theta); 72 let x = sunflower.centerX + r * math.cos(theta);
68 let y = sunflower.centerY - r * math.sin(theta); 73 let y = sunflower.centerY - r * math.sin(theta);
69 new sunflower.SunflowerSeed.new(x, y, sunflower.SEED_RADIUS).draw(sunflowe r.context); 74 new sunflower.SunflowerSeed.new(x, y, sunflower.SEED_RADIUS).draw(sunflowe r.context);
70 } 75 }
71 sunflower.notes[dartx.text] = dart.str`${sunflower.seeds} seeds`; 76 sunflower.notes[$text] = dart.str`${sunflower.seeds} seeds`;
72 }; 77 };
73 dart.fn(sunflower.draw, VoidTovoid()); 78 dart.fn(sunflower.draw, VoidTovoid());
74 circle.Circle = class Circle extends core.Object { 79 circle.Circle = class Circle extends core.Object {
75 get x() { 80 get x() {
76 return this[x$]; 81 return this[x$];
77 } 82 }
78 set x(value) { 83 set x(value) {
79 super.x = value; 84 super.x = value;
80 } 85 }
81 get y() { 86 get y() {
82 return this[y$]; 87 return this[y$];
83 } 88 }
84 set y(value) { 89 set y(value) {
85 super.y = value; 90 super.y = value;
86 } 91 }
87 get radius() { 92 get radius() {
88 return this[radius$]; 93 return this[radius$];
89 } 94 }
90 set radius(value) { 95 set radius(value) {
91 super.radius = value; 96 super.radius = value;
92 } 97 }
93 }; 98 };
94 (circle.Circle.new = function(x, y, radius) { 99 (circle.Circle.new = function(x, y, radius) {
95 this[x$] = x; 100 this[x$] = x;
96 this[y$] = y; 101 this[y$] = y;
97 this[radius$] = radius; 102 this[radius$] = radius;
98 }).prototype = circle.Circle.prototype; 103 }).prototype = circle.Circle.prototype;
104 dart.addTypeTests(circle.Circle);
99 const x$ = Symbol("Circle.x"); 105 const x$ = Symbol("Circle.x");
100 const y$ = Symbol("Circle.y"); 106 const y$ = Symbol("Circle.y");
101 const radius$ = Symbol("Circle.radius"); 107 const radius$ = Symbol("Circle.radius");
102 dart.setSignature(circle.Circle, { 108 dart.setSignature(circle.Circle, {
103 fields: () => ({ 109 fields: () => ({
104 x: dart.finalFieldType(core.num), 110 x: dart.finalFieldType(core.num),
105 y: dart.finalFieldType(core.num), 111 y: dart.finalFieldType(core.num),
106 radius: dart.finalFieldType(core.num) 112 radius: dart.finalFieldType(core.num)
107 }) 113 })
108 }); 114 });
109 painter.CirclePainter = class CirclePainter extends core.Object { 115 painter.CirclePainter = class CirclePainter extends core.Object {
110 get color() { 116 get color() {
111 return this[color]; 117 return this[color];
112 } 118 }
113 set color(value) { 119 set color(value) {
114 this[color] = value; 120 this[color] = value;
115 } 121 }
116 draw(context) { 122 draw(context) {
117 context.beginPath(); 123 context.beginPath();
118 context.lineWidth = 2; 124 context.lineWidth = 2;
119 context.fillStyle = this.color; 125 context.fillStyle = this.color;
120 context.strokeStyle = this.color; 126 context.strokeStyle = this.color;
121 context[dartx.arc](this.x, this.y, this.radius, 0, painter.TAU, false); 127 context[$arc](this.x, this.y, this.radius, 0, painter.TAU, false);
122 context[dartx.fill](); 128 context[$fill]();
123 context.closePath(); 129 context.closePath();
124 context.stroke(); 130 context.stroke();
125 } 131 }
126 }; 132 };
127 (painter.CirclePainter.new = function() { 133 (painter.CirclePainter.new = function() {
128 this[color] = painter.ORANGE; 134 this[color] = painter.ORANGE;
129 }).prototype = painter.CirclePainter.prototype; 135 }).prototype = painter.CirclePainter.prototype;
136 dart.addTypeTests(painter.CirclePainter);
130 const color = Symbol("CirclePainter.color"); 137 const color = Symbol("CirclePainter.color");
131 painter.CirclePainter[dart.implements] = () => [circle.Circle]; 138 painter.CirclePainter[dart.implements] = () => [circle.Circle];
132 dart.setSignature(painter.CirclePainter, { 139 dart.setSignature(painter.CirclePainter, {
133 fields: () => ({color: dart.fieldType(core.String)}), 140 fields: () => ({color: dart.fieldType(core.String)}),
134 methods: () => ({draw: dart.fnType(dart.void, [html.CanvasRenderingContext2D ])}) 141 methods: () => ({draw: dart.fnType(dart.void, [html.CanvasRenderingContext2D ])})
135 }); 142 });
136 sunflower.SunflowerSeed = class SunflowerSeed extends dart.mixin(circle.Circle , painter.CirclePainter) {}; 143 sunflower.SunflowerSeed = class SunflowerSeed extends dart.mixin(circle.Circle , painter.CirclePainter) {};
137 (sunflower.SunflowerSeed.new = function(x, y, radius, color) { 144 (sunflower.SunflowerSeed.new = function(x, y, radius, color) {
138 if (color === void 0) color = null; 145 if (color === void 0) color = null;
139 sunflower.SunflowerSeed.__proto__.new.call(this, x, y, radius); 146 sunflower.SunflowerSeed.__proto__.new.call(this, x, y, radius);
140 if (color != null) this.color = color; 147 if (color != null) this.color = color;
141 }).prototype = sunflower.SunflowerSeed.prototype; 148 }).prototype = sunflower.SunflowerSeed.prototype;
149 dart.addTypeTests(sunflower.SunflowerSeed);
142 dart.defineLazy(painter, { 150 dart.defineLazy(painter, {
143 get ORANGE() { 151 get ORANGE() {
144 return "orange"; 152 return "orange";
145 }, 153 },
146 get RED() { 154 get RED() {
147 return "red"; 155 return "red";
148 }, 156 },
149 get BLUE() { 157 get BLUE() {
150 return "blue"; 158 return "blue";
151 }, 159 },
152 get TAU() { 160 get TAU() {
153 return math.PI * 2; 161 return math.PI * 2;
154 } 162 }
155 }); 163 });
156 painter.querySelector = function(selector) { 164 painter.querySelector = function(selector) {
157 return html.document.querySelector(selector); 165 return html.document.querySelector(selector);
158 }; 166 };
159 dart.fn(painter.querySelector, StringToElement()); 167 dart.fn(painter.querySelector, StringToElement());
160 dart.defineLazy(painter, { 168 dart.defineLazy(painter, {
161 get canvas() { 169 get canvas() {
162 return html.CanvasElement.as(painter.querySelector("#canvas")); 170 return html.CanvasElement.as(painter.querySelector("#canvas"));
163 }, 171 },
164 get context() { 172 get context() {
165 return html.CanvasRenderingContext2D.as(painter.canvas[dartx.getContext](' 2d')); 173 return html.CanvasRenderingContext2D.as(painter.canvas[$getContext]('2d')) ;
166 } 174 }
167 }); 175 });
168 dart.trackLibraries("sunflower", { 176 dart.trackLibraries("sunflower", {
169 "sunflower.dart": sunflower, 177 "sunflower.dart": sunflower,
170 "circle.dart": circle, 178 "circle.dart": circle,
171 "painter.dart": painter 179 "painter.dart": painter
172 }, null); 180 }, null);
173 // Exports: 181 // Exports:
174 return { 182 return {
175 sunflower: sunflower, 183 sunflower: sunflower,
176 circle: circle, 184 circle: circle,
177 painter: painter 185 painter: painter
178 }; 186 };
179 }); 187 });
180 188
181 //# sourceMappingURL=sunflower.js.map 189 //# sourceMappingURL=sunflower.js.map
OLDNEW
« no previous file with comments | « pkg/dev_compiler/test/codegen_expected/script.js ('k') | pkg/dev_compiler/test/codegen_expected/sunflower/sunflower.js.map » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698