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

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

Issue 2763473002: [typedarrays] Move %TypedArray%.prototype.slice to C++ (Closed)
Patch Set: Add tests Created 3 years, 9 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 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 function TypedArrayReduceRight(callback, current) { 532 function TypedArrayReduceRight(callback, current) {
533 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); 533 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
534 534
535 var length = %_TypedArrayGetLength(this); 535 var length = %_TypedArrayGetLength(this);
536 return InnerArrayReduceRight(callback, current, this, length, 536 return InnerArrayReduceRight(callback, current, this, length,
537 arguments.length); 537 arguments.length);
538 } 538 }
539 %FunctionSetLength(TypedArrayReduceRight, 1); 539 %FunctionSetLength(TypedArrayReduceRight, 1);
540 540
541 541
542 function TypedArraySlice(start, end) {
543 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
544 var len = %_TypedArrayGetLength(this);
545
546 var relativeStart = TO_INTEGER(start);
547
548 var k;
549 if (relativeStart < 0) {
550 k = MaxSimple(len + relativeStart, 0);
551 } else {
552 k = MinSimple(relativeStart, len);
553 }
554
555 var relativeEnd;
556 if (IS_UNDEFINED(end)) {
557 relativeEnd = len;
558 } else {
559 relativeEnd = TO_INTEGER(end);
560 }
561
562 var final;
563 if (relativeEnd < 0) {
564 final = MaxSimple(len + relativeEnd, 0);
565 } else {
566 final = MinSimple(relativeEnd, len);
567 }
568
569 var count = MaxSimple(final - k, 0);
570 var array = TypedArraySpeciesCreate(this, count);
571 // The code below is the 'then' branch; the 'else' branch species
572 // a memcpy. Because V8 doesn't canonicalize NaN, the difference is
573 // unobservable.
574 var n = 0;
575 while (k < final) {
576 var kValue = this[k];
577 array[n] = kValue;
578 k++;
579 n++;
580 }
581 return array;
582 }
583
584
585 // ES6 draft 08-24-14, section 22.2.2.2 542 // ES6 draft 08-24-14, section 22.2.2.2
586 function TypedArrayOf() { 543 function TypedArrayOf() {
587 var length = arguments.length; 544 var length = arguments.length;
588 var array = TypedArrayCreate(this, length); 545 var array = TypedArrayCreate(this, length);
589 for (var i = 0; i < length; i++) { 546 for (var i = 0; i < length; i++) {
590 array[i] = arguments[i]; 547 array[i] = arguments[i];
591 } 548 }
592 return array; 549 return array;
593 } 550 }
594 551
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 "fill", TypedArrayFill, 618 "fill", TypedArrayFill,
662 "filter", TypedArrayFilter, 619 "filter", TypedArrayFilter,
663 "find", TypedArrayFind, 620 "find", TypedArrayFind,
664 "findIndex", TypedArrayFindIndex, 621 "findIndex", TypedArrayFindIndex,
665 "join", TypedArrayJoin, 622 "join", TypedArrayJoin,
666 "forEach", TypedArrayForEach, 623 "forEach", TypedArrayForEach,
667 "map", TypedArrayMap, 624 "map", TypedArrayMap,
668 "reduce", TypedArrayReduce, 625 "reduce", TypedArrayReduce,
669 "reduceRight", TypedArrayReduceRight, 626 "reduceRight", TypedArrayReduceRight,
670 "reverse", TypedArrayReverse, 627 "reverse", TypedArrayReverse,
671 "slice", TypedArraySlice,
672 "some", TypedArraySome, 628 "some", TypedArraySome,
673 "sort", TypedArraySort, 629 "sort", TypedArraySort,
674 "toLocaleString", TypedArrayToLocaleString 630 "toLocaleString", TypedArrayToLocaleString
675 ]); 631 ]);
676 632
677 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString, 633 %AddNamedProperty(GlobalTypedArray.prototype, "toString", ArrayToString,
678 DONT_ENUM); 634 DONT_ENUM);
679 635
680 636
681 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) 637 macro SETUP_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
682 %SetCode(GlobalNAME, NAMEConstructor); 638 %SetCode(GlobalNAME, NAMEConstructor);
683 %FunctionSetPrototype(GlobalNAME, new GlobalObject()); 639 %FunctionSetPrototype(GlobalNAME, new GlobalObject());
684 %InternalSetPrototype(GlobalNAME, GlobalTypedArray); 640 %InternalSetPrototype(GlobalNAME, GlobalTypedArray);
685 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype); 641 %InternalSetPrototype(GlobalNAME.prototype, GlobalTypedArray.prototype);
686 642
687 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE, 643 %AddNamedProperty(GlobalNAME, "BYTES_PER_ELEMENT", ELEMENT_SIZE,
688 READ_ONLY | DONT_ENUM | DONT_DELETE); 644 READ_ONLY | DONT_ENUM | DONT_DELETE);
689 645
690 %AddNamedProperty(GlobalNAME.prototype, 646 %AddNamedProperty(GlobalNAME.prototype,
691 "constructor", global.NAME, DONT_ENUM); 647 "constructor", global.NAME, DONT_ENUM);
692 %AddNamedProperty(GlobalNAME.prototype, 648 %AddNamedProperty(GlobalNAME.prototype,
693 "BYTES_PER_ELEMENT", ELEMENT_SIZE, 649 "BYTES_PER_ELEMENT", ELEMENT_SIZE,
694 READ_ONLY | DONT_ENUM | DONT_DELETE); 650 READ_ONLY | DONT_ENUM | DONT_DELETE);
695 endmacro 651 endmacro
696 652
697 TYPED_ARRAYS(SETUP_TYPED_ARRAY) 653 TYPED_ARRAYS(SETUP_TYPED_ARRAY)
698 654
699 }) 655 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698