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


The following commit has been merged in the debian/unstable branch:
commit a1a022857ec42fd84dbaef81e4b962c138306c26
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Dec 15 23:14:03 2003 +0000

    JavaScriptCore:
    	Last piece of LiveConnect!  This checkin adds implementation
    	of the Java to JavaScript object conversion functions.
    
            Reviewed by John.
    
            * bindings/jni/jni_instance.cpp:
            (JavaInstance::invokeMethod):
            * bindings/jni/jni_utility.cpp:
            * bindings/jni/jni_utility.h:
            * bindings/jni_jsobject.cpp:
            (Bindings::JSObject::invoke):
            (Bindings::JSObject::call):
            (Bindings::JSObject::eval):
            (Bindings::JSObject::getMember):
            (Bindings::JSObject::setMember):
            (Bindings::JSObject::getSlot):
            (Bindings::JSObject::setSlot):
            (Bindings::JSObject::createNative):
            (Bindings::JSObject::convertValueToJObject):
            (Bindings::JSObject::convertJObjectToValue):
            (Bindings::JSObject::listFromJArray):
            * bindings/jni_jsobject.h:
            (Bindings::):
            * bindings/runtime_method.cpp:
            (RuntimeMethodImp::get):
            (RuntimeMethodImp::codeType):
            (RuntimeMethodImp::execute):
    
    WebCore:
    	Return 0 if the view doesn't have a bridge.
    
            Reviewed by John.
    
            * kwq/WebCoreBridge.mm:
            (rootForView):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5801 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 3b326be..8b7fa5b 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,33 @@
+2003-12-15  Richard Williamson   <rjw at apple.com>
+
+	Last piece of LiveConnect!  This checkin adds implementation
+	of the Java to JavaScript object conversion functions.
+
+        Reviewed by John.
+
+        * bindings/jni/jni_instance.cpp:
+        (JavaInstance::invokeMethod):
+        * bindings/jni/jni_utility.cpp:
+        * bindings/jni/jni_utility.h:
+        * bindings/jni_jsobject.cpp:
+        (Bindings::JSObject::invoke):
+        (Bindings::JSObject::call):
+        (Bindings::JSObject::eval):
+        (Bindings::JSObject::getMember):
+        (Bindings::JSObject::setMember):
+        (Bindings::JSObject::getSlot):
+        (Bindings::JSObject::setSlot):
+        (Bindings::JSObject::createNative):
+        (Bindings::JSObject::convertValueToJObject):
+        (Bindings::JSObject::convertJObjectToValue):
+        (Bindings::JSObject::listFromJArray):
+        * bindings/jni_jsobject.h:
+        (Bindings::):
+        * bindings/runtime_method.cpp:
+        (RuntimeMethodImp::get):
+        (RuntimeMethodImp::codeType):
+        (RuntimeMethodImp::execute):
+
 2003-12-12  Richard Williamson   <rjw at apple.com>
 
 	Added implementation of stubs in JSObject.  All that
diff --git a/JavaScriptCore/bindings/jni/jni_instance.cpp b/JavaScriptCore/bindings/jni/jni_instance.cpp
index 8d9d12c..47cc4d6 100644
--- a/JavaScriptCore/bindings/jni/jni_instance.cpp
+++ b/JavaScriptCore/bindings/jni/jni_instance.cpp
@@ -84,8 +84,6 @@ Value JavaInstance::invokeMethod (KJS::ExecState *exec, const Method *method, co
     jvalue *jArgs;
     Value resultValue;
     
-    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));
     }
diff --git a/JavaScriptCore/bindings/jni/jni_utility.cpp b/JavaScriptCore/bindings/jni/jni_utility.cpp
index 803a398..328d8d5 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.cpp
+++ b/JavaScriptCore/bindings/jni/jni_utility.cpp
@@ -617,20 +617,3 @@ jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JN
     return result;
 }
 
