+2004-12-13 Richard Williamson <rjw@apple.com>
+
+ Fixed <rdar://problem/3827799> repro. crash with IBM Rational ClearCase Web under Safari (Java/LiveConnect-related)
+
+ Add support for calling static Java methods from JavaScript.
+
+ Reviewed by Maciej.
+
+ * bindings/jni/jni_instance.cpp:
+ (JavaInstance::invokeMethod):
+ * bindings/jni/jni_runtime.cpp:
+ (JavaMethod::JavaMethod):
+ * bindings/jni/jni_runtime.h:
+ (KJS::Bindings::JavaMethod::isStatic):
+ * bindings/jni/jni_utility.cpp:
+ (callJNIStaticMethod):
+ (KJS::Bindings::callJNIBooleanMethod):
+ (KJS::Bindings::callJNIStaticBooleanMethod):
+ * bindings/jni/jni_utility.h:
+
2004-12-13 Richard Williamson <rjw@apple.com>
Fixed <rdar://problem/3887767> LiveConnect doesn't propagate Java exceptions back to JavaScript (prevents security suite from running)
if (execContext && execContext->nativeHandle()) {
jobject obj = _instance->_instance;
Value exceptionDescription;
- bool isStatic = false; // FIXME, need to get meta data from Java about static methods
const char *callingURL = 0; // FIXME, need to propagate calling URL to Java
- handled = dispatchJNICall (execContext->nativeHandle(), obj, isStatic, jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription);
+ handled = dispatchJNICall (execContext->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription);
if (!exceptionDescription.isNull()) {
Object error = Error::create(exec, GeneralError, exceptionDescription.toString(exec).UTF8String().c_str());
return result;
}
+static jvalue callJNIStaticMethod (JNIType type, jclass cls, const char *name, const char *sig, va_list args)
+{
+ JavaVM *jvm = getJavaVM();
+ JNIEnv *env = getJNIEnv();
+ jvalue result;
+
+ bzero (&result, sizeof(jvalue));
+ if ( cls != NULL && jvm != NULL && env != NULL) {
+ jmethodID mid = env->GetStaticMethodID(cls, name, sig);
+ if ( mid != NULL )
+ {
+ switch (type) {
+ case void_type:
+ env->functions->CallStaticVoidMethodV(env, cls, mid, args);
+ break;
+ case object_type:
+ result.l = env->functions->CallStaticObjectMethodV(env, cls, mid, args);
+ break;
+ case boolean_type:
+ result.z = env->functions->CallStaticBooleanMethodV(env, cls, mid, args);
+ break;
+ case byte_type:
+ result.b = env->functions->CallStaticByteMethodV(env, cls, mid, args);
+ break;
+ case char_type:
+ result.c = env->functions->CallStaticCharMethodV(env, cls, mid, args);
+ break;
+ case short_type:
+ result.s = env->functions->CallStaticShortMethodV(env, cls, mid, args);
+ break;
+ case int_type:
+ result.i = env->functions->CallStaticIntMethodV(env, cls, mid, args);
+ break;
+ case long_type:
+ result.j = env->functions->CallStaticLongMethodV(env, cls, mid, args);
+ break;
+ case float_type:
+ result.f = env->functions->CallStaticFloatMethodV(env, cls, mid, args);
+ break;
+ case double_type:
+ result.d = env->functions->CallStaticDoubleMethodV(env, cls, mid, args);
+ break;
+ default:
+ fprintf(stderr, "%s: invalid function type (%d)\n", __PRETTY_FUNCTION__, (int)type);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "%s: Could not find method: %s for %p\n", __PRETTY_FUNCTION__, name, cls);
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ fprintf (stderr, "\n");
+ }
+ }
+
+ return result;
+}
+
static jvalue callJNIMethodIDA (JNIType type, jobject obj, jmethodID mid, jvalue *args)
{
JNIEnv *env = getJNIEnv();
\
va_end (args);
+#define CALL_JNI_STATIC_METHOD(function_type,cls,name,sig) \
+ va_list args;\
+ va_start (args, sig);\
+ \
+ jvalue result = callJNIStaticMethod(function_type, cls, name, sig, args);\
+ \
+ va_end (args);
+
void KJS::Bindings::callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... )
{
CALL_JNI_METHOD (void_type, obj, name, sig);
return result.z;
}
+jboolean KJS::Bindings::callJNIStaticBooleanMethod (jclass cls, const char *name, const char *sig, ... )
+{
+ CALL_JNI_STATIC_METHOD (boolean_type, cls, name, sig);
+ return result.z;
+}
+
jbyte KJS::Bindings::callJNIByteMethod( jobject obj, const char *name, const char *sig, ... )
{
CALL_JNI_METHOD (byte_type, obj, name, sig);
jobject callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... );
void callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... );
jboolean callJNIBooleanMethod (jobject obj, const char *name, const char *sig, ... );
+jboolean callJNIStaticBooleanMethod (jclass cls, const char *name, const char *sig, ... );
jbyte callJNIByteMethod (jobject obj, const char *name, const char *sig, ... );
jchar callJNICharMethod (jobject obj, const char *name, const char *sig, ... );
jshort callJNIShortMethod (jobject obj, const char *name, const char *sig, ... );