jscript: Make Array.join generic.

This commit is contained in:
Piotr Caban 2010-01-15 08:17:50 +01:00 committed by Alexandre Julliard
parent 6f61893685
commit db137cc975
2 changed files with 18 additions and 9 deletions

View File

@ -342,20 +342,18 @@ static HRESULT array_join(script_ctx_t *ctx, DispatchEx *array, DWORD length, co
}
/* ECMA-262 3rd Edition 15.4.4.5 */
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
DispatchEx *jsthis;
DWORD length;
HRESULT hres;
TRACE("\n");
if(is_vclass(jsthis, JSCLASS_ARRAY)) {
length = array_from_vdisp(jsthis)->length;
}else {
FIXME("dispid is not Array\n");
return E_NOTIMPL;
}
hres = get_length(ctx, vthis, ei, &jsthis, &length);
if(FAILED(hres))
return hres;
if(arg_cnt(dp)) {
BSTR sep;
@ -364,11 +362,11 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
if(FAILED(hres))
return hres;
hres = array_join(ctx, jsthis->u.jsdisp, length, sep, retv, ei, caller);
hres = array_join(ctx, jsthis, length, sep, retv, ei, caller);
SysFreeString(sep);
}else {
hres = array_join(ctx, jsthis->u.jsdisp, length, default_separatorW, retv, ei, caller);
hres = array_join(ctx, jsthis, length, default_separatorW, retv, ei, caller);
}
return hres;

View File

@ -654,6 +654,16 @@ ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
tmp = arr.toString("test");
ok(tmp === "1,2,,false,,,a", "arr.toString() = " + tmp);
arr = new Object();
arr.length = 3;
arr[0] = "aa";
arr[2] = 2;
arr[7] = 3;
arr.join = Array.prototype.join;
tmp = arr.join(",");
ok(arr.length === 3, "arr.length = " + arr.length);
ok(tmp === "aa,,2", "tmp = " + tmp);
arr = [5,true,2,-1,3,false,"2.5"];
tmp = arr.sort(function(x,y) { return y-x; });
ok(tmp === arr, "tmp !== arr");
@ -1880,6 +1890,7 @@ testArrayHostThis("slice");
testArrayHostThis("splice");
testArrayHostThis("unshift");
testArrayHostThis("reverse");
testArrayHostThis("join");
function testObjectInherit(obj, constr, ts, tls, vo) {
ok(obj instanceof Object, "obj is not instance of Object");