shithub: libmujs

Download patch

ref: e690d31ee365bebde97acf24035fc028622fbe2d
parent: b4484ab18a8bca9feed3555c2b6f5d029ca2c052
author: Tor Andersson <[email protected]>
date: Thu Jan 2 07:34:57 EST 2020

Issue 122: Allow floating point return values from Array.sort callback.

--- a/jsarray.c
+++ b/jsarray.c
@@ -259,6 +259,7 @@
 	const js_Value *a = &aslot->v, *b = &bslot->v;
 	js_State *J = aslot->J;
 	const char *sx, *sy;
+	double v;
 	int c;
 
 	int unx = (a->type == JS_TUNDEFINED);
@@ -272,7 +273,8 @@
 		js_pushvalue(J, *a);
 		js_pushvalue(J, *b);
 		js_call(J, 2);
-		c = js_tonumber(J, -1);
+		v = js_tonumber(J, -1);
+		c = (v == 0) ? 0 : (v < 0) ? -1 : 1;
 		js_pop(J, 1);
 	} else {
 		js_pushvalue(J, *a);