diff --git a/dlls/jscript/array.c b/dlls/jscript/array.c index c131865be1..18ee3f540d 100644 --- a/dlls/jscript/array.c +++ b/dlls/jscript/array.c @@ -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, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 45765edf44..c76a48598e 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -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();