diff options
author | Steve Block <steveblock@google.com> | 2012-04-25 21:12:50 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2012-04-26 12:06:32 +0100 |
commit | cb3fc20cd59c3956ace2b6b9966da170b92b9162 (patch) | |
tree | e95568b643b8be7ede997613f82481dca5e604c2 /Source/WebCore/bridge/jni | |
parent | 42ff8798399d2f8bbba1841908028131fa1d38b8 (diff) | |
download | external_webkit-cb3fc20cd59c3956ace2b6b9966da170b92b9162.zip external_webkit-cb3fc20cd59c3956ace2b6b9966da170b92b9162.tar.gz external_webkit-cb3fc20cd59c3956ace2b6b9966da170b92b9162.tar.bz2 |
Handle uncaught exceptions from methods called through the Java Bridge
If a method called on a Java object through the Java Bridge throws an uncaught
exception, handle it native-side by clearing the exception to prevent a crash,
and throwing a JavaScript exception.
See tests in https://android-git.corp.google.com/g/184260
Bug: 6386557
Change-Id: Ida96e9be7dba714cc8332682615c896120c50ab1
Diffstat (limited to 'Source/WebCore/bridge/jni')
4 files changed, 28 insertions, 4 deletions
diff --git a/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp b/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp index f2dd1d2..e7b854d 100644 --- a/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp +++ b/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.cpp @@ -65,15 +65,29 @@ JavaClass* JavaInstanceJobject::getClass() const return m_class.get(); } -JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args) +// ANDROID +JavaValue JavaInstanceJobject::invokeMethod(const JavaMethod* method, JavaValue* args, bool& didRaiseUncaughtException) { + didRaiseUncaughtException = false; +// END ANDROID + ASSERT(getClass()->methodsNamed(method->name().utf8().data()).find(method) != notFound); unsigned int numParams = method->numParameters(); OwnArrayPtr<jvalue> jvalueArgs = adoptArrayPtr(new jvalue[numParams]); for (unsigned int i = 0; i < numParams; ++i) jvalueArgs[i] = javaValueToJvalue(args[i]); jvalue result = callJNIMethod(javaInstance(), method->returnType(), method->name().utf8().data(), method->signature(), jvalueArgs.get()); + +// ANDROID + JNIEnv* env = getJNIEnv(); + if (env->ExceptionCheck() != JNI_FALSE) { + env->ExceptionClear(); + didRaiseUncaughtException = true; + return JavaValue(); + } + return jvalueToJavaValue(result, method->returnType()); +// END ANDROID } static void appendClassName(StringBuilder& builder, const char* className) diff --git a/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h b/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h index bb38e77..255c190 100644 --- a/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h +++ b/Source/WebCore/bridge/jni/v8/JavaInstanceJobjectV8.h @@ -52,7 +52,9 @@ public: // JavaInstance implementation virtual JavaClass* getClass() const; - virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args); +// ANDROID + virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args, bool& didRaiseUncaughtException); +// END ANDROID virtual JavaValue getField(const JavaField*); virtual void begin(); virtual void end(); diff --git a/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h b/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h index 7436de7..5a1960a 100644 --- a/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h +++ b/Source/WebCore/bridge/jni/v8/JavaInstanceV8.h @@ -49,7 +49,9 @@ public: virtual JavaClass* getClass() const = 0; // args must be an array of length greater than or equal to the number of // arguments expected by the method. - virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args) = 0; +// ANDROID + virtual JavaValue invokeMethod(const JavaMethod*, JavaValue* args, bool& didRaiseUncaughtException) = 0; +// END ANDROID virtual JavaValue getField(const JavaField*) = 0; // These functions are called before and after the main entry points into diff --git a/Source/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp b/Source/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp index b22d57f..784ea01 100644 --- a/Source/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp +++ b/Source/WebCore/bridge/jni/v8/JavaNPObjectV8.cpp @@ -146,10 +146,16 @@ bool JavaNPObjectInvoke(NPObject* obj, NPIdentifier identifier, const NPVariant* for (unsigned int i = 0; i < argCount; i++) jArgs[i] = convertNPVariantToJavaValue(args[i], jMethod->parameterAt(i)); - JavaValue jResult = instance->invokeMethod(jMethod, jArgs); +// ANDROID + bool exceptionOccurred; + JavaValue jResult = instance->invokeMethod(jMethod, jArgs, exceptionOccurred); instance->end(); delete[] jArgs; + if (exceptionOccurred) + return false; +// END ANDROID + VOID_TO_NPVARIANT(*result); convertJavaValueToNPVariant(jResult, result); return true; |