From 1a97632a4e1a5f653fbfacb695b6c2b6bf9af73f Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 16 Sep 2008 20:45:45 +0200 Subject: [PATCH] jscript: Added to_object(number) implementation. --- dlls/jscript/jscript.h | 1 + dlls/jscript/jsutils.c | 8 ++++++++ dlls/jscript/number.c | 17 +++++++++++++++++ dlls/jscript/tests/lang.js | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/dlls/jscript/jscript.h b/dlls/jscript/jscript.h index 8f14e632c18..4b384c73db7 100644 --- a/dlls/jscript/jscript.h +++ b/dlls/jscript/jscript.h @@ -135,6 +135,7 @@ HRESULT create_array(script_ctx_t*,DWORD,DispatchEx**); HRESULT create_regexp_str(script_ctx_t*,const WCHAR*,DWORD,const WCHAR*,DWORD,DispatchEx**); HRESULT create_string(script_ctx_t*,const WCHAR*,DWORD,DispatchEx**); HRESULT create_bool(script_ctx_t*,VARIANT_BOOL,DispatchEx**); +HRESULT create_number(script_ctx_t*,VARIANT*,DispatchEx**); HRESULT to_primitive(script_ctx_t*,VARIANT*,jsexcept_t*,VARIANT*); HRESULT to_boolean(VARIANT*,VARIANT_BOOL*); diff --git a/dlls/jscript/jsutils.c b/dlls/jscript/jsutils.c index 01b0ef7950a..616369e6f54 100644 --- a/dlls/jscript/jsutils.c +++ b/dlls/jscript/jsutils.c @@ -258,6 +258,14 @@ HRESULT to_object(exec_ctx_t *ctx, VARIANT *v, IDispatch **disp) if(FAILED(hres)) return hres; + *disp = (IDispatch*)_IDispatchEx_(dispex); + break; + case VT_I4: + case VT_R8: + hres = create_number(ctx->parser->script, v, &dispex); + if(FAILED(hres)) + return hres; + *disp = (IDispatch*)_IDispatchEx_(dispex); break; case VT_DISPATCH: diff --git a/dlls/jscript/number.c b/dlls/jscript/number.c index b4db8639a31..108cfff1a14 100644 --- a/dlls/jscript/number.c +++ b/dlls/jscript/number.c @@ -24,6 +24,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(jscript); typedef struct { DispatchEx dispex; + + VARIANT num; } NumberInstance; static const WCHAR toStringW[] = {'t','o','S','t','r','i','n','g',0}; @@ -165,3 +167,18 @@ HRESULT create_number_constr(script_ctx_t *ctx, DispatchEx **ret) jsdisp_release(&number->dispex); return hres; } + +HRESULT create_number(script_ctx_t *ctx, VARIANT *num, DispatchEx **ret) +{ + NumberInstance *number; + HRESULT hres; + + hres = alloc_number(ctx, TRUE, &number); + if(FAILED(hres)) + return hres; + + number->num = *num; + + *ret = &number->dispex; + return S_OK; +} diff --git a/dlls/jscript/tests/lang.js b/dlls/jscript/tests/lang.js index 3ca57c027b9..e099df99aa6 100644 --- a/dlls/jscript/tests/lang.js +++ b/dlls/jscript/tests/lang.js @@ -239,6 +239,10 @@ ok("".test === true, "\"\".test is not true"); Boolean.prototype.test = true; ok(true.test === true, "true.test is not true"); +Number.prototype.test = true; +ok((0).test === true, "(0).test is not true"); +ok((0.5).test === true, "(0.5).test is not true"); + var state = ""; try { ok(state === "", "try: state = " + state);