jscript: Added Array.push implementation.

This commit is contained in:
Jacek Caban 2008-09-21 15:35:58 +02:00 committed by Alexandre Julliard
parent 91b798ddf8
commit 34e82951c3
2 changed files with 34 additions and 2 deletions

View File

@ -89,11 +89,35 @@ static HRESULT Array_pop(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *
return E_NOTIMPL;
}
/* ECMA-262 3rd Edition 15.4.4.7 */
static HRESULT Array_push(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
DWORD length = 0;
int i, n;
HRESULT hres;
TRACE("\n");
if(dispex->builtin_info->class == JSCLASS_ARRAY) {
length = ((ArrayInstance*)dispex)->length;
}else {
FIXME("not Array this\n");
return E_NOTIMPL;
}
n = dp->cArgs - dp->cNamedArgs;
for(i=0; i < n; i++) {
hres = jsdisp_propput_idx(dispex, length+i, lcid, get_arg(dp, i), ei, sp);
if(FAILED(hres))
return hres;
}
if(retv) {
V_VT(retv) = VT_I4;
V_I4(retv) = length+n;
}
return S_OK;
}
static HRESULT Array_reverse(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,

View File

@ -60,4 +60,12 @@ ok(typeof(arr) === "object", "arr (6) is not object");
ok((arr.length === 6), "arr.length is not 6");
ok(arr["0"] === undefined, "arr[0] is not undefined");
ok(arr.push() === 6, "arr.push() !== 6");
ok(arr.push(1) === 7, "arr.push(1) !== 7");
ok(arr[6] === 1, "arr[6] != 1");
ok(arr.length === 7, "arr.length != 10");
ok(arr.push(true, 'b', false) === 10, "arr.push(true, 'b', false) !== 10");
ok(arr[8] === "b", "arr[8] != 'b'");
ok(arr.length === 10, "arr.length != 10");
reportSuccess();