Browse Source

Fix BigInt loose equality (#1073)

Marko Lahma 3 years ago
parent
commit
999ce2e4ae

+ 2 - 2
Jint.Tests.Ecma/TestCases/alltests.json

@@ -10385,8 +10385,8 @@
     source: "ch11/11.4/11.4.1/11.4.1-5-a-27-s.js"
     source: "ch11/11.4/11.4.1/11.4.1-5-a-27-s.js"
   },
   },
   {
   {
-    skip: false,
-    reason: "",
+    skip: true,
+    reason: "Spec has changed",
     source: "ch11/11.4/11.4.1/11.4.1-5-a-28-s.js"
     source: "ch11/11.4/11.4.1/11.4.1-5-a-28-s.js"
   },
   },
   {
   {

+ 21 - 2
Jint/Native/JsBigInt.cs

@@ -74,8 +74,27 @@ public sealed class JsBigInt : JsValue, IEquatable<JsBigInt>
             return Equals(bigInt);
             return Equals(bigInt);
         }
         }
 
 
-        return value is JsNumber jsNumber && TypeConverter.IsIntegralNumber(jsNumber._value) && _value == new BigInteger(jsNumber._value)
-               || value is JsString jsString && TypeConverter.TryStringToBigInt(jsString.ToString(), out var temp) && temp == _value;
+        if (value is JsNumber number && TypeConverter.IsIntegralNumber(number._value) && _value == new BigInteger(number._value))
+        {
+            return true;
+        }
+
+        if (value is JsBoolean b)
+        {
+            return b._value && _value == BigInteger.One || !b._value && _value == BigInteger.Zero;
+        }
+
+        if (value is JsString s && TypeConverter.TryStringToBigInt(s.ToString(), out var temp) && temp == _value)
+        {
+            return true;
+        }
+
+        if (value.IsObject())
+        {
+            return IsLooselyEqual(TypeConverter.ToPrimitive(value, Types.Number));
+        }
+
+        return false;
     }
     }
 
 
     public override bool Equals(object other)
     public override bool Equals(object other)

+ 1 - 1
Jint/Native/RegExp/RegExpConstructor.cs

@@ -24,7 +24,7 @@ namespace Jint.Native.RegExp
         {
         {
             _prototype = functionPrototype;
             _prototype = functionPrototype;
             PrototypeObject = new RegExpPrototype(engine, realm, this, objectPrototype);
             PrototypeObject = new RegExpPrototype(engine, realm, this, objectPrototype);
-            _length = new PropertyDescriptor(2, PropertyFlag.AllForbidden);
+            _length = new PropertyDescriptor(2, PropertyFlag.Configurable);
             _prototypeDescriptor= new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
             _prototypeDescriptor= new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
         }
         }