From 43e5c326e2511dcc92a8e06c4429cc6bf447ab4a Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 16 Feb 2022 00:22:56 +0200 Subject: [PATCH] AK: Exclude JsonValue String APIs from the Kernel These APIs are only used by userland, and String is OOM-infallible, so let's just ifdef it out of the Kernel. --- AK/JsonValue.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 2b0b0497da..346e021259 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -8,9 +8,12 @@ #include #include -#include #include +#ifndef KERNEL +# include +#endif + namespace AK { class JsonValue { @@ -53,7 +56,9 @@ public: #endif JsonValue(bool); JsonValue(const char*); +#ifndef KERNEL JsonValue(const String&); +#endif JsonValue(StringView); JsonValue(const JsonArray&); JsonValue(const JsonObject&); @@ -70,6 +75,7 @@ public: template void serialize(Builder&) const; +#ifndef KERNEL String as_string_or(String const& alternative) const { if (is_string()) @@ -83,8 +89,12 @@ public: return as_string(); return serialized(); } +#endif - int to_int(int default_value = 0) const { return to_i32(default_value); } + int to_int(int default_value = 0) const + { + return to_i32(default_value); + } i32 to_i32(i32 default_value = 0) const { return to_number(default_value); } i64 to_i64(i64 default_value = 0) const { return to_number(default_value); } @@ -138,11 +148,13 @@ public: return m_value.as_bool; } +#ifndef KERNEL String as_string() const { VERIFY(is_string()); return *m_value.as_string; } +#endif const JsonObject& as_object() const { @@ -230,7 +242,9 @@ private: Type m_type { Type::Null }; union { +#ifndef KERNEL StringImpl* as_string { nullptr }; +#endif JsonArray* as_array; JsonObject* as_object; #if !defined(KERNEL) @@ -244,6 +258,7 @@ private: } m_value; }; +#ifndef KERNEL template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, JsonValue const& value) @@ -251,6 +266,7 @@ struct Formatter : Formatter { return Formatter::format(builder, value.to_string()); } }; +#endif }