[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:16:09 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 46a017ec55dab1f9d8b1fd959c84a6aeb42a8031
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 4 01:41:24 2003 +0000

    WebCore:
    	LiveConnect:  Removed some debugging.
    
            Reviewed by Chris.
    
            * khtml/ecma/kjs_html.cpp:
            (KJS::HTMLCollection::tryGet):
    
    JavaScriptCore:
    	LiveConnect:  Added support for parameter passing to Java and conversion
    	of return values.
    
            Reviewed by Chris.
    
            * bindings/jni/jni_instance.cpp:
            (JavaInstance::invokeMethod):
            * bindings/jni/jni_instance.h:
            * bindings/jni/jni_runtime.cpp:
            (JavaParameter::JavaParameter):
            (JavaMethod::JavaMethod):
            (JavaMethod::signature):
            * bindings/jni/jni_runtime.h:
            (Bindings::JavaParameter::JavaParameter):
            (Bindings::JavaParameter::operator=):
            (Bindings::JavaParameter::getJNIType):
            * bindings/jni/jni_utility.cpp:
            (callJNIBooleanMethodA):
            (convertValueToJValue):
            * bindings/jni/jni_utility.h:
            * bindings/runtime.h:
            * bindings/runtime_method.cpp:
            (RuntimeMethodImp::call):
            * bindings/runtime_object.cpp:
            (RuntimeObjectImp::get):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5687 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 98db8ba..1ef6193 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,31 @@
+2003-12-03  Richard Williamson   <rjw at apple.com>
+
+	LiveConnect:  Added support for parameter passing to Java and conversion
+	of return values.
+
+        Reviewed by Chris.
+
+        * bindings/jni/jni_instance.cpp:
+        (JavaInstance::invokeMethod):
+        * bindings/jni/jni_instance.h:
+        * bindings/jni/jni_runtime.cpp:
+        (JavaParameter::JavaParameter):
+        (JavaMethod::JavaMethod):
+        (JavaMethod::signature):
+        * bindings/jni/jni_runtime.h:
+        (Bindings::JavaParameter::JavaParameter):
+        (Bindings::JavaParameter::operator=):
+        (Bindings::JavaParameter::getJNIType):
+        * bindings/jni/jni_utility.cpp:
+        (callJNIBooleanMethodA):
+        (convertValueToJValue):
+        * bindings/jni/jni_utility.h:
+        * bindings/runtime.h:
+        * bindings/runtime_method.cpp:
+        (RuntimeMethodImp::call):
+        * bindings/runtime_object.cpp:
+        (RuntimeObjectImp::get):
+
 2003-12-02  Richard Williamson   <rjw at apple.com>
 
 	Added support for calling simple methods in Java from JavaScript.
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index 0b7890a..cdc01d9 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -26,6 +26,7 @@
 #include <jni_instance.h>
 #include <jni_runtime.h>
 #include <jni_utility.h>
+#include <runtime_object.h>
 
 using namespace Bindings;
 using namespace KJS;
@@ -52,13 +53,14 @@ Class *JavaInstance::getClass() const
     return JavaClass::classForInstance (_instance->_instance);
 }
 
-Value JavaInstance::invokeMethod (const Method *method, const List &args)
+Value JavaInstance::invokeMethod (KJS::ExecState *exec, const Method *method, const List &args)
 {
     const JavaMethod *jMethod = static_cast<const JavaMethod*>(method);
     int i, count = args.size();
     jvalue *jArgs;
+    Value resultValue;
     
-    fprintf(stderr,"%s: this=%p, invoking %s which returns %s and takes %d args\n", __PRETTY_FUNCTION__, this, method->name(), method->returnType(), count);
+    fprintf(stderr,"%s: this=%p, invoking %s with signature %s\n", __PRETTY_FUNCTION__, this, method->name(), jMethod->signature());
     
     if (count > 0) {
         jArgs = (jvalue *)malloc (count * sizeof(jvalue));
@@ -68,70 +70,82 @@ Value JavaInstance::invokeMethod (const Method *method, const List &args)
         
     for (i = 0; i < count; i++) {
         fprintf (stderr, "%s:  %d, type %d\n", __PRETTY_FUNCTION__, i, args.at(i).type());
+        JavaParameter *aParameter = static_cast<JavaParameter *>(jMethod->parameterAt(i));
+        jArgs[i] = convertValueToJValue (exec, args.at(i), aParameter);
     }
     
     jvalue result;
     switch (jMethod->JNIReturnType()){
         case void_type: {
-            callJNIVoidMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            callJNIVoidMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Undefined();
         }
         break;
         
         case object_type: {
-            result.l = callJNIObjectMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.l = callJNIObjectMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Object(new RuntimeObjectImp(new JavaInstance (result.l)));
         }
         break;
         
         case boolean_type: {
-            result.z = callJNIBooleanMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.z = callJNIBooleanMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = KJS::Boolean(result.z);
         }
         break;
         
         case byte_type: {
-            result.b = callJNIByteMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.b = callJNIByteMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.b);
         }
         break;
         
         case char_type: {
-            result.c = callJNICharMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.c = callJNICharMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.c);
         }
         break;
         
         case short_type: {
-            result.s = callJNIShortMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.s = callJNIShortMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.s);
         }
         break;
         
         case int_type: {
-            result.i = callJNIIntMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.i = callJNIIntMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.i);
         }
         break;
         
         case long_type: {
-            result.j = callJNILongMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.j = callJNILongMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number((long int)result.j);
         }
         break;
         
         case float_type: {
-            result.f = callJNIFloatMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.f = callJNIFloatMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.f);
         }
         break;
         
         case double_type: {
-            result.d = callJNIDoubleMethod (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            result.d = callJNIDoubleMethodA (_instance->_instance, method->name(), jMethod->signature(), jArgs);
+            resultValue = Number(result.d);
         }
         break;
 
         case invalid_type:
-        default:
+        default: {
+            resultValue = Undefined();
+        }
         break;
     }
