mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-20 01:13:29 +00:00
Fixed: Runtime method argument functions will now comply to how Objective-C runtime works.
This commit is contained in:
+21
-8
@@ -1020,6 +1020,7 @@ GLOBAL(method_getName) = function(/*Method*/ aMethod)
|
||||
return aMethod.method_name;
|
||||
}
|
||||
|
||||
// This will not return correct values if the compiler does not have the option 'IncludeTypeSignatures'
|
||||
GLOBAL(method_copyReturnType) = function(/*Method*/ aMethod)
|
||||
{
|
||||
var types = aMethod.method_types;
|
||||
@@ -1034,25 +1035,37 @@ GLOBAL(method_copyReturnType) = function(/*Method*/ aMethod)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// This will not return correct values for index > 1 if the compiler does not have the option 'IncludeTypeSignatures'
|
||||
GLOBAL(method_copyArgumentType) = function(/*Method*/ aMethod, /*unsigned int*/ index)
|
||||
{
|
||||
var types = aMethod.method_types;
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "id";
|
||||
|
||||
if (types)
|
||||
{
|
||||
var argType = types[index + 1];
|
||||
case 1:
|
||||
return "SEL";
|
||||
|
||||
return argType != NULL ? argType : NULL;
|
||||
default:
|
||||
var types = aMethod.method_types;
|
||||
|
||||
if (types)
|
||||
{
|
||||
var argType = types[index - 1];
|
||||
|
||||
return argType != NULL ? argType : NULL;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Returns number of arguments for a method. The first argument is 'self' and the second is the selector.
|
||||
// Those are followed by the method arguments. So for example it will return 2 for a method with no arguments.
|
||||
GLOBAL(method_getNumberOfArguments) = function(/*Method*/ aMethod)
|
||||
{
|
||||
var types = aMethod.method_types;
|
||||
|
||||
return types ? types.length - 1 : ((aMethod.method_name.match(/:/g) || []).length);
|
||||
return types ? types.length + 1 : ((aMethod.method_name.match(/:/g) || []).length + 2);
|
||||
}
|
||||
|
||||
GLOBAL(method_getImplementation) = function(/*Method*/ aMethod)
|
||||
|
||||
@@ -87,17 +87,17 @@
|
||||
[self assert:method_getName(method) equals:@"sqrt:"];
|
||||
}
|
||||
|
||||
- (void)testMethodNoArguments
|
||||
- (void)testMethodNoOfArguments
|
||||
{
|
||||
var method = class_getInstanceMethod(MathClass, @selector(five));
|
||||
|
||||
[self assert:method_getNumberOfArguments(method) equals:0];
|
||||
[self assert:method_getNumberOfArguments(method) equals:2];
|
||||
|
||||
method = class_getInstanceMethod(MathClass, @selector(multiply:));
|
||||
[self assert:method_getNumberOfArguments(method) equals:1];
|
||||
[self assert:method_getNumberOfArguments(method) equals:3];
|
||||
|
||||
method = class_getInstanceMethod(MathClass, @selector(multiply:with:));
|
||||
[self assert:method_getNumberOfArguments(method) equals:2];
|
||||
[self assert:method_getNumberOfArguments(method) equals:4];
|
||||
}
|
||||
|
||||
- (void)testMethodTypes
|
||||
@@ -113,20 +113,26 @@
|
||||
var method = class_getInstanceMethod(theClass, @selector(myMethod:));
|
||||
|
||||
[self assert:method_copyReturnType(method) equals:@"void" message:@"Return type of method 'myMethod:'"];
|
||||
[self assert:method_copyArgumentType(method, 0) equals:@"CPNumber"];
|
||||
[self assertTrue:method_copyArgumentType(method, 1) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:1];
|
||||
[self assert:method_copyArgumentType(method, 0) equals:@"id"];
|
||||
[self assert:method_copyArgumentType(method, 1) equals:@"SEL"];
|
||||
[self assert:method_copyArgumentType(method, 2) equals:@"CPNumber"];
|
||||
[self assertTrue:method_copyArgumentType(method, 3) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:3];
|
||||
|
||||
method = class_getInstanceMethod(theClass, @selector(myMethod2:));
|
||||
[self assert:method_copyReturnType(method) equals:@"int" message:@"Return type of method 'myMethod2:'"];
|
||||
[self assert:method_copyArgumentType(method, 0) equals:@"float"];
|
||||
[self assertTrue:method_copyArgumentType(method, 1) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:1];
|
||||
[self assert:method_copyArgumentType(method, 0) equals:@"id"];
|
||||
[self assert:method_copyArgumentType(method, 1) equals:@"SEL"];
|
||||
[self assert:method_copyArgumentType(method, 2) equals:@"float"];
|
||||
[self assertTrue:method_copyArgumentType(method, 3) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:3];
|
||||
|
||||
method = class_getInstanceMethod(theClass, @selector(myMethod3:));
|
||||
[self assertTrue:method_copyReturnType(method) == nil];
|
||||
[self assertTrue:method_copyArgumentType(method, 0) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:1];
|
||||
[self assert:method_copyArgumentType(method, 0) equals:@"id"];
|
||||
[self assert:method_copyArgumentType(method, 1) equals:@"SEL"];
|
||||
[self assertTrue:method_copyArgumentType(method, 2) === nil];
|
||||
[self assert:method_getNumberOfArguments(method) equals:3];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user