فهرست منبع

LibJS: Support non-base-10 BigInt literals in bytecode VM

Fixes 39 tests in test262 and a handful in test-js. :^)
Andreas Kling 2 سال پیش
والد
کامیت
178f0b9971
1فایلهای تغییر یافته به همراه13 افزوده شده و 1 حذف شده
  1. 13 1
      Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

+ 13 - 1
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 {};
 }