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

Side by Side Diff: frog/leg/lib/js_helper.dart

Issue 9568011: Unify Date.fromString and support more Iso 8601. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « frog/leg/lib/date_helper.dart ('k') | frog/leg/lib/mockimpl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #library('js_helper'); 5 #library('js_helper');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 8
9 #source('date_helper.dart'); 9 #source('date_helper.dart');
10 #source('regexp_helper.dart'); 10 #source('regexp_helper.dart');
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 checkNull(receiver); 1121 checkNull(receiver);
1122 if (receiver is !String) return UNINTERCEPTED(receiver.trim()); 1122 if (receiver is !String) return UNINTERCEPTED(receiver.trim());
1123 1123
1124 return JS('String', @'$0.trim()', receiver); 1124 return JS('String', @'$0.trim()', receiver);
1125 } 1125 }
1126 1126
1127 class MathNatives { 1127 class MathNatives {
1128 static int parseInt(str) { 1128 static int parseInt(str) {
1129 checkNull(str); 1129 checkNull(str);
1130 if (str is !String) throw new IllegalArgumentException(str); 1130 if (str is !String) throw new IllegalArgumentException(str);
1131 var trimmed = str.trim(); 1131 if (!JS('bool', @'/^\s*[+-]?(0[xX])?\d+\s*$/.test($0)', str)) {
1132 if (!JS('bool', @'/^(0[xX])?[+-]?[0-9]+$/.test($0)', trimmed)) {
1133 throw new BadNumberFormatException(str); 1132 throw new BadNumberFormatException(str);
1134 } 1133 }
1135 var ret = JS('num', @'parseInt($0, 10)', str); 1134 var trimmed = str.trim();
1135 var base = 10;;
1136 if ((trimmed.length > 2 && (trimmed[1] == 'x' || trimmed[1] == 'X')) ||
1137 (trimmed.length > 3 && (trimmed[2] == 'x' || trimmed[2] == 'X'))) {
1138 base = 16;
1139 }
1140 var ret = JS('num', @'parseInt($0, $1)', trimmed, base);
1136 if (ret.isNaN()) throw new BadNumberFormatException(str); 1141 if (ret.isNaN()) throw new BadNumberFormatException(str);
1137 return ret; 1142 return ret;
1138 } 1143 }
1139 1144
1140 static double parseDouble(String str) { 1145 static double parseDouble(String str) {
1141 checkNull(str); 1146 checkNull(str);
1142 if (str is !String) throw new IllegalArgumentException(); 1147 if (str is !String) throw new IllegalArgumentException();
1143 var ret = JS('num', @'parseFloat($0)', str); 1148 var ret = JS('num', @'parseFloat($0)', str);
1144 if (ret == 0 && (str.startsWith("0x") || str.startsWith("0X"))) { 1149 if (ret == 0 && (str.startsWith("0x") || str.startsWith("0X"))) {
1145 // TODO(ahe): This is unspecified, but tested by co19. 1150 // TODO(ahe): This is unspecified, but tested by co19.
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 } 1292 }
1288 } 1293 }
1289 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { 1294 } else if (JS('bool', @'$0 instanceof RangeError', ex)) {
1290 var message = JS('String', @'$0.message', ex); 1295 var message = JS('String', @'$0.message', ex);
1291 if (message.contains('call stack')) { 1296 if (message.contains('call stack')) {
1292 return new StackOverflowException(); 1297 return new StackOverflowException();
1293 } 1298 }
1294 } 1299 }
1295 return ex; 1300 return ex;
1296 } 1301 }
OLDNEW
« no previous file with comments | « frog/leg/lib/date_helper.dart ('k') | frog/leg/lib/mockimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698