LibJS: Add a method to stringify a BigInt to UTF-16

And remove the ByteString variant while we are here.
This commit is contained in:
Timothy Flynn 2025-08-07 16:33:10 -04:00 committed by Jelle Raaijmakers
commit c87122eb32
Notes: github-actions[bot] 2025-08-14 08:28:33 +00:00
3 changed files with 7 additions and 2 deletions

View file

@ -103,7 +103,7 @@ static ByteString format_operand(StringView name, Operand operand, Bytecode::Exe
else if (value.is_double())
builder.appendff("Double({})", value.as_double());
else if (value.is_bigint())
builder.appendff("BigInt({})", value.as_bigint().to_byte_string());
builder.appendff("BigInt({})", MUST(value.as_bigint().to_string()));
else if (value.is_string())
builder.appendff("String(\"{}\")", value.as_string().utf8_string_view());
else if (value.is_undefined())

View file

@ -28,6 +28,11 @@ ErrorOr<String> BigInt::to_string() const
return String::formatted("{}n", TRY(m_big_integer.to_base(10)));
}
Utf16String BigInt::to_utf16_string() const
{
return Utf16String::formatted("{}n", MUST(m_big_integer.to_base(10)));
}
// 21.2.1.1.1 NumberToBigInt ( number ), https://tc39.es/ecma262/#sec-numbertobigint
ThrowCompletionOr<GC::Ref<BigInt>> number_to_bigint(VM& vm, Value number)
{

View file

@ -28,7 +28,7 @@ public:
Crypto::SignedBigInteger const& big_integer() const { return m_big_integer; }
ErrorOr<String> to_string() const;
ByteString to_byte_string() const { return ByteString::formatted("{}n", MUST(m_big_integer.to_base(10))); }
Utf16String to_utf16_string() const;
private:
explicit BigInt(Crypto::SignedBigInteger);