Skip to content

Commit

Permalink
Code clean & bug fix for defineProtocol()
Browse files Browse the repository at this point in the history
  • Loading branch information
bang590 committed Dec 21, 2015
1 parent d6e4738 commit bd17f7e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions JSPatch/JPEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static void setPropIMP(id slf, SEL selector, id val, NSString *propName) {

static void defineProtocol(NSString *protocolDeclaration, JSValue *instProtocol, JSValue *clsProtocol)
{
const char* protocolName = [protocolDeclaration UTF8String];
const char *protocolName = [protocolDeclaration UTF8String];
Protocol* newprotocol = objc_allocateProtocol(protocolName);
if (newprotocol) {
addGroupMethodsToProtocol(newprotocol, instProtocol, YES);
Expand Down Expand Up @@ -377,6 +377,7 @@ static void addGroupMethodsToProtocol(Protocol* protocol,JSValue *groupMethods,B
JP_DEFINE_TYPE_ENCODE_CASE(void*);

[_protocolTypeEncodeDict setObject:@"@?" forKey:@"block"];
[_protocolTypeEncodeDict setObject:@"^@" forKey:@"id*"];
}

NSString *returnEncode = _protocolTypeEncodeDict[returnString];
Expand All @@ -387,11 +388,11 @@ static void addGroupMethodsToProtocol(Protocol* protocol,JSValue *groupMethods,B
NSString *argStr = trim([argStrArr objectAtIndex:i]);
NSString *argEncode = _protocolTypeEncodeDict[argStr];
if (!argEncode) {
Class cls = NSClassFromString(argStr);
if ([(id)cls isKindOfClass:[NSObject class]]) {
NSString *argClassName = trim([argStr stringByReplacingOccurrencesOfString:@"*" withString:@""]);
if (NSClassFromString(argClassName) != NULL) {
argEncode = @"@";
} else {
NSCAssert(argEncode, @"unreconized type %@", argStr);
NSCAssert(NO, @"unreconized type %@", argStr);
return;
}
}
Expand Down Expand Up @@ -460,9 +461,7 @@ static void addMethodToProtocol(Protocol* protocol, NSString *selectorName, NSSt
for (NSString *jsMethodName in methodDict.allKeys) {
JSValue *jsMethodArr = [jsMethods valueForProperty:jsMethodName];
int numberOfArg = [jsMethodArr[0] toInt32];
NSString *tmpJSMethodName = [jsMethodName stringByReplacingOccurrencesOfString:@"__" withString:@"-"];
NSString *selectorName = [tmpJSMethodName stringByReplacingOccurrencesOfString:@"_" withString:@":"];
selectorName = [selectorName stringByReplacingOccurrencesOfString:@"-" withString:@"_"];
NSString *selectorName = convertJPSelectorString(jsMethodName);

if ([selectorName componentsSeparatedByString:@":"].count - 1 < numberOfArg) {
selectorName = [selectorName stringByAppendingString:@":"];
Expand Down

0 comments on commit bd17f7e

Please sign in to comment.