-    
-    // FIXME:  create a KJS::Value from the jvalue result.
-    
+        
     free (jArgs);
     
-    return Undefined();
+    return resultValue;
 }
 
 
diff --git a/JavaScriptCore/bindings/jni/jni_instance.h b/JavaScriptCore/bindings/jni/jni_instance.h
index 896a028..0ca9135 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.h
+++ b/JavaScriptCore/bindings/jni/jni_instance.h
@@ -85,7 +85,7 @@ public:
     
     jobject javaInstance() const { return _instance->_instance; }
 
-    virtual KJS::Value invokeMethod (const Method *method, const KJS::List &args);
+    virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args);
     
 private:
     JObjectWrapper *_instance;
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index 20bc897..b2b1f98 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -35,6 +35,12 @@ using namespace KJS;
 using namespace Bindings;
 
 
+JavaParameter::JavaParameter (JNIEnv *env, jstring type)
+{
+    _type = new JavaString (env, type);
+    _JNIType = primitiveTypeFromClassName (_type->characters());
+};
+
 JavaField::JavaField (JNIEnv *env, jobject aField)
 {
     // Get field type
@@ -131,6 +137,9 @@ JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
     // Get method name
     jstring methodName = (jstring)callJNIObjectMethod (aMethod, "getName", "()Ljava/lang/String;");
     _name = new JavaString (env, methodName);
+    
+    // Created lazily.
+    _signature = 0;
 }
 
 const char *JavaMethod::signature() const 
@@ -140,6 +149,9 @@ const char *JavaMethod::signature() const
         
         _signature = new UString("(");
         for (i = 0; i < _numParameters; i++) {
+            JavaParameter *aParameter = static_cast<JavaParameter *>(parameterAt(i));
+            _signature->append(signatureFromPrimitiveType (aParameter->getJNIType()));
+            // FIXME!  Add class description for object types.
         }
         _signature->append(")");
         
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 62fd6d3..de6287d 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -83,18 +83,17 @@ private:
 class JavaParameter : public Parameter
 {
 public:
-    JavaParameter () : _type (0) {};
-    
-    JavaParameter (JNIEnv *env, jstring type) {
-        _type = new JavaString (env, type);
-    };
+    JavaParameter () : _type (0), _JNIType(invalid_type) {};
     
+    JavaParameter (JNIEnv *env, jstring type);
+        
     ~JavaParameter() {
         delete _type;
     };
 
     JavaParameter(const JavaParameter &other) : Parameter() {
         _type = other._type;
+        _JNIType = other._JNIType;
     };
 
     JavaParameter &operator=(const JavaParameter &other)
@@ -105,14 +104,18 @@ public:
         delete _type;
         
         _type = other._type;
+        _JNIType = other._JNIType;
 
         return *this;
     }
     
     virtual RuntimeType type() const { return _type->characters(); }
+
+    JNIType getJNIType() const { return _JNIType; }
     
 private:
     JavaString *_type;
+    JNIType _JNIType;
 };
 
 
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index dd21487..7bbb016 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -22,8 +22,11 @@
  * (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 "interpreter.h"
+
+#include "jni_runtime.h"
 #include "jni_utility.h"
+#include "runtime_object.h"
 
 static JavaVM *jvm;
 
@@ -309,6 +312,12 @@ jdouble callJNIDoubleMethodA (jobject obj, const char *name, const char *sig, jv
     return result.d;
 }
 
+jboolean callJNIBooleanMethodA (jobject obj, const char *name, const char *sig, jvalue *args)
+{
+    jvalue result = callJNIMethodA (boolean_type, obj, name, sig, args);
+    return result.z;
+}
+
 const char *getCharactersFromJString (jstring aJString)
 {
     return getCharactersFromJStringInEnv (getJNIEnv(), aJString);
@@ -463,3 +472,72 @@ jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *sig
     return result;
 }
 
+jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, Bindings::JavaParameter *aParameter)
+{
+    jvalue result;
+    double d = 0;
+   
+    d = value.toNumber(exec);
+    switch (aParameter->getJNIType()){
+        case object_type: {
+            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp*>(value.imp());
+            if (imp) {
+                Bindings::JavaInstance *instance = static_cast<Bindings::JavaInstance*>(imp->getInternalInstance());
+                result.l = instance->javaInstance();
+            }
+            else
+                result.l = (jobject)0;
+        }
+        break;
+        
+        case boolean_type: {
+            result.z = (jboolean)d;
+        }
+        break;
+            
+        case byte_type: {
+            result.b = (jbyte)d;
+        }
+        break;
+        
+        case char_type: {
+            result.c = (jchar)d;
+        }
+        break;
+
+        case short_type: {
+            result.s = (jshort)d;
+        }
+        break;
+
+        case int_type: {
+            result.i = (jint)d;
+        }
+        break;
+
+        case long_type: {
+            result.j = (jlong)d;
+        }
+        break;
+
+        case float_type: {
+            result.f = (jfloat)d;
+        }
+        break;
+
+        case double_type: {
+            result.d = (jdouble)d;
+        }
+        break;
+            
+        break;
+
+        case invalid_type:
+        default:
+        case void_type: {
+            bzero (&result, sizeof(jvalue));
+        }
+        break;
+    }
+    return result;
+}
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index e8e2da2..b9d69bb 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -25,6 +25,8 @@
 #ifndef _JNI_UTILITY_H_
 #define _JNI_UTILITY_H_
 
