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


The following commit has been merged in the debian/unstable branch:
commit bc59b935f55d25aee409dc70f6b801f213e1b0fd
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Dec 5 00:28:00 2003 +0000

    JavaScriptCore:
    	LiveConnect:  Added support for setting the value of Java
    	fields.
    
            Reviewed by Chris.
    
            * bindings/jni/jni_instance.cpp:
            (JavaInstance::invokeMethod):
            * bindings/jni/jni_runtime.cpp:
            (JavaParameter::JavaParameter):
            (JavaField::JavaField):
            (JavaField::valueFromInstance):
            (JavaField::setValueToInstance):
            (JavaMethod::JavaMethod):
            * bindings/jni/jni_runtime.h:
            (Bindings::JavaField::getJNIType):
            * bindings/jni/jni_utility.cpp:
            (JNITypeFromClassName):
            (convertValueToJValue):
            * bindings/jni/jni_utility.h:
            * bindings/runtime.cpp:
            (Instance::setValueOfField):
            * bindings/runtime.h:
            * bindings/runtime_object.cpp:
            (RuntimeObjectImp::get):
            (RuntimeObjectImp::put):
            (RuntimeObjectImp::defaultValue):
    
    Tests:
            Added test of setting Java fields from JavaScript.
    
            Reviewed by Chris.
    
            * LiveConnect/Blink/Holder.java:
            (Holder):
            * LiveConnect/Blink/test.html:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5697 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 41edac2..756f731 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,5 +1,34 @@
 2003-12-04  Richard Williamson   <rjw at apple.com>
 
