Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 97 lines (74 sloc) 2.623 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//

#import "KWInvocationCapturer.h"
#import "KWWorkarounds.h"
#import "NSInvocation+KiwiAdditions.h"

@implementation KWInvocationCapturer

#pragma mark -
#pragma mark Initializing

- (id)initWithDelegate:(id)aDelegate {
    return [self initWithDelegate:aDelegate userInfo:nil];
}

- (id)initWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo {
    delegate = aDelegate;
    userInfo = [aUserInfo retain];
    return self;
}

+ (id)invocationCapturerWithDelegate:(id)aDelegate {
    return [self invocationCapturerWithDelegate:aDelegate userInfo:nil];
}

+ (id)invocationCapturerWithDelegate:(id)aDelegate userInfo:(NSDictionary *)aUserInfo {
    return [[[self alloc] initWithDelegate:aDelegate userInfo:aUserInfo] autorelease];
}

- (void)dealloc {
    [userInfo release];
    [super dealloc];
}

#pragma mark -
#pragma mark Properties

@synthesize delegate;
@synthesize userInfo;

#pragma mark -
#pragma mark Capturing Invocations

- (void)KW_captureInvocation:(NSInvocation *)anInvocation {
    [self.delegate invocationCapturer:self didCaptureInvocation:anInvocation];
}

#pragma mark -
#pragma mark Handling Invocations

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
    return [self.delegate invocationCapturer:self methodSignatureForSelector:aSelector];
}

- (void)forwardInvocation:(NSInvocation *)anInvocation {
#if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
    @try {
#endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG

    [self KW_captureInvocation:anInvocation];

#if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
    } @catch (NSException *exception) {
        KWSetExceptionFromAcrossInvocationBoundary(exception);
    }
#endif // #if KW_TARGET_HAS_INVOCATION_EXCEPTION_BUG
}

#pragma mark -
#pragma mark Whitelisted NSObject Methods

// The return values from these methods should never be needed, so just call
// the super implementation after capturing the invocation.

- (BOOL)isEqual:(id)anObject {
    NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd messageArguments:&anObject];
    [self KW_captureInvocation:invocation];
    return [super isEqual:anObject];
}

- (NSUInteger)hash {
    NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd];
    [self KW_captureInvocation:invocation];
    return [super hash];
}

- (NSString *)description {
    NSInvocation *invocation = [NSInvocation invocationWithTarget:self selector:_cmd];
    [self KW_captureInvocation:invocation];
    return [super description];
}

@end
Something went wrong with that request. Please try again.