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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 function TypedArrayReduceRight(callback, current) { | 567 function TypedArrayReduceRight(callback, current) { |
568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
569 | 569 |
570 var length = %_TypedArrayGetLength(this); | 570 var length = %_TypedArrayGetLength(this); |
571 return InnerArrayReduceRight(callback, current, this, length, | 571 return InnerArrayReduceRight(callback, current, this, length, |
572 arguments.length); | 572 arguments.length); |
573 } | 573 } |
574 %FunctionSetLength(TypedArrayReduceRight, 1); | 574 %FunctionSetLength(TypedArrayReduceRight, 1); |
575 | 575 |
576 | 576 |
577 function TypedArraySlice(start, end) { | |
578 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | |
579 var len = %_TypedArrayGetLength(this); | |
580 | |
581 var relativeStart = TO_INTEGER(start); | |
582 | |
583 var k; | |
584 if (relativeStart < 0) { | |
585 k = MaxSimple(len + relativeStart, 0); | |
586 } else { | |
587 k = MinSimple(relativeStart, len); | |
588 } | |
589 | |
590 var relativeEnd; | |
591 if (IS_UNDEFINED(end)) { | |
592 relativeEnd = len; | |
593 } else { | |
594 relativeEnd = TO_INTEGER(end); | |
595 } | |
596 | |
597 var final; | |
598 if (relativeEnd < 0) { | |
599 final = MaxSimple(len + relativeEnd, 0); | |
600 } else { | |
601 final = MinSimple(relativeEnd, len); | |
602 } | |
603 | |
604 var count = MaxSimple(final - k, 0); | |
605 var array = TypedArraySpeciesCreate(this, count); | |
606 // The code below is the 'then' branch; the 'else' branch species | |
607 // a memcpy. Because V8 doesn't canonicalize NaN, the difference is | |
608 // unobservable. | |
609 var n = 0; | |
610 while (k < final) { | |
611 var kValue = this[k]; | |
612 array[n] = kValue; | |
613 k++; | |
614 n++; | |
615 } | |
616 return array; | |
617 } | |
618 | |
619 | |
620 // ES6 draft 08-24-14, section 22.2.2.2 | 577 // ES6 draft 08-24-14, section 22.2.2.2 |
621 function TypedArrayOf() { | 578 function TypedArrayOf() { |
622 var length = arguments.length; | 579 var length = arguments.length; |
623 var array = TypedArrayCreate(this, length); | 580 var array = TypedArrayCreate(this, length); |
624 for (var i = 0; i < length; i++) { | 581 for (var i = 0; i < length; i++) { |
625 array[i] = arguments[i]; | 582 array[i] = arguments[i]; |
626 } | 583 } |
627 return array; | 584 return array; |
628 } | 585 } |
629 | 586 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 "set", TypedArraySet, | 651 "set", TypedArraySet, |
695 "every", TypedArrayEvery, | 652 "every", TypedArrayEvery, |
696 "filter", TypedArrayFilter, | 653 "filter", TypedArrayFilter, |
697 "find", TypedArrayFind, | 654 "find", TypedArrayFind, |
698 "findIndex", TypedArrayFindIndex, | 655 "findIndex", TypedArrayFindIndex, |
699 "join", TypedArrayJoin, | 656 "join", TypedArrayJoin, |
700 "forEach", TypedArrayForEach, | 657 "forEach", TypedArrayForEach, |
701 "map", TypedArrayMap, | 658 "map", TypedArrayMap, |
702 "reduce", TypedArrayReduce, | 659 "reduce", TypedArrayReduce, |
703 "reduceRight", TypedArrayReduceRight, | 660 "reduceRight", TypedArrayReduceRight, |
704 "slice", TypedArraySlice, | |
705 "some", TypedArraySome, | 661 "some", TypedArraySome, |
706 "sort", TypedArraySort, | 662 "sort", TypedArraySort, |
707 "toLocaleString", TypedArrayToLocaleString | 663 "toLocaleString", TypedArrayToLocaleString |
708 ]); | 664 ]); |
709 | 665 |
710 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, | 666 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, |
711 DONT_ENUM); | 667 DONT_ENUM); |
712 | 668 |
713 | 669 |
714 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | 670 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
715 %SetCode(GlobalNAME, NAMEConstructor); | 671 %SetCode(GlobalNAME, NAMEConstructor); |
716 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); | 672 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); |
717 %InternalSetPrototype(GlobalNAME, GlobalTypedArray); | 673 %InternalSetPrototype(GlobalNAME, GlobalTypedArray); |
718 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); | 674 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); |
719 | 675 |
720 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 676 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
721 READ_ONLY | DONT_ENUM | DONT_DELETE); | 677 READ_ONLY | DONT_ENUM | DONT_DELETE); |
722 | 678 |
723 %AddNamedProperty(GlobalNAME.prototype, | 679 %AddNamedProperty(GlobalNAME.prototype, |
724 "constructor", global.NAME, DONT_ENUM); | 680 "constructor", global.NAME, DONT_ENUM); |
725 %AddNamedProperty(GlobalNAME.prototype, | 681 %AddNamedProperty(GlobalNAME.prototype, |
726 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 682 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
727 READ_ONLY | DONT_ENUM | DONT_DELETE); | 683 READ_ONLY | DONT_ENUM | DONT_DELETE); |
728 endmacro | 684 endmacro |
729 | 685 |
730 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 686 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
731 | 687 |
732 }) | 688 }) |
OLD | NEW |