jscript: Make Array.pop generic.

This commit is contained in:
Piotr Caban 2010-01-20 17:12:38 +01:00 committed by Alexandre Julliard
parent 9a9c075ee9
commit 91dcc245f9
2 changed files with 29 additions and 26 deletions

View File

@ -372,52 +372,42 @@ static HRESULT Array_join(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPAR
return hres;
}
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *caller)
{
DispatchEx *jsthis;
VARIANT val;
DWORD length;
WCHAR buf[14];
DISPID id;
HRESULT hres;
static const WCHAR formatW[] = {'%','d',0};
TRACE("\n");
if(is_vclass(jsthis, JSCLASS_ARRAY)) {
ArrayInstance *array = array_from_vdisp(jsthis);
length = array->length;
}else {
FIXME("not Array this\n");
return E_NOTIMPL;
}
hres = get_length(ctx, vthis, ei, &jsthis, &length);
if(FAILED(hres))
return hres;
if(!length) {
hres = set_length(jsthis, ei, 0);
if(FAILED(hres))
return hres;
if(retv)
V_VT(retv) = VT_EMPTY;
return S_OK;
}
sprintfW(buf, formatW, --length);
hres = jsdisp_get_id(jsthis->u.jsdisp, buf, 0, &id);
length--;
hres = jsdisp_propget_idx(jsthis, length, &val, ei, caller);
if(SUCCEEDED(hres)) {
hres = jsdisp_propget(jsthis->u.jsdisp, id, &val, ei, caller);
if(FAILED(hres))
return hres;
hres = IDispatchEx_DeleteMemberByDispID(jsthis->u.dispex, id);
}else if(hres == DISP_E_UNKNOWNNAME) {
hres = jsdisp_delete_idx(jsthis, length);
} else if(hres == DISP_E_UNKNOWNNAME) {
V_VT(&val) = VT_EMPTY;
hres = S_OK;
}else {
} else
return hres;
}
if(SUCCEEDED(hres)) {
ArrayInstance *array = array_from_vdisp(jsthis);
array->length = length;
}
if(SUCCEEDED(hres))
hres = set_length(jsthis, ei, length);
if(FAILED(hres)) {
VariantClear(&val);
@ -428,6 +418,7 @@ static HRESULT Array_pop(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPAR
*retv = val;
else
VariantClear(&val);
return S_OK;
}

View File

@ -618,6 +618,12 @@ 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.pop = Array.prototype.pop;
ok(arr.pop() === false, "arr.pop() !== false");
ok(arr[8] === "b", "arr[8] !== 'b'");
ok(arr.pop() === 'b', "arr.pop() !== 'b'");
ok(arr[8] === undefined, "arr[8] !== undefined");
arr = [3,4,5];
tmp = arr.pop();
ok(arr.length === 2, "arr.length = " + arr.length);
@ -633,6 +639,11 @@ for(tmp in arr)
tmp = arr.pop();
ok(arr.length === 0, "arr.length = " + arr.length);
ok(tmp === undefined, "tmp = " + tmp);
arr = new Object();
arr.pop = Array.prototype.pop;
tmp = arr.pop();
ok(arr.length === 0, "arr.length = " + arr.length);
ok(tmp === undefined, "tmp = " + tmp);
arr = [,,,,,];
tmp = arr.pop();
ok(arr.length === 5, "arr.length = " + arr.length);
@ -1891,6 +1902,7 @@ testArrayHostThis("splice");
testArrayHostThis("unshift");
testArrayHostThis("reverse");
testArrayHostThis("join");
testArrayHostThis("pop");
function testObjectInherit(obj, constr, ts, tls, vo) {
ok(obj instanceof Object, "obj is not instance of Object");