mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:27:34 +00:00
LibJS: Add spec comments to same_value()
This commit is contained in:
parent
c892b1c2b6
commit
44a243cae4
1 changed files with 12 additions and 0 deletions
|
@ -2091,19 +2091,30 @@ ThrowCompletionOr<Value> ordinary_has_instance(VM& vm, Value lhs, Value rhs)
|
||||||
// 7.2.10 SameValue ( x, y ), https://tc39.es/ecma262/#sec-samevalue
|
// 7.2.10 SameValue ( x, y ), https://tc39.es/ecma262/#sec-samevalue
|
||||||
bool same_value(Value lhs, Value rhs)
|
bool same_value(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::sameValue(x, y).
|
||||||
|
|
||||||
|
// 6.1.6.1.14 Number::sameValue ( x, y ), https://tc39.es/ecma262/#sec-numeric-types-number-sameValue
|
||||||
|
// 1. If x is NaN and y is NaN, return true.
|
||||||
if (lhs.is_nan() && rhs.is_nan())
|
if (lhs.is_nan() && rhs.is_nan())
|
||||||
return true;
|
return true;
|
||||||
|
// 2. If x is +0𝔽 and y is -0𝔽, return false.
|
||||||
if (lhs.is_positive_zero() && rhs.is_negative_zero())
|
if (lhs.is_positive_zero() && rhs.is_negative_zero())
|
||||||
return false;
|
return false;
|
||||||
|
// 3. If x is -0𝔽 and y is +0𝔽, return false.
|
||||||
if (lhs.is_negative_zero() && rhs.is_positive_zero())
|
if (lhs.is_negative_zero() && rhs.is_positive_zero())
|
||||||
return false;
|
return false;
|
||||||
|
// 4. If x is the same Number value as y, return true.
|
||||||
|
// 5. Return false.
|
||||||
return lhs.as_double() == rhs.as_double();
|
return lhs.as_double() == rhs.as_double();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: This should be handled in SameValueNonNumber now (formerly SameValueNonNumeric)
|
||||||
if (lhs.is_bigint()) {
|
if (lhs.is_bigint()) {
|
||||||
auto lhs_big_integer = lhs.as_bigint().big_integer();
|
auto lhs_big_integer = lhs.as_bigint().big_integer();
|
||||||
auto rhs_big_integer = rhs.as_bigint().big_integer();
|
auto rhs_big_integer = rhs.as_bigint().big_integer();
|
||||||
|
@ -2112,6 +2123,7 @@ bool same_value(Value lhs, Value rhs)
|
||||||
return lhs_big_integer == rhs_big_integer;
|
return lhs_big_integer == rhs_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