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


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

    JavaScriptCore:
    	LiveConnect:  Part 1 of supporting JS bindings to
    	native language arrays.
    
            Reviewed by Chris.
    
            * JavaScriptCore.pbproj/project.pbxproj:
            * bindings/jni/jni_runtime.cpp:
            (JavaField::JavaField):
            (convertJObjectToArray):
            (JavaField::valueFromInstance):
            (JavaField::setValueToInstance):
            * bindings/jni/jni_runtime.h:
            * bindings/runtime.cpp:
            (Instance::setValueOfField):
            * bindings/runtime.h:
            (Bindings::Array::~Array):
    
    Tests:
            Added tests to access Java arrays.
    
            Reviewed by Chris.
    
            * LiveConnect/Blink/Blink.java:
            (Blink):
            (Blink.init):
            * LiveConnect/Blink/test.html:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@5710 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 67b6c9d..9c1d8ac 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,22 @@
+2003-12-05  Richard Williamson   <rjw at apple.com>
+
+	LiveConnect:  Part 1 of supporting JS bindings to
+	native language arrays.
+
+        Reviewed by Chris.
+
+        * JavaScriptCore.pbproj/project.pbxproj:
+        * bindings/jni/jni_runtime.cpp:
+        (JavaField::JavaField):
+        (convertJObjectToArray):
+        (JavaField::valueFromInstance):
+        (JavaField::setValueToInstance):
+        * bindings/jni/jni_runtime.h:
+        * bindings/runtime.cpp:
+        (Instance::setValueOfField):
+        * bindings/runtime.h:
+        (Bindings::Array::~Array):
+
 2003-12-04  Richard Williamson   <rjw at apple.com>
 
 	LiveConnect:  Moved defaultValue into concrete implementation because
diff --git a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
index 10f5b13..99663a5 100644
--- a/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
+++ b/JavaScriptCore/JavaScriptCore.pbproj/project.pbxproj
@@ -241,6 +241,7 @@
 				517D52DF056BF2F6003851BD,
 				517D534A056BFB5D003851BD,
 				51A58A90057D3A6A00A3E942,
+				7073BE3F0581291E005EE2C9,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -300,6 +301,7 @@
 				517D52DE056BF2F6003851BD,
 				517D5349056BFB5D003851BD,
 				51A58A8F057D3A6A00A3E942,
+				7073BE3E0581291E005EE2C9,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -586,6 +588,8 @@
 				51856D900562EE95008B9D83,
 				704FD44505698F17003DBED9,
 				511B0870056468730080E486,
+				7073BE3C0581291E005EE2C9,
+				7073BE3D0581291E005EE2C9,
 				51A58A8D057D3A6A00A3E942,
 				51A58A8E057D3A6A00A3E942,
 				70B16A260569A10900DB756D,
@@ -886,6 +890,36 @@
 			settings = {
 			};
 		};
+		7073BE3C0581291E005EE2C9 = {
+			expectedFileType = sourcecode.cpp.cpp;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = runtime_array.cpp;
+			path = bindings/runtime_array.cpp;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		7073BE3D0581291E005EE2C9 = {
+			expectedFileType = sourcecode.c.h;
+			fileEncoding = 30;
+			isa = PBXFileReference;
+			name = runtime_array.h;
+			path = bindings/runtime_array.h;
+			refType = 4;
+			sourceTree = "<group>";
+		};
+		7073BE3E0581291E005EE2C9 = {
+			fileRef = 7073BE3C0581291E005EE2C9;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		7073BE3F0581291E005EE2C9 = {
+			fileRef = 7073BE3D0581291E005EE2C9;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		70B16A260569A10900DB756D = {
 			expectedFileType = sourcecode.cpp.cpp;
 			fileEncoding = 30;
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index bc27eb4..6a84560 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -52,10 +52,70 @@ JavaField::JavaField (JNIEnv *env, jobject aField)
     // Get field name
     jstring fieldName = (jstring)callJNIObjectMethod (aField, "getName", "()Ljava/lang/String;");
     _name = JavaString(env, fieldName);
-    
+
+    printf ("%s: %s (%d)\n", _name.characters(), _type.characters(), _JNIType);
+
     _field = new JavaInstance(aField);
 }
 
+KJS::Value convertJObjectToArray (KJS::ExecState *exec, jobject anObject, const char *type)
+{
+#if 0
+    if (type[0] != '[')
+        return Undefined();
+    
+    JNIType arrayType = JNITypeFromClassName(type+1);
+    switch (arrayType) {
+        case object_type: {
+            jobjectArray objectArray = (jObjectArray)anObject;
+            break;
+        }
+            
+        case boolean_type: {
+            jbooleanArray boolArray = (jbooleanArray)anObject;
+            break;
+        }
+            
+        case byte_type: {
+            jbyteArray byteArray = (jbyteArray)anObject;
+            break;
+        }
+            
+        case char_type: {
+            jcharArray charArray = (jcharArray)anObject;
+            break;
+        }
+            
+        case short_type: {
+            jshortArray shortArray = (jshortArray)anObject;
+            break;
+        }
+            
+        case int_type: {
+            jintArray intArray = (jintArray)anObject;
+            break;
+        }
+            
+        case long_type: {
+            jlongArray longArray = (jlongArray)anObject;
+            break;
+        }
+            
+        case float_type: {
+            jfloatArray floatArray = (jfloatArray)anObject;
+            break;
+        }
+            
+        case double_type: {
+            jdoubleArray doubleArray = (jdoubleArray)anObject;
+            break;
+        }
+        default:
+    }
+#endif
+    return Undefined();
+}
+
 KJS::Value JavaField::valueFromInstance(const Instance *i) const 
 {
     const JavaInstance *instance = static_cast<const JavaInstance *>(i);
@@ -65,7 +125,14 @@ KJS::Value JavaField::valueFromInstance(const Instance *i) const
     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)));
+
+            const char *arrayType = type();
+            if (arrayType[0] == '[') {
+                return convertJObjectToArray (0, anObject, arrayType);
+            }
+            else {
+                return KJS::Object(new RuntimeObjectImp(new JavaInstance ((jobject)anObject)));
+            }
         }
         break;
             
