/hg/release/icedtea6-1.7: - Adding last bits for full Java->JS a...

dbhole at icedtea.classpath.org dbhole at icedtea.classpath.org
Wed Jan 13 16:31:03 PST 2010


changeset eaf5d54cc7d1 in /hg/release/icedtea6-1.7
details: http://icedtea.classpath.org/hg/release/icedtea6-1.7?cmd=changeset;node=eaf5d54cc7d1
author: Deepak Bhole <dbhole at redhat.com>
date: Wed Jan 13 19:36:54 2010 -0500

	- Adding last bits for full Java->JS array element access (read and
	write) support.
	- Checking in initial version of LiveConnect tests (WIP)


diffstat:

24 files changed, 4647 insertions(+), 48 deletions(-)
.hgignore                                             |    1 
ChangeLog                                             |   46 
plugin/icedteanp/IcedTeaJavaRequestProcessor.cc       |    2 
plugin/icedteanp/IcedTeaPluginRequestProcessor.cc     |  118 +-
plugin/icedteanp/IcedTeaPluginUtils.cc                |    6 
plugin/tests/LiveConnect/DummyObject.java             |   15 
plugin/tests/LiveConnect/OverloadTestHelper1.java     |    1 
plugin/tests/LiveConnect/OverloadTestHelper2.java     |    1 
plugin/tests/LiveConnect/OverloadTestHelper3.java     |    1 
plugin/tests/LiveConnect/PluginTest.java              |  699 ++++++++++++++
plugin/tests/LiveConnect/build                        |   18 
plugin/tests/LiveConnect/common.js                    |  215 ++++
plugin/tests/LiveConnect/index.html                   |   89 +
plugin/tests/LiveConnect/jjs_func_parameters_tests.js |  107 ++
plugin/tests/LiveConnect/jjs_func_rettype_tests.js    |   61 +
plugin/tests/LiveConnect/jjs_get_tests.js             |  114 ++
plugin/tests/LiveConnect/jjs_set_tests.js             |  314 ++++++
plugin/tests/LiveConnect/jsj_func_overload_tests.js   |  181 +++
plugin/tests/LiveConnect/jsj_func_parameters_tests.js |  216 ++++
plugin/tests/LiveConnect/jsj_func_rettype_tests.js    |  262 +++++
plugin/tests/LiveConnect/jsj_get_tests.js             |  260 +++++
plugin/tests/LiveConnect/jsj_set_tests.js             |  318 ++++++
plugin/tests/LiveConnect/jsj_type_casting_tests.js    |  825 +++++++++++++++++
plugin/tests/LiveConnect/jsj_type_conversion_tests.js |  825 +++++++++++++++++

diffs (truncated from 4929 to 500 lines):

diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 .hgignore
--- a/.hgignore	Wed Jan 13 21:32:58 2010 +0000
+++ b/.hgignore	Wed Jan 13 19:36:54 2010 -0500
@@ -469,3 +469,4 @@ pulse-java.jar
 pulse-java.jar
 hotspot.tar.gz
 ports/hotspot/src/cpu/zero/vm/bytecodes_arm.s
