Log Message
Expected shouldn't assume its contained types are copyable https://bugs.webkit.org/show_bug.cgi?id=195986
Patch by Alex Christensen <[email protected]> on 2019-03-25 Reviewed by JF Bastien. Source/WebCore: * contentextensions/ContentExtensionParser.cpp: (WebCore::ContentExtensions::loadAction): Source/WTF: * wtf/Expected.h: (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base): (std::experimental::fundamentals_v3::operator==): (std::experimental::fundamentals_v3::operator!=): * wtf/Unexpected.h: (std::experimental::fundamentals_v3::unexpected::unexpected): Tools: * TestWebKitAPI/Tests/WTF/Expected.cpp: (TestWebKitAPI::NonCopyable::operator== const): (TestWebKitAPI::NonCopyable::operator!= const): (TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (243485 => 243486)
--- trunk/Source/WTF/ChangeLog 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Source/WTF/ChangeLog 2019-03-26 05:53:57 UTC (rev 243486)
@@ -1,3 +1,17 @@
+2019-03-25 Alex Christensen <[email protected]>
+
+ Expected shouldn't assume its contained types are copyable
+ https://bugs.webkit.org/show_bug.cgi?id=195986
+
+ Reviewed by JF Bastien.
+
+ * wtf/Expected.h:
+ (std::experimental::fundamentals_v3::__expected_detail::constexpr_base::constexpr_base):
+ (std::experimental::fundamentals_v3::operator==):
+ (std::experimental::fundamentals_v3::operator!=):
+ * wtf/Unexpected.h:
+ (std::experimental::fundamentals_v3::unexpected::unexpected):
+
2019-03-24 Keith Miller <[email protected]>
Unreviewed, forgot to refactor variable name for windows build in
Modified: trunk/Source/WTF/wtf/Expected.h (243485 => 243486)
--- trunk/Source/WTF/wtf/Expected.h 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Source/WTF/wtf/Expected.h 2019-03-26 05:53:57 UTC (rev 243486)
@@ -249,8 +249,10 @@
constexpr constexpr_storage() : dummy() { }
constexpr constexpr_storage(value_tag_t) : val() { }
constexpr constexpr_storage(error_tag_t) : err() { }
- constexpr constexpr_storage(value_tag_t, const value_type& v) : val(v) { }
- constexpr constexpr_storage(error_tag_t, const error_type& e) : err(e) { }
+ template<typename U = T>
+ constexpr constexpr_storage(value_tag_t, U&& v) : val(std::forward<U>(v)) { }
+ template<typename U = E>
+ constexpr constexpr_storage(error_tag_t, U&& e) : err(std::forward<U>(e)) { }
~constexpr_storage() = default;
};
@@ -311,8 +313,10 @@
constexpr constexpr_base() : s(), has(true) { }
constexpr constexpr_base(value_tag_t tag) : s(tag), has(true) { }
constexpr constexpr_base(error_tag_t tag) : s(tag), has(false) { }
- constexpr constexpr_base(value_tag_t tag, const value_type& val) : s(tag, val), has(true) { }
- constexpr constexpr_base(error_tag_t tag, const error_type& err) : s(tag, err), has(false) { }
+ template<typename U = T>
+ constexpr constexpr_base(value_tag_t tag, U&& val) : s(tag, std::forward<U>(val)), has(true) { }
+ template<typename U = E>
+ constexpr constexpr_base(error_tag_t tag, U&& err) : s(tag, std::forward<U>(err)), has(false) { }
~constexpr_base() = default;
};
@@ -558,15 +562,15 @@
template<class E> constexpr bool operator==(const expected<void, E>& x, const expected<void, E>& y) { return bool(x) == bool(y) && (x ? true : x.error() == y.error()); }
-template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x == expected<T, E>(y); }
-template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
-template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x != expected<T, E>(y); }
-template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
+template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const T& y) { return x ? *x == y : false; }
+template<class T, class E> constexpr bool operator==(const T& x, const expected<T, E>& y) { return y ? x == *y : false; }
+template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const T& y) { return x ? *x != y : true; }
+template<class T, class E> constexpr bool operator!=(const T& x, const expected<T, E>& y) { return y ? x != *y : true; }
-template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x == expected<T, E>(y); }
-template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) == y; }
-template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x != expected<T, E>(y); }
-template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return expected<T, E>(x) != y; }
+template<class T, class E> constexpr bool operator==(const expected<T, E>& x, const unexpected<E>& y) { return x ? false : x.error() == y.value(); }
+template<class T, class E> constexpr bool operator==(const unexpected<E>& x, const expected<T, E>& y) { return y ? false : x.value() == y.error(); }
+template<class T, class E> constexpr bool operator!=(const expected<T, E>& x, const unexpected<E>& y) { return x ? true : x.error() != y.value(); }
+template<class T, class E> constexpr bool operator!=(const unexpected<E>& x, const expected<T, E>& y) { return y ? true : x.value() != y.error(); }
template<typename T, typename E> void swap(expected<T, E>& x, expected<T, E>& y) { x.swap(y); }
Modified: trunk/Source/WTF/wtf/Unexpected.h (243485 => 243486)
--- trunk/Source/WTF/wtf/Unexpected.h 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Source/WTF/wtf/Unexpected.h 2019-03-26 05:53:57 UTC (rev 243486)
@@ -49,8 +49,8 @@
class unexpected {
public:
unexpected() = delete;
- constexpr explicit unexpected(const E&);
- constexpr explicit unexpected(E&&);
+ template <class U = E>
+ constexpr explicit unexpected(E&&);
constexpr const E& value() const &;
constexpr E& value() &;
constexpr E&& value() &&;
@@ -75,8 +75,8 @@
class unexpected {
public:
unexpected() = delete;
- constexpr explicit unexpected(const E& e) : val(e) { }
- constexpr explicit unexpected(E&& e) : val(std::forward<E>(e)) { }
+ template <class U = E>
+ constexpr explicit unexpected(U&& u) : val(std::forward<U>(u)) { }
constexpr const E& value() const & { return val; }
constexpr E& value() & { return val; }
constexpr E&& value() && { return WTFMove(val); }
Modified: trunk/Source/WebCore/ChangeLog (243485 => 243486)
--- trunk/Source/WebCore/ChangeLog 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Source/WebCore/ChangeLog 2019-03-26 05:53:57 UTC (rev 243486)
@@ -1,3 +1,13 @@
+2019-03-25 Alex Christensen <[email protected]>
+
+ Expected shouldn't assume its contained types are copyable
+ https://bugs.webkit.org/show_bug.cgi?id=195986
+
+ Reviewed by JF Bastien.
+
+ * contentextensions/ContentExtensionParser.cpp:
+ (WebCore::ContentExtensions::loadAction):
+
2019-03-20 Ryosuke Niwa <[email protected]>
Leak of SVGFontFaceElement when RenderStyle holds onto a FontRances which uses it
Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (243485 => 243486)
--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp 2019-03-26 05:53:57 UTC (rev 243486)
@@ -256,11 +256,11 @@
String actionType = asString(typeObject)->value(&exec);
if (actionType == "block")
- return {{ ActionType::BlockLoad }};
+ return { Action(ActionType::BlockLoad) };
if (actionType == "ignore-previous-rules")
- return {{ ActionType::IgnorePreviousRules }};
+ return { Action(ActionType::IgnorePreviousRules) };
if (actionType == "block-cookies")
- return {{ ActionType::BlockCookies }};
+ return { Action(ActionType::BlockCookies) };
if (actionType == "css-display-none") {
JSValue selector = actionObject.get(&exec, Identifier::fromString(&exec, "selector"));
if (scope.exception() || !selector.isString())
@@ -274,7 +274,7 @@
return { Action(ActionType::CSSDisplayNoneSelector, selectorString) };
}
if (actionType == "make-https")
- return {{ ActionType::MakeHTTPS }};
+ return { Action(ActionType::MakeHTTPS) };
if (actionType == "notify") {
JSValue notification = actionObject.get(&exec, Identifier::fromString(&exec, "notification"));
if (scope.exception() || !notification.isString())
Modified: trunk/Tools/ChangeLog (243485 => 243486)
--- trunk/Tools/ChangeLog 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Tools/ChangeLog 2019-03-26 05:53:57 UTC (rev 243486)
@@ -1,3 +1,15 @@
+2019-03-25 Alex Christensen <[email protected]>
+
+ Expected shouldn't assume its contained types are copyable
+ https://bugs.webkit.org/show_bug.cgi?id=195986
+
+ Reviewed by JF Bastien.
+
+ * TestWebKitAPI/Tests/WTF/Expected.cpp:
+ (TestWebKitAPI::NonCopyable::operator== const):
+ (TestWebKitAPI::NonCopyable::operator!= const):
+ (TestWebKitAPI::TEST):
+
2019-03-25 Tim Horton <[email protected]>
Remove some now-unnecessary dynamic class lookup
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp (243485 => 243486)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2019-03-26 05:48:08 UTC (rev 243485)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2019-03-26 05:53:57 UTC (rev 243486)
@@ -289,6 +289,17 @@
}
}
+template<typename T>
+struct NonCopyable {
+ NonCopyable(NonCopyable&&) = default;
+ NonCopyable(const NonCopyable&) = delete;
+ NonCopyable& operator=(const NonCopyable&) = delete;
+ NonCopyable& operator=(NonCopyable&&) = default;
+ bool operator==(const NonCopyable<T>& other) const { return value == other.value; }
+ bool operator!=(const NonCopyable<T>& other) const { return value != other.value; }
+ T value;
+};
+
TEST(WTF_Expected, comparison)
{
typedef Expected<int, const char*> Ex;
@@ -334,6 +345,32 @@
EXPECT_FALSE(makeUnexpected(oops) == Ex(42));
EXPECT_NE(makeUnexpected(oops), Ex(42));
+
+ NonCopyable<int> a { 5 };
+ NonCopyable<int> b { 6 };
+ Unexpected<NonCopyable<double>> c { makeUnexpected(NonCopyable<double> { 5.0 }) };
+ Expected<NonCopyable<int>, NonCopyable<double>> d { NonCopyable<int> { 5 } };
+ Expected<NonCopyable<int>, NonCopyable<double>> e { makeUnexpected(NonCopyable<double> { 5.0 }) };
+
+ EXPECT_TRUE(a != e);
+ EXPECT_TRUE(e != a);
+ EXPECT_FALSE(a == e);
+ EXPECT_FALSE(e == a);
+
+ EXPECT_TRUE(b != e);
+ EXPECT_TRUE(e != b);
+ EXPECT_FALSE(b == e);
+ EXPECT_FALSE(e == b);
+
+ EXPECT_TRUE(c != d);
+ EXPECT_TRUE(d != c);
+ EXPECT_FALSE(c == d);
+ EXPECT_FALSE(d == c);
+
+ EXPECT_TRUE(c == e);
+ EXPECT_TRUE(e == c);
+ EXPECT_FALSE(c != e);
+ EXPECT_FALSE(e != c);
}
struct NonTrivialDtor {
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
