ladybird/Userland/Libraries/LibJS/Runtime/BigInt.h
Andreas Kling 6e973ce69b LibJS: Add JS_CELL macro and use it in all JS::Cell subclasses
This is similar to what we already had with JS_OBJECT (and also
JS_ENVIRONMENT) but sits at the top of the Cell inheritance hierarchy.
2022-08-29 03:24:54 +02:00

33 lines
811 B
C++

/*
* Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/StringView.h>
#include <LibCrypto/BigInt/SignedBigInteger.h>
#include <LibJS/Heap/Cell.h>
namespace JS {
class BigInt final : public Cell {
JS_CELL(BigInt, Cell);
public:
explicit BigInt(Crypto::SignedBigInteger);
virtual ~BigInt() override = default;
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
private:
Crypto::SignedBigInteger m_big_integer;
};
BigInt* js_bigint(Heap&, Crypto::SignedBigInteger);
BigInt* js_bigint(VM&, Crypto::SignedBigInteger);
ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
}