diff options
author | Luke <luke.wilde@live.co.uk> | 2021-06-18 09:52:13 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-18 10:29:33 +0100 |
commit | 02de3cbce3379eae34c642995cdcad34e2785ed7 (patch) | |
tree | 963f053aae66f7248f122e3361623812892ad6ba /Userland/Libraries | |
parent | b6a74b6bd93f1cfcd11cca9608970f5856acce00 (diff) | |
download | serenity-02de3cbce3379eae34c642995cdcad34e2785ed7.zip |
LibJS: Add Number.parseInt
This is initialized to be the same function object as the initial value
of the parseInt function on the global object.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/Number/Number.parseInt.js | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index c9f17b6ee1..5962b579cf 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -42,6 +42,7 @@ void NumberConstructor::initialize(GlobalObject& global_object) define_native_function(vm.names.isInteger, is_integer, 1, attr); define_native_function(vm.names.isNaN, is_nan, 1, attr); define_native_function(vm.names.isSafeInteger, is_safe_integer, 1, attr); + define_property(vm.names.parseInt, global_object.get(vm.names.parseInt), attr); define_property(vm.names.parseFloat, global_object.get(vm.names.parseFloat), attr); define_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0); define_property(vm.names.MAX_VALUE, Value(NumericLimits<double>::max()), 0); diff --git a/Userland/Libraries/LibJS/Tests/builtins/Number/Number.parseInt.js b/Userland/Libraries/LibJS/Tests/builtins/Number/Number.parseInt.js new file mode 100644 index 0000000000..18a1ed1faa --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Number/Number.parseInt.js @@ -0,0 +1,5 @@ +test("basic functionality", () => { + // Ensuring it's the same function as the global + // parseInt() is enough as that already has tests :^) + expect(Number.parseInt).toBe(parseInt); +}); |