+plugin/tests/LiveConnect/*jar
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 ChangeLog
--- a/ChangeLog	Wed Jan 13 21:32:58 2010 +0000
+++ b/ChangeLog	Wed Jan 13 19:36:54 2010 -0500
@@ -1,3 +1,49 @@ 2010-01-13 Andrew John Hughes  <ahughes@
+2010-01-13  Deepak Bhole <dbhole at redhat.com>
+
+	* plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
+	(newMessageOnBus): Service GetSlot and SetSlot requests.
+	(call): Create Java object from result only if it is non-null.
+	(setMember): Pass a preset identifier to _setMember. Handle array slot
+	setting.
+	(sendMember): Handle array slot read.
+	(queue_processor): Service GetSlot and SetSlot requests.
+	(_setMember): Work with property NPIdentifier instead of name string.
+	(_getMember): Same.
+	* plugin/icedteanp/IcedTeaPluginUtils.cc
+	(isObjectJSArray): Handle void constructor objects like 'window'.
+	* plugin/tests/LiveConnect/DummyObject.java: New file. Helper for plugin 
+	tests.
+	* plugin/tests/LiveConnect/OverloadTestHelper1.java: Same.
+	* plugin/tests/LiveConnect/OverloadTestHelper2.java: Same.
+	* plugin/tests/LiveConnect/OverloadTestHelper3.java: Same.
+	* plugin/tests/LiveConnect/PluginTest.java: New file. Plugin test applet to 
+	drive LiveConnect tests.
+	* plugin/tests/LiveConnect/build: New build. Build file for plugin tests.
+	* plugin/tests/LiveConnect/common.js: New file. Contains common
+	LiveConnect test functions.
+	* plugin/tests/LiveConnect/index.html: New file. Index from which
+	LiveConnect tests can be launched.
+	* plugin/tests/LiveConnect/jjs_func_parameters_tests.js: New file.
+	Contains Java -> JS parameter passing tests.
+	* plugin/tests/LiveConnect/jjs_func_rettype_tests.js: New file. Contains
+	Java -> JS invocation return type read tests.
+	* plugin/tests/LiveConnect/jjs_get_tests.js: New file. Contains Java ->
+	JS variable read tests.
+	* plugin/tests/LiveConnect/jjs_set_tests.js: New file. Contains Java -> JS
+	variable write tests.
+	* plugin/tests/LiveConnect/jsj_func_overload_tests.js: New file. Contains
+	overload resolution tests for JS -> Java invocation.
+	* plugin/tests/LiveConnect/jsj_func_parameters_tests.js: New file.
+	Contains JS -> Java parameter passing tests.
+	* plugin/tests/LiveConnect/jsj_func_rettype_tests.js: New file. Contains
+	JS -> Java invocation return type read tests.
+	* plugin/tests/LiveConnect/jsj_get_tests.js: New file. Contains JS -> Java
+	variable read tests.
+	* plugin/tests/LiveConnect/jsj_set_tests.js: New file. Contains JS -> Java
+	variable write tests.
+	* plugin/tests/LiveConnect/jsj_type_casting_tests.js: New file. Contains
+	JS -> Java type conversion tests.
+
 2010-01-13 Andrew John Hughes  <ahughes at redhat.com>
 
 	* Makefile.am:
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/icedteanp/IcedTeaJavaRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Wed Jan 13 21:32:58 2010 +0000
+++ b/plugin/icedteanp/IcedTeaJavaRequestProcessor.cc	Wed Jan 13 19:36:54 2010 -0500
@@ -899,7 +899,7 @@ createJavaObjectFromVariant(NPP instance
             alreadyCreated = true;
         } else
         {
-            PLUGIN_DEBUG_0ARG("NPObject is not a Java object");
+            PLUGIN_DEBUG_0ARG("NPObject is not a Java object\n");
             NPIdentifier length_id = browser_functions.getstringidentifier("length");
 
             // FIXME: We currently only handle <= 2 dim arrays. Do we really need more though?
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
--- a/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Wed Jan 13 21:32:58 2010 +0000
+++ b/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc	Wed Jan 13 19:36:54 2010 -0500
@@ -117,6 +117,8 @@ PluginRequestProcessor::newMessageOnBus(
                    command == "SetMember" ||
                    command == "ToString"  ||
                    command == "Call"      ||
+                   command == "GetSlot"   ||
+                   command == "SetSlot"   ||
                    command == "Eval")
         {
 
@@ -331,7 +333,14 @@ PluginRequestProcessor::call(std::vector
 
     NPVariant* result_variant = (NPVariant*) IcedTeaPluginUtilities::stringToJSID(thread_data.result);
     std::string result_variant_jniid = std::string();
-    createJavaObjectFromVariant(instance, *result_variant, &result_variant_jniid);
+
+    if (result_variant)
+    {
+        createJavaObjectFromVariant(instance, *result_variant, &result_variant_jniid);
+    } else
+    {
+        result_variant_jniid = "0";
+    }
 
     IcedTeaPluginUtilities::constructMessagePrefix(0, &response);
     response += " JavaScriptCall ";
@@ -408,11 +417,11 @@ PluginRequestProcessor::setMember(std::v
 PluginRequestProcessor::setMember(std::vector<std::string>* message_parts)
 {
     std::string propertyNameID;
-    std::string property_name = std::string();
     std::string value = std::string();
 
     NPP instance;
     NPVariant* member;
+    NPIdentifier property_identifier;
 
     JavaRequestProcessor java_request = JavaRequestProcessor();
     JavaResultData* java_result;
@@ -434,17 +443,22 @@ PluginRequestProcessor::setMember(std::v
 
     instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(member);
 
-    java_result = java_request.getString(propertyNameID);
-
-    // the result we want is in result_string (assuming there was no error)
-    if (java_result->error_occurred)
-    {
-        printf("Unable to get member name for setMember. Error occurred: %s\n", java_result->error_msg);
-        //goto cleanup;
-    }
-
-    // Copy into local variable before disposing the object
-    property_name.append(*(java_result->return_string));
+    if (message_parts->at(2) == "SetSlot")
+    {
+        property_identifier = browser_functions.getintidentifier(atoi(message_parts->at(4).c_str()));
+    } else
+    {
+        java_result = java_request.getString(propertyNameID);
+
+        // the result we want is in result_string (assuming there was no error)
+        if (java_result->error_occurred)
+        {
+            printf("Unable to get member name for setMember. Error occurred: %s\n", java_result->error_msg);
+            //goto cleanup;
+        }
+
+        property_identifier = browser_functions.getstringidentifier(java_result->return_string->c_str());
+    }
 
     AsyncCallThreadData thread_data = AsyncCallThreadData();
     thread_data.result_ready = false;
@@ -453,7 +467,7 @@ PluginRequestProcessor::setMember(std::v
 
     thread_data.parameters.push_back(instance);
     thread_data.parameters.push_back(NPVARIANT_TO_OBJECT(*member));
-    thread_data.parameters.push_back(&property_name);
+    thread_data.parameters.push_back(&property_identifier);
     thread_data.parameters.push_back(&value);
 
 #ifdef CHROMIUM_WORKAROUND
@@ -505,6 +519,8 @@ PluginRequestProcessor::sendMember(std::
     std::string jsObjectConstructorID = std::string();
     std::string response = std::string();
 
+    NPIdentifier member_identifier;
+
     int method_id;
     int instance_id;
     long reference;
@@ -517,16 +533,23 @@ PluginRequestProcessor::sendMember(std::
     parent_ptr = (NPVariant*) (IcedTeaPluginUtilities::stringToJSID(message_parts->at(3)));
     member_id += message_parts->at(4);
 
-    /** Request data from Java **/
-
-    // make a new request for getString, to get the name of the identifier
-    java_result = java_request.getString(member_id);
-
-    // the result we want is in result_string (assuming there was no error)
-    if (java_result->error_occurred)
-    {
-        printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
-        //goto cleanup;
+    /** Request data from Java if necessary **/
+    if (message_parts->at(2) == "GetSlot")
+    {
+        member_identifier = browser_functions.getintidentifier(atoi(member_id.c_str()));
+    } else
+    {
+        // make a new request for getString, to get the name of the identifier
+        java_result = java_request.getString(member_id);
+
+        // the result we want is in result_string (assuming there was no error)
+        if (java_result->error_occurred)
+        {
+            printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
+            //goto cleanup;
+        }
+
+        member_identifier = browser_functions.getstringidentifier(java_result->return_string->c_str());
     }
 
     /** Make an internal request for the main thread to handle, to get the member pointer **/
@@ -541,7 +564,7 @@ PluginRequestProcessor::sendMember(std::
     NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(parent_ptr);
     thread_data.parameters.push_back(instance);
     thread_data.parameters.push_back(NPVARIANT_TO_OBJECT(*parent_ptr));
-    thread_data.parameters.push_back(java_result->return_string);
+    thread_data.parameters.push_back(&member_identifier);
 
 #ifdef CHROMIUM_WORKAROUND
     // Workaround for chromium
@@ -609,7 +632,12 @@ PluginRequestProcessor::sendMember(std::
 
 
     IcedTeaPluginUtilities::constructMessagePrefix(0, &response);
-    response.append(" JavaScriptGetMember ");
+    if (message_parts->at(2) == "GetSlot")
+    {
+        response.append(" JavaScriptGetMember ");
+    } else {
+        response.append(" JavaScriptGetSlot ");
+    }
     response.append(java_result->return_string->c_str());
     plugin_to_java_bus->post(response.c_str());
 
@@ -678,6 +706,12 @@ queue_processor(void* data)
                 pthread_mutex_lock(&syn_write_mutex);
                 processor->sendMember(message_parts);
                 pthread_mutex_unlock(&syn_write_mutex);
+            } else if (command == "SetSlot")
+            {
+                // write methods are synchronized
+                pthread_mutex_lock(&syn_write_mutex);
+                processor->setMember(message_parts);
+                pthread_mutex_unlock(&syn_write_mutex);
             } else
             {
                 // Nothing matched
@@ -704,27 +738,25 @@ void
 void
 _setMember(void* data)
 {
-    std::string* property_name;
     std::string* value;
     std::string response = std::string();
 
     NPP instance;
     NPVariant value_variant = NPVariant();
     NPObject* member;
-    NPIdentifier property;
+    NPIdentifier* property;
 
     std::vector<void*> parameters = ((AsyncCallThreadData*) data)->parameters;
     instance = (NPP) parameters.at(0);
     member = (NPObject*) parameters.at(1);
-    property_name = (std::string*) parameters.at(2);
+    property = (NPIdentifier*) parameters.at(2);
     value = (std::string*) parameters.at(3);
 
-    PLUGIN_DEBUG_4ARG("Setting %s on instance %p, object %p to value %s\n", property_name->c_str(), instance, member, value->c_str());
+    PLUGIN_DEBUG_4ARG("Setting %s on instance %p, object %p to value %s\n", browser_functions.utf8fromidentifier(*property), instance, member, value->c_str());
 
     IcedTeaPluginUtilities::javaResultToNPVariant(instance, value, &value_variant);
 
-    property = browser_functions.getstringidentifier(property_name->c_str());
-    ((AsyncCallThreadData*) data)->call_successful = browser_functions.setproperty(instance, member, property, &value_variant);
+    ((AsyncCallThreadData*) data)->call_successful = browser_functions.setproperty(instance, member, *property, &value_variant);
 
     IcedTeaPluginUtilities::constructMessagePrefix(0, &response);
     response.append(" JavaScriptSetMember ");
@@ -737,31 +769,25 @@ void
 void
 _getMember(void* data)
 {
-    std::string* member_name;
-
     NPObject* parent_ptr;
     NPVariant* member_ptr = new NPVariant();
     std::string member_ptr_str = std::string();
     NPP instance;
-    NPIdentifier member_identifier;
 
     std::vector<void*> parameters = ((AsyncCallThreadData*) data)->parameters;
 
     instance = (NPP) parameters.at(0);
     parent_ptr = (NPObject*) parameters.at(1);
-    member_name = (std::string*) parameters.at(2);
-
-    // Get the corresponding windowId
-    member_identifier = browser_functions.getstringidentifier(member_name->c_str());
+    NPIdentifier* member_identifier = (NPIdentifier*) parameters.at(2);
 
     // Get the NPVariant corresponding to this member
-    PLUGIN_DEBUG_4ARG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier,member_name->c_str());
-
-    if (!browser_functions.hasproperty(instance, parent_ptr, member_identifier))
-    {
-        printf("%s not found!\n", member_name->c_str());
-    }
-    ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, member_identifier, member_ptr);
+    PLUGIN_DEBUG_4ARG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier, browser_functions.utf8fromidentifier(*member_identifier));
+
+    if (!browser_functions.hasproperty(instance, parent_ptr, *member_identifier))
+    {
+        printf("%s not found!\n", browser_functions.utf8fromidentifier(*member_identifier));
+    }
+    ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, *member_identifier, member_ptr);
 
     IcedTeaPluginUtilities::printNPVariant(*member_ptr);
 
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/icedteanp/IcedTeaPluginUtils.cc
--- a/plugin/icedteanp/IcedTeaPluginUtils.cc	Wed Jan 13 21:32:58 2010 +0000
+++ b/plugin/icedteanp/IcedTeaPluginUtils.cc	Wed Jan 13 19:36:54 2010 -0500
@@ -815,14 +815,18 @@ IcedTeaPluginUtilities::isObjectJSArray(
     NPVariant constructor_v = NPVariant();
     NPIdentifier constructor_id = browser_functions.getstringidentifier("constructor");
     browser_functions.getproperty(instance, object, constructor_id, &constructor_v);
-
     IcedTeaPluginUtilities::printNPVariant(constructor_v);
+
+    // void constructor => not an array
+    if (NPVARIANT_IS_VOID(constructor_v))
+        return false;
 
     NPObject* constructor = NPVARIANT_TO_OBJECT(constructor_v);
 
     NPVariant constructor_str;
     NPIdentifier toString = browser_functions.getstringidentifier("toString");
     browser_functions.invoke(instance, constructor, toString, NULL, 0, &constructor_str);
+    IcedTeaPluginUtilities::printNPVariant(constructor_str);
 
     std::string constructor_name = std::string();
 
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/tests/LiveConnect/DummyObject.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/tests/LiveConnect/DummyObject.java	Wed Jan 13 19:36:54 2010 -0500
@@ -0,0 +1,15 @@
+public class DummyObject {
+     private String str;
+     
+     public DummyObject(String s) {
+        this.str = s;
+     }
+     
+     public void setStr(String s) {
+        this.str = s;
+     }
+     
+     public String toString() {
+        return str;
+     }
+}
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/tests/LiveConnect/OverloadTestHelper1.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/tests/LiveConnect/OverloadTestHelper1.java	Wed Jan 13 19:36:54 2010 -0500
@@ -0,0 +1,1 @@
+public class OverloadTestHelper1 {}
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/tests/LiveConnect/OverloadTestHelper2.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/tests/LiveConnect/OverloadTestHelper2.java	Wed Jan 13 19:36:54 2010 -0500
@@ -0,0 +1,1 @@
+public class OverloadTestHelper2 extends OverloadTestHelper1 {}
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/tests/LiveConnect/OverloadTestHelper3.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/tests/LiveConnect/OverloadTestHelper3.java	Wed Jan 13 19:36:54 2010 -0500
@@ -0,0 +1,1 @@
+public class OverloadTestHelper3 extends  OverloadTestHelper2 {}
diff -r e3fb5ca2bab8 -r eaf5d54cc7d1 plugin/tests/LiveConnect/PluginTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/tests/LiveConnect/PluginTest.java	Wed Jan 13 19:36:54 2010 -0500
@@ -0,0 +1,699 @@
+import javax.swing.JApplet;
+import java.awt.Graphics;
+import java.awt.*;
+import java.applet.*;
+import java.awt.event.*;
+import netscape.javascript.JSObject;
+import java.lang.reflect.Array;
+
+public class PluginTest extends JApplet {
+
+    public int i = 42;
+    public double d = 42.42;
+    public float f = 42.1F;
+    public long l = 4294967296L;
+    public boolean b = true;
+    public char c = '\u2323';
+    public byte by = 43;
+    public String rs = "I'm a string!";
+    public String ss = "𠁎〒£$ǣ€𝍖";
+    public Object n = null;
+    public int[] ia = new int[5];
+
+    public Integer I = 24;
+    public Double D = 24.24;
+    public Float F = 24.124F;
+    public Long L = 6927694924L;
+    public Boolean B = false;
+    public Character C = '\u1526';
+    public Byte By = 34;
+    public Double[] Da1 = new Double[10];
+    public Double[] Da2 = null;
+
+    public char[] ca = new char[3];
+    public Character[] Ca = new Character[3];
+
+    public void setUpForGMTests() {
+        i = 42;
+        d = 42.42;
+        f = 42.1F;
+        l = 4294967296L;
+        b = true;
+        c = '\u2323';
+        by = 43;
+        rs = "I'm a string!";
+        ss = "𠁎〒£$ǣ€𝍖";
+        n = null;
+
+        I = 24;
+        D = 24.24;
+        F = 24.124F;
+        L = 6927694924L;
+        B = false;
+        C = '\u1526';
+        By = 34;
+
+        ia[4] = 1024;
+        Da1[9] = D;
+    }
+
+    public void setUpForSMTests() {
+        i = 0;
+        d = 0.0;
+        f = 0F;
+        l = 0L;
+        b = false;
+        c = 'A';
+        by = 0;
+        rs = "";
+        ss = "";
+        n = new String("non-null object");
+
+        I = 0;
+        D = 0.0;
+        F = 0F;
+        L = 0L;
+        B = false;
+        C = 'A';
+        By = null;
+
+        ia[4] = 0;
+        Da1[9] = D;
+    }
+
+    /*
+     *****************************************
+     * JS -> Java Parameter conversion tests *
+     *****************************************
+    */
+    public void setUpForReturnTests() {
+        i = 41;
+        d = 41.41;
+        f = 41.411F;
+        l = 4294967297L;
+        b = true;
+        c = '\u2329';
+        by = 44;
+        rs = "I'm a string too!";
+        ss = "𠁎〒£$ǣ€𝍖";
+        n = null;
+
+        I = 14;
+        D = 14.14;
+        F = 14.114F;
+        L = 6927694925L;
+        B = false;
+        C = '\u2417';
+        By = 46;
+    }
+
+    /*
+     **************************************
+     * JS -> Java invocation return tests *
+     **************************************
+    */
+
+    public int intReturnTest() { return i; }
+
+    public double doubleReturnTest() { return d; }
+
+    public float floatReturnTest() { return f; }
+
+    public long longReturnTest() { return l; }
+
+    public boolean booleanReturnTest() { return b; }
+
+    public char charReturnTest() { return c; }
+
+    public byte byteReturnTest() { return by; }
+    
+    public char[] charArrayReturnTest() { 
+        ca[0] = '\u2410';



More information about the distro-pkg-dev mailing list