Commit 06064d22 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Make Array.push generic.

parent 5c819cb2
......@@ -46,6 +46,29 @@ static const WCHAR unshiftW[] = {'u','n','s','h','i','f','t',0};
static const WCHAR default_separatorW[] = {',',0};
static HRESULT get_jsdisp_length(DispatchEx *obj, LCID lcid, jsexcept_t *ei, DWORD *ret)
{
VARIANT var;
HRESULT hres;
hres = jsdisp_propget_name(obj, lengthW, lcid, &var, ei, NULL/*FIXME*/);
if(FAILED(hres))
return hres;
hres = to_uint32(obj->ctx, &var, ei, ret);
VariantClear(&var);
return hres;
}
static HRESULT set_jsdisp_length(DispatchEx *obj, LCID lcid, jsexcept_t *ei, DWORD length)
{
VARIANT var;
V_VT(&var) = VT_I4;
V_I4(&var) = length;
return jsdisp_propput_name(obj, lengthW, lcid, &var, ei, NULL/*FIXME*/);
}
static HRESULT Array_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
......@@ -380,17 +403,24 @@ static HRESULT Array_push(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS
if(dispex->builtin_info->class == JSCLASS_ARRAY) {
length = ((ArrayInstance*)dispex)->length;
}else {
FIXME("not Array this\n");
return E_NOTIMPL;
hres = get_jsdisp_length(dispex, lcid, ei, &length);
if(FAILED(hres))
return hres;
}
n = dp->cArgs - dp->cNamedArgs;
n = arg_cnt(dp);
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(!is_class(dispex, JSCLASS_ARRAY)) {
hres = set_jsdisp_length(dispex, lcid, ei, length+n);
if(FAILED(hres))
return hres;
}
if(retv) {
V_VT(retv) = VT_I4;
V_I4(retv) = length+n;
......
......@@ -492,6 +492,19 @@ 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");
var arr = new Object();
arr.push = Array.prototype.push;
arr.length = 6;
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");
arr = [3,4,5];
tmp = arr.pop();
ok(arr.length === 2, "arr.length = " + arr.length);
......
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