| 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('dart:_js_helper'); | 5 #library('dart:_js_helper'); |
| 6 | 6 |
| 7 #import('dart:coreimpl'); | 7 #import('dart:coreimpl'); |
| 8 | 8 |
| 9 #source('constant_map.dart'); | 9 #source('constant_map.dart'); |
| 10 #source('native_helper.dart'); | 10 #source('native_helper.dart'); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 checkString(string); | 402 checkString(string); |
| 403 var match = JS('List', | 403 var match = JS('List', |
| 404 r'/^\s*[+-]?(?:0(x)[a-f0-9]+|\d+)\s*$/i.exec(#)', | 404 r'/^\s*[+-]?(?:0(x)[a-f0-9]+|\d+)\s*$/i.exec(#)', |
| 405 string); | 405 string); |
| 406 if (match == null) { | 406 if (match == null) { |
| 407 throw new FormatException(string); | 407 throw new FormatException(string); |
| 408 } | 408 } |
| 409 var base = 10; | 409 var base = 10; |
| 410 if (match[1] != null) base = 16; | 410 if (match[1] != null) base = 16; |
| 411 var result = JS('num', r'parseInt(#, #)', string, base); | 411 var result = JS('num', r'parseInt(#, #)', string, base); |
| 412 if (result.isNaN()) throw new FormatException(string); | 412 if (result.isNaN) throw new FormatException(string); |
| 413 return result; | 413 return result; |
| 414 } | 414 } |
| 415 | 415 |
| 416 static double parseDouble(String string) { | 416 static double parseDouble(String string) { |
| 417 checkString(string); | 417 checkString(string); |
| 418 // Notice that JS parseFloat accepts garbage at the end of the string. | 418 // Notice that JS parseFloat accepts garbage at the end of the string. |
| 419 // Accept, ignoring leading and trailing whitespace: | 419 // Accept, ignoring leading and trailing whitespace: |
| 420 // - NaN | 420 // - NaN |
| 421 // - [+/-]Infinity | 421 // - [+/-]Infinity |
| 422 // - a Dart double literal | 422 // - a Dart double literal |
| 423 if (!JS('bool', | 423 if (!JS('bool', |
| 424 r'/^\s*(?:NaN|[+-]?(?:Infinity|' | 424 r'/^\s*(?:NaN|[+-]?(?:Infinity|' |
| 425 r'(?:\.\d+|\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?))\s*$/.test(#)', | 425 r'(?:\.\d+|\d+(?:\.\d+)?)(?:[eE][+-]?\d+)?))\s*$/.test(#)', |
| 426 string)) { | 426 string)) { |
| 427 throw new FormatException(string); | 427 throw new FormatException(string); |
| 428 } | 428 } |
| 429 var result = JS('num', r'parseFloat(#)', string); | 429 var result = JS('num', r'parseFloat(#)', string); |
| 430 if (result.isNaN() && string != 'NaN') { | 430 if (result.isNaN && string != 'NaN') { |
| 431 throw new FormatException(string); | 431 throw new FormatException(string); |
| 432 } | 432 } |
| 433 return result; | 433 return result; |
| 434 } | 434 } |
| 435 | 435 |
| 436 /** [: r"$".charCodeAt(0) :] */ | 436 /** [: r"$".charCodeAt(0) :] */ |
| 437 static const int DOLLAR_CHAR_VALUE = 36; | 437 static const int DOLLAR_CHAR_VALUE = 36; |
| 438 | 438 |
| 439 static String objectTypeName(Object object) { | 439 static String objectTypeName(Object object) { |
| 440 String name = constructorNameFallback(object); | 440 String name = constructorNameFallback(object); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 checkBool(isUtc); | 502 checkBool(isUtc); |
| 503 var jsMonth = month - 1; | 503 var jsMonth = month - 1; |
| 504 var value; | 504 var value; |
| 505 if (isUtc) { | 505 if (isUtc) { |
| 506 value = JS('num', r'Date.UTC(#, #, #, #, #, #, #)', | 506 value = JS('num', r'Date.UTC(#, #, #, #, #, #, #)', |
| 507 years, jsMonth, day, hours, minutes, seconds, milliseconds); | 507 years, jsMonth, day, hours, minutes, seconds, milliseconds); |
| 508 } else { | 508 } else { |
| 509 value = JS('num', r'new Date(#, #, #, #, #, #, #).valueOf()', | 509 value = JS('num', r'new Date(#, #, #, #, #, #, #).valueOf()', |
| 510 years, jsMonth, day, hours, minutes, seconds, milliseconds); | 510 years, jsMonth, day, hours, minutes, seconds, milliseconds); |
| 511 } | 511 } |
| 512 if (value.isNaN() || | 512 if (value.isNaN || |
| 513 value < -MAX_MILLISECONDS_SINCE_EPOCH || | 513 value < -MAX_MILLISECONDS_SINCE_EPOCH || |
| 514 value > MAX_MILLISECONDS_SINCE_EPOCH) { | 514 value > MAX_MILLISECONDS_SINCE_EPOCH) { |
| 515 throw new ArgumentError(); | 515 throw new ArgumentError(); |
| 516 } | 516 } |
| 517 if (years <= 0 || years < 100) return patchUpY2K(value, years, isUtc); | 517 if (years <= 0 || years < 100) return patchUpY2K(value, years, isUtc); |
| 518 return value; | 518 return value; |
| 519 } | 519 } |
| 520 | 520 |
| 521 static patchUpY2K(value, years, isUtc) { | 521 static patchUpY2K(value, years, isUtc) { |
| 522 var date = JS('Object', r'new Date(#)', value); | 522 var date = JS('Object', r'new Date(#)', value); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver)) | 588 ? JS('int', r'#.getUTCDay() + 0', lazyAsJsDate(receiver)) |
| 589 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver)); | 589 : JS('int', r'#.getDay() + 0', lazyAsJsDate(receiver)); |
| 590 // Adjust by one because JS weeks start on Sunday. | 590 // Adjust by one because JS weeks start on Sunday. |
| 591 return (weekday + 6) % 7 + 1; | 591 return (weekday + 6) % 7 + 1; |
| 592 } | 592 } |
| 593 | 593 |
| 594 static valueFromDateString(str) { | 594 static valueFromDateString(str) { |
| 595 checkNull(str); | 595 checkNull(str); |
| 596 if (str is !String) throw new ArgumentError(str); | 596 if (str is !String) throw new ArgumentError(str); |
| 597 var value = JS('num', r'Date.parse(#)', str); | 597 var value = JS('num', r'Date.parse(#)', str); |
| 598 if (value.isNaN()) throw new ArgumentError(str); | 598 if (value.isNaN) throw new ArgumentError(str); |
| 599 return value; | 599 return value; |
| 600 } | 600 } |
| 601 | 601 |
| 602 static getProperty(object, key) { | 602 static getProperty(object, key) { |
| 603 checkNull(object); | 603 checkNull(object); |
| 604 if (object is bool || object is num || object is String) { | 604 if (object is bool || object is num || object is String) { |
| 605 throw new ArgumentError(object); | 605 throw new ArgumentError(object); |
| 606 } | 606 } |
| 607 return JS('var', '#[#]', object, key); | 607 return JS('var', '#[#]', object, key); |
| 608 } | 608 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 str)) { | 754 str)) { |
| 755 throw new FormatException(str); | 755 throw new FormatException(str); |
| 756 } | 756 } |
| 757 var trimmed = str.trim(); | 757 var trimmed = str.trim(); |
| 758 var base = 10;; | 758 var base = 10;; |
| 759 if ((trimmed.length > 2 && (trimmed[1] == 'x' || trimmed[1] == 'X')) || | 759 if ((trimmed.length > 2 && (trimmed[1] == 'x' || trimmed[1] == 'X')) || |
| 760 (trimmed.length > 3 && (trimmed[2] == 'x' || trimmed[2] == 'X'))) { | 760 (trimmed.length > 3 && (trimmed[2] == 'x' || trimmed[2] == 'X'))) { |
| 761 base = 16; | 761 base = 16; |
| 762 } | 762 } |
| 763 var ret = JS('num', r'parseInt(#, #)', trimmed, base); | 763 var ret = JS('num', r'parseInt(#, #)', trimmed, base); |
| 764 if (ret.isNaN()) throw new FormatException(str); | 764 if (ret.isNaN) throw new FormatException(str); |
| 765 return ret; | 765 return ret; |
| 766 } | 766 } |
| 767 | 767 |
| 768 static double parseDouble(String str) { | 768 static double parseDouble(String str) { |
| 769 checkString(str); | 769 checkString(str); |
| 770 var ret = JS('num', r'parseFloat(#)', str); | 770 var ret = JS('num', r'parseFloat(#)', str); |
| 771 if (ret == 0 && (str.startsWith("0x") || str.startsWith("0X"))) { | 771 if (ret == 0 && (str.startsWith("0x") || str.startsWith("0X"))) { |
| 772 // TODO(ahe): This is unspecified, but tested by co19. | 772 // TODO(ahe): This is unspecified, but tested by co19. |
| 773 ret = JS('num', r'parseInt(#)', str); | 773 ret = JS('num', r'parseInt(#)', str); |
| 774 } | 774 } |
| 775 if (ret.isNaN() && str != 'NaN' && str != '-NaN') { | 775 if (ret.isNaN && str != 'NaN' && str != '-NaN') { |
| 776 throw new FormatException(str); | 776 throw new FormatException(str); |
| 777 } | 777 } |
| 778 return ret; | 778 return ret; |
| 779 } | 779 } |
| 780 | 780 |
| 781 static double sqrt(num value) | 781 static double sqrt(num value) |
| 782 => JS('double', r'Math.sqrt(#)', checkNum(value)); | 782 => JS('double', r'Math.sqrt(#)', checkNum(value)); |
| 783 | 783 |
| 784 static double sin(num value) | 784 static double sin(num value) |
| 785 => JS('double', r'Math.sin(#)', checkNum(value)); | 785 => JS('double', r'Math.sin(#)', checkNum(value)); |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 JS('void', r'#.runtimeTypeCache[#] = #', JS_CURRENT_ISOLATE(), key, | 1401 JS('void', r'#.runtimeTypeCache[#] = #', JS_CURRENT_ISOLATE(), key, |
| 1402 runtimeType); | 1402 runtimeType); |
| 1403 } | 1403 } |
| 1404 return runtimeType; | 1404 return runtimeType; |
| 1405 } | 1405 } |
| 1406 | 1406 |
| 1407 String getRuntimeTypeString(var object) { | 1407 String getRuntimeTypeString(var object) { |
| 1408 var typeInfo = JS('Object', r'#.builtin$typeInfo', object); | 1408 var typeInfo = JS('Object', r'#.builtin$typeInfo', object); |
| 1409 return JS('String', r'#.runtimeType', typeInfo); | 1409 return JS('String', r'#.runtimeType', typeInfo); |
| 1410 } | 1410 } |
| OLD | NEW |