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

Side by Side Diff: lib/runtime/dart/math.js

Issue 1156993015: fixes #193, factory constructors as static methods (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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 var math = dart.defineLibrary(math, {}); 1 var math = dart.defineLibrary(math, {});
2 var core = dart.import(core); 2 var core = dart.import(core);
3 var _js_helper = dart.lazyImport(_js_helper); 3 var _js_helper = dart.lazyImport(_js_helper);
4 (function(exports, core, _js_helper) { 4 (function(exports, core, _js_helper) {
5 'use strict'; 5 'use strict';
6 class _JenkinsSmiHash extends core.Object { 6 class _JenkinsSmiHash extends core.Object {
7 static combine(hash, value) { 7 static combine(hash, value) {
8 hash = 536870911 & dart.notNull(hash) + dart.notNull(value); 8 hash = 536870911 & dart.notNull(hash) + dart.notNull(value);
9 hash = 536870911 & dart.notNull(hash) + ((524287 & dart.notNull(hash)) << 10); 9 hash = 536870911 & dart.notNull(hash) + ((524287 & dart.notNull(hash)) << 10);
10 return dart.notNull(hash) ^ dart.notNull(hash) >> 6; 10 return dart.notNull(hash) ^ dart.notNull(hash) >> 6;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 '-': [Point$(T), [Point$(T)]], 81 '-': [Point$(T), [Point$(T)]],
82 '*': [Point$(T), [core.num]], 82 '*': [Point$(T), [core.num]],
83 distanceTo: [core.double, [Point$(T)]], 83 distanceTo: [core.double, [Point$(T)]],
84 squaredDistanceTo: [T, [Point$(T)]] 84 squaredDistanceTo: [T, [Point$(T)]]
85 }) 85 })
86 }); 86 });
87 return Point; 87 return Point;
88 }); 88 });
89 let Point = Point$(); 89 let Point = Point$();
90 class Random extends core.Object { 90 class Random extends core.Object {
91 Random(seed) { 91 static new(seed) {
92 if (seed === void 0) 92 if (seed === void 0)
93 seed = null; 93 seed = null;
94 return seed == null ? dart.const(new _JSRandom()) : new _Random(seed); 94 return seed == null ? dart.const(new _JSRandom()) : new _Random(seed);
95 } 95 }
96 } 96 }
97 dart.setSignature(Random, { 97 dart.setSignature(Random, {
98 constructors: () => ({Random: [Random, [], [core.int]]}) 98 constructors: () => ({new: [Random, [], [core.int]]})
99 }); 99 });
100 let _RectangleBase$ = dart.generic(function(T) { 100 let _RectangleBase$ = dart.generic(function(T) {
101 class _RectangleBase extends core.Object { 101 class _RectangleBase extends core.Object {
102 _RectangleBase() { 102 _RectangleBase() {
103 } 103 }
104 get right() { 104 get right() {
105 return dart.as(this.left['+'](this.width), T); 105 return dart.as(this.left['+'](this.width), T);
106 } 106 }
107 get bottom() { 107 get bottom() {
108 return dart.as(this.top['+'](this.height), T); 108 return dart.as(this.top['+'](this.height), T);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 let _RectangleBase = _RectangleBase$(); 176 let _RectangleBase = _RectangleBase$();
177 let Rectangle$ = dart.generic(function(T) { 177 let Rectangle$ = dart.generic(function(T) {
178 class Rectangle extends _RectangleBase$(T) { 178 class Rectangle extends _RectangleBase$(T) {
179 Rectangle(left, top, width, height) { 179 Rectangle(left, top, width, height) {
180 this.left = left; 180 this.left = left;
181 this.top = top; 181 this.top = top;
182 this.width = dart.as(width['<'](0) ? dart.notNull(width['unary-']()) * 0 : width, T); 182 this.width = dart.as(width['<'](0) ? dart.notNull(width['unary-']()) * 0 : width, T);
183 this.height = dart.as(height['<'](0) ? dart.notNull(height['unary-']()) * 0 : height, T); 183 this.height = dart.as(height['<'](0) ? dart.notNull(height['unary-']()) * 0 : height, T);
184 super._RectangleBase(); 184 super._RectangleBase();
185 } 185 }
186 fromPoints(a, b) { 186 static fromPoints(a, b) {
187 let left = dart.as(min(a.x, b.x), T); 187 let left = dart.as(min(a.x, b.x), T);
188 let width = dart.as(max(a.x, b.x)['-'](left), T); 188 let width = dart.as(max(a.x, b.x)['-'](left), T);
189 let top = dart.as(min(a.y, b.y), T); 189 let top = dart.as(min(a.y, b.y), T);
190 let height = dart.as(max(a.y, b.y)['-'](top), T); 190 let height = dart.as(max(a.y, b.y)['-'](top), T);
191 return new (Rectangle$(T))(left, top, width, height); 191 return new (Rectangle$(T))(left, top, width, height);
192 } 192 }
193 } 193 }
194 dart.defineNamedConstructor(Rectangle, 'fromPoints');
195 dart.setSignature(Rectangle, { 194 dart.setSignature(Rectangle, {
196 constructors: () => ({ 195 constructors: () => ({
197 Rectangle: [Rectangle$(T), [T, T, T, T]], 196 Rectangle: [Rectangle$(T), [T, T, T, T]],
198 fromPoints: [Rectangle$(T), [Point$(T), Point$(T)]] 197 fromPoints: [Rectangle$(T), [Point$(T), Point$(T)]]
199 }) 198 })
200 }); 199 });
201 return Rectangle; 200 return Rectangle;
202 }); 201 });
203 let Rectangle = Rectangle$(); 202 let Rectangle = Rectangle$();
204 let _width = Symbol('_width'); 203 let _width = Symbol('_width');
205 let _height = Symbol('_height'); 204 let _height = Symbol('_height');
206 let MutableRectangle$ = dart.generic(function(T) { 205 let MutableRectangle$ = dart.generic(function(T) {
207 class MutableRectangle extends _RectangleBase$(T) { 206 class MutableRectangle extends _RectangleBase$(T) {
208 MutableRectangle(left, top, width, height) { 207 MutableRectangle(left, top, width, height) {
209 this.left = left; 208 this.left = left;
210 this.top = top; 209 this.top = top;
211 this[_width] = dart.as(width['<'](0) ? _clampToZero(width) : width, T); 210 this[_width] = dart.as(width['<'](0) ? _clampToZero(width) : width, T);
212 this[_height] = dart.as(height['<'](0) ? _clampToZero(height) : height, T); 211 this[_height] = dart.as(height['<'](0) ? _clampToZero(height) : height, T);
213 super._RectangleBase(); 212 super._RectangleBase();
214 } 213 }
215 fromPoints(a, b) { 214 static fromPoints(a, b) {
216 let left = dart.as(min(a.x, b.x), T); 215 let left = dart.as(min(a.x, b.x), T);
217 let width = dart.as(max(a.x, b.x)['-'](left), T); 216 let width = dart.as(max(a.x, b.x)['-'](left), T);
218 let top = dart.as(min(a.y, b.y), T); 217 let top = dart.as(min(a.y, b.y), T);
219 let height = dart.as(max(a.y, b.y)['-'](top), T); 218 let height = dart.as(max(a.y, b.y)['-'](top), T);
220 return new (MutableRectangle$(T))(left, top, width, height); 219 return new (MutableRectangle$(T))(left, top, width, height);
221 } 220 }
222 get width() { 221 get width() {
223 return this[_width]; 222 return this[_width];
224 } 223 }
225 set width(width) { 224 set width(width) {
226 dart.as(width, T); 225 dart.as(width, T);
227 if (width['<'](0)) 226 if (width['<'](0))
228 width = dart.as(_clampToZero(width), T); 227 width = dart.as(_clampToZero(width), T);
229 this[_width] = width; 228 this[_width] = width;
230 } 229 }
231 get height() { 230 get height() {
232 return this[_height]; 231 return this[_height];
233 } 232 }
234 set height(height) { 233 set height(height) {
235 dart.as(height, T); 234 dart.as(height, T);
236 if (height['<'](0)) 235 if (height['<'](0))
237 height = dart.as(_clampToZero(height), T); 236 height = dart.as(_clampToZero(height), T);
238 this[_height] = height; 237 this[_height] = height;
239 } 238 }
240 } 239 }
241 MutableRectangle[dart.implements] = () => [Rectangle$(T)]; 240 MutableRectangle[dart.implements] = () => [Rectangle$(T)];
242 dart.defineNamedConstructor(MutableRectangle, 'fromPoints');
243 dart.setSignature(MutableRectangle, { 241 dart.setSignature(MutableRectangle, {
244 constructors: () => ({ 242 constructors: () => ({
245 MutableRectangle: [MutableRectangle$(T), [T, T, T, T]], 243 MutableRectangle: [MutableRectangle$(T), [T, T, T, T]],
246 fromPoints: [MutableRectangle$(T), [Point$(T), Point$(T)]] 244 fromPoints: [MutableRectangle$(T), [Point$(T), Point$(T)]]
247 }) 245 })
248 }); 246 });
249 return MutableRectangle; 247 return MutableRectangle;
250 }); 248 });
251 let MutableRectangle = MutableRectangle$(); 249 let MutableRectangle = MutableRectangle$();
252 function _clampToZero(value) { 250 function _clampToZero(value) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 exports.sin = sin; 515 exports.sin = sin;
518 exports.cos = cos; 516 exports.cos = cos;
519 exports.tan = tan; 517 exports.tan = tan;
520 exports.acos = acos; 518 exports.acos = acos;
521 exports.asin = asin; 519 exports.asin = asin;
522 exports.atan = atan; 520 exports.atan = atan;
523 exports.sqrt = sqrt; 521 exports.sqrt = sqrt;
524 exports.exp = exp; 522 exports.exp = exp;
525 exports.log = log; 523 exports.log = log;
526 })(math, core, _js_helper); 524 })(math, core, _js_helper);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698