Permalink
Browse files

Bugfix: crash when forward an invocation with nil params #19

  • Loading branch information...
bang590 committed Jun 4, 2015
1 parent 770d4ef commit 5f2f081d9b75a3719e53d9c40eae48e2252a0934
View
@@ -231,8 +231,13 @@ static _type JPMETHOD_IMPLEMENTATION_NAME(_typeString) (id slf, SEL selector) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#define JPMETHOD_RET_ID \
id obj = [ret toObject]; \
if ([obj isKindOfClass:[NSNull class]]) return nil; \
return obj;
JPMETHOD_IMPLEMENTATION_RET(void, v, nil)
JPMETHOD_IMPLEMENTATION_RET(id, id, return [ret toObject])
JPMETHOD_IMPLEMENTATION_RET(id, id, JPMETHOD_RET_ID)
JPMETHOD_IMPLEMENTATION_RET(CGRect, rect, return dictToRect([ret toObject]))
JPMETHOD_IMPLEMENTATION_RET(CGSize, size, return dictToSize([ret toObject]))
JPMETHOD_IMPLEMENTATION_RET(CGPoint, point, return dictToPoint([ret toObject]))
@@ -330,13 +335,13 @@ static void JPForwardInvocation(id slf, SEL selector, NSInvocation *invocation)
JP_FWD_ARG_CASE('d', double)
JP_FWD_ARG_CASE('B', BOOL)
case '@': {
void *arg;
__unsafe_unretained id arg;
[invocation getArgument:&arg atIndex:i];
static const char *blockType = @encode(typeof(^{}));
if (!strcmp(argumentType, blockType)) {
[argList addObject:[(__bridge id)arg copy]];
[argList addObject:(arg ? [arg copy]: [NSNull null])];
} else {
[argList addObject:(__bridge id)arg];
[argList addObject:(arg ? arg: [NSNull null])];
}
break;
}
@@ -790,7 +795,9 @@ static BOOL typeIsObject(NSString *typeString) {
static NSDictionary *toJSObj(id obj)
{
if (!obj) return nil;
if (!obj || [obj isKindOfClass:[NSNull class]]) {
return @{@"__isNull": @(YES)};
}
return @{@"__isObj": @(YES), @"cls": NSStringFromClass([obj class]), @"obj": obj};
}
@end
View
@@ -38,8 +38,9 @@ var global = this
var _formatOCToJS = function(obj) {
if (obj === undefined || obj === null) return null
if (typeof obj == "object" && obj.__isObj) {
return _toJSObj(obj)
if (typeof obj == "object") {
if (obj.__isObj) return _toJSObj(obj)
if (obj.__isNull) return null
}
if (obj instanceof Array) {
var ret = []
@@ -40,6 +40,7 @@
@property (nonatomic, assign) BOOL funcToSwizzleViewPassed;
@property (nonatomic, assign) BOOL funcToSwizzleViewCalledOriginalPassed;
@property (nonatomic, assign) BOOL funcToSwizzleReturnViewPassed;
@property (nonatomic, assign) BOOL funcToSwizzleParamNilPassed;
@property (nonatomic, assign) BOOL funcToSwizzleReturnIntPassed;
@property (nonatomic, assign) BOOL funcToSwizzleWithBlockPassed;
@property (nonatomic, assign) BOOL funcToSwizzle_withUnderLine_Passed;
@@ -139,6 +139,9 @@ - (void)callSwizzleMethod
UIView *view = [self funcToSwizzleReturnView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]];
self.funcToSwizzleReturnViewPassed = view.frame.size.width == 100;
UIView *nilView = [self funcToSwizzleReturnView:nil];
self.funcToSwizzleParamNilPassed = !nilView;
int num = [self funcToSwizzleReturnInt:42];
self.funcToSwizzleReturnIntPassed = num == 42;
@@ -69,6 +69,7 @@ - (void)testEngine {
XCTAssert(obj.funcToSwizzleViewPassed, @"funcToSwizzleViewPassed");
XCTAssert(obj.funcToSwizzleViewCalledOriginalPassed, @"funcToSwizzleViewCalledOriginalPassed");
XCTAssert(obj.funcToSwizzleReturnViewPassed, @"funcToSwizzleReturnViewPassed");
XCTAssert(obj.funcToSwizzleParamNilPassed, @"funcToSwizzleParamNilPassed");
XCTAssert(obj.funcToSwizzleReturnIntPassed, @"funcToSwizzleReturnIntPassed");
XCTAssert(obj.funcToSwizzleWithBlockPassed, @"funcToSwizzleWithBlockPassed");
XCTAssert(obj.funcToSwizzle_withUnderLine_Passed, @"funcToSwizzle_withUnderLine_Passed");

0 comments on commit 5f2f081

Please sign in to comment.