4040 return propertyName;
4141}
4242
43+ #pragma mark -
44+
4345static NSArray *extractArguments (NSInvocation *invocation)
4446{
4547 NSMethodSignature *methodSignature = invocation.methodSignature ;
112114 void *argument;
113115 [invocation getArgument: &argument atIndex: i];
114116 [arguments addObject: (__bridge id )argument];
115- } else if (strcmp (type, @encode (SEL )) == 0 ) {
116- const char *argument = nil ;
117- [invocation getArgument: &argument atIndex: i];
118- [arguments addObject: @(argument)];
119117 } else if (strcmp (type, @encode (id )) == 0 ) {
120118 id __unsafe_unretained argument = nil ;
121119 [invocation getArgument: &argument atIndex: i];
122120 [arguments addObject: argument];
121+ } else if (strcmp (type, @encode (SEL )) == 0 ) {
122+ const char *argument = nil ;
123+ [invocation getArgument: &argument atIndex: i];
124+ [arguments addObject: @(argument)];
123125 } else if (strcmp (type, @encode (Class )) == 0 ) {
124126 Class __unsafe_unretained argument = nil ;
125127 [invocation getArgument: &argument atIndex: i];
126128 [arguments addObject: argument];
127- } else if (strcmp (type, @encode (NSInteger )) == 0 ) {
128- NSInteger argument;
129- [invocation getArgument: &argument atIndex: i];
130- [arguments addObject: @(argument)];
131- } else if (strcmp (type, @encode (NSUInteger )) == 0 ) {
132- NSUInteger argument;
133- [invocation getArgument: &argument atIndex: i];
134- [arguments addObject: @(argument)];
135- } else if (strcmp (type, @encode (CGFloat)) == 0 ) {
136- CGFloat argument;
137- [invocation getArgument: &argument atIndex: i];
138- [arguments addObject: @(argument)];
139129 }
140130 }
141131
@@ -154,23 +144,22 @@ static void setReturnValue(JSValue *value, NSInvocation *invocation)
154144 if (strcmp (type, @encode (char )) == 0 ||
155145 strcmp (type, @encode (short )) == 0 ||
156146 strcmp (type, @encode (int )) == 0 ||
157- strcmp (type, @encode (long )) == 0 ||
158- strcmp (type, @encode (long long )) == 0 ||
159147 strcmp (type, @encode (unsigned char )) == 0 ||
160148 strcmp (type, @encode (unsigned short )) == 0 ||
161- strcmp (type, @encode (unsigned int )) == 0 ||
162- strcmp (type, @encode (unsigned long )) == 0 ||
163- strcmp (type, @encode (unsigned long long )) == 0 ||
164- strcmp (type, @encode (NSInteger )) == 0 ||
165- strcmp (type, @encode (NSUInteger )) == 0 ) {
149+ strcmp (type, @encode (unsigned int )) == 0 ) {
166150 int32_t returnValue = value.toInt32 ;
167151 [invocation setReturnValue: &returnValue];
152+ } else if (strcmp (type, @encode (long )) == 0 ||
153+ strcmp (type, @encode (unsigned long )) == 0 ||
154+ strcmp (type, @encode (long long )) == 0 ||
155+ strcmp (type, @encode (unsigned long long )) == 0 ) {
156+ int64_t returnValue = value.toInt32 ;
157+ [invocation setReturnValue: &returnValue];
168158 } else if (strcmp (type, @encode (bool )) == 0 ||
169159 strcmp (type, @encode (BOOL )) == 0 ) {
170160 BOOL returnValue = value.toBool ;
171161 [invocation setReturnValue: &returnValue];
172- } else if (strcmp (type, @encode (float )) == 0 ||
173- strcmp (type, @encode (CGFloat)) == 0 ) {
162+ } else if (strcmp (type, @encode (float )) == 0 ) {
174163 float returnValue = value.toDouble ;
175164 [invocation setReturnValue: &returnValue];
176165 } else if (strcmp (type, @encode (double )) == 0 ) {
@@ -182,6 +171,21 @@ static void setReturnValue(JSValue *value, NSInvocation *invocation)
182171 }
183172}
184173
174+ #pragma mark -
175+
176+ static CGFloat tableViewHeightForRowAtIndexPath (id self, SEL _cmd, UITableView *tableView, NSIndexPath *indexPath)
177+ {
178+ NSString *propertyName = propertyNameFromSelector (_cmd);
179+ JSValue *value = globalContext[mangledNameFromClass ([self class ])][@" instanceMembers" ][propertyName];
180+
181+ if (!value.isUndefined ) {
182+ JSValue *returnValue = [value callWithArguments: @[tableView, indexPath]];
183+ return returnValue.toDouble ;
184+ }
185+
186+ return 0 .0f ;
187+ }
188+
185189static void setupForwardingImplementations (Class targetClass, Class cls, JSValue *functions)
186190{
187191 unsigned int count = 0 ;
@@ -193,7 +197,11 @@ static void setupForwardingImplementations(Class targetClass, Class cls, JSValue
193197 NSString *propertyName = propertyNameFromSelector (description->name );
194198 JSValue *function = functions[propertyName];
195199 if (!function.isUndefined ) {
196- class_addMethod (targetClass, description->name , _objc_msgForward, description->types );
200+ if (description->name == @selector (tableView:heightForRowAtIndexPath: )) {
201+ class_addMethod (targetClass, description->name , (IMP )tableViewHeightForRowAtIndexPath, description->types );
202+ } else {
203+ class_addMethod (targetClass, description->name , _objc_msgForward, description->types );
204+ }
197205 }
198206 }
199207 if (methods) {
@@ -206,6 +214,8 @@ static void setupForwardingImplementations(Class targetClass, Class cls, JSValue
206214 }
207215}
208216
217+ #pragma mark -
218+
209219static void forwardInvocation (id self, SEL _cmd, NSInvocation *invocation)
210220{
211221 JSContext *context = globalContext;
@@ -221,7 +231,7 @@ static void forwardInvocation(id self, SEL _cmd, NSInvocation *invocation)
221231 setReturnValue (returnValue, invocation);
222232 }
223233
224- context[@" self" ] = [ NSNull null ] ;
234+ context[@" self" ] = nil ;
225235}
226236
227237static NSMethodSignature *methodSignatureForSelector (id self, SEL _cmd, SEL selector)
0 commit comments