| 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) && !IS_UNDETECTABLE(this)) { |
| 379 throw MakeTypeError("called_on_null_or_undefined", |
| 380 ["Array.prototype.join"]); |
| 381 } |
| 382 |
| 378 if (IS_UNDEFINED(separator)) { | 383 if (IS_UNDEFINED(separator)) { |
| 379 separator = ','; | 384 separator = ','; |
| 380 } else if (!IS_STRING(separator)) { | 385 } else if (!IS_STRING(separator)) { |
| 381 separator = NonStringToString(separator); | 386 separator = NonStringToString(separator); |
| 382 } | 387 } |
| 383 | 388 |
| 384 var result = %_FastAsciiArrayJoin(this, separator); | 389 var result = %_FastAsciiArrayJoin(this, separator); |
| 385 if (!IS_UNDEFINED(result)) return result; | 390 if (!IS_UNDEFINED(result)) return result; |
| 386 | 391 |
| 387 return Join(this, TO_UINT32(this.length), separator, ConvertToString); | 392 return Join(this, TO_UINT32(this.length), separator, ConvertToString); |
| 388 } | 393 } |
| 389 | 394 |
| 390 | 395 |
| 391 // Removes the last element from the array and returns it. See | 396 // Removes the last element from the array and returns it. See |
| 392 // ECMA-262, section 15.4.4.6. | 397 // ECMA-262, section 15.4.4.6. |
| 393 function ArrayPop() { | 398 function ArrayPop() { |
| 399 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 400 throw MakeTypeError("called_on_null_or_undefined", |
| 401 ["Array.prototype.pop"]); |
| 402 } |
| 403 |
| 394 var n = TO_UINT32(this.length); | 404 var n = TO_UINT32(this.length); |
| 395 if (n == 0) { | 405 if (n == 0) { |
| 396 this.length = n; | 406 this.length = n; |
| 397 return; | 407 return; |
| 398 } | 408 } |
| 399 n--; | 409 n--; |
| 400 var value = this[n]; | 410 var value = this[n]; |
| 401 this.length = n; | 411 this.length = n; |
| 402 delete this[n]; | 412 delete this[n]; |
| 403 return value; | 413 return value; |
| 404 } | 414 } |
| 405 | 415 |
| 406 | 416 |
| 407 // Appends the arguments to the end of the array and returns the new | 417 // 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. | 418 // length of the array. See ECMA-262, section 15.4.4.7. |
| 409 function ArrayPush() { | 419 function ArrayPush() { |
| 420 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 421 throw MakeTypeError("called_on_null_or_undefined", |
| 422 ["Array.prototype.push"]); |
| 423 } |
| 424 |
| 410 var n = TO_UINT32(this.length); | 425 var n = TO_UINT32(this.length); |
| 411 var m = %_ArgumentsLength(); | 426 var m = %_ArgumentsLength(); |
| 412 for (var i = 0; i < m; i++) { | 427 for (var i = 0; i < m; i++) { |
| 413 this[i+n] = %_Arguments(i); | 428 this[i+n] = %_Arguments(i); |
| 414 } | 429 } |
| 415 this.length = n + m; | 430 this.length = n + m; |
| 416 return this.length; | 431 return this.length; |
| 417 } | 432 } |
| 418 | 433 |
| 419 | 434 |
| 420 function ArrayConcat(arg1) { // length == 1 | 435 function ArrayConcat(arg1) { // length == 1 |
| 436 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 437 throw MakeTypeError("called_on_null_or_undefined", |
| 438 ["Array.prototype.concat"]); |
| 439 } |
| 440 |
| 421 var arg_count = %_ArgumentsLength(); | 441 var arg_count = %_ArgumentsLength(); |
| 422 var arrays = new InternalArray(1 + arg_count); | 442 var arrays = new InternalArray(1 + arg_count); |
| 423 arrays[0] = this; | 443 arrays[0] = this; |
| 424 for (var i = 0; i < arg_count; i++) { | 444 for (var i = 0; i < arg_count; i++) { |
| 425 arrays[i + 1] = %_Arguments(i); | 445 arrays[i + 1] = %_Arguments(i); |
| 426 } | 446 } |
| 427 | 447 |
| 428 return %ArrayConcat(arrays); | 448 return %ArrayConcat(arrays); |
| 429 } | 449 } |
| 430 | 450 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (!IS_UNDEFINED(current_j) || high in array) { | 487 if (!IS_UNDEFINED(current_j) || high in array) { |
| 468 array[low] = current_j; | 488 array[low] = current_j; |
| 469 delete array[high]; | 489 delete array[high]; |
| 470 } | 490 } |
| 471 } | 491 } |
| 472 } | 492 } |
| 473 } | 493 } |
| 474 | 494 |
| 475 | 495 |
| 476 function ArrayReverse() { | 496 function ArrayReverse() { |
| 497 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 498 throw MakeTypeError("called_on_null_or_undefined", |
| 499 ["Array.prototype.reverse"]); |
| 500 } |
| 501 |
| 477 var j = TO_UINT32(this.length) - 1; | 502 var j = TO_UINT32(this.length) - 1; |
| 478 | 503 |
| 479 if (UseSparseVariant(this, j, IS_ARRAY(this))) { | 504 if (UseSparseVariant(this, j, IS_ARRAY(this))) { |
| 480 SparseReverse(this, j+1); | 505 SparseReverse(this, j+1); |
| 481 return this; | 506 return this; |
| 482 } | 507 } |
| 483 | 508 |
| 484 for (var i = 0; i < j; i++, j--) { | 509 for (var i = 0; i < j; i++, j--) { |
| 485 var current_i = this[i]; | 510 var current_i = this[i]; |
| 486 if (!IS_UNDEFINED(current_i) || i in this) { | 511 if (!IS_UNDEFINED(current_i) || i in this) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 498 this[i] = current_j; | 523 this[i] = current_j; |
| 499 delete this[j]; | 524 delete this[j]; |
| 500 } | 525 } |
| 501 } | 526 } |
| 502 } | 527 } |
| 503 return this; | 528 return this; |
| 504 } | 529 } |
| 505 | 530 |
| 506 | 531 |
| 507 function ArrayShift() { | 532 function ArrayShift() { |
| 533 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 534 throw MakeTypeError("called_on_null_or_undefined", |
| 535 ["Array.prototype.shift"]); |
| 536 } |
| 537 |
| 508 var len = TO_UINT32(this.length); | 538 var len = TO_UINT32(this.length); |
| 509 | 539 |
| 510 if (len === 0) { | 540 if (len === 0) { |
| 511 this.length = 0; | 541 this.length = 0; |
| 512 return; | 542 return; |
| 513 } | 543 } |
| 514 | 544 |
| 515 var first = this[0]; | 545 var first = this[0]; |
| 516 | 546 |
| 517 if (IS_ARRAY(this)) | 547 if (IS_ARRAY(this)) |
| 518 SmartMove(this, 0, 1, len, 0); | 548 SmartMove(this, 0, 1, len, 0); |
| 519 else | 549 else |
| 520 SimpleMove(this, 0, 1, len, 0); | 550 SimpleMove(this, 0, 1, len, 0); |
| 521 | 551 |
| 522 this.length = len - 1; | 552 this.length = len - 1; |
| 523 | 553 |
| 524 return first; | 554 return first; |
| 525 } | 555 } |
| 526 | 556 |
| 527 | 557 |
| 528 function ArrayUnshift(arg1) { // length == 1 | 558 function ArrayUnshift(arg1) { // length == 1 |
| 559 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 560 throw MakeTypeError("called_on_null_or_undefined", |
| 561 ["Array.prototype.unshift"]); |
| 562 } |
| 563 |
| 529 var len = TO_UINT32(this.length); | 564 var len = TO_UINT32(this.length); |
| 530 var num_arguments = %_ArgumentsLength(); | 565 var num_arguments = %_ArgumentsLength(); |
| 531 | 566 |
| 532 if (IS_ARRAY(this)) | 567 if (IS_ARRAY(this)) |
| 533 SmartMove(this, 0, 0, len, num_arguments); | 568 SmartMove(this, 0, 0, len, num_arguments); |
| 534 else | 569 else |
| 535 SimpleMove(this, 0, 0, len, num_arguments); | 570 SimpleMove(this, 0, 0, len, num_arguments); |
| 536 | 571 |
| 537 for (var i = 0; i < num_arguments; i++) { | 572 for (var i = 0; i < num_arguments; i++) { |
| 538 this[i] = %_Arguments(i); | 573 this[i] = %_Arguments(i); |
| 539 } | 574 } |
| 540 | 575 |
| 541 this.length = len + num_arguments; | 576 this.length = len + num_arguments; |
| 542 | 577 |
| 543 return len + num_arguments; | 578 return len + num_arguments; |
| 544 } | 579 } |
| 545 | 580 |
| 546 | 581 |
| 547 function ArraySlice(start, end) { | 582 function ArraySlice(start, end) { |
| 583 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 584 throw MakeTypeError("called_on_null_or_undefined", |
| 585 ["Array.prototype.slice"]); |
| 586 } |
| 587 |
| 548 var len = TO_UINT32(this.length); | 588 var len = TO_UINT32(this.length); |
| 549 var start_i = TO_INTEGER(start); | 589 var start_i = TO_INTEGER(start); |
| 550 var end_i = len; | 590 var end_i = len; |
| 551 | 591 |
| 552 if (end !== void 0) end_i = TO_INTEGER(end); | 592 if (end !== void 0) end_i = TO_INTEGER(end); |
| 553 | 593 |
| 554 if (start_i < 0) { | 594 if (start_i < 0) { |
| 555 start_i += len; | 595 start_i += len; |
| 556 if (start_i < 0) start_i = 0; | 596 if (start_i < 0) start_i = 0; |
| 557 } else { | 597 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 575 SimpleSlice(this, start_i, end_i - start_i, len, result); | 615 SimpleSlice(this, start_i, end_i - start_i, len, result); |
| 576 } | 616 } |
| 577 | 617 |
| 578 result.length = end_i - start_i; | 618 result.length = end_i - start_i; |
| 579 | 619 |
| 580 return result; | 620 return result; |
| 581 } | 621 } |
| 582 | 622 |
| 583 | 623 |
| 584 function ArraySplice(start, delete_count) { | 624 function ArraySplice(start, delete_count) { |
| 625 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 626 throw MakeTypeError("called_on_null_or_undefined", |
| 627 ["Array.prototype.splice"]); |
| 628 } |
| 629 |
| 585 var num_arguments = %_ArgumentsLength(); | 630 var num_arguments = %_ArgumentsLength(); |
| 586 | 631 |
| 587 var len = TO_UINT32(this.length); | 632 var len = TO_UINT32(this.length); |
| 588 var start_i = TO_INTEGER(start); | 633 var start_i = TO_INTEGER(start); |
| 589 | 634 |
| 590 if (start_i < 0) { | 635 if (start_i < 0) { |
| 591 start_i += len; | 636 start_i += len; |
| 592 if (start_i < 0) start_i = 0; | 637 if (start_i < 0) start_i = 0; |
| 593 } else { | 638 } else { |
| 594 if (start_i > len) start_i = len; | 639 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++); | 691 this[i++] = %_Arguments(arguments_index++); |
| 647 } | 692 } |
| 648 this.length = len - del_count + num_additional_args; | 693 this.length = len - del_count + num_additional_args; |
| 649 | 694 |
| 650 // Return the deleted elements. | 695 // Return the deleted elements. |
| 651 return deleted_elements; | 696 return deleted_elements; |
| 652 } | 697 } |
| 653 | 698 |
| 654 | 699 |
| 655 function ArraySort(comparefn) { | 700 function ArraySort(comparefn) { |
| 701 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 702 throw MakeTypeError("called_on_null_or_undefined", |
| 703 ["Array.prototype.sort"]); |
| 704 } |
| 705 |
| 656 // In-place QuickSort algorithm. | 706 // In-place QuickSort algorithm. |
| 657 // For short (length <= 22) arrays, insertion sort is used for efficiency. | 707 // For short (length <= 22) arrays, insertion sort is used for efficiency. |
| 658 | 708 |
| 659 if (!IS_FUNCTION(comparefn)) { | 709 if (!IS_FUNCTION(comparefn)) { |
| 660 comparefn = function (x, y) { | 710 comparefn = function (x, y) { |
| 661 if (x === y) return 0; | 711 if (x === y) return 0; |
| 662 if (%_IsSmi(x) && %_IsSmi(y)) { | 712 if (%_IsSmi(x) && %_IsSmi(y)) { |
| 663 return %SmiLexicographicCompare(x, y); | 713 return %SmiLexicographicCompare(x, y); |
| 664 } | 714 } |
| 665 x = ToString(x); | 715 x = ToString(x); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 907 } | 957 } |
| 908 | 958 |
| 909 return this; | 959 return this; |
| 910 } | 960 } |
| 911 | 961 |
| 912 | 962 |
| 913 // The following functions cannot be made efficient on sparse arrays while | 963 // The following functions cannot be made efficient on sparse arrays while |
| 914 // preserving the semantics, since the calls to the receiver function can add | 964 // preserving the semantics, since the calls to the receiver function can add |
| 915 // or delete elements from the array. | 965 // or delete elements from the array. |
| 916 function ArrayFilter(f, receiver) { | 966 function ArrayFilter(f, receiver) { |
| 967 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 968 throw MakeTypeError("called_on_null_or_undefined", |
| 969 ["Array.prototype.filter"]); |
| 970 } |
| 971 |
| 917 if (!IS_FUNCTION(f)) { | 972 if (!IS_FUNCTION(f)) { |
| 918 throw MakeTypeError('called_non_callable', [ f ]); | 973 throw MakeTypeError('called_non_callable', [ f ]); |
| 919 } | 974 } |
| 920 // Pull out the length so that modifications to the length in the | 975 // Pull out the length so that modifications to the length in the |
| 921 // loop will not affect the looping. | 976 // loop will not affect the looping. |
| 922 var length = this.length; | 977 var length = this.length; |
| 923 var result = []; | 978 var result = []; |
| 924 var result_length = 0; | 979 var result_length = 0; |
| 925 for (var i = 0; i < length; i++) { | 980 for (var i = 0; i < length; i++) { |
| 926 var current = this[i]; | 981 var current = this[i]; |
| 927 if (!IS_UNDEFINED(current) || i in this) { | 982 if (!IS_UNDEFINED(current) || i in this) { |
| 928 if (f.call(receiver, current, i, this)) { | 983 if (f.call(receiver, current, i, this)) { |
| 929 result[result_length++] = current; | 984 result[result_length++] = current; |
| 930 } | 985 } |
| 931 } | 986 } |
| 932 } | 987 } |
| 933 return result; | 988 return result; |
| 934 } | 989 } |
| 935 | 990 |
| 936 | 991 |
| 937 function ArrayForEach(f, receiver) { | 992 function ArrayForEach(f, receiver) { |
| 993 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 994 throw MakeTypeError("called_on_null_or_undefined", |
| 995 ["Array.prototype.forEach"]); |
| 996 } |
| 997 |
| 938 if (!IS_FUNCTION(f)) { | 998 if (!IS_FUNCTION(f)) { |
| 939 throw MakeTypeError('called_non_callable', [ f ]); | 999 throw MakeTypeError('called_non_callable', [ f ]); |
| 940 } | 1000 } |
| 941 // Pull out the length so that modifications to the length in the | 1001 // Pull out the length so that modifications to the length in the |
| 942 // loop will not affect the looping. | 1002 // loop will not affect the looping. |
| 943 var length = TO_UINT32(this.length); | 1003 var length = TO_UINT32(this.length); |
| 944 for (var i = 0; i < length; i++) { | 1004 for (var i = 0; i < length; i++) { |
| 945 var current = this[i]; | 1005 var current = this[i]; |
| 946 if (!IS_UNDEFINED(current) || i in this) { | 1006 if (!IS_UNDEFINED(current) || i in this) { |
| 947 f.call(receiver, current, i, this); | 1007 f.call(receiver, current, i, this); |
| 948 } | 1008 } |
| 949 } | 1009 } |
| 950 } | 1010 } |
| 951 | 1011 |
| 952 | 1012 |
| 953 // Executes the function once for each element present in the | 1013 // Executes the function once for each element present in the |
| 954 // array until it finds one where callback returns true. | 1014 // array until it finds one where callback returns true. |
| 955 function ArraySome(f, receiver) { | 1015 function ArraySome(f, receiver) { |
| 1016 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1017 throw MakeTypeError("called_on_null_or_undefined", |
| 1018 ["Array.prototype.some"]); |
| 1019 } |
| 1020 |
| 956 if (!IS_FUNCTION(f)) { | 1021 if (!IS_FUNCTION(f)) { |
| 957 throw MakeTypeError('called_non_callable', [ f ]); | 1022 throw MakeTypeError('called_non_callable', [ f ]); |
| 958 } | 1023 } |
| 959 // Pull out the length so that modifications to the length in the | 1024 // Pull out the length so that modifications to the length in the |
| 960 // loop will not affect the looping. | 1025 // loop will not affect the looping. |
| 961 var length = TO_UINT32(this.length); | 1026 var length = TO_UINT32(this.length); |
| 962 for (var i = 0; i < length; i++) { | 1027 for (var i = 0; i < length; i++) { |
| 963 var current = this[i]; | 1028 var current = this[i]; |
| 964 if (!IS_UNDEFINED(current) || i in this) { | 1029 if (!IS_UNDEFINED(current) || i in this) { |
| 965 if (f.call(receiver, current, i, this)) return true; | 1030 if (f.call(receiver, current, i, this)) return true; |
| 966 } | 1031 } |
| 967 } | 1032 } |
| 968 return false; | 1033 return false; |
| 969 } | 1034 } |
| 970 | 1035 |
| 971 | 1036 |
| 972 function ArrayEvery(f, receiver) { | 1037 function ArrayEvery(f, receiver) { |
| 1038 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1039 throw MakeTypeError("called_on_null_or_undefined", |
| 1040 ["Array.prototype.every"]); |
| 1041 } |
| 1042 |
| 973 if (!IS_FUNCTION(f)) { | 1043 if (!IS_FUNCTION(f)) { |
| 974 throw MakeTypeError('called_non_callable', [ f ]); | 1044 throw MakeTypeError('called_non_callable', [ f ]); |
| 975 } | 1045 } |
| 976 // Pull out the length so that modifications to the length in the | 1046 // Pull out the length so that modifications to the length in the |
| 977 // loop will not affect the looping. | 1047 // loop will not affect the looping. |
| 978 var length = TO_UINT32(this.length); | 1048 var length = TO_UINT32(this.length); |
| 979 for (var i = 0; i < length; i++) { | 1049 for (var i = 0; i < length; i++) { |
| 980 var current = this[i]; | 1050 var current = this[i]; |
| 981 if (!IS_UNDEFINED(current) || i in this) { | 1051 if (!IS_UNDEFINED(current) || i in this) { |
| 982 if (!f.call(receiver, current, i, this)) return false; | 1052 if (!f.call(receiver, current, i, this)) return false; |
| 983 } | 1053 } |
| 984 } | 1054 } |
| 985 return true; | 1055 return true; |
| 986 } | 1056 } |
| 987 | 1057 |
| 988 function ArrayMap(f, receiver) { | 1058 function ArrayMap(f, receiver) { |
| 1059 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1060 throw MakeTypeError("called_on_null_or_undefined", |
| 1061 ["Array.prototype.map"]); |
| 1062 } |
| 1063 |
| 989 if (!IS_FUNCTION(f)) { | 1064 if (!IS_FUNCTION(f)) { |
| 990 throw MakeTypeError('called_non_callable', [ f ]); | 1065 throw MakeTypeError('called_non_callable', [ f ]); |
| 991 } | 1066 } |
| 992 // Pull out the length so that modifications to the length in the | 1067 // Pull out the length so that modifications to the length in the |
| 993 // loop will not affect the looping. | 1068 // loop will not affect the looping. |
| 994 var length = TO_UINT32(this.length); | 1069 var length = TO_UINT32(this.length); |
| 995 var result = new $Array(); | 1070 var result = new $Array(); |
| 996 var accumulator = new InternalArray(length); | 1071 var accumulator = new InternalArray(length); |
| 997 for (var i = 0; i < length; i++) { | 1072 for (var i = 0; i < length; i++) { |
| 998 var current = this[i]; | 1073 var current = this[i]; |
| 999 if (!IS_UNDEFINED(current) || i in this) { | 1074 if (!IS_UNDEFINED(current) || i in this) { |
| 1000 accumulator[i] = f.call(receiver, current, i, this); | 1075 accumulator[i] = f.call(receiver, current, i, this); |
| 1001 } | 1076 } |
| 1002 } | 1077 } |
| 1003 %MoveArrayContents(accumulator, result); | 1078 %MoveArrayContents(accumulator, result); |
| 1004 return result; | 1079 return result; |
| 1005 } | 1080 } |
| 1006 | 1081 |
| 1007 | 1082 |
| 1008 function ArrayIndexOf(element, index) { | 1083 function ArrayIndexOf(element, index) { |
| 1084 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1085 throw MakeTypeError("called_on_null_or_undefined", |
| 1086 ["Array.prototype.indexOf"]); |
| 1087 } |
| 1088 |
| 1009 var length = TO_UINT32(this.length); | 1089 var length = TO_UINT32(this.length); |
| 1010 if (length == 0) return -1; | 1090 if (length == 0) return -1; |
| 1011 if (IS_UNDEFINED(index)) { | 1091 if (IS_UNDEFINED(index)) { |
| 1012 index = 0; | 1092 index = 0; |
| 1013 } else { | 1093 } else { |
| 1014 index = TO_INTEGER(index); | 1094 index = TO_INTEGER(index); |
| 1015 // If index is negative, index from the end of the array. | 1095 // If index is negative, index from the end of the array. |
| 1016 if (index < 0) { | 1096 if (index < 0) { |
| 1017 index = length + index; | 1097 index = length + index; |
| 1018 // If index is still negative, search the entire array. | 1098 // 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++) { | 1136 for (var i = min; i < max; i++) { |
| 1057 if (IS_UNDEFINED(this[i]) && i in this) { | 1137 if (IS_UNDEFINED(this[i]) && i in this) { |
| 1058 return i; | 1138 return i; |
| 1059 } | 1139 } |
| 1060 } | 1140 } |
| 1061 return -1; | 1141 return -1; |
| 1062 } | 1142 } |
| 1063 | 1143 |
| 1064 | 1144 |
| 1065 function ArrayLastIndexOf(element, index) { | 1145 function ArrayLastIndexOf(element, index) { |
| 1146 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1147 throw MakeTypeError("called_on_null_or_undefined", |
| 1148 ["Array.prototype.lastIndexOf"]); |
| 1149 } |
| 1150 |
| 1066 var length = TO_UINT32(this.length); | 1151 var length = TO_UINT32(this.length); |
| 1067 if (length == 0) return -1; | 1152 if (length == 0) return -1; |
| 1068 if (%_ArgumentsLength() < 2) { | 1153 if (%_ArgumentsLength() < 2) { |
| 1069 index = length - 1; | 1154 index = length - 1; |
| 1070 } else { | 1155 } else { |
| 1071 index = TO_INTEGER(index); | 1156 index = TO_INTEGER(index); |
| 1072 // If index is negative, index from end of the array. | 1157 // If index is negative, index from end of the array. |
| 1073 if (index < 0) index += length; | 1158 if (index < 0) index += length; |
| 1074 // If index is still negative, do not search the array. | 1159 // If index is still negative, do not search the array. |
| 1075 if (index < 0) return -1; | 1160 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--) { | 1194 for (var i = max; i >= min; i--) { |
| 1110 if (IS_UNDEFINED(this[i]) && i in this) { | 1195 if (IS_UNDEFINED(this[i]) && i in this) { |
| 1111 return i; | 1196 return i; |
| 1112 } | 1197 } |
| 1113 } | 1198 } |
| 1114 return -1; | 1199 return -1; |
| 1115 } | 1200 } |
| 1116 | 1201 |
| 1117 | 1202 |
| 1118 function ArrayReduce(callback, current) { | 1203 function ArrayReduce(callback, current) { |
| 1204 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1205 throw MakeTypeError("called_on_null_or_undefined", |
| 1206 ["Array.prototype.reduce"]); |
| 1207 } |
| 1208 |
| 1119 if (!IS_FUNCTION(callback)) { | 1209 if (!IS_FUNCTION(callback)) { |
| 1120 throw MakeTypeError('called_non_callable', [callback]); | 1210 throw MakeTypeError('called_non_callable', [callback]); |
| 1121 } | 1211 } |
| 1122 // Pull out the length so that modifications to the length in the | 1212 // Pull out the length so that modifications to the length in the |
| 1123 // loop will not affect the looping. | 1213 // loop will not affect the looping. |
| 1124 var length = this.length; | 1214 var length = this.length; |
| 1125 var i = 0; | 1215 var i = 0; |
| 1126 | 1216 |
| 1127 find_initial: if (%_ArgumentsLength() < 2) { | 1217 find_initial: if (%_ArgumentsLength() < 2) { |
| 1128 for (; i < length; i++) { | 1218 for (; i < length; i++) { |
| 1129 current = this[i]; | 1219 current = this[i]; |
| 1130 if (!IS_UNDEFINED(current) || i in this) { | 1220 if (!IS_UNDEFINED(current) || i in this) { |
| 1131 i++; | 1221 i++; |
| 1132 break find_initial; | 1222 break find_initial; |
| 1133 } | 1223 } |
| 1134 } | 1224 } |
| 1135 throw MakeTypeError('reduce_no_initial', []); | 1225 throw MakeTypeError('reduce_no_initial', []); |
| 1136 } | 1226 } |
| 1137 | 1227 |
| 1138 for (; i < length; i++) { | 1228 for (; i < length; i++) { |
| 1139 var element = this[i]; | 1229 var element = this[i]; |
| 1140 if (!IS_UNDEFINED(element) || i in this) { | 1230 if (!IS_UNDEFINED(element) || i in this) { |
| 1141 current = callback.call(null, current, element, i, this); | 1231 current = callback.call(null, current, element, i, this); |
| 1142 } | 1232 } |
| 1143 } | 1233 } |
| 1144 return current; | 1234 return current; |
| 1145 } | 1235 } |
| 1146 | 1236 |
| 1147 function ArrayReduceRight(callback, current) { | 1237 function ArrayReduceRight(callback, current) { |
| 1238 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 1239 throw MakeTypeError("called_on_null_or_undefined", |
| 1240 ["Array.prototype.reduceRight"]); |
| 1241 } |
| 1242 |
| 1148 if (!IS_FUNCTION(callback)) { | 1243 if (!IS_FUNCTION(callback)) { |
| 1149 throw MakeTypeError('called_non_callable', [callback]); | 1244 throw MakeTypeError('called_non_callable', [callback]); |
| 1150 } | 1245 } |
| 1151 var i = this.length - 1; | 1246 var i = this.length - 1; |
| 1152 | 1247 |
| 1153 find_initial: if (%_ArgumentsLength() < 2) { | 1248 find_initial: if (%_ArgumentsLength() < 2) { |
| 1154 for (; i >= 0; i--) { | 1249 for (; i >= 0; i--) { |
| 1155 current = this[i]; | 1250 current = this[i]; |
| 1156 if (!IS_UNDEFINED(current) || i in this) { | 1251 if (!IS_UNDEFINED(current) || i in this) { |
| 1157 i--; | 1252 i--; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 InternalArray.prototype.join = getFunction("join", ArrayJoin); | 1335 InternalArray.prototype.join = getFunction("join", ArrayJoin); |
| 1241 InternalArray.prototype.pop = getFunction("pop", ArrayPop); | 1336 InternalArray.prototype.pop = getFunction("pop", ArrayPop); |
| 1242 InternalArray.prototype.push = getFunction("push", ArrayPush); | 1337 InternalArray.prototype.push = getFunction("push", ArrayPush); |
| 1243 InternalArray.prototype.toString = function() { | 1338 InternalArray.prototype.toString = function() { |
| 1244 return "Internal Array, length " + this.length; | 1339 return "Internal Array, length " + this.length; |
| 1245 }; | 1340 }; |
| 1246 } | 1341 } |
| 1247 | 1342 |
| 1248 | 1343 |
| 1249 SetupArray(); | 1344 SetupArray(); |
| OLD | NEW |