1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:14:58 +00:00

AK+Applications: Return value from JsonObject::get_double more often

Previously, we were returning an empty optional if key contained a
numerical value which was not stored as double. Stop doing that and
rename the method to signify the change in the behavior.

Apparently, this fixes bug in an InspectorWidget in Ladybird on
Serenity: it showed 0 for element's boxes with integer sizes.
This commit is contained in:
Dan Klishch 2023-11-14 00:36:05 -05:00 committed by Andreas Kling
parent 7cdd07b89a
commit 80d1c93edf
4 changed files with 24 additions and 24 deletions

View file

@ -135,19 +135,19 @@ Optional<JsonArray const&> JsonObject::get_array(StringView key) const
}
#if !defined(KERNEL)
Optional<double> JsonObject::get_double(StringView key) const
Optional<double> JsonObject::get_double_with_precision_loss(StringView key) const
{
auto maybe_value = get(key);
if (maybe_value.has_value() && maybe_value->is_double())
return maybe_value->as_double();
if (maybe_value.has_value() && maybe_value->is_number())
return maybe_value->to_number<double>();
return {};
}
Optional<float> JsonObject::get_float(StringView key) const
Optional<float> JsonObject::get_float_with_precision_loss(StringView key) const
{
auto maybe_value = get(key);
if (maybe_value.has_value() && maybe_value->is_double())
return static_cast<float>(maybe_value->as_double());
if (maybe_value.has_value() && maybe_value->is_number())
return maybe_value->to_number<float>();
return {};
}
#endif