mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-02 15:46:33 +00:00
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:
parent
12dc771186
commit
c87122eb32
Notes:
github-actions[bot]
2025-08-14 08:28:33 +00:00
Author: https://github.com/trflynn89
Commit: c87122eb32
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5845
Reviewed-by: https://github.com/gmta ✅
3 changed files with 7 additions and 2 deletions
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue