From 0e8bcbd9de6d2f824bc47662f4891ee0f241b7d8 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 11 Dec 2008 12:27:39 +0100 Subject: [PATCH] jscript: Added Math.PI implementation. --- dlls/jscript/math.c | 20 ++++++++++++++++++-- dlls/jscript/tests/api.js | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index e6b7202e1a2..ceabc36639b 100644 --- a/dlls/jscript/math.c +++ b/dlls/jscript/math.c @@ -54,6 +54,21 @@ static const WCHAR sinW[] = {'s','i','n',0}; static const WCHAR sqrtW[] = {'s','q','r','t',0}; static const WCHAR tanW[] = {'t','a','n',0}; +static HRESULT math_constant(DOUBLE val, WORD flags, VARIANT *retv) +{ + switch(flags) { + case DISPATCH_PROPERTYGET: + V_VT(retv) = VT_R8; + V_R8(retv) = val; + return S_OK; + case DISPATCH_PROPERTYPUT: + return S_OK; + } + + FIXME("unhandled flags %x\n", flags); + return E_NOTIMPL; +} + static HRESULT Math_E(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { @@ -89,11 +104,12 @@ static HRESULT Math_LN10(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS * return E_NOTIMPL; } +/* ECMA-262 3rd Edition 15.8.1.6 */ static HRESULT Math_PI(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + TRACE("\n"); + return math_constant(M_PI, flags, retv); } static HRESULT Math_SQRT2(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 2868c0f7aed..738161217ba 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -609,4 +609,9 @@ date = new Date(100); ok(date.getTime() === 100, "date.getTime() = " + date.getTime()); ok(Date.prototype.getTime() === 0, "date.prototype.getTime() = " + Date.prototype.getTime()); +ok(typeof(Math.PI) === "number", "typeof(Math.PI) = " + typeof(Math.PI)); +ok(Math.floor(Math.PI*100) === 314, "Math.PI = " + Math.PI); +Math.PI = "test"; +ok(Math.floor(Math.PI*100) === 314, "modified Math.PI = " + Math.PI); + reportSuccess();