Changeset 102813 in webkit
- Timestamp:
- Dec 14, 2011 12:59:53 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r102811 r102813 1 2011-12-14 Anders Carlsson <andersca@apple.com> 2 3 bind should handle member functions 4 https://bugs.webkit.org/show_bug.cgi?id=74529 5 6 Reviewed by Sam Weinig. 7 8 Add FunctionWrapper partial specializations for member function pointers. 9 10 * wtf/Functional.h: 11 (WTF::C::): 12 1 13 2011-12-14 Gavin Barraclough <barraclough@apple.com> 2 14 -
trunk/Source/JavaScriptCore/wtf/Functional.h
r102808 r102813 97 97 }; 98 98 99 template<typename R, typename C> class FunctionWrapper<R (C::*)()> { 100 public: 101 typedef R ResultType; 102 103 explicit FunctionWrapper(R (C::*function)()) 104 : m_function(function) 105 { 106 } 107 108 R operator()(C* c) 109 { 110 return (c->*m_function)(); 111 } 112 113 private: 114 R (C::*m_function)(); 115 }; 116 117 template<typename R, typename C, typename P0> class FunctionWrapper<R (C::*)(P0)> { 118 public: 119 typedef R ResultType; 120 121 explicit FunctionWrapper(R (C::*function)(P0)) 122 : m_function(function) 123 { 124 } 125 126 R operator()(C* c, P0 p0) 127 { 128 return (c->*m_function)(p0); 129 } 130 131 private: 132 R (C::*m_function)(P0); 133 }; 134 99 135 class FunctionImplBase : public ThreadSafeRefCounted<FunctionImplBase> { 100 136 public: -
trunk/Tools/ChangeLog
r102808 r102813 1 2011-12-14 Anders Carlsson <andersca@apple.com> 2 3 bind should handle member functions 4 https://bugs.webkit.org/show_bug.cgi?id=74529 5 6 Reviewed by Sam Weinig. 7 8 Add tests. 9 10 * TestWebKitAPI/Tests/WTF/Functional.cpp: 11 (TestWebKitAPI::A::A): 12 (TestWebKitAPI::A::f): 13 (TestWebKitAPI::A::addF): 14 (TestWebKitAPI::TEST): 15 1 16 2011-12-14 Anders Carlsson <andersca@apple.com> 2 17 -
trunk/Tools/TestWebKitAPI/Tests/WTF/Functional.cpp
r102808 r102813 82 82 } 83 83 84 class A { 85 public: 86 explicit A(int i) 87 : m_i(i) 88 { 89 } 90 91 int f() { return m_i; } 92 int addF(int j) { return m_i + j; } 93 94 private: 95 int m_i; 96 }; 97 98 TEST(FunctionalTest, MemberFunctionBind) 99 { 100 A a(10); 101 Function<int ()> function1 = bind(&A::f, &a); 102 ASSERT_EQ(10, function1()); 103 104 Function<int ()> function2 = bind(&A::addF, &a, 15); 105 ASSERT_EQ(25, function2()); 106 } 107 84 108 } // namespace TestWebKitAPI
Note: See TracChangeset
for help on using the changeset viewer.