jscript: Added Array length setting implementation.

This commit is contained in:
Piotr Caban 2009-07-14 02:06:59 +02:00 committed by Alexandre Julliard
parent eeeb349eee
commit 346619d093
4 changed files with 52 additions and 0 deletions

View File

@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <math.h>
#include "jscript.h"
#include "wine/debug.h"
@ -60,6 +62,32 @@ static HRESULT Array_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
V_VT(retv) = VT_I4;
V_I4(retv) = This->length;
break;
case DISPATCH_PROPERTYPUT: {
VARIANT num;
DOUBLE len = -1;
DWORD i;
HRESULT hres;
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &num);
if(V_VT(&num) == VT_I4)
len = V_I4(&num);
else
len = floor(V_R8(&num));
if(len!=(DWORD)len) {
FIXME("Throw RangeError\n");
return E_FAIL;
}
for(i=len; i<This->length; i++) {
hres = jsdisp_delete_idx(dispex, i);
if(FAILED(hres))
return hres;
}
This->length = len;
break;
}
default:
FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL;

View File

@ -1010,3 +1010,19 @@ HRESULT disp_propget(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexce
return hres;
}
HRESULT jsdisp_delete_idx(DispatchEx *obj, DWORD idx)
{
static const WCHAR formatW[] = {'%','d',0};
WCHAR buf[12];
dispex_prop_t *prop;
HRESULT hres;
sprintfW(buf, formatW, idx);
hres = find_prop_name(obj, buf, &prop);
if(FAILED(hres) || !prop)
return hres;
return delete_prop(prop);
}

View File

@ -132,6 +132,7 @@ HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceP
HRESULT jsdisp_propget_name(DispatchEx*,LPCWSTR,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_get_id(DispatchEx*,const WCHAR*,DWORD,DISPID*);
HRESULT jsdisp_delete_idx(DispatchEx*,DWORD);
HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_info_t*,DWORD,
DispatchEx*,DispatchEx**);

View File

@ -494,6 +494,13 @@ ok(arr.sort() === arr, "arr.sort() !== arr");
for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[i]);
arr = ["1", "2", "3"];
arr.length = 1;
ok(arr.length === 1, "arr.length = " + arr.length);
arr.length = 3;
ok(arr.length === 3, "arr.length = " + arr.length);
ok(arr.toString() === "1,,", "arr.toString() = " + arr.toString());
ok(arr.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
ok(arr === arr.valueOf(), "arr !== arr.valueOf");