Commit 6682290d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Support ES5 Array.prototype.sort arguments handling.

parent 8a9bbe49
......@@ -685,23 +685,22 @@ static HRESULT Array_sort(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigne
if(FAILED(hres))
return hres;
if(argc > 1) {
if(argc >= 1) {
if(is_object_instance(argv[0])) {
if(argc > 1 && ctx->version < SCRIPTLANGUAGEVERSION_ES5) {
WARN("invalid arg_cnt %d\n", argc);
return E_FAIL;
}
if(argc == 1) {
if(!is_object_instance(argv[0])) {
WARN("arg is not dispatch\n");
return E_FAIL;
return JS_E_JSCRIPT_EXPECTED;
}
cmp_func = iface_to_jsdisp(get_object(argv[0]));
if(!cmp_func || !is_class(cmp_func, JSCLASS_FUNCTION)) {
WARN("cmp_func is not a function\n");
if(cmp_func)
jsdisp_release(cmp_func);
return E_FAIL;
return JS_E_JSCRIPT_EXPECTED;
}
}else if(ctx->version >= SCRIPTLANGUAGEVERSION_ES5 ? !is_undefined(argv[0]) : !is_null(argv[0])) {
WARN("invalid arg %s\n", debugstr_jsval(argv[0]));
return JS_E_JSCRIPT_EXPECTED;
}
}
......
......@@ -1039,6 +1039,19 @@ tmp = [5,3,"2.5",2,true,false,-1];
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
tmp = [3,1,2].sort(function(x,y) { return y-x; }).join();
ok(tmp === "3,2,1", "reverse sorted [3,1,2] = " + tmp);
tmp = [3,1,2].sort(null).join();
ok(tmp === "1,2,3", "null sorted [3,1,2] = " + tmp);
try {
tmp = [3,1,2].sort(function(x,y) { return y-x; }, 1, 2, 3);
ok(false, "expected sort(undefined) exception");
} catch(e) {
ok(e.name === "TypeError", "got exception " + e.name);
}
arr = [5,false,2,0,"abc",3,"a",-1];
tmp = arr.sort();
ok(tmp === arr, "tmp !== arr");
......
......@@ -188,6 +188,25 @@ function test_array_map() {
next_test();
}
function test_array_sort() {
var r;
r = [3,1,2].sort(function(x,y) { return y-x; }, 1, 2, 3, true, undefined ).join();
ok(r === "3,2,1", "reverse sorted [3,1,2] = " + r);
r = [3,1,2].sort(undefined).join();
ok(r === "1,2,3", "null sorted [3,1,2] = " + r);
try {
r = [3,1,2].sort(null);
ok(false, "expected sort(null) exception");
}catch(e) {
ok(e.name === "TypeError", "got exception " + e.name);
}
next_test();
}
function test_identifier_keywords() {
var o = {
if: 1,
......@@ -883,6 +902,7 @@ var tests = [
test_array_forEach,
test_isArray,
test_array_map,
test_array_sort,
test_identifier_keywords,
test_getOwnPropertyDescriptor,
test_defineProperty,
......
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