diff --git a/Demo/iOSDemo/JSPatchTests/JPTestObject.h b/Demo/iOSDemo/JSPatchTests/JPTestObject.h index 825cc885..f6f905d7 100755 --- a/Demo/iOSDemo/JSPatchTests/JPTestObject.h +++ b/Demo/iOSDemo/JSPatchTests/JPTestObject.h @@ -138,3 +138,17 @@ @interface JPTestProtocolObject : NSObject - (BOOL)testProtocolMethods; @end + +@interface JPTestSwizzledForwardInvocationSuperObject : NSObject + +@property (nonatomic, assign) BOOL callSwizzledSuperForwardInvocationPassed; + +- (void)swizzleSuperForwoardInvocation; + +@end + +@interface JPTestSwizzledForwardInvocationSubObject : JPTestSwizzledForwardInvocationSuperObject + +- (void)callTestSwizzledSuperForwardInvocation; + +@end diff --git a/Demo/iOSDemo/JSPatchTests/JPTestObject.m b/Demo/iOSDemo/JSPatchTests/JPTestObject.m index 3f4dfa15..3aa000aa 100755 --- a/Demo/iOSDemo/JSPatchTests/JPTestObject.m +++ b/Demo/iOSDemo/JSPatchTests/JPTestObject.m @@ -7,6 +7,7 @@ // #import "JPTestObject.h" +#import @implementation JPTestObject - (void)funcReturnVoid @@ -576,3 +577,46 @@ - (BOOL)testProtocolMethods } #pragma clang diagnostic pop @end + +@implementation JPTestSwizzledForwardInvocationSuperObject + +- (void)swizzleSuperForwoardInvocation +{ + class_replaceMethod([JPTestSwizzledForwardInvocationSuperObject class], @selector(forwardInvocation:), (IMP)SwizzledSuperForwardInvocation, "v@:@"); +} + +static void SwizzledSuperForwardInvocation(__unsafe_unretained id assignSlf, SEL selector, NSInvocation *invocation) +{ + if ([NSStringFromSelector(invocation.selector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) { + ((JPTestSwizzledForwardInvocationSuperObject *)assignSlf).callSwizzledSuperForwardInvocationPassed = YES; + } +} + +- (void)forwardInvocation:(NSInvocation *)anInvocation +{ + if ([NSStringFromSelector(anInvocation.selector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) { + self.callSwizzledSuperForwardInvocationPassed = NO; + } +} + +@end + +@implementation JPTestSwizzledForwardInvocationSubObject + +- (void)callTestSwizzledSuperForwardInvocation +{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wundeclared-selector" + [self performSelector:@selector(testSwizzledSuperForwardInvocation) withObject:nil]; +#pragma clang diagnostic pop +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector +{ + if ([NSStringFromSelector(aSelector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) { + return [self methodSignatureForSelector:@selector(callTestSwizzledSuperForwardInvocation)]; + } + return [super methodSignatureForSelector:aSelector]; +} + +@end diff --git a/Demo/iOSDemo/JSPatchTests/JSPatchTests.m b/Demo/iOSDemo/JSPatchTests/JSPatchTests.m index 728a91cc..9f266892 100644 --- a/Demo/iOSDemo/JSPatchTests/JSPatchTests.m +++ b/Demo/iOSDemo/JSPatchTests/JSPatchTests.m @@ -152,6 +152,13 @@ - (void)testEngine { XCTAssert(subObj.funcCallSuperPassed, @"funcCallSuperPassed"); XCTAssert(obj.callForwardInvocationPassed, @"callForwardInvocationPassed"); + JPTestSwizzledForwardInvocationSubObject *tmp = [[JPTestSwizzledForwardInvocationSubObject alloc] init]; + [tmp callTestSwizzledSuperForwardInvocation]; + XCTAssert(!tmp.callSwizzledSuperForwardInvocationPassed); + [tmp swizzleSuperForwoardInvocation]; + [tmp callTestSwizzledSuperForwardInvocation]; + XCTAssert(tmp.callSwizzledSuperForwardInvocationPassed); + XCTAssert(obj.propertySetFramePassed, @"propertySetFramePassed"); XCTAssert(obj.propertySetViewPassed, @"propertySetViewPassed"); diff --git a/Demo/iOSDemo/JSPatchTests/test.js b/Demo/iOSDemo/JSPatchTests/test.js index 82a18783..f2d62007 100755 --- a/Demo/iOSDemo/JSPatchTests/test.js +++ b/Demo/iOSDemo/JSPatchTests/test.js @@ -107,6 +107,9 @@ require('JPEngine').defineStruct({ return d } }) + defineClass("JPTestSwizzledForwardInvocationSubObject",{ + stubMethod: function() {} + }) var JPTestObject = require("JPTestObject") var UIView = require("UIView")