From e690d31ee365bebde97acf24035fc028622fbe2d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 2 Jan 2020 12:34:57 +0100 Subject: [PATCH] Issue 122: Allow floating point return values from Array.sort callback. --- jsarray.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jsarray.c b/jsarray.c index b6cc343..03963cd 100644 --- a/jsarray.c +++ b/jsarray.c @@ -259,6 +259,7 @@ static int sortcmp(const void *avoid, const void *bvoid) 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 @@ static int sortcmp(const void *avoid, const void *bvoid) 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);