LibJS: Add spec comments to same_value_zero()
This commit is contained in:
parent
44a243cae4
commit
625ad4192f
Notes:
sideshowbarker
2024-07-17 11:06:06 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/625ad4192f Pull-request: https://github.com/SerenityOS/serenity/pull/16405 Reviewed-by: https://github.com/davidot ✅
1 changed files with 5 additions and 0 deletions
|
@ -2130,18 +2130,23 @@ bool same_value(Value lhs, Value rhs)
|
|||
// 7.2.11 SameValueZero ( x, y ), https://tc39.es/ecma262/#sec-samevaluezero
|
||||
bool same_value_zero(Value lhs, Value rhs)
|
||||
{
|
||||
// 1. If Type(x) is different from Type(y), return false.
|
||||
if (!same_type_for_equality(lhs, rhs))
|
||||
return false;
|
||||
|
||||
// 2. If x is a Number, then
|
||||
if (lhs.is_number()) {
|
||||
// a. Return Number::sameValueZero(x, y).
|
||||
if (lhs.is_nan() && rhs.is_nan())
|
||||
return true;
|
||||
return lhs.as_double() == rhs.as_double();
|
||||
}
|
||||
|
||||
// FIXME: This should be handled in SameValueNonNumber now (formerly SameValueNonNumeric)
|
||||
if (lhs.is_bigint())
|
||||
return lhs.as_bigint().big_integer() == rhs.as_bigint().big_integer();
|
||||
|
||||
// 3. Return SameValueNonNumber(x, y).
|
||||
return same_value_non_numeric(lhs, rhs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue