summaryrefslogtreecommitdiffstats
path: root/WebKit/mac/Misc/WebNSObjectExtras.mm
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2009-08-11 17:01:47 +0100
committerBen Murdoch <benm@google.com>2009-08-11 18:21:02 +0100
commit0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch)
tree2943df35f62d885c89d01063cc528dd73b480fea /WebKit/mac/Misc/WebNSObjectExtras.mm
parent7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff)
downloadexternal_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2
Merge in WebKit r47029.
Diffstat (limited to 'WebKit/mac/Misc/WebNSObjectExtras.mm')
-rw-r--r--WebKit/mac/Misc/WebNSObjectExtras.mm40
1 files changed, 30 insertions, 10 deletions
diff --git a/WebKit/mac/Misc/WebNSObjectExtras.mm b/WebKit/mac/Misc/WebNSObjectExtras.mm
index 2d682b9..3beb641 100644
--- a/WebKit/mac/Misc/WebNSObjectExtras.mm
+++ b/WebKit/mac/Misc/WebNSObjectExtras.mm
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
#import "WebNSObjectExtras.h"
+#import <wtf/Assertions.h>
@interface WebMainThreadInvoker : NSProxy
{
@@ -36,23 +37,35 @@
}
@end
+static bool returnTypeIsObject(NSInvocation *invocation)
+{
+ // Could use either _C_ID or NSObjCObjectType, but it seems that neither is
+ // both available and non-deprecated on all versions of Mac OS X we support.
+ return strchr([[invocation methodSignature] methodReturnType], '@');
+}
+
@implementation WebMainThreadInvoker
-- (id)initWithTarget:(id)theTarget
+- (id)initWithTarget:(id)passedTarget
{
- target = theTarget;
+ target = passedTarget;
return self;
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
[invocation setTarget:target];
- [invocation retainArguments];
[invocation performSelectorOnMainThread:@selector(_webkit_invokeAndHandleException:) withObject:self waitUntilDone:YES];
if (exception) {
id exceptionToThrow = [exception autorelease];
exception = nil;
@throw exceptionToThrow;
+ } else if (returnTypeIsObject(invocation)) {
+ // _webkit_invokeAndHandleException retained the return value on the main thread.
+ // Now autorelease it on the calling thread.
+ id returnValue;
+ [invocation getReturnValue:&returnValue];
+ [returnValue autorelease];
}
}
@@ -61,28 +74,35 @@
return [target methodSignatureForSelector:selector];
}
-- (void)handleException:(id)e
+- (void)handleException:(id)passedException
{
- exception = [e retain];
+ ASSERT(!exception);
+ exception = [passedException retain];
}
@end
-
@implementation NSInvocation (WebMainThreadInvoker)
- (void)_webkit_invokeAndHandleException:(WebMainThreadInvoker *)exceptionHandler
{
@try {
[self invoke];
- } @catch (id e) {
- [exceptionHandler handleException:e];
+ } @catch (id exception) {
+ [exceptionHandler handleException:exception];
+ return;
+ }
+ if (returnTypeIsObject(self)) {
+ // Retain the return value on the main thread.
+ // -[WebMainThreadInvoker forwardInvocation:] will autorelease it on the calling thread.
+ id value;
+ [self getReturnValue:&value];
+ [value retain];
}
}
@end
-
@implementation NSObject (WebNSObjectExtras)
- (id)_webkit_invokeOnMainThread