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

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: 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
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 90679e0c1fe1afffb6b6b7115e93719e02d7b0c1..1c1f3d9e355948a91ada1f9f830d43ff53130a7e 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -91,6 +91,42 @@ function TypedArrayFindIndex(predicate, thisArg) {
%FunctionSetLength(TypedArrayFindIndex, 1);
+function TypedArrayComparefn(x, y) {
arv (Not doing code reviews) 2015/05/19 15:49:31 This is OK for now but I think we might want to in
dehrenberg 2015/05/19 16:39:09 Acknowledged.
+ if ($isNaN(x) && $isNaN(y)) {
+ return 0;
+ } else if ($isNaN(x)) {
arv (Not doing code reviews) 2015/05/19 15:49:31 no else after return The order can be changed to
dehrenberg 2015/05/19 16:39:08 Done.
+ return 1;
+ } else if ($isNaN(y)) {
+ return -1;
+ } else if (x < y) {
+ return -1;
arv (Not doing code reviews) 2015/05/19 15:49:31 Do we care about -1? Generally this just has to be
dehrenberg 2015/05/19 16:39:09 Done.
+ } else if (x > y) {
+ return 1;
+ } else if (x === y && x === 0) {
+ if (%_IsMinusZero(x) && !%_IsMinusZero(y)) {
+ return -1;
+ } else if (!%_IsMinusZero(x) && %_IsMinusZero(y)) {
arv (Not doing code reviews) 2015/05/19 15:49:31 reorg to reduce test?
dehrenberg 2015/05/19 16:39:08 Done.
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+// 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();
@@ -140,7 +176,8 @@ macro EXTEND_TYPED_ARRAY(NAME)
"forEach", TypedArrayForEach,
"find", TypedArrayFind,
"findIndex", TypedArrayFindIndex,
- "fill", TypedArrayFill
+ "fill", TypedArrayFill,
+ "sort", TypedArraySort
]);
endmacro

Powered by Google App Engine
This is Rietveld 408576698