| 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('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'); |
| 11 #source('string_helper.dart'); |
| 11 | 12 |
| 12 /** | 13 /** |
| 13 * Returns true if both arguments are numbers. | 14 * Returns true if both arguments are numbers. |
| 14 * If only the first argument is a number, throws the given message as | 15 * If only the first argument is a number, throws the given message as |
| 15 * exception. | 16 * exception. |
| 16 */ | 17 */ |
| 17 bool checkNumbers(var a, var b, var message) { | 18 bool checkNumbers(var a, var b, var message) { |
| 18 if (a is num) { | 19 if (a is num) { |
| 19 if (b is num) { | 20 if (b is num) { |
| 20 return true; | 21 return true; |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 return UNINTERCEPTED(receiver.toRadixString(radix)); | 942 return UNINTERCEPTED(receiver.toRadixString(radix)); |
| 942 } | 943 } |
| 943 checkNum(radix); | 944 checkNum(radix); |
| 944 | 945 |
| 945 return JS("String", @"$0.toString($1)", receiver, radix); | 946 return JS("String", @"$0.toString($1)", receiver, radix); |
| 946 } | 947 } |
| 947 | 948 |
| 948 builtin$allMatches$1(receiver, str) { | 949 builtin$allMatches$1(receiver, str) { |
| 949 checkNull(receiver); | 950 checkNull(receiver); |
| 950 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); | 951 if (receiver is !String) return UNINTERCEPTED(receiver.allMatches(str)); |
| 951 | 952 checkString(str); |
| 952 throw 'String.allMatches is not implemented'; | 953 return allMatchesInStringUnchecked(receiver, str); |
| 953 } | 954 } |
| 954 | 955 |
| 955 builtin$concat$1(receiver, other) { | 956 builtin$concat$1(receiver, other) { |
| 956 checkNull(receiver); | 957 checkNull(receiver); |
| 957 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); | 958 if (receiver is !String) return UNINTERCEPTED(receiver.concat(other)); |
| 958 | 959 |
| 959 if (other is !String) throw new IllegalArgumentException(other); | 960 if (other is !String) throw new IllegalArgumentException(other); |
| 960 return JS('String', @'$0.concat($1)', receiver, other); | 961 return JS('String', @'$0.concat($1)', receiver, other); |
| 961 } | 962 } |
| 962 | 963 |
| 964 builtin$contains$1(receiver, other) { |
| 965 if (receiver is !String) { |
| 966 checkNull(receiver); |
| 967 return UNINTERCEPTED(receiver.contains(other)); |
| 968 } |
| 969 return builtin$contains$2(receiver, other, 0); |
| 970 } |
| 971 |
| 963 builtin$contains$2(receiver, other, startIndex) { | 972 builtin$contains$2(receiver, other, startIndex) { |
| 964 checkNull(receiver); | 973 checkNull(receiver); |
| 965 if (receiver is !String) { | 974 if (receiver is !String) { |
| 966 return UNINTERCEPTED(receiver.contains(other, startIndex)); | 975 return UNINTERCEPTED(receiver.contains(other, startIndex)); |
| 967 } | 976 } |
| 968 checkNull(other); | 977 checkNull(other); |
| 969 if (other is !String) { | 978 return stringContainsUnchecked(receiver, other, startIndex); |
| 970 throw 'String.contains with non-String is not implemented'; | |
| 971 } | |
| 972 if ((startIndex !== null) && (startIndex is !num)) { | |
| 973 throw new IllegalArgumentException(startIndex); | |
| 974 } | |
| 975 return receiver.indexOf(other, startIndex) >= 0; | |
| 976 } | 979 } |
| 977 | 980 |
| 978 builtin$endsWith$1(receiver, other) { | 981 builtin$endsWith$1(receiver, other) { |
| 979 checkNull(receiver); | 982 checkNull(receiver); |
| 980 if (receiver is !String) return UNINTERCEPTED(receiver.endsWith(other)); | 983 if (receiver is !String) return UNINTERCEPTED(receiver.endsWith(other)); |
| 981 | 984 |
| 982 checkNull(other); | 985 checkNull(other); |
| 983 if (other is !String) throw new IllegalArgumentException(other); | 986 if (other is !String) throw new IllegalArgumentException(other); |
| 984 | 987 |
| 985 int receiverLength = receiver.length; | 988 int receiverLength = receiver.length; |
| 986 int otherLength = other.length; | 989 int otherLength = other.length; |
| 987 if (otherLength > receiverLength) return false; | 990 if (otherLength > receiverLength) return false; |
| 988 return other == receiver.substring(receiverLength - otherLength); | 991 return other == receiver.substring(receiverLength - otherLength); |
| 989 } | 992 } |
| 990 | 993 |
| 991 builtin$replaceAll$2(receiver, from, to) { | 994 builtin$replaceAll$2(receiver, from, to) { |
| 992 checkNull(receiver); | 995 checkNull(receiver); |
| 993 if (receiver is !String) return UNINTERCEPTED(receiver.replaceAll(from, to)); | 996 if (receiver is !String) return UNINTERCEPTED(receiver.replaceAll(from, to)); |
| 994 | 997 |
| 995 throw 'String.replaceAll is not implemented'; | 998 checkNull(from); |
| 999 checkString(to); |
| 1000 return stringReplaceAllUnchecked(receiver, from, to); |
| 996 } | 1001 } |
| 997 | 1002 |
| 998 builtin$replaceFirst$2(receiver, from, to) { | 1003 builtin$replaceFirst$2(receiver, from, to) { |
| 999 checkNull(receiver); | 1004 checkNull(receiver); |
| 1000 if (receiver is !String) { | 1005 if (receiver is !String) { |
| 1001 return UNINTERCEPTED(receiver.replaceFirst(from, to)); | 1006 return UNINTERCEPTED(receiver.replaceFirst(from, to)); |
| 1002 } | 1007 } |
| 1003 if (from is !String) throw new IllegalArgumentException(from); | 1008 checkNull(from); |
| 1004 if (to is !String) throw new IllegalArgumentException(to); | 1009 checkString(to); |
| 1005 | 1010 return stringReplaceFirstUnchecked(receiver, from, to); |
| 1006 return JS('String', @'$0.replace($1, $2)', receiver, from, to); | |
| 1007 } | 1011 } |
| 1008 | 1012 |
| 1009 builtin$split$1(receiver, pattern) { | 1013 builtin$split$1(receiver, pattern) { |
| 1010 checkNull(receiver); | 1014 checkNull(receiver); |
| 1011 if (receiver is !String) return UNINTERCEPTED(receiver.split(pattern)); | 1015 if (receiver is !String) return UNINTERCEPTED(receiver.split(pattern)); |
| 1012 checkNull(pattern); | 1016 checkNull(pattern); |
| 1013 if (pattern is !String) throw new IllegalArgumentException(pattern); | 1017 return stringSplitUnchecked(receiver, pattern); |
| 1014 | |
| 1015 return JS('List', @'$0.split($1)', receiver, pattern); | |
| 1016 } | 1018 } |
| 1017 | 1019 |
| 1018 builtin$splitChars$0(receiver) { | 1020 builtin$splitChars$0(receiver) { |
| 1019 checkNull(receiver); | 1021 checkNull(receiver); |
| 1020 if (receiver is !String) return UNINTERCEPTED(receiver.splitChars()); | 1022 if (receiver is !String) return UNINTERCEPTED(receiver.splitChars()); |
| 1021 | 1023 |
| 1022 return JS('List', @'$0.split("")', receiver); | 1024 return JS('List', @'$0.split("")', receiver); |
| 1023 } | 1025 } |
| 1024 | 1026 |
| 1025 builtin$startsWith$1(receiver, other) { | 1027 builtin$startsWith$1(receiver, other) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 builtin$hashCode$0(receiver) { | 1146 builtin$hashCode$0(receiver) { |
| 1145 if (receiver is num) return receiver & 0x1FFFFFFF; | 1147 if (receiver is num) return receiver & 0x1FFFFFFF; |
| 1146 if (receiver is String) { | 1148 if (receiver is String) { |
| 1147 throw 'String.hashCode is not implemented'; | 1149 throw 'String.hashCode is not implemented'; |
| 1148 } | 1150 } |
| 1149 if (isJsArray(receiver)) { | 1151 if (isJsArray(receiver)) { |
| 1150 throw 'List.hashCode is not implemented'; | 1152 throw 'List.hashCode is not implemented'; |
| 1151 } | 1153 } |
| 1152 return UNINTERCEPTED(receiver.hashCode()); | 1154 return UNINTERCEPTED(receiver.hashCode()); |
| 1153 } | 1155 } |
| OLD | NEW |