WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
138450
De-templatize Timer
https://bugs.webkit.org/show_bug.cgi?id=138450
Summary
De-templatize Timer
Jer Noble
Reported
2014-11-05 18:34:32 PST
De-templatize Timer
Attachments
Patch
(274.74 KB, patch)
2014-11-06 08:29 PST
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(274.42 KB, patch)
2014-11-06 10:40 PST
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(272.35 KB, patch)
2014-11-06 11:10 PST
,
Jer Noble
andersca
: review+
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Jer Noble
Comment 1
2014-11-06 08:29:32 PST
Created
attachment 241110
[details]
Patch
WebKit Commit Bot
Comment 2
2014-11-06 08:32:05 PST
Attachment 241110
[details]
did not pass style-queue: ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:189: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] ERROR: Source/WebCore/platform/Timer.h:139: Extra space before ( in function call [whitespace/parens] [4] Total errors found: 2 in 280 files If any of these errors are false positives, please file a bug against check-webkit-style.
Anders Carlsson
Comment 3
2014-11-06 09:06:50 PST
Comment on
attachment 241110
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=241110&action=review
> Source/WebCore/platform/Timer.h:125 > - Timer(TimerFiredClass* object, TimerFiredFunction function) > + template <typename TimerFiredClass, typename TimerFiredBaseClass> > + using is_compatible = typename std::enable_if<std::is_base_of<TimerFiredBaseClass, TimerFiredClass>::value>::type*;
I don't think we need to do this.
> Source/WebCore/platform/Timer.h:137 > + template <typename TimerFiredClass, typename TimerFiredBaseClass, is_compatible<TimerFiredBaseClass, TimerFiredClass> = nullptr> > + Timer(TimerFiredClass* object, TimerFiredFunction<TimerFiredBaseClass> function) > : m_function(std::bind(function, object, std::ref(*this))) > { > } > > - Timer(TimerFiredClass* object, DeprecatedTimerFiredFunction function) > + template <typename TimerFiredClass, typename TimerFiredBaseClass, is_compatible<TimerFiredBaseClass, TimerFiredClass> = nullptr> > + Timer(TimerFiredClass* object, DeprecatedTimerFiredFunction<TimerFiredBaseClass> function) > : m_function(std::bind(function, object, this)) > { > }
How about something like this instead? template<typename TimerFiredClass, typename TimerFiredMemberFunctionClass> Timer(TimerFiredClass* object, void (TimerFiredMemberFunctionClass::*function)(Timer<TimerFiredClass>&)) : m_function(std::bind(function, object, std::ref(*this))) { } template<typename TimerFiredClass, typename TimerFiredMemberFunctionClass> Timer(TimerFiredClass* object, void (TimerFiredMemberFunctionClass::*function)(Timer<TimerFiredClass>*)) : m_function(std::bind(function, object, this)) { } I also think we should deprecate both the constructors above and add template<typename TimerFiredClass, typename TimerFiredMemberFunctionClass> Timer(TimerFiredClass& object, void (TimerFiredMemberFunctionClass::*function)()) : m_function(std::bind(function, &object)) { which has two advantages: 1. It doesn't require the member function to take a Timer - we almost never do anything with the timer anyway. Those clients who want a timer can use std::bind with the constructor below. 2. It takes the object by reference since we can guarantee that its' not null.
> Source/WebCore/platform/Timer.h:140 > + : m_function(function)
This should use WTF::move.
Jer Noble
Comment 4
2014-11-06 09:10:22 PST
Looks like the Windows build failure is due to this MSVC bug: <
https://connect.microsoft.com/VisualStudio/feedback/details/800231/c-11-alias-template-issue
>
Jer Noble
Comment 5
2014-11-06 09:17:50 PST
(In reply to
comment #3
)
> Comment on
attachment 241110
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=241110&action=review
> > > Source/WebCore/platform/Timer.h:125 > > - Timer(TimerFiredClass* object, TimerFiredFunction function) > > + template <typename TimerFiredClass, typename TimerFiredBaseClass> > > + using is_compatible = typename std::enable_if<std::is_base_of<TimerFiredBaseClass, TimerFiredClass>::value>::type*; > > I don't think we need to do this.
Okay. I added it because, without it, passing in an incompatible ends up with a really obscure error message from std::bind(). But we're all used to obscure error messages by now. :)
> > Source/WebCore/platform/Timer.h:137 > > + template <typename TimerFiredClass, typename TimerFiredBaseClass, is_compatible<TimerFiredBaseClass, TimerFiredClass> = nullptr> > > + Timer(TimerFiredClass* object, TimerFiredFunction<TimerFiredBaseClass> function) > > : m_function(std::bind(function, object, std::ref(*this))) > > { > > } > > > > - Timer(TimerFiredClass* object, DeprecatedTimerFiredFunction function) > > + template <typename TimerFiredClass, typename TimerFiredBaseClass, is_compatible<TimerFiredBaseClass, TimerFiredClass> = nullptr> > > + Timer(TimerFiredClass* object, DeprecatedTimerFiredFunction<TimerFiredBaseClass> function) > > : m_function(std::bind(function, object, this)) > > { > > } > > How about something like this instead? > > template<typename TimerFiredClass, typename > TimerFiredMemberFunctionClass> > Timer(TimerFiredClass* object, void > (TimerFiredMemberFunctionClass::*function)(Timer<TimerFiredClass>&)) > : m_function(std::bind(function, object, std::ref(*this))) > { > }
You'd need "Timer&" instead of "Timer<TimerFiredClass>&", but that'd work. That should fix the Windows build too (which seems to be triggered by "using = member function ptr".
> template<typename TimerFiredClass, typename > TimerFiredMemberFunctionClass> > Timer(TimerFiredClass* object, void > (TimerFiredMemberFunctionClass::*function)(Timer<TimerFiredClass>*)) > : m_function(std::bind(function, object, this)) > { > } > > I also think we should deprecate both the constructors above and add > > template<typename TimerFiredClass, typename > TimerFiredMemberFunctionClass> > Timer(TimerFiredClass& object, void > (TimerFiredMemberFunctionClass::*function)()) > : m_function(std::bind(function, &object)) > { > > which has two advantages: > 1. It doesn't require the member function to take a Timer - we almost > never do anything with the timer anyway. Those clients who want a timer can > use std::bind with the constructor below.
Yep!
> 2. It takes the object by reference since we can guarantee that its' not > null.
Yep!
> > Source/WebCore/platform/Timer.h:140 > > + : m_function(function) > > This should use WTF::move.
Ok.
Jer Noble
Comment 6
2014-11-06 10:40:25 PST
Created
attachment 241116
[details]
Patch
WebKit Commit Bot
Comment 7
2014-11-06 10:43:16 PST
Attachment 241116
[details]
did not pass style-queue: ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:189: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] ERROR: Source/WebCore/platform/Timer.h:136: Extra space before ( in function call [whitespace/parens] [4] Total errors found: 2 in 280 files If any of these errors are false positives, please file a bug against check-webkit-style.
Jer Noble
Comment 8
2014-11-06 11:10:48 PST
Created
attachment 241119
[details]
Patch
WebKit Commit Bot
Comment 9
2014-11-06 11:12:46 PST
Attachment 241119
[details]
did not pass style-queue: ERROR: Source/WebCore/Modules/geolocation/Geolocation.h:189: enum members should use InterCaps with an initial capital letter. [readability/enum_casing] [4] ERROR: Source/WebCore/platform/Timer.h:136: Extra space before ( in function call [whitespace/parens] [4] Total errors found: 2 in 277 files If any of these errors are false positives, please file a bug against check-webkit-style.
Jer Noble
Comment 10
2014-11-06 15:06:01 PST
Committed
r175719
: <
http://trac.webkit.org/changeset/175719
>
Jer Noble
Comment 11
2014-12-16 13:29:01 PST
<
rdar://problem/19269065
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug