summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-05-17 15:12:50 +0100
committerAndreas Kling <kling@serenityos.org>2020-05-17 16:21:38 +0200
commit73eef31f49f6022c5a219c4c19ecaed9ac77a833 (patch)
tree50e576fb0ddcb15a328b7666069ea80613061779 /Libraries
parent6f6b089aa01ad88041f3da8120b99c03ccd9d1d4 (diff)
downloadserenity-73eef31f49f6022c5a219c4c19ecaed9ac77a833.zip
LibJS: Add Number.parseFloat()
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Runtime/NumberConstructor.cpp2
-rw-r--r--Libraries/LibJS/Tests/Number.isFinite.js1
-rw-r--r--Libraries/LibJS/Tests/Number.isNaN.js1
-rw-r--r--Libraries/LibJS/Tests/Number.parseFloat.js11
4 files changed, 14 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Libraries/LibJS/Runtime/NumberConstructor.cpp
index 26809e5431..ff99b1dc47 100644
--- a/Libraries/LibJS/Runtime/NumberConstructor.cpp
+++ b/Libraries/LibJS/Runtime/NumberConstructor.cpp
@@ -45,7 +45,7 @@ NumberConstructor::NumberConstructor()
put_native_function("isInteger", is_integer, 1, attr);
put_native_function("isNaN", is_nan, 1, attr);
put_native_function("isSafeInteger", is_safe_integer, 1, attr);
-
+ put("parseFloat", interpreter().global_object().get("parseFloat"));
put("prototype", interpreter().global_object().number_prototype(), 0);
put("length", Value(1), Attribute::Configurable);
put("EPSILON", Value(EPSILON), 0);
diff --git a/Libraries/LibJS/Tests/Number.isFinite.js b/Libraries/LibJS/Tests/Number.isFinite.js
index 09ae0cd9ec..892b24031a 100644
--- a/Libraries/LibJS/Tests/Number.isFinite.js
+++ b/Libraries/LibJS/Tests/Number.isFinite.js
@@ -1,6 +1,7 @@
load("test-common.js");
try {
+ assert(Number.isFinite !== isFinite);
assert(Number.isFinite.length === 1);
assert(Number.isFinite(0) === true);
diff --git a/Libraries/LibJS/Tests/Number.isNaN.js b/Libraries/LibJS/Tests/Number.isNaN.js
index 0de64012b4..bbd3a5c9c5 100644
--- a/Libraries/LibJS/Tests/Number.isNaN.js
+++ b/Libraries/LibJS/Tests/Number.isNaN.js
@@ -1,6 +1,7 @@
load("test-common.js");
try {
+ assert(Number.isNaN !== isNaN);
assert(Number.isNaN.length === 1);
assert(Number.isNaN(0) === false);
diff --git a/Libraries/LibJS/Tests/Number.parseFloat.js b/Libraries/LibJS/Tests/Number.parseFloat.js
new file mode 100644
index 0000000000..e395e43602
--- /dev/null
+++ b/Libraries/LibJS/Tests/Number.parseFloat.js
@@ -0,0 +1,11 @@
+load("test-common.js");
+
+try {
+ // Ensuring it's the same function as the global
+ // parseFloat() is enough as that already has tests :^)
+ assert(Number.parseFloat === parseFloat);
+
+ console.log("PASS");
+} catch (e) {
+ console.log("FAIL: " + e);
+}