ソースを参照

LibJS: Return -Infinity in Math.max() with no argument

Linus Groh 5 年 前
コミット
9e7dcaa106

+ 1 - 2
Libraries/LibJS/Runtime/MathObject.cpp

@@ -126,8 +126,7 @@ Value MathObject::round(Interpreter& interpreter)
 Value MathObject::max(Interpreter& interpreter)
 {
     if (!interpreter.argument_count()) {
-        // FIXME: I think this should return *negative* infinity.
-        return js_infinity();
+        return Value(-js_infinity().as_double());
     } else if (interpreter.argument_count() == 1) {
         return interpreter.argument(0).to_number();
     } else {

+ 1 - 0
Libraries/LibJS/Tests/Math.max.js

@@ -1,5 +1,6 @@
 try {
     assert(Math.max.length === 2);
+    assert(Math.max() === -Infinity);
     assert(Math.max(1) === 1);
     assert(Math.max(2, 1) === 2);
     assert(Math.max(1, 2, 3) === 3);