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


The following commit has been merged in the debian/unstable branch:
commit b386908f3ad3c02177869882c1f3ad216b980cd3
Author: rjw <rjw at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Feb 18 21:58:35 2004 +0000

    	Added support for export NSArrays.
    
    	Updated valueAt() to take an ExecState so we can throw
    	JS exceptions.
    
    	Implemented excludeSelectorFromJavaScript: in ObjcClass.  This allows
    	ObjectiveC classes to control the visibility of their methods in
    	JavaScript.
    
            Reviewed by Ken.
    
            * bindings/jni/jni_runtime.cpp:
            (JavaField::valueFromInstance):
            (JavaArray::valueAt):
            * bindings/jni/jni_runtime.h:
            * bindings/objc/objc_class.mm:
            (ObjcClass::methodsNamed):
            * bindings/objc/objc_runtime.h:
            (KJS::Bindings::ObjcArray::getObjcArray):
            * bindings/objc/objc_runtime.mm:
            (ObjcField::valueFromInstance):
            (ObjcField::setValueToInstance):
            (ObjcArray::ObjcArray):
            (ObjcArray::~ObjcArray):
            (ObjcArray::operator=):
            (ObjcArray::setValueAt):
            (ObjcArray::valueAt):
            (ObjcArray::getLength):
            * bindings/objc/objc_utility.mm:
            (KJS::Bindings::convertValueToObjcValue):
            (KJS::Bindings::convertObjcValueToValue):
            * bindings/runtime.cpp:
            (Instance::getValueOfField):
            * bindings/runtime.h:
            * bindings/runtime_array.cpp:
            (RuntimeArrayImp::get):
            * bindings/runtime_object.cpp:
            (RuntimeObjectImp::get):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6097 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index fb287d2..82e69bf 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,44 @@
+2004-02-18  Richard Williamson   <rjw at apple.com>
+
+	Added support for export NSArrays.
+
+	Updated valueAt() to take an ExecState so we can throw
+	JS exceptions.
+
+	Implemented excludeSelectorFromJavaScript: in ObjcClass.  This allows
+	ObjectiveC classes to control the visibility of their methods in 
+	JavaScript.
+
+        Reviewed by Ken.
+
+        * bindings/jni/jni_runtime.cpp:
+        (JavaField::valueFromInstance):
+        (JavaArray::valueAt):
+        * bindings/jni/jni_runtime.h:
+        * bindings/objc/objc_class.mm:
+        (ObjcClass::methodsNamed):
+        * bindings/objc/objc_runtime.h:
+        (KJS::Bindings::ObjcArray::getObjcArray):
+        * bindings/objc/objc_runtime.mm:
+        (ObjcField::valueFromInstance):
+        (ObjcField::setValueToInstance):
+        (ObjcArray::ObjcArray):
+        (ObjcArray::~ObjcArray):
+        (ObjcArray::operator=):
+        (ObjcArray::setValueAt):
+        (ObjcArray::valueAt):
+        (ObjcArray::getLength):
+        * bindings/objc/objc_utility.mm:
+        (KJS::Bindings::convertValueToObjcValue):
+        (KJS::Bindings::convertObjcValueToValue):
+        * bindings/runtime.cpp:
+        (Instance::getValueOfField):
+        * bindings/runtime.h:
+        * bindings/runtime_array.cpp:
+        (RuntimeArrayImp::get):
+        * bindings/runtime_object.cpp:
+        (RuntimeObjectImp::get):
+
 2004-02-17  Richard Williamson   <rjw at apple.com>
 
 	Added String <-> NSString conversion.
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.cpp b/JavaScriptCore/bindings/jni/jni_runtime.cpp
index 9240c7c..99574b5 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.cpp
+++ b/JavaScriptCore/bindings/jni/jni_runtime.cpp
@@ -65,7 +65,7 @@ KJS::Value JavaArray::convertJObjectToArray (KJS::ExecState *exec, jobject anObj
     return KJS::Object(new RuntimeArrayImp(new JavaArray ((jobject)anObject, type)));
 }
 
-KJS::Value JavaField::valueFromInstance(const Instance *i) const 
+KJS::Value JavaField::valueFromInstance(KJS::ExecState *exec, const Instance *i) const 
 {
     const JavaInstance *instance = static_cast<const JavaInstance *>(i);
     jobject jinstance = instance->javaInstance();
@@ -380,7 +380,7 @@ void JavaArray::setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::
 }
 
 
