mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:47:45 +00:00
LibJS: Rename same_value_non_{numeric => number}() and handle BigInts
This is an editorial change in the ECMA-262 spec. See:f660b14
Note that the explicit check for zero sign equality is no longer needed as ofb0d6399
, which removed the ability of Crypto::SignedBigInteger to represent negative zero.
This commit is contained in:
parent
78895984e9
commit
ff5882291f
2 changed files with 14 additions and 26 deletions
|
@ -2114,17 +2114,8 @@ bool same_value(Value lhs, Value rhs)
|
||||||
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()) {
|
|
||||||
auto lhs_big_integer = lhs.as_bigint().big_integer();
|
|
||||||
auto rhs_big_integer = rhs.as_bigint().big_integer();
|
|
||||||
if (lhs_big_integer == BIGINT_ZERO && rhs_big_integer == BIGINT_ZERO && lhs_big_integer.is_negative() != rhs_big_integer.is_negative())
|
|
||||||
return false;
|
|
||||||
return lhs_big_integer == rhs_big_integer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Return SameValueNonNumber(x, y).
|
// 3. Return SameValueNonNumber(x, y).
|
||||||
return same_value_non_numeric(lhs, rhs);
|
return same_value_non_number(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.11 SameValueZero ( x, y ), https://tc39.es/ecma262/#sec-samevaluezero
|
// 7.2.11 SameValueZero ( x, y ), https://tc39.es/ecma262/#sec-samevaluezero
|
||||||
|
@ -2142,24 +2133,25 @@ bool same_value_zero(Value lhs, Value rhs)
|
||||||
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())
|
|
||||||
return lhs.as_bigint().big_integer() == rhs.as_bigint().big_integer();
|
|
||||||
|
|
||||||
// 3. Return SameValueNonNumber(x, y).
|
// 3. Return SameValueNonNumber(x, y).
|
||||||
return same_value_non_numeric(lhs, rhs);
|
return same_value_non_number(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.12 SameValueNonNumber ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric
|
// 7.2.12 SameValueNonNumber ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric
|
||||||
// FIXME: Rename this to same_value_non_number()
|
bool same_value_non_number(Value lhs, Value rhs)
|
||||||
bool same_value_non_numeric(Value lhs, Value rhs)
|
|
||||||
{
|
{
|
||||||
// 1. Assert: Type(x) is the same as Type(y).
|
// 1. Assert: Type(x) is the same as Type(y).
|
||||||
VERIFY(same_type_for_equality(lhs, rhs));
|
VERIFY(same_type_for_equality(lhs, rhs));
|
||||||
VERIFY(!lhs.is_number());
|
VERIFY(!lhs.is_number());
|
||||||
|
|
||||||
// FIXME: 2. If x is a BigInt, then
|
// 2. If x is a BigInt, then
|
||||||
// a. Return BigInt::equal(x, y).
|
if (lhs.is_bigint()) {
|
||||||
|
// a. Return BigInt::equal(x, y).
|
||||||
|
|
||||||
|
// 6.1.6.2.13 BigInt::equal ( x, y ), https://tc39.es/ecma262/#sec-numeric-types-bigint-equal
|
||||||
|
// 1. If ℝ(x) = ℝ(y), return true; otherwise return false.
|
||||||
|
return lhs.as_bigint().big_integer() == rhs.as_bigint().big_integer();
|
||||||
|
}
|
||||||
|
|
||||||
// 5. If x is a String, then
|
// 5. If x is a String, then
|
||||||
if (lhs.is_string()) {
|
if (lhs.is_string()) {
|
||||||
|
@ -2203,12 +2195,8 @@ bool is_strictly_equal(Value lhs, Value rhs)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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).
|
// 3. Return SameValueNonNumber(x, y).
|
||||||
return same_value_non_numeric(lhs, rhs);
|
return same_value_non_number(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.14 IsLooselyEqual ( x, y ), https://tc39.es/ecma262/#sec-islooselyequal
|
// 7.2.14 IsLooselyEqual ( x, y ), https://tc39.es/ecma262/#sec-islooselyequal
|
||||||
|
|
|
@ -498,7 +498,7 @@ private:
|
||||||
friend ThrowCompletionOr<Value> less_than(VM&, Value lhs, Value rhs);
|
friend ThrowCompletionOr<Value> less_than(VM&, Value lhs, Value rhs);
|
||||||
friend ThrowCompletionOr<Value> less_than_equals(VM&, Value lhs, Value rhs);
|
friend ThrowCompletionOr<Value> less_than_equals(VM&, Value lhs, Value rhs);
|
||||||
friend ThrowCompletionOr<Value> add(VM&, Value lhs, Value rhs);
|
friend ThrowCompletionOr<Value> add(VM&, Value lhs, Value rhs);
|
||||||
friend bool same_value_non_numeric(Value lhs, Value rhs);
|
friend bool same_value_non_number(Value lhs, Value rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Value js_undefined()
|
inline Value js_undefined()
|
||||||
|
@ -559,7 +559,7 @@ ThrowCompletionOr<bool> is_loosely_equal(VM&, Value lhs, Value rhs);
|
||||||
bool is_strictly_equal(Value lhs, Value rhs);
|
bool is_strictly_equal(Value lhs, Value rhs);
|
||||||
bool same_value(Value lhs, Value rhs);
|
bool same_value(Value lhs, Value rhs);
|
||||||
bool same_value_zero(Value lhs, Value rhs);
|
bool same_value_zero(Value lhs, Value rhs);
|
||||||
bool same_value_non_numeric(Value lhs, Value rhs);
|
bool same_value_non_number(Value lhs, Value rhs);
|
||||||
ThrowCompletionOr<TriState> is_less_than(VM&, Value lhs, Value rhs, bool left_first);
|
ThrowCompletionOr<TriState> is_less_than(VM&, Value lhs, Value rhs, bool left_first);
|
||||||
|
|
||||||
double to_integer_or_infinity(double);
|
double to_integer_or_infinity(double);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue