summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-04-26 18:31:56 +0100
committerAndreas Kling <kling@serenityos.org>2020-04-26 20:36:59 +0200
commit7bd6b58b291d016d4d79ea7b589b1828483a3c6d (patch)
tree2ac4243e36fbe27f4a455fee15dcf0bac5941f43 /Libraries/LibJS/Runtime
parentc350f5ae67f73457732386c9213db4f429857cd4 (diff)
downloadserenity-7bd6b58b291d016d4d79ea7b589b1828483a3c6d.zip
LibJS: Implement Number.isNaN()
Like the global isNaN() without the number coercion.
Diffstat (limited to 'Libraries/LibJS/Runtime')
-rw-r--r--Libraries/LibJS/Runtime/GlobalObject.cpp3
-rw-r--r--Libraries/LibJS/Runtime/NumberConstructor.cpp6
-rw-r--r--Libraries/LibJS/Runtime/NumberConstructor.h1
3 files changed, 8 insertions, 2 deletions
diff --git a/Libraries/LibJS/Runtime/GlobalObject.cpp b/Libraries/LibJS/Runtime/GlobalObject.cpp
index 0612da4669..6e289b7f56 100644
--- a/Libraries/LibJS/Runtime/GlobalObject.cpp
+++ b/Libraries/LibJS/Runtime/GlobalObject.cpp
@@ -138,8 +138,7 @@ Value GlobalObject::gc(Interpreter& interpreter)
Value GlobalObject::is_nan(Interpreter& interpreter)
{
- auto value = interpreter.argument(0).to_number();
- return Value(value.is_nan());
+ return Value(interpreter.argument(0).to_number().is_nan());
}
Value GlobalObject::is_finite(Interpreter& interpreter)
diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp
index d1e2d8b245..1c1f4cebc8 100644
--- a/Libraries/LibJS/Runtime/NumberConstructor.cpp
+++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp
@@ -41,6 +41,7 @@ NumberConstructor::NumberConstructor()
: NativeFunction("Number", *interpreter().global_object().function_prototype())
{
put_native_function("isFinite", is_finite, 1);
+ put_native_function("isNaN", is_nan, 1);
put_native_function("isSafeInteger", is_safe_integer, 1);
put("prototype", interpreter().global_object().number_prototype());
@@ -79,6 +80,11 @@ Value NumberConstructor::is_finite(Interpreter& interpreter)
return Value(interpreter.argument(0).is_finite_number());
}
+Value NumberConstructor::is_nan(Interpreter& interpreter)
+{
+ return Value(interpreter.argument(0).is_nan());
+}
+
Value NumberConstructor::is_safe_integer(Interpreter& interpreter)
{
if (!interpreter.argument(0).is_number())
diff --git a/Libraries/LibJS/Runtime/NumberConstructor.h b/Libraries/LibJS/Runtime/NumberConstructor.h
index 23557009b0..ba22130530 100644
--- a/Libraries/LibJS/Runtime/NumberConstructor.h
+++ b/Libraries/LibJS/Runtime/NumberConstructor.h
@@ -43,6 +43,7 @@ private:
virtual const char* class_name() const override { return "NumberConstructor"; }
static Value is_finite(Interpreter&);
+ static Value is_nan(Interpreter&);
static Value is_safe_integer(Interpreter&);
};