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