-jobject convertValueToJObject (KJS::ExecState *exec, KJS::Value value)
-{
-    // FIXME:  Implement!
-    return 0;
-}
-
-KJS::Value convertJObjectToValue (KJS::ExecState *exec, jobject)
-{
-    // FIXME:  Implement!
-    return KJS::Undefined();
-}
-
-KJS::List listFromJArray(jobjectArray jArray)
-{
-    // FIXME:  Implement!
-    return KJS::List::empty();
-}
diff --git a/JavaScriptCore/bindings/jni/jni_utility.h b/JavaScriptCore/bindings/jni/jni_utility.h
index 120fb8d..1062bcc 100644
--- a/JavaScriptCore/bindings/jni/jni_utility.h
+++ b/JavaScriptCore/bindings/jni/jni_utility.h
@@ -62,8 +62,6 @@ JNIType JNITypeFromPrimitiveType(char type);
 const char *signatureFromPrimitiveType(JNIType type);
 
 jvalue convertValueToJValue (KJS::ExecState *exec, KJS::Value value, JNIType _JNIType, const char *javaClassName);
-jobject convertValueToJObject (KJS::ExecState *exec, KJS::Value value);
-KJS::Value convertJObjectToValue (KJS::ExecState *exec, jobject);
 
 jvalue getJNIField( jobject obj, JNIType type, const char *name, const char *signature);
 
@@ -89,8 +87,6 @@ jlong callJNILongMethodA( jobject obj, const char *name, const char *sig, jvalue
 jfloat callJNIFloatMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 jdouble callJNIDoubleMethodA( jobject obj, const char *name, const char *sig, jvalue *args);
 
-KJS::List listFromJArray(jobjectArray jArray);
-
 JavaVM *getJavaVM();
 JNIEnv *getJNIEnv();
 
diff --git a/JavaScriptCore/bindings/jni_jsobject.cpp b/JavaScriptCore/bindings/jni_jsobject.cpp
index eb9e077..5b86b15 100644
--- a/JavaScriptCore/bindings/jni_jsobject.cpp
+++ b/JavaScriptCore/bindings/jni_jsobject.cpp
@@ -33,7 +33,7 @@
 #include <jni_jsobject.h>
 #include <jni_runtime.h>
 #include <jni_utility.h>
-
+#include <runtime_object.h>
 
 using namespace Bindings;
 using namespace KJS;
@@ -47,6 +47,8 @@ using namespace KJS;
 }
 #endif
 
+#define UndefinedHandle 1
+
 static bool isJavaScriptThread()
 {
     return (RootObject::runLoop() == CFRunLoopGetCurrent());
@@ -352,8 +354,8 @@ jvalue JSObject::invoke (JSObjectCallContext *context)
     else {
         jlong nativeHandle = context->nativeHandle;
         switch (context->type){
-            case GetWindow: {
-                result.j = JSObject::getWindow(nativeHandle);
+            case CreateNative: {
+                result.j = JSObject::createNative(nativeHandle);
                 break;
             }
         
@@ -442,7 +444,7 @@ jobject JSObject::call(jstring methodName, jobjectArray args) const
     Value result = funcImp->call (exec, thisObj, argList);
 
     // Convert and return the result of the function call.
-    return convertValueToJObject (exec, result);
+    return convertValueToJObject (exec, _root, result);
 }
 
 jobject JSObject::eval(jstring script) const
@@ -453,7 +455,7 @@ jobject JSObject::eval(jstring script) const
     KJS::Value result = _root->interpreter()->evaluate(JavaString(script).ustring(),thisObj).value();
     ExecState *exec = _root->interpreter()->globalExec();
 
-    return convertValueToJObject (exec, result);
+    return convertValueToJObject (exec, _root, result);
 }
 
 jobject JSObject::getMember(jstring memberName) const
@@ -463,14 +465,14 @@ jobject JSObject::getMember(jstring memberName) const
     ExecState *exec = _root->interpreter()->globalExec();
     Value result = _imp->get (exec, Identifier (JavaString(memberName).ustring()));
 
-    return convertValueToJObject (exec, result);
+    return convertValueToJObject (exec, _root, result);
 }
 
 void JSObject::setMember(jstring memberName, jobject value) const
 {
     JS_LOG ("memberName = %s\n", JavaString(memberName).characters());
     ExecState *exec = _root->interpreter()->globalExec();
-    _imp->put (exec, Identifier (JavaString(memberName).ustring()), convertJObjectToValue(exec, value));
+    _imp->put (exec, Identifier (JavaString(memberName).ustring()), convertJObjectToValue(value));
 }
 
 
@@ -490,7 +492,7 @@ jobject JSObject::getSlot(jint index) const
     ExecState *exec = _root->interpreter()->globalExec();
     Value result = _imp->get (exec, (unsigned)index);
 
-    return convertValueToJObject (exec, result);
+    return convertValueToJObject (exec, _root, result);
 }
 
 
