diff options
author | Steve Block <steveblock@google.com> | 2010-02-02 14:57:50 +0000 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2010-02-04 15:06:55 +0000 |
commit | d0825bca7fe65beaee391d30da42e937db621564 (patch) | |
tree | 7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /WebCore/bridge/jni | |
parent | 3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff) | |
download | external_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2 |
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'WebCore/bridge/jni')
-rw-r--r-- | WebCore/bridge/jni/JNIBridge.cpp | 39 | ||||
-rw-r--r-- | WebCore/bridge/jni/JNIBridge.h | 6 | ||||
-rw-r--r-- | WebCore/bridge/jni/JNIUtility.h | 4 | ||||
-rw-r--r-- | WebCore/bridge/jni/jni_jsobject.mm | 45 | ||||
-rw-r--r-- | WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp | 16 | ||||
-rw-r--r-- | WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp | 16 |
6 files changed, 100 insertions, 26 deletions
diff --git a/WebCore/bridge/jni/JNIBridge.cpp b/WebCore/bridge/jni/JNIBridge.cpp index 4810e5f..008b3d3 100644 --- a/WebCore/bridge/jni/JNIBridge.cpp +++ b/WebCore/bridge/jni/JNIBridge.cpp @@ -55,20 +55,39 @@ JavaParameter::JavaParameter(JNIEnv* env, jstring type) JavaMethod::JavaMethod(JNIEnv* env, jobject aMethod) { +<<<<<<< HEAD // Get return type jobject returnType = callJNIMethod<jobject>(aMethod, "getReturnType", "()Ljava/lang/Class;"); jstring returnTypeName = static_cast<jstring>(callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;")); m_returnType = JavaString(env, returnTypeName); m_JNIReturnType = JNITypeFromClassName(m_returnType.UTF8String()); env->DeleteLocalRef(returnType); +======= + // Get return type name + jstring returnTypeName = 0; + if (jobject returnType = callJNIMethod<jobject>(aMethod, "getReturnType", "()Ljava/lang/Class;")) { + returnTypeName = static_cast<jstring>(callJNIMethod<jobject>(returnType, "getName", "()Ljava/lang/String;")); + if (!returnTypeName) + returnTypeName = env->NewStringUTF("<Unknown>"); + env->DeleteLocalRef(returnType); + } + m_returnType = JavaString(env, returnTypeName); + m_JNIReturnType = JNITypeFromClassName(m_returnType.UTF8String()); +>>>>>>> webkit.org at r54127 env->DeleteLocalRef(returnTypeName); // Get method name jstring methodName = static_cast<jstring>(callJNIMethod<jobject>(aMethod, "getName", "()Ljava/lang/String;")); +<<<<<<< HEAD +======= + if (!returnTypeName) + returnTypeName = env->NewStringUTF("<Unknown>"); +>>>>>>> webkit.org at r54127 m_name = JavaString(env, methodName); env->DeleteLocalRef(methodName); // Get parameters +<<<<<<< HEAD jarray jparameters = static_cast<jarray>(callJNIMethod<jobject>(aMethod, "getParameterTypes", "()[Ljava/lang/Class;")); m_numParameters = env->GetArrayLength(jparameters); m_parameters = new JavaParameter[m_numParameters]; @@ -81,6 +100,26 @@ JavaMethod::JavaMethod(JNIEnv* env, jobject aMethod) env->DeleteLocalRef(parameterName); } env->DeleteLocalRef(jparameters); +======= + if (jarray jparameters = static_cast<jarray>(callJNIMethod<jobject>(aMethod, "getParameterTypes", "()[Ljava/lang/Class;"))) { + m_numParameters = env->GetArrayLength(jparameters); + m_parameters = new JavaParameter[m_numParameters]; + + for (int i = 0; i < m_numParameters; i++) { + jobject aParameter = env->GetObjectArrayElement(static_cast<jobjectArray>(jparameters), i); + jstring parameterName = static_cast<jstring>(callJNIMethod<jobject>(aParameter, "getName", "()Ljava/lang/String;")); + if (!parameterName) + parameterName = env->NewStringUTF("<Unknown>"); + m_parameters[i] = JavaParameter(env, parameterName); + env->DeleteLocalRef(aParameter); + env->DeleteLocalRef(parameterName); + } + env->DeleteLocalRef(jparameters); + } else { + m_numParameters = 0; + m_parameters = 0; + } +>>>>>>> webkit.org at r54127 // Created lazily. m_signature = 0; diff --git a/WebCore/bridge/jni/JNIBridge.h b/WebCore/bridge/jni/JNIBridge.h index 5d482a7..c9d3a24 100644 --- a/WebCore/bridge/jni/JNIBridge.h +++ b/WebCore/bridge/jni/JNIBridge.h @@ -29,13 +29,19 @@ #if ENABLE(MAC_JAVA_BRIDGE) +<<<<<<< HEAD #include "Bridge.h" +======= +>>>>>>> webkit.org at r54127 #include "JNIUtility.h" #if USE(JSC) #include "JavaStringJSC.h" +<<<<<<< HEAD #elif USE(V8) #include "JavaStringV8.h" +======= +>>>>>>> webkit.org at r54127 #endif namespace JSC { diff --git a/WebCore/bridge/jni/JNIUtility.h b/WebCore/bridge/jni/JNIUtility.h index 85c3533..c832ef3 100644 --- a/WebCore/bridge/jni/JNIUtility.h +++ b/WebCore/bridge/jni/JNIUtility.h @@ -81,11 +81,11 @@ template <typename T> struct JNICaller; template<> struct JNICaller<void> { static void callA(jobject obj, jmethodID mid, jvalue* args) { - return getJNIEnv()->CallVoidMethodA(obj, mid, args); + getJNIEnv()->CallVoidMethodA(obj, mid, args); } static void callV(jobject obj, jmethodID mid, va_list args) { - return getJNIEnv()->CallVoidMethodV(obj, mid, args); + getJNIEnv()->CallVoidMethodV(obj, mid, args); } }; diff --git a/WebCore/bridge/jni/jni_jsobject.mm b/WebCore/bridge/jni/jni_jsobject.mm index de67711..603624f 100644 --- a/WebCore/bridge/jni/jni_jsobject.mm +++ b/WebCore/bridge/jni/jni_jsobject.mm @@ -128,7 +128,7 @@ static void dispatchToJavaScriptThread(JSObjectCallContext *context) completionSource = CFRunLoopSourceCreate(NULL, 0, &sourceContext); CFRunLoopAddSource(currentRunLoop, completionSource, kCFRunLoopDefaultMode); - // Wakeup JavaScript access thread and make it do it's work. + // Wakeup JavaScript access thread and make it do its work. CFRunLoopSourceSignal(_performJavaScriptSource); if (CFRunLoopIsWaiting(_performJavaScriptRunLoop)) CFRunLoopWakeUp(_performJavaScriptRunLoop); @@ -533,7 +533,7 @@ jobject JavaJSObject::convertValueToJObject(JSValue value) const // We either have a wrapper around a Java instance or a JavaScript // object. If we have a wrapper around a Java instance, return that // instance, otherwise create a new Java JavaJSObject with the JSObject* - // as it's nativeHandle. + // as its nativeHandle. if (imp->classInfo() && strcmp(imp->classInfo()->className, "RuntimeObject") == 0) { RuntimeObjectImp* runtimeImp = static_cast<RuntimeObjectImp*>(imp); JavaInstance *runtimeInstance = static_cast<JavaInstance *>(runtimeImp->getInternalInstance()); @@ -552,7 +552,7 @@ jobject JavaJSObject::convertValueToJObject(JSValue value) const nativeHandle = UndefinedHandle; } - // Now create the Java JavaJSObject. Look for the JavaJSObject in it's new (Tiger) + // Now create the Java JavaJSObject. Look for the JavaJSObject in its new (Tiger) // location and in the original Java 1.4.2 location. jclass JSObjectClass; @@ -580,30 +580,31 @@ JSValue JavaJSObject::convertJObjectToValue(ExecState* exec, jobject theObject) // See section 22.7 of 'JavaScript: The Definitive Guide, 4th Edition', // figure 22-4. jobject classOfInstance = callJNIMethod<jobject>(theObject, "getClass", "()Ljava/lang/Class;"); - jstring className = (jstring)callJNIMethod<jobject>(classOfInstance, "getName", "()Ljava/lang/String;"); - + if (!classOfInstance) { + JSLock lock(SilenceAssertionsOnly); + return JavaInstance::create(theObject, _rootObject)->createRuntimeObject(exec); + } + // Only the sun.plugin.javascript.webkit.JSObject has a member called nativeJSObject. This class is // created above to wrap internal browser objects. The constructor of this class takes the native // pointer and stores it in this object, so that it can be retrieved below. - if (strcmp(JavaString(className).UTF8String(), "sun.plugin.javascript.webkit.JSObject") == 0) { - // Pull the nativeJSObject value from the Java instance. This is a - // pointer to the JSObject. - JNIEnv *env = getJNIEnv(); - jfieldID fieldID = env->GetFieldID((jclass)classOfInstance, "nativeJSObject", "J"); - if (fieldID == NULL) { - return jsUndefined(); - } - jlong nativeHandle = env->GetLongField(theObject, fieldID); - if (nativeHandle == UndefinedHandle) { - return jsUndefined(); - } - JSObject *imp = static_cast<JSObject*>(jlong_to_impptr(nativeHandle)); - return imp; + jstring className = (jstring)callJNIMethod<jobject>(classOfInstance, "getName", "()Ljava/lang/String;"); + if (!className || (strcmp(JavaString(className).UTF8String(), "sun.plugin.javascript.webkit.JSObject") != 0)) { + JSLock lock(SilenceAssertionsOnly); + return JavaInstance::create(theObject, _rootObject)->createRuntimeObject(exec); } - JSLock lock(SilenceAssertionsOnly); - - return JavaInstance::create(theObject, _rootObject)->createRuntimeObject(exec); + // Pull the nativeJSObject value from the Java instance. This is a + // pointer to the JSObject. + JNIEnv *env = getJNIEnv(); + jfieldID fieldID = env->GetFieldID((jclass)classOfInstance, "nativeJSObject", "J"); + if (fieldID == NULL) + return jsUndefined(); + jlong nativeHandle = env->GetLongField(theObject, fieldID); + if (nativeHandle == UndefinedHandle) + return jsUndefined(); + JSObject *imp = static_cast<JSObject*>(jlong_to_impptr(nativeHandle)); + return imp; } void JavaJSObject::getListFromJArray(ExecState* exec, jobjectArray jArray, MarkedArgumentBuffer& list) const diff --git a/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp b/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp index 4bc6c47..4520bd6 100644 --- a/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp +++ b/WebCore/bridge/jni/jsc/JNIBridgeJSC.cpp @@ -49,14 +49,30 @@ using namespace JSC::Bindings; JavaField::JavaField(JNIEnv* env, jobject aField) { +<<<<<<< HEAD // Get field type jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;"); jstring fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;")); m_type = JavaString(env, fieldTypeName); +======= + // Get field type name + jstring fieldTypeName = 0; + if (jobject fieldType = callJNIMethod<jobject>(aField, "getType", "()Ljava/lang/Class;")) + fieldTypeName = static_cast<jstring>(callJNIMethod<jobject>(fieldType, "getName", "()Ljava/lang/String;")); + if (!fieldTypeName) + fieldTypeName = env->NewStringUTF("<Unknown>"); + m_type = JavaString(env, fieldTypeName); + +>>>>>>> webkit.org at r54127 m_JNIType = JNITypeFromClassName(m_type.UTF8String()); // Get field name jstring fieldName = static_cast<jstring>(callJNIMethod<jobject>(aField, "getName", "()Ljava/lang/String;")); +<<<<<<< HEAD +======= + if (!fieldName) + fieldName = env->NewStringUTF("<Unknown>"); +>>>>>>> webkit.org at r54127 m_name = JavaString(env, fieldName); m_field = new JObjectWrapper(aField); diff --git a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp index 4d403ab..a0e6db5 100644 --- a/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp +++ b/WebCore/bridge/jni/jsc/JavaInstanceJSC.cpp @@ -90,6 +90,14 @@ JSValue JavaInstance::stringValue(ExecState* exec) const JSLock lock(SilenceAssertionsOnly); jstring stringValue = (jstring)callJNIMethod<jobject>(m_instance->m_instance, "toString", "()Ljava/lang/String;"); +<<<<<<< HEAD +======= + + // Should throw a JS exception, rather than returning ""? - but better than a null dereference. + if (!stringValue) + return jsString(exec, UString()); + +>>>>>>> webkit.org at r54127 JNIEnv* env = getJNIEnv(); const jchar* c = getUCharactersFromJStringInEnv(env, stringValue); UString u((const UChar*)c, (int)env->GetStringLength(stringValue)); @@ -118,7 +126,11 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList size_t numMethods = methodList.size(); // Try to find a good match for the overloaded method. The +<<<<<<< HEAD // fundamental problem is that JavaScript doesn't have the +======= + // fundamental problem is that JavaScript doesn have the +>>>>>>> webkit.org at r54127 // notion of method overloading and Java does. We could // get a bit more sophisticated and attempt to does some // type checking as we as checking the number of parameters. @@ -152,7 +164,7 @@ JSValue JavaInstance::invokeMethod(ExecState* exec, const MethodList& methodList jvalue result; // Try to use the JNI abstraction first, otherwise fall back to - // nornmal JNI. The JNI dispatch abstraction allows the Java plugin + // normal JNI. The JNI dispatch abstraction allows the Java plugin // to dispatch the call on the appropriate internal VM thread. RootObject* rootObject = this->rootObject(); if (!rootObject) @@ -320,7 +332,7 @@ JObjectWrapper::JObjectWrapper(jobject instance) { assert(instance); - // Cache the JNIEnv used to get the global ref for this java instanace. + // Cache the JNIEnv used to get the global ref for this java instance. // It'll be used to delete the reference. m_env = getJNIEnv(); |