You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2012/10/10 20:15:52 UTC
[3/3] ios commit: Fix alert dead-lock in contacts mobile-spec test.
Fix alert dead-lock in contacts mobile-spec test.
Switches from dispatch_async to performSelectorOnMainThread: and for
some reason this behaves better...
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/7b4014cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/7b4014cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/7b4014cb
Branch: refs/heads/master
Commit: 7b4014cbfb38e47320259ef3af3c22926c797623
Parents: 4d322c0
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Oct 10 14:10:06 2012 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Oct 10 14:10:06 2012 -0400
----------------------------------------------------------------------
CordovaLib/Classes/CDVCommandDelegateImpl.m | 25 +++++++++++++--------
1 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/7b4014cb/CordovaLib/Classes/CDVCommandDelegateImpl.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.m b/CordovaLib/Classes/CDVCommandDelegateImpl.m
index f35705a..806a821 100644
--- a/CordovaLib/Classes/CDVCommandDelegateImpl.m
+++ b/CordovaLib/Classes/CDVCommandDelegateImpl.m
@@ -53,22 +53,26 @@
return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr];
}
-- (void)evalJsHelper:(NSString*)js
+- (void)evalJsHelper2:(NSString*)js
{
- void (^doIt)() = ^{
- NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js];
- [_commandQueue enqueCommandBatch:commandsJSON];
- };
+ NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js];
+
+ [_commandQueue enqueCommandBatch:commandsJSON];
+}
+- (void)evalJsHelper:(NSString*)js
+{
// Cycle the run-loop before executing the JS.
// This works around a bug where sometimes alerts() within callbacks can cause
// dead-lock.
// If the commandQueue is currently executing, then we know that it is safe to
// execute the callback immediately.
+ // Using dispatch_async(dispatch_get_main_queue()) does *not* fix deadlocks for some reaon,
+ // but performSelectorOnMainThread: does.
if (![NSThread isMainThread] || !_commandQueue.currentlyExecuting) {
- dispatch_async (dispatch_get_main_queue (), doIt);
+ [self performSelectorOnMainThread:@selector(evalJsHelper2:) withObject:js waitUntilDone:NO];
} else {
- doIt ();
+ [self evalJsHelper2:js];
}
}
@@ -82,7 +86,7 @@
message = [NSArray arrayWithObject:message];
NSString* encodedMessage = [message cdvjk_JSONString];
// And then strip off the outer []s.
- encodedMessage = [encodedMessage substringWithRange:NSMakeRange (1, [encodedMessage length] - 2)];
+ encodedMessage = [encodedMessage substringWithRange:NSMakeRange(1, [encodedMessage length] - 2)];
NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)",
callbackId, status, encodedMessage, keepCallback];
@@ -110,8 +114,9 @@
[_viewController registerPlugin:plugin withClassName:className];
}
-- (void)runInBackground:(void (^) ())block {
- dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
+- (void)runInBackground:(void (^)())block
+{
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
}
@end