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

Unified Diff: dart/frog/leg/lib/js_helper.dart

Issue 9425038: Implement Math API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 | « no previous file | dart/tests/co19/co19-leg.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/js_helper.dart
diff --git a/dart/frog/leg/lib/js_helper.dart b/dart/frog/leg/lib/js_helper.dart
index 8223235978705412bc65bca432523af4e33db418..6cee23de56b729b12946aec55fafc08ba4c54879 100644
--- a/dart/frog/leg/lib/js_helper.dart
+++ b/dart/frog/leg/lib/js_helper.dart
@@ -16,6 +16,7 @@ bool checkNumbers(var a, var b, var message) {
if (b is num) {
return true;
} else {
+ checkNull(b);
throw new IllegalArgumentException(message);
}
}
@@ -393,6 +394,7 @@ class Primitives {
}
builtin$compareTo$1(a, b) {
+ checkNull(a);
if (checkNumbers(a, b, 'illegal argument')) {
if (a < b) {
return -1;
@@ -896,16 +898,28 @@ builtin$trim$0(receiver) {
checkNull(receiver);
ngeoffray 2012/02/21 09:39:43 No need for check null.
if (receiver is !String) return UNINTERCEPTED(receiver.trim());
- throw new NotImplementedException();
+ return JS('String', @'$0.trim()', receiver);
}
class MathNatives {
- static int parseInt(String str) {
- throw 'MathNatives.parseInt is not implemented';
+ static int parseInt(str) {
+ checkNull(str);
ngeoffray 2012/02/21 09:39:43 No need for check null.
+ if (str is !String) throw new IllegalArgumentException(str);
+ var trimmed = str.trim();
+ if (!JS('bool', @'/^(0[xX])?[+-]?[0-9]+$/.test($0)', trimmed)) {
+ throw new BadNumberFormatException(str);
+ }
+ var ret = JS("num", @"parseInt($0, 10)", str);
+ if (ret.isNaN()) throw new BadNumberFormatException(str);
+ return ret;
}
static double parseDouble(String str) {
- throw 'MathNatives.parseDouble is not implemented';
+ checkNull(str);
ngeoffray 2012/02/21 09:39:43 No need for check null.
+ if (str is !String) throw new IllegalArgumentException();
+ var ret = JS("num", @"parseFloat($0)", str);
+ if (ret.isNaN() && str != 'NaN') throw new BadNumberFormatException(str);
+ return ret;
}
static double sqrt(num value)
@@ -930,7 +944,7 @@ class MathNatives {
=> JS("double", @"Math.atan($0)", checkNum(value));
static double atan2(num a, num b)
- => JS("double", @"Math.atan2($0)", checkNum(value));
+ => JS("double", @"Math.atan2($0, $1)", checkNum(a), checkNum(b));
static double exp(num value)
=> JS("double", @"Math.exp($0)", checkNum(value));
@@ -944,7 +958,7 @@ class MathNatives {
return JS("num", @"Math.pow($0, $1)", value, exponent);
}
- static double random() => JS("double", "Math.random()");
+ static double random() => JS("double", @"Math.random()");
}
builtin$hashCode$0(receiver) {
« no previous file with comments | « no previous file | dart/tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698