Skip to content

Commit

Permalink
Fix BigInt loose equality (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma committed Jan 30, 2022
1 parent 2d16a66 commit 999ce2e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Jint.Tests.Ecma/TestCases/alltests.json
Original file line number Diff line number Diff line change
Expand Up @@ -10385,8 +10385,8 @@
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"
},
{
Expand Down
23 changes: 21 additions & 2 deletions Jint/Native/JsBigInt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,27 @@ public override bool IsLooselyEqual(JsValue value)
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)
Expand Down
2 changes: 1 addition & 1 deletion Jint/Native/RegExp/RegExpConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class RegExpConstructor : FunctionInstance, IConstructor
{
_prototype = functionPrototype;
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);
}

Expand Down

0 comments on commit 999ce2e

Please sign in to comment.