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

Side by Side Diff: tool/input_sdk/private/js_number.dart

Issue 1153003003: fixes #40, extension methods for primitive types (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 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of _interceptors; 5 part of _interceptors;
6 6
7 /** 7 /**
8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler 8 * The super interceptor class for [JSInt] and [JSDouble]. The compiler
9 * recognizes this class as an interceptor, and changes references to 9 * recognizes this class as an interceptor, and changes references to
10 * [:this:] to actually use the receiver of the method, which is 10 * [:this:] to actually use the receiver of the method, which is
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 Type get runtimeType => num; 334 Type get runtimeType => num;
335 } 335 }
336 336
337 /** 337 /**
338 * The interceptor class for [int]s. 338 * The interceptor class for [int]s.
339 * 339 *
340 * This class implements double since in JavaScript all numbers are doubles, so 340 * This class implements double since in JavaScript all numbers are doubles, so
341 * while we want to treat `2.0` as an integer for some operations, its 341 * while we want to treat `2.0` as an integer for some operations, its
342 * interceptor should answer `true` to `is double`. 342 * interceptor should answer `true` to `is double`.
343 */ 343 */
344 // TODO(jmesserly): for dev_compiler all numbers will get `int` members at
345 // runtime for dynamic dispatch. We can fix by checking it at dispatch time.
346 @JsPeerInterface(name: 'Number')
344 class JSInt extends JSNumber implements int, double { 347 class JSInt extends JSNumber implements int, double {
345 const JSInt(); 348 const JSInt();
346 349
347 bool get isEven => (this & 1) == 0; 350 bool get isEven => (this & 1) == 0;
348 351
349 bool get isOdd => (this & 1) == 1; 352 bool get isOdd => (this & 1) == 1;
350 353
351 int toUnsigned(int width) { 354 int toUnsigned(int width) {
352 return this & ((1 << width) - 1); 355 return this & ((1 << width) - 1);
353 } 356 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 416 }
414 417
415 class JSDouble extends JSNumber implements double { 418 class JSDouble extends JSNumber implements double {
416 const JSDouble(); 419 const JSDouble();
417 Type get runtimeType => double; 420 Type get runtimeType => double;
418 } 421 }
419 422
420 class JSPositiveInt extends JSInt {} 423 class JSPositiveInt extends JSInt {}
421 class JSUInt32 extends JSPositiveInt {} 424 class JSUInt32 extends JSPositiveInt {}
422 class JSUInt31 extends JSUInt32 {} 425 class JSUInt31 extends JSUInt32 {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698