summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-10-19 19:17:58 +0200
committerAndreas Kling <kling@serenityos.org>2022-10-19 19:58:15 +0200
commit178f0b99711283e61d86ac13efa2f7fe22f46b51 (patch)
treedd7c442a7e487fa9ec05f152bde3ec118614f3d4 /Userland/Libraries
parent29935fe9437d2357ae0ef619c98bcd34da2ec5ba (diff)
downloadserenity-178f0b99711283e61d86ac13efa2f7fe22f46b51.zip
LibJS: Support non-base-10 BigInt literals in bytecode VM
Fixes 39 tests in test262 and a handful in test-js. :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
index e294fb4842..edfcd642fc 100644
--- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
+++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp
@@ -498,7 +498,19 @@ Bytecode::CodeGenerationErrorOr<void> NullLiteral::generate_bytecode(Bytecode::G
Bytecode::CodeGenerationErrorOr<void> BigIntLiteral::generate_bytecode(Bytecode::Generator& generator) const
{
- generator.emit<Bytecode::Op::NewBigInt>(Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1)));
+ // 1. Return the NumericValue of NumericLiteral as defined in 12.8.3.
+ auto integer = [&] {
+ if (m_value[0] == '0' && m_value.length() >= 3)
+ if (m_value[1] == 'x' || m_value[1] == 'X')
+ return Crypto::SignedBigInteger::from_base(16, m_value.substring(2, m_value.length() - 3));
+ if (m_value[1] == 'o' || m_value[1] == 'O')
+ return Crypto::SignedBigInteger::from_base(8, m_value.substring(2, m_value.length() - 3));
+ if (m_value[1] == 'b' || m_value[1] == 'B')
+ return Crypto::SignedBigInteger::from_base(2, m_value.substring(2, m_value.length() - 3));
+ return Crypto::SignedBigInteger::from_base(10, m_value.substring(0, m_value.length() - 1));
+ }();
+
+ generator.emit<Bytecode::Op::NewBigInt>(integer);
return {};
}