mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
LibJS: Convert is_less_than() to ThrowCompletionOr
This commit is contained in:
parent
c15a3b0576
commit
b5e28410c5
Notes:
sideshowbarker
2024-07-18 02:10:23 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/b5e28410c5e Pull-request: https://github.com/SerenityOS/serenity/pull/10534 Reviewed-by: https://github.com/linusg ✅
|
@ -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
|
||||
// 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);
|
||||
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);
|
||||
|
||||
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
|
||||
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)
|
||||
return Value(false);
|
||||
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
|
||||
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)
|
||||
return Value(false);
|
||||
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
|
||||
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)
|
||||
return Value(false);
|
||||
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
|
||||
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)
|
||||
return Value(false);
|
||||
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
|
||||
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 y_primitive;
|
||||
|
||||
if (left_first) {
|
||||
x_primitive = TRY_OR_DISCARD(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
y_primitive = TRY_OR_DISCARD(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
x_primitive = TRY(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
y_primitive = TRY(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
} else {
|
||||
y_primitive = TRY_OR_DISCARD(lhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
x_primitive = TRY_OR_DISCARD(rhs.to_primitive(global_object, Value::PreferredType::Number));
|
||||
y_primitive = TRY(lhs.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()) {
|
||||
|
@ -1435,8 +1435,8 @@ TriState is_less_than(GlobalObject& global_object, bool left_first, Value lhs, V
|
|||
return TriState::False;
|
||||
}
|
||||
|
||||
auto x_numeric = TRY_OR_DISCARD(x_primitive.to_numeric(global_object));
|
||||
auto y_numeric = TRY_OR_DISCARD(y_primitive.to_numeric(global_object));
|
||||
auto x_numeric = TRY(x_primitive.to_numeric(global_object));
|
||||
auto y_numeric = TRY(y_primitive.to_numeric(global_object));
|
||||
|
||||
if (x_numeric.is_nan() || y_numeric.is_nan())
|
||||
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_zero(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); }
|
||||
|
||||
|
|
Loading…
Reference in a new issue