mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-22 03:43:58 +00:00
ECMA fix to (117144).
Array.prototype.sort(comparefn) was casting the result of the compare to an int, which lost when the compare function returned (ecma-valid) strange double values. These now get clamped to -1, 0, 1.
This commit is contained in:
parent
df793a8c99
commit
9e50a5d27b
@ -622,10 +622,22 @@ sort_compare(const void *a, const void *b, void *arg)
|
||||
ok = js_CallFunctionValue(cx,
|
||||
OBJ_GET_PARENT(cx, JSVAL_TO_OBJECT(fval)),
|
||||
fval, 2, argv, &rval);
|
||||
if (ok)
|
||||
if (ok) {
|
||||
ok = js_ValueToNumber(cx, rval, &cmp);
|
||||
if (!ok)
|
||||
/* Clamp cmp to -1, 0, 1. */
|
||||
if (JSDOUBLE_IS_NaN(cmp)) {
|
||||
/* XXX report some kind of error here? ECMA talks about
|
||||
* 'consistent compare functions' that don't return NaN, but is
|
||||
* silent about what the result should be. So we currently
|
||||
* ignore it.
|
||||
*/
|
||||
cmp = 0;
|
||||
} else if (cmp != 0) {
|
||||
cmp = cmp > 0 ? 1 : -1;
|
||||
}
|
||||
} else {
|
||||
ca->status = ok;
|
||||
}
|
||||
}
|
||||
return (int)cmp;
|
||||
}
|
||||
|
@ -622,10 +622,22 @@ sort_compare(const void *a, const void *b, void *arg)
|
||||
ok = js_CallFunctionValue(cx,
|
||||
OBJ_GET_PARENT(cx, JSVAL_TO_OBJECT(fval)),
|
||||
fval, 2, argv, &rval);
|
||||
if (ok)
|
||||
if (ok) {
|
||||
ok = js_ValueToNumber(cx, rval, &cmp);
|
||||
if (!ok)
|
||||
/* Clamp cmp to -1, 0, 1. */
|
||||
if (JSDOUBLE_IS_NaN(cmp)) {
|
||||
/* XXX report some kind of error here? ECMA talks about
|
||||
* 'consistent compare functions' that don't return NaN, but is
|
||||
* silent about what the result should be. So we currently
|
||||
* ignore it.
|
||||
*/
|
||||
cmp = 0;
|
||||
} else if (cmp != 0) {
|
||||
cmp = cmp > 0 ? 1 : -1;
|
||||
}
|
||||
} else {
|
||||
ca->status = ok;
|
||||
}
|
||||
}
|
||||
return (int)cmp;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user