Truly independent web browser
LibJS: Name a class field initializer's value by its BigInt key's value
Shannon Booth5b43528e5f08
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen.rs b/Libraries/LibJS/Rust/src/bytecode/codegen.rsindex 3c5d00a0f8b..7f77ba6965a 100644--- a/Libraries/LibJS/Rust/src/bytecode/codegen.rs+++ b/Libraries/LibJS/Rust/src/bytecode/codegen.rs@@ -7262,8 +7262,10 @@ fn generate_class_expression(ExpressionKind::PrivateIdentifier(p) => p.name.clone(),ExpressionKind::NumericLiteral(n) => crate::host::js_number_to_utf16(*n),ExpressionKind::BigIntLiteral(s) => {- let digits = bigint_literal_digits(s);- Utf16String(digits.to_vec())+ let digits = String::from_utf16_lossy(bigint_literal_digits(s));+ let value =+ parse_bigint(&digits).expect("the lexer only produces valid BigInt literals");+ Utf16String(value.to_string().encode_utf16().collect())}_ => Utf16String::new(),};diff --git a/Tests/LibJS/Runtime/classes/class-public-fields.js b/Tests/LibJS/Runtime/classes/class-public-fields.jsindex dfc1789d3d2..ed7e3d842aa 100644--- a/Tests/LibJS/Runtime/classes/class-public-fields.js+++ b/Tests/LibJS/Runtime/classes/class-public-fields.js@@ -172,6 +172,18 @@ test("using 'arguments' via indirect eval throws at runtime instead of parse tim}).toThrowWithMessage(ReferenceError, "'arguments' is not defined");});+test("anonymous function initializer is named by a literal key", () => {+ class A {+ static 0x10 = function () {};+ static 0x20n = function () {};+ static "a string" = () => {};+ }++ expect(A[16].name).toBe("16");+ expect(A[32].name).toBe("32");+ expect(A["a string"].name).toBe("a string");+});+test("regex field initializer", () => {class A {pattern = /hello/;