Author: Stephan <[email protected]>
Branch:
Changeset: r78:4b47771526e6
Date: 2011-05-18 18:08 +0200
http://bitbucket.org/pypy/lang-js/changeset/4b47771526e6/
Log: added Math.random()
diff --git a/js/interpreter.py b/js/interpreter.py
--- a/js/interpreter.py
+++ b/js/interpreter.py
@@ -1,5 +1,6 @@
import math
+import random
from js.jsparser import parse, ParseError
from js.astbuilder import ASTBuilder
from js.jsobj import global_context, W_Object,\
@@ -241,6 +242,9 @@
def versionjs(ctx, args, this):
return w_Undefined
+def randomjs(ctx, args, this):
+ return W_FloatNumber(random.random())
+
def _ishex(ch):
return ((ch >= 'a' and ch <= 'f') or (ch >= '0' and ch <= '9') or
(ch >= 'A' and ch <= 'F'))
@@ -866,6 +870,7 @@
w_math.Put(ctx, 'PI', W_FloatNumber(math.pi), flags=allon)
w_math.Put(ctx, 'SQRT1_2', W_FloatNumber(math.sqrt(0.5)), flags=allon)
w_math.Put(ctx, 'SQRT2', W_FloatNumber(math.sqrt(2)), flags=allon)
+ w_math.Put(ctx, 'random', W_Builtin(randomjs, Class='function'))
w_Global.Put(ctx, 'version', W_Builtin(versionjs), flags=allon)
#Date
diff --git a/js/test/test_interp.py b/js/test/test_interp.py
--- a/js/test/test_interp.py
+++ b/js/test/test_interp.py
@@ -845,7 +845,7 @@
""", 2
def test_compare_string_null():
- assertv, """
+ yield assertv, """
var x;
if('a' == null){
x = true;
@@ -854,3 +854,6 @@
}
x;
""", False
+
+def test_math_random():
+ yield assertv, "var x = Math.random(); var y = Math.random(); x == y;",
False
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit