New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[7_4_X] fix(ios): Fix iOS 8/9 compatibility of timers on main thread, register exception handler #10428
Conversation
iphone/Classes/KrollContext.m
Outdated
JSValue *callbackFunction = [callbackArgs objectAtIndex:0]; | ||
[callbackArgs removeObjectAtIndex:0]; | ||
double interval = [[callbackArgs objectAtIndex:0] toDouble] / 1000; | ||
[callbackArgs removeObjectAtIndex:0]; | ||
JSVirtualMachine *vm = callbackFunction.context.virtualMachine; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For SDK < 8, this should likely use the Ti prefixed JSCore calls, otherwise this could break apps not using JSCore so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new timer management is only enabled with JSCore
e3b94cb
to
fcefb32
Compare
iphone/Classes/KrollContext.m
Outdated
return [timerIdentifier unsignedIntegerValue]; | ||
} | ||
|
||
- (void)callJsCallback:(NSTimer *_Nonnull)timer | ||
{ | ||
NSArray<JSValue *> *args = [timer userInfo]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if trying to optimize for the most common case of no additional arguments and setting just the callback as the user info and then checking type here would improve performance or not...
Tests:
Generated by 🚫 dangerJS |
…r exception handler - Re-work timers to try and do less ourselves around cleaning up single-shot timers. Keep weak references to timers, let API invalidate those single-shot timers - Handle unspecified interval/duration, set minimum to 1ms - Make setTimeout/setInterval/clearTimeout block signatures match expected types (even though we cheat and access JSContext currentArguments for varargs)
d5d9aa1
to
f07b13d
Compare
iphone/Classes/KrollContext.m
Outdated
@@ -1610,36 +1622,54 @@ - (void)dealloc | |||
|
|||
- (void)invalidateAllTimers | |||
{ | |||
for (NSNumber *timerIdentifier in self.timers.allKeys) { | |||
for (NSNumber *timerIdentifier in self.timers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it save to iterate directly over the NSMapTable and remove entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah good catch.
… register exception handler (#10428) * fix(ios): Fix iOS 8/9 compatibility of timers on main thread, register exception handler - Re-work timers to try and do less ourselves around cleaning up single-shot timers. Keep weak references to timers, let API invalidate those single-shot timers - Handle unspecified interval/duration, set minimum to 1ms - Make setTimeout/setInterval/clearTimeout block signatures match expected types (even though we cheat and access JSContext currentArguments for varargs)
… register exception handler (tidev#10428) * fix(ios): Fix iOS 8/9 compatibility of timers on main thread, register exception handler - Re-work timers to try and do less ourselves around cleaning up single-shot timers. Keep weak references to timers, let API invalidate those single-shot timers - Handle unspecified interval/duration, set minimum to 1ms - Make setTimeout/setInterval/clearTimeout block signatures match expected types (even though we cheat and access JSContext currentArguments for varargs)
JIRA: https://jira.appcelerator.org/browse/TIMOB-26391
Optional Description:
Backport of #10426