
This is supposed to be its own AO, but since it was only used in one place, we inlined it. Now that it's also being used in the Temporal proposal (Date.prototype.toTemporalInstant() specifically), it makes sense to have it as a standalone function. A small difference is that we now construct the SignedBigInteger without casting to i32 but instead take the (known to be integral) double and cast it to i64. Not perfect, but slightly better. Also clean up the BigInt constructor a bit while we're here and sprinkle some spec comments.
31 lines
743 B
C++
31 lines
743 B
C++
/*
|
|
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibCrypto/BigInt/SignedBigInteger.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
namespace JS {
|
|
|
|
class BigInt final : public Cell {
|
|
public:
|
|
BigInt(Crypto::SignedBigInteger);
|
|
virtual ~BigInt();
|
|
|
|
const Crypto::SignedBigInteger& big_integer() const { return m_big_integer; }
|
|
const String to_string() const { return String::formatted("{}n", m_big_integer.to_base(10)); }
|
|
|
|
private:
|
|
virtual const char* class_name() const override { return "BigInt"; }
|
|
|
|
Crypto::SignedBigInteger m_big_integer;
|
|
};
|
|
|
|
BigInt* js_bigint(Heap&, Crypto::SignedBigInteger);
|
|
BigInt* number_to_bigint(GlobalObject&, Value);
|
|
|
|
}
|