mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibJS: Add spec comments to same_value()
This commit is contained in:
parent
c892b1c2b6
commit
44a243cae4
Notes:
sideshowbarker
2024-07-18 02:47:59 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/44a243cae4 Pull-request: https://github.com/SerenityOS/serenity/pull/16405 Reviewed-by: https://github.com/davidot ✅
@ -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
|
||||
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))
|
||||
return false;
|
||||
|
||||
// 2. If x is a Number, then
|
||||
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())
|
||||
return true;
|
||||
// 2. If x is +0𝔽 and y is -0𝔽, return false.
|
||||
if (lhs.is_positive_zero() && rhs.is_negative_zero())
|
||||
return false;
|
||||
// 3. If x is -0𝔽 and y is +0𝔽, return false.
|
||||
if (lhs.is_negative_zero() && rhs.is_positive_zero())
|
||||
return false;
|
||||
// 4. If x is the same Number value as y, return true.
|
||||
// 5. Return false.
|
||||
return lhs.as_double() == rhs.as_double();
|
||||
}
|
||||
|
||||
// FIXME: This should be handled in SameValueNonNumber now (formerly SameValueNonNumeric)
|
||||
if (lhs.is_bigint()) {
|
||||
auto lhs_big_integer = lhs.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;
|
||||
}
|
||||
|
||||
// 3. Return SameValueNonNumber(x, y).
|
||||
return same_value_non_numeric(lhs, rhs);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user