Chromium Code Reviews| 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'); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 return value; | 352 return value; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 builtin$charCodeAt$1(var receiver, int index) { | 356 builtin$charCodeAt$1(var receiver, int index) { |
| 357 checkNull(receiver); | 357 checkNull(receiver); |
| 358 if (receiver is String) { | 358 if (receiver is String) { |
| 359 if (index is !num) throw new IllegalArgumentException(index); | 359 if (index is !num) throw new IllegalArgumentException(index); |
| 360 if (index < 0) throw new IndexOutOfRangeException(index); | 360 if (index < 0) throw new IndexOutOfRangeException(index); |
| 361 if (index >= receiver.length) throw new IndexOutOfRangeException(index); | 361 if (index >= receiver.length) throw new IndexOutOfRangeException(index); |
| 362 return JS("string", @"$0.charCodeAt($1)", receiver, index); | 362 return JS("int", @"$0.charCodeAt($1)", receiver, index); |
| 363 } else { | 363 } else { |
| 364 return UNINTERCEPTED(receiver.charCodeAt(index)); | 364 return UNINTERCEPTED(receiver.charCodeAt(index)); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 builtin$isEmpty$0(receiver) { | 368 builtin$isEmpty$0(receiver) { |
| 369 checkNull(receiver); | 369 checkNull(receiver); |
| 370 if (receiver is String || isJsArray(receiver)) { | 370 if (receiver is String || isJsArray(receiver)) { |
| 371 return JS("bool", @"$0.length === 0", receiver); | 371 return JS("bool", @"$0.length === 0", receiver); |
| 372 } | 372 } |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 | 1173 |
| 1174 static num pow(num value, num exponent) { | 1174 static num pow(num value, num exponent) { |
| 1175 checkNum(value); | 1175 checkNum(value); |
| 1176 checkNum(exponent); | 1176 checkNum(exponent); |
| 1177 return JS("num", @"Math.pow($0, $1)", value, exponent); | 1177 return JS("num", @"Math.pow($0, $1)", value, exponent); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 static double random() => JS("double", @"Math.random()"); | 1180 static double random() => JS("double", @"Math.random()"); |
| 1181 } | 1181 } |
| 1182 | 1182 |
| 1183 /** | |
| 1184 * This is the [Jenkins hash function][1], but always using XOR | |
|
kasperl
2012/02/28 13:58:42
Update comment to match reality.
ahe
2012/02/28 17:26:10
Done.
| |
| 1185 * instead of addition to keep the hash value in 32bit. This was | |
| 1186 * inspired by jmesserly's work in Frog. | |
| 1187 * | |
| 1188 * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function | |
| 1189 */ | |
| 1183 builtin$hashCode$0(receiver) { | 1190 builtin$hashCode$0(receiver) { |
| 1184 if (receiver is num) return receiver & 0x1FFFFFFF; | 1191 if (receiver is num) return JS('int', @'$0 & 0x1FFFFFFF', receiver); |
|
Lasse Reichstein Nielsen
2012/02/28 14:12:16
That's a somewhat bad hash for doubles (specifical
ahe
2012/02/28 17:26:10
What do you suggest I use instead?
| |
| 1185 if (receiver is String) { | 1192 if (receiver is !String) return UNINTERCEPTED(receiver.hashCode()); |
|
Lasse Reichstein Nielsen
2012/02/28 14:12:16
What about arrays and booleans?
ahe
2012/02/28 17:26:10
I checked, neither List nor bool are hashable.
| |
| 1186 throw 'String.hashCode is not implemented'; | 1193 int hash = 0; |
| 1194 int length = JS('int', @'$0.length', receiver); | |
| 1195 for (int i = 0; i < length; i++) { | |
| 1196 hash = 0x1fffffff & (hash + JS('int', @'$0.charCodeAt($1)', receiver, i)); | |
| 1197 hash = 0x1fffffff & (hash + JS("int", @"$0 << $1", 0x0007ffff & hash, 10)); | |
| 1198 hash ^= hash >> 6; | |
| 1187 } | 1199 } |
| 1188 if (isJsArray(receiver)) { | 1200 hash = 0x1fffffff & (hash + JS("int", @"$0 << $1", 0x03ffffff & hash, 3)); |
| 1189 throw 'List.hashCode is not implemented'; | 1201 hash ^= hash >> 11; |
| 1190 } | 1202 return 0x1fffffff & (hash + JS("int", @"$0 << $1", 0x00003fff & hash, 15)); |
| 1191 return UNINTERCEPTED(receiver.hashCode()); | |
| 1192 } | 1203 } |
| 1193 | 1204 |
| 1194 // TODO(ahe): Dynamic may be overridden. | 1205 // TODO(ahe): Dynamic may be overridden. |
| 1195 builtin$get$dynamic(receiver) => receiver; | 1206 builtin$get$dynamic(receiver) => receiver; |
| 1196 | 1207 |
| 1197 /** | 1208 /** |
| 1198 * Called by generated code to capture the stacktrace before throwing | 1209 * Called by generated code to capture the stacktrace before throwing |
| 1199 * an exception. | 1210 * an exception. |
| 1200 */ | 1211 */ |
| 1201 captureStackTrace(ex) { | 1212 captureStackTrace(ex) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 } | 1274 } |
| 1264 } | 1275 } |
| 1265 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { | 1276 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { |
| 1266 var message = JS('String', @'$0.message', ex); | 1277 var message = JS('String', @'$0.message', ex); |
| 1267 if (message.contains('call stack')) { | 1278 if (message.contains('call stack')) { |
| 1268 return new StackOverflowException(); | 1279 return new StackOverflowException(); |
| 1269 } | 1280 } |
| 1270 } | 1281 } |
| 1271 return ex; | 1282 return ex; |
| 1272 } | 1283 } |
| OLD | NEW |