Changeset 30868 in webkit
- Timestamp:
- Mar 6, 2008 5:55:18 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r30867 r30868 1 2008-03-06 Anders Carlsson <andersca@apple.com> 2 3 Reviewed by Jon. 4 5 Templatize the JNI call code to reduce the amount of code that has 6 to be duplicated. 7 8 * bridge/jni/jni_class.cpp: 9 (JavaClass::JavaClass): 10 * bridge/jni/jni_instance.cpp: 11 (JavaInstance::stringValue): 12 (JavaInstance::numberValue): 13 (JavaInstance::booleanValue): 14 (JavaInstance::invokeMethod): 15 * bridge/jni/jni_jsobject.cpp: 16 (JavaJSObject::convertJObjectToValue): 17 * bridge/jni/jni_runtime.cpp: 18 (JavaField::JavaField): 19 (JavaMethod::JavaMethod): 20 * bridge/jni/jni_utility.cpp: 21 * bridge/jni/jni_utility.h: 22 (KJS::Bindings::): 23 (KJS::Bindings::callJNIMethodIDA): 24 (KJS::Bindings::callJNIMethodV): 25 (KJS::Bindings::callJNIMethod): 26 (KJS::Bindings::callJNIStaticMethod): 27 1 28 2008-03-06 Darin Adler <darin@apple.com> 2 29 -
trunk/WebCore/bridge/jni/jni_class.cpp
r30782 r30868 34 34 JavaClass::JavaClass(jobject anInstance) 35 35 { 36 jobject aClass = callJNI ObjectMethod(anInstance, "getClass", "()Ljava/lang/Class;");36 jobject aClass = callJNIMethod<jobject>(anInstance, "getClass", "()Ljava/lang/Class;"); 37 37 38 38 if (!aClass) { … … 41 41 } 42 42 43 jstring className = (jstring)callJNI ObjectMethod(aClass, "getName", "()Ljava/lang/String;");43 jstring className = (jstring)callJNIMethod<jobject>(aClass, "getName", "()Ljava/lang/String;"); 44 44 const char *classNameC = getCharactersFromJString(className); 45 45 _name = strdup(classNameC); … … 50 50 51 51 // Get the fields 52 jarray fields = (jarray)callJNI ObjectMethod(aClass, "getFields", "()[Ljava/lang/reflect/Field;");52 jarray fields = (jarray)callJNIMethod<jobject>(aClass, "getFields", "()[Ljava/lang/reflect/Field;"); 53 53 int numFields = env->GetArrayLength(fields); 54 54 for (i = 0; i < numFields; i++) { … … 63 63 64 64 // Get the methods 65 jarray methods = (jarray)callJNI ObjectMethod(aClass, "getMethods", "()[Ljava/lang/reflect/Method;");65 jarray methods = (jarray)callJNIMethod<jobject>(aClass, "getMethods", "()[Ljava/lang/reflect/Method;"); 66 66 int numMethods = env->GetArrayLength(methods); 67 67 for (i = 0; i < numMethods; i++) { -
trunk/WebCore/bridge/jni/jni_instance.cpp
r23479 r30868 79 79 JSLock lock; 80 80 81 jstring stringValue = (jstring)callJNI ObjectMethod(_instance->_instance, "toString", "()Ljava/lang/String;");81 jstring stringValue = (jstring)callJNIMethod<jobject>(_instance->_instance, "toString", "()Ljava/lang/String;"); 82 82 JNIEnv *env = getJNIEnv(); 83 83 const jchar *c = getUCharactersFromJStringInEnv(env, stringValue); … … 89 89 JSValue *JavaInstance::numberValue() const 90 90 { 91 jdouble doubleValue = callJNI DoubleMethod(_instance->_instance, "doubleValue", "()D");91 jdouble doubleValue = callJNIMethod<jdouble>(_instance->_instance, "doubleValue", "()D"); 92 92 return jsNumber(doubleValue); 93 93 } … … 95 95 JSValue *JavaInstance::booleanValue() const 96 96 { 97 jboolean booleanValue = callJNI BooleanMethod(_instance->_instance, "booleanValue", "()Z");97 jboolean booleanValue = callJNIMethod<jboolean>(_instance->_instance, "booleanValue", "()Z"); 98 98 return jsBoolean(booleanValue); 99 99 } … … 167 167 jobject obj = _instance->_instance; 168 168 switch (jMethod->JNIReturnType()){ 169 case void_type: { 170 callJNIVoidMethodIDA (obj, jMethod->methodID(obj), jArgs); 171 } 172 break; 169 case void_type: 170 callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); 171 break; 172 case object_type: 173 result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); 174 break; 175 case boolean_type: 176 result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); 177 break; 178 case byte_type: 179 result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); 180 break; 181 case char_type: 182 result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); 183 break; 184 case short_type: 185 result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); 186 break; 187 case int_type: 188 result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); 189 break; 173 190 174 case object_type: { 175 result.l = callJNIObjectMethodIDA (obj, jMethod->methodID(obj), jArgs); 176 } 177 break; 178 179 case boolean_type: { 180 result.z = callJNIBooleanMethodIDA (obj, jMethod->methodID(obj), jArgs); 181 } 182 break; 183 184 case byte_type: { 185 result.b = callJNIByteMethodIDA (obj, jMethod->methodID(obj), jArgs); 186 } 187 break; 188 189 case char_type: { 190 result.c = callJNICharMethodIDA (obj, jMethod->methodID(obj), jArgs); 191 } 192 break; 193 194 case short_type: { 195 result.s = callJNIShortMethodIDA (obj, jMethod->methodID(obj), jArgs); 196 } 197 break; 198 199 case int_type: { 200 result.i = callJNIIntMethodIDA (obj, jMethod->methodID(obj), jArgs); 201 } 202 break; 203 204 case long_type: { 205 result.j = callJNILongMethodIDA (obj, jMethod->methodID(obj), jArgs); 206 } 207 break; 208 209 case float_type: { 210 result.f = callJNIFloatMethodIDA (obj, jMethod->methodID(obj), jArgs); 211 } 212 break; 213 214 case double_type: { 215 result.d = callJNIDoubleMethodIDA (obj, jMethod->methodID(obj), jArgs); 216 } 217 break; 218 191 case long_type: 192 result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); 193 break; 194 case float_type: 195 result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); 196 break; 197 case double_type: 198 result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); 199 break; 219 200 case invalid_type: 220 default: { 221 } 222 break; 201 default: 202 break; 223 203 } 224 204 } -
trunk/WebCore/bridge/jni/jni_jsobject.cpp
r30816 r30868 573 573 // See section 22.7 of 'JavaScript: The Definitive Guide, 4th Edition', 574 574 // figure 22-4. 575 jobject classOfInstance = callJNI ObjectMethod(theObject, "getClass", "()Ljava/lang/Class;");576 jstring className = (jstring)callJNI ObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");575 jobject classOfInstance = callJNIMethod<jobject>(theObject, "getClass", "()Ljava/lang/Class;"); 576 jstring className = (jstring)callJNIMethod<jobject>(classOfInstance, "getName", "()Ljava/lang/String;"); 577 577 578 578 // Only the sun.plugin.javascript.webkit.JSObject has a member called nativeJSObject. This class is -
trunk/WebCore/bridge/jni/jni_runtime.cpp
r30782 r30868 54 54 { 55 55 // Get field type 56 jobject fieldType = callJNI ObjectMethod(aField, "getType", "()Ljava/lang/Class;");57 jstring fieldTypeName = (jstring)callJNI ObjectMethod(fieldType, "getName", "()Ljava/lang/String;");56 jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;"); 57 jstring fieldTypeName = (jstring)callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;"); 58 58 _type = JavaString(env, fieldTypeName); 59 59 _JNIType = JNITypeFromClassName (_type.UTF8String()); 60 60 61 61 // Get field name 62 jstring fieldName = (jstring)callJNI ObjectMethod(aField, "getName", "()Ljava/lang/String;");62 jstring fieldName = (jstring)callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;"); 63 63 _name = JavaString(env, fieldName); 64 64 … … 246 246 { 247 247 // Get return type 248 jobject returnType = callJNI ObjectMethod(aMethod, "getReturnType", "()Ljava/lang/Class;");249 jstring returnTypeName = (jstring)callJNI ObjectMethod(returnType, "getName", "()Ljava/lang/String;");248 jobject returnType = callJNIMethod<jobject>(aMethod, "getReturnType", "()Ljava/lang/Class;"); 249 jstring returnTypeName = (jstring)callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;"); 250 250 _returnType =JavaString (env, returnTypeName); 251 251 _JNIReturnType = JNITypeFromClassName (_returnType.UTF8String()); … … 254 254 255 255 // Get method name 256 jstring methodName = (jstring)callJNI ObjectMethod(aMethod, "getName", "()Ljava/lang/String;");256 jstring methodName = (jstring)callJNIMethod<jobject>(aMethod, "getName", "()Ljava/lang/String;"); 257 257 _name = JavaString (env, methodName); 258 258 env->DeleteLocalRef (methodName); 259 259 260 260 // Get parameters 261 jarray jparameters = (jarray)callJNI ObjectMethod(aMethod, "getParameterTypes", "()[Ljava/lang/Class;");261 jarray jparameters = (jarray)callJNIMethod<jobject>(aMethod, "getParameterTypes", "()[Ljava/lang/Class;"); 262 262 _numParameters = env->GetArrayLength (jparameters); 263 263 _parameters = new JavaParameter[_numParameters]; … … 266 266 for (i = 0; i < _numParameters; i++) { 267 267 jobject aParameter = env->GetObjectArrayElement ((jobjectArray)jparameters, i); 268 jstring parameterName = (jstring)callJNI ObjectMethod(aParameter, "getName", "()Ljava/lang/String;");268 jstring parameterName = (jstring)callJNIMethod<jobject>(aParameter, "getName", "()Ljava/lang/String;"); 269 269 _parameters[i] = JavaParameter(env, parameterName); 270 270 env->DeleteLocalRef (aParameter); … … 278 278 279 279 jclass modifierClass = env->FindClass("java/lang/reflect/Modifier"); 280 int modifiers = callJNI IntMethod(aMethod, "getModifiers", "()I");281 _isStatic = (bool)callJNIStatic BooleanMethod(modifierClass, "isStatic", "(I)Z", modifiers);280 int modifiers = callJNIMethod<jint>(aMethod, "getModifiers", "()I"); 281 _isStatic = (bool)callJNIStaticMethod<jboolean>(modifierClass, "isStatic", "(I)Z", modifiers); 282 282 } 283 283 -
trunk/WebCore/bridge/jni/jni_utility.cpp
r30782 r30868 101 101 } 102 102 103 static jvalue callJNIMethod (JNIType type, jobject obj, const char *name, const char *sig, va_list args)104 {105 JavaVM *jvm = getJavaVM();106 JNIEnv *env = getJNIEnv();107 jvalue result;108 109 bzero (&result, sizeof(jvalue));110 if ( obj != NULL && jvm != NULL && env != NULL) {111 jclass cls = env->GetObjectClass(obj);112 if ( cls != NULL ) {113 jmethodID mid = env->GetMethodID(cls, name, sig);114 if ( mid != NULL )115 {116 switch (type) {117 case void_type:118 env->functions->CallVoidMethodV(env, obj, mid, args);119 break;120 case array_type:121 case object_type:122 result.l = env->functions->CallObjectMethodV(env, obj, mid, args);123 break;124 case boolean_type:125 result.z = env->functions->CallBooleanMethodV(env, obj, mid, args);126 break;127 case byte_type:128 result.b = env->functions->CallByteMethodV(env, obj, mid, args);129 break;130 case char_type:131 result.c = env->functions->CallCharMethodV(env, obj, mid, args);132 break;133 case short_type:134 result.s = env->functions->CallShortMethodV(env, obj, mid, args);135 break;136 case int_type:137 result.i = env->functions->CallIntMethodV(env, obj, mid, args);138 break;139 case long_type:140 result.j = env->functions->CallLongMethodV(env, obj, mid, args);141 break;142 case float_type:143 result.f = env->functions->CallFloatMethodV(env, obj, mid, args);144 break;145 case double_type:146 result.d = env->functions->CallDoubleMethodV(env, obj, mid, args);147 break;148 default:149 fprintf(stderr, "%s: invalid function type (%d)\n", __PRETTY_FUNCTION__, (int)type);150 }151 }152 else153 {154 fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, name, obj);155 env->ExceptionDescribe();156 env->ExceptionClear();157 fprintf (stderr, "\n");158 }159 160 env->DeleteLocalRef(cls);161 }162 else {163 fprintf(stderr, "%s: Could not find class for %p\n", __PRETTY_FUNCTION__, obj);164 }165 }166 167 return result;168 }169 170 static jvalue callJNIStaticMethod (JNIType type, jclass cls, const char *name, const char *sig, va_list args)171 {172 JavaVM *jvm = getJavaVM();173 JNIEnv *env = getJNIEnv();174 jvalue result;175 176 bzero (&result, sizeof(jvalue));177 if ( cls != NULL && jvm != NULL && env != NULL) {178 jmethodID mid = env->GetStaticMethodID(cls, name, sig);179 if ( mid != NULL )180 {181 switch (type) {182 case void_type:183 env->functions->CallStaticVoidMethodV(env, cls, mid, args);184 break;185 case array_type:186 case object_type:187 result.l = env->functions->CallStaticObjectMethodV(env, cls, mid, args);188 break;189 case boolean_type:190 result.z = env->functions->CallStaticBooleanMethodV(env, cls, mid, args);191 break;192 case byte_type:193 result.b = env->functions->CallStaticByteMethodV(env, cls, mid, args);194 break;195 case char_type:196 result.c = env->functions->CallStaticCharMethodV(env, cls, mid, args);197 break;198 case short_type:199 result.s = env->functions->CallStaticShortMethodV(env, cls, mid, args);200 break;201 case int_type:202 result.i = env->functions->CallStaticIntMethodV(env, cls, mid, args);203 break;204 case long_type:205 result.j = env->functions->CallStaticLongMethodV(env, cls, mid, args);206 break;207 case float_type:208 result.f = env->functions->CallStaticFloatMethodV(env, cls, mid, args);209 break;210 case double_type:211 result.d = env->functions->CallStaticDoubleMethodV(env, cls, mid, args);212 break;213 default:214 fprintf(stderr, "%s: invalid function type (%d)\n", __PRETTY_FUNCTION__, (int)type);215 }216 }217 else218 {219 fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, name, cls);220 env->ExceptionDescribe();221 env->ExceptionClear();222 fprintf (stderr, "\n");223 }224 }225 226 return result;227 }228 229 static jvalue callJNIMethodIDA (JNIType type, jobject obj, jmethodID mid, jvalue *args)230 {231 JNIEnv *env = getJNIEnv();232 jvalue result;233 234 bzero (&result, sizeof(jvalue));235 if ( obj != NULL && mid != NULL )236 {237 switch (type) {238 case void_type:239 env->functions->CallVoidMethodA(env, obj, mid, args);240 break;241 case array_type:242 case object_type:243 result.l = env->functions->CallObjectMethodA(env, obj, mid, args);244 break;245 case boolean_type:246 result.z = env->functions->CallBooleanMethodA(env, obj, mid, args);247 break;248 case byte_type:249 result.b = env->functions->CallByteMethodA(env, obj, mid, args);250 break;251 case char_type:252 result.c = env->functions->CallCharMethodA(env, obj, mid, args);253 break;254 case short_type:255 result.s = env->functions->CallShortMethodA(env, obj, mid, args);256 break;257 case int_type:258 result.i = env->functions->CallIntMethodA(env, obj, mid, args);259 break;260 case long_type:261 result.j = env->functions->CallLongMethodA(env, obj, mid, args);262 break;263 case float_type:264 result.f = env->functions->CallFloatMethodA(env, obj, mid, args);265 break;266 case double_type:267 result.d = env->functions->CallDoubleMethodA(env, obj, mid, args);268 break;269 default:270 fprintf(stderr, "%s: invalid function type (%d)\n", __PRETTY_FUNCTION__, (int)type);271 }272 }273 274 return result;275 }276 277 static jvalue callJNIMethodA (JNIType type, jobject obj, const char *name, const char *sig, jvalue *args)278 {279 JavaVM *jvm = getJavaVM();280 JNIEnv *env = getJNIEnv();281 jvalue result;282 283 bzero (&result, sizeof(jvalue));284 if ( obj != NULL && jvm != NULL && env != NULL) {285 jclass cls = env->GetObjectClass(obj);286 if ( cls != NULL ) {287 jmethodID mid = env->GetMethodID(cls, name, sig);288 if ( mid != NULL ) {289 result = callJNIMethodIDA (type, obj, mid, args);290 }291 else {292 fprintf(stderr, "%s: Could not find method: %s\n", __PRETTY_FUNCTION__, name);293 env->ExceptionDescribe();294 env->ExceptionClear();295 fprintf (stderr, "\n");296 }297 298 env->DeleteLocalRef(cls);299 }300 else {301 fprintf(stderr, "%s: Could not find class for object\n", __PRETTY_FUNCTION__);302 }303 }304 305 return result;306 }307 308 103 jmethodID getMethodID (jobject obj, const char *name, const char *sig) 309 104 { … … 326 121 } 327 122 return mid; 328 }329 330 331 #define CALL_JNI_METHOD(function_type,obj,name,sig) \332 va_list args;\333 va_start (args, sig);\334 \335 jvalue result = callJNIMethod(function_type, obj, name, sig, args);\336 \337 va_end (args);338 339 #define CALL_JNI_STATIC_METHOD(function_type,cls,name,sig) \340 va_list args;\341 va_start (args, sig);\342 \343 jvalue result = callJNIStaticMethod(function_type, cls, name, sig, args);\344 \345 va_end (args);346 347 void callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... )348 {349 CALL_JNI_METHOD (void_type, obj, name, sig);350 }351 352 jobject callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... )353 {354 CALL_JNI_METHOD (object_type, obj, name, sig);355 return result.l;356 }357 358 jboolean callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... )359 {360 CALL_JNI_METHOD (boolean_type, obj, name, sig);361 return result.z;362 }363 364 jboolean callJNIStaticBooleanMethod (jclass cls, const char *name, const char *sig, ... )365 {366 CALL_JNI_STATIC_METHOD (boolean_type, cls, name, sig);367 return result.z;368 }369 370 jbyte callJNIByteMethod( jobject obj, const char *name, const char *sig, ... )371 {372 CALL_JNI_METHOD (byte_type, obj, name, sig);373 return result.b;374 }375 376 jchar callJNICharMethod (jobject obj, const char *name, const char *sig, ... )377 {378 CALL_JNI_METHOD (char_type, obj, name, sig);379 return result.c;380 }381 382 jshort callJNIShortMethod (jobject obj, const char *name, const char *sig, ... )383 {384 CALL_JNI_METHOD (short_type, obj, name, sig);385 return result.s;386 }387 388 jint callJNIIntMethod (jobject obj, const char *name, const char *sig, ... )389 {390 CALL_JNI_METHOD (int_type, obj, name, sig);391 return result.i;392 }393 394 jlong callJNILongMethod (jobject obj, const char *name, const char *sig, ... )395 {396 CALL_JNI_METHOD (long_type, obj, name, sig);397 return result.j;398 }399 400 jfloat callJNIFloatMethod (jobject obj, const char *name, const char *sig, ... )401 {402 CALL_JNI_METHOD (float_type, obj, name, sig);403 return result.f;404 }405 406 jdouble callJNIDoubleMethod (jobject obj, const char *name, const char *sig, ... )407 {408 CALL_JNI_METHOD (double_type, obj, name, sig);409 return result.d;410 }411 412 void callJNIVoidMethodA (jobject obj, const char *name, const char *sig, jvalue *args)413 {414 jvalue result = callJNIMethodA (void_type, obj, name, sig, args);415 }416 417 jobject callJNIObjectMethodA (jobject obj, const char *name, const char *sig, jvalue *args)418 {419 jvalue result = callJNIMethodA (object_type, obj, name, sig, args);420 return result.l;421 }422 423 jbyte callJNIByteMethodA ( jobject obj, const char *name, const char *sig, jvalue *args)424 {425 jvalue result = callJNIMethodA (byte_type, obj, name, sig, args);426 return result.b;427 }428 429 jchar callJNICharMethodA (jobject obj, const char *name, const char *sig, jvalue *args)430 {431 jvalue result = callJNIMethodA (char_type, obj, name, sig, args);432 return result.c;433 }434 435 jshort callJNIShortMethodA (jobject obj, const char *name, const char *sig, jvalue *args)436 {437 jvalue result = callJNIMethodA (short_type, obj, name, sig, args);438 return result.s;439 }440 441 jint callJNIIntMethodA (jobject obj, const char *name, const char *sig, jvalue *args)442 {443 jvalue result = callJNIMethodA (int_type, obj, name, sig, args);444 return result.i;445 }446 447 jlong callJNILongMethodA (jobject obj, const char *name, const char *sig, jvalue *args)448 {449 jvalue result = callJNIMethodA (long_type, obj, name, sig, args);450 return result.j;451 }452 453 jfloat callJNIFloatMethodA (jobject obj, const char *name, const char *sig, jvalue *args)454 {455 jvalue result = callJNIMethodA (float_type, obj, name, sig, args);456 return result.f;457 }458 459 jdouble callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jvalue *args)460 {461 jvalue result = callJNIMethodA (double_type, obj, name, sig, args);462 return result.d;463 }464 465 jboolean callJNIBooleanMethodA (jobject obj, const char *name, const char *sig, jvalue *args)466 {467 jvalue result = callJNIMethodA (boolean_type, obj, name, sig, args);468 return result.z;469 }470 471 void callJNIVoidMethodIDA (jobject obj, jmethodID methodID, jvalue *args)472 {473 jvalue result = callJNIMethodIDA (void_type, obj, methodID, args);474 }475 476 jobject callJNIObjectMethodIDA (jobject obj, jmethodID methodID, jvalue *args)477 {478 jvalue result = callJNIMethodIDA (object_type, obj, methodID, args);479 return result.l;480 }481 482 jbyte callJNIByteMethodIDA ( jobject obj, jmethodID methodID, jvalue *args)483 {484 jvalue result = callJNIMethodIDA (byte_type, obj, methodID, args);485 return result.b;486 }487 488 jchar callJNICharMethodIDA (jobject obj, jmethodID methodID, jvalue *args)489 {490 jvalue result = callJNIMethodIDA (char_type, obj, methodID, args);491 return result.c;492 }493 494 jshort callJNIShortMethodIDA (jobject obj, jmethodID methodID, jvalue *args)495 {496 jvalue result = callJNIMethodIDA (short_type, obj, methodID, args);497 return result.s;498 }499 500 jint callJNIIntMethodIDA (jobject obj, jmethodID methodID, jvalue *args)501 {502 jvalue result = callJNIMethodIDA (int_type, obj, methodID, args);503 return result.i;504 }505 506 jlong callJNILongMethodIDA (jobject obj, jmethodID methodID, jvalue *args)507 {508 jvalue result = callJNIMethodIDA (long_type, obj, methodID, args);509 return result.j;510 }511 512 jfloat callJNIFloatMethodIDA (jobject obj, jmethodID methodID, jvalue *args)513 {514 jvalue result = callJNIMethodIDA (float_type, obj, methodID, args);515 return result.f;516 }517 518 jdouble callJNIDoubleMethodIDA (jobject obj, jmethodID methodID, jvalue *args)519 {520 jvalue result = callJNIMethodIDA (double_type, obj, methodID, args);521 return result.d;522 }523 524 jboolean callJNIBooleanMethodIDA (jobject obj, jmethodID methodID, jvalue *args)525 {526 jvalue result = callJNIMethodIDA (boolean_type, obj, methodID, args);527 return result.z;528 123 } 529 124 -
trunk/WebCore/bridge/jni/jni_utility.h
r30782 r30868 75 75 76 76 jmethodID getMethodID(jobject obj, const char *name, const char *sig); 77 78 jobject callJNIObjectMethod(jobject obj, const char *name, const char *sig, ... ); 79 void callJNIVoidMethod(jobject obj, const char *name, const char *sig, ... ); 80 jboolean callJNIBooleanMethod(jobject obj, const char *name, const char *sig, ... ); 81 jboolean callJNIStaticBooleanMethod(jclass cls, const char *name, const char *sig, ... ); 82 jbyte callJNIByteMethod(jobject obj, const char *name, const char *sig, ... ); 83 jchar callJNICharMethod(jobject obj, const char *name, const char *sig, ... ); 84 jshort callJNIShortMethod(jobject obj, const char *name, const char *sig, ... ); 85 jint callJNIIntMethod(jobject obj, const char *name, const char *sig, ... ); 86 jlong callJNILongMethod(jobject obj, const char *name, const char *sig, ... ); 87 jfloat callJNIFloatMethod(jobject obj, const char *name, const char *sig, ... ); 88 jdouble callJNIDoubleMethod(jobject obj, const char *name, const char *sig, ... ); 89 90 jobject callJNIObjectMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 91 void callJNIVoidMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 92 jboolean callJNIBooleanMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 93 jbyte callJNIByteMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 94 jchar callJNICharMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 95 jshort callJNIShortMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 96 jint callJNIIntMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 97 jlong callJNILongMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 98 jfloat callJNIFloatMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 99 jdouble callJNIDoubleMethodA(jobject obj, const char *name, const char *sig, jvalue *args); 100 101 jobject callJNIObjectMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 102 void callJNIVoidMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 103 jboolean callJNIBooleanMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 104 jbyte callJNIByteMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 105 jchar callJNICharMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 106 jshort callJNIShortMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 107 jint callJNIIntMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 108 jlong callJNILongMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 109 jfloat callJNIFloatMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 110 jdouble callJNIDoubleMethodIDA(jobject obj, jmethodID methodID, jvalue *args); 111 112 JavaVM *getJavaVM(); 113 void setJavaVM(JavaVM *javaVM); 114 JNIEnv *getJNIEnv(); 115 77 JNIEnv* getJNIEnv(); 78 JavaVM* getJavaVM(); 79 void setJavaVM(JavaVM*); 80 81 82 template <typename T> struct JNICaller; 83 84 template<> struct JNICaller<void> { 85 static void callA(jobject obj, jmethodID mid, jvalue* args) 86 { 87 return getJNIEnv()->CallVoidMethodA(obj, mid, args); 88 } 89 static void callV(jobject obj, jmethodID mid, va_list args) 90 { 91 return getJNIEnv()->CallVoidMethodV(obj, mid, args); 92 } 93 }; 94 95 template<> struct JNICaller<jobject> { 96 static jobject callA(jobject obj, jmethodID mid, jvalue* args) 97 { 98 return getJNIEnv()->CallObjectMethodA(obj, mid, args); 99 } 100 static jobject callV(jobject obj, jmethodID mid, va_list args) 101 { 102 return getJNIEnv()->CallObjectMethodV(obj, mid, args); 103 } 104 }; 105 106 template<> struct JNICaller<jboolean> { 107 static jboolean callA(jobject obj, jmethodID mid, jvalue* args) 108 { 109 return getJNIEnv()->CallBooleanMethodA(obj, mid, args); 110 } 111 static jboolean callV(jobject obj, jmethodID mid, va_list args) 112 { 113 return getJNIEnv()->CallBooleanMethodV(obj, mid, args); 114 } 115 static jboolean callStaticV(jclass cls, jmethodID mid, va_list args) 116 { 117 return getJNIEnv()->CallStaticBooleanMethod(cls, mid, args); 118 } 119 120 }; 121 122 template<> struct JNICaller<jbyte> { 123 static jbyte callA(jobject obj, jmethodID mid, jvalue* args) 124 { 125 return getJNIEnv()->CallByteMethodA(obj, mid, args); 126 } 127 static jbyte callV(jobject obj, jmethodID mid, va_list args) 128 { 129 return getJNIEnv()->CallByteMethodV(obj, mid, args); 130 } 131 }; 132 133 template<> struct JNICaller<jchar> { 134 static jchar callA(jobject obj, jmethodID mid, jvalue* args) 135 { 136 return getJNIEnv()->CallCharMethodA(obj, mid, args); 137 } 138 static jchar callV(jobject obj, jmethodID mid, va_list args) 139 { 140 return getJNIEnv()->CallCharMethodV(obj, mid, args); 141 } 142 }; 143 144 template<> struct JNICaller<jshort> { 145 static jshort callA(jobject obj, jmethodID mid, jvalue* args) 146 { 147 return getJNIEnv()->CallShortMethodA(obj, mid, args); 148 } 149 static jshort callV(jobject obj, jmethodID mid, va_list args) 150 { 151 return getJNIEnv()->CallShortMethodV(obj, mid, args); 152 } 153 }; 154 155 template<> struct JNICaller<jint> { 156 static jint callA(jobject obj, jmethodID mid, jvalue* args) 157 { 158 return getJNIEnv()->CallIntMethodA(obj, mid, args); 159 } 160 static jint callV(jobject obj, jmethodID mid, va_list args) 161 { 162 return getJNIEnv()->CallIntMethodV(obj, mid, args); 163 } 164 }; 165 166 template<> struct JNICaller<jlong> { 167 static jlong callA(jobject obj, jmethodID mid, jvalue* args) 168 { 169 return getJNIEnv()->CallLongMethodA(obj, mid, args); 170 } 171 static jlong callV(jobject obj, jmethodID mid, va_list args) 172 { 173 return getJNIEnv()->CallLongMethodV(obj, mid, args); 174 } 175 }; 176 177 template<> struct JNICaller<jfloat> { 178 static jfloat callA(jobject obj, jmethodID mid, jvalue* args) 179 { 180 return getJNIEnv()->CallFloatMethodA(obj, mid, args); 181 } 182 static jfloat callV(jobject obj, jmethodID mid, va_list args) 183 { 184 return getJNIEnv()->CallFloatMethodV(obj, mid, args); 185 } 186 }; 187 188 template<> struct JNICaller<jdouble> { 189 static jdouble callA(jobject obj, jmethodID mid, jvalue* args) 190 { 191 return getJNIEnv()->CallDoubleMethodA(obj, mid, args); 192 } 193 static jdouble callV(jobject obj, jmethodID mid, va_list args) 194 { 195 return getJNIEnv()->CallDoubleMethodV(obj, mid, args); 196 } 197 }; 198 199 template<typename T> T callJNIMethodIDA(jobject obj, jmethodID mid, jvalue *args) 200 { 201 return JNICaller<T>::callA(obj, mid, args); 202 } 203 204 template<typename T> 205 static T callJNIMethodV(jobject obj, const char *name, const char *sig, va_list args) 206 { 207 JavaVM *jvm = getJavaVM(); 208 JNIEnv *env = getJNIEnv(); 209 210 if ( obj != NULL && jvm != NULL && env != NULL) { 211 jclass cls = env->GetObjectClass(obj); 212 if ( cls != NULL ) { 213 jmethodID mid = env->GetMethodID(cls, name, sig); 214 if ( mid != NULL ) 215 { 216 return JNICaller<T>::callV(obj, mid, args); 217 } 218 else 219 { 220 fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, name, obj); 221 env->ExceptionDescribe(); 222 env->ExceptionClear(); 223 fprintf (stderr, "\n"); 224 } 225 226 env->DeleteLocalRef(cls); 227 } 228 else { 229 fprintf(stderr, "%s: Could not find class for %p\n", __PRETTY_FUNCTION__, obj); 230 } 231 } 232 233 return 0; 234 } 235 236 template<typename T> 237 T callJNIMethod(jobject obj, const char* methodName, const char* methodSignature, ...) 238 { 239 va_list args; 240 va_start(args, methodSignature); 241 242 T result= callJNIMethodV<T>(obj, methodName, methodSignature, args); 243 244 va_end(args); 245 246 return result; 247 } 248 249 template<typename T> 250 T callJNIStaticMethod(jclass cls, const char* methodName, const char* methodSignature, ...) 251 { 252 JavaVM *jvm = getJavaVM(); 253 JNIEnv *env = getJNIEnv(); 254 va_list args; 255 256 va_start(args, methodSignature); 257 258 T result = 0; 259 260 if (cls != NULL && jvm != NULL && env != NULL) { 261 jmethodID mid = env->GetStaticMethodID(cls, methodName, methodSignature); 262 if (mid != NULL) 263 result = JNICaller<T>::callStaticV(cls, mid, args); 264 else { 265 fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, methodName, cls); 266 env->ExceptionDescribe(); 267 env->ExceptionClear(); 268 fprintf (stderr, "\n"); 269 } 270 } 271 272 va_end(args); 273 274 return result; 275 } 276 116 277 bool dispatchJNICall(const void *targetAppletView, jobject obj, bool isStatic, JNIType returnType, jmethodID methodID, jvalue *args, jvalue &result, const char *callingURL, JSValue *&exceptionDescription); 117 278
Note: See TracChangeset
for help on using the changeset viewer.