diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-12-22 20:40:33 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-26 09:36:16 +0100 |
commit | 9b483625e653d2ea89533c99b501a2e296c4d366 (patch) | |
tree | a84ddbd6a8bae04104dd9617e3b99e5e1f8e9c4a /Userland/Libraries/LibWeb/Cookie/Cookie.cpp | |
parent | 765c5b416f61f08dd68ea4b77a39e9380f2c8f9d (diff) | |
download | serenity-9b483625e653d2ea89533c99b501a2e296c4d366.zip |
LibIPC+Everywhere: Change IPC decoders to construct values in-place
Currently, the generated IPC decoders will default-construct the type to
be decoded, then pass that value by reference to the concrete decoder.
This, of course, requires that the type is default-constructible. This
was an issue for decoding Variants, which had to require the first type
in the Variant list is Empty, to ensure it is default constructible.
Further, this made it possible for values to become uninitialized in
user-defined decoders.
This patch makes the decoder interface such that the concrete decoders
themselves contruct the decoded type upon return from the decoder. To do
so, the default decoders in IPC::Decoder had to be moved to the IPC
namespace scope, as these decoders are now specializations instead of
overloaded methods (C++ requires specializations to be in a namespace
scope).
Diffstat (limited to 'Userland/Libraries/LibWeb/Cookie/Cookie.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/Cookie/Cookie.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/Userland/Libraries/LibWeb/Cookie/Cookie.cpp b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp index 2a43385e64..6ddaa79c05 100644 --- a/Userland/Libraries/LibWeb/Cookie/Cookie.cpp +++ b/Userland/Libraries/LibWeb/Cookie/Cookie.cpp @@ -58,19 +58,20 @@ bool IPC::encode(Encoder& encoder, Web::Cookie::Cookie const& cookie) } template<> -ErrorOr<void> IPC::decode(Decoder& decoder, Web::Cookie::Cookie& cookie) +ErrorOr<Web::Cookie::Cookie> IPC::decode(Decoder& decoder) { - TRY(decoder.decode(cookie.name)); - TRY(decoder.decode(cookie.value)); - TRY(decoder.decode(cookie.domain)); - TRY(decoder.decode(cookie.path)); - TRY(decoder.decode(cookie.creation_time)); - TRY(decoder.decode(cookie.expiry_time)); - TRY(decoder.decode(cookie.host_only)); - TRY(decoder.decode(cookie.http_only)); - TRY(decoder.decode(cookie.last_access_time)); - TRY(decoder.decode(cookie.persistent)); - TRY(decoder.decode(cookie.secure)); - TRY(decoder.decode(cookie.same_site)); - return {}; + auto name = TRY(decoder.decode<DeprecatedString>()); + auto value = TRY(decoder.decode<DeprecatedString>()); + auto domain = TRY(decoder.decode<DeprecatedString>()); + auto path = TRY(decoder.decode<DeprecatedString>()); + auto creation_time = TRY(decoder.decode<Core::DateTime>()); + auto expiry_time = TRY(decoder.decode<Core::DateTime>()); + auto host_only = TRY(decoder.decode<bool>()); + auto http_only = TRY(decoder.decode<bool>()); + auto last_access_time = TRY(decoder.decode<Core::DateTime>()); + auto persistent = TRY(decoder.decode<bool>()); + auto secure = TRY(decoder.decode<bool>()); + auto same_site = TRY(decoder.decode<Web::Cookie::SameSite>()); + + return Web::Cookie::Cookie { move(name), move(value), same_site, move(creation_time), move(last_access_time), move(expiry_time), move(domain), move(path), secure, http_only, host_only, persistent }; } |