@@ -499,7 +501,7 @@ void JSObject::setSlot(jint index, jobject value) const
     JS_LOG ("index = %d, value = %p\n", index, value);
 
     ExecState *exec = _root->interpreter()->globalExec();
-    _imp->put (exec, (unsigned)index, convertJObjectToValue(exec, value));
+    _imp->put (exec, (unsigned)index, convertJObjectToValue(value));
 }
 
 
@@ -520,20 +522,150 @@ void JSObject::finalize() const
     removeJavaReference (_imp);
 }
 
-jlong JSObject::getWindow(jlong nativeHandle)
+// We're either creating a 'Root' object (via a call to JSObject.getWindow()), or
+// another JSObject.
+jlong JSObject::createNative(jlong nativeHandle)
 {
     JS_LOG ("nativeHandle = %d\n", (int)nativeHandle);
 
+    if (nativeHandle == UndefinedHandle)
+        return nativeHandle;
+    else if (rootForImp(jlong_to_impptr(nativeHandle))){
+        return nativeHandle;
+    }
+        
     FindRootObjectForNativeHandleFunctionPtr aFunc = RootObject::findRootObjectForNativeHandleFunction();
     if (aFunc) {
         Bindings::RootObject *root = aFunc(jlong_to_ptr(nativeHandle));
-        addJavaReference (root, root->rootObjectImp());        
-        return ptr_to_jlong(root->rootObjectImp());
+        // If root is !NULL We must have been called via netscape.javascript.JSObject.getWindow(),
+        // otherwise we are being called after creating a JSObject in
+        // JSObject::convertValueToJObject().
+        if (root) {
+            addJavaReference (root, root->rootObjectImp());        
+            return ptr_to_jlong(root->rootObjectImp());
+        }
+        else {
+            return nativeHandle;
+        }
     }
     
     return ptr_to_jlong(0);
 }
 