@@ -98,7 +165,7 @@ KJS::Value JavaField::valueFromInstance(const Instance *i) const
     return Undefined();
 }
 
-void JavaField::setValueToInstance(KJS::ExecState *exec, const Instance *i, KJS::Value aValue) const
+void JavaField::setValueToInstance(KJS::ExecState *exec, const Instance *i, const KJS::Value &aValue) const
 {
     const JavaInstance *instance = static_cast<const JavaInstance *>(i);
     jobject jinstance = instance->javaInstance();
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 5058b52..ce746d3 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -186,7 +186,7 @@ public:
     }
     
     virtual KJS::Value valueFromInstance(const Instance *instance) const;
-    virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, KJS::Value aValue) const;
+    virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;
     
     virtual const char *name() const { return _name.characters(); }
     virtual RuntimeType type() const { return _type.characters(); }
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index 58fc2ed..42b2f89 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -41,6 +41,6 @@ Value Instance::getValueOfField (const Field *aField) const {
     return aField->valueFromInstance (this);
 }
 
-void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, Value aValue) const {  
+void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, const Value &aValue) const {  
     return aField->setValueToInstance (exec, this, aValue);
 }
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index a063d86..4d55471 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -61,7 +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 void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const = 0;
 
     virtual ~Field() {};
 };
@@ -107,7 +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 void setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const;
     
     virtual KJS::Value invokeMethod (KJS::ExecState *exec, const Method *method, const KJS::List &args) = 0;
     
@@ -118,6 +118,15 @@ public:
     virtual ~Instance() {};
 };
 
+class Array
+{
+public:
+    virtual void setValueAt(unsigned int index, const KJS::Value &aValue) const = 0;
+    virtual KJS::Value valueAt(unsigned int index) const = 0;
+    
+    virtual ~Array() {};
+};
+
 const char *signatureForParameters(const KJS::List &aList);
 
 };
