From 50a24a4a1378e9bca1b6ff65055ab6d186048ee9 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Sun, 21 Sep 2008 15:45:00 +0200 Subject: [PATCH] jscript: Added Math.min implementation. --- dlls/jscript/math.c | 37 +++++++++++++++++++++++++++++++++++-- dlls/jscript/tests/api.js | 9 +++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index 8454cfa87e3..a2aa6a9a7da 100644 --- a/dlls/jscript/math.c +++ b/dlls/jscript/math.c @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + #include "jscript.h" #include "wine/debug.h" @@ -182,11 +184,42 @@ static HRESULT Math_max(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d return E_NOTIMPL; } +/* ECMA-262 3rd Edition 15.8.2.12 */ static HRESULT Math_min(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + DOUBLE min, d; + VARIANT v; + DWORD i; + HRESULT hres; + + TRACE("\n"); + + /* FIXME: Handle NaN */ + + if(!arg_cnt(dp)) { + FIXME("arg_cnt = 0\n"); + return E_NOTIMPL; + } + + hres = to_number(dispex->ctx, get_arg(dp, 0), ei, &v); + if(FAILED(hres)) + return hres; + + min = num_val(&v); + for(i=1; i < arg_cnt(dp); i++) { + hres = to_number(dispex->ctx, get_arg(dp, i), ei, &v); + if(FAILED(hres)) + return hres; + + d = num_val(&v); + if(d < min) + min = d; + } + + if(retv) + num_set_val(retv, min); + return S_OK; } static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 04515e3c78c..93f131d855f 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -246,4 +246,13 @@ ok(Number() === 0, "Number() = " + Number()); ok(Number(false) === 0, "Number(false) = " + Number(false)); ok(Number("43") === 43, "Number('43') = " + Number("43")); +tmp = Math.min(1); +ok(tmp === 1, "Math.min(1) = " + tmp); + +tmp = Math.min(1, false); +ok(tmp === 0, "Math.min(1, false) = " + tmp); + +tmp = Math.min(1, false, true, null, -3); +ok(tmp === -3, "Math.min(1, false, true, null, -3) = " + tmp); + reportSuccess();