Module: wine Branch: master Commit: a20a9166a2b0cde1ad2d04a67b19434becd76fef URL: http://source.winehq.org/git/wine.git/?a=commit;h=a20a9166a2b0cde1ad2d04a67b...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Jan 22 13:47:00 2009 +0100
jscript: Added Math.random implementation.
---
dlls/jscript/Makefile.in | 2 +- dlls/jscript/math.c | 16 ++++++++++++++-- dlls/jscript/tests/api.js | 8 ++++++++ 3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/dlls/jscript/Makefile.in b/dlls/jscript/Makefile.in index 5d4506a..5d7ee69 100644 --- a/dlls/jscript/Makefile.in +++ b/dlls/jscript/Makefile.in @@ -3,7 +3,7 @@ TOPOBJDIR = ../.. SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = jscript.dll -IMPORTS = oleaut32 kernel32 +IMPORTS = oleaut32 advapi32 kernel32
RC_SRCS = rsrc.rc
diff --git a/dlls/jscript/math.c b/dlls/jscript/math.c index f2a3d0c..9c1a56b 100644 --- a/dlls/jscript/math.c +++ b/dlls/jscript/math.c @@ -20,8 +20,10 @@ #include "wine/port.h"
#include <math.h> +#include <limits.h>
#include "jscript.h" +#include "ntsecapi.h"
#include "wine/debug.h"
@@ -352,11 +354,21 @@ static HRESULT Math_pow(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *d return S_OK; }
+/* ECMA-262 3rd Edition 15.8.2.14 */ static HRESULT Math_random(DispatchEx *dispex, LCID lcid, WORD flags, DISPPARAMS *dp, VARIANT *retv, jsexcept_t *ei, IServiceProvider *sp) { - FIXME("\n"); - return E_NOTIMPL; + UINT r; + + TRACE("\n"); + + if(!RtlGenRandom(&r, sizeof(r))) + return E_UNEXPECTED; + + if(retv) + num_set_val(retv, (DOUBLE)r/(DOUBLE)UINT_MAX); + + return S_OK; }
/* ECMA-262 3rd Edition 15.8.2.15 */ diff --git a/dlls/jscript/tests/api.js b/dlls/jscript/tests/api.js index 16fba15..7fd20a6 100644 --- a/dlls/jscript/tests/api.js +++ b/dlls/jscript/tests/api.js @@ -585,6 +585,14 @@ ok(tmp === 2, "Math.pow(2, 2) = " + tmp); tmp = Math.pow(2, 2, 3); ok(tmp === 4, "Math.pow(2, 2, 3) = " + tmp);
+tmp = Math.random(); +ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp)); +ok(0 <= tmp && tmp <= 1, "Math.random() = " + tmp); + +tmp = Math.random(100); +ok(typeof(tmp) == "number", "typeof(tmp) = " + typeof(tmp)); +ok(0 <= tmp && tmp <= 1, "Math.random(100) = " + tmp); + var func = function (a) { var a = 1; if(a) return;