Modified: trunk/Source/WTF/ChangeLog (210252 => 210253)
--- trunk/Source/WTF/ChangeLog 2017-01-03 23:06:52 UTC (rev 210252)
+++ trunk/Source/WTF/ChangeLog 2017-01-03 23:18:45 UTC (rev 210253)
@@ -1,3 +1,23 @@
+2017-01-03 Sam Weinig <[email protected]>
+
+ Make WTF::Expected support Ref template parameters
+ https://bugs.webkit.org/show_bug.cgi?id=166662
+
+ Reviewed by Alex Christensen.
+
+ Tests: Added to TestWebKitAPI/Expected.cpp
+
+ * wtf/Expected.h:
+ (WTF::UnexpectedType::value):
+ Add overloads based on this value type to allow getting at the value
+ as an rvalue for moving the error into the Expected.
+
+ (WTF::Expected::Expected):
+ Add overload that takes an ErrorType/UnexpectedType<ErrorType> as an rvalue.
+
+ (WTF::Expected::swap):
+ Move the temporary value/error rather than copying.
+
2017-01-02 Julien Brianceau <[email protected]>
Remove sh4 specific code from _javascript_Core
Modified: trunk/Source/WTF/wtf/Expected.h (210252 => 210253)
--- trunk/Source/WTF/wtf/Expected.h 2017-01-03 23:06:52 UTC (rev 210252)
+++ trunk/Source/WTF/wtf/Expected.h 2017-01-03 23:18:45 UTC (rev 210253)
@@ -46,8 +46,9 @@
UnexpectedType() = delete;
constexpr explicit UnexpectedType(const E& e) : val(e) { }
constexpr explicit UnexpectedType(E&& e) : val(std::forward<E>(e)) { }
- constexpr const E& value() const { return val; }
- RELAXED_CONSTEXPR E& value() { return val; }
+ constexpr const E& value() const& { return val; }
+ RELAXED_CONSTEXPR E& value() & { return val; }
+ RELAXED_CONSTEXPR E&& value() && { return WTFMove(val); }
private:
E val;
@@ -199,6 +200,7 @@
constexpr ConstexprBase(ValueTagType tag) : s(tag), has(true) { }
constexpr ConstexprBase(ErrorTagType tag) : s(tag), has(false) { }
constexpr ConstexprBase(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
+ constexpr ConstexprBase(ErrorTagType tag, ErrorType&& err) : s(tag, std::forward<ErrorType>(err)), has(false) { }
~ConstexprBase() = default;
};
@@ -212,6 +214,7 @@
constexpr Base(ValueTagType tag) : s(tag), has(true) { }
constexpr Base(ErrorTagType tag) : s(tag), has(false) { }
constexpr Base(ErrorTagType tag, const ErrorType& err) : s(tag, err), has(false) { }
+ constexpr Base(ErrorTagType tag, ErrorType&& err) : s(tag, std::forward<ErrorType>(err)), has(false) { }
Base(const Base& o)
: has(o.has)
{
@@ -263,6 +266,7 @@
// template <class... Args> constexpr explicit Expected(in_place_t, Args&&...);
// template <class U, class... Args> constexpr explicit Expected(in_place_t, std::initializer_list<U>, Args&&...);
constexpr Expected(UnexpectedType<ErrorType> const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
+ constexpr Expected(UnexpectedType<ErrorType>&& u) : base(ExpectedDetail::ErrorTag, std::forward<UnexpectedType<E>>(u).value()) { }
template <class Err> constexpr Expected(UnexpectedType<Err> const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
// template <class... Args> constexpr explicit Expected(UnexpectTag, Args&&...);
// template <class U, class... Args> constexpr explicit Expected(UnexpectTag, std::initializer_list<U>, Args&&...);
@@ -285,12 +289,12 @@
else if (base::has && !o.has) {
ErrorType e(WTFMove(o.s.err));
::new (&o.s.val) ValueType(WTFMove(base::s.val));
- ::new (&base::s.err) ErrorType(e);
+ ::new (&base::s.err) ErrorType(WTFMove(e));
swap(base::has, o.has);
} else if (!base::has && o.has) {
ValueType v(WTFMove(o.s.val));
::new (&o.s.err) ErrorType(WTFMove(base::s.err));
- ::new (&base::s.val) ValueType(v);
+ ::new (&base::s.val) ValueType(WTFMove(v));
swap(base::has, o.has);
} else
swap(base::s.err, o.s.err);
@@ -336,6 +340,7 @@
Expected(Expected&&) = default;
// constexpr explicit Expected(in_place_t);
constexpr Expected(UnexpectedType<E> const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
+ constexpr Expected(UnexpectedType<E>&& u) : base(ExpectedDetail::ErrorTag, std::forward<UnexpectedType<E>>(u).value()) { }
template <class Err> constexpr Expected(UnexpectedType<Err> const& u) : base(ExpectedDetail::ErrorTag, u.value()) { }
~Expected() = default;
Modified: trunk/Tools/ChangeLog (210252 => 210253)
--- trunk/Tools/ChangeLog 2017-01-03 23:06:52 UTC (rev 210252)
+++ trunk/Tools/ChangeLog 2017-01-03 23:18:45 UTC (rev 210253)
@@ -1,3 +1,14 @@
+2017-01-03 Sam Weinig <[email protected]>
+
+ Make WTF::Expected support Ref template parameters
+ https://bugs.webkit.org/show_bug.cgi?id=166662
+
+ Reviewed by Alex Christensen.
+
+ * TestWebKitAPI/Tests/WTF/Expected.cpp:
+ (TestWebKitAPI::TEST):
+ Add tests for using Ref with Expected.
+
2017-01-03 Michael Catanzaro <[email protected]>
[GTK] Expose WebKitSecurityOrigin API
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp (210252 => 210253)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2017-01-03 23:06:52 UTC (rev 210252)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Expected.cpp 2017-01-03 23:18:45 UTC (rev 210253)
@@ -25,10 +25,13 @@
#include "config.h"
+#include "RefLogger.h"
+
#include <string>
#include <unordered_map>
#include <wtf/Expected.h>
+#include <wtf/Ref.h>
namespace WTF {
@@ -467,4 +470,43 @@
EXPECT_EQ(m[E(makeUnexpected(foof))], 0xf00f);
}
+TEST(WTF_Expected, Ref)
+{
+ {
+ RefLogger a("a");
+ Expected<Ref<RefLogger>, int> expected = Ref<RefLogger>(a);
+ EXPECT_TRUE(expected.hasValue());
+ EXPECT_EQ(&a, expected.value().ptr());
+ }
+
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefLogger a("a");
+ Expected<Ref<RefLogger>, int> expected = makeExpected<Ref<RefLogger>, int>(Ref<RefLogger>(a));
+ EXPECT_TRUE(expected.hasValue());
+ EXPECT_EQ(&a, expected.value().ptr());
+ }
+
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefLogger a("a");
+ Expected<int, Ref<RefLogger>> expected = makeUnexpected(Ref<RefLogger>(a));
+ EXPECT_FALSE(expected.hasValue());
+ EXPECT_EQ(&a, expected.error().ptr());
+ }
+
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+
+ {
+ RefLogger a("a");
+ Expected<void, Ref<RefLogger>> expected = makeUnexpected(Ref<RefLogger>(a));
+ EXPECT_FALSE(expected.hasValue());
+ EXPECT_EQ(&a, expected.error().ptr());
+ }
+
+ ASSERT_STREQ("ref(a) deref(a) ", takeLogStr().c_str());
+}
+
} // namespace TestWebkitAPI