Author: Stephan <[email protected]>
Branch:
Changeset: r81:ee102cdfa79e
Date: 2011-05-18 18:13 +0200
http://bitbucket.org/pypy/lang-js/changeset/ee102cdfa79e/
Log: implemented Math.max
diff --git a/js/interpreter.py b/js/interpreter.py
--- a/js/interpreter.py
+++ b/js/interpreter.py
@@ -250,6 +250,11 @@
b = args[1].ToNumber(ctx)
return W_FloatNumber(min(a, b))
+def maxjs(ctx, args, this):
+ a = args[0].ToNumber(ctx)
+ b = args[1].ToNumber(ctx)
+ return W_FloatNumber(max(a, b))
+
def _ishex(ch):
return ((ch >= 'a' and ch <= 'f') or (ch >= '0' and ch <= '9') or
(ch >= 'A' and ch <= 'F'))
@@ -877,6 +882,7 @@
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_math.Put(ctx, 'max', W_Builtin(maxjs, 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
@@ -863,5 +863,10 @@
yield assertv, "Math.min(0, 2);", 0
yield assertv, "Math.min(-1, 1);", -1
+def test_math_max():
+ yield assertv, "Math.max(1, 2);", 2
+ yield assertv, "Math.max(0, 2);", 2
+ yield assertv, "Math.max(-1, 1);", 1
+
def test_date_get_time():
yield assertv, "var i = new Date(); i.valueOf() == i.getTime()", True
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit