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

Unified Diff: src/harmony-typedarray.js

Issue 1148513002: Implement %TypedArray%.prototype.sort (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/array.js ('k') | test/mjsunit/harmony/typedarray-sort.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 59c9a79bd22144422d1bce9559c4cf1367dc37d8..025de55d582e6287833fd2f6f716e41a16021aa4 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -100,6 +100,40 @@ function TypedArrayReverse() {
}
+function TypedArrayComparefn(x, y) {
+ if ($isNaN(x) && $isNaN(y)) {
+ return $isNaN(y) ? 0 : 1;
+ }
+ if ($isNaN(x)) {
+ return 1;
+ }
+ if (x === 0 && x === y) {
+ if (%_IsMinusZero(x)) {
+ if (!%_IsMinusZero(y)) {
+ return -1;
+ }
+ } else if (%_IsMinusZero(y)) {
+ return 1;
+ }
+ }
+ return x - y;
+}
+
+
+// ES6 draft 05-18-15, section 22.2.3.25
+function TypedArraySort(comparefn) {
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
+
+ var length = %_TypedArrayGetLength(this);
+
+ if (IS_UNDEFINED(comparefn)) {
+ comparefn = TypedArrayComparefn;
+ }
+
+ return %_CallFunction(this, length, comparefn, $innerArraySort);
+}
+
+
// ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() {
var length = %_ArgumentsLength();
@@ -150,7 +184,8 @@ macro EXTEND_TYPED_ARRAY(NAME)
"find", TypedArrayFind,
"findIndex", TypedArrayFindIndex,
"fill", TypedArrayFill,
- "reverse", TypedArrayReverse
+ "reverse", TypedArrayReverse,
+ "sort", TypedArraySort
]);
endmacro
« no previous file with comments | « src/array.js ('k') | test/mjsunit/harmony/typedarray-sort.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698