Commit f30de9b9 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

jscript: Added Number.valueOf implementation.

parent 7526b880
......@@ -105,8 +105,18 @@ static HRESULT Number_toPrecision(DispatchEx *dispex, LCID lcid, WORD flags, DIS
static HRESULT Number_valueOf(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp)
{
FIXME("\n");
return E_NOTIMPL;
TRACE("\n");
if(!is_class(dispex, JSCLASS_NUMBER)) {
FIXME("throw TypeError\n");
return E_FAIL;
}
if(retv) {
NumberInstance *number = (NumberInstance*)dispex;
*retv = number->num;
}
return S_OK;
}
static HRESULT Number_hasOwnProperty(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp,
......@@ -198,19 +208,13 @@ static HRESULT NumberConstr_value(DispatchEx *dispex, LCID lcid, WORD flags, DIS
case DISPATCH_CONSTRUCT: {
DispatchEx *obj;
switch(arg_cnt(dp)) {
case 0:
V_VT(&num) = VT_I4;
V_I4(&num) = 0;
break;
case 1:
if(arg_cnt(dp)) {
hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &num);
if(FAILED(hres))
return hres;
break;
default:
FIXME("unimplemented args\n");
return E_NOTIMPL;
}else {
V_VT(&num) = VT_I4;
V_I4(&num) = 0;
}
hres = create_number(dispex->ctx, &num, &obj);
......@@ -258,6 +262,7 @@ HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx **ret)
if(FAILED(hres))
return hres;
V_VT(&number->num) = VT_I4;
hres = create_builtin_function(ctx, NumberConstr_value, PROPF_CONSTR, &number->dispex, ret);
jsdisp_release(&number->dispex);
......
......@@ -362,6 +362,15 @@ ok(Number() === 0, "Number() = " + Number());
ok(Number(false) === 0, "Number(false) = " + Number(false));
ok(Number("43") === 43, "Number('43') = " + Number("43"));
tmp = (new Number(1)).valueOf();
ok(tmp === 1, "(new Number(1)).valueOf = " + tmp);
tmp = (new Number(1,2)).valueOf();
ok(tmp === 1, "(new Number(1,2)).valueOf = " + tmp);
tmp = (new Number()).valueOf();
ok(tmp === 0, "(new Number()).valueOf = " + tmp);
tmp = Number.prototype.valueOf();
ok(tmp === 0, "Number.prototype.valueOf = " + tmp);
tmp = Math.min(1);
ok(tmp === 1, "Math.min(1) = " + tmp);
......
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