| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 indexSet(var a, var index, var value) { | 236 indexSet(var a, var index, var value) { |
| 237 checkNull(a); | 237 checkNull(a); |
| 238 if (isJsArray(a)) { | 238 if (isJsArray(a)) { |
| 239 if (!(index is int)) { | 239 if (!(index is int)) { |
| 240 throw new IllegalArgumentException(index); | 240 throw new IllegalArgumentException(index); |
| 241 } | 241 } |
| 242 if (index < 0 || index >= a.length) { | 242 if (index < 0 || index >= a.length) { |
| 243 throw new IndexOutOfRangeException(index); | 243 throw new IndexOutOfRangeException(index); |
| 244 } | 244 } |
| 245 checkMutable(a, 'indexed set'); |
| 245 return JS("Object", @"$0[$1] = $2", a, index, value); | 246 return JS("Object", @"$0[$1] = $2", a, index, value); |
| 246 } | 247 } |
| 247 checkNull(a); | 248 checkNull(a); |
| 248 UNINTERCEPTED(a[index] = value); | 249 UNINTERCEPTED(a[index] = value); |
| 249 return value; | 250 return value; |
| 250 } | 251 } |
| 251 | 252 |
| 253 checkMutable(list, reason) { |
| 254 if (JS('bool', @'!!($0.immutable$list)', list)) { |
| 255 throw new UnsupportedOperationException(reason); |
| 256 } |
| 257 } |
| 258 |
| 252 builtin$add$1(var receiver, var value) { | 259 builtin$add$1(var receiver, var value) { |
| 253 checkNull(receiver); | 260 checkNull(receiver); |
| 254 if (isJsArray(receiver)) { | 261 if (isJsArray(receiver)) { |
| 262 checkGrowable(receiver, 'add'); |
| 255 JS("Object", @"$0.push($1)", receiver, value); | 263 JS("Object", @"$0.push($1)", receiver, value); |
| 256 return; | 264 return; |
| 257 } | 265 } |
| 258 return UNINTERCEPTED(receiver.add(value)); | 266 return UNINTERCEPTED(receiver.add(value)); |
| 259 } | 267 } |
| 260 | 268 |
| 261 builtin$removeLast$0(var receiver) { | 269 builtin$removeLast$0(var receiver) { |
| 262 checkNull(receiver); | 270 checkNull(receiver); |
| 263 if (isJsArray(receiver)) { | 271 if (isJsArray(receiver)) { |
| 272 checkGrowable(receiver, 'removeLast'); |
| 264 if (receiver.length === 0) throw new IndexOutOfRangeException(-1); | 273 if (receiver.length === 0) throw new IndexOutOfRangeException(-1); |
| 265 return JS("Object", @"$0.pop()", receiver); | 274 return JS("Object", @"$0.pop()", receiver); |
| 266 } | 275 } |
| 267 return UNINTERCEPTED(receiver.removeLast()); | 276 return UNINTERCEPTED(receiver.removeLast()); |
| 268 } | 277 } |
| 269 | 278 |
| 270 builtin$filter$1(var receiver, var predicate) { | 279 builtin$filter$1(var receiver, var predicate) { |
| 271 checkNull(receiver); | 280 checkNull(receiver); |
| 272 if (isJsArray(receiver)) { | 281 if (isJsArray(receiver)) { |
| 273 return JS("Object", @"$0.filter(function(v) { return $1(v) === true; })", | 282 return JS("Object", @"$0.filter(function(v) { return $1(v) === true; })", |
| (...skipping 10 matching lines...) Expand all Loading... |
| 284 } | 293 } |
| 285 return UNINTERCEPTED(receiver.length); | 294 return UNINTERCEPTED(receiver.length); |
| 286 } | 295 } |
| 287 | 296 |
| 288 builtin$set$length(receiver, newLength) { | 297 builtin$set$length(receiver, newLength) { |
| 289 checkNull(receiver); | 298 checkNull(receiver); |
| 290 if (isJsArray(receiver)) { | 299 if (isJsArray(receiver)) { |
| 291 checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it. | 300 checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it. |
| 292 if (newLength is !int) throw new IllegalArgumentException(newLength); | 301 if (newLength is !int) throw new IllegalArgumentException(newLength); |
| 293 if (newLength < 0) throw new IndexOutOfRangeException(newLength); | 302 if (newLength < 0) throw new IndexOutOfRangeException(newLength); |
| 303 checkGrowable(receiver, 'set length'); |
| 294 JS('void', @"$0.length = $1", receiver, newLength); | 304 JS('void', @"$0.length = $1", receiver, newLength); |
| 295 } else { | 305 } else { |
| 296 UNINTERCEPTED(receiver.length = newLength); | 306 UNINTERCEPTED(receiver.length = newLength); |
| 297 } | 307 } |
| 298 return newLength; | 308 return newLength; |
| 299 } | 309 } |
| 300 | 310 |
| 311 checkGrowable(list, reason) { |
| 312 if (JS('bool', @'!!($0.fixed$length)', list)) { |
| 313 throw new UnsupportedOperationException(reason); |
| 314 } |
| 315 } |
| 316 |
| 301 builtin$toString$0(var value) { | 317 builtin$toString$0(var value) { |
| 302 if (JS("bool", @"typeof $0 == 'object'", value)) { | 318 if (JS("bool", @"typeof $0 == 'object'", value)) { |
| 303 if (isJsArray(value)) { | 319 if (isJsArray(value)) { |
| 304 return "Instance of 'List'"; | 320 return "Instance of 'List'"; |
| 305 } | 321 } |
| 306 return UNINTERCEPTED(value.toString()); | 322 return UNINTERCEPTED(value.toString()); |
| 307 } | 323 } |
| 308 if (JS("bool", @"$0 === 0 && (1 / $0) < 0", value)) { | 324 if (JS("bool", @"$0 === 0 && (1 / $0) < 0", value)) { |
| 309 return "-0.0"; | 325 return "-0.0"; |
| 310 } | 326 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 static String objectToString(Object object) { | 387 static String objectToString(Object object) { |
| 372 String name = JS('String', @'$0.constructor.name', object); | 388 String name = JS('String', @'$0.constructor.name', object); |
| 373 if (name === null) { | 389 if (name === null) { |
| 374 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]', | 390 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]', |
| 375 JS('String', @'$0.constructor.toString()', object)); | 391 JS('String', @'$0.constructor.toString()', object)); |
| 376 } | 392 } |
| 377 return "Instance of '$name'"; | 393 return "Instance of '$name'"; |
| 378 } | 394 } |
| 379 | 395 |
| 380 static List newList(length) { | 396 static List newList(length) { |
| 381 if (length == null) return JS("Object", @"new Array()"); | 397 if (length === null) return JS("Object", @"new Array()"); |
| 382 if ((length is !int) || (length < 0)) { | 398 if ((length is !int) || (length < 0)) { |
| 383 throw new IllegalArgumentException(length); | 399 throw new IllegalArgumentException(length); |
| 384 } | 400 } |
| 385 return JS("Object", @"new Array($0)", length); | 401 var result = JS("Object", @"new Array($0)", length); |
| 402 JS('void', @'$0.fixed$length = $1', result, true); |
| 403 return result; |
| 386 } | 404 } |
| 387 | 405 |
| 388 static num dateNow() => JS("num", @"Date.now()"); | 406 static num dateNow() => JS("num", @"Date.now()"); |
| 389 | 407 |
| 390 static String stringFromCharCodes(charCodes) { | 408 static String stringFromCharCodes(charCodes) { |
| 391 for (var i in charCodes) { | 409 for (var i in charCodes) { |
| 392 if (i is !int) throw new IllegalArgumentException(i); | 410 if (i is !int) throw new IllegalArgumentException(i); |
| 393 } | 411 } |
| 394 return JS('String', @'String.fromCharCode.apply($0, $1)', null, charCodes); | 412 return JS('String', @'String.fromCharCode.apply($0, $1)', null, charCodes); |
| 395 } | 413 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 var iterator = collection.iterator(); | 583 var iterator = collection.iterator(); |
| 566 while (iterator.hasNext()) { | 584 while (iterator.hasNext()) { |
| 567 receiver.add(iterator.next()); | 585 receiver.add(iterator.next()); |
| 568 } | 586 } |
| 569 } | 587 } |
| 570 | 588 |
| 571 builtin$addLast$1(receiver, value) { | 589 builtin$addLast$1(receiver, value) { |
| 572 checkNull(receiver); | 590 checkNull(receiver); |
| 573 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addLast(value)); | 591 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addLast(value)); |
| 574 | 592 |
| 593 checkGrowable(receiver, 'addLast'); |
| 575 JS("Object", @"$0.push($1)", receiver, value); | 594 JS("Object", @"$0.push($1)", receiver, value); |
| 576 } | 595 } |
| 577 | 596 |
| 578 builtin$clear$0(receiver) { | 597 builtin$clear$0(receiver) { |
| 579 checkNull(receiver); | 598 checkNull(receiver); |
| 580 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.clear()); | 599 if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.clear()); |
| 581 receiver.length = 0; | 600 receiver.length = 0; |
| 582 } | 601 } |
| 583 | 602 |
| 584 builtin$forEach$1(receiver, f) { | 603 builtin$forEach$1(receiver, f) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 739 } |
| 721 | 740 |
| 722 stringLastIndexOfUnchecked(receiver, element, start) | 741 stringLastIndexOfUnchecked(receiver, element, start) |
| 723 => JS('int', @'$0.lastIndexOf($1, $2)', receiver, element, start); | 742 => JS('int', @'$0.lastIndexOf($1, $2)', receiver, element, start); |
| 724 | 743 |
| 725 builtin$removeRange$2(receiver, start, length) { | 744 builtin$removeRange$2(receiver, start, length) { |
| 726 checkNull(receiver); | 745 checkNull(receiver); |
| 727 if (!isJsArray(receiver)) { | 746 if (!isJsArray(receiver)) { |
| 728 return UNINTERCEPTED(receiver.removeRange(start, length)); | 747 return UNINTERCEPTED(receiver.removeRange(start, length)); |
| 729 } | 748 } |
| 749 checkGrowable(receiver, 'removeRange'); |
| 730 if (length == 0) { | 750 if (length == 0) { |
| 731 return; | 751 return; |
| 732 } | 752 } |
| 733 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. | 753 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. |
| 734 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. | 754 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. |
| 735 if (start is !int) throw new IllegalArgumentException(start); | 755 if (start is !int) throw new IllegalArgumentException(start); |
| 736 if (length is !int) throw new IllegalArgumentException(length); | 756 if (length is !int) throw new IllegalArgumentException(length); |
| 737 if (length < 0) throw new IllegalArgumentException(length); | 757 if (length < 0) throw new IllegalArgumentException(length); |
| 738 var receiverLength = JS("num", @"$0.length", receiver); | 758 var receiverLength = JS("num", @"$0.length", receiver); |
| 739 if (start < 0 || start >= receiverLength) { | 759 if (start < 0 || start >= receiverLength) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 757 } | 777 } |
| 758 return UNINTERCEPTED(receiver.setRange(start, length, from)); | 778 return UNINTERCEPTED(receiver.setRange(start, length, from)); |
| 759 } | 779 } |
| 760 | 780 |
| 761 builtin$setRange$4(receiver, start, length, from, startFrom) { | 781 builtin$setRange$4(receiver, start, length, from, startFrom) { |
| 762 checkNull(receiver); | 782 checkNull(receiver); |
| 763 if (!isJsArray(receiver)) { | 783 if (!isJsArray(receiver)) { |
| 764 return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom)); | 784 return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom)); |
| 765 } | 785 } |
| 766 | 786 |
| 787 checkMutable(receiver, 'indexed set'); |
| 767 if (length === 0) return; | 788 if (length === 0) return; |
| 768 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. | 789 checkNull(start); // TODO(ahe): This is not specified but co19 tests it. |
| 769 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. | 790 checkNull(length); // TODO(ahe): This is not specified but co19 tests it. |
| 770 checkNull(from); // TODO(ahe): This is not specified but co19 tests it. | 791 checkNull(from); // TODO(ahe): This is not specified but co19 tests it. |
| 771 checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it. | 792 checkNull(startFrom); // TODO(ahe): This is not specified but co19 tests it. |
| 772 if (start is !int) throw new IllegalArgumentException(start); | 793 if (start is !int) throw new IllegalArgumentException(start); |
| 773 if (length is !int) throw new IllegalArgumentException(length); | 794 if (length is !int) throw new IllegalArgumentException(length); |
| 774 if (startFrom is !int) throw new IllegalArgumentException(startFrom); | 795 if (startFrom is !int) throw new IllegalArgumentException(startFrom); |
| 775 if (length < 0) throw new IllegalArgumentException(length); | 796 if (length < 0) throw new IllegalArgumentException(length); |
| 776 if (start < 0) throw new IndexOutOfRangeException(start); | 797 if (start < 0) throw new IndexOutOfRangeException(start); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 builtin$charCodes$0(receiver) { | 1210 builtin$charCodes$0(receiver) { |
| 1190 checkNull(receiver); | 1211 checkNull(receiver); |
| 1191 if (receiver is !String) return UNINTERCEPTED(receiver.charCodes()); | 1212 if (receiver is !String) return UNINTERCEPTED(receiver.charCodes()); |
| 1192 int len = receiver.length; | 1213 int len = receiver.length; |
| 1193 List<int> result = new List<int>(len); | 1214 List<int> result = new List<int>(len); |
| 1194 for (int i = 0; i < len; i++) { | 1215 for (int i = 0; i < len; i++) { |
| 1195 result[i] = receiver.charCodeAt(i); | 1216 result[i] = receiver.charCodeAt(i); |
| 1196 } | 1217 } |
| 1197 return result; | 1218 return result; |
| 1198 } | 1219 } |
| 1220 |
| 1221 makeLiteralListConst(list) { |
| 1222 JS('bool', @'$0.immutable$list = $1', list, true); |
| 1223 JS('bool', @'$0.fixed$length = $1', list, true); |
| 1224 return list; |
| 1225 } |
| OLD | NEW |