[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
rjw
rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:14:29 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 9298c6b84fbb69f55ae6254b44ef3a01c2d40fc6
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Nov 21 03:13:52 2003 +0000
JavaScriptCore:
More LiveConnect stuff. Primitive Java fields are now
accessible from JavaScript! Yay!
Reviewed by Maciej.
* bindings/jni/jni_class.cpp:
(JavaClass::methodNamed):
(JavaClass::fieldNamed):
* bindings/jni/jni_class.h:
(Bindings::JavaClass::_commonDelete):
* bindings/jni/jni_instance.cpp:
(JavaInstance::JavaInstance):
(JavaInstance::~JavaInstance):
(JavaInstance::getClass):
* bindings/jni/jni_instance.h:
(Bindings::JavaInstance::javaInstance):
* bindings/jni/jni_runtime.cpp:
(JavaField::JavaField):
(JavaField::valueFromInstance):
* bindings/jni/jni_runtime.h:
(Bindings::JavaField::JavaField):
(Bindings::JavaField::~JavaField):
(Bindings::JavaField::operator=):
* bindings/jni/jni_utility.cpp:
(callJNIMethod):
(callJNIMethodA):
(callJNIVoidMethod):
(callJNIObjectMethod):
(callJNIBooleanMethod):
(callJNIByteMethod):
(callJNICharMethod):
(callJNIShortMethod):
(callJNIIntMethod):
(callJNILongMethod):
(callJNIFloatMethod):
(callJNIDoubleMethod):
(callJNIVoidMethodA):
(callJNIObjectMethodA):
(callJNIByteMethodA):
(callJNICharMethodA):
(callJNIShortMethodA):
(callJNIIntMethodA):
(callJNILongMethodA):
(callJNIFloatMethodA):
(callJNIDoubleMethodA):
(releaseCharactersForJStringInEnv):
(primitiveTypeFromClassName):
(getJNIField):
* bindings/jni/jni_utility.h:
* bindings/runtime.cpp:
(Instance::createBindingForLanguageInstance):
(Instance::getValueOfField):
* bindings/runtime.h:
* bindings/runtime_object.cpp:
(RuntimeObjectImp::get):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5616 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 627348b..9767da5 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,63 @@
2003-11-20 Richard Williamson <rjw at apple.com>
+ More LiveConnect stuff. Primitive Java fields are now
+ accessible from JavaScript! Yay!
+
+ Reviewed by Maciej.
+
+ * bindings/jni/jni_class.cpp:
+ (JavaClass::methodNamed):
+ (JavaClass::fieldNamed):
+ * bindings/jni/jni_class.h:
+ (Bindings::JavaClass::_commonDelete):
+ * bindings/jni/jni_instance.cpp:
+ (JavaInstance::JavaInstance):
+ (JavaInstance::~JavaInstance):
+ (JavaInstance::getClass):
+ * bindings/jni/jni_instance.h:
+ (Bindings::JavaInstance::javaInstance):
+ * bindings/jni/jni_runtime.cpp:
+ (JavaField::JavaField):
+ (JavaField::valueFromInstance):
+ * bindings/jni/jni_runtime.h:
+ (Bindings::JavaField::JavaField):
+ (Bindings::JavaField::~JavaField):
+ (Bindings::JavaField::operator=):
+ * bindings/jni/jni_utility.cpp:
+ (callJNIMethod):
+ (callJNIMethodA):
+ (callJNIVoidMethod):
+ (callJNIObjectMethod):
+ (callJNIBooleanMethod):
+ (callJNIByteMethod):
+ (callJNICharMethod):
+ (callJNIShortMethod):
+ (callJNIIntMethod):
+ (callJNILongMethod):
+ (callJNIFloatMethod):
+ (callJNIDoubleMethod):
+ (callJNIVoidMethodA):
+ (callJNIObjectMethodA):
+ (callJNIByteMethodA):
+ (callJNICharMethodA):
+ (callJNIShortMethodA):
+ (callJNIIntMethodA):
+ (callJNILongMethodA):
+ (callJNIFloatMethodA):
+ (callJNIDoubleMethodA):
+ (releaseCharactersForJStringInEnv):
+ (primitiveTypeFromClassName):
+ (getJNIField):
+ * bindings/jni/jni_utility.h:
+ * bindings/runtime.cpp:
+ (Instance::createBindingForLanguageInstance):
+ (Instance::getValueOfField):
+ * bindings/runtime.h:
+ * bindings/runtime_object.cpp:
+ (RuntimeObjectImp::get):
+
+2003-11-20 Richard Williamson <rjw at apple.com>
+
More LiveConnect stuff.
Reviewed by Chris.
diff --git a/JavaScriptCore/bindings/jni/jni_class.cpp b/JavaScriptCore/bindings/jni/jni_class.cpp
index e932eb7..bfd200c 100644
--- a/JavaScriptCore/bindings/jni/jni_class.cpp
+++ b/JavaScriptCore/bindings/jni/jni_class.cpp
@@ -135,14 +135,16 @@ JavaClass *JavaClass::classForInstance (jobject instance)
return aClass;
}
-Method *JavaClass::methodNamed(const char *name) const {
+Method *JavaClass::methodNamed(const char *name) const
+{
CFStringRef methodName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
Method *aMethod = (Method *)CFDictionaryGetValue(_methods, methodName);
CFRelease (methodName);
return aMethod;
};
-Field *JavaClass::fieldNamed(const char *name) const {
+Field *JavaClass::fieldNamed(const char *name) const
+{
CFStringRef fieldName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
Field *aField = (Field *)CFDictionaryGetValue(_fields, fieldName);
CFRelease (fieldName);
diff --git a/JavaScriptCore/bindings/jni/jni_class.h b/JavaScriptCore/bindings/jni/jni_class.h
index 8edcebc..1f858f7 100644
--- a/JavaScriptCore/bindings/jni/jni_class.h
+++ b/JavaScriptCore/bindings/jni/jni_class.h
@@ -29,12 +29,14 @@
#include <JavaVM/jni.h>
+#include <runtime.h>
#include <jni_runtime.h>
#include <runtime.h>
namespace Bindings {
+
class JavaClass : public Class
{
// Use the public static factory methods to get instances of JavaClass.
@@ -57,7 +59,7 @@ public:
free((void *)_name);
CFRelease (_fields);
CFRelease (_methods);
- delete _constructors;
+ delete [] _constructors;
}
~JavaClass () {
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index b673716..e9ce787 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -23,27 +23,30 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <jni_utility.h>
-#include <jni_runtime.h>
+#include <jni_class.h>
#include <jni_instance.h>
+#include <jni_runtime.h>
using namespace Bindings;
-JavaInstance::JavaInstance (jobject instance) {
+JavaInstance::JavaInstance (jobject instance)
+{
_instance = new JObjectWrapper (instance);
};
-JavaInstance::~JavaInstance () {
+JavaInstance::~JavaInstance ()
+{
_instance->deref();
}
-JavaInstance::JavaInstance (const JavaInstance &other) : Instance() {
+JavaInstance::JavaInstance (const JavaInstance &other) : Instance()
+{
_instance = other._instance;
_instance->ref();
};
-KJS::Value JavaInstance::getValueOfField (const Field *aField) const
+Class *JavaInstance::getClass() const
{
- return KJS::Value(0);
+ return JavaClass::classForInstance (_instance->_instance);
}
-
diff --git a/JavaScriptCore/bindings/jni/jni_instance.h b/JavaScriptCore/bindings/jni/jni_instance.h
index 654d5ae..dcd8be9 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.h
+++ b/JavaScriptCore/bindings/jni/jni_instance.h
@@ -29,13 +29,15 @@
#include <JavaVM/jni.h>
-#include <jni_runtime.h>
-#include <jni_utility.h>
-#include <jni_class.h>
+#include <runtime.h>
+
#include <jni_instance.h>
+#include <jni_utility.h>
namespace Bindings {
+class JavaClass;
+
class JObjectWrapper
{
friend class JavaInstance;
@@ -79,10 +81,8 @@ public:
~JavaInstance ();
- virtual Class *getClass() const {
- return JavaClass::classForInstance (_instance->_instance);
- }
-
+ virtual Class *getClass() const;
+
JavaInstance (const JavaInstance &other);
JavaInstance &operator=(const JavaInstance &other){
@@ -96,8 +96,8 @@ public:
return *this;
};
-
- virtual KJS::Value getValueOfField (const Field *aField) const;
+
+ jobject javaInstance() const { return _instance->_instance; }
private:
JObjectWrapper *_instance;
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index 824875d..e986dbb 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -22,23 +22,69 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <value.h>
+#include <internal.h>
+
#include <jni_utility.h>
#include <jni_runtime.h>
+using namespace KJS;
using namespace Bindings;
+
JavaField::JavaField (JNIEnv *env, jobject aField)
{
// Get field type
jobject fieldType = callJNIObjectMethod (aField, "getType", "()Ljava/lang/Class;");
jstring fieldTypeName = (jstring)callJNIObjectMethod (fieldType, "toString", "()Ljava/lang/String;");
_type = new JavaString(env, fieldTypeName);
+ _primitiveType = primitiveTypeFromClassName (_type->characters());
// Get field name
jstring fieldName = (jstring)callJNIObjectMethod (aField, "getName", "()Ljava/lang/String;");
_name = new JavaString(env, fieldName);
+
+ _field = new JavaInstance(aField);
}
+KJS::Value JavaField::valueFromInstance(const Instance *i) const
+{
+ const JavaInstance *instance = static_cast<const JavaInstance *>(i);
+ jobject jinstance = instance->javaInstance();
+ jobject fieldJInstance = _field->javaInstance();
+
+ switch (_primitiveType) {
+ case object_type: {
+ //jobject value = callJNIObjectMethod(_field->javaInstance(), "get", "(Ljava/lang/Object;)Ljava/lang/Object;", jinstace);
+ return KJS::Value(0);
+ }
+ break;
+
+ case boolean_type: {
+ jboolean value = callJNIBooleanMethod(fieldJInstance, "getBoolean", "(Ljava/lang/Object;)B", jinstance);
+ return KJS::Boolean((bool)value);
+ }
+ break;
+
+ case byte_type:
+ case char_type:
+ case short_type:
+ case int_type:
+ case long_type:
+ case float_type:
+ case double_type: {
+ jdouble value;
+ value = callJNIDoubleMethod(fieldJInstance, "getDouble", "(Ljava/lang/Object;)D", jinstance);
+ return Number((double)value);
+ }
+ break;
+ default:
+ break;
+ }
+ return Undefined();
+}
+
+
JavaConstructor::JavaConstructor (JNIEnv *env, jobject aConstructor)
{
// Get parameters
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 6e03f18..34ffa69 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -28,6 +28,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <jni_utility.h>
+#include <jni_instance.h>
#include <runtime.h>
namespace KJS
@@ -164,14 +165,16 @@ private:
class JavaField : public Field
{
public:
- JavaField() : _name(0), _type(0) {};
+ JavaField() : _name(0), _type(0), _field(0) {};
JavaField (JNIEnv *env, jobject aField);
~JavaField() {
delete _name;
delete _type;
+ delete _field;
};
- JavaField(const JavaField &other) : Field(), _name(other._name), _type(other._type) {};
+ JavaField(const JavaField &other) :
+ Field(), _name(other._name), _type(other._type), _field(other._field) {};
JavaField &operator=(const JavaField &other)
{
@@ -180,20 +183,25 @@ public:
delete _name;
delete _type;
+ delete _field;
_name = other._name;
_type = other._type;
+ _field = other._field;
return *this;
}
- virtual KJS::Value value() const { return KJS::Value(0); }
+ virtual KJS::Value valueFromInstance(const Instance *instance) const;
+
virtual const char *name() const { return _name->characters(); }
virtual RuntimeType type() const { return _type->characters(); }
private:
JavaString *_name;
JavaString *_type;
+ JNIType _primitiveType;
+ JavaInstance *_field;
};
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index d3a973f..452bca2 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -61,170 +61,128 @@ JNIEnv *getJNIEnv()
return NULL;
}
-
-static bool attachToJavaVM(JavaVM **jvm, JNIEnv **env)
+static jvalue callJNIMethod( JNIType type, jobject obj, const char *name, const char *sig, va_list args)
{
- JavaVM *jvmArray[1];
- jsize bufLen = 1;
- jsize nJVMs = 0;
- jint jniError = 0;
- bool attached = false;
-
- // if a JVM is already running ...
- jniError = JNI_GetCreatedJavaVMs(jvmArray, bufLen, &nJVMs);
- if ( jniError == JNI_OK )
- {
- // how many JVMs?
- if ( nJVMs > 0 )
- {
- // connect to the Java VM
- // there can be only one per process -- mhay 2002.09.30
- *jvm = jvmArray[0];
- jniError = (*jvm)->AttachCurrentThread((void**)env, (void *)NULL);
- if ( jniError == JNI_OK )
- attached = true;
- else
- fprintf(stderr, "%s: AttachCurrentThread failed, returned %d", __PRETTY_FUNCTION__, jniError);
- }
- }
- else
- fprintf(stderr, "%s: JNI_GetCreatedJavaVMs failed, returned %d", __PRETTY_FUNCTION__, jniError);
-
- return attached;
-}
-
-static jvalue callJNIMethod( JNIFunctionType type, jobject obj, const char *name, const char *sig, va_list args)
-{
- JavaVM *jvm = NULL;
- JNIEnv *env = NULL;
+ JavaVM *jvm = getJavaVM();
+ JNIEnv *env = getJNIEnv();
jvalue result;
- if ( obj != NULL ) {
- if ( attachToJavaVM(&jvm, &env) ) {
- jclass cls = env->GetObjectClass(obj);
- if ( cls != NULL ) {
- jmethodID mid = env->GetMethodID(cls, name, sig);
- if ( mid != NULL )
- {
- switch (type) {
- case void_function:
- env->functions->CallVoidMethodV(env, obj, mid, args);
- break;
- case object_function:
- result.l = env->functions->CallObjectMethodV(env, obj, mid, args);
- break;
- case boolean_function:
- result.z = env->functions->CallBooleanMethodV(env, obj, mid, args);
- break;
- case byte_function:
- result.b = env->functions->CallByteMethodV(env, obj, mid, args);
- break;
- case char_function:
- result.c = env->functions->CallCharMethodV(env, obj, mid, args);
- break;
- case short_function:
- result.s = env->functions->CallShortMethodV(env, obj, mid, args);
- break;
- case int_function:
- result.i = env->functions->CallIntMethodV(env, obj, mid, args);
- break;
- case long_function:
- result.j = env->functions->CallLongMethodV(env, obj, mid, args);
- break;
- case float_function:
- result.f = env->functions->CallFloatMethodV(env, obj, mid, args);
- break;
- case double_function:
- result.d = env->functions->CallDoubleMethodV(env, obj, mid, args);
- break;
- default:
- fprintf(stderr, "%s: invalid function type (%d)", __PRETTY_FUNCTION__, (int)type);
- }
- }
- else
- {
- fprintf(stderr, "%s: Could not find method: %s!", __PRETTY_FUNCTION__, name);
- env->ExceptionDescribe();
- env->ExceptionClear();
+ if ( obj != NULL && jvm != NULL && env != NULL) {
+ jclass cls = env->GetObjectClass(obj);
+ if ( cls != NULL ) {
+ jmethodID mid = env->GetMethodID(cls, name, sig);
+ if ( mid != NULL )
+ {
+ switch (type) {
+ case void_type:
+ env->functions->CallVoidMethodV(env, obj, mid, args);
+ break;
+ case object_type:
+ result.l = env->functions->CallObjectMethodV(env, obj, mid, args);
+ break;
+ case boolean_type:
+ result.z = env->functions->CallBooleanMethodV(env, obj, mid, args);
+ break;
+ case byte_type:
+ result.b = env->functions->CallByteMethodV(env, obj, mid, args);
+ break;
+ case char_type:
+ result.c = env->functions->CallCharMethodV(env, obj, mid, args);
+ break;
+ case short_type:
+ result.s = env->functions->CallShortMethodV(env, obj, mid, args);
+ break;
+ case int_type:
+ result.i = env->functions->CallIntMethodV(env, obj, mid, args);
+ break;
+ case long_type:
+ result.j = env->functions->CallLongMethodV(env, obj, mid, args);
+ break;
+ case float_type:
+ result.f = env->functions->CallFloatMethodV(env, obj, mid, args);
+ break;
+ case double_type:
+ result.d = env->functions->CallDoubleMethodV(env, obj, mid, args);
+ break;
+ default:
+ fprintf(stderr, "%s: invalid function type (%d)", __PRETTY_FUNCTION__, (int)type);
}
-
- env->DeleteLocalRef(cls);
}
- else {
- fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
+ else
+ {
+ fprintf(stderr, "%s: Could not find method: %s!", __PRETTY_FUNCTION__, name);
+ env->ExceptionDescribe();
+ env->ExceptionClear();
}
+
+ env->DeleteLocalRef(cls);
}
else {
- fprintf(stderr, "%s: Could not attach to the VM!", __PRETTY_FUNCTION__);
+ fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
}
}
return result;
}
-static jvalue callJNIMethodA( JNIFunctionType type, jobject obj, const char *name, const char *sig, jvalue *args)
+static jvalue callJNIMethodA( JNIType type, jobject obj, const char *name, const char *sig, jvalue *args)
{
- JavaVM *jvm = NULL;
- JNIEnv *env = NULL;
+ JavaVM *jvm = getJavaVM();
+ JNIEnv *env = getJNIEnv();
jvalue result;
- if ( obj != NULL ) {
- if ( attachToJavaVM(&jvm, &env) ) {
- jclass cls = env->GetObjectClass(obj);
- if ( cls != NULL ) {
- jmethodID mid = env->GetMethodID(cls, name, sig);
- if ( mid != NULL )
- {
- switch (type) {
- case void_function:
- env->functions->CallVoidMethodA(env, obj, mid, args);
- break;
- case object_function:
- result.l = env->functions->CallObjectMethodA(env, obj, mid, args);
- break;
- case boolean_function:
- result.z = env->functions->CallBooleanMethodA(env, obj, mid, args);
- break;
- case byte_function:
- result.b = env->functions->CallByteMethodA(env, obj, mid, args);
- break;
- case char_function:
- result.c = env->functions->CallCharMethodA(env, obj, mid, args);
- break;
- case short_function:
- result.s = env->functions->CallShortMethodA(env, obj, mid, args);
- break;
- case int_function:
- result.i = env->functions->CallIntMethodA(env, obj, mid, args);
- break;
- case long_function:
- result.j = env->functions->CallLongMethodA(env, obj, mid, args);
- break;
- case float_function:
- result.f = env->functions->CallFloatMethodA(env, obj, mid, args);
- break;
- case double_function:
- result.d = env->functions->CallDoubleMethodA(env, obj, mid, args);
- break;
- default:
- fprintf(stderr, "%s: invalid function type (%d)", __PRETTY_FUNCTION__, (int)type);
- }
- }
- else
- {
- fprintf(stderr, "%s: Could not find method: %s!", __PRETTY_FUNCTION__, name);
- env->ExceptionDescribe();
- env->ExceptionClear();
+ if ( obj != NULL && jvm != NULL && env != NULL) {
+ jclass cls = env->GetObjectClass(obj);
+ if ( cls != NULL ) {
+ jmethodID mid = env->GetMethodID(cls, name, sig);
+ if ( mid != NULL )
+ {
+ switch (type) {
+ case void_type:
+ env->functions->CallVoidMethodA(env, obj, mid, args);
+ break;
+ case object_type:
+ result.l = env->functions->CallObjectMethodA(env, obj, mid, args);
+ break;
+ case boolean_type:
+ result.z = env->functions->CallBooleanMethodA(env, obj, mid, args);
+ break;
+ case byte_type:
+ result.b = env->functions->CallByteMethodA(env, obj, mid, args);
+ break;
+ case char_type:
+ result.c = env->functions->CallCharMethodA(env, obj, mid, args);
+ break;
+ case short_type:
+ result.s = env->functions->CallShortMethodA(env, obj, mid, args);
+ break;
+ case int_type:
+ result.i = env->functions->CallIntMethodA(env, obj, mid, args);
+ break;
+ case long_type:
+ result.j = env->functions->CallLongMethodA(env, obj, mid, args);
+ break;
+ case float_type:
+ result.f = env->functions->CallFloatMethodA(env, obj, mid, args);
+ break;
+ case double_type:
+ result.d = env->functions->CallDoubleMethodA(env, obj, mid, args);
+ break;
+ default:
+ fprintf(stderr, "%s: invalid function type (%d)", __PRETTY_FUNCTION__, (int)type);
}
-
- env->DeleteLocalRef(cls);
}
- else {
- fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
+ else
+ {
+ fprintf(stderr, "%s: Could not find method: %s!", __PRETTY_FUNCTION__, name);
+ env->ExceptionDescribe();
+ env->ExceptionClear();
}
+
+ env->DeleteLocalRef(cls);
}
else {
- fprintf(stderr, "%s: Could not attach to the VM!", __PRETTY_FUNCTION__);
+ fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
}
}
@@ -241,107 +199,113 @@ static jvalue callJNIMethodA( JNIFunctionType type, jobject obj, const char *nam
void callJNIVoidMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (void_function, obj, name, sig);
+ CALL_JNI_METHOD (void_type, obj, name, sig);
}
jobject callJNIObjectMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (object_function, obj, name, sig);
+ CALL_JNI_METHOD (object_type, obj, name, sig);
return result.l;
}
+jboolean callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... )
+{
+ CALL_JNI_METHOD (boolean_type, obj, name, sig);
+ return result.z;
+}
+
jbyte callJNIByteMethod( jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (byte_function, obj, name, sig);
+ CALL_JNI_METHOD (byte_type, obj, name, sig);
return result.b;
}
jchar callJNICharMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (char_function, obj, name, sig);
+ CALL_JNI_METHOD (char_type, obj, name, sig);
return result.c;
}
jshort callJNIShortMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (short_function, obj, name, sig);
+ CALL_JNI_METHOD (short_type, obj, name, sig);
return result.s;
}
jint callJNIIntMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (int_function, obj, name, sig);
+ CALL_JNI_METHOD (int_type, obj, name, sig);
return result.i;
}
jlong callJNILongMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (long_function, obj, name, sig);
+ CALL_JNI_METHOD (long_type, obj, name, sig);
return result.j;
}
jfloat callJNIFloatMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (float_function, obj, name, sig);
+ CALL_JNI_METHOD (float_type, obj, name, sig);
return result.f;
}
jdouble callJNIDoubleMethod (jobject obj, const char *name, const char *sig, ... )
{
- CALL_JNI_METHOD (double_function, obj, name, sig);
+ CALL_JNI_METHOD (double_type, obj, name, sig);
return result.d;
}
void callJNIVoidMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (void_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (void_type, obj, name, sig, args);
}
jobject callJNIObjectMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (object_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (object_type, obj, name, sig, args);
return result.l;
}
jbyte callJNIByteMethodA ( jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (byte_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (byte_type, obj, name, sig, args);
return result.b;
}
jchar callJNICharMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (char_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (char_type, obj, name, sig, args);
return result.c;
}
jshort callJNIShortMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (short_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (short_type, obj, name, sig, args);
return result.s;
}
jint callJNIIntMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (int_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (int_type, obj, name, sig, args);
return result.i;
}
jlong callJNILongMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (long_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (long_type, obj, name, sig, args);
return result.j;
}
jfloat callJNIFloatMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (float_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (float_type, obj, name, sig, args);
return result.f;
}
jdouble callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
{
- jvalue result = callJNIMethodA (double_function, obj, name, sig, args);
+ jvalue result = callJNIMethodA (double_type, obj, name, sig, args);
return result.d;
}
@@ -371,3 +335,91 @@ void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char
env->ReleaseStringUTFChars (aJString, s);
}
+JNIType primitiveTypeFromClassName(const char *name)
+{
+ JNIType type;
+
+ if (strcmp("byte",name) == 0)
+ type = byte_type;
+ else if (strcmp("short",name) == 0)
+ type = short_type;
+ else if (strcmp("int",name) == 0)
+ type = int_type;
+ else if (strcmp("long",name) == 0)
+ type = long_type;
+ else if (strcmp("float",name) == 0)
+ type = float_type;
+ else if (strcmp("double",name) == 0)
+ type = double_type;
+ else if (strcmp("char",name) == 0)
+ type = char_type;
+ else if (strcmp("boolean",name) == 0)
+ type = boolean_type;
+ else if (strcmp("void",name) == 0)
+ type = void_type;
+ else
+ type = object_type;
+
+ return type;
+}
+
+jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature)
+{
+ JavaVM *jvm = getJavaVM();
+ JNIEnv *env = getJNIEnv();
+ jvalue result;
+
+ if ( obj != NULL && jvm != NULL && env != NULL) {
+ jclass cls = env->GetObjectClass(obj);
+ if ( cls != NULL ) {
+ jfieldID field = env->GetFieldID(cls, name, signature);
+ if ( field != NULL ) {
+ switch (type) {
+ case object_type:
+ result.l = env->functions->GetObjectField(env, obj, field);
+ break;
+ case boolean_type:
+ result.z = env->functions->GetBooleanField(env, obj, field);
+ break;
+ case byte_type:
+ result.b = env->functions->GetByteField(env, obj, field);
+ break;
+ case char_type:
+ result.c = env->functions->GetCharField(env, obj, field);
+ break;
+ case short_type:
+ result.s = env->functions->GetShortField(env, obj, field);
+ break;
+ case int_type:
+ result.i = env->functions->GetIntField(env, obj, field);
+ break;
+ case long_type:
+ result.j = env->functions->GetLongField(env, obj, field);
+ break;
+ case float_type:
+ result.f = env->functions->GetFloatField(env, obj, field);
+ break;
+ case double_type:
+ result.d = env->functions->GetDoubleField(env, obj, field);
+ break;
+ default:
+ fprintf(stderr, "%s: invalid field type (%d)", __PRETTY_FUNCTION__, (int)type);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "%s: Could not find field: %s!", __PRETTY_FUNCTION__, name);
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ }
+
+ env->DeleteLocalRef(cls);
+ }
+ else {
+ fprintf(stderr, "%s: Could not find class for object!", __PRETTY_FUNCTION__);
+ }
+ }
+
+ return result;
+}
+
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index 3599857..6d25bc7 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -28,17 +28,18 @@
#include <JavaVM/jni.h>
typedef enum {
- void_function,
- object_function,
- boolean_function,
- byte_function,
- char_function,
- short_function,
- int_function,
- long_function,
- float_function,
- double_function
-} JNIFunctionType;
+ invalid_type = 0,
+ void_type,
+ object_type,
+ boolean_type,
+ byte_type,
+ char_type,
+ short_type,
+ int_type,
+ long_type,
+ float_type,
+ double_type
+} JNIType;
const char *getCharactersFromJString (jstring aJString);
void releaseCharactersForJString (jstring aJString, const char *s);
@@ -46,6 +47,9 @@ void releaseCharactersForJString (jstring aJString, const char *s);
const char *getCharactersFromJStringInEnv (JNIEnv *env, jstring aJString);
void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char *s);
+JNIType primitiveTypeFromClassName(const char *name);
+jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature);
+
jobject callJNIObjectMethod( jobject obj, const char *name, const char *sig, ... );
void callJNIVoidMethod( jobject obj, const char *name, const char *sig, ... );
jboolean callJNIBooleanMethod( jobject obj, const char *name, const char *sig, ... );
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index 2085757..1cbe1d1 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -22,6 +22,8 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <value.h>
+
#include <runtime.h>
#include <jni_instance.h>
@@ -34,3 +36,7 @@ Instance *Instance::createBindingForLanguageInstance (BindingLanguage language,
return new Bindings::JavaInstance ((jobject)instance);
return 0;
}
+
+Value Instance::getValueOfField (const Field *aField) const {
+ return aField->valueFromInstance (this);
+}
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 9edcdbd..d251f81 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -31,6 +31,8 @@
namespace Bindings
{
+class Instance;
+
// For now just use Java style type descriptors.
typedef const char * RuntimeType;
@@ -58,7 +60,7 @@ public:
virtual const char *name() const = 0;
virtual RuntimeType type() const = 0;
- virtual KJS::Value value() const = 0;
+ virtual KJS::Value valueFromInstance(const Instance *instance) const = 0;
virtual ~Field() {};
};
@@ -103,8 +105,8 @@ public:
virtual Class *getClass() const = 0;
- virtual KJS::Value getValueOfField (const Field *aField) const = 0;
-
+ virtual KJS::Value getValueOfField (const Field *aField) const;
+
virtual ~Instance() {};
};
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index 169589e..cc2c6b8 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -70,8 +70,8 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
if (aField){
- instance->getValueOfField (aField);
printf ("%s: found field = %p, type = %s\n", __PRETTY_FUNCTION__, aField, aField->type());
+ return instance->getValueOfField (aField);
}
return Undefined();
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list