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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 | 523 |
524 // ES6 draft 05-18-15, section 22.2.3.21 | 524 // ES6 draft 05-18-15, section 22.2.3.21 |
525 function TypedArrayReverse() { | 525 function TypedArrayReverse() { |
526 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 526 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
527 | 527 |
528 var length = %_TypedArrayGetLength(this); | 528 var length = %_TypedArrayGetLength(this); |
529 | 529 |
530 return PackedArrayReverse(this, length); | 530 return PackedArrayReverse(this, length); |
531 } | 531 } |
532 | 532 |
533 | |
534 function TypedArrayComparefn(x, y) { | |
535 if (x === 0 && x === y) { | |
536 x = 1 / x; | |
537 y = 1 / y; | |
538 } | |
539 if (x < y) { | |
540 return -1; | |
541 } else if (x > y) { | |
542 return 1; | |
543 } else if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) { | |
544 return NUMBER_IS_NAN(y) ? 0 : 1; | |
545 } else if (NUMBER_IS_NAN(x)) { | |
546 return 1; | |
547 } | |
548 return 0; | |
549 } | |
550 | |
551 | |
552 // ES6 draft 05-18-15, section 22.2.3.25 | 533 // ES6 draft 05-18-15, section 22.2.3.25 |
553 function TypedArraySort(comparefn) { | 534 function TypedArraySort(comparefn) { |
554 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 535 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
555 | 536 |
556 var length = %_TypedArrayGetLength(this); | 537 var length = %_TypedArrayGetLength(this); |
557 | 538 |
558 if (IS_UNDEFINED(comparefn)) { | 539 if (IS_UNDEFINED(comparefn)) { |
559 comparefn = TypedArrayComparefn; | 540 return %_TypedArraySortFast(this); |
Benedikt Meurer
2017/02/15 05:08:04
Since you call to the runtime anyways, just use %T
| |
560 } | 541 } |
561 | 542 |
562 return InnerArraySort(this, length, comparefn); | 543 return InnerArraySort(this, length, comparefn); |
563 } | 544 } |
564 | 545 |
565 | 546 |
566 // ES6 section 22.2.3.13 | 547 // ES6 section 22.2.3.13 |
567 function TypedArrayIndexOf(element, index) { | 548 function TypedArrayIndexOf(element, index) { |
568 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); | 549 if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray); |
569 | 550 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
894 %AddNamedProperty(GlobalNAME.prototype, | 875 %AddNamedProperty(GlobalNAME.prototype, |
895 "constructor", global.NAME, DONT_ENUM); | 876 "constructor", global.NAME, DONT_ENUM); |
896 %AddNamedProperty(GlobalNAME.prototype, | 877 %AddNamedProperty(GlobalNAME.prototype, |
897 "BYTES_PER_ELEMENT", ELEMENT_SIZE, | 878 "BYTES_PER_ELEMENT", ELEMENT_SIZE, |
898 READ_ONLY | DONT_ENUM | DONT_DELETE); | 879 READ_ONLY | DONT_ENUM | DONT_DELETE); |
899 endmacro | 880 endmacro |
900 | 881 |
901 TYPED_ARRAYS(SETUP_TYPED_ARRAY) | 882 TYPED_ARRAYS(SETUP_TYPED_ARRAY) |
902 | 883 |
903 }) | 884 }) |
OLD | NEW |