mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibJS: Support non-base-10 BigInt literals in bytecode VM
Fixes 39 tests in test262 and a handful in test-js. :^)
This commit is contained in:
parent
29935fe943
commit
178f0b9971
Notes:
sideshowbarker
2024-07-17 05:21:12 +09:00
Author: https://github.com/awesomekling
Commit: 178f0b9971
Pull-request: https://github.com/SerenityOS/serenity/pull/15702
1 changed files with 13 additions and 1 deletions
|
@ -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 {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue