Commit 346619d0 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

jscript: Added Array length setting implementation.

parent eeeb349e
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <math.h>
#include "jscript.h" #include "jscript.h"
#include "wine/debug.h" #include "wine/debug.h"
...@@ -60,6 +62,32 @@ static HRESULT Array_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM ...@@ -60,6 +62,32 @@ static HRESULT Array_length(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAM
V_VT(retv) = VT_I4; V_VT(retv) = VT_I4;
V_I4(retv) = This->length; V_I4(retv) = This->length;
break; 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: default:
FIXME("unimplemented flags %x\n", flags); FIXME("unimplemented flags %x\n", flags);
return E_NOTIMPL; return E_NOTIMPL;
......
...@@ -1010,3 +1010,19 @@ HRESULT disp_propget(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexce ...@@ -1010,3 +1010,19 @@ HRESULT disp_propget(IDispatch *disp, DISPID id, LCID lcid, VARIANT *val, jsexce
return hres; 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);
}
...@@ -132,6 +132,7 @@ HRESULT jsdisp_propput_idx(DispatchEx*,DWORD,LCID,VARIANT*,jsexcept_t*,IServiceP ...@@ -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_name(DispatchEx*,LPCWSTR,LCID,VARIANT*,jsexcept_t*,IServiceProvider*);
HRESULT jsdisp_propget_idx(DispatchEx*,DWORD,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_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, HRESULT create_builtin_function(script_ctx_t*,builtin_invoke_t,const builtin_info_t*,DWORD,
DispatchEx*,DispatchEx**); DispatchEx*,DispatchEx**);
......
...@@ -494,6 +494,13 @@ ok(arr.sort() === arr, "arr.sort() !== arr"); ...@@ -494,6 +494,13 @@ ok(arr.sort() === arr, "arr.sort() !== arr");
for(var i=0; i < arr.length; i++) for(var i=0; i < arr.length; i++)
ok(arr[i] === tmp[i], "arr[" + i + "] = " + arr[i] + " expected " + tmp[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.valueOf === Object.prototype.valueOf, "arr.valueOf !== Object.prototype.valueOf");
ok(arr === arr.valueOf(), "arr !== arr.valueOf"); ok(arr === arr.valueOf(), "arr !== arr.valueOf");
......
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