ladybird/Userland/Libraries/LibJS/Runtime/BigInt.h
Linus Groh 5db38d7ba1 LibJS: Replace standalone js_bigint() with BigInt::create()
Three standalone Cell creation functions remain in the JS namespace:

- js_bigint()
- js_string()
- js_symbol()

All of them are leftovers from early iterations when LibJS still took
inspiration from JSC, which itself has jsString(). Nowadays, we pretty
much exclusively use static create() functions to construct types
allocated on the JS heap, and there's no reason to not do the same for
these.
Also change the return type from BigInt* to NonnullGCPtr<BigInt> while
we're here.

This is patch 1/3, replacement of js_string() and js_symbol() follow.
2022-12-07 16:43:06 +00:00

34 lines
827 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:
[[nodiscard]] static NonnullGCPtr<BigInt> create(VM&, Crypto::SignedBigInteger);
virtual ~BigInt() override = default;
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
const DeprecatedString to_deprecated_string() const { return DeprecatedString::formatted("{}n", m_big_integer.to_base(10)); }
private:
explicit BigInt(Crypto::SignedBigInteger);
Crypto::SignedBigInteger m_big_integer;
};
ThrowCompletionOr<BigInt*> number_to_bigint(VM&, Value);
}