summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.cpp5
-rw-r--r--Libraries/LibJS/Tests/isNaN.js28
2 files changed, 30 insertions, 3 deletions
diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp
index 317fd32eed..7a1f062675 100644
--- a/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -137,9 +137,8 @@ Value GlobalObject::gc(Interpreter& interpreter)
Value GlobalObject::is_nan(Interpreter& interpreter)
{
- if (interpreter.argument_count() < 1)
- return js_undefined();
- return Value(interpreter.argument(0).to_number().is_nan());
+ auto value = interpreter.argument(0).to_number();
+ return Value(value.is_nan());
}
}
diff --git a/Libraries/LibJS/Tests/isNaN.js b/Libraries/LibJS/Tests/isNaN.js
new file mode 100644
index 0000000000..7519b68fd2
--- /dev/null
+++ b/Libraries/LibJS/Tests/isNaN.js
@@ -0,0 +1,28 @@
+load("test-common.js");
+
+try {
+ assert(isNaN.length === 1);
+
+ assert(isNaN(0) === false);
+ assert(isNaN(42) === false);
+ assert(isNaN("") === false);
+ assert(isNaN("0") === false);
+ assert(isNaN("42") === false);
+ assert(isNaN(true) === false);
+ assert(isNaN(false) === false);
+ assert(isNaN(null) === false);
+ assert(isNaN([]) === false);
+ assert(isNaN(Infinity) === false);
+ assert(isNaN(-Infinity) === false);
+
+ assert(isNaN() === true);
+ assert(isNaN(NaN) === true);
+ assert(isNaN(undefined) === true);
+ assert(isNaN("foo") === true);
+ assert(isNaN({}) === true);
+ assert(isNaN([1, 2, 3]) === true);
+
+ console.log("PASS");
+} catch (e) {
+ console.log("FAIL: " + e.message);
+}