Title: [102813] trunk
- Revision
- 102813
- Author
- [email protected]
- Date
- 2011-12-14 12:59:53 -0800 (Wed, 14 Dec 2011)
Log Message
bind should handle member functions
https://bugs.webkit.org/show_bug.cgi?id=74529
Reviewed by Sam Weinig.
Source/_javascript_Core:
Add FunctionWrapper partial specializations for member function pointers.
* wtf/Functional.h:
(WTF::C::):
Tools:
Add tests.
* TestWebKitAPI/Tests/WTF/Functional.cpp:
(TestWebKitAPI::A::A):
(TestWebKitAPI::A::f):
(TestWebKitAPI::A::addF):
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (102812 => 102813)
--- trunk/Source/_javascript_Core/ChangeLog 2011-12-14 20:56:46 UTC (rev 102812)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-12-14 20:59:53 UTC (rev 102813)
@@ -1,3 +1,15 @@
+2011-12-14 Anders Carlsson <[email protected]>
+
+ bind should handle member functions
+ https://bugs.webkit.org/show_bug.cgi?id=74529
+
+ Reviewed by Sam Weinig.
+
+ Add FunctionWrapper partial specializations for member function pointers.
+
+ * wtf/Functional.h:
+ (WTF::C::):
+
2011-12-14 Gavin Barraclough <[email protected]>
DFG relies on returning a struct in registers
Modified: trunk/Source/_javascript_Core/wtf/Functional.h (102812 => 102813)
--- trunk/Source/_javascript_Core/wtf/Functional.h 2011-12-14 20:56:46 UTC (rev 102812)
+++ trunk/Source/_javascript_Core/wtf/Functional.h 2011-12-14 20:59:53 UTC (rev 102813)
@@ -96,6 +96,42 @@
R (*m_function)(P0, P1);
};
+template<typename R, typename C> class FunctionWrapper<R (C::*)()> {
+public:
+ typedef R ResultType;
+
+ explicit FunctionWrapper(R (C::*function)())
+ : m_function(function)
+ {
+ }
+
+ R operator()(C* c)
+ {
+ return (c->*m_function)();
+ }
+
+private:
+ R (C::*m_function)();
+};
+
+template<typename R, typename C, typename P0> class FunctionWrapper<R (C::*)(P0)> {
+public:
+ typedef R ResultType;
+
+ explicit FunctionWrapper(R (C::*function)(P0))
+ : m_function(function)
+ {
+ }
+
+ R operator()(C* c, P0 p0)
+ {
+ return (c->*m_function)(p0);
+ }
+
+private:
+ R (C::*m_function)(P0);
+};
+
class FunctionImplBase : public ThreadSafeRefCounted<FunctionImplBase> {
public:
virtual ~FunctionImplBase() { }
Modified: trunk/Tools/ChangeLog (102812 => 102813)
--- trunk/Tools/ChangeLog 2011-12-14 20:56:46 UTC (rev 102812)
+++ trunk/Tools/ChangeLog 2011-12-14 20:59:53 UTC (rev 102813)
@@ -1,5 +1,20 @@
2011-12-14 Anders Carlsson <[email protected]>
+ bind should handle member functions
+ https://bugs.webkit.org/show_bug.cgi?id=74529
+
+ Reviewed by Sam Weinig.
+
+ Add tests.
+
+ * TestWebKitAPI/Tests/WTF/Functional.cpp:
+ (TestWebKitAPI::A::A):
+ (TestWebKitAPI::A::f):
+ (TestWebKitAPI::A::addF):
+ (TestWebKitAPI::TEST):
+
+2011-12-14 Anders Carlsson <[email protected]>
+
Add unary and binary bind overloads
https://bugs.webkit.org/show_bug.cgi?id=74524
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Functional.cpp (102812 => 102813)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/Functional.cpp 2011-12-14 20:56:46 UTC (rev 102812)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Functional.cpp 2011-12-14 20:59:53 UTC (rev 102813)
@@ -81,4 +81,28 @@
ASSERT_EQ(2, subtractTwoFromFourFunction());
}
+class A {
+public:
+ explicit A(int i)
+ : m_i(i)
+ {
+ }
+
+ int f() { return m_i; }
+ int addF(int j) { return m_i + j; }
+
+private:
+ int m_i;
+};
+
+TEST(FunctionalTest, MemberFunctionBind)
+{
+ A a(10);
+ Function<int ()> function1 = bind(&A::f, &a);
+ ASSERT_EQ(10, function1());
+
+ Function<int ()> function2 = bind(&A::addF, &a, 15);
+ ASSERT_EQ(25, function2());
+}
+
} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes