Commit adb4e83e authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Fixed sort_cmp for non-string arguments.

parent 06b6e3bd
......@@ -677,29 +677,31 @@ static HRESULT sort_cmp(script_ctx_t *ctx, DispatchEx *cmp_func, VARIANT *v1, VA
*cmp = V_I4(&tmp);
else
*cmp = V_R8(&tmp) > 0.0 ? 1 : -1;
}else if(is_num_vt(V_VT(v1))) {
if(is_num_vt(V_VT(v2))) {
DOUBLE d = num_val(v1)-num_val(v2);
if(d > 0.0)
*cmp = 1;
else if(d < -0.0)
*cmp = -1;
else
*cmp = 0;
}else {
*cmp = -1;
}
}else if(is_num_vt(V_VT(v2))) {
*cmp = 1;
}else if(V_VT(v1) == VT_BSTR) {
if(V_VT(v2) == VT_BSTR)
*cmp = strcmpW(V_BSTR(v1), V_BSTR(v2));
}else if(V_VT(v1) == VT_EMPTY) {
*cmp = V_VT(v2) == VT_EMPTY ? 0 : 1;
}else if(V_VT(v2) == VT_EMPTY) {
*cmp = -1;
}else if(is_num_vt(V_VT(v1)) && is_num_vt(V_VT(v2))) {
DOUBLE d = num_val(v1)-num_val(v2);
if(d > 0.0)
*cmp = 1;
else
*cmp = -1;
}else if(V_VT(v2) == VT_BSTR) {
*cmp = 1;
*cmp = d < -0.0 ? -1 : 0;
}else {
*cmp = 0;
BSTR x, y;
hres = to_string(ctx, v1, ei, &x);
if(FAILED(hres))
return hres;
hres = to_string(ctx, v2, ei, &y);
if(SUCCEEDED(hres)) {
*cmp = strcmpW(x, y);
SysFreeString(y);
}
SysFreeString(x);
if(FAILED(hres))
return hres;
}
return S_OK;
......
......@@ -704,6 +704,27 @@ tmp = arr.sort();
ok(arr === tmp, "tmp !== arr");
ok(arr[0]===1 && arr[1]==="aa" && arr[2]===undefined, "arr is sorted incorectly");
tmp = [["bb","aa"],["ab","aa"]].sort().toString();
ok(tmp === "ab,aa,bb,aa", "sort() = " + tmp);
tmp = [["bb","aa"],"ab"].sort().toString();
ok(tmp === "ab,bb,aa", "sort() = " + tmp);
tmp = [["bb","aa"],"cc"].sort().toString();
ok(tmp === "bb,aa,cc", "sort() = " + tmp);
tmp = [2,"1"].sort().toString();
ok(tmp === "1,2", "sort() = " + tmp);
tmp = ["2",1].sort().toString();
ok(tmp === "1,2", "sort() = " + tmp);
tmp = [,,0,"z"].sort().toString();
ok(tmp === "0,z,,", "sort() = " + tmp);
tmp = ["a,b",["a","a"],["a","c"]].sort().toString();
ok(tmp === "a,a,a,b,a,c", "sort() = " + tmp);
arr = ["1", "2", "3"];
arr.length = 1;
ok(arr.length === 1, "arr.length = " + arr.length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment