[webkit-changes] cvs commit: JavaScriptCore/bindings/objc objc_class.mm objc_utility.h objc_utility.mm

Timothy thatcher at opensource.apple.com
Thu Jan 5 17:25:36 PST 2006


thatcher    06/01/05 17:25:35

  Modified:    .        Tag: Safari-1-3-branch ChangeLog
               bindings/objc Tag: Safari-1-3-branch objc_class.mm
                        objc_utility.h objc_utility.mm
  Log:
          Merges fixes from TOT to Safari-1-3-branch
  
      2005-12-19  Geoffrey Garen  <ggaren at apple.com>
  
          Reviewed by Maciej.
  
          Fixed <rdar://problem/4370397> Missing return statement in
          JSMethodNameToObjcMethodName.
  
          JSMethodNameToObjcMethodName had a check for a name being too long, but
          the check was missing a return statement.
  
          A lot of this code was confusing and some of it was wrong, so I fixed
          it up, added some asserts to catch this type of bug in the future,
          changed some comments, and renamed some variables.
  
          The two advantages of the new algorithm are (1) It makes writing past
          the end of the buffer virtually impossible because the test on the main
          loop is "while (not past end of buffer)" and (2) It's twice as fast
          because it doesn't call strlen. (There's no need to call strlen when
          we're walking the string ourselves.)
  
          methodsNamed also supports arbitrary-length method names now. Just in
          case the AppKit folks start getting REALLY verbose...
  
          * bindings/objc/objc_class.mm:
          (KJS::Bindings::ObjcClass::methodsNamed):
          * bindings/objc/objc_utility.h:
          * bindings/objc/objc_utility.mm:
          (KJS::Bindings::JSMethodNameToObjcMethodName):
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.677.4.10 +33 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.677.4.9
  retrieving revision 1.677.4.10
  diff -u -r1.677.4.9 -r1.677.4.10
  --- ChangeLog	4 Dec 2005 21:56:48 -0000	1.677.4.9
  +++ ChangeLog	6 Jan 2006 01:25:30 -0000	1.677.4.10
  @@ -1,3 +1,36 @@
  +2006-01-05  Timothy Hatcher  <timothy at apple.com>
  +
  +        Merges fixes from TOT to Safari-1-3-branch
  +
  +    2005-12-19  Geoffrey Garen  <ggaren at apple.com>
  +  
  +        Reviewed by Maciej.
  +
  +        Fixed <rdar://problem/4370397> Missing return statement in
  +        JSMethodNameToObjcMethodName.
  +
  +        JSMethodNameToObjcMethodName had a check for a name being too long, but
  +        the check was missing a return statement.
  +
  +        A lot of this code was confusing and some of it was wrong, so I fixed
  +        it up, added some asserts to catch this type of bug in the future, 
  +        changed some comments, and renamed some variables.
  +
  +        The two advantages of the new algorithm are (1) It makes writing past
  +        the end of the buffer virtually impossible because the test on the main
  +        loop is "while (not past end of buffer)" and (2) It's twice as fast
  +        because it doesn't call strlen. (There's no need to call strlen when
  +        we're walking the string ourselves.) 
  +        
  +        methodsNamed also supports arbitrary-length method names now. Just in 
  +        case the AppKit folks start getting REALLY verbose...
  +
  +        * bindings/objc/objc_class.mm:
  +        (KJS::Bindings::ObjcClass::methodsNamed):
  +        * bindings/objc/objc_utility.h:
  +        * bindings/objc/objc_utility.mm:
  +        (KJS::Bindings::JSMethodNameToObjcMethodName):
  +
   === JavaScriptCore-312.3 ===
   
   2005-11-28  Adele Peterson  <adele at apple.com>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.8.8.1   +14 -10    JavaScriptCore/bindings/objc/objc_class.mm
  
  Index: objc_class.mm
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/bindings/objc/objc_class.mm,v
  retrieving revision 1.8
  retrieving revision 1.8.8.1
  diff -u -r1.8 -r1.8.8.1
  --- objc_class.mm	1 Oct 2004 00:24:39 -0000	1.8
  +++ objc_class.mm	6 Jan 2006 01:25:34 -0000	1.8.8.1
  @@ -85,19 +85,21 @@
       return _isa->name;
   }
   
  -MethodList ObjcClass::methodsNamed(const char *_name, Instance *instance) const
  +MethodList ObjcClass::methodsNamed(const char *JSName, Instance *instance) const
   {
       MethodList methodList;
  -    char name[4096];
  -    
  -    JSMethodNameToObjCMethodName (_name, name, 4096);
  -    
  -    if (*name == 0) {
  -        return methodList;
  +    char fixedSizeBuffer[1024];
  +    char *buffer = fixedSizeBuffer;
  +
  +    if (!convertJSMethodNameToObjc(JSName, buffer, sizeof(fixedSizeBuffer))) {
  +        int length = strlen(JSName) + 1;
  +        buffer = new char[length];
  +        if (!buffer || !convertJSMethodNameToObjc(JSName, buffer, length))
  +            return methodList;
       }
           
  -    CFStringRef methodName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
  -    Method *method = (Method *)CFDictionaryGetValue (_methods, methodName);
  +    CFStringRef methodName = CFStringCreateWithCString(NULL, buffer, kCFStringEncodingASCII);
  +    Method *method = (Method *)CFDictionaryGetValue(_methods, methodName);
       if (method) {
           CFRelease (methodName);
           methodList.addMethod(method);
  @@ -129,7 +131,7 @@
                   }
   
                   if ((mappedName && [mappedName isEqual:(NSString *)methodName]) ||
  -                    strcmp ((const char *)objcMethod->method_name, name) == 0) {
  +                    strcmp ((const char *)objcMethod->method_name, buffer) == 0) {
                       Method *aMethod = new ObjcMethod (thisClass, (const char *)objcMethod->method_name);
                       CFDictionaryAddValue ((CFMutableDictionaryRef)_methods, methodName, aMethod);
                       methodList.addMethod (aMethod);
  @@ -141,6 +143,8 @@
       }
       
       CFRelease (methodName);
  +    if (buffer != fixedSizeBuffer)
  +        delete [] buffer;
   
       return methodList;
   }
  
  
  
  1.4.6.1   +1 -1      JavaScriptCore/bindings/objc/objc_utility.h
  
  Index: objc_utility.h
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/bindings/objc/objc_utility.h,v
  retrieving revision 1.4
  retrieving revision 1.4.6.1
  diff -u -r1.4 -r1.4.6.1
  --- objc_utility.h	12 Feb 2005 00:58:13 -0000	1.4
  +++ objc_utility.h	6 Jan 2006 01:25:34 -0000	1.4.6.1
  @@ -73,7 +73,7 @@
   Value convertObjcValueToValue (KJS::ExecState *exec, void *buffer, ObjcValueType type);
   ObjcValueType objcValueTypeForType (const char *type);
   
  -void JSMethodNameToObjCMethodName(const char *name, char *name, unsigned int length);
  +bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize);
   
   void *createObjcInstanceForValue (const Object &value, const RootObject *origin, const RootObject *current);
   
  
  
  
  1.17.6.1  +40 -28    JavaScriptCore/bindings/objc/objc_utility.mm
  
  Index: objc_utility.mm
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/bindings/objc/objc_utility.mm,v
  retrieving revision 1.17
  retrieving revision 1.17.6.1
  diff -u -r1.17 -r1.17.6.1
  --- objc_utility.mm	15 Mar 2005 23:52:26 -0000	1.17
  +++ objc_utility.mm	6 Jan 2006 01:25:34 -0000	1.17.6.1
  @@ -40,41 +40,53 @@
   using namespace KJS::Bindings;
   
   /*
  -    The default name concatenates the components of the
  -    ObjectiveC selector name and replaces ':' with '_'.  '_' characters
  -    are escaped with an additional '$', i.e. '_' becomes "$_".  '$' are
  -    also escaped, i.e.
  -        ObjectiveC name         Default script name
  -        moveTo::                move__
  +    By default, a JavaScript method name is produced by concatenating the 
  +    components of an ObjectiveC method name, replacing ':' with '_', and 
  +    escaping '_' and '$' with a leading '$', such that '_' becomes "$_" and 
  +    '$' becomes "$$". For example:
  +
  +    ObjectiveC name         Default JavaScript name
  +        moveTo::                moveTo__
           moveTo_                 moveTo$_
           moveTo$_                moveTo$$$_
  -    @result Returns the name to be used to represent the specificed selector in the
  +
  +    This function performs the inverse of that operation.
  + 
  +    @result Fills 'buffer' with the ObjectiveC method name that corresponds to 'JSName'. 
  +            Returns true for success, false for failure. (Failure occurs when 'buffer' 
  +            is not big enough to hold the result.)
   */
  -void KJS::Bindings::JSMethodNameToObjCMethodName(const char *name, char *buffer, unsigned int len)
  +bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize)
   {
  -    const char *np = name;
  -    char *bp;
  -
  -    if (strlen(name)*2+1 > len){
  -        *buffer = 0;
  -    }
  -
  -    bp = buffer;
  -    while (*np) {
  -        if (*np == '$') {
  -            np++;
  -            *bp++ = *np++;
  -            continue;
  -        }
  +    assert(JSName && buffer);
  +    
  +    const char *sp = JSName; // source pointer
  +    char *dp = buffer; // destination pointer
  +        
  +    char *end = buffer + bufferSize;
  +    while (dp < end) {
  +        if (*sp == '$') {
  +            ++sp;
  +            *dp = *sp;
  +        } else if (*sp == '_')
  +            *dp = ':';
  +	else
  +            *dp = *sp;
  +
  +        // If a future coder puts funny ++ operators above, we might write off the end 
  +        // of the buffer in the middle of this loop. Let's make sure to check for that.
  +        assert(dp < end);
           
  -        if (*np == '_') {
  -            np++;
  -            *bp++ = ':';
  +        if (*sp == 0) { // We finished converting JSName
  +            assert(strlen(JSName) < bufferSize);
  +            return true;
           }
  -        else
  -            *bp++ = *np++;
  +        
  +        ++sp; 
  +        ++dp;
       }
  -    *bp++ = 0;
  +
  +    return false; // We ran out of buffer before converting JSName
   }
   
   /*
  
  
  



More information about the webkit-changes mailing list