+#include <value.h>
+
 #include <JavaVM/jni.h>
 
 typedef enum {
@@ -41,6 +43,11 @@ typedef enum {
     double_type
 } JNIType;
 
+namespace Bindings 
+{
+class JavaParameter;
+}
+
 const char *getCharactersFromJString (jstring aJString);
 void releaseCharactersForJString (jstring aJString, const char *s);
 
@@ -50,6 +57,8 @@ void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char
 JNIType primitiveTypeFromClassName(const char *name);
 const char *signatureFromPrimitiveType(JNIType type);
 
+jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, Bindings::JavaParameter *aParameter);
+
 jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature);
 
 jobject callJNIObjectMethod( jobject obj, const char *name, const char *sig, ... );
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 5263c16..80154bc 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -107,7 +107,7 @@ public:
     
     virtual KJS::Value getValueOfField (const Field *aField) const;
     
-    virtual KJS::Value invokeMethod (const Method *method, const KJS::List &args) = 0;
+    virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args) = 0;
         
     virtual ~Instance() {};
 };
diff --git a/JavaScriptCore/bindings/runtime_method.cpp b/JavaScriptCore/bindings/runtime_method.cpp
index 5e187eb..aa81114 100644
--- a/JavaScriptCore/bindings/runtime_method.cpp
+++ b/JavaScriptCore/bindings/runtime_method.cpp
@@ -75,7 +75,7 @@ Value RuntimeMethodImp::call(ExecState *exec, Object &thisObj, const List &args)
     if (method) {
         RuntimeObjectImp *imp = static_cast<RuntimeObjectImp*>(thisObj.imp());
         if (imp) {
-            imp->getInternalInstance()->invokeMethod(method, args);
+            imp->getInternalInstance()->invokeMethod(exec, method, args);
         }
     }
     
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index 564e863..3778424 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -71,7 +71,7 @@ RuntimeObjectImp::RuntimeObjectImp(Bindings::Instance *i, bool oi) : ObjectImp (
 
 Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) const
 {
-    printf ("%s: NOT FULLY IMPLEMENTED %p: propertyName %s\n", __PRETTY_FUNCTION__, instance, propertyName.ascii());
+    printf ("%s: %p: propertyName %s\n", __PRETTY_FUNCTION__, instance, propertyName.ascii());
     // Get the value of the RuntimeObject's property.
     
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
@@ -88,6 +88,8 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
         return Object (new RuntimeMethodImp(exec, propertyName, aMethod));
     }
     
+    printf ("%s: %p: unable to find propertyName %s\n", __PRETTY_FUNCTION__, instance, propertyName.ascii());
+
     return Undefined();
 }
 
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 7fa6f0e..14c719e 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,12 @@
+2003-12-03  Richard Williamson   <rjw at apple.com>
+
+	LiveConnect:  Removed some debugging.
+
+        Reviewed by Chris.
+
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::HTMLCollection::tryGet):
+
 2003-12-03  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3475761, list bullets mislayout after text zooming.
diff --git a/WebCore/khtml/ecma/kjs_html.cpp b/WebCore/khtml/ecma/kjs_html.cpp
index bf292b0..de9a815 100644
--- a/WebCore/khtml/ecma/kjs_html.cpp
+++ b/WebCore/khtml/ecma/kjs_html.cpp
@@ -2910,7 +2910,6 @@ Value KJS::HTMLCollection::tryGet(ExecState *exec, const Identifier &propertyNam
             DOM::HTMLElement element = static_cast<DOM::HTMLElement>(node);
             DOM::HTMLAppletElementImpl *appletElement = static_cast<DOM::HTMLAppletElementImpl *>(element.handle());
             
-            fprintf (stderr,"%s:  need to return applet instance\n", __PRETTY_FUNCTION__);
             if (appletElement->getAppletInstance()) {
                 // The instance is owned by the applet element.
                 RuntimeObjectImp *appletImp = new RuntimeObjectImp(appletElement->getAppletInstance(), false);

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list