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

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

Issue 2763473002: [typedarrays] Move %TypedArray%.prototype.slice to C++ (Closed)
Patch Set: rebase Created 3 years, 8 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/elements.cc ('k') | test/mjsunit/es6/typedarray-slice.js » ('j') | 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
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 function TypedArrayReduceRight(callback, current) { 576 function TypedArrayReduceRight(callback, current) {
577 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 577 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
578 578
579 var length = %_TypedArrayGetLength(this); 579 var length = %_TypedArrayGetLength(this);
580 return InnerArrayReduceRight(callback, current, this, length, 580 return InnerArrayReduceRight(callback, current, this, length,
581 arguments.length); 581 arguments.length);
582 } 582 }
583 %FunctionSetLength(TypedArrayReduceRight, 1); 583 %FunctionSetLength(TypedArrayReduceRight, 1);
584 584
585 585
586 function TypedArraySlice(start, end) {
587 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
588 var len = %_TypedArrayGetLength(this);
589
590 var relativeStart = TO_INTEGER(start);
591
592 var k;
593 if (relativeStart < 0) {
594 k = MaxSimple(len + relativeStart, 0);
595 } else {
596 k = MinSimple(relativeStart, len);
597 }
598
599 var relativeEnd;
600 if (IS_UNDEFINED(end)) {
601 relativeEnd = len;
602 } else {
603 relativeEnd = TO_INTEGER(end);
604 }
605
606 var final;
607 if (relativeEnd < 0) {
608 final = MaxSimple(len + relativeEnd, 0);
609 } else {
610 final = MinSimple(relativeEnd, len);
611 }
612
613 var count = MaxSimple(final - k, 0);
614 var array = TypedArraySpeciesCreate(this, count);
615 // The code below is the 'then' branch; the 'else' branch species
616 // a memcpy. Because V8 doesn't canonicalize NaN, the difference is
617 // unobservable.
618 var n = 0;
619 while (k < final) {
620 var kValue = this[k];
621 array[n] = kValue;
622 k++;
623 n++;
624 }
625 return array;
626 }
627
628
629 // ES6 draft 08-24-14, section 22.2.2.2 586 // ES6 draft 08-24-14, section 22.2.2.2
630 function TypedArrayOf() { 587 function TypedArrayOf() {
631 var length = arguments.length; 588 var length = arguments.length;
632 var array = TypedArrayCreate(this, length); 589 var array = TypedArrayCreate(this, length);
633 for (var i = 0; i < length; i++) { 590 for (var i = 0; i < length; i++) {
634 array[i] = arguments[i]; 591 array[i] = arguments[i];
635 } 592 }
636 return array; 593 return array;
637 } 594 }
638 595
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 "set", TypedArraySet, 660 "set", TypedArraySet,
704 "every", TypedArrayEvery, 661 "every", TypedArrayEvery,
705 "filter", TypedArrayFilter, 662 "filter", TypedArrayFilter,
706 "find", TypedArrayFind, 663 "find", TypedArrayFind,
707 "findIndex", TypedArrayFindIndex, 664 "findIndex", TypedArrayFindIndex,
708 "join", TypedArrayJoin, 665 "join", TypedArrayJoin,
709 "forEach", TypedArrayForEach, 666 "forEach", TypedArrayForEach,
710 "map", TypedArrayMap, 667 "map", TypedArrayMap,
711 "reduce", TypedArrayReduce, 668 "reduce", TypedArrayReduce,
712 "reduceRight", TypedArrayReduceRight, 669 "reduceRight", TypedArrayReduceRight,
713 "slice", TypedArraySlice,
714 "some", TypedArraySome, 670 "some", TypedArraySome,
715 "sort", TypedArraySort, 671 "sort", TypedArraySort,
716 "toLocaleString", TypedArrayToLocaleString 672 "toLocaleString", TypedArrayToLocaleString
717 ]); 673 ]);
718 674
719 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, 675 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString,
720 DONT_ENUM); 676 DONT_ENUM);
721 677
722 678
723 macro SETUP_TYPED_ARRAY(NAME, ELEMENT_SIZE) 679 macro SETUP_TYPED_ARRAY(NAME, ELEMENT_SIZE)
724 %SetCode(GlobalNAME, NAMEConstructor); 680 %SetCode(GlobalNAME, NAMEConstructor);
725 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); 681 %FunctionSetPrototype(GlobalNAME, new GlobalObject());
726 %InternalSetPrototype(GlobalNAME, GlobalTypedArray); 682 %InternalSetPrototype(GlobalNAME, GlobalTypedArray);
727 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); 683 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype);
728 684
729 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 685 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
730 READ_ONLY | DONT_ENUM | DONT_DELETE); 686 READ_ONLY | DONT_ENUM | DONT_DELETE);
731 687
732 %AddNamedProperty(GlobalNAME.prototype, 688 %AddNamedProperty(GlobalNAME.prototype,
733 "constructor", global.NAME, DONT_ENUM); 689 "constructor", global.NAME, DONT_ENUM);
734 %AddNamedProperty(GlobalNAME.prototype, 690 %AddNamedProperty(GlobalNAME.prototype,
735 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 691 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
736 READ_ONLY | DONT_ENUM | DONT_DELETE); 692 READ_ONLY | DONT_ENUM | DONT_DELETE);
737 endmacro 693 endmacro
738 694
739 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 695 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
740 696
741 }) 697 })
OLDNEW
« no previous file with comments | « src/elements.cc ('k') | test/mjsunit/es6/typedarray-slice.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698