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

Unified Diff: lib/compiler/implementation/lib/math.dartp

Issue 10703188: Allow patch files to add top-level declarations to the patched library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix errors caught by editor. Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/patch_parser.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/lib/math.dartp
diff --git a/lib/compiler/implementation/lib/math.dartp b/lib/compiler/implementation/lib/math.dartp
index d1c6f68742cb06997c59d57ea1bd2ec9cffc348e..66000c89dca3cf0f75c2dac9bf937e0b88296dec 100644
--- a/lib/compiler/implementation/lib/math.dartp
+++ b/lib/compiler/implementation/lib/math.dartp
@@ -7,6 +7,10 @@
// 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',
@@ -15,7 +19,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;
@@ -74,24 +78,28 @@ patch num pow(num value, num exponent) {
return JS('num', @'Math.pow(#, #)', value, exponent);
}
-patch class _Random {
- // The Dart2JS implementation of Random doesn't use the seed.
- patch _Random([int seed]);
+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 int nextInt(int max) {
+ int nextInt(int max) {
if (max < 0) throw new IllegalArgumentException("negative max: $max");
- if (max > 0x100000000) max = 0x100000000;
- return JS("int", "Math.floor(Math.random() * #)", max);
+ if (max > 0xFFFFFFFF) max = 0xFFFFFFFF;
+ return JS("int", "(Math.random() * #) >>> 0", max);
}
/**
* Generates a positive random floating point value uniformly distributed on
* the range from 0.0, inclusive, to 1.0, exclusive.
*/
- patch double nextDouble() => JS("double", "Math.random()");
+ double nextDouble() => JS("double", "Math.random()");
/**
* Generates a random boolean value.
*/
- patch bool nextBool() => JS("bool", "Math.random() < 0.5");
+ bool nextBool() => JS("bool", "Math.random() < 0.5");
}
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/patch_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698