Reviewed by Tim O. and Darin.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2006 23:57:33 +0000 (23:57 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Sep 2006 23:57:33 +0000 (23:57 +0000)
        Add support for more method signatures affecting ObjC methods called from JavaScript:
        - Added unsigned types and long long.
        - Allow methods that use const, oneway, bycopy and byref type modifiers.

        * bindings/objc/objc_instance.mm:
        (ObjcInstance::invokeMethod):
        * bindings/objc/objc_utility.h:
        (KJS::Bindings::):
        * bindings/objc/objc_utility.mm:
        (KJS::Bindings::convertValueToObjcValue):
        (KJS::Bindings::convertObjcValueToValue):
        (KJS::Bindings::objcValueTypeForType):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16310 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/objc/objc_instance.mm
JavaScriptCore/bindings/objc/objc_utility.h
JavaScriptCore/bindings/objc/objc_utility.mm

index 636a0de33a8a691ea072812d894bf0f379498d7b..b0913654cee6544a6375b9135d1839dc15ddbab1 100644 (file)
@@ -1,3 +1,20 @@
+2006-09-11  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Tim O. and Darin.
+
+        Add support for more method signatures affecting ObjC methods called from JavaScript:
+        - Added unsigned types and long long.
+        - Allow methods that use const, oneway, bycopy and byref type modifiers.
+
+        * bindings/objc/objc_instance.mm:
+        (ObjcInstance::invokeMethod):
+        * bindings/objc/objc_utility.h:
+        (KJS::Bindings::):
+        * bindings/objc/objc_utility.mm:
+        (KJS::Bindings::convertValueToObjcValue):
+        (KJS::Bindings::convertObjcValueToValue):
+        (KJS::Bindings::objcValueTypeForType):
+
 2006-09-05  Timothy Hatcher  <timothy@apple.com>
 
         Reviewed by Tim O.
index 4c732956b0d9eeb440e4d0abf1a3c43cd5e0a988..a02846bdc0e3241f3368a0db910fee94444910aa 100644 (file)
@@ -167,17 +167,25 @@ JSValue* ObjcInstance::invokeMethod(ExecState* exec, const MethodList &methodLis
                     [invocation setArgument:&value.objectValue atIndex:i];
                     break;
                 case ObjcCharType:
+                case ObjcUnsignedCharType:
                     [invocation setArgument:&value.charValue atIndex:i];
                     break;
                 case ObjcShortType:
+                case ObjcUnsignedShortType:
                     [invocation setArgument:&value.shortValue atIndex:i];
                     break;
                 case ObjcIntType:
+                case ObjcUnsignedIntType:
                     [invocation setArgument:&value.intValue atIndex:i];
                     break;
                 case ObjcLongType:
+                case ObjcUnsignedLongType:
                     [invocation setArgument:&value.longValue atIndex:i];
                     break;
+                case ObjcLongLongType:
+                case ObjcUnsignedLongLongType:
+                    [invocation setArgument:&value.longLongValue atIndex:i];
+                    break;
                 case ObjcFloatType:
                     [invocation setArgument:&value.floatValue atIndex:i];
                     break;
index 5e8dab757c175eace31868422490f32ca5944b4a..e57f3d3f1657389526178f2fb22c7d81367c5abb 100644 (file)
@@ -47,6 +47,7 @@ typedef union {
     short shortValue;
     int intValue;
     long longValue;
+    long long longLongValue;
     float floatValue;
     double doubleValue;
 } ObjcValue;
@@ -55,9 +56,15 @@ typedef enum {
     ObjcVoidType,
     ObjcObjectType,
     ObjcCharType,
+    ObjcUnsignedCharType,
     ObjcShortType,
+    ObjcUnsignedShortType,
     ObjcIntType,
+    ObjcUnsignedIntType,
     ObjcLongType,
+    ObjcUnsignedLongType,
+    ObjcLongLongType,
+    ObjcUnsignedLongLongType,
     ObjcFloatType,
     ObjcDoubleType,
     ObjcInvalidType
index 815cd5a3819aca85bd6f8e78647be2e526702c45..a0ee39bdccaa94d4fbd35c6e50954076b0360517 100644 (file)
 
 #include "WebScriptObject.h"
 
+#if !defined(_C_BYCOPY)
+#define _C_BYCOPY 'O'
+#endif
+
+#if !defined(_C_BYREF)
+#define _C_BYREF 'R'
+#endif
+
+#if !defined(_C_ONEWAY)
+#define _C_ONEWAY 'V'
+#endif
+
+#if !defined(_C_GCINVISIBLE)
+#define _C_GCINVISIBLE '!'
+#endif
+
 namespace KJS {
 namespace Bindings {
 
@@ -97,23 +113,22 @@ bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSi
     [], other       exception
 
 */
-ObjcValue convertValueToObjcValue (ExecState *exec, JSValue *value, ObjcValueType type)
+ObjcValue convertValueToObjcValue(ExecState *exec, JSValue *value, ObjcValueType type)
 {
     ObjcValue result;
     double d = 0;
 
     if (value->isNumber() || value->isString() || value->isBoolean())
         d = value->toNumber(exec);
-        
-    switch (type){
+
+    switch (type) {
         case ObjcObjectType: {
             Interpreter *originInterpreter = exec->dynamicInterpreter();
             const RootObject *originExecutionContext = rootForInterpreter(originInterpreter);
 
             Interpreter *interpreter = 0;
-            if (originInterpreter->isGlobalObject(value)) {
-                interpreter = originInterpreter->interpreterForGlobalObject (value);
-            }
+            if (originInterpreter->isGlobalObject(value))
+                interpreter = originInterpreter->interpreterForGlobalObject(value);
 
             if (!interpreter)
                 interpreter = originInterpreter;
@@ -124,55 +139,49 @@ ObjcValue convertValueToObjcValue (ExecState *exec, JSValue *value, ObjcValueTyp
                 newExecutionContext->setInterpreter (interpreter);
                 executionContext = newExecutionContext;
             }
+
             if (!webScriptObjectClass)
                 webScriptObjectClass = NSClassFromString(@"WebScriptObject");
             result.objectValue = [webScriptObjectClass _convertValueToObjcValue:value originExecutionContext:originExecutionContext executionContext:executionContext ];
         }
         break;
-        
-        
-        case ObjcCharType: {
-            result.charValue = (char)d;
-        }
-        break;
 
-        case ObjcShortType: {
+        case ObjcCharType:
+        case ObjcUnsignedCharType:
+            result.charValue = (char)d;
+            break;
+        case ObjcShortType:
+        case ObjcUnsignedShortType:
             result.shortValue = (short)d;
-        }
-        break;
-
-        case ObjcIntType: {
+            break;
+        case ObjcIntType:
+        case ObjcUnsignedIntType:
             result.intValue = (int)d;
-        }
-        break;
-
-        case ObjcLongType: {
+            break;
+        case ObjcLongType:
+        case ObjcUnsignedLongType:
             result.longValue = (long)d;
-        }
-        break;
-
-        case ObjcFloatType: {
+            break;
+        case ObjcLongLongType:
+        case ObjcUnsignedLongLongType:
+            result.longValue = (long long)d;
+            break;
+        case ObjcFloatType:
             result.floatValue = (float)d;
-        }
-        break;
-
-        case ObjcDoubleType: {
+            break;
+        case ObjcDoubleType:
             result.doubleValue = (double)d;
-        }
-        break;
-
-        case ObjcVoidType: {
-            bzero (&result, sizeof(ObjcValue));
-        }
-        break;
+            break;
+        case ObjcVoidType:
+            bzero(&result, sizeof(ObjcValue));
+            break;
 
         case ObjcInvalidType:
         default:
-        {
-            // FIXME:  throw an exception
-        }
-        break;
+            // FIXME: throw an exception?
+            break;
     }
+
     return result;
 }
 
@@ -239,12 +248,24 @@ JSValue* convertObjcValueToValue(ExecState* exec, void* buffer, ObjcValueType ty
         }
         case ObjcCharType:
             return jsNumber(*(char *)buffer);
+        case ObjcUnsignedCharType:
+            return jsNumber(*(unsigned char *)buffer);
         case ObjcShortType:
             return jsNumber(*(short *)buffer);
+        case ObjcUnsignedShortType:
+            return jsNumber(*(unsigned short *)buffer);
         case ObjcIntType:
             return jsNumber(*(int *)buffer);
+        case ObjcUnsignedIntType:
+            return jsNumber(*(unsigned int *)buffer);
         case ObjcLongType:
             return jsNumber(*(long *)buffer);
+        case ObjcUnsignedLongType:
+            return jsNumber(*(unsigned long *)buffer);
+        case ObjcLongLongType:
+            return jsNumber(*(long long *)buffer);
+        case ObjcUnsignedLongLongType:
+            return jsNumber(*(unsigned long long *)buffer);
         case ObjcFloatType:
             return jsNumber(*(float *)buffer);
         case ObjcDoubleType:
@@ -258,53 +279,76 @@ JSValue* convertObjcValueToValue(ExecState* exec, void* buffer, ObjcValueType ty
     return 0;
 }
 
-
-ObjcValueType objcValueTypeForType (const char *type)
+ObjcValueType objcValueTypeForType(const char *type)
 {
     int typeLength = strlen(type);
     ObjcValueType objcValueType = ObjcInvalidType;
-    
-    if (typeLength == 1) {
-        char typeChar = type[0];
-        switch (typeChar){
-            case _C_ID: {
+
+    for (int i = 0; i < typeLength; ++i) {
+        char typeChar = type[i];
+        switch (typeChar) {
+            case _C_CONST:
+            case _C_BYCOPY:
+            case _C_BYREF:
+            case _C_ONEWAY:
+            case _C_GCINVISIBLE:
+                // skip these type modifiers
+                break;
+            case _C_ID:
                 objcValueType = ObjcObjectType;
-            }
-            break;
-            case _C_CHR: {
+                break;
+            case _C_CHR:
                 objcValueType = ObjcCharType;
-            }
-            break;
-            case _C_SHT: {
+                break;
+            case _C_UCHR:
+                objcValueType = ObjcUnsignedCharType;
+                break;
+            case _C_SHT:
                 objcValueType = ObjcShortType;
-            }
-            break;
-            case _C_INT: {
+                break;
+            case _C_USHT:
+                objcValueType = ObjcUnsignedShortType;
+                break;
+            case _C_INT:
                 objcValueType = ObjcIntType;
-            }
-            break;
-            case _C_LNG: {
+                break;
+            case _C_UINT:
+                objcValueType = ObjcUnsignedIntType;
+                break;
+            case _C_LNG:
                 objcValueType = ObjcLongType;
-            }
-            break;
-            case _C_FLT: {
+                break;
+            case _C_ULNG:
+                objcValueType = ObjcUnsignedLongType;
+                break;
+            case _C_LNG_LNG:
+                objcValueType = ObjcLongLongType;
+                break;
+            case _C_ULNG_LNG:
+                objcValueType = ObjcUnsignedLongLongType;
+                break;
+            case _C_FLT:
                 objcValueType = ObjcFloatType;
-            }
-            break;
-            case _C_DBL: {
+                break;
+            case _C_DBL:
                 objcValueType = ObjcDoubleType;
-            }
-            break;
-            case _C_VOID: {
+                break;
+            case _C_VOID:
                 objcValueType = ObjcVoidType;
-            }
-            break;
+                break;
+            default:
+                // Unhandled type. We don't handle C structs, unions, etc.
+                // FIXME: throw an exception?
+                assert(false);
         }
+
+        if (objcValueType != ObjcInvalidType)
+            break;
     }
+
     return objcValueType;
 }
 
-
 void *createObjcInstanceForValue(JSValue *value, const RootObject *origin, const RootObject *current)
 {
     if (!value->isObject())