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

Side by Side Diff: src/js/array.js

Issue 1667453002: Remove flags for ES2015 features shipped in M48 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Mark failing ignition/arm64 test as flaky Created 4 years, 10 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
« no previous file with comments | « src/flag-definitions.h ('k') | src/js/macros.py » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var AddIndexedProperty; 14 var AddIndexedProperty;
15 var FLAG_harmony_tolength;
16 var FLAG_harmony_species; 15 var FLAG_harmony_species;
17 var GetIterator; 16 var GetIterator;
18 var GetMethod; 17 var GetMethod;
19 var GlobalArray = global.Array; 18 var GlobalArray = global.Array;
20 var InternalArray = utils.InternalArray; 19 var InternalArray = utils.InternalArray;
21 var InternalPackedArray = utils.InternalPackedArray; 20 var InternalPackedArray = utils.InternalPackedArray;
22 var MakeTypeError; 21 var MakeTypeError;
23 var MaxSimple; 22 var MaxSimple;
24 var MinSimple; 23 var MinSimple;
25 var ObjectDefineProperty; 24 var ObjectDefineProperty;
(...skipping 15 matching lines...) Expand all
41 MinSimple = from.MinSimple; 40 MinSimple = from.MinSimple;
42 ObjectDefineProperty = from.ObjectDefineProperty; 41 ObjectDefineProperty = from.ObjectDefineProperty;
43 ObjectHasOwnProperty = from.ObjectHasOwnProperty; 42 ObjectHasOwnProperty = from.ObjectHasOwnProperty;
44 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice; 43 ObserveBeginPerformSplice = from.ObserveBeginPerformSplice;
45 ObserveEndPerformSplice = from.ObserveEndPerformSplice; 44 ObserveEndPerformSplice = from.ObserveEndPerformSplice;
46 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord; 45 ObserveEnqueueSpliceRecord = from.ObserveEnqueueSpliceRecord;
47 SameValueZero = from.SameValueZero; 46 SameValueZero = from.SameValueZero;
48 }); 47 });
49 48
50 utils.ImportFromExperimental(function(from) { 49 utils.ImportFromExperimental(function(from) {
51 FLAG_harmony_tolength = from.FLAG_harmony_tolength;
52 FLAG_harmony_species = from.FLAG_harmony_species; 50 FLAG_harmony_species = from.FLAG_harmony_species;
53 }); 51 });
54 52
55 // ------------------------------------------------------------------- 53 // -------------------------------------------------------------------
56 54
57 55
58 function ArraySpeciesCreate(array, length) { 56 function ArraySpeciesCreate(array, length) {
59 var constructor; 57 var constructor;
60 if (FLAG_harmony_species) { 58 if (FLAG_harmony_species) {
61 constructor = %ArraySpeciesConstructor(array); 59 constructor = %ArraySpeciesConstructor(array);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 func = array.join; 422 func = array.join;
425 } 423 }
426 if (!IS_CALLABLE(func)) { 424 if (!IS_CALLABLE(func)) {
427 return %_Call(ObjectToString, array); 425 return %_Call(ObjectToString, array);
428 } 426 }
429 return %_Call(func, array); 427 return %_Call(func, array);
430 } 428 }
431 429
432 430
433 function InnerArrayToLocaleString(array, length) { 431 function InnerArrayToLocaleString(array, length) {
434 var len = TO_LENGTH_OR_UINT32(length); 432 var len = TO_LENGTH(length);
435 if (len === 0) return ""; 433 if (len === 0) return "";
436 return Join(array, len, ',', ConvertToLocaleString); 434 return Join(array, len, ',', ConvertToLocaleString);
437 } 435 }
438 436
439 437
440 function ArrayToLocaleString() { 438 function ArrayToLocaleString() {
441 var array = TO_OBJECT(this); 439 var array = TO_OBJECT(this);
442 var arrayLen = array.length; 440 var arrayLen = array.length;
443 return InnerArrayToLocaleString(array, arrayLen); 441 return InnerArrayToLocaleString(array, arrayLen);
444 } 442 }
(...skipping 17 matching lines...) Expand all
462 } 460 }
463 461
464 return Join(array, length, separator, ConvertToString); 462 return Join(array, length, separator, ConvertToString);
465 } 463 }
466 464
467 465
468 function ArrayJoin(separator) { 466 function ArrayJoin(separator) {
469 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join"); 467 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join");
470 468
471 var array = TO_OBJECT(this); 469 var array = TO_OBJECT(this);
472 var length = TO_LENGTH_OR_UINT32(array.length); 470 var length = TO_LENGTH(array.length);
473 471
474 return InnerArrayJoin(separator, array, length); 472 return InnerArrayJoin(separator, array, length);
475 } 473 }
476 474
477 475
478 function ObservedArrayPop(n) { 476 function ObservedArrayPop(n) {
479 n--; 477 n--;
480 var value = this[n]; 478 var value = this[n];
481 479
482 try { 480 try {
483 ObserveBeginPerformSplice(this); 481 ObserveBeginPerformSplice(this);
484 delete this[n]; 482 delete this[n];
485 this.length = n; 483 this.length = n;
486 } finally { 484 } finally {
487 ObserveEndPerformSplice(this); 485 ObserveEndPerformSplice(this);
488 ObserveEnqueueSpliceRecord(this, n, [value], 0); 486 ObserveEnqueueSpliceRecord(this, n, [value], 0);
489 } 487 }
490 488
491 return value; 489 return value;
492 } 490 }
493 491
494 492
495 // Removes the last element from the array and returns it. See 493 // Removes the last element from the array and returns it. See
496 // ECMA-262, section 15.4.4.6. 494 // ECMA-262, section 15.4.4.6.
497 function ArrayPop() { 495 function ArrayPop() {
498 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); 496 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
499 497
500 var array = TO_OBJECT(this); 498 var array = TO_OBJECT(this);
501 var n = TO_LENGTH_OR_UINT32(array.length); 499 var n = TO_LENGTH(array.length);
502 if (n == 0) { 500 if (n == 0) {
503 array.length = n; 501 array.length = n;
504 return; 502 return;
505 } 503 }
506 504
507 if (%IsObserved(array)) 505 if (%IsObserved(array))
508 return ObservedArrayPop.call(array, n); 506 return ObservedArrayPop.call(array, n);
509 507
510 n--; 508 n--;
511 var value = array[n]; 509 var value = array[n];
512 %DeleteProperty_Strict(array, n); 510 %DeleteProperty_Strict(array, n);
513 array.length = n; 511 array.length = n;
514 return value; 512 return value;
515 } 513 }
516 514
517 515
518 function ObservedArrayPush() { 516 function ObservedArrayPush() {
519 var n = TO_LENGTH_OR_UINT32(this.length); 517 var n = TO_LENGTH(this.length);
520 var m = %_ArgumentsLength(); 518 var m = %_ArgumentsLength();
521 519
522 try { 520 try {
523 ObserveBeginPerformSplice(this); 521 ObserveBeginPerformSplice(this);
524 for (var i = 0; i < m; i++) { 522 for (var i = 0; i < m; i++) {
525 this[i+n] = %_Arguments(i); 523 this[i+n] = %_Arguments(i);
526 } 524 }
527 var new_length = n + m; 525 var new_length = n + m;
528 this.length = new_length; 526 this.length = new_length;
529 } finally { 527 } finally {
530 ObserveEndPerformSplice(this); 528 ObserveEndPerformSplice(this);
531 ObserveEnqueueSpliceRecord(this, n, [], m); 529 ObserveEnqueueSpliceRecord(this, n, [], m);
532 } 530 }
533 531
534 return new_length; 532 return new_length;
535 } 533 }
536 534
537 535
538 // Appends the arguments to the end of the array and returns the new 536 // Appends the arguments to the end of the array and returns the new
539 // length of the array. See ECMA-262, section 15.4.4.7. 537 // length of the array. See ECMA-262, section 15.4.4.7.
540 function ArrayPush() { 538 function ArrayPush() {
541 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); 539 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push");
542 540
543 if (%IsObserved(this)) 541 if (%IsObserved(this))
544 return ObservedArrayPush.apply(this, arguments); 542 return ObservedArrayPush.apply(this, arguments);
545 543
546 var array = TO_OBJECT(this); 544 var array = TO_OBJECT(this);
547 var n = TO_LENGTH_OR_UINT32(array.length); 545 var n = TO_LENGTH(array.length);
548 var m = %_ArgumentsLength(); 546 var m = %_ArgumentsLength();
549 547
550 // It appears that there is no enforced, absolute limit on the number of 548 // It appears that there is no enforced, absolute limit on the number of
551 // arguments, but it would surely blow the stack to use 2**30 or more. 549 // arguments, but it would surely blow the stack to use 2**30 or more.
552 // To avoid integer overflow, do the comparison to the max safe integer 550 // To avoid integer overflow, do the comparison to the max safe integer
553 // after subtracting 2**30 from both sides. (2**31 would seem like a 551 // after subtracting 2**30 from both sides. (2**31 would seem like a
554 // natural value, but it is negative in JS, and 2**32 is 1.) 552 // natural value, but it is negative in JS, and 2**32 is 1.)
555 if (m > (1 << 30) || (n - (1 << 30)) + m > kMaxSafeInteger - (1 << 30)) { 553 if (m > (1 << 30) || (n - (1 << 30)) + m > kMaxSafeInteger - (1 << 30)) {
556 throw MakeTypeError(kPushPastSafeLength, m, n); 554 throw MakeTypeError(kPushPastSafeLength, m, n);
557 } 555 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 } 641 }
644 } 642 }
645 return array; 643 return array;
646 } 644 }
647 645
648 646
649 function ArrayReverse() { 647 function ArrayReverse() {
650 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse"); 648 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
651 649
652 var array = TO_OBJECT(this); 650 var array = TO_OBJECT(this);
653 var len = TO_LENGTH_OR_UINT32(array.length); 651 var len = TO_LENGTH(array.length);
654 var isArray = IS_ARRAY(array); 652 var isArray = IS_ARRAY(array);
655 653
656 if (UseSparseVariant(array, len, isArray, len)) { 654 if (UseSparseVariant(array, len, isArray, len)) {
657 %NormalizeElements(array); 655 %NormalizeElements(array);
658 SparseReverse(array, len); 656 SparseReverse(array, len);
659 return array; 657 return array;
660 } else if (isArray && %_HasFastPackedElements(array)) { 658 } else if (isArray && %_HasFastPackedElements(array)) {
661 return PackedArrayReverse(array, len); 659 return PackedArrayReverse(array, len);
662 } else { 660 } else {
663 return GenericArrayReverse(array, len); 661 return GenericArrayReverse(array, len);
(...skipping 14 matching lines...) Expand all
678 } 676 }
679 677
680 return first; 678 return first;
681 } 679 }
682 680
683 681
684 function ArrayShift() { 682 function ArrayShift() {
685 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); 683 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
686 684
687 var array = TO_OBJECT(this); 685 var array = TO_OBJECT(this);
688 var len = TO_LENGTH_OR_UINT32(array.length); 686 var len = TO_LENGTH(array.length);
689 687
690 if (len === 0) { 688 if (len === 0) {
691 array.length = 0; 689 array.length = 0;
692 return; 690 return;
693 } 691 }
694 692
695 if (%object_is_sealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed); 693 if (%object_is_sealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed);
696 694
697 if (%IsObserved(array)) 695 if (%IsObserved(array))
698 return ObservedArrayShift.call(array, len); 696 return ObservedArrayShift.call(array, len);
699 697
700 var first = array[0]; 698 var first = array[0];
701 699
702 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) { 700 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
703 SparseMove(array, 0, 1, len, 0); 701 SparseMove(array, 0, 1, len, 0);
704 } else { 702 } else {
705 SimpleMove(array, 0, 1, len, 0); 703 SimpleMove(array, 0, 1, len, 0);
706 } 704 }
707 705
708 array.length = len - 1; 706 array.length = len - 1;
709 707
710 return first; 708 return first;
711 } 709 }
712 710
713 711
714 function ObservedArrayUnshift() { 712 function ObservedArrayUnshift() {
715 var len = TO_LENGTH_OR_UINT32(this.length); 713 var len = TO_LENGTH(this.length);
716 var num_arguments = %_ArgumentsLength(); 714 var num_arguments = %_ArgumentsLength();
717 715
718 try { 716 try {
719 ObserveBeginPerformSplice(this); 717 ObserveBeginPerformSplice(this);
720 SimpleMove(this, 0, 0, len, num_arguments); 718 SimpleMove(this, 0, 0, len, num_arguments);
721 for (var i = 0; i < num_arguments; i++) { 719 for (var i = 0; i < num_arguments; i++) {
722 this[i] = %_Arguments(i); 720 this[i] = %_Arguments(i);
723 } 721 }
724 var new_length = len + num_arguments; 722 var new_length = len + num_arguments;
725 this.length = new_length; 723 this.length = new_length;
726 } finally { 724 } finally {
727 ObserveEndPerformSplice(this); 725 ObserveEndPerformSplice(this);
728 ObserveEnqueueSpliceRecord(this, 0, [], num_arguments); 726 ObserveEnqueueSpliceRecord(this, 0, [], num_arguments);
729 } 727 }
730 728
731 return new_length; 729 return new_length;
732 } 730 }
733 731
734 732
735 function ArrayUnshift(arg1) { // length == 1 733 function ArrayUnshift(arg1) { // length == 1
736 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); 734 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
737 735
738 if (%IsObserved(this)) 736 if (%IsObserved(this))
739 return ObservedArrayUnshift.apply(this, arguments); 737 return ObservedArrayUnshift.apply(this, arguments);
740 738
741 var array = TO_OBJECT(this); 739 var array = TO_OBJECT(this);
742 var len = TO_LENGTH_OR_UINT32(array.length); 740 var len = TO_LENGTH(array.length);
743 var num_arguments = %_ArgumentsLength(); 741 var num_arguments = %_ArgumentsLength();
744 742
745 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) && 743 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) &&
746 !%object_is_sealed(array)) { 744 !%object_is_sealed(array)) {
747 SparseMove(array, 0, 0, len, num_arguments); 745 SparseMove(array, 0, 0, len, num_arguments);
748 } else { 746 } else {
749 SimpleMove(array, 0, 0, len, num_arguments); 747 SimpleMove(array, 0, 0, len, num_arguments);
750 } 748 }
751 749
752 for (var i = 0; i < num_arguments; i++) { 750 for (var i = 0; i < num_arguments; i++) {
753 array[i] = %_Arguments(i); 751 array[i] = %_Arguments(i);
754 } 752 }
755 753
756 var new_length = len + num_arguments; 754 var new_length = len + num_arguments;
757 array.length = new_length; 755 array.length = new_length;
758 return new_length; 756 return new_length;
759 } 757 }
760 758
761 759
762 function ArraySlice(start, end) { 760 function ArraySlice(start, end) {
763 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice"); 761 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice");
764 762
765 var array = TO_OBJECT(this); 763 var array = TO_OBJECT(this);
766 var len = TO_LENGTH_OR_UINT32(array.length); 764 var len = TO_LENGTH(array.length);
767 var start_i = TO_INTEGER(start); 765 var start_i = TO_INTEGER(start);
768 var end_i = len; 766 var end_i = len;
769 767
770 if (!IS_UNDEFINED(end)) end_i = TO_INTEGER(end); 768 if (!IS_UNDEFINED(end)) end_i = TO_INTEGER(end);
771 769
772 if (start_i < 0) { 770 if (start_i < 0) {
773 start_i += len; 771 start_i += len;
774 if (start_i < 0) start_i = 0; 772 if (start_i < 0) start_i = 0;
775 } else { 773 } else {
776 if (start_i > len) start_i = len; 774 if (start_i > len) start_i = len;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 825
828 if (del_count > len - start_i) 826 if (del_count > len - start_i)
829 return len - start_i; 827 return len - start_i;
830 828
831 return del_count; 829 return del_count;
832 } 830 }
833 831
834 832
835 function ObservedArraySplice(start, delete_count) { 833 function ObservedArraySplice(start, delete_count) {
836 var num_arguments = %_ArgumentsLength(); 834 var num_arguments = %_ArgumentsLength();
837 var len = TO_LENGTH_OR_UINT32(this.length); 835 var len = TO_LENGTH(this.length);
838 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 836 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
839 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 837 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
840 start_i); 838 start_i);
841 var deleted_elements = []; 839 var deleted_elements = [];
842 deleted_elements.length = del_count; 840 deleted_elements.length = del_count;
843 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 841 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
844 842
845 try { 843 try {
846 ObserveBeginPerformSplice(this); 844 ObserveBeginPerformSplice(this);
847 845
(...skipping 26 matching lines...) Expand all
874 872
875 873
876 function ArraySplice(start, delete_count) { 874 function ArraySplice(start, delete_count) {
877 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice"); 875 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.splice");
878 876
879 if (%IsObserved(this)) 877 if (%IsObserved(this))
880 return ObservedArraySplice.apply(this, arguments); 878 return ObservedArraySplice.apply(this, arguments);
881 879
882 var num_arguments = %_ArgumentsLength(); 880 var num_arguments = %_ArgumentsLength();
883 var array = TO_OBJECT(this); 881 var array = TO_OBJECT(this);
884 var len = TO_LENGTH_OR_UINT32(array.length); 882 var len = TO_LENGTH(array.length);
885 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 883 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
886 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 884 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
887 start_i); 885 start_i);
888 var deleted_elements = ArraySpeciesCreate(array, del_count); 886 var deleted_elements = ArraySpeciesCreate(array, del_count);
889 deleted_elements.length = del_count; 887 deleted_elements.length = del_count;
890 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 888 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
891 889
892 if (del_count != num_elements_to_add && %object_is_sealed(array)) { 890 if (del_count != num_elements_to_add && %object_is_sealed(array)) {
893 throw MakeTypeError(kArrayFunctionsOnSealed); 891 throw MakeTypeError(kArrayFunctionsOnSealed);
894 } else if (del_count > 0 && %object_is_frozen(array)) { 892 } else if (del_count > 0 && %object_is_frozen(array)) {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 } 1208 }
1211 1209
1212 return array; 1210 return array;
1213 } 1211 }
1214 1212
1215 1213
1216 function ArraySort(comparefn) { 1214 function ArraySort(comparefn) {
1217 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.sort"); 1215 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.sort");
1218 1216
1219 var array = TO_OBJECT(this); 1217 var array = TO_OBJECT(this);
1220 var length = TO_LENGTH_OR_UINT32(array.length); 1218 var length = TO_LENGTH(array.length);
1221 return InnerArraySort(array, length, comparefn); 1219 return InnerArraySort(array, length, comparefn);
1222 } 1220 }
1223 1221
1224 1222
1225 // The following functions cannot be made efficient on sparse arrays while 1223 // The following functions cannot be made efficient on sparse arrays while
1226 // preserving the semantics, since the calls to the receiver function can add 1224 // preserving the semantics, since the calls to the receiver function can add
1227 // or delete elements from the array. 1225 // or delete elements from the array.
1228 function InnerArrayFilter(f, receiver, array, length, result) { 1226 function InnerArrayFilter(f, receiver, array, length, result) {
1229 var result_length = 0; 1227 var result_length = 0;
1230 var is_array = IS_ARRAY(array); 1228 var is_array = IS_ARRAY(array);
(...skipping 10 matching lines...) Expand all
1241 } 1239 }
1242 1240
1243 1241
1244 1242
1245 function ArrayFilter(f, receiver) { 1243 function ArrayFilter(f, receiver) {
1246 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter"); 1244 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.filter");
1247 1245
1248 // Pull out the length so that modifications to the length in the 1246 // Pull out the length so that modifications to the length in the
1249 // loop will not affect the looping and side effects are visible. 1247 // loop will not affect the looping and side effects are visible.
1250 var array = TO_OBJECT(this); 1248 var array = TO_OBJECT(this);
1251 var length = TO_LENGTH_OR_UINT32(array.length); 1249 var length = TO_LENGTH(array.length);
1252 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 1250 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
1253 var result = ArraySpeciesCreate(array, 0); 1251 var result = ArraySpeciesCreate(array, 0);
1254 return InnerArrayFilter(f, receiver, array, length, result); 1252 return InnerArrayFilter(f, receiver, array, length, result);
1255 } 1253 }
1256 1254
1257 1255
1258 function InnerArrayForEach(f, receiver, array, length) { 1256 function InnerArrayForEach(f, receiver, array, length) {
1259 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 1257 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
1260 1258
1261 var is_array = IS_ARRAY(array); 1259 var is_array = IS_ARRAY(array);
1262 for (var i = 0; i < length; i++) { 1260 for (var i = 0; i < length; i++) {
1263 if (HAS_INDEX(array, i, is_array)) { 1261 if (HAS_INDEX(array, i, is_array)) {
1264 var element = array[i]; 1262 var element = array[i];
1265 %_Call(f, receiver, element, i, array); 1263 %_Call(f, receiver, element, i, array);
1266 } 1264 }
1267 } 1265 }
1268 } 1266 }
1269 1267
1270 1268
1271 function ArrayForEach(f, receiver) { 1269 function ArrayForEach(f, receiver) {
1272 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach"); 1270 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
1273 1271
1274 // Pull out the length so that modifications to the length in the 1272 // Pull out the length so that modifications to the length in the
1275 // loop will not affect the looping and side effects are visible. 1273 // loop will not affect the looping and side effects are visible.
1276 var array = TO_OBJECT(this); 1274 var array = TO_OBJECT(this);
1277 var length = TO_LENGTH_OR_UINT32(array.length); 1275 var length = TO_LENGTH(array.length);
1278 InnerArrayForEach(f, receiver, array, length); 1276 InnerArrayForEach(f, receiver, array, length);
1279 } 1277 }
1280 1278
1281 1279
1282 function InnerArraySome(f, receiver, array, length) { 1280 function InnerArraySome(f, receiver, array, length) {
1283 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 1281 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
1284 1282
1285 var is_array = IS_ARRAY(array); 1283 var is_array = IS_ARRAY(array);
1286 for (var i = 0; i < length; i++) { 1284 for (var i = 0; i < length; i++) {
1287 if (HAS_INDEX(array, i, is_array)) { 1285 if (HAS_INDEX(array, i, is_array)) {
1288 var element = array[i]; 1286 var element = array[i];
1289 if (%_Call(f, receiver, element, i, array)) return true; 1287 if (%_Call(f, receiver, element, i, array)) return true;
1290 } 1288 }
1291 } 1289 }
1292 return false; 1290 return false;
1293 } 1291 }
1294 1292
1295 1293
1296 // Executes the function once for each element present in the 1294 // Executes the function once for each element present in the
1297 // array until it finds one where callback returns true. 1295 // array until it finds one where callback returns true.
1298 function ArraySome(f, receiver) { 1296 function ArraySome(f, receiver) {
1299 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some"); 1297 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.some");
1300 1298
1301 // Pull out the length so that modifications to the length in the 1299 // Pull out the length so that modifications to the length in the
1302 // loop will not affect the looping and side effects are visible. 1300 // loop will not affect the looping and side effects are visible.
1303 var array = TO_OBJECT(this); 1301 var array = TO_OBJECT(this);
1304 var length = TO_LENGTH_OR_UINT32(array.length); 1302 var length = TO_LENGTH(array.length);
1305 return InnerArraySome(f, receiver, array, length); 1303 return InnerArraySome(f, receiver, array, length);
1306 } 1304 }
1307 1305
1308 1306
1309 function InnerArrayEvery(f, receiver, array, length) { 1307 function InnerArrayEvery(f, receiver, array, length) {
1310 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 1308 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
1311 1309
1312 var is_array = IS_ARRAY(array); 1310 var is_array = IS_ARRAY(array);
1313 for (var i = 0; i < length; i++) { 1311 for (var i = 0; i < length; i++) {
1314 if (HAS_INDEX(array, i, is_array)) { 1312 if (HAS_INDEX(array, i, is_array)) {
1315 var element = array[i]; 1313 var element = array[i];
1316 if (!%_Call(f, receiver, element, i, array)) return false; 1314 if (!%_Call(f, receiver, element, i, array)) return false;
1317 } 1315 }
1318 } 1316 }
1319 return true; 1317 return true;
1320 } 1318 }
1321 1319
1322 function ArrayEvery(f, receiver) { 1320 function ArrayEvery(f, receiver) {
1323 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every"); 1321 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
1324 1322
1325 // Pull out the length so that modifications to the length in the 1323 // Pull out the length so that modifications to the length in the
1326 // loop will not affect the looping and side effects are visible. 1324 // loop will not affect the looping and side effects are visible.
1327 var array = TO_OBJECT(this); 1325 var array = TO_OBJECT(this);
1328 var length = TO_LENGTH_OR_UINT32(array.length); 1326 var length = TO_LENGTH(array.length);
1329 return InnerArrayEvery(f, receiver, array, length); 1327 return InnerArrayEvery(f, receiver, array, length);
1330 } 1328 }
1331 1329
1332 1330
1333 function ArrayMap(f, receiver) { 1331 function ArrayMap(f, receiver) {
1334 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map"); 1332 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
1335 1333
1336 // Pull out the length so that modifications to the length in the 1334 // Pull out the length so that modifications to the length in the
1337 // loop will not affect the looping and side effects are visible. 1335 // loop will not affect the looping and side effects are visible.
1338 var array = TO_OBJECT(this); 1336 var array = TO_OBJECT(this);
1339 var length = TO_LENGTH_OR_UINT32(array.length); 1337 var length = TO_LENGTH(array.length);
1340 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f); 1338 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
1341 var result = ArraySpeciesCreate(array, length); 1339 var result = ArraySpeciesCreate(array, length);
1342 var is_array = IS_ARRAY(array); 1340 var is_array = IS_ARRAY(array);
1343 for (var i = 0; i < length; i++) { 1341 for (var i = 0; i < length; i++) {
1344 if (HAS_INDEX(array, i, is_array)) { 1342 if (HAS_INDEX(array, i, is_array)) {
1345 var element = array[i]; 1343 var element = array[i];
1346 DefineIndexedProperty(result, i, %_Call(f, receiver, element, i, array)); 1344 DefineIndexedProperty(result, i, %_Call(f, receiver, element, i, array));
1347 } 1345 }
1348 } 1346 }
1349 return result; 1347 return result;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 return i; 1402 return i;
1405 } 1403 }
1406 } 1404 }
1407 return -1; 1405 return -1;
1408 } 1406 }
1409 1407
1410 1408
1411 function ArrayIndexOf(element, index) { 1409 function ArrayIndexOf(element, index) {
1412 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf"); 1410 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.indexOf");
1413 1411
1414 var length = TO_LENGTH_OR_UINT32(this.length); 1412 var length = TO_LENGTH(this.length);
1415 return InnerArrayIndexOf(this, element, index, length); 1413 return InnerArrayIndexOf(this, element, index, length);
1416 } 1414 }
1417 1415
1418 1416
1419 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) { 1417 function InnerArrayLastIndexOf(array, element, index, length, argumentsLength) {
1420 if (length == 0) return -1; 1418 if (length == 0) return -1;
1421 if (argumentsLength < 2) { 1419 if (argumentsLength < 2) {
1422 index = length - 1; 1420 index = length - 1;
1423 } else { 1421 } else {
1424 index = TO_INTEGER(index); 1422 index = TO_INTEGER(index);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 return i; 1460 return i;
1463 } 1461 }
1464 } 1462 }
1465 return -1; 1463 return -1;
1466 } 1464 }
1467 1465
1468 1466
1469 function ArrayLastIndexOf(element, index) { 1467 function ArrayLastIndexOf(element, index) {
1470 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf"); 1468 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.lastIndexOf");
1471 1469
1472 var length = TO_LENGTH_OR_UINT32(this.length); 1470 var length = TO_LENGTH(this.length);
1473 return InnerArrayLastIndexOf(this, element, index, length, 1471 return InnerArrayLastIndexOf(this, element, index, length,
1474 %_ArgumentsLength()); 1472 %_ArgumentsLength());
1475 } 1473 }
1476 1474
1477 1475
1478 function InnerArrayReduce(callback, current, array, length, argumentsLength) { 1476 function InnerArrayReduce(callback, current, array, length, argumentsLength) {
1479 if (!IS_CALLABLE(callback)) { 1477 if (!IS_CALLABLE(callback)) {
1480 throw MakeTypeError(kCalledNonCallable, callback); 1478 throw MakeTypeError(kCalledNonCallable, callback);
1481 } 1479 }
1482 1480
(...skipping 18 matching lines...) Expand all
1501 return current; 1499 return current;
1502 } 1500 }
1503 1501
1504 1502
1505 function ArrayReduce(callback, current) { 1503 function ArrayReduce(callback, current) {
1506 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce"); 1504 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduce");
1507 1505
1508 // Pull out the length so that modifications to the length in the 1506 // Pull out the length so that modifications to the length in the
1509 // loop will not affect the looping and side effects are visible. 1507 // loop will not affect the looping and side effects are visible.
1510 var array = TO_OBJECT(this); 1508 var array = TO_OBJECT(this);
1511 var length = TO_LENGTH_OR_UINT32(array.length); 1509 var length = TO_LENGTH(array.length);
1512 return InnerArrayReduce(callback, current, array, length, 1510 return InnerArrayReduce(callback, current, array, length,
1513 %_ArgumentsLength()); 1511 %_ArgumentsLength());
1514 } 1512 }
1515 1513
1516 1514
1517 function InnerArrayReduceRight(callback, current, array, length, 1515 function InnerArrayReduceRight(callback, current, array, length,
1518 argumentsLength) { 1516 argumentsLength) {
1519 if (!IS_CALLABLE(callback)) { 1517 if (!IS_CALLABLE(callback)) {
1520 throw MakeTypeError(kCalledNonCallable, callback); 1518 throw MakeTypeError(kCalledNonCallable, callback);
1521 } 1519 }
(...skipping 19 matching lines...) Expand all
1541 return current; 1539 return current;
1542 } 1540 }
1543 1541
1544 1542
1545 function ArrayReduceRight(callback, current) { 1543 function ArrayReduceRight(callback, current) {
1546 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight"); 1544 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reduceRight");
1547 1545
1548 // Pull out the length so that side effects are visible before the 1546 // Pull out the length so that side effects are visible before the
1549 // callback function is checked. 1547 // callback function is checked.
1550 var array = TO_OBJECT(this); 1548 var array = TO_OBJECT(this);
1551 var length = TO_LENGTH_OR_UINT32(array.length); 1549 var length = TO_LENGTH(array.length);
1552 return InnerArrayReduceRight(callback, current, array, length, 1550 return InnerArrayReduceRight(callback, current, array, length,
1553 %_ArgumentsLength()); 1551 %_ArgumentsLength());
1554 } 1552 }
1555 1553
1556 1554
1557 function InnerArrayCopyWithin(target, start, end, array, length) { 1555 function InnerArrayCopyWithin(target, start, end, array, length) {
1558 target = TO_INTEGER(target); 1556 target = TO_INTEGER(target);
1559 var to; 1557 var to;
1560 if (target < 0) { 1558 if (target < 0) {
1561 to = MaxSimple(length + target, 0); 1559 to = MaxSimple(length + target, 0);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 array[i] = value; 1692 array[i] = value;
1695 return array; 1693 return array;
1696 } 1694 }
1697 1695
1698 1696
1699 // ES6, draft 04-05-14, section 22.1.3.6 1697 // ES6, draft 04-05-14, section 22.1.3.6
1700 function ArrayFill(value, start, end) { 1698 function ArrayFill(value, start, end) {
1701 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); 1699 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
1702 1700
1703 var array = TO_OBJECT(this); 1701 var array = TO_OBJECT(this);
1704 var length = TO_LENGTH_OR_UINT32(array.length); 1702 var length = TO_LENGTH(array.length);
1705 1703
1706 return InnerArrayFill(value, start, end, array, length); 1704 return InnerArrayFill(value, start, end, array, length);
1707 } 1705 }
1708 1706
1709 1707
1710 function InnerArrayIncludes(searchElement, fromIndex, array, length) { 1708 function InnerArrayIncludes(searchElement, fromIndex, array, length) {
1711 if (length === 0) { 1709 if (length === 0) {
1712 return false; 1710 return false;
1713 } 1711 }
1714 1712
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 %InstallToContext([ 1972 %InstallToContext([
1975 "array_pop", ArrayPop, 1973 "array_pop", ArrayPop,
1976 "array_push", ArrayPush, 1974 "array_push", ArrayPush,
1977 "array_shift", ArrayShift, 1975 "array_shift", ArrayShift,
1978 "array_splice", ArraySplice, 1976 "array_splice", ArraySplice,
1979 "array_slice", ArraySlice, 1977 "array_slice", ArraySlice,
1980 "array_unshift", ArrayUnshift, 1978 "array_unshift", ArrayUnshift,
1981 ]); 1979 ]);
1982 1980
1983 }); 1981 });
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | src/js/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698