OLD | NEW |
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 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, | 8 import 'dart:_foreign_helper' show DART_CLOSURE_TO_JS, |
9 JS, | 9 JS, |
10 JS_CALL_IN_ISOLATE, | 10 JS_CALL_IN_ISOLATE, |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 if (match == null) return handleError(source); | 269 if (match == null) return handleError(source); |
270 return JS('num', r'parseInt(#, #)', source, radix); | 270 return JS('num', r'parseInt(#, #)', source, radix); |
271 } | 271 } |
272 | 272 |
273 static double parseDouble(String source, double handleError(String source)) { | 273 static double parseDouble(String source, double handleError(String source)) { |
274 checkString(source); | 274 checkString(source); |
275 if (handleError == null) handleError = _throwFormatException; | 275 if (handleError == null) handleError = _throwFormatException; |
276 // Notice that JS parseFloat accepts garbage at the end of the string. | 276 // Notice that JS parseFloat accepts garbage at the end of the string. |
277 // Accept only: | 277 // Accept only: |
278 // - NaN | 278 // - [+/-]NaN |
279 // - [+/-]Infinity | 279 // - [+/-]Infinity |
280 // - a Dart double literal | 280 // - a Dart double literal |
281 // We do not allow leading or trailing whitespace. | 281 // We do allow leading or trailing whitespace. |
282 if (!JS('bool', | 282 if (!JS('bool', |
283 r'/^\s*(?:NaN|[+-]?(?:Infinity|' | 283 r'/^\s*[+-]?(?:Infinity|NaN|' |
284 r'(?:\.\d+|\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?))\s*$/.test(#)', | 284 r'(?:\.\d+|\d+(?:\.\d*)?)(?:[eE][+-]?\d+)?)\s*$/.test(#)', |
285 source)) { | 285 source)) { |
286 return handleError(source); | 286 return handleError(source); |
287 } | 287 } |
288 var result = JS('num', r'parseFloat(#)', source); | 288 var result = JS('num', r'parseFloat(#)', source); |
289 if (result.isNaN && source != 'NaN') { | 289 if (result.isNaN) { |
| 290 var trimmed = source.trim(); |
| 291 if (trimmed == 'NaN' || trimmed == '+NaN' || trimmed == '-NaN') { |
| 292 return result; |
| 293 } |
290 return handleError(source); | 294 return handleError(source); |
291 } | 295 } |
292 return result; | 296 return result; |
293 } | 297 } |
294 | 298 |
295 /** [: r"$".codeUnitAt(0) :] */ | 299 /** [: r"$".codeUnitAt(0) :] */ |
296 static const int DOLLAR_CHAR_VALUE = 36; | 300 static const int DOLLAR_CHAR_VALUE = 36; |
297 | 301 |
298 static String objectTypeName(Object object) { | 302 static String objectTypeName(Object object) { |
299 String name = constructorNameFallback(object); | 303 String name = constructorNameFallback(object); |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 expectedArgumentNames); | 1397 expectedArgumentNames); |
1394 } | 1398 } |
1395 | 1399 |
1396 /** | 1400 /** |
1397 * Called by generated code when a static field's initializer references the | 1401 * Called by generated code when a static field's initializer references the |
1398 * field that is currently being initialized. | 1402 * field that is currently being initialized. |
1399 */ | 1403 */ |
1400 void throwCyclicInit(String staticName) { | 1404 void throwCyclicInit(String staticName) { |
1401 throw new RuntimeError("Cyclic initialization for static $staticName"); | 1405 throw new RuntimeError("Cyclic initialization for static $staticName"); |
1402 } | 1406 } |
OLD | NEW |