OLD | NEW |
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 var length = %_TypedArrayGetLength(this); | 507 var length = %_TypedArrayGetLength(this); |
508 | 508 |
509 if (IS_UNDEFINED(comparefn)) { | 509 if (IS_UNDEFINED(comparefn)) { |
510 return %TypedArraySortFast(this); | 510 return %TypedArraySortFast(this); |
511 } | 511 } |
512 | 512 |
513 return InnerArraySort(this, length, comparefn); | 513 return InnerArraySort(this, length, comparefn); |
514 } | 514 } |
515 | 515 |
516 | 516 |
517 // ES6 section 22.2.3.16 | |
518 function TypedArrayLastIndexOf(element, index) { | |
519 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | |
520 | |
521 var length = %_TypedArrayGetLength(this); | |
522 | |
523 if (length === 0) return -1; | |
524 if (!IS_NUMBER(element)) return -1; | |
525 var n; | |
526 if (arguments.length < 2) { | |
527 n = length - 1; | |
528 } else { | |
529 n = TO_INTEGER(index); | |
530 } | |
531 | |
532 var k; | |
533 if (n >= 0) { | |
534 if (length <= n) { | |
535 k = length - 1; | |
536 } else if (n === 0) { | |
537 k = 0; | |
538 } else { | |
539 k = n; | |
540 } | |
541 } else { | |
542 k = length + n; | |
543 } | |
544 | |
545 while (k >= 0) { | |
546 var elementK = this[k]; | |
547 if (element === elementK) { | |
548 return k; | |
549 } | |
550 --k; | |
551 } | |
552 return -1; | |
553 } | |
554 %FunctionSetLength(TypedArrayLastIndexOf, 1); | |
555 | |
556 | |
557 // ES6 draft 07-15-13, section 22.2.3.18 | 517 // ES6 draft 07-15-13, section 22.2.3.18 |
558 function TypedArrayMap(f, thisArg) { | 518 function TypedArrayMap(f, thisArg) { |
559 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 519 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
560 | 520 |
561 var length = %_TypedArrayGetLength(this); | 521 var length = %_TypedArrayGetLength(this); |
562 var result = TypedArraySpeciesCreate(this, length); | 522 var result = TypedArraySpeciesCreate(this, length); |
563 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); | 523 if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f); |
564 for (var i = 0; i < length; i++) { | 524 for (var i = 0; i < length; i++) { |
565 var element = this[i]; | 525 var element = this[i]; |
566 result[i] = %_Call(f, thisArg, element, i, this); | 526 result[i] = %_Call(f, thisArg, element, i, this); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 TypedArrayGetToStringTag); | 700 TypedArrayGetToStringTag); |
741 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ | 701 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ |
742 "subarray", TypedArraySubArray, | 702 "subarray", TypedArraySubArray, |
743 "set", TypedArraySet, | 703 "set", TypedArraySet, |
744 "every", TypedArrayEvery, | 704 "every", TypedArrayEvery, |
745 "fill", TypedArrayFill, | 705 "fill", TypedArrayFill, |
746 "filter", TypedArrayFilter, | 706 "filter", TypedArrayFilter, |
747 "find", TypedArrayFind, | 707 "find", TypedArrayFind, |
748 "findIndex", TypedArrayFindIndex, | 708 "findIndex", TypedArrayFindIndex, |
749 "join", TypedArrayJoin, | 709 "join", TypedArrayJoin, |
750 "lastIndexOf", TypedArrayLastIndexOf, | |
751 "forEach", TypedArrayForEach, | 710 "forEach", TypedArrayForEach, |
752 "map", TypedArrayMap, | 711 "map", TypedArrayMap, |
753 "reduce", TypedArrayReduce, | 712 "reduce", TypedArrayReduce, |
754 "reduceRight", TypedArrayReduceRight, | 713 "reduceRight", TypedArrayReduceRight, |
755 "reverse", TypedArrayReverse, | 714 "reverse", TypedArrayReverse, |
756 "slice", TypedArraySlice, | 715 "slice", TypedArraySlice, |
757 "some", TypedArraySome, | 716 "some", TypedArraySome, |
758 "sort", TypedArraySort, | 717 "sort", TypedArraySort, |
759 "toLocaleString", TypedArrayToLocaleString | 718 "toLocaleString", TypedArrayToLocaleString |
760 ]); | 719 ]); |
(...skipping 14 matching lines...) Expand all Loading... |
775 %AddNamedProperty(GlobalNAME.prototype, | 734 %AddNamedProperty(GlobalNAME.prototype, |
776 "constructor", global.NAME, DONT_ENUM); | 735 "constructor", global.NAME, DONT_ENUM); |
777 %AddNamedProperty(GlobalNAME.prototype, | 736 %AddNamedProperty(GlobalNAME.prototype, |
778 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 737 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
779 READ_ONLY | DONT_ENUM | DONT_DELETE); | 738 READ_ONLY | DONT_ENUM | DONT_DELETE); |
780 endmacro | 739 endmacro |
781 | 740 |
782 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 741 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
783 | 742 |
784 }) | 743 }) |
OLD | NEW |