From 5f1f309ebaf150da711c6562c86425efcb797d38 Mon Sep 17 00:00:00 2001 From: Grant Gayed Date: Fri, 25 Jan 2013 08:42:00 -0500 Subject: Bug 398070 - BrowserFunction not converting correctly boolean arrays with XULRunner 10 --- .../Eclipse SWT Mozilla/common/library/xpcom.cpp | 27 +++++++++++++++++++++- .../common/library/xpcom_stats.cpp | 7 +++++- .../common/library/xpcom_stats.h | 7 +++++- .../common/org/eclipse/swt/browser/External.java | 13 ++++++++--- .../org/eclipse/swt/internal/mozilla/XPCOM.java | 9 ++++++++ .../eclipse/swt/internal/mozilla/nsIVariant.java | 7 ++++++ .../swt/internal/mozilla/nsIWritableVariant.java | 4 ++++ 7 files changed, 68 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp index b3db8282e1..026e178742 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -213,6 +213,31 @@ JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IJ)(JNIEnv *env, jclass that, ji } #endif +#if (!defined(NO__1VtblCall__IIB) && !defined(JNI64)) || (!defined(NO__1VtblCall__IJB) && defined(JNI64)) +#ifndef JNI64 +extern "C" JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IIB)(JNIEnv *env, jclass that, jint arg0, jintLong arg1, jbyte arg2); +JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IIB)(JNIEnv *env, jclass that, jint arg0, jintLong arg1, jbyte arg2) +#else +extern "C" JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IJB)(JNIEnv *env, jclass that, jint arg0, jintLong arg1, jbyte arg2); +JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IJB)(JNIEnv *env, jclass that, jint arg0, jintLong arg1, jbyte arg2) +#endif +{ + jint rc = 0; +#ifndef JNI64 + XPCOM_NATIVE_ENTER(env, that, _1VtblCall__IIB_FUNC); +#else + XPCOM_NATIVE_ENTER(env, that, _1VtblCall__IJB_FUNC); +#endif + rc = (jint)((jint (STDMETHODCALLTYPE *)(jintLong, jbyte))(*(jintLong **)arg1)[arg0])(arg1, arg2); +#ifndef JNI64 + XPCOM_NATIVE_EXIT(env, that, _1VtblCall__IIB_FUNC); +#else + XPCOM_NATIVE_EXIT(env, that, _1VtblCall__IJB_FUNC); +#endif + return rc; +} +#endif + #if (!defined(NO__1VtblCall__IID) && !defined(JNI64)) || (!defined(NO__1VtblCall__IJD) && defined(JNI64)) #ifndef JNI64 extern "C" JNIEXPORT jint JNICALL XPCOM_NATIVE(_1VtblCall__IID)(JNIEnv *env, jclass that, jint arg0, jintLong arg1, jdouble arg2); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp index c8b5b7cebd..c51c1689e3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -50,6 +50,11 @@ char * XPCOM_nativeFunctionNames[] = { #else "_1VtblCall__IJ", #endif +#ifndef JNI64 + "_1VtblCall__IIB", +#else + "_1VtblCall__IJB", +#endif #ifndef JNI64 "_1VtblCall__IID", #else diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h index b47b3aecc0..ff1e3a0e5a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 IBM Corporation and others. + * Copyright (c) 2000, 2013 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -60,6 +60,11 @@ typedef enum { #else _1VtblCall__IJ_FUNC, #endif +#ifndef JNI64 + _1VtblCall__IIB_FUNC, +#else + _1VtblCall__IJB_FUNC, +#endif #ifndef JNI64 _1VtblCall__IID_FUNC, #else diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java index c4087df868..4ac867ba02 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/browser/External.java @@ -251,9 +251,16 @@ static Object convertToJava (nsIVariant variant, short type) { case nsIDataType.VTYPE_BOOL: arrayReturn = new Object[count[0]]; for (int i = 0; i < count[0]; i++) { - int[] boolValue = new int[1]; /* PRUInt32 */ - C.memmove (boolValue, ptr[0] + i * 4, 4); - arrayReturn[i] = new Boolean (boolValue[0] != 0); + /* mozilla's representation of boolean changed from 4 bytes to 1 byte as of XULRunner 4.x */ + if (nsISupports.IsXULRunner10) { + byte[] byteValue = new byte[1]; + C.memmove (byteValue, ptr[0] + i, 1); + arrayReturn[i] = new Boolean (byteValue[0] != 0); + } else { + int[] boolValue = new int[1]; /* PRUInt32 */ + C.memmove (boolValue, ptr[0] + i * 4, 4); + arrayReturn[i] = new Boolean (boolValue[0] != 0); + } } break; case nsIDataType.VTYPE_INT32: diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java index 1b29b85eee..b5c7f2751a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/XPCOM.java @@ -643,6 +643,15 @@ static final int VtblCall(int fnNumber, long /*int*/ ppVtbl) { } } +static final native int _VtblCall(int fnNumber, long /*int*/ ppVtbl, byte arg0); +static final int VtblCall(int fnNumber, long /*int*/ ppVtbl, byte arg0) { + lock.lock(); + try { + return _VtblCall(fnNumber, ppVtbl, arg0); + } finally { + lock.unlock(); + } +} static final native int _VtblCall(int fnNumber, long /*int*/ ppVtbl, byte[] arg0); static final int VtblCall(int fnNumber, long /*int*/ ppVtbl, byte[] arg0) { lock.lock(); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIVariant.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIVariant.java index 07b3525ecd..36ea2a2915 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIVariant.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIVariant.java @@ -92,6 +92,13 @@ public class nsIVariant extends nsISupports { } public int GetAsBool(int[] _retval) { + /* mozilla's representation of boolean changed from 4 bytes to 1 byte as of XULRunner 4.x */ + if (nsISupports.IsXULRunner10) { + byte[] byteValue = new byte[1]; + int rc = XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 12, getAddress(), byteValue); + _retval[0] = (int)byteValue[0]; + return rc; + } return XPCOM.VtblCall(nsISupports.LAST_METHOD_ID + 12, getAddress(), _retval); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWritableVariant.java b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWritableVariant.java index 2ccd6283a1..59b5008028 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWritableVariant.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/org/eclipse/swt/internal/mozilla/nsIWritableVariant.java @@ -90,6 +90,10 @@ public class nsIWritableVariant extends nsIVariant { } public int SetAsBool(int aValue) { + /* mozilla's representation of boolean changed from 4 bytes to 1 byte as of XULRunner 4.x */ + if (IsXULRunner10) { + return XPCOM.VtblCall(nsIVariant.LAST_METHOD_ID + 13, getAddress(), (byte)aValue); + } return XPCOM.VtblCall(nsIVariant.LAST_METHOD_ID + 13, getAddress(), aValue); } -- cgit v1.2.3