diff options
author | Steve Block <steveblock@google.com> | 2011-09-01 12:08:57 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-09-02 13:07:23 +0100 |
commit | 70a54261052a5a78a33b5b91d4f3ab699b55e2ef (patch) | |
tree | 9e67f3aa8c057ce4971736e8bee5eb3f90898f09 /Source/WebCore/bridge/jni/v8 | |
parent | 24a08199b7204cfa19c1f61d93ea8df86d3bb99f (diff) | |
download | external_webkit-70a54261052a5a78a33b5b91d4f3ab699b55e2ef.zip external_webkit-70a54261052a5a78a33b5b91d4f3ab699b55e2ef.tar.gz external_webkit-70a54261052a5a78a33b5b91d4f3ab699b55e2ef.tar.bz2 |
Fix the Java bridge to correctly handle null strings
Passing null to methods expecting java/lang/String ...
- Previously null was converted to the empty string but should be
converted to Java null.
- convertNPVariantToJavaValue() already converts a null NPVariant to a
null WTF::String.
- Fixed javaValueToJvalue() to convert a null WTF::String to a null
jvalue.
Returning null from a method with return type java/lang/String ...
- Previously this would crash when trying to get the characters from
the null jstring, but should return JavaScript undefined.
- Fixed jvalueToJavaValue() to convert a null jvalue to a null
WTF::String.
- Fixed convertJavaValueToNPVariant() to convert a null WTF::String to
a void NPVariant.
Both of these are regressions from HC due to
http://trac.webkit.org/changeset/82194.
Added tests in https://android-git.corp.google.com/g/#/c/132580
Bug: 5222742
Change-Id: Id08bc7b40a51426fa7638ad0ed5260d09f3e28bb
Diffstat (limited to 'Source/WebCore/bridge/jni/v8')
-rw-r--r-- | Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp index 0d1a9f2..47b88d6 100644 --- a/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp +++ b/Source/WebCore/bridge/jni/v8/JNIUtilityPrivate.cpp @@ -352,6 +352,13 @@ void convertJavaValueToNPVariant(JavaValue value, NPVariant* result) case JavaTypeString: { +#if PLATFORM(ANDROID) + // This entire file will likely be removed usptream soon. + if (value.m_stringValue.isNull()) { + VOID_TO_NPVARIANT(*result); + break; + } +#endif const char* utf8String = strdup(value.m_stringValue.utf8().data()); // The copied string is freed in NPN_ReleaseVariantValue (see npruntime.cpp) STRINGZ_TO_NPVARIANT(utf8String, *result); @@ -429,6 +436,10 @@ JavaValue jvalueToJavaValue(const jvalue& value, const JavaType& type) case JavaTypeString: { jstring javaString = static_cast<jstring>(value.l); + if (!javaString) { + // result.m_stringValue is null by default + break; + } const UChar* characters = getUCharactersFromJStringInEnv(getJNIEnv(), javaString); // We take a copy to allow the Java String to be released. result.m_stringValue = String(characters, getJNIEnv()->GetStringLength(javaString)); @@ -487,6 +498,10 @@ jvalue javaValueToJvalue(const JavaValue& value) // be released when the call stack returns to Java. Note that this // may cause leaks if invoked from a native message loop, as is the // case in workers. + if (value.m_stringValue.isNull()) { + // result.l is null by default. + break; + } result.l = getJNIEnv()->NewString(value.m_stringValue.characters(), value.m_stringValue.length()); break; case JavaTypeBoolean: |