mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
LibJS: Add spec comments to is_strictly_equal()
This commit is contained in:
parent
abf1ba89cd
commit
f1d8a64510
1 changed files with 13 additions and 0 deletions
|
@ -2181,20 +2181,33 @@ bool same_value_non_numeric(Value lhs, Value rhs)
|
||||||
// 7.2.15 IsStrictlyEqual ( x, y ), https://tc39.es/ecma262/#sec-isstrictlyequal
|
// 7.2.15 IsStrictlyEqual ( x, y ), https://tc39.es/ecma262/#sec-isstrictlyequal
|
||||||
bool is_strictly_equal(Value lhs, Value rhs)
|
bool is_strictly_equal(Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
|
// 1. If Type(x) is different from Type(y), return false.
|
||||||
if (!same_type_for_equality(lhs, rhs))
|
if (!same_type_for_equality(lhs, rhs))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// 2. If x is a Number, then
|
||||||
if (lhs.is_number()) {
|
if (lhs.is_number()) {
|
||||||
|
// a. Return Number::equal(x, y).
|
||||||
|
|
||||||
|
// 6.1.6.1.13 Number::equal ( x, y ), https://tc39.es/ecma262/#sec-numeric-types-number-equal
|
||||||
|
// 1. If x is NaN, return false.
|
||||||
|
// 2. If y is NaN, return false.
|
||||||
if (lhs.is_nan() || rhs.is_nan())
|
if (lhs.is_nan() || rhs.is_nan())
|
||||||
return false;
|
return false;
|
||||||
|
// 3. If x is the same Number value as y, return true.
|
||||||
|
// 4. If x is +0𝔽 and y is -0𝔽, return true.
|
||||||
|
// 5. If x is -0𝔽 and y is +0𝔽, return true.
|
||||||
if (lhs.as_double() == rhs.as_double())
|
if (lhs.as_double() == rhs.as_double())
|
||||||
return true;
|
return true;
|
||||||
|
// 6. Return false.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: This should be handled in SameValueNonNumber now (formerly SameValueNonNumeric)
|
||||||
if (lhs.is_bigint())
|
if (lhs.is_bigint())
|
||||||
return lhs.as_bigint().big_integer() == rhs.as_bigint().big_integer();
|
return lhs.as_bigint().big_integer() == rhs.as_bigint().big_integer();
|
||||||
|
|
||||||
|
// 3. Return SameValueNonNumber(x, y).
|
||||||
return same_value_non_numeric(lhs, rhs);
|
return same_value_non_numeric(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue