Permalink
Browse files

Fix the bug when the return type is Class.

Modify the JPCFuction on the Class parameter parsing.
Add test case.
  • Loading branch information...
1 parent 1f1ae74 commit 0fdad5aa3d9694141fd76ed8c8cff0399f9b069e @YauzZ YauzZ committed Nov 30, 2016
@@ -74,6 +74,7 @@
@property (nonatomic, assign) BOOL funcToSwizzleTestClassPassed;
@property (nonatomic, assign) BOOL funcToSwizzleTestSelectorPassed;
@property (nonatomic, assign) BOOL funcToSwizzleTestCharPassed;
+@property (nonatomic, assign) BOOL funcToSwizzleReturnClassPassed;
@property (nonatomic, assign) BOOL funcTestCharPassed;
@property (nonatomic, assign) BOOL funcToSwizzleTestPointerPassed;
@property (nonatomic, assign) BOOL funcTestPointerPassed;
@@ -30,6 +30,11 @@ - (Class)funcReturnClass
return [self class];
}
+- (Class)funcToSwizzleReturnClass
+{
+ return nil;
+}
+
- (double)funcReturnDouble {
return 100.0;
@@ -275,6 +280,9 @@ - (void)callSwizzleMethod
char *cStr = [self funcToSwizzleTestChar:"JSPatch"];
self.funcToSwizzleTestCharPassed = strcmp("JSPatch", cStr) == 0;
+ Class myClass = [self funcToSwizzleReturnClass];
+ self.funcToSwizzleReturnClassPassed = [NSStringFromClass(myClass) isEqualToString:@"UIView"];
+
JPTestStruct *testStruct = (JPTestStruct*)malloc(sizeof(JPTestStruct));
testStruct->idx = 42;
testStruct->name = "JSPatch";
@@ -120,6 +120,7 @@ - (void)testEngine {
XCTAssert(obj.funcToSwizzleTestClassPassed, @"funcToSwizzleTestClassPassed");
XCTAssert(obj.funcToSwizzleTestSelectorPassed, @"funcToSwizzleTestSelectorPassed");
XCTAssert(obj.funcToSwizzleTestCharPassed, @"funcToSwizzleTestCharPassed");
+ XCTAssert(obj.funcToSwizzleTestClassPassed,@"funcToSwizzleTestClassPassed");
XCTAssert(obj.funcTestCharPassed, @"funcTestCharPassed");
XCTAssert(obj.funcToSwizzleTestPointerPassed, @"funcToSwizzleTestPointerPassed");
XCTAssert(obj.funcTestPointerPassed, @"funcTestPointerPassed");
@@ -90,6 +90,9 @@ require('JPEngine').defineStruct({
funcToSwizzleTestPointer: function(pointer) {
return pointer
},
+ funcToSwizzleReturnClass:function(){
+ return UIView.class()
+ }
},
{
classFuncToSwizzle_int: function(o, num) {
@@ -248,7 +248,7 @@ + (id)callCFunction:(NSString *)funcName arguments:(NSArray *)arguments
break;
}
case '#': {
- id ptr = [((JPBoxing *)arguments[i]) unboxClass];
+ id ptr = arguments[i];
void **argPtr = ffiArgPtr;
*argPtr = (__bridge void *)(ptr);
break;
@@ -309,9 +309,7 @@ + (id)callCFunction:(NSString *)funcName arguments:(NSArray *)arguments
break;
}
case '#': {
- JPBoxing *box = [[JPBoxing alloc] init];
- box.cls = (__bridge id)(*(void**)returnPtr);
- ret = box;
+ ret = (__bridge id)(*(void**)returnPtr);
break;
}
}
View
@@ -834,9 +834,10 @@ static void JPForwardInvocation(__unsafe_unretained id assignSlf, SEL selector,
#define JP_FWD_RET_CODE_CLASS \
Class ret; \
id obj = formatJSToOC(jsval); \
- if ([obj isKindOfClass:[JPBoxing class]]) { \
- ret = [((JPBoxing *)obj) unboxClass]; \
- }
+ if (object_isClass(obj)) { \
+ ret = obj; \
+ }\
+
#define JP_FWD_RET_CODE_SEL \
SEL ret; \
@@ -1187,8 +1188,8 @@ static id callSelector(NSString *className, NSString *selectorName, JSValue *arg
}
}
case '#': {
- if ([valObj isKindOfClass:[JPBoxing class]]) {
- Class value = [((JPBoxing *)valObj) unboxClass];
+ if (object_isClass(valObj)) {
+ Class value = (Class)valObj;
[invocation setArgument:&value atIndex:i];
break;
}
@@ -1647,6 +1648,9 @@ static id formatOCToJS(id obj)
if ([obj isKindOfClass:NSClassFromString(@"NSBlock")] || [obj isKindOfClass:[JSValue class]]) {
return obj;
}
+ if (object_isClass(obj)) {
+ return @{ @"__clsName": NSStringFromClass(obj)};
+ }
return _wrapObj(obj);
}

0 comments on commit 0fdad5a

Please sign in to comment.