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

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

Issue 1560763002: Add Array support for @@species and subclassing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Some fixes Created 4 years, 11 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
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
(...skipping 11 matching lines...) Expand all
22 var InnerArrayEvery; 22 var InnerArrayEvery;
23 var InnerArrayFill; 23 var InnerArrayFill;
24 var InnerArrayFilter; 24 var InnerArrayFilter;
25 var InnerArrayFind; 25 var InnerArrayFind;
26 var InnerArrayFindIndex; 26 var InnerArrayFindIndex;
27 var InnerArrayForEach; 27 var InnerArrayForEach;
28 var InnerArrayIncludes; 28 var InnerArrayIncludes;
29 var InnerArrayIndexOf; 29 var InnerArrayIndexOf;
30 var InnerArrayJoin; 30 var InnerArrayJoin;
31 var InnerArrayLastIndexOf; 31 var InnerArrayLastIndexOf;
32 var InnerArrayMap; 32 var InnerArrayMap;
adamk 2016/01/06 00:10:12 You can now remove this import.
33 var InnerArrayReduce; 33 var InnerArrayReduce;
34 var InnerArrayReduceRight; 34 var InnerArrayReduceRight;
35 var InnerArraySome; 35 var InnerArraySome;
36 var InnerArraySort; 36 var InnerArraySort;
37 var InnerArrayToLocaleString; 37 var InnerArrayToLocaleString;
38 var InternalArray = utils.InternalArray; 38 var InternalArray = utils.InternalArray;
39 var IsNaN; 39 var IsNaN;
40 var MakeRangeError; 40 var MakeRangeError;
41 var MakeTypeError; 41 var MakeTypeError;
42 var MaxSimple; 42 var MaxSimple;
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 486 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
487 487
488 var length = %_TypedArrayGetLength(this); 488 var length = %_TypedArrayGetLength(this);
489 489
490 return InnerArrayFill(value, start, end, this, length); 490 return InnerArrayFill(value, start, end, this, length);
491 } 491 }
492 %FunctionSetLength(TypedArrayFill, 1); 492 %FunctionSetLength(TypedArrayFill, 1);
493 493
494 494
495 // ES6 draft 07-15-13, section 22.2.3.9 495 // ES6 draft 07-15-13, section 22.2.3.9
496 function TypedArrayFilter(predicate, thisArg) { 496 function TypedArrayFilter(f, thisArg) {
497 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 497 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
498 498
499 var length = %_TypedArrayGetLength(this); 499 var length = %_TypedArrayGetLength(this);
500 var array = InnerArrayFilter(predicate, thisArg, this, length); 500 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
501 return ConstructTypedArrayLike(this, array); 501 var result = new InternalArray();
502 InnerArrayFilter(f, thisArg, this, length, result);
503 var captured = result.length;
504 var output = ConstructTypedArrayLike(this, captured);
505 for (var n = 0; n < captured; n++) {
adamk 2016/01/06 00:10:12 Can you use 'i' instead of 'n' for the name here?
Dan Ehrenberg 2016/01/07 00:42:57 Done
506 output[n] = result[n];
adamk 2016/01/06 00:10:12 Nit: indentation (need another space)
Dan Ehrenberg 2016/01/07 00:42:57 Done
507 }
508 return output;
502 } 509 }
503 %FunctionSetLength(TypedArrayFilter, 1); 510 %FunctionSetLength(TypedArrayFilter, 1);
504 511
505 512
506 // ES6 draft 07-15-13, section 22.2.3.10 513 // ES6 draft 07-15-13, section 22.2.3.10
507 function TypedArrayFind(predicate, thisArg) { 514 function TypedArrayFind(predicate, thisArg) {
508 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 515 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
509 516
510 var length = %_TypedArrayGetLength(this); 517 var length = %_TypedArrayGetLength(this);
511 518
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 592
586 var length = %_TypedArrayGetLength(this); 593 var length = %_TypedArrayGetLength(this);
587 594
588 return InnerArrayLastIndexOf(this, element, index, length, 595 return InnerArrayLastIndexOf(this, element, index, length,
589 %_ArgumentsLength()); 596 %_ArgumentsLength());
590 } 597 }
591 %FunctionSetLength(TypedArrayLastIndexOf, 1); 598 %FunctionSetLength(TypedArrayLastIndexOf, 1);
592 599
593 600
594 // ES6 draft 07-15-13, section 22.2.3.18 601 // ES6 draft 07-15-13, section 22.2.3.18
595 function TypedArrayMap(predicate, thisArg) { 602 function TypedArrayMap(f, thisArg) {
596 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 603 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
597 604
598 // TODO(littledan): Preallocate rather than making an intermediate
599 // InternalArray, for better performance.
600 var length = %_TypedArrayGetLength(this); 605 var length = %_TypedArrayGetLength(this);
601 var array = InnerArrayMap(predicate, thisArg, this, length); 606 var result = ConstructTypedArrayLike(this, length);
602 return ConstructTypedArrayLike(this, array); 607 if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
608 for (var i = 0; i < length; i++) {
609 var element = this[i];
610 result[i] = %_Call(f, thisArg, element, i, this);
611 }
612 return result;
603 } 613 }
604 %FunctionSetLength(TypedArrayMap, 1); 614 %FunctionSetLength(TypedArrayMap, 1);
605 615
606 616
607 // ES6 draft 05-05-15, section 22.2.3.24 617 // ES6 draft 05-05-15, section 22.2.3.24
608 function TypedArraySome(f, receiver) { 618 function TypedArraySome(f, receiver) {
609 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); 619 if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
610 620
611 var length = %_TypedArrayGetLength(this); 621 var length = %_TypedArrayGetLength(this);
612 622
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 "setUint32", DataViewSetUint32JS, 946 "setUint32", DataViewSetUint32JS,
937 947
938 "getFloat32", DataViewGetFloat32JS, 948 "getFloat32", DataViewGetFloat32JS,
939 "setFloat32", DataViewSetFloat32JS, 949 "setFloat32", DataViewSetFloat32JS,
940 950
941 "getFloat64", DataViewGetFloat64JS, 951 "getFloat64", DataViewGetFloat64JS,
942 "setFloat64", DataViewSetFloat64JS 952 "setFloat64", DataViewSetFloat64JS
943 ]); 953 ]);
944 954
945 }) 955 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698