mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 984458 - f. Add NativeJSObject opt getters; r=blassey
This commit is contained in:
parent
7e177c1c5f
commit
08b3ed07e3
@ -43,6 +43,24 @@ public class NativeJSObject
|
||||
*/
|
||||
public native boolean getBoolean(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of a boolean property.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @param fallback
|
||||
* Value to return if property does not exist
|
||||
* @throws IllegalArgumentException
|
||||
* If the property exists and its type does not match the return type
|
||||
* @throws NullPointerException
|
||||
* If name is null or if this JS object has been disposed
|
||||
* @throws IllegalThreadStateException
|
||||
* If not called on the thread this object is attached to
|
||||
* @throws UnsupportedOperationException
|
||||
* If an internal JSAPI call failed
|
||||
*/
|
||||
public native boolean optBoolean(String name, boolean fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of a double property.
|
||||
*
|
||||
@ -59,6 +77,24 @@ public class NativeJSObject
|
||||
*/
|
||||
public native double getDouble(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of a double property.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @param fallback
|
||||
* Value to return if property does not exist
|
||||
* @throws IllegalArgumentException
|
||||
* If the property exists and its type does not match the return type
|
||||
* @throws NullPointerException
|
||||
* If name is null or if this JS object has been disposed
|
||||
* @throws IllegalThreadStateException
|
||||
* If not called on the thread this object is attached to
|
||||
* @throws UnsupportedOperationException
|
||||
* If an internal JSAPI call failed
|
||||
*/
|
||||
public native double optDouble(String name, double fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of an int property.
|
||||
*
|
||||
@ -75,6 +111,24 @@ public class NativeJSObject
|
||||
*/
|
||||
public native int getInt(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of an int property.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @param fallback
|
||||
* Value to return if property does not exist
|
||||
* @throws IllegalArgumentException
|
||||
* If the property exists and its type does not match the return type
|
||||
* @throws NullPointerException
|
||||
* If name is null or if this JS object has been disposed
|
||||
* @throws IllegalThreadStateException
|
||||
* If not called on the thread this object is attached to
|
||||
* @throws UnsupportedOperationException
|
||||
* If an internal JSAPI call failed
|
||||
*/
|
||||
public native int optInt(String name, int fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of an object property.
|
||||
*
|
||||
@ -91,6 +145,24 @@ public class NativeJSObject
|
||||
*/
|
||||
public native NativeJSObject getObject(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of an object property.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @param fallback
|
||||
* Value to return if property does not exist
|
||||
* @throws IllegalArgumentException
|
||||
* If the property exists and its type does not match the return type
|
||||
* @throws NullPointerException
|
||||
* If name is null or if this JS object has been disposed
|
||||
* @throws IllegalThreadStateException
|
||||
* If not called on the thread this object is attached to
|
||||
* @throws UnsupportedOperationException
|
||||
* If an internal JSAPI call failed
|
||||
*/
|
||||
public native NativeJSObject optObject(String name, NativeJSObject fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of a string property.
|
||||
*
|
||||
@ -107,6 +179,24 @@ public class NativeJSObject
|
||||
*/
|
||||
public native String getString(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of a string property.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @param fallback
|
||||
* Value to return if property does not exist
|
||||
* @throws IllegalArgumentException
|
||||
* If the property exists and its type does not match the return type
|
||||
* @throws NullPointerException
|
||||
* If name is null or if this JS object has been disposed
|
||||
* @throws IllegalThreadStateException
|
||||
* If not called on the thread this object is attached to
|
||||
* @throws UnsupportedOperationException
|
||||
* If an internal JSAPI call failed
|
||||
*/
|
||||
public native String optString(String name, String fallback);
|
||||
|
||||
/**
|
||||
* Returns whether a property exists in this object
|
||||
*
|
||||
|
@ -628,6 +628,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_getBoolean(JNIEnv * arg0, jobject arg
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jboolean (*Java_org_mozilla_gecko_util_NativeJSObject_optBoolean_t)(JNIEnv *, jobject, jstring, jboolean);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optBoolean_t f_Java_org_mozilla_gecko_util_NativeJSObject_optBoolean;
|
||||
extern "C" NS_EXPORT jboolean JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optBoolean(JNIEnv * arg0, jobject arg1, jstring arg2, jboolean arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optBoolean) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return false;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optBoolean(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optBoolean", &f_Java_org_mozilla_gecko_util_NativeJSObject_optBoolean);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jdouble (*Java_org_mozilla_gecko_util_NativeJSObject_getDouble_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_getDouble_t f_Java_org_mozilla_gecko_util_NativeJSObject_getDouble;
|
||||
extern "C" NS_EXPORT jdouble JNICALL
|
||||
@ -647,6 +666,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_getDouble(JNIEnv * arg0, jobject arg1
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jdouble (*Java_org_mozilla_gecko_util_NativeJSObject_optDouble_t)(JNIEnv *, jobject, jstring, jdouble);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optDouble_t f_Java_org_mozilla_gecko_util_NativeJSObject_optDouble;
|
||||
extern "C" NS_EXPORT jdouble JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optDouble(JNIEnv * arg0, jobject arg1, jstring arg2, jdouble arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optDouble) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return 0;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optDouble(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optDouble", &f_Java_org_mozilla_gecko_util_NativeJSObject_optDouble);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jint (*Java_org_mozilla_gecko_util_NativeJSObject_getInt_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_getInt_t f_Java_org_mozilla_gecko_util_NativeJSObject_getInt;
|
||||
extern "C" NS_EXPORT jint JNICALL
|
||||
@ -666,6 +704,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_getInt(JNIEnv * arg0, jobject arg1, j
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jint (*Java_org_mozilla_gecko_util_NativeJSObject_optInt_t)(JNIEnv *, jobject, jstring, jint);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optInt_t f_Java_org_mozilla_gecko_util_NativeJSObject_optInt;
|
||||
extern "C" NS_EXPORT jint JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optInt(JNIEnv * arg0, jobject arg1, jstring arg2, jint arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optInt) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return 0;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optInt(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optInt", &f_Java_org_mozilla_gecko_util_NativeJSObject_optInt);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jobject (*Java_org_mozilla_gecko_util_NativeJSObject_getObject_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_getObject_t f_Java_org_mozilla_gecko_util_NativeJSObject_getObject;
|
||||
extern "C" NS_EXPORT jobject JNICALL
|
||||
@ -685,6 +742,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_getObject(JNIEnv * arg0, jobject arg1
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jobject (*Java_org_mozilla_gecko_util_NativeJSObject_optObject_t)(JNIEnv *, jobject, jstring, jobject);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optObject_t f_Java_org_mozilla_gecko_util_NativeJSObject_optObject;
|
||||
extern "C" NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optObject(JNIEnv * arg0, jobject arg1, jstring arg2, jobject arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optObject) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return nullptr;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optObject(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optObject", &f_Java_org_mozilla_gecko_util_NativeJSObject_optObject);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jstring (*Java_org_mozilla_gecko_util_NativeJSObject_getString_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_getString_t f_Java_org_mozilla_gecko_util_NativeJSObject_getString;
|
||||
extern "C" NS_EXPORT jstring JNICALL
|
||||
@ -704,6 +780,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_getString(JNIEnv * arg0, jobject arg1
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jstring (*Java_org_mozilla_gecko_util_NativeJSObject_optString_t)(JNIEnv *, jobject, jstring, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optString_t f_Java_org_mozilla_gecko_util_NativeJSObject_optString;
|
||||
extern "C" NS_EXPORT jstring JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optString(JNIEnv * arg0, jobject arg1, jstring arg2, jstring arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optString) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return nullptr;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optString(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optString", &f_Java_org_mozilla_gecko_util_NativeJSObject_optString);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jboolean (*Java_org_mozilla_gecko_util_NativeJSObject_has_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_has_t f_Java_org_mozilla_gecko_util_NativeJSObject_has;
|
||||
extern "C" NS_EXPORT jboolean JNICALL
|
||||
|
@ -406,13 +406,20 @@ struct HasProperty
|
||||
|
||||
static Type FromValue(JNIEnv* env, jobject instance,
|
||||
JSContext* cx, JS::HandleValue val) {
|
||||
return JSVAL_IS_VOID(val) ? JNI_TRUE : JNI_FALSE;
|
||||
return JNI_TRUE;
|
||||
}
|
||||
};
|
||||
|
||||
MOZ_BEGIN_ENUM_CLASS(FallbackOption)
|
||||
THROW,
|
||||
RETURN,
|
||||
MOZ_END_ENUM_CLASS(FallbackOption)
|
||||
|
||||
template <class Property>
|
||||
typename Property::Type
|
||||
GetProperty(JNIEnv* env, jobject instance, jstring name) {
|
||||
GetProperty(JNIEnv* env, jobject instance, jstring name,
|
||||
FallbackOption option = FallbackOption::THROW,
|
||||
typename Property::Type fallback = typename Property::Type()) {
|
||||
MOZ_ASSERT(env);
|
||||
MOZ_ASSERT(instance);
|
||||
|
||||
@ -429,11 +436,19 @@ GetProperty(JNIEnv* env, jobject instance, jstring name) {
|
||||
JS_GetUCProperty(cx, object, strName, strName.Length(), &val))) {
|
||||
return typename Property::Type();
|
||||
}
|
||||
if (val.isUndefined()) {
|
||||
if (option == FallbackOption::THROW) {
|
||||
AndroidBridge::ThrowException(env,
|
||||
"java/lang/IllegalArgumentException",
|
||||
"Property does not exist");
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
if (!Property::InValue(val)) {
|
||||
AndroidBridge::ThrowException(env,
|
||||
"java/lang/IllegalArgumentException",
|
||||
"Property does not exist or type mismatch");
|
||||
return typename Property::Type();
|
||||
"Property type mismatch");
|
||||
return fallback;
|
||||
}
|
||||
return Property::FromValue(env, instance, cx, val);
|
||||
}
|
||||
@ -462,34 +477,69 @@ Java_org_mozilla_gecko_util_NativeJSObject_getBoolean(JNIEnv* env, jobject insta
|
||||
return GetProperty<BooleanProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jboolean JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optBoolean(JNIEnv* env, jobject instance,
|
||||
jstring name, jboolean fallback)
|
||||
{
|
||||
return GetProperty<BooleanProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jdouble JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getDouble(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<DoubleProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jdouble JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optDouble(JNIEnv* env, jobject instance,
|
||||
jstring name, jdouble fallback)
|
||||
{
|
||||
return GetProperty<DoubleProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jint JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getInt(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<IntProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jint JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optInt(JNIEnv* env, jobject instance,
|
||||
jstring name, jint fallback)
|
||||
{
|
||||
return GetProperty<IntProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getObject(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<ObjectProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optObject(JNIEnv* env, jobject instance,
|
||||
jstring name, jobject fallback)
|
||||
{
|
||||
return GetProperty<ObjectProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jstring JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getString(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<StringProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jstring JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optString(JNIEnv* env, jobject instance,
|
||||
jstring name, jstring fallback)
|
||||
{
|
||||
return GetProperty<StringProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jboolean JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_has(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<HasProperty>(env, instance, name);
|
||||
return GetProperty<HasProperty>(env, instance, name, FallbackOption::RETURN, JNI_FALSE);
|
||||
}
|
||||
|
||||
NS_EXPORT jstring JNICALL
|
||||
|
Loading…
Reference in New Issue
Block a user