WebKit Bugzilla
Attachment 346358 Details for
Bug 188250
: Use WTF::Variant for WebPreferencesStore::Value
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188250-20180801215546.patch (text/plain), 18.42 KB, created by
Alex Christensen
on 2018-08-01 21:55:47 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Alex Christensen
Created:
2018-08-01 21:55:47 PDT
Size:
18.42 KB
patch
obsolete
>Index: Source/WebKit/ChangeLog >=================================================================== >--- Source/WebKit/ChangeLog (revision 234493) >+++ Source/WebKit/ChangeLog (working copy) >@@ -1,3 +1,39 @@ >+2018-08-01 Alex Christensen <achristensen@webkit.org> >+ >+ Use WTF::Variant for WebPreferencesStore::Value >+ https://bugs.webkit.org/show_bug.cgi?id=188250 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ It's basically a Variant now. This just uses templates. >+ >+ * Platform/IPC/VariantCoders.h: Added. >+ (IPC::VariantCoder::encodeHelper): >+ (IPC::VariantCoder::decodeHelper): >+ * Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb: >+ * Shared/WebPreferencesStore.cpp: >+ (WebKit::WebPreferencesStore::decode): >+ (WebKit::TypeVisitor::operator() const): >+ (WebKit::valueForKey): >+ (WebKit::WebPreferencesStore::Value::encode const): Deleted. >+ (WebKit::WebPreferencesStore::Value::decode): Deleted. >+ (WebKit::as<String>): Deleted. >+ (WebKit::as<bool>): Deleted. >+ (WebKit::as<uint32_t>): Deleted. >+ (WebKit::as<double>): Deleted. >+ * Shared/WebPreferencesStore.h: >+ (WebKit::WebPreferencesStore::Value::Value): Deleted. >+ (WebKit::WebPreferencesStore::Value::operator=): Deleted. >+ (WebKit::WebPreferencesStore::Value::~Value): Deleted. >+ (WebKit::WebPreferencesStore::Value::type const): Deleted. >+ (WebKit::WebPreferencesStore::Value::asString const): Deleted. >+ (WebKit::WebPreferencesStore::Value::asBool const): Deleted. >+ (WebKit::WebPreferencesStore::Value::asUInt32 const): Deleted. >+ (WebKit::WebPreferencesStore::Value::asDouble const): Deleted. >+ (WebKit::WebPreferencesStore::Value::destroy): Deleted. >+ (): Deleted. >+ * WebKit.xcodeproj/project.pbxproj: >+ > 2018-08-01 Tomas Popela <tpopela@redhat.com> > > [WTF] Rename String::format to String::deprecatedFormat >Index: Source/WebKit/Platform/IPC/VariantCoders.h >=================================================================== >--- Source/WebKit/Platform/IPC/VariantCoders.h (nonexistent) >+++ Source/WebKit/Platform/IPC/VariantCoders.h (working copy) >@@ -0,0 +1,95 @@ >+/* >+ * Copyright (C) 2018 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#include "ArgumentCoders.h" >+#include <wtf/Variant.h> >+ >+namespace IPC { >+ >+template<size_t index, typename... Types> >+struct VariantCoder { >+ static void encodeHelper(Encoder& encoder, const WTF::Variant<Types...>& variant, unsigned i) >+ { >+ if (i == index) { >+ encoder << WTF::get<index>(variant); >+ return; >+ } >+ VariantCoder<index - 1, Types...>::encodeHelper(encoder, variant, i); >+ } >+ >+ static auto decodeHelper(Decoder& decoder, unsigned i) -> std::optional<WTF::Variant<Types...>> >+ { >+ if (i == index) { >+ std::optional<WTF::variant_alternative_t<index, WTF::Variant<Types...>>> optional; >+ decoder >> optional; >+ if (!optional) >+ return std::nullopt; >+ return { WTFMove(*optional) }; >+ } >+ return VariantCoder<index - 1, Types...>::decodeHelper(decoder, i); >+ } >+}; >+ >+template<typename... Types> >+struct VariantCoder<0, Types...> { >+ static void encodeHelper(Encoder& encoder, const WTF::Variant<Types...>& variant, unsigned i) >+ { >+ ASSERT_UNUSED(i, !i); >+ encoder << WTF::get<0>(variant); >+ } >+ >+ static auto decodeHelper(Decoder& decoder, unsigned i) -> std::optional<WTF::Variant<Types...>> >+ { >+ ASSERT_UNUSED(i, !i); >+ std::optional<WTF::variant_alternative_t<0, WTF::Variant<Types...>>> optional; >+ decoder >> optional; >+ if (!optional) >+ return std::nullopt; >+ return { WTFMove(*optional) }; >+ } >+}; >+ >+template<typename... Types> struct ArgumentCoder<WTF::Variant<Types...>> { >+ static void encode(Encoder& encoder, const WTF::Variant<Types...>& variant) >+ { >+ ASSERT(static_cast<unsigned>(variant.index()) == variant.index()); >+ unsigned i = variant.index(); >+ encoder << i; >+ VariantCoder<sizeof...(Types) - 1, Types...>::encodeHelper(encoder, variant, i); >+ } >+ >+ static auto decode(Decoder& decoder) -> std::optional<WTF::Variant<Types...>> >+ { >+ std::optional<unsigned> i; >+ decoder >> i; >+ if (!i) >+ return std::nullopt; >+ return VariantCoder<sizeof...(Types) - 1, Types...>::decodeHelper(decoder, *i); >+ } >+}; >+ >+} >Index: Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb >=================================================================== >--- Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb (revision 234466) >+++ Source/WebKit/Scripts/PreferencesTemplates/WebPreferencesStoreDefaultsMap.cpp.erb (working copy) >@@ -31,6 +31,7 @@ > #include "WebPreferencesDefaultValues.h" > #include "WebPreferencesKeys.h" > #include <wtf/NeverDestroyed.h> >+#include <wtf/Variant.h> > > // FIXME: These should added via options in WebPreferences.yaml, rather than hardcoded. > #include "FontSmoothingLevel.h" >Index: Source/WebKit/Shared/WebPreferencesStore.cpp >=================================================================== >--- Source/WebKit/Shared/WebPreferencesStore.cpp (revision 234466) >+++ Source/WebKit/Shared/WebPreferencesStore.cpp (working copy) >@@ -26,6 +26,7 @@ > #include "config.h" > #include "WebPreferencesStore.h" > >+#include "VariantCoders.h" > #include "WebCoreArgumentCoders.h" > #include "WebPreferencesKeys.h" > #include <wtf/NeverDestroyed.h> >@@ -42,72 +43,6 @@ static BoolOverridesMap& boolTestRunnerO > return map; > } > >-void WebPreferencesStore::Value::encode(IPC::Encoder& encoder) const >-{ >- encoder.encodeEnum(m_type); >- >- switch (m_type) { >- case Type::None: >- break; >- case Type::String: >- encoder << m_string; >- break; >- case Type::Bool: >- encoder << m_bool; >- break; >- case Type::UInt32: >- encoder << m_uint32; >- break; >- case Type::Double: >- encoder << m_double; >- break; >- } >-} >- >-bool WebPreferencesStore::Value::decode(IPC::Decoder& decoder, Value& result) >-{ >- Value::Type type; >- if (!decoder.decodeEnum(type)) >- return false; >- >- switch (type) { >- case Type::None: >- break; >- case Type::String: { >- String value; >- if (!decoder.decode(value)) >- return false; >- result = Value(value); >- break; >- } >- case Type::Bool: { >- bool value; >- if (!decoder.decode(value)) >- return false; >- result = Value(value); >- break; >- } >- case Type::UInt32: { >- uint32_t value; >- if (!decoder.decode(value)) >- return false; >- result = Value(value); >- break; >- } >- case Type::Double: { >- double value; >- if (!decoder.decode(value)) >- return false; >- result = Value(value); >- break; >- } >- default: >- return false; >- } >- >- return true; >-} >- > WebPreferencesStore::WebPreferencesStore() > { > } >@@ -120,10 +55,17 @@ void WebPreferencesStore::encode(IPC::En > > bool WebPreferencesStore::decode(IPC::Decoder& decoder, WebPreferencesStore& result) > { >- if (!decoder.decode(result.m_values)) >+ std::optional<HashMap<String, Value>> values; >+ decoder >> values; >+ if (!values) > return false; >- if (!decoder.decode(result.m_overridenDefaults)) >+ result.m_values = WTFMove(*values); >+ >+ std::optional<HashMap<String, Value>> overridenDefaults; >+ decoder >> overridenDefaults; >+ if (!overridenDefaults) > return false; >+ result.m_overridenDefaults = WTFMove(*overridenDefaults); > return true; > } > >@@ -137,37 +79,21 @@ void WebPreferencesStore::removeTestRunn > boolTestRunnerOverridesMap().clear(); > } > >-template <typename T> struct ToType { }; >- >-template<> struct ToType<String> { static const auto value = WebPreferencesStore::Value::Type::String; }; >-template<> struct ToType<bool> { static const auto value = WebPreferencesStore::Value::Type::Bool; }; >-template<> struct ToType<uint32_t> { static const auto value = WebPreferencesStore::Value::Type::UInt32; }; >-template<> struct ToType<double> { static const auto value = WebPreferencesStore::Value::Type::Double; }; >- >- >-template<typename MappedType> MappedType as(const WebPreferencesStore::Value&); >- >-template<> String as<String>(const WebPreferencesStore::Value& value) { return value.asString(); } >-template<> bool as<bool>(const WebPreferencesStore::Value& value) { return value.asBool(); } >-template<> uint32_t as<uint32_t>(const WebPreferencesStore::Value& value) { return value.asUInt32(); } >-template<> double as<double>(const WebPreferencesStore::Value& value) { return value.asDouble(); } >- >- > template<typename MappedType> > static MappedType valueForKey(const WebPreferencesStore::ValueMap& values, const WebPreferencesStore::ValueMap& overridenDefaults, const String& key) > { > auto valuesIt = values.find(key); >- if (valuesIt != values.end() && valuesIt->value.type() == ToType<MappedType>::value) >- return as<MappedType>(valuesIt->value); >+ if (valuesIt != values.end() && WTF::holds_alternative<MappedType>(valuesIt->value)) >+ return WTF::get<MappedType>(valuesIt->value); > > auto overridenDefaultsIt = overridenDefaults.find(key); >- if (overridenDefaultsIt != overridenDefaults.end() && overridenDefaultsIt->value.type() == ToType<MappedType>::value) >- return as<MappedType>(overridenDefaultsIt->value); >+ if (overridenDefaultsIt != overridenDefaults.end() && WTF::holds_alternative<MappedType>(overridenDefaultsIt->value)) >+ return WTF::get<MappedType>(overridenDefaultsIt->value); > > auto& defaultsMap = WebPreferencesStore::defaults(); > auto defaultsIt = defaultsMap.find(key); >- if (defaultsIt != defaultsMap.end() && defaultsIt->value.type() == ToType<MappedType>::value) >- return as<MappedType>(defaultsIt->value); >+ if (defaultsIt != defaultsMap.end() && WTF::holds_alternative<MappedType>(defaultsIt->value)) >+ return WTF::get<MappedType>(defaultsIt->value); > > return MappedType(); > } >Index: Source/WebKit/Shared/WebPreferencesStore.h >=================================================================== >--- Source/WebKit/Shared/WebPreferencesStore.h (revision 234466) >+++ Source/WebKit/Shared/WebPreferencesStore.h (working copy) >@@ -62,119 +62,7 @@ struct WebPreferencesStore { > static void overrideBoolValueForKey(const String& key, bool value); > static void removeTestRunnerOverrides(); > >- struct Value { >- enum class Type { >- None, >- String, >- Bool, >- UInt32, >- Double, >- }; >- >- void encode(IPC::Encoder&) const; >- static bool decode(IPC::Decoder&, Value&); >- >- explicit Value() : m_type(Type::None) { } >- explicit Value(const String& value) : m_type(Type::String), m_string(value) { } >- explicit Value(bool value) : m_type(Type::Bool), m_bool(value) { } >- explicit Value(uint32_t value) : m_type(Type::UInt32), m_uint32(value) { } >- explicit Value(double value) : m_type(Type::Double), m_double(value) { } >- >- Value(Value&& value) >- : m_type(value.m_type) >- { >- switch (m_type) { >- case Type::None: >- break; >- case Type::String: >- new (&m_string) String(WTFMove(value.m_string)); >- break; >- case Type::Bool: >- m_bool = value.m_bool; >- break; >- case Type::UInt32: >- m_uint32 = value.m_uint32; >- break; >- case Type::Double: >- m_double = value.m_double; >- break; >- } >- } >- >- Value& operator=(const Value& other) >- { >- if (this == &other) >- return *this; >- >- destroy(); >- >- m_type = other.m_type; >- switch (m_type) { >- case Type::None: >- break; >- case Type::String: >- new (&m_string) String(other.m_string); >- break; >- case Type::Bool: >- m_bool = other.m_bool; >- break; >- case Type::UInt32: >- m_uint32 = other.m_uint32; >- break; >- case Type::Double: >- m_double = other.m_double; >- break; >- } >- >- return *this; >- } >- >- ~Value() >- { >- destroy(); >- } >- >- Type type() const { return m_type; } >- >- String asString() const >- { >- ASSERT(m_type == Type::String); >- return m_string; >- } >- >- bool asBool() const >- { >- ASSERT(m_type == Type::Bool); >- return m_bool; >- } >- >- uint32_t asUInt32() const >- { >- ASSERT(m_type == Type::UInt32); >- return m_uint32; >- } >- >- double asDouble() const >- { >- ASSERT(m_type == Type::Double); >- return m_double; >- } >- >- private: >- void destroy() >- { >- if (m_type == Type::String) >- m_string.~String(); >- } >- >- Type m_type; >- union { >- String m_string; >- bool m_bool; >- uint32_t m_uint32; >- double m_double; >- }; >- }; >+ using Value = Variant<String, bool, uint32_t, double>; > > typedef HashMap<String, Value> ValueMap; > ValueMap m_values; >Index: Source/WebKit/WebKit.xcodeproj/project.pbxproj >=================================================================== >--- Source/WebKit/WebKit.xcodeproj/project.pbxproj (revision 234466) >+++ Source/WebKit/WebKit.xcodeproj/project.pbxproj (working copy) >@@ -1287,6 +1287,7 @@ > 5C8DD3801FE4521600F2A556 /* WebsiteAutoplayPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C8DD37F1FE4519200F2A556 /* WebsiteAutoplayPolicy.h */; }; > 5C9E56821DF7F1AB00C9EE33 /* WKWebsitePolicies.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5C9E56801DF7F05500C9EE33 /* WKWebsitePolicies.cpp */; }; > 5C9E56831DF7F1B300C9EE33 /* WKWebsitePolicies.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C9E56811DF7F05500C9EE33 /* WKWebsitePolicies.h */; settings = {ATTRIBUTES = (Private, ); }; }; >+ 5CA9854F211289430057EB6B /* VariantCoders.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CA9854E211288FC0057EB6B /* VariantCoders.h */; }; > 5CB2378B1DF0DE5300117AA3 /* _WKWebsitePolicies.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB2378A1DF0DD4300117AA3 /* _WKWebsitePolicies.mm */; }; > 5CB2378C1DF0DE6E00117AA3 /* _WKWebsitePolicies.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB237891DF0DD4300117AA3 /* _WKWebsitePolicies.h */; settings = {ATTRIBUTES = (Private, ); }; }; > 5CB2378E1DF0E0D300117AA3 /* _WKWebsitePoliciesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5CB2378D1DF0E0C200117AA3 /* _WKWebsitePoliciesInternal.h */; }; >@@ -3850,6 +3851,7 @@ > 5C8DD3811FE455CA00F2A556 /* WebsiteAutoplayQuirk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebsiteAutoplayQuirk.h; sourceTree = "<group>"; }; > 5C9E56801DF7F05500C9EE33 /* WKWebsitePolicies.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKWebsitePolicies.cpp; sourceTree = "<group>"; }; > 5C9E56811DF7F05500C9EE33 /* WKWebsitePolicies.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebsitePolicies.h; sourceTree = "<group>"; }; >+ 5CA9854E211288FC0057EB6B /* VariantCoders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VariantCoders.h; sourceTree = "<group>"; }; > 5CB237891DF0DD4300117AA3 /* _WKWebsitePolicies.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebsitePolicies.h; sourceTree = "<group>"; }; > 5CB2378A1DF0DD4300117AA3 /* _WKWebsitePolicies.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKWebsitePolicies.mm; sourceTree = "<group>"; }; > 5CB2378D1DF0E0C200117AA3 /* _WKWebsitePoliciesInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebsitePoliciesInternal.h; sourceTree = "<group>"; }; >@@ -5732,6 +5734,7 @@ > 1AAB0378185A7C6A00EDF501 /* MessageSender.h */, > 1AE00D6918327C1200087DD7 /* StringReference.cpp */, > 1AE00D6A18327C1200087DD7 /* StringReference.h */, >+ 5CA9854E211288FC0057EB6B /* VariantCoders.h */, > ); > path = IPC; > sourceTree = "<group>"; >@@ -9409,6 +9412,7 @@ > 4A3CC18B19B0640F00D14AEF /* UserMediaPermissionRequestManagerProxy.h in Headers */, > 4A3CC18D19B0641900D14AEF /* UserMediaPermissionRequestProxy.h in Headers */, > 074E75FE1DF2211900D318EC /* UserMediaProcessManager.h in Headers */, >+ 5CA9854F211289430057EB6B /* VariantCoders.h in Headers */, > E4E864931B16750700C82F40 /* VersionChecks.h in Headers */, > 52D5A1B01C57495A00DE34A3 /* VideoFullscreenManagerProxy.h in Headers */, > 2D125C5E1857EA05003BA3CB /* ViewGestureController.h in Headers */,
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188250
:
346358
|
346393
|
346394
|
346395
|
346418