[pypy-commit] lang-js default: added Math.min
stepahn
noreply at buildbot.pypy.org
Wed May 18 19:27:55 CEST 2011
Author: Stephan <stephan at stzal.com>
Branch:
Changeset: r79:1666384efb59
Date: 2011-05-18 18:09 +0200
http://bitbucket.org/pypy/lang-js/changeset/1666384efb59/
Log: added Math.min
diff --git a/js/interpreter.py b/js/interpreter.py
--- a/js/interpreter.py
+++ b/js/interpreter.py
@@ -245,6 +245,11 @@
def randomjs(ctx, args, this):
return W_FloatNumber(random.random())
+def minjs(ctx, args, this):
+ a = args[0].ToNumber(ctx)
+ b = args[1].ToNumber(ctx)
+ return W_FloatNumber(min(a, b))
+
def _ishex(ch):
return ((ch >= 'a' and ch <= 'f') or (ch >= '0' and ch <= '9') or
(ch >= 'A' and ch <= 'F'))
@@ -871,6 +876,7 @@
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_math.Put(ctx, 'min', W_Builtin(minjs, 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
@@ -857,3 +857,8 @@
def test_math_random():
yield assertv, "var x = Math.random(); var y = Math.random(); x == y;", False
+
+def test_math_min():
+ yield assertv, "Math.min(1, 2);", 1
+ yield assertv, "Math.min(0, 2);", 0
+ yield assertv, "Math.min(-1, 1);", -1
More information about the pypy-commit
mailing list