diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.cpp b/Userland/Libraries/LibJS/Runtime/BigInt.cpp index 8c0b8a443f..6cf4306c6c 100644 --- a/Userland/Libraries/LibJS/Runtime/BigInt.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigInt.cpp @@ -22,6 +22,11 @@ BigInt::BigInt(Crypto::SignedBigInteger big_integer) VERIFY(!m_big_integer.is_invalid()); } +ErrorOr BigInt::to_string() const +{ + return String::formatted("{}n", TRY(m_big_integer.to_base(10))); +} + // 21.2.1.1.1 NumberToBigInt ( number ), https://tc39.es/ecma262/#sec-numbertobigint ThrowCompletionOr number_to_bigint(VM& vm, Value number) { diff --git a/Userland/Libraries/LibJS/Runtime/BigInt.h b/Userland/Libraries/LibJS/Runtime/BigInt.h index b5df053366..bb937a71e4 100644 --- a/Userland/Libraries/LibJS/Runtime/BigInt.h +++ b/Userland/Libraries/LibJS/Runtime/BigInt.h @@ -6,6 +6,8 @@ #pragma once +#include +#include #include #include #include @@ -21,7 +23,9 @@ public: virtual ~BigInt() override = default; Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; } - const DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base_deprecated(10)); } + + ErrorOr to_string() const; + DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base_deprecated(10)); } private: explicit BigInt(Crypto::SignedBigInteger);