summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-10 11:35:20 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-10 11:35:20 +0000
commitff5882291ff5af37c02e285ff245525e5c903eb4 (patch)
tree8466bffdaaaf7d621abbfdbe63e0aac70012051f /Userland
parent78895984e9b703cc00e0a9aeb55d39c5e0f2f060 (diff)
downloadserenity-ff5882291ff5af37c02e285ff245525e5c903eb4.zip
LibJS: Rename same_value_non_{numeric => number}() and handle BigInts
This is an editorial change in the ECMA-262 spec. See: https://github.com/tc39/ecma262/commit/f660b14 Note that the explicit check for zero sign equality is no longer needed as of b0d6399, which removed the ability of Crypto::SignedBigInteger to represent negative zero.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp36
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.h4
2 files changed, 14 insertions, 26 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index c69ccd4325..768f9753b7 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -2114,17 +2114,8 @@ bool same_value(Value lhs, Value rhs)
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).
- 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
@@ -2142,24 +2133,25 @@ bool same_value_zero(Value lhs, Value rhs)
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);
+ return same_value_non_number(lhs, rhs);
}
// 7.2.12 SameValueNonNumber ( x, y ), https://tc39.es/ecma262/#sec-samevaluenonnumeric
-// FIXME: Rename this to same_value_non_number()
-bool same_value_non_numeric(Value lhs, Value rhs)
+bool same_value_non_number(Value lhs, Value rhs)
{
// 1. Assert: Type(x) is the same as Type(y).
VERIFY(same_type_for_equality(lhs, rhs));
VERIFY(!lhs.is_number());
- // FIXME: 2. If x is a BigInt, then
- // a. Return BigInt::equal(x, y).
+ // 2. If x is a BigInt, then
+ 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
if (lhs.is_string()) {
@@ -2203,12 +2195,8 @@ bool is_strictly_equal(Value lhs, Value rhs)
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).
- 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
diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h
index 2adbffd8ff..3b7206afce 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.h
+++ b/Userland/Libraries/LibJS/Runtime/Value.h
@@ -498,7 +498,7 @@ private:
friend ThrowCompletionOr<Value> less_than(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 bool same_value_non_numeric(Value lhs, Value rhs);
+ friend bool same_value_non_number(Value lhs, Value rhs);
};
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 same_value(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);
double to_integer_or_infinity(double);