OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 function ArrayToLocaleString() { | 369 function ArrayToLocaleString() { |
370 if (!IS_ARRAY(this)) { | 370 if (!IS_ARRAY(this)) { |
371 throw new $TypeError('Array.prototype.toString is not generic'); | 371 throw new $TypeError('Array.prototype.toString is not generic'); |
372 } | 372 } |
373 return Join(this, this.length, ',', ConvertToLocaleString); | 373 return Join(this, this.length, ',', ConvertToLocaleString); |
374 } | 374 } |
375 | 375 |
376 | 376 |
377 function ArrayJoin(separator) { | 377 function ArrayJoin(separator) { |
| 378 if (IS_NULL_OR_UNDEFINED(this)) { |
| 379 throw MakeTypeError("obj_ctor_property_non_object", ["Array.join"]); |
| 380 } |
| 381 |
378 if (IS_UNDEFINED(separator)) { | 382 if (IS_UNDEFINED(separator)) { |
379 separator = ','; | 383 separator = ','; |
380 } else if (!IS_STRING(separator)) { | 384 } else if (!IS_STRING(separator)) { |
381 separator = NonStringToString(separator); | 385 separator = NonStringToString(separator); |
382 } | 386 } |
383 | 387 |
384 var result = %_FastAsciiArrayJoin(this, separator); | 388 var result = %_FastAsciiArrayJoin(this, separator); |
385 if (!IS_UNDEFINED(result)) return result; | 389 if (!IS_UNDEFINED(result)) return result; |
386 | 390 |
387 return Join(this, TO_UINT32(this.length), separator, ConvertToString); | 391 return Join(this, TO_UINT32(this.length), separator, ConvertToString); |
388 } | 392 } |
389 | 393 |
390 | 394 |
391 // Removes the last element from the array and returns it. See | 395 // Removes the last element from the array and returns it. See |
392 // ECMA-262, section 15.4.4.6. | 396 // ECMA-262, section 15.4.4.6. |
393 function ArrayPop() { | 397 function ArrayPop() { |
| 398 if (IS_NULL_OR_UNDEFINED(this)) { |
| 399 throw MakeTypeError("obj_ctor_property_non_object", ["Array.pop"]); |
| 400 } |
| 401 |
394 var n = TO_UINT32(this.length); | 402 var n = TO_UINT32(this.length); |
395 if (n == 0) { | 403 if (n == 0) { |
396 this.length = n; | 404 this.length = n; |
397 return; | 405 return; |
398 } | 406 } |
399 n--; | 407 n--; |
400 var value = this[n]; | 408 var value = this[n]; |
401 this.length = n; | 409 this.length = n; |
402 delete this[n]; | 410 delete this[n]; |
403 return value; | 411 return value; |
404 } | 412 } |
405 | 413 |
406 | 414 |
407 // Appends the arguments to the end of the array and returns the new | 415 // Appends the arguments to the end of the array and returns the new |
408 // length of the array. See ECMA-262, section 15.4.4.7. | 416 // length of the array. See ECMA-262, section 15.4.4.7. |
409 function ArrayPush() { | 417 function ArrayPush() { |
| 418 if (IS_NULL_OR_UNDEFINED(this)) { |
| 419 throw MakeTypeError("obj_ctor_property_non_object", ["Array.push"]); |
| 420 } |
410 var n = TO_UINT32(this.length); | 421 var n = TO_UINT32(this.length); |
411 var m = %_ArgumentsLength(); | 422 var m = %_ArgumentsLength(); |
412 for (var i = 0; i < m; i++) { | 423 for (var i = 0; i < m; i++) { |
413 this[i+n] = %_Arguments(i); | 424 this[i+n] = %_Arguments(i); |
414 } | 425 } |
415 this.length = n + m; | 426 this.length = n + m; |
416 return this.length; | 427 return this.length; |
417 } | 428 } |
418 | 429 |
419 | 430 |
420 function ArrayConcat(arg1) { // length == 1 | 431 function ArrayConcat(arg1) { // length == 1 |
| 432 if (IS_NULL_OR_UNDEFINED(this)) { |
| 433 throw MakeTypeError("obj_ctor_property_non_object", ["Array.concat"]); |
| 434 } |
421 var arg_count = %_ArgumentsLength(); | 435 var arg_count = %_ArgumentsLength(); |
422 var arrays = new InternalArray(1 + arg_count); | 436 var arrays = new InternalArray(1 + arg_count); |
423 arrays[0] = this; | 437 arrays[0] = this; |
424 for (var i = 0; i < arg_count; i++) { | 438 for (var i = 0; i < arg_count; i++) { |
425 arrays[i + 1] = %_Arguments(i); | 439 arrays[i + 1] = %_Arguments(i); |
426 } | 440 } |
427 | 441 |
428 return %ArrayConcat(arrays); | 442 return %ArrayConcat(arrays); |
429 } | 443 } |
430 | 444 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (!IS_UNDEFINED(current_j) || high in array) { | 481 if (!IS_UNDEFINED(current_j) || high in array) { |
468 array[low] = current_j; | 482 array[low] = current_j; |
469 delete array[high]; | 483 delete array[high]; |
470 } | 484 } |
471 } | 485 } |
472 } | 486 } |
473 } | 487 } |
474 | 488 |
475 | 489 |
476 function ArrayReverse() { | 490 function ArrayReverse() { |
| 491 if (IS_NULL_OR_UNDEFINED(this)) { |
| 492 throw MakeTypeError("obj_ctor_property_non_object", ["Array.reverse"]); |
| 493 } |
| 494 |
477 var j = TO_UINT32(this.length) - 1; | 495 var j = TO_UINT32(this.length) - 1; |
478 | 496 |
479 if (UseSparseVariant(this, j, IS_ARRAY(this))) { | 497 if (UseSparseVariant(this, j, IS_ARRAY(this))) { |
480 SparseReverse(this, j+1); | 498 SparseReverse(this, j+1); |
481 return this; | 499 return this; |
482 } | 500 } |
483 | 501 |
484 for (var i = 0; i < j; i++, j--) { | 502 for (var i = 0; i < j; i++, j--) { |
485 var current_i = this[i]; | 503 var current_i = this[i]; |
486 if (!IS_UNDEFINED(current_i) || i in this) { | 504 if (!IS_UNDEFINED(current_i) || i in this) { |
(...skipping 11 matching lines...) Expand all Loading... |
498 this[i] = current_j; | 516 this[i] = current_j; |
499 delete this[j]; | 517 delete this[j]; |
500 } | 518 } |
501 } | 519 } |
502 } | 520 } |
503 return this; | 521 return this; |
504 } | 522 } |
505 | 523 |
506 | 524 |
507 function ArrayShift() { | 525 function ArrayShift() { |
| 526 if (IS_NULL_OR_UNDEFINED(this)) { |
| 527 throw MakeTypeError("obj_ctor_property_non_object", ["Array.shift"]); |
| 528 } |
| 529 |
508 var len = TO_UINT32(this.length); | 530 var len = TO_UINT32(this.length); |
509 | 531 |
510 if (len === 0) { | 532 if (len === 0) { |
511 this.length = 0; | 533 this.length = 0; |
512 return; | 534 return; |
513 } | 535 } |
514 | 536 |
515 var first = this[0]; | 537 var first = this[0]; |
516 | 538 |
517 if (IS_ARRAY(this)) | 539 if (IS_ARRAY(this)) |
518 SmartMove(this, 0, 1, len, 0); | 540 SmartMove(this, 0, 1, len, 0); |
519 else | 541 else |
520 SimpleMove(this, 0, 1, len, 0); | 542 SimpleMove(this, 0, 1, len, 0); |
521 | 543 |
522 this.length = len - 1; | 544 this.length = len - 1; |
523 | 545 |
524 return first; | 546 return first; |
525 } | 547 } |
526 | 548 |
527 | 549 |
528 function ArrayUnshift(arg1) { // length == 1 | 550 function ArrayUnshift(arg1) { // length == 1 |
| 551 if (IS_NULL_OR_UNDEFINED(this)) { |
| 552 throw MakeTypeError("obj_ctor_property_non_object", ["Array.unshift"]); |
| 553 } |
| 554 |
529 var len = TO_UINT32(this.length); | 555 var len = TO_UINT32(this.length); |
530 var num_arguments = %_ArgumentsLength(); | 556 var num_arguments = %_ArgumentsLength(); |
531 | 557 |
532 if (IS_ARRAY(this)) | 558 if (IS_ARRAY(this)) |
533 SmartMove(this, 0, 0, len, num_arguments); | 559 SmartMove(this, 0, 0, len, num_arguments); |
534 else | 560 else |
535 SimpleMove(this, 0, 0, len, num_arguments); | 561 SimpleMove(this, 0, 0, len, num_arguments); |
536 | 562 |
537 for (var i = 0; i < num_arguments; i++) { | 563 for (var i = 0; i < num_arguments; i++) { |
538 this[i] = %_Arguments(i); | 564 this[i] = %_Arguments(i); |
539 } | 565 } |
540 | 566 |
541 this.length = len + num_arguments; | 567 this.length = len + num_arguments; |
542 | 568 |
543 return len + num_arguments; | 569 return len + num_arguments; |
544 } | 570 } |
545 | 571 |
546 | 572 |
547 function ArraySlice(start, end) { | 573 function ArraySlice(start, end) { |
| 574 if (IS_NULL_OR_UNDEFINED(this)) { |
| 575 throw MakeTypeError("obj_ctor_property_non_object", ["Array.slice"]); |
| 576 } |
548 var len = TO_UINT32(this.length); | 577 var len = TO_UINT32(this.length); |
549 var start_i = TO_INTEGER(start); | 578 var start_i = TO_INTEGER(start); |
550 var end_i = len; | 579 var end_i = len; |
551 | 580 |
552 if (end !== void 0) end_i = TO_INTEGER(end); | 581 if (end !== void 0) end_i = TO_INTEGER(end); |
553 | 582 |
554 if (start_i < 0) { | 583 if (start_i < 0) { |
555 start_i += len; | 584 start_i += len; |
556 if (start_i < 0) start_i = 0; | 585 if (start_i < 0) start_i = 0; |
557 } else { | 586 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
575 SimpleSlice(this, start_i, end_i - start_i, len, result); | 604 SimpleSlice(this, start_i, end_i - start_i, len, result); |
576 } | 605 } |
577 | 606 |
578 result.length = end_i - start_i; | 607 result.length = end_i - start_i; |
579 | 608 |
580 return result; | 609 return result; |
581 } | 610 } |
582 | 611 |
583 | 612 |
584 function ArraySplice(start, delete_count) { | 613 function ArraySplice(start, delete_count) { |
| 614 if (IS_NULL_OR_UNDEFINED(this)) { |
| 615 throw MakeTypeError("obj_ctor_property_non_object", ["Array.splice"]); |
| 616 } |
585 var num_arguments = %_ArgumentsLength(); | 617 var num_arguments = %_ArgumentsLength(); |
586 | 618 |
587 var len = TO_UINT32(this.length); | 619 var len = TO_UINT32(this.length); |
588 var start_i = TO_INTEGER(start); | 620 var start_i = TO_INTEGER(start); |
589 | 621 |
590 if (start_i < 0) { | 622 if (start_i < 0) { |
591 start_i += len; | 623 start_i += len; |
592 if (start_i < 0) start_i = 0; | 624 if (start_i < 0) start_i = 0; |
593 } else { | 625 } else { |
594 if (start_i > len) start_i = len; | 626 if (start_i > len) start_i = len; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 this[i++] = %_Arguments(arguments_index++); | 678 this[i++] = %_Arguments(arguments_index++); |
647 } | 679 } |
648 this.length = len - del_count + num_additional_args; | 680 this.length = len - del_count + num_additional_args; |
649 | 681 |
650 // Return the deleted elements. | 682 // Return the deleted elements. |
651 return deleted_elements; | 683 return deleted_elements; |
652 } | 684 } |
653 | 685 |
654 | 686 |
655 function ArraySort(comparefn) { | 687 function ArraySort(comparefn) { |
| 688 if (IS_NULL_OR_UNDEFINED(this)) { |
| 689 throw MakeTypeError("obj_ctor_property_non_object", ["Array.sort"]); |
| 690 } |
| 691 |
656 // In-place QuickSort algorithm. | 692 // In-place QuickSort algorithm. |
657 // For short (length <= 22) arrays, insertion sort is used for efficiency. | 693 // For short (length <= 22) arrays, insertion sort is used for efficiency. |
658 | 694 |
659 if (!IS_FUNCTION(comparefn)) { | 695 if (!IS_FUNCTION(comparefn)) { |
660 comparefn = function (x, y) { | 696 comparefn = function (x, y) { |
661 if (x === y) return 0; | 697 if (x === y) return 0; |
662 if (%_IsSmi(x) && %_IsSmi(y)) { | 698 if (%_IsSmi(x) && %_IsSmi(y)) { |
663 return %SmiLexicographicCompare(x, y); | 699 return %SmiLexicographicCompare(x, y); |
664 } | 700 } |
665 x = ToString(x); | 701 x = ToString(x); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 } | 943 } |
908 | 944 |
909 return this; | 945 return this; |
910 } | 946 } |
911 | 947 |
912 | 948 |
913 // The following functions cannot be made efficient on sparse arrays while | 949 // The following functions cannot be made efficient on sparse arrays while |
914 // preserving the semantics, since the calls to the receiver function can add | 950 // preserving the semantics, since the calls to the receiver function can add |
915 // or delete elements from the array. | 951 // or delete elements from the array. |
916 function ArrayFilter(f, receiver) { | 952 function ArrayFilter(f, receiver) { |
| 953 if (IS_NULL_OR_UNDEFINED(this)) { |
| 954 throw MakeTypeError("obj_ctor_property_non_object", ["Array.filter"]); |
| 955 } |
| 956 |
917 if (!IS_FUNCTION(f)) { | 957 if (!IS_FUNCTION(f)) { |
918 throw MakeTypeError('called_non_callable', [ f ]); | 958 throw MakeTypeError('called_non_callable', [ f ]); |
919 } | 959 } |
920 // Pull out the length so that modifications to the length in the | 960 // Pull out the length so that modifications to the length in the |
921 // loop will not affect the looping. | 961 // loop will not affect the looping. |
922 var length = this.length; | 962 var length = this.length; |
923 var result = []; | 963 var result = []; |
924 var result_length = 0; | 964 var result_length = 0; |
925 for (var i = 0; i < length; i++) { | 965 for (var i = 0; i < length; i++) { |
926 var current = this[i]; | 966 var current = this[i]; |
927 if (!IS_UNDEFINED(current) || i in this) { | 967 if (!IS_UNDEFINED(current) || i in this) { |
928 if (f.call(receiver, current, i, this)) { | 968 if (f.call(receiver, current, i, this)) { |
929 result[result_length++] = current; | 969 result[result_length++] = current; |
930 } | 970 } |
931 } | 971 } |
932 } | 972 } |
933 return result; | 973 return result; |
934 } | 974 } |
935 | 975 |
936 | 976 |
937 function ArrayForEach(f, receiver) { | 977 function ArrayForEach(f, receiver) { |
| 978 if (IS_NULL_OR_UNDEFINED(this)) { |
| 979 throw MakeTypeError("obj_ctor_property_non_object", ["Array.forEach"]); |
| 980 } |
| 981 |
938 if (!IS_FUNCTION(f)) { | 982 if (!IS_FUNCTION(f)) { |
939 throw MakeTypeError('called_non_callable', [ f ]); | 983 throw MakeTypeError('called_non_callable', [ f ]); |
940 } | 984 } |
941 // Pull out the length so that modifications to the length in the | 985 // Pull out the length so that modifications to the length in the |
942 // loop will not affect the looping. | 986 // loop will not affect the looping. |
943 var length = TO_UINT32(this.length); | 987 var length = TO_UINT32(this.length); |
944 for (var i = 0; i < length; i++) { | 988 for (var i = 0; i < length; i++) { |
945 var current = this[i]; | 989 var current = this[i]; |
946 if (!IS_UNDEFINED(current) || i in this) { | 990 if (!IS_UNDEFINED(current) || i in this) { |
947 f.call(receiver, current, i, this); | 991 f.call(receiver, current, i, this); |
948 } | 992 } |
949 } | 993 } |
950 } | 994 } |
951 | 995 |
952 | 996 |
953 // Executes the function once for each element present in the | 997 // Executes the function once for each element present in the |
954 // array until it finds one where callback returns true. | 998 // array until it finds one where callback returns true. |
955 function ArraySome(f, receiver) { | 999 function ArraySome(f, receiver) { |
| 1000 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1001 throw MakeTypeError("obj_ctor_property_non_object", ["Array.some"]); |
| 1002 } |
| 1003 |
956 if (!IS_FUNCTION(f)) { | 1004 if (!IS_FUNCTION(f)) { |
957 throw MakeTypeError('called_non_callable', [ f ]); | 1005 throw MakeTypeError('called_non_callable', [ f ]); |
958 } | 1006 } |
959 // Pull out the length so that modifications to the length in the | 1007 // Pull out the length so that modifications to the length in the |
960 // loop will not affect the looping. | 1008 // loop will not affect the looping. |
961 var length = TO_UINT32(this.length); | 1009 var length = TO_UINT32(this.length); |
962 for (var i = 0; i < length; i++) { | 1010 for (var i = 0; i < length; i++) { |
963 var current = this[i]; | 1011 var current = this[i]; |
964 if (!IS_UNDEFINED(current) || i in this) { | 1012 if (!IS_UNDEFINED(current) || i in this) { |
965 if (f.call(receiver, current, i, this)) return true; | 1013 if (f.call(receiver, current, i, this)) return true; |
966 } | 1014 } |
967 } | 1015 } |
968 return false; | 1016 return false; |
969 } | 1017 } |
970 | 1018 |
971 | 1019 |
972 function ArrayEvery(f, receiver) { | 1020 function ArrayEvery(f, receiver) { |
| 1021 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1022 throw MakeTypeError("obj_ctor_property_non_object", ["Array.every"]); |
| 1023 } |
973 if (!IS_FUNCTION(f)) { | 1024 if (!IS_FUNCTION(f)) { |
974 throw MakeTypeError('called_non_callable', [ f ]); | 1025 throw MakeTypeError('called_non_callable', [ f ]); |
975 } | 1026 } |
976 // Pull out the length so that modifications to the length in the | 1027 // Pull out the length so that modifications to the length in the |
977 // loop will not affect the looping. | 1028 // loop will not affect the looping. |
978 var length = TO_UINT32(this.length); | 1029 var length = TO_UINT32(this.length); |
979 for (var i = 0; i < length; i++) { | 1030 for (var i = 0; i < length; i++) { |
980 var current = this[i]; | 1031 var current = this[i]; |
981 if (!IS_UNDEFINED(current) || i in this) { | 1032 if (!IS_UNDEFINED(current) || i in this) { |
982 if (!f.call(receiver, current, i, this)) return false; | 1033 if (!f.call(receiver, current, i, this)) return false; |
983 } | 1034 } |
984 } | 1035 } |
985 return true; | 1036 return true; |
986 } | 1037 } |
987 | 1038 |
988 function ArrayMap(f, receiver) { | 1039 function ArrayMap(f, receiver) { |
| 1040 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1041 throw MakeTypeError("obj_ctor_property_non_object", ["Array.map"]); |
| 1042 } |
| 1043 |
989 if (!IS_FUNCTION(f)) { | 1044 if (!IS_FUNCTION(f)) { |
990 throw MakeTypeError('called_non_callable', [ f ]); | 1045 throw MakeTypeError('called_non_callable', [ f ]); |
991 } | 1046 } |
992 // Pull out the length so that modifications to the length in the | 1047 // Pull out the length so that modifications to the length in the |
993 // loop will not affect the looping. | 1048 // loop will not affect the looping. |
994 var length = TO_UINT32(this.length); | 1049 var length = TO_UINT32(this.length); |
995 var result = new $Array(); | 1050 var result = new $Array(); |
996 var accumulator = new InternalArray(length); | 1051 var accumulator = new InternalArray(length); |
997 for (var i = 0; i < length; i++) { | 1052 for (var i = 0; i < length; i++) { |
998 var current = this[i]; | 1053 var current = this[i]; |
999 if (!IS_UNDEFINED(current) || i in this) { | 1054 if (!IS_UNDEFINED(current) || i in this) { |
1000 accumulator[i] = f.call(receiver, current, i, this); | 1055 accumulator[i] = f.call(receiver, current, i, this); |
1001 } | 1056 } |
1002 } | 1057 } |
1003 %MoveArrayContents(accumulator, result); | 1058 %MoveArrayContents(accumulator, result); |
1004 return result; | 1059 return result; |
1005 } | 1060 } |
1006 | 1061 |
1007 | 1062 |
1008 function ArrayIndexOf(element, index) { | 1063 function ArrayIndexOf(element, index) { |
| 1064 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1065 throw MakeTypeError("obj_ctor_property_non_object", ["Array.indexOf"]); |
| 1066 } |
1009 var length = TO_UINT32(this.length); | 1067 var length = TO_UINT32(this.length); |
1010 if (length == 0) return -1; | 1068 if (length == 0) return -1; |
1011 if (IS_UNDEFINED(index)) { | 1069 if (IS_UNDEFINED(index)) { |
1012 index = 0; | 1070 index = 0; |
1013 } else { | 1071 } else { |
1014 index = TO_INTEGER(index); | 1072 index = TO_INTEGER(index); |
1015 // If index is negative, index from the end of the array. | 1073 // If index is negative, index from the end of the array. |
1016 if (index < 0) { | 1074 if (index < 0) { |
1017 index = length + index; | 1075 index = length + index; |
1018 // If index is still negative, search the entire array. | 1076 // If index is still negative, search the entire array. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 for (var i = min; i < max; i++) { | 1114 for (var i = min; i < max; i++) { |
1057 if (IS_UNDEFINED(this[i]) && i in this) { | 1115 if (IS_UNDEFINED(this[i]) && i in this) { |
1058 return i; | 1116 return i; |
1059 } | 1117 } |
1060 } | 1118 } |
1061 return -1; | 1119 return -1; |
1062 } | 1120 } |
1063 | 1121 |
1064 | 1122 |
1065 function ArrayLastIndexOf(element, index) { | 1123 function ArrayLastIndexOf(element, index) { |
| 1124 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1125 throw MakeTypeError("obj_ctor_property_non_object", ["Array.lastIndexOf"]); |
| 1126 } |
| 1127 |
1066 var length = TO_UINT32(this.length); | 1128 var length = TO_UINT32(this.length); |
1067 if (length == 0) return -1; | 1129 if (length == 0) return -1; |
1068 if (%_ArgumentsLength() < 2) { | 1130 if (%_ArgumentsLength() < 2) { |
1069 index = length - 1; | 1131 index = length - 1; |
1070 } else { | 1132 } else { |
1071 index = TO_INTEGER(index); | 1133 index = TO_INTEGER(index); |
1072 // If index is negative, index from end of the array. | 1134 // If index is negative, index from end of the array. |
1073 if (index < 0) index += length; | 1135 if (index < 0) index += length; |
1074 // If index is still negative, do not search the array. | 1136 // If index is still negative, do not search the array. |
1075 if (index < 0) return -1; | 1137 if (index < 0) return -1; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1109 for (var i = max; i >= min; i--) { | 1171 for (var i = max; i >= min; i--) { |
1110 if (IS_UNDEFINED(this[i]) && i in this) { | 1172 if (IS_UNDEFINED(this[i]) && i in this) { |
1111 return i; | 1173 return i; |
1112 } | 1174 } |
1113 } | 1175 } |
1114 return -1; | 1176 return -1; |
1115 } | 1177 } |
1116 | 1178 |
1117 | 1179 |
1118 function ArrayReduce(callback, current) { | 1180 function ArrayReduce(callback, current) { |
| 1181 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1182 throw MakeTypeError("obj_ctor_property_non_object", ["Array.reduce"]); |
| 1183 } |
1119 if (!IS_FUNCTION(callback)) { | 1184 if (!IS_FUNCTION(callback)) { |
1120 throw MakeTypeError('called_non_callable', [callback]); | 1185 throw MakeTypeError('called_non_callable', [callback]); |
1121 } | 1186 } |
1122 // Pull out the length so that modifications to the length in the | 1187 // Pull out the length so that modifications to the length in the |
1123 // loop will not affect the looping. | 1188 // loop will not affect the looping. |
1124 var length = this.length; | 1189 var length = this.length; |
1125 var i = 0; | 1190 var i = 0; |
1126 | 1191 |
1127 find_initial: if (%_ArgumentsLength() < 2) { | 1192 find_initial: if (%_ArgumentsLength() < 2) { |
1128 for (; i < length; i++) { | 1193 for (; i < length; i++) { |
1129 current = this[i]; | 1194 current = this[i]; |
1130 if (!IS_UNDEFINED(current) || i in this) { | 1195 if (!IS_UNDEFINED(current) || i in this) { |
1131 i++; | 1196 i++; |
1132 break find_initial; | 1197 break find_initial; |
1133 } | 1198 } |
1134 } | 1199 } |
1135 throw MakeTypeError('reduce_no_initial', []); | 1200 throw MakeTypeError('reduce_no_initial', []); |
1136 } | 1201 } |
1137 | 1202 |
1138 for (; i < length; i++) { | 1203 for (; i < length; i++) { |
1139 var element = this[i]; | 1204 var element = this[i]; |
1140 if (!IS_UNDEFINED(element) || i in this) { | 1205 if (!IS_UNDEFINED(element) || i in this) { |
1141 current = callback.call(null, current, element, i, this); | 1206 current = callback.call(null, current, element, i, this); |
1142 } | 1207 } |
1143 } | 1208 } |
1144 return current; | 1209 return current; |
1145 } | 1210 } |
1146 | 1211 |
1147 function ArrayReduceRight(callback, current) { | 1212 function ArrayReduceRight(callback, current) { |
| 1213 if (IS_NULL_OR_UNDEFINED(this)) { |
| 1214 throw MakeTypeError("obj_ctor_property_non_object", ["Array.reduceRight"]); |
| 1215 } |
| 1216 |
1148 if (!IS_FUNCTION(callback)) { | 1217 if (!IS_FUNCTION(callback)) { |
1149 throw MakeTypeError('called_non_callable', [callback]); | 1218 throw MakeTypeError('called_non_callable', [callback]); |
1150 } | 1219 } |
1151 var i = this.length - 1; | 1220 var i = this.length - 1; |
1152 | 1221 |
1153 find_initial: if (%_ArgumentsLength() < 2) { | 1222 find_initial: if (%_ArgumentsLength() < 2) { |
1154 for (; i >= 0; i--) { | 1223 for (; i >= 0; i--) { |
1155 current = this[i]; | 1224 current = this[i]; |
1156 if (!IS_UNDEFINED(current) || i in this) { | 1225 if (!IS_UNDEFINED(current) || i in this) { |
1157 i--; | 1226 i--; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 InternalArray.prototype.join = getFunction("join", ArrayJoin); | 1309 InternalArray.prototype.join = getFunction("join", ArrayJoin); |
1241 InternalArray.prototype.pop = getFunction("pop", ArrayPop); | 1310 InternalArray.prototype.pop = getFunction("pop", ArrayPop); |
1242 InternalArray.prototype.push = getFunction("push", ArrayPush); | 1311 InternalArray.prototype.push = getFunction("push", ArrayPush); |
1243 InternalArray.prototype.toString = function() { | 1312 InternalArray.prototype.toString = function() { |
1244 return "Internal Array, length " + this.length; | 1313 return "Internal Array, length " + this.length; |
1245 }; | 1314 }; |
1246 } | 1315 } |
1247 | 1316 |
1248 | 1317 |
1249 SetupArray(); | 1318 SetupArray(); |
OLD | NEW |