+jobject JSObject::convertValueToJObject (KJS::ExecState *exec, const Bindings::RootObject *root, KJS::Value value)
+{
+    JNIEnv *env = getJNIEnv();
+    jobject result = 0;
+    
+    // See section 22.7 of 'JavaScript:  The Definitive Guide, 4th Edition',
+    // figure 22-5.
+    // number -> java.lang.Double
+    // string -> java.lang.String
+    // boolean -> java.lang.Boolean
+    // Java instance -> Java instance
+    // Everything else -> JSObject
+    
+    KJS::Type type = value.type();
+    if (type == KJS::NumberType) {
+        jclass JSObjectClass = env->FindClass ("java/lang/Double");
+        jmethodID constructorID = env->GetMethodID (JSObjectClass, "<init>", "(D)V");
+        if (constructorID != NULL) {
+            result = env->NewObject (JSObjectClass, constructorID, (jdouble)value.toNumber(exec));
+        }
+    }
+    else if (type == KJS::StringType) {
+        KJS::UString stringValue = value.toString(exec);
+        JNIEnv *env = getJNIEnv();
+        result = env->NewString ((const jchar *)stringValue.data(), stringValue.size());
+    }
+    else if (type == KJS::BooleanType) {
+        jclass JSObjectClass = env->FindClass ("java/lang/Boolean");
+        jmethodID constructorID = env->GetMethodID (JSObjectClass, "<init>", "(Z)V");
+        if (constructorID != NULL) {
+            result = env->NewObject (JSObjectClass, constructorID, (jboolean)value.toBoolean(exec));
+        }
+    }
+    else {
+        // Create a JSObject.
+        jlong nativeHandle;
+        
+        if (type == KJS::ObjectType){
+            KJS::ObjectImp *imp = static_cast<KJS::ObjectImp*>(value.imp());
+            
+            // We either have a wrapper around a Java instance or a JavaScript
+            // object.  If we have a wrapper around a Java instance, return that
+            // instance, otherwise create a new Java JSObject with the ObjectImp*
+            // as it's nativeHandle.
+            if (strcmp(imp->classInfo()->className, "RuntimeObject") == 0) {
+                KJS::RuntimeObjectImp *runtimeImp = static_cast<KJS::RuntimeObjectImp*>(value.imp());
+                Bindings::JavaInstance *runtimeInstance = static_cast<Bindings::JavaInstance *>(runtimeImp->getInternalInstance());
+                return runtimeInstance->javaInstance();
+            }
+            else {
+                nativeHandle = ptr_to_jlong(imp);
+                
+                // Bump our 'meta' reference count for the imp.  We maintain the reference
+                // until either finalize is called or the applet shuts down.
+                addJavaReference (root, imp);
+            }
+        }
+        // All other types will result in an undefined object.
+        else {
+            nativeHandle = UndefinedHandle;
+        }
+        
+        // Now create the Java JSObject.
+        jclass JSObjectClass = env->FindClass ("apple/applet/JSObject");
+        jmethodID constructorID = env->GetMethodID (JSObjectClass, "<init>", "(J)V");
+        if (constructorID != NULL) {
+            result = env->NewObject (JSObjectClass, constructorID, nativeHandle);
+        }
+    }
+    
+    return result;
+}
+
+KJS::Value JSObject::convertJObjectToValue (jobject theObject)
+{
+    // Instances of netscape.javascript.JSObject get converted back to
+    // JavaScript objects.  All other objects are wrapped.  It's not
+    // possible to pass primitive types from the Java to JavaScript.
+    // See section 22.7 of 'JavaScript:  The Definitive Guide, 4th Edition',
+    // figure 22-4.
+    jobject classOfInstance = callJNIObjectMethod(theObject, "getClass", "()Ljava/lang/Class;");
+    jstring className = (jstring)callJNIObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");
+    if (strcmp(Bindings::JavaString(className).characters(), "netscape.javascript.JSObject") == 0) {
+        // Pull the nativeJSObject value from the Java instance.  This is a
+        // pointer to the ObjectImp.
+        JNIEnv *env = getJNIEnv();
+        jfieldID fieldID = env->GetFieldID((jclass)classOfInstance, "nativeJSObject", "long");
+        if (fieldID == NULL) {
+            return KJS::Undefined();
+        }
+        jlong nativeHandle = env->GetLongField(theObject, fieldID);
+        if (nativeHandle == UndefinedHandle) {
+            return KJS::Undefined();
+        }
+        KJS::ObjectImp *imp = static_cast<KJS::ObjectImp*>(jlong_to_impptr(nativeHandle));
+        return KJS::Object(const_cast<KJS::ObjectImp*>(imp));
+    }
+
+    return KJS::Object(new KJS::RuntimeObjectImp(new Bindings::JavaInstance (theObject)));
+}
+
+KJS::List JSObject::listFromJArray(jobjectArray jArray) const
+{
+    JNIEnv *env = getJNIEnv();
+    long i, numArgs = env->GetArrayLength (jArray);
+    KJS::List aList;
+    
+    for (i = 0; i < numArgs; i++) {
+        jobject anArg = env->GetObjectArrayElement ((jobjectArray)jArray, i);
+        aList.append (convertJObjectToValue(anArg));
+    }
+    return aList;
+}
+
 }
 
 extern "C" {
@@ -541,7 +673,7 @@ extern "C" {
 jlong KJS_JSCreateNativeJSObject (JNIEnv *env, jclass clazz, jstring jurl, jlong nativeHandle, jboolean ctx)
 {
     JSObjectCallContext context;
-    context.type = GetWindow;
+    context.type = CreateNative;
     context.nativeHandle = nativeHandle;
     return JSObject::invoke (&context).j;
 }
diff --git a/JavaScriptCore/bindings/jni_jsobject.h b/JavaScriptCore/bindings/jni_jsobject.h
index 07ab628..fc9606e 100644
--- a/JavaScriptCore/bindings/jni_jsobject.h
+++ b/JavaScriptCore/bindings/jni_jsobject.h
@@ -82,7 +82,7 @@ private:
 };
 
 enum JSObjectCallType {
-    GetWindow,
+    CreateNative,
     Call,
     Eval,
     GetMember,
@@ -111,6 +111,7 @@ class JSObject
 public:
     JSObject(jlong nativeHandle);
     
+    static jlong createNative(jlong nativeHandle);
     jobject call(jstring methodName, jobjectArray args) const;
     jobject eval(jstring script) const;
     jobject getMember(jstring memberName) const;
@@ -120,10 +121,12 @@ public:
     void setSlot(jint index, jobject value) const;
     jstring toString() const;
     void finalize() const;
-
-    static jlong getWindow(jlong nativeHandle);
     
     static jvalue invoke (JSObjectCallContext *context);
+
+    static jobject convertValueToJObject (KJS::ExecState *exec, const RootObject *root, KJS::Value value);
+    static KJS::Value convertJObjectToValue (jobject theObject);
+    KJS::List listFromJArray(jobjectArray jArray) const;
     
 private:
     const Bindings::RootObject *_root;
diff --git a/JavaScriptCore/bindings/runtime_method.cpp b/JavaScriptCore/bindings/runtime_method.cpp
index 8435137..eb132a6 100644
--- a/JavaScriptCore/bindings/runtime_method.cpp
+++ b/JavaScriptCore/bindings/runtime_method.cpp
@@ -42,7 +42,6 @@ RuntimeMethodImp::~RuntimeMethodImp()
 
 Value RuntimeMethodImp::get(ExecState *exec, const Identifier &propertyName) const
 {
-    fprintf(stderr,"%s: this=%p, %s\n", __PRETTY_FUNCTION__, this, propertyName.ascii());
     // Find the arguments from the closest context.
     if (propertyName == argumentsPropertyName) {
         ContextImp *context = exec->_context;
@@ -82,16 +81,12 @@ Value RuntimeMethodImp::call(ExecState *exec, Object &thisObj, const List &args)
 
 CodeType RuntimeMethodImp::codeType() const
 {
-    fprintf(stderr,"%s: this=%p\n", __PRETTY_FUNCTION__, this);
-    // NOTE:  What is this?  I don't think this is ever called.
     return FunctionCode;
 }
 
 
 Completion RuntimeMethodImp::execute(ExecState *exec)
 {
-    fprintf(stderr,"%s: this=%p\n", __PRETTY_FUNCTION__, this);
-    // NOTE:  What is this?  I don't think this is ever called.
     return Completion(Normal, Undefined());
 }
 
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index c4c6d75..5fec647 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,12 @@
+2003-12-15  Richard Williamson   <rjw at apple.com>
+
+	Return 0 if the view doesn't have a bridge.
+
+        Reviewed by John.
+
+        * kwq/WebCoreBridge.mm:
+        (rootForView):
+
 2003-12-15  David Hyatt  <hyatt at apple.com>
 
 	Fix for 3508792.  Remove tables and cells as AxObjects.
diff --git a/WebCore/kwq/WebCoreBridge.mm b/WebCore/kwq/WebCoreBridge.mm
index 00194ac..3492df2 100644
--- a/WebCore/kwq/WebCoreBridge.mm
+++ b/WebCore/kwq/WebCoreBridge.mm
@@ -109,14 +109,17 @@ static RootObject *rootForView(void *v)
 {
     NSView *aView = (NSView *)v;
     WebCoreBridge *aBridge = [[WebCoreViewFactory sharedFactory] bridgeForView:aView];
-    KWQKHTMLPart *part = [aBridge part];
-    RootObject *root = new RootObject(v);    // The root gets deleted by JavaScriptCore.
-    
-    root->setRootObjectImp (static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(part)));
-    root->setInterpreter (KJSProxy::proxy(part)->interpreter());
-    part->addPluginRootObject (root);
+    if (aBridge) {
+        KWQKHTMLPart *part = [aBridge part];
+        RootObject *root = new RootObject(v);    // The root gets deleted by JavaScriptCore.
         
-    return root;
+        root->setRootObjectImp (static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(part)));
+        root->setInterpreter (KJSProxy::proxy(part)->interpreter());
+        part->addPluginRootObject (root);
+            
+        return root;
+    }
+    return 0;
 }
 
 @implementation WebCoreBridge

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list