diff --git a/JavaScriptCore/bindings/runtime_array.cpp b/JavaScriptCore/bindings/runtime_array.cpp
new file mode 100644
index 0000000..97ec607
--- /dev/null
+++ b/JavaScriptCore/bindings/runtime_array.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (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 <identifier.h>
+#include <interpreter.h>
+#include <runtime.h>
+#include <runtime_array.h>
+
+using namespace KJS;
+
+const ClassInfo RuntimeArrayImp::info = {"RuntimeArray", 0, 0, 0};
+
+RuntimeArrayImp::RuntimeArrayImp(Bindings::Array *a)
+{
+    // Always takes ownership of concrete array.
+    array = a;
+}
+
+RuntimeArrayImp::~RuntimeArrayImp()
+{
+    delete array;
+}
+
+
+Value RuntimeArrayImp::get(ExecState *exec, const Identifier &propertyName) const
+{
+    if (propertyName == lengthPropertyName)
+        return Number(length);
+    
+    bool ok;
+    unsigned index = propertyName.toArrayIndex(&ok);
+    if (ok) {
+        if (index >= length)
+            return Undefined();
+        return getConcreteArray()->valueAt(index);
+    }
+    
+    return ObjectImp::get(exec, propertyName);
+}
+
+Value RuntimeArrayImp::get(ExecState *exec, unsigned index) const
+{
+    if (index >= length)
+        return Undefined();
+    return getConcreteArray()->valueAt(index);
+}
+
+void RuntimeArrayImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
+{
+    if (propertyName == lengthPropertyName) {
+        Object err = Error::create(exec,RangeError);
+        exec->setException(err);
+        return;
+    }
+    
+    bool ok;
+    unsigned index = propertyName.toArrayIndex(&ok);
+    if (ok) {
+        getConcreteArray()->setValueAt(index, value);
+        return;
+    }
+    
+    ObjectImp::put(exec, propertyName, value, attr);
+}
+
+void RuntimeArrayImp::put(ExecState *exec, unsigned index, const Value &value, int attr)
+{
+    if (index >= length) {
+        Object err = Error::create(exec,RangeError);
+        exec->setException(err);
+        return;
+    }
+    
+    getConcreteArray()->setValueAt(index, value);
+}
+
+
+bool RuntimeArrayImp::hasProperty(ExecState *exec, const Identifier &propertyName) const
+{
+    if (propertyName == lengthPropertyName)
+        return true;
+    
+    bool ok;
+    unsigned index = propertyName.toArrayIndex(&ok);
+    if (ok) {
+        if (index >= length)
+            return false;
+        return true;
+    }
+    
+    return ObjectImp::hasProperty(exec, propertyName);
+}
+
+bool RuntimeArrayImp::hasProperty(ExecState *exec, unsigned index) const
+{
+    if (index >= length)
+        return false;
+    return true;
+}
+
+bool RuntimeArrayImp::deleteProperty(ExecState *exec, const Identifier &propertyName)
+{
+    return false;
+}
+
+bool RuntimeArrayImp::deleteProperty(ExecState *exec, unsigned index)
+{
+    return false;
+}
diff --git a/WebCore/kwq/KWQAccObjectCache.h b/JavaScriptCore/bindings/runtime_array.h
similarity index 55%
copy from WebCore/kwq/KWQAccObjectCache.h
copy to JavaScriptCore/bindings/runtime_array.h
index 7320ad7..a1f1969 100644
--- a/WebCore/kwq/KWQAccObjectCache.h
+++ b/JavaScriptCore/bindings/runtime_array.h
@@ -20,33 +20,44 @@
                                         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
+#ifndef _RUNTIME_ARRAY_H_
+#define _RUNTIME_ARRAY_H_
 
-#include <CoreFoundation/CoreFoundation.h>
+#include <object.h>
 
-#ifdef __OBJC__
- at class KWQAccObject;
-#else
-class KWQAccObject;
-#endif
-
-namespace khtml {
-    class RenderObject;
-}
 
-class KWQAccObjectCache
-{
+namespace KJS {
+    
+class RuntimeArrayImp : public ObjectImp {
 public:
-    KWQAccObjectCache();
-    ~KWQAccObjectCache();
+    RuntimeArrayImp(Bindings::Array *i);
+    ~RuntimeArrayImp();
+    
+    virtual Value get(ExecState *exec, const Identifier &propertyName) const;
+    virtual Value get(ExecState *exec, unsigned index) const ;
+    virtual void put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr = None);
+    virtual void put(ExecState *exec, unsigned propertyName, const Value &value, int attr = None);
+    
+    virtual bool hasProperty(ExecState *exec, const Identifier &propertyName) const;
+    virtual bool hasProperty(ExecState *exec, unsigned propertyName) const;
+    virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
+    virtual bool deleteProperty(ExecState *exec, unsigned propertyName);
+    
+    virtual const ClassInfo *classInfo() const { return &info; }
     
-    KWQAccObject* accObject(khtml::RenderObject* renderer);
-    void setAccObject(khtml::RenderObject* renderer, KWQAccObject* obj);
-    void removeAccObject(khtml::RenderObject* renderer);
+    unsigned getLength() const { return length; }
     
-    void detach(khtml::RenderObject* renderer);
-        
+    Bindings::Array *getConcreteArray() const { return array; }
+
 private:
-    CFMutableDictionaryRef accCache;
+    static const ClassInfo info;
+    Bindings::Array *array;
+
+    unsigned length;
 };
+    
+}; // namespace KJS
+
+#endif

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list