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

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

Issue 2776433003: [builtins] Implement Array.prototype.reduceRight in the CSA (Closed)
Patch Set: Add back accidental removals Created 3 years, 9 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/js/array.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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) { 5 (function(global, utils) {
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 // array.js has to come before typedarray.js for this to work 14 // array.js has to come before typedarray.js for this to work
15 var ArrayToString = utils.ImportNow("ArrayToString"); 15 var ArrayToString = utils.ImportNow("ArrayToString");
16 var ArrayValues; 16 var ArrayValues;
17 var GetIterator; 17 var GetIterator;
18 var GetMethod; 18 var GetMethod;
19 var GlobalArray = global.Array; 19 var GlobalArray = global.Array;
20 var GlobalArrayBuffer = global.ArrayBuffer; 20 var GlobalArrayBuffer = global.ArrayBuffer;
21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype; 21 var GlobalArrayBufferPrototype = GlobalArrayBuffer.prototype;
22 var GlobalObject = global.Object; 22 var GlobalObject = global.Object;
23 var InnerArrayFilter; 23 var InnerArrayFilter;
24 var InnerArrayFind; 24 var InnerArrayFind;
25 var InnerArrayFindIndex; 25 var InnerArrayFindIndex;
26 var InnerArrayJoin; 26 var InnerArrayJoin;
27 var InnerArrayReduceRight;
28 var InnerArraySort; 27 var InnerArraySort;
29 var InnerArrayToLocaleString; 28 var InnerArrayToLocaleString;
30 var InternalArray = utils.InternalArray; 29 var InternalArray = utils.InternalArray;
31 var MaxSimple; 30 var MaxSimple;
32 var MinSimple; 31 var MinSimple;
33 var PackedArrayReverse; 32 var PackedArrayReverse;
34 var SpeciesConstructor; 33 var SpeciesConstructor;
35 var ToPositiveInteger; 34 var ToPositiveInteger;
36 var ToIndex; 35 var ToIndex;
37 var iteratorSymbol = utils.ImportNow("iterator_symbol"); 36 var iteratorSymbol = utils.ImportNow("iterator_symbol");
(...skipping 21 matching lines...) Expand all
59 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array); 58 var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
60 59
61 utils.Import(function(from) { 60 utils.Import(function(from) {
62 ArrayValues = from.ArrayValues; 61 ArrayValues = from.ArrayValues;
63 GetIterator = from.GetIterator; 62 GetIterator = from.GetIterator;
64 GetMethod = from.GetMethod; 63 GetMethod = from.GetMethod;
65 InnerArrayFilter = from.InnerArrayFilter; 64 InnerArrayFilter = from.InnerArrayFilter;
66 InnerArrayFind = from.InnerArrayFind; 65 InnerArrayFind = from.InnerArrayFind;
67 InnerArrayFindIndex = from.InnerArrayFindIndex; 66 InnerArrayFindIndex = from.InnerArrayFindIndex;
68 InnerArrayJoin = from.InnerArrayJoin; 67 InnerArrayJoin = from.InnerArrayJoin;
69 InnerArrayReduceRight = from.InnerArrayReduceRight;
70 InnerArraySort = from.InnerArraySort; 68 InnerArraySort = from.InnerArraySort;
71 InnerArrayToLocaleString = from.InnerArrayToLocaleString; 69 InnerArrayToLocaleString = from.InnerArrayToLocaleString;
72 MaxSimple = from.MaxSimple; 70 MaxSimple = from.MaxSimple;
73 MinSimple = from.MinSimple; 71 MinSimple = from.MinSimple;
74 PackedArrayReverse = from.PackedArrayReverse; 72 PackedArrayReverse = from.PackedArrayReverse;
75 SpeciesConstructor = from.SpeciesConstructor; 73 SpeciesConstructor = from.SpeciesConstructor;
76 ToPositiveInteger = from.ToPositiveInteger; 74 ToPositiveInteger = from.ToPositiveInteger;
77 ToIndex = from.ToIndex; 75 ToIndex = from.ToIndex;
78 }); 76 });
79 77
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // ES6 draft 07-15-13, section 22.2.3.19 563 // ES6 draft 07-15-13, section 22.2.3.19
566 function TypedArrayReduce(callback, current) { 564 function TypedArrayReduce(callback, current) {
567 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 565 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
568 566
569 var length = %_TypedArrayGetLength(this); 567 var length = %_TypedArrayGetLength(this);
570 return InnerTypedArrayReduce( 568 return InnerTypedArrayReduce(
571 callback, current, this, length, arguments.length); 569 callback, current, this, length, arguments.length);
572 } 570 }
573 %FunctionSetLength(TypedArrayReduce, 1); 571 %FunctionSetLength(TypedArrayReduce, 1);
574 572
573 function InnerArrayReduceRight(callback, current, array, length,
574 argumentsLength) {
575 if (!IS_CALLABLE(callback)) {
576 throw %make_type_error(kCalledNonCallable, callback);
577 }
578
579 var i = length - 1;
580 find_initial: if (argumentsLength < 2) {
581 for (; i >= 0; i--) {
582 if (i in array) {
583 current = array[i--];
584 break find_initial;
585 }
586 }
587 throw %make_type_error(kReduceNoInitial);
588 }
589
590 for (; i >= 0; i--) {
591 if (i in array) {
592 var element = array[i];
593 current = callback(current, element, i, array);
594 }
595 }
596 return current;
597 }
575 598
576 // ES6 draft 07-15-13, section 22.2.3.19 599 // ES6 draft 07-15-13, section 22.2.3.19
577 function TypedArrayReduceRight(callback, current) { 600 function TypedArrayReduceRight(callback, current) {
578 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 601 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
579 602
580 var length = %_TypedArrayGetLength(this); 603 var length = %_TypedArrayGetLength(this);
581 return InnerArrayReduceRight(callback, current, this, length, 604 return InnerArrayReduceRight(callback, current, this, length,
582 arguments.length); 605 arguments.length);
583 } 606 }
584 %FunctionSetLength(TypedArrayReduceRight, 1); 607 %FunctionSetLength(TypedArrayReduceRight, 1);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 %AddNamedProperty(GlobalNAME.prototype, 757 %AddNamedProperty(GlobalNAME.prototype,
735 "constructor", global.NAME, DONT_ENUM); 758 "constructor", global.NAME, DONT_ENUM);
736 %AddNamedProperty(GlobalNAME.prototype, 759 %AddNamedProperty(GlobalNAME.prototype,
737 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 760 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
738 READ_ONLY | DONT_ENUM | DONT_DELETE); 761 READ_ONLY | DONT_ENUM | DONT_DELETE);
739 endmacro 762 endmacro
740 763
741 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 764 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
742 765
743 }) 766 })
OLDNEW
« no previous file with comments | « src/js/array.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698