BigInt.h 811 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2020-2022, 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. JS_CELL(BigInt, Cell);
  13. public:
  14. explicit BigInt(Crypto::SignedBigInteger);
  15. virtual ~BigInt() override = default;
  16. Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
  17. const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
  18. private:
  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(VM&, Value);
  24. }