| 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 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 var length = %_TypedArrayGetLength(this); | 524 var length = %_TypedArrayGetLength(this); |
| 525 | 525 |
| 526 if (IS_UNDEFINED(comparefn)) { | 526 if (IS_UNDEFINED(comparefn)) { |
| 527 return %TypedArraySortFast(this); | 527 return %TypedArraySortFast(this); |
| 528 } | 528 } |
| 529 | 529 |
| 530 return InnerArraySort(this, length, comparefn); | 530 return InnerArraySort(this, length, comparefn); |
| 531 } | 531 } |
| 532 | 532 |
| 533 | 533 |
| 534 // ES6 section 22.2.3.13 | |
| 535 function TypedArrayIndexOf(element, index) { | |
| 536 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | |
| 537 | |
| 538 var length = %_TypedArrayGetLength(this); | |
| 539 | |
| 540 if (length === 0) return -1; | |
| 541 if (!IS_NUMBER(element)) return -1; | |
| 542 var n = TO_INTEGER(index); | |
| 543 | |
| 544 var k; | |
| 545 if (n === 0) { | |
| 546 k = 0; | |
| 547 } else if (n > 0) { | |
| 548 k = n; | |
| 549 } else { | |
| 550 k = length + n; | |
| 551 if (k < 0) { | |
| 552 k = 0; | |
| 553 } | |
| 554 } | |
| 555 | |
| 556 while (k < length) { | |
| 557 var elementK = this[k]; | |
| 558 if (element === elementK) { | |
| 559 return k; | |
| 560 } | |
| 561 ++k; | |
| 562 } | |
| 563 return -1; | |
| 564 } | |
| 565 %FunctionSetLength(TypedArrayIndexOf, 1); | |
| 566 | |
| 567 | |
| 568 // ES6 section 22.2.3.16 | 534 // ES6 section 22.2.3.16 |
| 569 function TypedArrayLastIndexOf(element, index) { | 535 function TypedArrayLastIndexOf(element, index) { |
| 570 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 536 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
| 571 | 537 |
| 572 var length = %_TypedArrayGetLength(this); | 538 var length = %_TypedArrayGetLength(this); |
| 573 | 539 |
| 574 if (length === 0) return -1; | 540 if (length === 0) return -1; |
| 575 if (!IS_NUMBER(element)) return -1; | 541 if (!IS_NUMBER(element)) return -1; |
| 576 var n; | 542 var n; |
| 577 if (arguments.length < 2) { | 543 if (arguments.length < 2) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol, | 756 utils.InstallGetter(GlobalTypedArray.prototype, toStringTagSymbol, |
| 791 TypedArrayGetToStringTag); | 757 TypedArrayGetToStringTag); |
| 792 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ | 758 utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ |
| 793 "subarray", TypedArraySubArray, | 759 "subarray", TypedArraySubArray, |
| 794 "set", TypedArraySet, | 760 "set", TypedArraySet, |
| 795 "every", TypedArrayEvery, | 761 "every", TypedArrayEvery, |
| 796 "fill", TypedArrayFill, | 762 "fill", TypedArrayFill, |
| 797 "filter", TypedArrayFilter, | 763 "filter", TypedArrayFilter, |
| 798 "find", TypedArrayFind, | 764 "find", TypedArrayFind, |
| 799 "findIndex", TypedArrayFindIndex, | 765 "findIndex", TypedArrayFindIndex, |
| 800 "indexOf", TypedArrayIndexOf, | |
| 801 "join", TypedArrayJoin, | 766 "join", TypedArrayJoin, |
| 802 "lastIndexOf", TypedArrayLastIndexOf, | 767 "lastIndexOf", TypedArrayLastIndexOf, |
| 803 "forEach", TypedArrayForEach, | 768 "forEach", TypedArrayForEach, |
| 804 "map", TypedArrayMap, | 769 "map", TypedArrayMap, |
| 805 "reduce", TypedArrayReduce, | 770 "reduce", TypedArrayReduce, |
| 806 "reduceRight", TypedArrayReduceRight, | 771 "reduceRight", TypedArrayReduceRight, |
| 807 "reverse", TypedArrayReverse, | 772 "reverse", TypedArrayReverse, |
| 808 "slice", TypedArraySlice, | 773 "slice", TypedArraySlice, |
| 809 "some", TypedArraySome, | 774 "some", TypedArraySome, |
| 810 "sort", TypedArraySort, | 775 "sort", TypedArraySort, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 827 %AddNamedProperty(GlobalNAME.prototype, | 792 %AddNamedProperty(GlobalNAME.prototype, |
| 828 "constructor", global.NAME, DONT_ENUM); | 793 "constructor", global.NAME, DONT_ENUM); |
| 829 %AddNamedProperty(GlobalNAME.prototype, | 794 %AddNamedProperty(GlobalNAME.prototype, |
| 830 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 795 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
| 831 READ_ONLY | DONT_ENUM | DONT_DELETE); | 796 READ_ONLY | DONT_ENUM | DONT_DELETE); |
| 832 endmacro | 797 endmacro |
| 833 | 798 |
| 834 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 799 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
| 835 | 800 |
| 836 }) | 801 }) |
| OLD | NEW |