Skip to content

Commit 2c62ced

Browse files
Fix on 64bit device.
1 parent 16f1cbc commit 2c62ced

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

Classes/JSBScriptingSupport.m

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
return propertyName;
4141
}
4242

43+
#pragma mark -
44+
4345
static NSArray *extractArguments(NSInvocation *invocation)
4446
{
4547
NSMethodSignature *methodSignature = invocation.methodSignature;
@@ -112,30 +114,18 @@
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+
185189
static 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+
209219
static 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

227237
static NSMethodSignature *methodSignatureForSelector(id self, SEL _cmd, SEL selector)

Examples/UICatalog/UICatalog/Images.xcassets/LaunchImage.launchimage/Contents.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
"idiom" : "iphone",
66
"extent" : "full-screen",
77
"minimum-system-version" : "7.0",
8+
"filename" : "[email protected]",
89
"scale" : "2x"
910
},
1011
{
11-
"orientation" : "portrait",
12+
"extent" : "full-screen",
1213
"idiom" : "iphone",
1314
"subtype" : "retina4",
14-
"extent" : "full-screen",
15+
"filename" : "[email protected]",
1516
"minimum-system-version" : "7.0",
17+
"orientation" : "portrait",
1618
"scale" : "2x"
1719
}
1820
],
29.8 KB
Loading
19.5 KB
Loading

Examples/UICatalog/UICatalog/controlsViewController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var ControlsViewController = JSB.define('ControlsViewController : UITableViewCon
1212
};
1313

1414
self.sliderCtl = function() {
15-
var frame = {x: 0, y: 12, width: 120, height: 7};
15+
var frame = {x: 0, y: 12, width: 120, height: 31};
1616
var sliderCtl = UISlider.alloc().initWithFrame(frame);
1717
sliderCtl.addTargetActionForControlEvents(self, 'sliderAction:', 1 << 12);
1818
sliderCtl.backgroundColor = UIColor.clearColor();

0 commit comments

Comments
 (0)