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