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 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 builtin$hashCode$0(receiver) { | 1183 builtin$hashCode$0(receiver) { |
| 1184 if (receiver is String) return stringHashCodeUnchecked(receiver); | |
| 1184 if (receiver is num) return receiver & 0x1FFFFFFF; | 1185 if (receiver is num) return receiver & 0x1FFFFFFF; |
| 1185 if (receiver is String) { | 1186 return UNINTERCEPTED(receiver.hashCode()); |
| 1186 throw 'String.hashCode is not implemented'; | 1187 } |
| 1188 | |
| 1189 /** | |
| 1190 * This is the [Jenkins hash function][1], but always using XOR | |
| 1191 * instead of addition to keep the hash value in 32bit. This was | |
| 1192 * inspired by jmesserly's work in Frog. However, using XOR is 40% | |
| 1193 * faster than the original version in Frog. | |
| 1194 * | |
| 1195 * Caveat: As long as String.hashCode isn't optimized, Frog will | |
| 1196 * out-perform Leg because of the overhead of calling | |
| 1197 * [builtin$hashCode$0]. | |
| 1198 * | |
| 1199 * [1]: http://en.wikipedia.org/wiki/Jenkins_hash_function | |
| 1200 */ | |
| 1201 stringHashCodeUnchecked(string) { | |
| 1202 var hash = 0; | |
|
kasperl
2012/02/28 09:37:08
int hash?
ahe
2012/02/28 10:09:35
Done.
| |
| 1203 var length = JS('int', @'$0.length', string); | |
| 1204 for (var i = 0; i < length; i++) { | |
|
kasperl
2012/02/28 09:37:08
int i?
ahe
2012/02/28 10:09:35
Done.
| |
| 1205 hash ^= JS('int', @'$0.charCodeAt($1)', string, i); | |
| 1206 hash ^= JS("int", @"$0 << $1", hash, 10); | |
|
ngeoffray
2012/02/28 10:13:25
Cobnsistency -> use ' instead of "
ahe
2012/02/28 17:26:10
Done.
| |
| 1207 hash ^= hash >> 6; | |
| 1187 } | 1208 } |
| 1188 if (isJsArray(receiver)) { | 1209 hash ^= JS("int", @"$0 << $1", hash, 3); |
|
ngeoffray
2012/02/28 10:13:25
ditto
ahe
2012/02/28 17:26:10
Done.
| |
| 1189 throw 'List.hashCode is not implemented'; | 1210 hash ^= hash >> 11; |
| 1190 } | 1211 return 0x1fffffff & (hash ^ JS("int", @"$0 << $1", hash, 15)); |
| 1191 return UNINTERCEPTED(receiver.hashCode()); | |
| 1192 } | 1212 } |
| 1193 | 1213 |
| 1194 // TODO(ahe): Dynamic may be overridden. | 1214 // TODO(ahe): Dynamic may be overridden. |
| 1195 builtin$get$dynamic(receiver) => receiver; | 1215 builtin$get$dynamic(receiver) => receiver; |
| 1196 | 1216 |
| 1197 /** | 1217 /** |
| 1198 * Called by generated code to capture the stacktrace before throwing | 1218 * Called by generated code to capture the stacktrace before throwing |
| 1199 * an exception. | 1219 * an exception. |
| 1200 */ | 1220 */ |
| 1201 captureStackTrace(ex) { | 1221 captureStackTrace(ex) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1263 } | 1283 } |
| 1264 } | 1284 } |
| 1265 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { | 1285 } else if (JS('bool', @'$0 instanceof RangeError', ex)) { |
| 1266 var message = JS('String', @'$0.message', ex); | 1286 var message = JS('String', @'$0.message', ex); |
| 1267 if (message.contains('call stack')) { | 1287 if (message.contains('call stack')) { |
| 1268 return new StackOverflowException(); | 1288 return new StackOverflowException(); |
| 1269 } | 1289 } |
| 1270 } | 1290 } |
| 1271 return ex; | 1291 return ex; |
| 1272 } | 1292 } |
| OLD | NEW |