+	LiveConnect:  Added support for setting the value of Java
+	fields.
+
+        Reviewed by Chris.
+
+        * bindings/jni/jni_instance.cpp:
+        (JavaInstance::invokeMethod):
+        * bindings/jni/jni_runtime.cpp:
+        (JavaParameter::JavaParameter):
+        (JavaField::JavaField):
+        (JavaField::valueFromInstance):
+        (JavaField::setValueToInstance):
+        (JavaMethod::JavaMethod):
+        * bindings/jni/jni_runtime.h:
+        (Bindings::JavaField::getJNIType):
+        * bindings/jni/jni_utility.cpp:
+        (JNITypeFromClassName):
+        (convertValueToJValue):
+        * bindings/jni/jni_utility.h:
+        * bindings/runtime.cpp:
+        (Instance::setValueOfField):
+        * bindings/runtime.h:
+        * bindings/runtime_object.cpp:
+        (RuntimeObjectImp::get):
+        (RuntimeObjectImp::put):
+        (RuntimeObjectImp::defaultValue):
+
+2003-12-04  Richard Williamson   <rjw at apple.com>
+
 	Added support for string conversions.
 	Changed various JavaString member variables to be inline.
 	Implemented defaultValue for context relevant type coercion.
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index 0a8b62f..1b20f39 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -94,7 +94,7 @@ Value JavaInstance::invokeMethod (KJS::ExecState *exec, const Method *method, co
         
     for (i = 0; i < count; i++) {
         JavaParameter *aParameter = static_cast<JavaParameter *>(jMethod->parameterAt(i));
-        jArgs[i] = convertValueToJValue (exec, args.at(i), aParameter);
+        jArgs[i] = convertValueToJValue (exec, args.at(i), aParameter->getJNIType(), aParameter->type());
     }
     
     jvalue result;
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index af7cebb..bc27eb4 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -38,16 +38,16 @@ using namespace Bindings;
 JavaParameter::JavaParameter (JNIEnv *env, jstring type)
 {
     _type = JavaString (env, type);
-    _JNIType = primitiveTypeFromClassName (_type.characters());
+    _JNIType = JNITypeFromClassName (_type.characters());
 };
 
 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;");
+    jstring fieldTypeName = (jstring)callJNIObjectMethod (fieldType, "getName", "()Ljava/lang/String;");
     _type = JavaString(env, fieldTypeName);
-    _primitiveType = primitiveTypeFromClassName (_type.characters());
+    _JNIType = JNITypeFromClassName (_type.characters());
 
     // Get field name
     jstring fieldName = (jstring)callJNIObjectMethod (aField, "getName", "()Ljava/lang/String;");
@@ -62,7 +62,7 @@ KJS::Value JavaField::valueFromInstance(const Instance *i) const
     jobject jinstance = instance->javaInstance();
     jobject fieldJInstance = _field->javaInstance();
 
-    switch (_primitiveType) {
+    switch (_JNIType) {
         case object_type: {
             jobject anObject = callJNIObjectMethod(_field->javaInstance(), "get", "(Ljava/lang/Object;)Ljava/lang/Object;", jinstance);
             return KJS::Object(new RuntimeObjectImp(new JavaInstance ((jobject)anObject)));
@@ -98,6 +98,62 @@ KJS::Value JavaField::valueFromInstance(const Instance *i) const
     return Undefined();
 }
 
+void JavaField::setValueToInstance(KJS::ExecState *exec, const Instance *i, KJS::Value aValue) const
+{
+    const JavaInstance *instance = static_cast<const JavaInstance *>(i);
+    jobject jinstance = instance->javaInstance();
+    jobject fieldJInstance = _field->javaInstance();
+    jvalue javaValue = convertValueToJValue (exec, aValue, _JNIType, type());
+
+    switch (_JNIType) {
+        case object_type: {
+            callJNIVoidMethod(fieldJInstance, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", jinstance, javaValue.l);
+        }
+        break;
+            
+        case boolean_type: {
+            callJNIVoidMethod(fieldJInstance, "setBoolean", "(Ljava/lang/Object;Z)V", jinstance, javaValue.z);
+        }
+        break;
+            
+        case byte_type: {
+            callJNIVoidMethod(fieldJInstance, "setByte", "(Ljava/lang/Object;B)V", jinstance, javaValue.b);
+        }
+        break;
+
+        case char_type: {
+            callJNIVoidMethod(fieldJInstance, "setChar", "(Ljava/lang/Object;C)V", jinstance, javaValue.c);
+        }
+        break;
+
+        case short_type: {
+            callJNIVoidMethod(fieldJInstance, "setShort", "(Ljava/lang/Object;S)V", jinstance, javaValue.s);
+        }
+        break;
+
+        case int_type: {
+            callJNIVoidMethod(fieldJInstance, "setInt", "(Ljava/lang/Object;I)V", jinstance, javaValue.i);
+        }
+        break;
+
+        case long_type: {
+            callJNIVoidMethod(fieldJInstance, "setLong", "(Ljava/lang/Object;J)V", jinstance, javaValue.j);
+        }
+        break;
+
+        case float_type: {
+            callJNIVoidMethod(fieldJInstance, "setFloat", "(Ljava/lang/Object;F)V", jinstance, javaValue.f);
+        }
+        break;
+
+        case double_type: {
+            callJNIVoidMethod(fieldJInstance, "setDouble", "(Ljava/lang/Object;D)V", jinstance, javaValue.d);
+        }
+        break;
+        default:
+        break;
+    }
+}
 
 JavaConstructor::JavaConstructor (JNIEnv *env, jobject aConstructor)
 {
@@ -120,7 +176,7 @@ JavaMethod::JavaMethod (JNIEnv *env, jobject aMethod)
     jobject returnType = callJNIObjectMethod (aMethod, "getReturnType", "()Ljava/lang/Class;");
     jstring returnTypeName = (jstring)callJNIObjectMethod (returnType, "getName", "()Ljava/lang/String;");
     _returnType =JavaString (env, returnTypeName);
-    _JNIReturnType = primitiveTypeFromClassName (_returnType.characters());
+    _JNIReturnType = JNITypeFromClassName (_returnType.characters());
 
     // Get method name
     jstring methodName = (jstring)callJNIObjectMethod (aMethod, "getName", "()Ljava/lang/String;");
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index d9fcac1..5058b52 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -186,14 +186,17 @@ public:
     }
     
     virtual KJS::Value valueFromInstance(const Instance *instance) const;
+    virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, KJS::Value aValue) const;
     
     virtual const char *name() const { return _name.characters(); }
     virtual RuntimeType type() const { return _type.characters(); }
+
+    JNIType getJNIType() const { return _JNIType; }
     
 private:
     JavaString _name;
     JavaString _type;
-    JNIType _primitiveType;
+    JNIType _JNIType;
     JavaInstance *_field;
 };
 
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index 3f767e4..adc875e 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -344,7 +344,7 @@ void releaseCharactersForJStringInEnv (JNIEnv *env, jstring aJString, const char
     env->ReleaseStringUTFChars (aJString, s);
 }
 
-JNIType primitiveTypeFromClassName(const char *name)
+JNIType JNITypeFromClassName(const char *name)
 {
     JNIType type;
     
@@ -472,13 +472,13 @@ 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 convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JNIType, const char *javaClassName)
 {
     jvalue result;
     double d = 0;
    
     d = value.toNumber(exec);
-    switch (aParameter->getJNIType()){
+    switch (_JNIType){
         case object_type: {
             result.l = (jobject)0;
             
@@ -493,7 +493,7 @@ jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, Bindings::J
             }
             
             // Now convert value to a string if the target type is a java.lang.string.
-            if (result.l == 0 && strcmp(aParameter->type(), "java.lang.String") == 0) {
+            if (result.l == 0 && strcmp(javaClassName, "java.lang.String") == 0) {
                 KJS::UString stringValue = value.toString(exec);
                 JNIEnv *env = getJNIEnv();
                 jobject javaString = env->functions->NewString (env, (const jchar *)stringValue.data(), stringValue.size());
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index b9d69bb..619aa33 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -54,10 +54,10 @@ 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);
+JNIType JNITypeFromClassName(const char *name);
 const char *signatureFromPrimitiveType(JNIType type);
 
-jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, Bindings::JavaParameter *aParameter);
+jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JNIType, const char *javaClassName);
 
 jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature);
 
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index 1cbe1d1..58fc2ed 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -40,3 +40,7 @@ Instance *Instance::createBindingForLanguageInstance (BindingLanguage language,
 Value Instance::getValueOfField (const Field *aField) const {  
     return aField->valueFromInstance (this);
 }
+
+void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, Value aValue) const {  
+    return aField->setValueToInstance (exec, this, aValue);
+}
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 03162fd..b6ef95c 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -61,6 +61,7 @@ public:
     virtual RuntimeType type() const = 0;
 
     virtual KJS::Value valueFromInstance(const Instance *instance) const = 0;
+    virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, KJS::Value aValue) const = 0;
 
     virtual ~Field() {};
 };
@@ -106,6 +107,7 @@ public:
     virtual Class *getClass() const = 0;
     
     virtual KJS::Value getValueOfField (const Field *aField) const;
+    virtual void setValueOfField (KJS::ExecState *exec, const Field *aField, KJS::Value aValue) const;
     
     virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args) = 0;
     
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index 20c227e..c880648 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -64,7 +64,7 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
 {
     // See if the instance have a field with the specified name.
     Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
-    if (aField){
+    if (aField) {
         return instance->getValueOfField (aField); 
     }
     
@@ -83,8 +83,11 @@ Value RuntimeObjectImp::get(ExecState *exec, const Identifier &propertyName) con
 void RuntimeObjectImp::put(ExecState *exec, const Identifier &propertyName,
                     const Value &value, int attr)
 {
-    printf ("%s: NOT YET IMPLEMENTED %p: propertyName %s\n", __PRETTY_FUNCTION__, instance, propertyName.ascii());
     // Set the value of the property.
+    Field *aField = instance->getClass()->fieldNamed(propertyName.ascii());
+    if (aField) {
+        getInternalInstance()->setValueOfField(exec, aField, value);
+    }
 }
 
 bool RuntimeObjectImp::canPut(ExecState *exec, const Identifier &propertyName) const
@@ -112,8 +115,6 @@ bool RuntimeObjectImp::deleteProperty(ExecState *exec,
 
 Value RuntimeObjectImp::defaultValue(ExecState *exec, Type hint) const
 {
-    // Return a string representation of the instance.
-    
     // FIXME:  Convert to appropriate type based on hint.
     // If UnspecifiedType should only convert to string if
     // native class is a string.  

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list