Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Unified Diff: third_party/WebKit/Source/wtf/FunctionalTest.cpp

Issue 2097013002: Remove ParamStorageTraits::wrap and move unwrap to global scope (3/5) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@weak_persistent
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/FunctionalTest.cpp
diff --git a/third_party/WebKit/Source/wtf/FunctionalTest.cpp b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
index b2498526763f3108d856f7e710cb9bcf1e7b9d8e..5f9196220fa4f84a9f03ada791ee2ed28d27a5e9 100644
--- a/third_party/WebKit/Source/wtf/FunctionalTest.cpp
+++ b/third_party/WebKit/Source/wtf/FunctionalTest.cpp
@@ -45,38 +45,46 @@ private:
int m_value;
};
-class WrappedClass {
+// This class must be wrapped in bind() and unwrapped in closure execution.
+class ClassToBeWrapped {
+ WTF_MAKE_NONCOPYABLE(ClassToBeWrapped);
public:
- explicit WrappedClass(int value)
+ explicit ClassToBeWrapped(int value)
: m_value(value)
{
}
- UnwrappedClass unwrap() const { return UnwrappedClass(m_value); }
+ int value() const { return m_value; }
private:
int m_value;
};
-// This class must be wrapped in bind() and unwrapped in closure execution.
-class ClassToBeWrapped {
- WTF_MAKE_NONCOPYABLE(ClassToBeWrapped);
+class WrappedClass {
public:
- explicit ClassToBeWrapped(int value)
+ WrappedClass(const ClassToBeWrapped& to_be_wrapped)
+ : m_value(to_be_wrapped.value())
+ {
+ }
+
+ explicit WrappedClass(int value)
: m_value(value)
{
}
- WrappedClass wrap() const { return WrappedClass(m_value); }
+ UnwrappedClass unwrap() const { return UnwrappedClass(m_value); }
private:
int m_value;
};
+UnwrappedClass Unwrap(const WrappedClass& wrapped)
+{
+ return wrapped.unwrap();
+}
+
template<> struct ParamStorageTraits<ClassToBeWrapped> {
using StorageType = WrappedClass;
- static StorageType wrap(const ClassToBeWrapped& value) { return value.wrap(); }
- static UnwrappedClass unwrap(const StorageType& value) { return value.unwrap(); }
};
class HasWeakPtrSupport {
@@ -523,16 +531,16 @@ TEST(FunctionalTest, CountCopiesOfBoundArguments)
{
CountCopy lvalue;
std::unique_ptr<Function<int()>> bound = bind(takeCountCopyAsConstReference, lvalue);
- EXPECT_EQ(2, (*bound)()); // wrapping and unwrapping.
+ EXPECT_EQ(1, (*bound)()); // unwrapping.
bound = bind(takeCountCopyAsConstReference, CountCopy()); // Rvalue.
- EXPECT_EQ(2, (*bound)());
+ EXPECT_EQ(1, (*bound)());
bound = bind(takeCountCopyAsValue, lvalue);
- EXPECT_EQ(3, (*bound)()); // wrapping, unwrapping and copying in the final function argument.
+ EXPECT_EQ(2, (*bound)()); // unwrapping and copying in the final function argument.
bound = bind(takeCountCopyAsValue, CountCopy());
- EXPECT_EQ(3, (*bound)());
+ EXPECT_EQ(2, (*bound)());
}
TEST(FunctionalTest, MoveUnboundArgumentsByRvalueReference)
« no previous file with comments | « third_party/WebKit/Source/wtf/Functional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698