Skip to content

Truly independent web browser

LibJS: Stringify BigInt constants in decimal

Shannon Boothfd9d83a70321
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen.rs b/Libraries/LibJS/Rust/src/bytecode/codegen.rs
index 25ffcb3ed84..099a1287df7 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen.rs
@@ -10292,7 +10292,7 @@ fn constant_to_string(val: &ConstantValue) -> Option<Utf16String> {
ConstantValue::Undefined => Some(Utf16String(utf16!("undefined").to_vec())),
ConstantValue::BigInt(s) => {
// BigInt.prototype.toString() returns the decimal string representation.
- Some(Utf16String(s.encode_utf16().collect()))
+ Some(Utf16String(parse_bigint(s)?.to_string().encode_utf16().collect()))
}
_ => None,
}
diff --git a/Tests/LibJS/Runtime/regress/bigint-constant-folding.js b/Tests/LibJS/Runtime/regress/bigint-constant-folding.js
new file mode 100644
index 00000000000..2c57381bf7a
--- /dev/null
+++ b/Tests/LibJS/Runtime/regress/bigint-constant-folding.js
@@ -0,0 +1,6 @@
+describe("BigInt constant folding", () => {
+ test("conversion to string is decimal", () => {
+ expect(0x10n + "").toBe("16");
+ expect(0x1_0n + "").toBe("16");
+ });
+});