-KJS::Value JavaArray::valueAt(unsigned int index) const
+KJS::Value JavaArray::valueAt(KJS::ExecState *exec, unsigned int index) const
 {
     JNIEnv *env = getJNIEnv();
     JNIType arrayType = JNITypeFromPrimitiveType(_type[1]);
diff --git a/JavaScriptCore/bindings/jni/jni_runtime.h b/JavaScriptCore/bindings/jni/jni_runtime.h
index 3c9a40f..454f7a3 100644
--- a/JavaScriptCore/bindings/jni/jni_runtime.h
+++ b/JavaScriptCore/bindings/jni/jni_runtime.h
@@ -181,7 +181,7 @@ public:
         return *this;
     }
     
-    virtual KJS::Value valueFromInstance(const Instance *instance) const;
+    virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;
     virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;
     
     virtual const char *name() const { return _name.UTF8String(); }
@@ -284,7 +284,7 @@ public:
     };
 
     virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;
-    virtual KJS::Value valueAt(unsigned int index) const;
+    virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;
     virtual unsigned int getLength() const;
     
     virtual ~JavaArray();
diff --git a/JavaScriptCore/bindings/objc/objc_class.mm b/JavaScriptCore/bindings/objc/objc_class.mm
index b980f05..89acf68 100644
--- a/JavaScriptCore/bindings/objc/objc_class.mm
+++ b/JavaScriptCore/bindings/objc/objc_class.mm
@@ -112,6 +112,16 @@ MethodList ObjcClass::methodsNamed(const char *_name) const
                 struct objc_method *objcMethod = &objcMethodList->method_list[i];
                 NSString *mappedName = 0;
             
+                // See if the class wants to exclude the selector from visibility in JavaScript.
+                if ([(id)thisClass respondsToSelector:@selector(excludeSelectorFromJavaScript:)]) {
+                    if ([(id)thisClass excludeSelectorFromJavaScript:objcMethod->method_name]) {
+                        continue;
+                    }
+                }
+                
+                // See if the class want to provide a different name for the selector in JavaScript.
+                // Note that we do not do any checks to guarantee uniqueness. That's the responsiblity
+                // of the class.
                 if ([(id)thisClass respondsToSelector:@selector(JavaScriptNameForSelector:)]){
                     mappedName = [(id)thisClass JavaScriptNameForSelector: objcMethod->method_name];
                 }
diff --git a/JavaScriptCore/bindings/objc/objc_runtime.h b/JavaScriptCore/bindings/objc/objc_runtime.h
index 78a5952..2e1bc94 100644
--- a/JavaScriptCore/bindings/objc/objc_runtime.h
+++ b/JavaScriptCore/bindings/objc/objc_runtime.h
@@ -59,7 +59,7 @@ public:
         return *this;
     };
         
-    virtual KJS::Value valueFromInstance(const Instance *instance) const;
+    virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;
     virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;
     
     virtual const char *name() const;
@@ -105,6 +105,29 @@ private:
     const char *_selector;
 };
 
+class ObjcArray : public Array
+{
+public:
+    ObjcArray (ObjectStructPtr a);
+
+    ObjcArray (const ObjcArray &other);
+
+    ObjcArray &operator=(const ObjcArray &other);
+    
+    virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;
+    virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;
+    virtual unsigned int getLength() const;
+    
+    virtual ~ObjcArray();
+
+    ObjectStructPtr getObjcArray() const { return _array; }
+
+    static KJS::Value convertObjcArrayToArray (KJS::ExecState *exec, ObjectStructPtr anObject);
+
+private:
+    ObjectStructPtr _array;
+};
+
 } // namespace Bindings
 
 } // namespace KJS
diff --git a/JavaScriptCore/bindings/objc/objc_runtime.mm b/JavaScriptCore/bindings/objc/objc_runtime.mm
index 89de8f6..e48b874 100644
--- a/JavaScriptCore/bindings/objc/objc_runtime.mm
+++ b/JavaScriptCore/bindings/objc/objc_runtime.mm
@@ -24,6 +24,9 @@
  */
 #include <Foundation/Foundation.h>
 
+
+#include <JavaScriptCore/internal.h>
+
 #include <objc_instance.h>
 
 #include <runtime_array.h>
@@ -33,6 +36,7 @@
 using namespace KJS;
 using namespace KJS::Bindings;
 
+// ---------------------- ObjcMethod ----------------------
 
 ObjcMethod::ObjcMethod(ClassStructPtr aClass, const char *name)
 {
@@ -56,6 +60,8 @@ NSMethodSignature *ObjcMethod::getMethodSignature() const
     return [(id)_objcClass instanceMethodSignatureForSelector:(SEL)_selector];
 }
 
+// ---------------------- ObjcField ----------------------
+
 
 ObjcField::ObjcField(Ivar ivar) 
 {
@@ -72,7 +78,7 @@ RuntimeType ObjcField::type() const
     return _ivar->ivar_type;
 }
 
