зеркало из https://github.com/mozilla/gecko-dev.git
Bug 992359 - b. Add skeletal NativeJSObject.toBundle; r=blassey
This commit is contained in:
Родитель
6869b0b792
Коммит
3a91fe28bb
|
@ -7,6 +7,8 @@ package org.mozilla.gecko.util;
|
|||
|
||||
import org.mozilla.gecko.mozglue.JNITarget;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
/**
|
||||
* NativeJSObject is a wrapper around the SpiderMonkey JSAPI to make it possible to
|
||||
* access Javascript objects in Java.
|
||||
|
@ -61,6 +63,40 @@ public class NativeJSObject
|
|||
*/
|
||||
public native boolean optBoolean(String name, boolean fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of an object property as a Bundle.
|
||||
*
|
||||
* @param name
|
||||
* Property name
|
||||
* @throws IllegalArgumentException
|
||||
* If the property does not exist or if 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 Bundle getBundle(String name);
|
||||
|
||||
/**
|
||||
* Returns the value of an object property as a Bundle.
|
||||
*
|
||||
* @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 Bundle optBundle(String name, Bundle fallback);
|
||||
|
||||
/**
|
||||
* Returns the value of a double property.
|
||||
*
|
||||
|
@ -211,6 +247,18 @@ public class NativeJSObject
|
|||
*/
|
||||
public native boolean has(String name);
|
||||
|
||||
/**
|
||||
* Returns the Bundle representation of this object.
|
||||
*
|
||||
* @throws NullPointerException
|
||||
* 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 Bundle toBundle();
|
||||
|
||||
/**
|
||||
* Returns the JSON representation of this object.
|
||||
*
|
||||
|
|
|
@ -647,6 +647,44 @@ Java_org_mozilla_gecko_util_NativeJSObject_optBoolean(JNIEnv * arg0, jobject arg
|
|||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jobject (*Java_org_mozilla_gecko_util_NativeJSObject_getBundle_t)(JNIEnv *, jobject, jstring);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_getBundle_t f_Java_org_mozilla_gecko_util_NativeJSObject_getBundle;
|
||||
extern "C" NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getBundle(JNIEnv * arg0, jobject arg1, jstring arg2) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_getBundle) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return nullptr;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_getBundle(arg0, arg1, arg2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_getBundle", &f_Java_org_mozilla_gecko_util_NativeJSObject_getBundle);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jobject (*Java_org_mozilla_gecko_util_NativeJSObject_optBundle_t)(JNIEnv *, jobject, jstring, jobject);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_optBundle_t f_Java_org_mozilla_gecko_util_NativeJSObject_optBundle;
|
||||
extern "C" NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optBundle(JNIEnv * arg0, jobject arg1, jstring arg2, jobject arg3) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_optBundle) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return nullptr;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_optBundle(arg0, arg1, arg2, arg3);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_optBundle", &f_Java_org_mozilla_gecko_util_NativeJSObject_optBundle);
|
||||
#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
|
||||
|
@ -818,6 +856,25 @@ Java_org_mozilla_gecko_util_NativeJSObject_has(JNIEnv * arg0, jobject arg1, jstr
|
|||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jobject (*Java_org_mozilla_gecko_util_NativeJSObject_toBundle_t)(JNIEnv *, jobject);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_toBundle_t f_Java_org_mozilla_gecko_util_NativeJSObject_toBundle;
|
||||
extern "C" NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_toBundle(JNIEnv * arg0, jobject arg1) {
|
||||
if (!f_Java_org_mozilla_gecko_util_NativeJSObject_toBundle) {
|
||||
arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"),
|
||||
"JNI Function called before it was loaded");
|
||||
return nullptr;
|
||||
}
|
||||
return f_Java_org_mozilla_gecko_util_NativeJSObject_toBundle(arg0, arg1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef JNI_BINDINGS
|
||||
xul_dlsym("Java_org_mozilla_gecko_util_NativeJSObject_toBundle", &f_Java_org_mozilla_gecko_util_NativeJSObject_toBundle);
|
||||
#endif
|
||||
|
||||
#ifdef JNI_STUBS
|
||||
|
||||
typedef jstring (*Java_org_mozilla_gecko_util_NativeJSObject_toString_t)(JNIEnv *, jobject);
|
||||
static Java_org_mozilla_gecko_util_NativeJSObject_toString_t f_Java_org_mozilla_gecko_util_NativeJSObject_toString;
|
||||
extern "C" NS_EXPORT jstring JNICALL
|
||||
|
|
|
@ -135,6 +135,7 @@ public:
|
|||
}
|
||||
|
||||
static jobject CreateObjectInstance(JNIEnv* env, jobject object,
|
||||
JSContext* cx,
|
||||
JS::HandleObject jsObject) {
|
||||
MOZ_ASSERT(object);
|
||||
MOZ_ASSERT(jsObject);
|
||||
|
@ -378,7 +379,9 @@ struct StringProperty
|
|||
}
|
||||
};
|
||||
|
||||
struct ObjectProperty
|
||||
template <jobject (*FactoryMethod)
|
||||
(JNIEnv*, jobject, JSContext*, JS::HandleObject)>
|
||||
struct BaseObjectProperty
|
||||
{
|
||||
typedef jobject Type;
|
||||
|
||||
|
@ -392,10 +395,19 @@ struct ObjectProperty
|
|||
return nullptr;
|
||||
}
|
||||
JS::RootedObject object(cx, &val.toObject());
|
||||
return NativeJSContainer::CreateObjectInstance(env, instance, object);
|
||||
return FactoryMethod(env, instance, cx, object);
|
||||
}
|
||||
};
|
||||
|
||||
jobject GetBundle(JNIEnv*, jobject, JSContext*, JS::HandleObject);
|
||||
|
||||
// Returns a NativeJSObject from a JSObject
|
||||
typedef BaseObjectProperty<
|
||||
NativeJSContainer::CreateObjectInstance> ObjectProperty;
|
||||
|
||||
// Returns a Bundle from a JSObject
|
||||
typedef BaseObjectProperty<GetBundle> BundleProperty;
|
||||
|
||||
struct HasProperty
|
||||
{
|
||||
typedef jboolean Type;
|
||||
|
@ -453,6 +465,13 @@ GetProperty(JNIEnv* env, jobject instance, jstring name,
|
|||
return Property::FromValue(env, instance, cx, val);
|
||||
}
|
||||
|
||||
jobject
|
||||
GetBundle(JNIEnv* env, jobject instance, JSContext* cx, JS::HandleObject obj)
|
||||
{
|
||||
// TODO: add implementation
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
@ -484,6 +503,19 @@ Java_org_mozilla_gecko_util_NativeJSObject_optBoolean(JNIEnv* env, jobject insta
|
|||
return GetProperty<BooleanProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getBundle(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
return GetProperty<BundleProperty>(env, instance, name);
|
||||
}
|
||||
|
||||
NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_optBundle(JNIEnv* env, jobject instance,
|
||||
jstring name, jobject fallback)
|
||||
{
|
||||
return GetProperty<BundleProperty>(env, instance, name, FallbackOption::RETURN, fallback);
|
||||
}
|
||||
|
||||
NS_EXPORT jdouble JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_getDouble(JNIEnv* env, jobject instance, jstring name)
|
||||
{
|
||||
|
@ -542,6 +574,20 @@ Java_org_mozilla_gecko_util_NativeJSObject_has(JNIEnv* env, jobject instance, js
|
|||
return GetProperty<HasProperty>(env, instance, name, FallbackOption::RETURN, JNI_FALSE);
|
||||
}
|
||||
|
||||
NS_EXPORT jobject JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_toBundle(JNIEnv* env, jobject instance)
|
||||
{
|
||||
MOZ_ASSERT(env);
|
||||
MOZ_ASSERT(instance);
|
||||
|
||||
JSContext* const cx = NativeJSContainer::GetContextFromObject(env, instance);
|
||||
const JS::RootedObject object(cx, NativeJSContainer::GetObjectFromObject(env, instance));
|
||||
if (!object) {
|
||||
return nullptr;
|
||||
}
|
||||
return GetBundle(env, instance, cx, object);
|
||||
}
|
||||
|
||||
NS_EXPORT jstring JNICALL
|
||||
Java_org_mozilla_gecko_util_NativeJSObject_toString(JNIEnv* env, jobject instance)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче