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 allow leading or trailing whitespace. | 281 // We do not allow leading or trailing whitespace. |
282 if (!JS('bool', | 282 if (!JS('bool', |
283 r'/^\s*[+-]?(?:Infinity|NaN|' | 283 r'/^\s*(?:NaN|[+-]?(?:Infinity|' |
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) { | 289 if (result.isNaN && source != 'NaN') { |
290 var trimmed = source.trim(); | |
291 if (trimmed == 'NaN' || trimmed == '+NaN' || trimmed == '-NaN') { | |
292 return result; | |
293 } | |
294 return handleError(source); | 290 return handleError(source); |
295 } | 291 } |
296 return result; | 292 return result; |
297 } | 293 } |
298 | 294 |
299 /** [: r"$".codeUnitAt(0) :] */ | 295 /** [: r"$".codeUnitAt(0) :] */ |
300 static const int DOLLAR_CHAR_VALUE = 36; | 296 static const int DOLLAR_CHAR_VALUE = 36; |
301 | 297 |
302 /// Creates a string containing the complete type for the class [className] | 298 /// Creates a string containing the complete type for the class [className] |
303 /// with the given type arguments. | 299 /// with the given type arguments. |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 expectedArgumentNames); | 1402 expectedArgumentNames); |
1407 } | 1403 } |
1408 | 1404 |
1409 /** | 1405 /** |
1410 * Called by generated code when a static field's initializer references the | 1406 * Called by generated code when a static field's initializer references the |
1411 * field that is currently being initialized. | 1407 * field that is currently being initialized. |
1412 */ | 1408 */ |
1413 void throwCyclicInit(String staticName) { | 1409 void throwCyclicInit(String staticName) { |
1414 throw new RuntimeError("Cyclic initialization for static $staticName"); | 1410 throw new RuntimeError("Cyclic initialization for static $staticName"); |
1415 } | 1411 } |
OLD | NEW |