72{
74
75 NSString *selectorString =
nil;
76 SEL selector = NULL;
77 NSString *paramString =
nil;
79 BOOL haveParameter = NO,
80 error = NO;
82
83 if (argc == 0)
84 {
85 OOJSReportError(context,
@"%@.callObjC(): no selector specified.", oo_jsClassName);
86 return NO;
87 }
88
90 {
91 [
PLAYER setScriptTarget:object];
92 }
93
95
96
97 if (1 < argc && [selectorString hasSuffix:@":"])
98 {
99 haveParameter = YES;
100 paramString = [NSString concatenationOfStringsFromJavaScriptValues:argv + 1
count:argc - 1 separator:
@" " inContext:context];
101 }
102
103 selector = NSSelectorFromString(selectorString);
104
105 if ([object respondsToSelector:selector])
106 {
107
109
111 {
112 OOJSReportError(context,
@"%@.callObjC(): method %@ requires a parameter.", oo_jsClassName, selectorString);
113 error = YES;
114 }
115 else
116 {
117 IMP method = [object methodForSelector:selector];
118 switch (type)
119 {
121 [object performSelector:selector withObject:paramString];
122 break;
123
125 result = [object performSelector:selector withObject:paramString];
126 break;
127
129 result = [object performSelector:selector];
130 if ([selectorString hasSuffix:
@"_bool"]) result = [NSNumber numberWithBool:
OOBooleanFromObject(result, NO)];
131 break;
132
134 [object performSelector:selector];
135 break;
136
145 break;
146
149 break;
150
154 break;
155
157 {
160 break;
161 }
162
164 {
167 break;
168 }
169
173 OOJSReportError(context,
@"%@.callObjC(): method %@ cannot be called from JavaScript.", oo_jsClassName, selectorString);
174 error = YES;
175 break;
176 }
178 {
179 *outResult = [result oo_jsValueInContext:context];
180 }
181 }
182 }
183 else
184 {
185 OOJSReportError(context,
@"%@.callObjC(): %@ does not respond to method %@.", oo_jsClassName, [
object shortDescription], selectorString);
186 error = YES;
187 }
188
189 return !error;
190
192}
@ kMethodTypeUnsignedShortVoid
@ kMethodTypeUnsignedIntVoid
@ kMethodTypeUnsignedLongVoid
@ kMethodTypeUnsignedCharVoid
@ kMethodTypeQuaternionVoid
@ kMethodTypeObjectObject
OOINLINE BOOL MethodExpectsParameter(MethodType type)
static MethodType GetMethodType(id object, SEL selector)
#define OOJS_PROFILE_EXIT
#define OOJS_PROFILE_ENTER
JSObject * JSQuaternionWithQuaternion(JSContext *context, Quaternion quaternion) NONNULL_FUNC
JSObject * JSVectorWithVector(JSContext *context, Vector vector) NONNULL_FUNC
NSString * OOStringFromJSValue(JSContext *context, jsval value)
void OOJSReportError(JSContext *context, NSString *format,...)