mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
LibJS: Convert is_less_than() to ThrowCompletionOr
This commit is contained in:
parent
c15a3b0576
commit
b5e28410c5
3 changed files with 14 additions and 14 deletions
|
@ -982,9 +982,9 @@ static void array_merge_sort(VM& vm, GlobalObject& global_object, FunctionObject
|
||||||
|
|
||||||
// Because they are called with primitive strings, these is_less_than calls
|
// Because they are called with primitive strings, these is_less_than calls
|
||||||
// should never result in a VM exception.
|
// should never result in a VM exception.
|
||||||
auto x_lt_y_relation = is_less_than(global_object, true, x_string_value, y_string_value);
|
auto x_lt_y_relation = MUST(is_less_than(global_object, true, x_string_value, y_string_value));
|
||||||
VERIFY(x_lt_y_relation != TriState::Unknown);
|
VERIFY(x_lt_y_relation != TriState::Unknown);
|
||||||
auto y_lt_x_relation = is_less_than(global_object, true, y_string_value, x_string_value);
|
auto y_lt_x_relation = MUST(is_less_than(global_object, true, y_string_value, x_string_value));
|
||||||
VERIFY(y_lt_x_relation != TriState::Unknown);
|
VERIFY(y_lt_x_relation != TriState::Unknown);
|
||||||
|
|
||||||
if (x_lt_y_relation == TriState::True) {
|
if (x_lt_y_relation == TriState::True) {
|
||||||
|
|
|
@ -771,7 +771,7 @@ ThrowCompletionOr<FunctionObject*> Value::get_method(GlobalObject& global_object
|
||||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||||
Value greater_than(GlobalObject& global_object, Value lhs, Value rhs)
|
Value greater_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
TriState relation = is_less_than(global_object, false, lhs, rhs);
|
TriState relation = TRY_OR_DISCARD(is_less_than(global_object, false, lhs, rhs));
|
||||||
if (relation == TriState::Unknown)
|
if (relation == TriState::Unknown)
|
||||||
return Value(false);
|
return Value(false);
|
||||||
return Value(relation == TriState::True);
|
return Value(relation == TriState::True);
|
||||||
|
@ -780,7 +780,7 @@ Value greater_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||||
Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
TriState relation = is_less_than(global_object, true, lhs, rhs);
|
TriState relation = TRY_OR_DISCARD(is_less_than(global_object, true, lhs, rhs));
|
||||||
if (relation == TriState::Unknown || relation == TriState::True)
|
if (relation == TriState::Unknown || relation == TriState::True)
|
||||||
return Value(false);
|
return Value(false);
|
||||||
return Value(true);
|
return Value(true);
|
||||||
|
@ -789,7 +789,7 @@ Value greater_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||||
Value less_than(GlobalObject& global_object, Value lhs, Value rhs)
|
Value less_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
TriState relation = is_less_than(global_object, true, lhs, rhs);
|
TriState relation = TRY_OR_DISCARD(is_less_than(global_object, true, lhs, rhs));
|
||||||
if (relation == TriState::Unknown)
|
if (relation == TriState::Unknown)
|
||||||
return Value(false);
|
return Value(false);
|
||||||
return Value(relation == TriState::True);
|
return Value(relation == TriState::True);
|
||||||
|
@ -798,7 +798,7 @@ Value less_than(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
// 13.10 Relational Operators, https://tc39.es/ecma262/#sec-relational-operators
|
||||||
Value less_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
Value less_than_equals(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
TriState relation = is_less_than(global_object, false, lhs, rhs);
|
TriState relation = TRY_OR_DISCARD(is_less_than(global_object, false, lhs, rhs));
|
||||||
if (relation == TriState::Unknown || relation == TriState::True)
|
if (relation == TriState::Unknown || relation == TriState::True)
|
||||||
return Value(false);
|
return Value(false);
|
||||||
return Value(true);
|
return Value(true);
|
||||||
|
@ -1376,17 +1376,17 @@ bool is_loosely_equal(GlobalObject& global_object, Value lhs, Value rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.2.13 IsLessThan ( x, y, LeftFirst ), https://tc39.es/ecma262/#sec-islessthan
|
// 7.2.13 IsLessThan ( x, y, LeftFirst ), https://tc39.es/ecma262/#sec-islessthan
|
||||||
TriState is_less_than(GlobalObject& global_object, bool left_first, Value lhs, Value rhs)
|
ThrowCompletionOr<TriState> is_less_than(GlobalObject& global_object, bool left_first, Value lhs, Value rhs)
|
||||||
{
|
{
|
||||||
Value x_primitive;
|
Value x_primitive;
|
||||||
Value y_primitive;
|
Value y_primitive;
|
||||||
|
|
||||||
if (left_first) {
|
if (left_first) {
|
||||||
x_primitive = TRY_OR_DISCARD(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
x_primitive = TRY(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||||
y_primitive = TRY_OR_DISCARD(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
y_primitive = TRY(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||||
} else {
|
} else {
|
||||||
y_primitive = TRY_OR_DISCARD(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
y_primitive = TRY(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||||
x_primitive = TRY_OR_DISCARD(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
x_primitive = TRY(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x_primitive.is_string() && y_primitive.is_string()) {
|
if (x_primitive.is_string() && y_primitive.is_string()) {
|
||||||
|
@ -1435,8 +1435,8 @@ TriState is_less_than(GlobalObject& global_object, bool left_first, Value lhs, V
|
||||||
return TriState::False;
|
return TriState::False;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto x_numeric = TRY_OR_DISCARD(x_primitive.to_numeric(global_object));
|
auto x_numeric = TRY(x_primitive.to_numeric(global_object));
|
||||||
auto y_numeric = TRY_OR_DISCARD(y_primitive.to_numeric(global_object));
|
auto y_numeric = TRY(y_primitive.to_numeric(global_object));
|
||||||
|
|
||||||
if (x_numeric.is_nan() || y_numeric.is_nan())
|
if (x_numeric.is_nan() || y_numeric.is_nan())
|
||||||
return TriState::Unknown;
|
return TriState::Unknown;
|
||||||
|
|
|
@ -427,7 +427,7 @@ 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_numeric(Value lhs, Value rhs);
|
||||||
TriState is_less_than(GlobalObject&, bool left_first, Value lhs, Value rhs);
|
ThrowCompletionOr<TriState> is_less_than(GlobalObject&, bool left_first, Value lhs, Value rhs);
|
||||||
|
|
||||||
inline bool Value::operator==(Value const& value) const { return same_value(*this, value); }
|
inline bool Value::operator==(Value const& value) const { return same_value(*this, value); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue