2020-06-05 21:14:10 -03:00
|
|
|
/*
|
2022-08-21 16:38:35 -03:00
|
|
|
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
|
2020-06-05 21:14:10 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-05 21:14:10 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-02-12 23:03:11 -03:00
|
|
|
#include <AK/Error.h>
|
|
|
|
|
#include <AK/String.h>
|
2022-03-16 21:26:49 -03:00
|
|
|
#include <AK/StringView.h>
|
2020-06-05 21:14:10 -03:00
|
|
|
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
2024-11-14 12:01:23 -03:00
|
|
|
#include <LibGC/CellAllocator.h>
|
2025-07-19 17:49:30 -03:00
|
|
|
#include <LibJS/Export.h>
|
2021-05-17 14:50:20 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2020-06-05 21:14:10 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2025-07-19 17:49:30 -03:00
|
|
|
class JS_API BigInt final : public Cell {
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_CELL(BigInt, Cell);
|
|
|
|
|
GC_DECLARE_ALLOCATOR(BigInt);
|
2022-08-28 17:11:20 -03:00
|
|
|
|
2020-06-05 21:14:10 -03:00
|
|
|
public:
|
2024-11-14 12:01:23 -03:00
|
|
|
[[nodiscard]] static GC::Ref<BigInt> create(VM&, Crypto::SignedBigInteger);
|
2022-12-06 19:03:52 -03:00
|
|
|
|
2022-03-14 13:25:06 -03:00
|
|
|
virtual ~BigInt() override = default;
|
2020-06-05 21:14:10 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
|
2023-02-12 23:03:11 -03:00
|
|
|
|
|
|
|
|
ErrorOr<String> to_string() const;
|
2025-08-07 17:33:10 -03:00
|
|
|
Utf16String to_utf16_string() const;
|
2020-06-05 21:14:10 -03:00
|
|
|
|
|
|
|
|
private:
|
2022-08-28 18:51:28 -03:00
|
|
|
explicit BigInt(Crypto::SignedBigInteger);
|
|
|
|
|
|
2020-06-05 21:14:10 -03:00
|
|
|
Crypto::SignedBigInteger m_big_integer;
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-19 14:41:08 -03:00
|
|
|
ThrowCompletionOr<GC::Ref<BigInt>> number_to_bigint(VM&, Value);
|
2020-06-05 21:14:10 -03:00
|
|
|
|
|
|
|
|
}
|