Index: lib/compiler/implementation/lib/math.dartp |
diff --git a/lib/compiler/implementation/lib/math.dartp b/lib/compiler/implementation/lib/math.dartp |
index 66000c89dca3cf0f75c2dac9bf937e0b88296dec..d1c6f68742cb06997c59d57ea1bd2ec9cffc348e 100644 |
--- a/lib/compiler/implementation/lib/math.dartp |
+++ b/lib/compiler/implementation/lib/math.dartp |
@@ -7,10 +7,6 @@ |
// Imports checkNum etc. used below. |
#import("js_helper.dart"); |
-// TODO(lrn): Consider not using the JS function directly, but instead calling |
-// helper functions in the "js_helper" library. Then we can stop enabling JS |
-// in all patched library files. |
- |
patch int parseInt(str) { |
checkString(str); |
if (!JS('bool', |
@@ -19,7 +15,7 @@ patch int parseInt(str) { |
throw new BadNumberFormatException(str); |
} |
var trimmed = str.trim(); |
- var base = 10; |
+ var base = 10;; |
if ((trimmed.length > 2 && (trimmed[1] == 'x' || trimmed[1] == 'X')) || |
(trimmed.length > 3 && (trimmed[2] == 'x' || trimmed[2] == 'X'))) { |
base = 16; |
@@ -78,28 +74,24 @@ patch num pow(num value, num exponent) { |
return JS('num', @'Math.pow(#, #)', value, exponent); |
} |
-patch class Random { |
- patch factory Random([int seed]) => const _Random(); |
-} |
- |
-class _Random implements Random { |
- // The Dart2JS implementation of Random doesn't use a seed. |
- _Random(); |
+patch class _Random { |
+ // The Dart2JS implementation of Random doesn't use the seed. |
+ patch _Random([int seed]); |
- int nextInt(int max) { |
+ patch int nextInt(int max) { |
if (max < 0) throw new IllegalArgumentException("negative max: $max"); |
- if (max > 0xFFFFFFFF) max = 0xFFFFFFFF; |
- return JS("int", "(Math.random() * #) >>> 0", max); |
+ if (max > 0x100000000) max = 0x100000000; |
+ return JS("int", "Math.floor(Math.random() * #)", max); |
} |
/** |
* Generates a positive random floating point value uniformly distributed on |
* the range from 0.0, inclusive, to 1.0, exclusive. |
*/ |
- double nextDouble() => JS("double", "Math.random()"); |
+ patch double nextDouble() => JS("double", "Math.random()"); |
/** |
* Generates a random boolean value. |
*/ |
- bool nextBool() => JS("bool", "Math.random() < 0.5"); |
+ patch bool nextBool() => JS("bool", "Math.random() < 0.5"); |
} |