1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +00:00

AK+GMLCompiler: Remove JsonValue::as_double()

Replace its single (non-test) usage with newly created as_number(),
which does not leak information about internal integer storage type.
This commit is contained in:
Dan Klishch 2023-11-14 00:49:41 -05:00 committed by Andrew Kaster
parent 5230d2af91
commit faef802229
3 changed files with 27 additions and 13 deletions

View file

@ -210,15 +210,15 @@ static ErrorOr<String> generate_initializer_for(Optional<StringView> property_na
return String::formatted(R"~~~("{}"_string)~~~", TRY(escape_string(value)));
}
// No need to handle the smaller integer types separately.
if (value.is_integer<i64>())
return String::formatted("static_cast<i64>({})", value.as_integer<i64>());
if (value.is_integer<u64>())
return String::formatted("static_cast<u64>({})", value.as_integer<u64>());
if (value.is_bool())
return String::formatted("{}", value.as_bool());
if (value.is_double())
return String::formatted("static_cast<double>({})", value.as_double());
if (value.is_number()) {
return value.as_number().visit(
// NOTE: Passing by mutable reference here in order to disallow implicit casts.
[](u64& value) { return String::formatted("static_cast<u64>({})", value); },
[](i64& value) { return String::formatted("static_cast<i64>({})", value); },
[](double& value) { return String::formatted("static_cast<double>({})", value); });
}
if (value.is_array()) {
auto const& array = value.as_array();
auto child_type = Optional<StringView> {};