Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BigInt loose equality #1073

Merged
merged 1 commit into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ internal RegExpConstructor(
{
_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