BigInt.h 868 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/StringView.h>
  8. #include <LibCrypto/BigInt/SignedBigInteger.h>
  9. #include <LibJS/Heap/Cell.h>
  10. namespace JS {
  11. class BigInt final : public Cell {
  12. public:
  13. explicit BigInt(Crypto::SignedBigInteger);
  14. virtual ~BigInt() override = default;
  15. Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
  16. const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
  17. private:
  18. virtual StringView class_name() const override { return "BigInt"sv; }
  19. Crypto::SignedBigInteger m_big_integer;
  20. };
  21. BigInt* js_bigint(Heap&, Crypto::SignedBigInteger);
  22. BigInt* js_bigint(VM&, Crypto::SignedBigInteger);
  23. ThrowCompletionOr<BigInt*> number_to_bigint(GlobalObject&, Value);
  24. }