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 */ /* 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) VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{ {
DispatchEx *jsthis;
DWORD length; DWORD length;
HRESULT hres; HRESULT hres;
TRACE("\n"); TRACE("\n");
if(is_vclass(jsthis, JSCLASS_ARRAY)) { hres = get_length(ctx, vthis, ei, &jsthis, &length);
length = array_from_vdisp(jsthis)->length; if(FAILED(hres))
}else { return hres;
FIXME("dispid is not Array\n");
return E_NOTIMPL;
}
if(arg_cnt(dp)) { if(arg_cnt(dp)) {
BSTR sep; BSTR sep;
@ -364,11 +362,11 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPA
if(FAILED(hres)) if(FAILED(hres))
return 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); SysFreeString(sep);
}else { }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; return hres;

View File

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