-Value ObjcField::valueFromInstance(const Instance *instance) const
+Value ObjcField::valueFromInstance(KJS::ExecState *exec, const Instance *instance) const
 {
     Value aValue;
     char *ivarValuePtr = ((char *)(static_cast<const ObjcInstance*>(instance))->getObject() + _ivar->ivar_offset);
@@ -127,10 +133,10 @@ Value ObjcField::valueFromInstance(const Instance *instance) const
         }
         break;
         
-        
         case ObjcInvalidType:
         default: {
-            aValue = Undefined();
+            aValue = Error::create(exec, TypeError, "Invalid ObjectiveC type.");
+            exec->setException(aValue);
         }
         break;
     }
@@ -155,6 +161,8 @@ void ObjcField::setValueToInstance(KJS::ExecState *exec, const Instance *instanc
                 *(ObjectStructPtr *)(ivarValuePtr) = result.objectValue;
             }
             
+            // FIXME.  Deal with numbers.
+            
             // FIXME.  Deal with arrays.
             
             // FIXME.  Deal with strings.
@@ -193,10 +201,108 @@ void ObjcField::setValueToInstance(KJS::ExecState *exec, const Instance *instanc
         
         case ObjcInvalidType:
         default: {
-            // FIXME:  Throw an exception?
+            Object error = Error::create(exec, TypeError, "Invalid ObjectiveC type.");
+            exec->setException(error);
         }
         break;
     }
 }
 
+// ---------------------- ObjcArray ----------------------
+
+ObjcArray::ObjcArray (ObjectStructPtr a) 
+{
+    _array = [a retain];
+};
+
+ObjcArray::~ObjcArray () 
+{
+    [_array release];
+}
+
 
