Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(869)

Side by Side Diff: src/array.js

Issue 6928007: Reapply 7763, including arm and x64 variants. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm/builtins-arm.cc ('k') | src/date.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 390
391 function ArrayToLocaleString() { 391 function ArrayToLocaleString() {
392 if (!IS_ARRAY(this)) { 392 if (!IS_ARRAY(this)) {
393 throw new $TypeError('Array.prototype.toString is not generic'); 393 throw new $TypeError('Array.prototype.toString is not generic');
394 } 394 }
395 return Join(this, this.length, ',', ConvertToLocaleString); 395 return Join(this, this.length, ',', ConvertToLocaleString);
396 } 396 }
397 397
398 398
399 function ArrayJoin(separator) { 399 function ArrayJoin(separator) {
400 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
401 throw MakeTypeError("called_on_null_or_undefined",
402 ["Array.prototype.join"]);
403 }
404
400 if (IS_UNDEFINED(separator)) { 405 if (IS_UNDEFINED(separator)) {
401 separator = ','; 406 separator = ',';
402 } else if (!IS_STRING(separator)) { 407 } else if (!IS_STRING(separator)) {
403 separator = NonStringToString(separator); 408 separator = NonStringToString(separator);
404 } 409 }
405 410
406 var result = %_FastAsciiArrayJoin(this, separator); 411 var result = %_FastAsciiArrayJoin(this, separator);
407 if (!IS_UNDEFINED(result)) return result; 412 if (!IS_UNDEFINED(result)) return result;
408 413
409 return Join(this, TO_UINT32(this.length), separator, ConvertToString); 414 return Join(this, TO_UINT32(this.length), separator, ConvertToString);
410 } 415 }
411 416
412 417
413 // Removes the last element from the array and returns it. See 418 // Removes the last element from the array and returns it. See
414 // ECMA-262, section 15.4.4.6. 419 // ECMA-262, section 15.4.4.6.
415 function ArrayPop() { 420 function ArrayPop() {
421 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
422 throw MakeTypeError("called_on_null_or_undefined",
423 ["Array.prototype.pop"]);
424 }
425
416 var n = TO_UINT32(this.length); 426 var n = TO_UINT32(this.length);
417 if (n == 0) { 427 if (n == 0) {
418 this.length = n; 428 this.length = n;
419 return; 429 return;
420 } 430 }
421 n--; 431 n--;
422 var value = this[n]; 432 var value = this[n];
423 this.length = n; 433 this.length = n;
424 delete this[n]; 434 delete this[n];
425 return value; 435 return value;
426 } 436 }
427 437
428 438
429 // Appends the arguments to the end of the array and returns the new 439 // Appends the arguments to the end of the array and returns the new
430 // length of the array. See ECMA-262, section 15.4.4.7. 440 // length of the array. See ECMA-262, section 15.4.4.7.
431 function ArrayPush() { 441 function ArrayPush() {
442 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
443 throw MakeTypeError("called_on_null_or_undefined",
444 ["Array.prototype.push"]);
445 }
446
432 var n = TO_UINT32(this.length); 447 var n = TO_UINT32(this.length);
433 var m = %_ArgumentsLength(); 448 var m = %_ArgumentsLength();
434 for (var i = 0; i < m; i++) { 449 for (var i = 0; i < m; i++) {
435 this[i+n] = %_Arguments(i); 450 this[i+n] = %_Arguments(i);
436 } 451 }
437 this.length = n + m; 452 this.length = n + m;
438 return this.length; 453 return this.length;
439 } 454 }
440 455
441 456
442 function ArrayConcat(arg1) { // length == 1 457 function ArrayConcat(arg1) { // length == 1
458 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
459 throw MakeTypeError("called_on_null_or_undefined",
460 ["Array.prototype.concat"]);
461 }
462
443 var arg_count = %_ArgumentsLength(); 463 var arg_count = %_ArgumentsLength();
444 var arrays = new InternalArray(1 + arg_count); 464 var arrays = new InternalArray(1 + arg_count);
445 arrays[0] = this; 465 arrays[0] = this;
446 for (var i = 0; i < arg_count; i++) { 466 for (var i = 0; i < arg_count; i++) {
447 arrays[i + 1] = %_Arguments(i); 467 arrays[i + 1] = %_Arguments(i);
448 } 468 }
449 469
450 return %ArrayConcat(arrays); 470 return %ArrayConcat(arrays);
451 } 471 }
452 472
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (!IS_UNDEFINED(current_j) || high in array) { 509 if (!IS_UNDEFINED(current_j) || high in array) {
490 array[low] = current_j; 510 array[low] = current_j;
491 delete array[high]; 511 delete array[high];
492 } 512 }
493 } 513 }
494 } 514 }
495 } 515 }
496 516
497 517
498 function ArrayReverse() { 518 function ArrayReverse() {
519 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
520 throw MakeTypeError("called_on_null_or_undefined",
521 ["Array.prototype.reverse"]);
522 }
523
499 var j = TO_UINT32(this.length) - 1; 524 var j = TO_UINT32(this.length) - 1;
500 525
501 if (UseSparseVariant(this, j, IS_ARRAY(this))) { 526 if (UseSparseVariant(this, j, IS_ARRAY(this))) {
502 SparseReverse(this, j+1); 527 SparseReverse(this, j+1);
503 return this; 528 return this;
504 } 529 }
505 530
506 for (var i = 0; i < j; i++, j--) { 531 for (var i = 0; i < j; i++, j--) {
507 var current_i = this[i]; 532 var current_i = this[i];
508 if (!IS_UNDEFINED(current_i) || i in this) { 533 if (!IS_UNDEFINED(current_i) || i in this) {
(...skipping 11 matching lines...) Expand all
520 this[i] = current_j; 545 this[i] = current_j;
521 delete this[j]; 546 delete this[j];
522 } 547 }
523 } 548 }
524 } 549 }
525 return this; 550 return this;
526 } 551 }
527 552
528 553
529 function ArrayShift() { 554 function ArrayShift() {
555 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
556 throw MakeTypeError("called_on_null_or_undefined",
557 ["Array.prototype.shift"]);
558 }
559
530 var len = TO_UINT32(this.length); 560 var len = TO_UINT32(this.length);
531 561
532 if (len === 0) { 562 if (len === 0) {
533 this.length = 0; 563 this.length = 0;
534 return; 564 return;
535 } 565 }
536 566
537 var first = this[0]; 567 var first = this[0];
538 568
539 if (IS_ARRAY(this)) 569 if (IS_ARRAY(this))
540 SmartMove(this, 0, 1, len, 0); 570 SmartMove(this, 0, 1, len, 0);
541 else 571 else
542 SimpleMove(this, 0, 1, len, 0); 572 SimpleMove(this, 0, 1, len, 0);
543 573
544 this.length = len - 1; 574 this.length = len - 1;
545 575
546 return first; 576 return first;
547 } 577 }
548 578
549 579
550 function ArrayUnshift(arg1) { // length == 1 580 function ArrayUnshift(arg1) { // length == 1
581 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
582 throw MakeTypeError("called_on_null_or_undefined",
583 ["Array.prototype.unshift"]);
584 }
585
551 var len = TO_UINT32(this.length); 586 var len = TO_UINT32(this.length);
552 var num_arguments = %_ArgumentsLength(); 587 var num_arguments = %_ArgumentsLength();
553 588
554 if (IS_ARRAY(this)) 589 if (IS_ARRAY(this))
555 SmartMove(this, 0, 0, len, num_arguments); 590 SmartMove(this, 0, 0, len, num_arguments);
556 else 591 else
557 SimpleMove(this, 0, 0, len, num_arguments); 592 SimpleMove(this, 0, 0, len, num_arguments);
558 593
559 for (var i = 0; i < num_arguments; i++) { 594 for (var i = 0; i < num_arguments; i++) {
560 this[i] = %_Arguments(i); 595 this[i] = %_Arguments(i);
561 } 596 }
562 597
563 this.length = len + num_arguments; 598 this.length = len + num_arguments;
564 599
565 return len + num_arguments; 600 return len + num_arguments;
566 } 601 }
567 602
568 603
569 function ArraySlice(start, end) { 604 function ArraySlice(start, end) {
605 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
606 throw MakeTypeError("called_on_null_or_undefined",
607 ["Array.prototype.slice"]);
608 }
609
570 var len = TO_UINT32(this.length); 610 var len = TO_UINT32(this.length);
571 var start_i = TO_INTEGER(start); 611 var start_i = TO_INTEGER(start);
572 var end_i = len; 612 var end_i = len;
573 613
574 if (end !== void 0) end_i = TO_INTEGER(end); 614 if (end !== void 0) end_i = TO_INTEGER(end);
575 615
576 if (start_i < 0) { 616 if (start_i < 0) {
577 start_i += len; 617 start_i += len;
578 if (start_i < 0) start_i = 0; 618 if (start_i < 0) start_i = 0;
579 } else { 619 } else {
(...skipping 17 matching lines...) Expand all
597 SimpleSlice(this, start_i, end_i - start_i, len, result); 637 SimpleSlice(this, start_i, end_i - start_i, len, result);
598 } 638 }
599 639
600 result.length = end_i - start_i; 640 result.length = end_i - start_i;
601 641
602 return result; 642 return result;
603 } 643 }
604 644
605 645
606 function ArraySplice(start, delete_count) { 646 function ArraySplice(start, delete_count) {
647 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
648 throw MakeTypeError("called_on_null_or_undefined",
649 ["Array.prototype.splice"]);
650 }
651
607 var num_arguments = %_ArgumentsLength(); 652 var num_arguments = %_ArgumentsLength();
608 653
609 var len = TO_UINT32(this.length); 654 var len = TO_UINT32(this.length);
610 var start_i = TO_INTEGER(start); 655 var start_i = TO_INTEGER(start);
611 656
612 if (start_i < 0) { 657 if (start_i < 0) {
613 start_i += len; 658 start_i += len;
614 if (start_i < 0) start_i = 0; 659 if (start_i < 0) start_i = 0;
615 } else { 660 } else {
616 if (start_i > len) start_i = len; 661 if (start_i > len) start_i = len;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 this[i++] = %_Arguments(arguments_index++); 713 this[i++] = %_Arguments(arguments_index++);
669 } 714 }
670 this.length = len - del_count + num_additional_args; 715 this.length = len - del_count + num_additional_args;
671 716
672 // Return the deleted elements. 717 // Return the deleted elements.
673 return deleted_elements; 718 return deleted_elements;
674 } 719 }
675 720
676 721
677 function ArraySort(comparefn) { 722 function ArraySort(comparefn) {
723 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
724 throw MakeTypeError("called_on_null_or_undefined",
725 ["Array.prototype.sort"]);
726 }
727
678 // In-place QuickSort algorithm. 728 // In-place QuickSort algorithm.
679 // For short (length <= 22) arrays, insertion sort is used for efficiency. 729 // For short (length <= 22) arrays, insertion sort is used for efficiency.
680 730
681 if (!IS_FUNCTION(comparefn)) { 731 if (!IS_FUNCTION(comparefn)) {
682 comparefn = function (x, y) { 732 comparefn = function (x, y) {
683 if (x === y) return 0; 733 if (x === y) return 0;
684 if (%_IsSmi(x) && %_IsSmi(y)) { 734 if (%_IsSmi(x) && %_IsSmi(y)) {
685 return %SmiLexicographicCompare(x, y); 735 return %SmiLexicographicCompare(x, y);
686 } 736 }
687 x = ToString(x); 737 x = ToString(x);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 } 979 }
930 980
931 return this; 981 return this;
932 } 982 }
933 983
934 984
935 // The following functions cannot be made efficient on sparse arrays while 985 // The following functions cannot be made efficient on sparse arrays while
936 // preserving the semantics, since the calls to the receiver function can add 986 // preserving the semantics, since the calls to the receiver function can add
937 // or delete elements from the array. 987 // or delete elements from the array.
938 function ArrayFilter(f, receiver) { 988 function ArrayFilter(f, receiver) {
989 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
990 throw MakeTypeError("called_on_null_or_undefined",
991 ["Array.prototype.filter"]);
992 }
993
939 if (!IS_FUNCTION(f)) { 994 if (!IS_FUNCTION(f)) {
940 throw MakeTypeError('called_non_callable', [ f ]); 995 throw MakeTypeError('called_non_callable', [ f ]);
941 } 996 }
942 // Pull out the length so that modifications to the length in the 997 // Pull out the length so that modifications to the length in the
943 // loop will not affect the looping. 998 // loop will not affect the looping.
944 var length = this.length; 999 var length = this.length;
945 var result = []; 1000 var result = [];
946 var result_length = 0; 1001 var result_length = 0;
947 for (var i = 0; i < length; i++) { 1002 for (var i = 0; i < length; i++) {
948 var current = this[i]; 1003 var current = this[i];
949 if (!IS_UNDEFINED(current) || i in this) { 1004 if (!IS_UNDEFINED(current) || i in this) {
950 if (f.call(receiver, current, i, this)) { 1005 if (f.call(receiver, current, i, this)) {
951 result[result_length++] = current; 1006 result[result_length++] = current;
952 } 1007 }
953 } 1008 }
954 } 1009 }
955 return result; 1010 return result;
956 } 1011 }
957 1012
958 1013
959 function ArrayForEach(f, receiver) { 1014 function ArrayForEach(f, receiver) {
1015 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1016 throw MakeTypeError("called_on_null_or_undefined",
1017 ["Array.prototype.forEach"]);
1018 }
1019
960 if (!IS_FUNCTION(f)) { 1020 if (!IS_FUNCTION(f)) {
961 throw MakeTypeError('called_non_callable', [ f ]); 1021 throw MakeTypeError('called_non_callable', [ f ]);
962 } 1022 }
963 // Pull out the length so that modifications to the length in the 1023 // Pull out the length so that modifications to the length in the
964 // loop will not affect the looping. 1024 // loop will not affect the looping.
965 var length = TO_UINT32(this.length); 1025 var length = TO_UINT32(this.length);
966 for (var i = 0; i < length; i++) { 1026 for (var i = 0; i < length; i++) {
967 var current = this[i]; 1027 var current = this[i];
968 if (!IS_UNDEFINED(current) || i in this) { 1028 if (!IS_UNDEFINED(current) || i in this) {
969 f.call(receiver, current, i, this); 1029 f.call(receiver, current, i, this);
970 } 1030 }
971 } 1031 }
972 } 1032 }
973 1033
974 1034
975 // Executes the function once for each element present in the 1035 // Executes the function once for each element present in the
976 // array until it finds one where callback returns true. 1036 // array until it finds one where callback returns true.
977 function ArraySome(f, receiver) { 1037 function ArraySome(f, receiver) {
1038 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1039 throw MakeTypeError("called_on_null_or_undefined",
1040 ["Array.prototype.some"]);
1041 }
1042
978 if (!IS_FUNCTION(f)) { 1043 if (!IS_FUNCTION(f)) {
979 throw MakeTypeError('called_non_callable', [ f ]); 1044 throw MakeTypeError('called_non_callable', [ f ]);
980 } 1045 }
981 // 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
982 // loop will not affect the looping. 1047 // loop will not affect the looping.
983 var length = TO_UINT32(this.length); 1048 var length = TO_UINT32(this.length);
984 for (var i = 0; i < length; i++) { 1049 for (var i = 0; i < length; i++) {
985 var current = this[i]; 1050 var current = this[i];
986 if (!IS_UNDEFINED(current) || i in this) { 1051 if (!IS_UNDEFINED(current) || i in this) {
987 if (f.call(receiver, current, i, this)) return true; 1052 if (f.call(receiver, current, i, this)) return true;
988 } 1053 }
989 } 1054 }
990 return false; 1055 return false;
991 } 1056 }
992 1057
993 1058
994 function ArrayEvery(f, receiver) { 1059 function ArrayEvery(f, receiver) {
1060 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1061 throw MakeTypeError("called_on_null_or_undefined",
1062 ["Array.prototype.every"]);
1063 }
1064
995 if (!IS_FUNCTION(f)) { 1065 if (!IS_FUNCTION(f)) {
996 throw MakeTypeError('called_non_callable', [ f ]); 1066 throw MakeTypeError('called_non_callable', [ f ]);
997 } 1067 }
998 // Pull out the length so that modifications to the length in the 1068 // Pull out the length so that modifications to the length in the
999 // loop will not affect the looping. 1069 // loop will not affect the looping.
1000 var length = TO_UINT32(this.length); 1070 var length = TO_UINT32(this.length);
1001 for (var i = 0; i < length; i++) { 1071 for (var i = 0; i < length; i++) {
1002 var current = this[i]; 1072 var current = this[i];
1003 if (!IS_UNDEFINED(current) || i in this) { 1073 if (!IS_UNDEFINED(current) || i in this) {
1004 if (!f.call(receiver, current, i, this)) return false; 1074 if (!f.call(receiver, current, i, this)) return false;
1005 } 1075 }
1006 } 1076 }
1007 return true; 1077 return true;
1008 } 1078 }
1009 1079
1010 function ArrayMap(f, receiver) { 1080 function ArrayMap(f, receiver) {
1081 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1082 throw MakeTypeError("called_on_null_or_undefined",
1083 ["Array.prototype.map"]);
1084 }
1085
1011 if (!IS_FUNCTION(f)) { 1086 if (!IS_FUNCTION(f)) {
1012 throw MakeTypeError('called_non_callable', [ f ]); 1087 throw MakeTypeError('called_non_callable', [ f ]);
1013 } 1088 }
1014 // Pull out the length so that modifications to the length in the 1089 // Pull out the length so that modifications to the length in the
1015 // loop will not affect the looping. 1090 // loop will not affect the looping.
1016 var length = TO_UINT32(this.length); 1091 var length = TO_UINT32(this.length);
1017 var result = new $Array(); 1092 var result = new $Array();
1018 var accumulator = new InternalArray(length); 1093 var accumulator = new InternalArray(length);
1019 for (var i = 0; i < length; i++) { 1094 for (var i = 0; i < length; i++) {
1020 var current = this[i]; 1095 var current = this[i];
1021 if (!IS_UNDEFINED(current) || i in this) { 1096 if (!IS_UNDEFINED(current) || i in this) {
1022 accumulator[i] = f.call(receiver, current, i, this); 1097 accumulator[i] = f.call(receiver, current, i, this);
1023 } 1098 }
1024 } 1099 }
1025 %MoveArrayContents(accumulator, result); 1100 %MoveArrayContents(accumulator, result);
1026 return result; 1101 return result;
1027 } 1102 }
1028 1103
1029 1104
1030 function ArrayIndexOf(element, index) { 1105 function ArrayIndexOf(element, index) {
1106 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1107 throw MakeTypeError("called_on_null_or_undefined",
1108 ["Array.prototype.indexOf"]);
1109 }
1110
1031 var length = TO_UINT32(this.length); 1111 var length = TO_UINT32(this.length);
1032 if (length == 0) return -1; 1112 if (length == 0) return -1;
1033 if (IS_UNDEFINED(index)) { 1113 if (IS_UNDEFINED(index)) {
1034 index = 0; 1114 index = 0;
1035 } else { 1115 } else {
1036 index = TO_INTEGER(index); 1116 index = TO_INTEGER(index);
1037 // If index is negative, index from the end of the array. 1117 // If index is negative, index from the end of the array.
1038 if (index < 0) { 1118 if (index < 0) {
1039 index = length + index; 1119 index = length + index;
1040 // If index is still negative, search the entire array. 1120 // If index is still negative, search the entire array.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 for (var i = min; i < max; i++) { 1158 for (var i = min; i < max; i++) {
1079 if (IS_UNDEFINED(this[i]) && i in this) { 1159 if (IS_UNDEFINED(this[i]) && i in this) {
1080 return i; 1160 return i;
1081 } 1161 }
1082 } 1162 }
1083 return -1; 1163 return -1;
1084 } 1164 }
1085 1165
1086 1166
1087 function ArrayLastIndexOf(element, index) { 1167 function ArrayLastIndexOf(element, index) {
1168 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1169 throw MakeTypeError("called_on_null_or_undefined",
1170 ["Array.prototype.lastIndexOf"]);
1171 }
1172
1088 var length = TO_UINT32(this.length); 1173 var length = TO_UINT32(this.length);
1089 if (length == 0) return -1; 1174 if (length == 0) return -1;
1090 if (%_ArgumentsLength() < 2) { 1175 if (%_ArgumentsLength() < 2) {
1091 index = length - 1; 1176 index = length - 1;
1092 } else { 1177 } else {
1093 index = TO_INTEGER(index); 1178 index = TO_INTEGER(index);
1094 // If index is negative, index from end of the array. 1179 // If index is negative, index from end of the array.
1095 if (index < 0) index += length; 1180 if (index < 0) index += length;
1096 // If index is still negative, do not search the array. 1181 // If index is still negative, do not search the array.
1097 if (index < 0) return -1; 1182 if (index < 0) return -1;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 for (var i = max; i >= min; i--) { 1216 for (var i = max; i >= min; i--) {
1132 if (IS_UNDEFINED(this[i]) && i in this) { 1217 if (IS_UNDEFINED(this[i]) && i in this) {
1133 return i; 1218 return i;
1134 } 1219 }
1135 } 1220 }
1136 return -1; 1221 return -1;
1137 } 1222 }
1138 1223
1139 1224
1140 function ArrayReduce(callback, current) { 1225 function ArrayReduce(callback, current) {
1226 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1227 throw MakeTypeError("called_on_null_or_undefined",
1228 ["Array.prototype.reduce"]);
1229 }
1230
1141 if (!IS_FUNCTION(callback)) { 1231 if (!IS_FUNCTION(callback)) {
1142 throw MakeTypeError('called_non_callable', [callback]); 1232 throw MakeTypeError('called_non_callable', [callback]);
1143 } 1233 }
1144 // Pull out the length so that modifications to the length in the 1234 // Pull out the length so that modifications to the length in the
1145 // loop will not affect the looping. 1235 // loop will not affect the looping.
1146 var length = this.length; 1236 var length = this.length;
1147 var i = 0; 1237 var i = 0;
1148 1238
1149 find_initial: if (%_ArgumentsLength() < 2) { 1239 find_initial: if (%_ArgumentsLength() < 2) {
1150 for (; i < length; i++) { 1240 for (; i < length; i++) {
1151 current = this[i]; 1241 current = this[i];
1152 if (!IS_UNDEFINED(current) || i in this) { 1242 if (!IS_UNDEFINED(current) || i in this) {
1153 i++; 1243 i++;
1154 break find_initial; 1244 break find_initial;
1155 } 1245 }
1156 } 1246 }
1157 throw MakeTypeError('reduce_no_initial', []); 1247 throw MakeTypeError('reduce_no_initial', []);
1158 } 1248 }
1159 1249
1160 for (; i < length; i++) { 1250 for (; i < length; i++) {
1161 var element = this[i]; 1251 var element = this[i];
1162 if (!IS_UNDEFINED(element) || i in this) { 1252 if (!IS_UNDEFINED(element) || i in this) {
1163 current = callback.call(null, current, element, i, this); 1253 current = callback.call(null, current, element, i, this);
1164 } 1254 }
1165 } 1255 }
1166 return current; 1256 return current;
1167 } 1257 }
1168 1258
1169 function ArrayReduceRight(callback, current) { 1259 function ArrayReduceRight(callback, current) {
1260 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1261 throw MakeTypeError("called_on_null_or_undefined",
1262 ["Array.prototype.reduceRight"]);
1263 }
1264
1170 if (!IS_FUNCTION(callback)) { 1265 if (!IS_FUNCTION(callback)) {
1171 throw MakeTypeError('called_non_callable', [callback]); 1266 throw MakeTypeError('called_non_callable', [callback]);
1172 } 1267 }
1173 var i = this.length - 1; 1268 var i = this.length - 1;
1174 1269
1175 find_initial: if (%_ArgumentsLength() < 2) { 1270 find_initial: if (%_ArgumentsLength() < 2) {
1176 for (; i >= 0; i--) { 1271 for (; i >= 0; i--) {
1177 current = this[i]; 1272 current = this[i];
1178 if (!IS_UNDEFINED(current) || i in this) { 1273 if (!IS_UNDEFINED(current) || i in this) {
1179 i--; 1274 i--;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 InternalArray.prototype.join = getFunction("join", ArrayJoin); 1357 InternalArray.prototype.join = getFunction("join", ArrayJoin);
1263 InternalArray.prototype.pop = getFunction("pop", ArrayPop); 1358 InternalArray.prototype.pop = getFunction("pop", ArrayPop);
1264 InternalArray.prototype.push = getFunction("push", ArrayPush); 1359 InternalArray.prototype.push = getFunction("push", ArrayPush);
1265 InternalArray.prototype.toString = function() { 1360 InternalArray.prototype.toString = function() {
1266 return "Internal Array, length " + this.length; 1361 return "Internal Array, length " + this.length;
1267 }; 1362 };
1268 } 1363 }
1269 1364
1270 1365
1271 SetupArray(); 1366 SetupArray();
OLDNEW
« no previous file with comments | « src/arm/builtins-arm.cc ('k') | src/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698