+ObjcArray::ObjcArray (const ObjcArray &other) : Array() 
+{
+    if (other._array != _array) {
+        [_array release];
+        _array = [other._array retain];
+    }
+};
+
+ObjcArray &ObjcArray::operator=(const ObjcArray &other) {
+    if (this == &other)
+        return *this;
+    
+    ObjectStructPtr _oldArray = _array;
+    _array = other._array;
+    [_array retain];
+    [_oldArray release];
+    
+    return *this;
+};
+
+void ObjcArray::setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const
+{
+    if (![_array respondsToSelector:@selector(insertObject:atIndex:)]) {
+        Object error = Error::create(exec, TypeError, "Array is not mutable.");
+        exec->setException(error);
+        return;
+    }
+
+    if (index > [_array count]) {
+        Object error = Error::create(exec, RangeError, "Index exceeds array size.");
+        exec->setException(error);
+        return;
+    }
+    
+    // Always try to convert the value to an ObjC object, so it can be placed in the
+    // array.
+    ObjcValue oValue = convertValueToObjcValue (exec, aValue, ObjcObjectType);
+
+NS_DURING
+
+    [_array insertObject:oValue.objectValue atIndex:index];
+
+NS_HANDLER
+    
+    Object error = Error::create(exec, GeneralError, "ObjectiveC exception.");
+    exec->setException(error);
+    
+NS_ENDHANDLER
+}
+
+
+KJS::Value ObjcArray::valueAt(KJS::ExecState *exec, unsigned int index) const
+{
+    ObjectStructPtr obj = 0;
+    Object error;
+    bool haveError = false;
+    
+    if (index > [_array count]) {
+        Object error = Error::create(exec, RangeError, "Index exceeds array size.");
+        exec->setException(error);
+        return error;
+    }
+    
+NS_DURING
+
+    obj = [_array objectAtIndex:index];
+    
+NS_HANDLER
+    
+    Object error = Error::create(exec, GeneralError, "ObjectiveC exception.");
+    exec->setException(error);
+    haveError = true;
+    
+NS_ENDHANDLER
+
+    if (haveError)
+        return error;
+        
+    return convertObjcValueToValue (exec, &obj, ObjcObjectType);
+}
+
+unsigned int ObjcArray::getLength() const
+{
+    return [_array count];
+}
diff --git a/JavaScriptCore/bindings/objc/objc_utility.mm b/JavaScriptCore/bindings/objc/objc_utility.mm
index 250698b..01adc68 100644
--- a/JavaScriptCore/bindings/objc/objc_utility.mm
+++ b/JavaScriptCore/bindings/objc/objc_utility.mm
@@ -82,7 +82,7 @@ void KJS::Bindings::JSMethodNameToObjCMethodName(const char *name, char *buffer,
 /*
 
     JavaScript to   ObjC
-    Number          coerced to char, short, int, long, float, or double as appropriate
+    Number          coerced to char, short, int, long, float, double, or NSNumber, as appropriate
     String          NSString
     wrapper         id
     Object          JavaScriptObject
@@ -119,6 +119,8 @@ ObjcValue KJS::Bindings::convertValueToObjcValue (KJS::ExecState *exec, KJS::Val
                 result.objectValue = string;
             }
             
+            // FIXME:  Convert scalars to NSNumber.
+            
             // FIXME:  Deal with other Object types by creating a JavaScriptObjects
         }
         break;
@@ -180,6 +182,7 @@ ObjcValue KJS::Bindings::convertValueToObjcValue (KJS::ExecState *exec, KJS::Val
     long
     float
     double
+    NSNumber        Number
     NSString        string
     NSArray         []
     id              wrapper
@@ -208,6 +211,9 @@ Value KJS::Bindings::convertObjcValueToValue (KJS::ExecState *exec, void *buffer
                 else if ([*obj isKindOfClass:[NSArray class]]) {
                     // FIXME:  Deal with NSArray to Array conversions.
                 }
+                else if ([*obj isKindOfClass:[NSNumber class]]) {
+                    // FIXME:  Deal with NSNumber to Number conversions.
+                }
                 else {
                     aValue = Object(new RuntimeObjectImp(new ObjcInstance (*obj)));
                 }
diff --git a/JavaScriptCore/bindings/runtime.cpp b/JavaScriptCore/bindings/runtime.cpp
index bab211a..0b48ade 100644
--- a/JavaScriptCore/bindings/runtime.cpp
+++ b/JavaScriptCore/bindings/runtime.cpp
@@ -82,8 +82,8 @@ MethodList &MethodList::operator=(const MethodList &other)
 }
 
 
-Value Instance::getValueOfField (const Field *aField) const {  
-    return aField->valueFromInstance (this);
+Value Instance::getValueOfField (KJS::ExecState *exec, const Field *aField) const {  
+    return aField->valueFromInstance (exec, this);
 }
 
 void Instance::setValueOfField (KJS::ExecState *exec, const Field *aField, const Value &aValue) const {  
diff --git a/JavaScriptCore/bindings/runtime.h b/JavaScriptCore/bindings/runtime.h
index 67b752e..f12db7d 100644
--- a/JavaScriptCore/bindings/runtime.h
+++ b/JavaScriptCore/bindings/runtime.h
@@ -67,7 +67,7 @@ public:
     virtual const char *name() const = 0;
     virtual RuntimeType type() const = 0;
 
-    virtual KJS::Value valueFromInstance(const Instance *instance) const = 0;
+    virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const = 0;
     virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const = 0;
 
     virtual ~Field() {};
@@ -139,7 +139,7 @@ public:
     
     virtual Class *getClass() const = 0;
     
-    virtual KJS::Value getValueOfField (const Field *aField) const;
+    virtual KJS::Value getValueOfField (KJS::ExecState *exec, const Field *aField) const;
     virtual void setValueOfField (KJS::ExecState *exec, const Field *aField, const KJS::Value &aValue) const;
     
     virtual KJS::Value invokeMethod (KJS::ExecState *exec, const MethodList &method, const KJS::List &args) = 0;
@@ -155,7 +155,7 @@ class Array
 {
 public:
     virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const = 0;
-    virtual KJS::Value valueAt(unsigned int index) const = 0;
+    virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const = 0;
     virtual unsigned int getLength() const = 0;
     virtual ~Array() {};
 };
diff --git a/JavaScriptCore/bindings/runtime_array.cpp b/JavaScriptCore/bindings/runtime_array.cpp
index f06795a..fa4e509 100644
--- a/JavaScriptCore/bindings/runtime_array.cpp
+++ b/JavaScriptCore/bindings/runtime_array.cpp
@@ -53,7 +53,7 @@ Value RuntimeArrayImp::get(ExecState *exec, const Identifier &propertyName) cons
     if (ok) {
         if (index >= getLength())
             return Undefined();
-        return getConcreteArray()->valueAt(index);
+        return getConcreteArray()->valueAt(exec, index);
     }
     
     return ObjectImp::get(exec, propertyName);
@@ -63,7 +63,7 @@ Value RuntimeArrayImp::get(ExecState *exec, unsigned index) const
 {
     if (index >= getLength())
         return Undefined();
-    return getConcreteArray()->valueAt(index);
+    return getConcreteArray()->valueAt(exec, index);
 }
 
 void RuntimeArrayImp::put(ExecState *exec, const Identifier &propertyName, const Value &value, int attr)
diff --git a/JavaScriptCore/bindings/runtime_object.cpp b/JavaScriptCore/bindings/runtime_object.cpp
index 784f09f..b8147fd 100644
--- a/JavaScriptCore/bindings/runtime_object.cpp
+++ b/JavaScriptCore/bindings/runtime_object.cpp
@@ -66,7 +66,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) {
-        return instance->getValueOfField (aField); 
+        return instance->getValueOfField (exec, aField); 
     }
     
     // Now check if a method with specified name exists, if so return a function object for

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list