[webkit-changes] cvs commit: JavaScriptCore/bindings/objc objc_instance.mm

Geoffrey ggaren at opensource.apple.com
Tue Nov 8 22:34:57 PST 2005


ggaren      05/11/08 22:34:57

  Modified:    .        ChangeLog
               bindings/objc objc_instance.mm
  Log:
          Reviewed by Darin.
  
          This patch fixes some naughty naughty code -- 5 crashes and 2
          may-go-haywire-in-the-futures.
  
          One such crash is <rdar://problem/4247330> 8C46 Crash with with
          incomplete parameter list to webScript object function.
  
          I replaced early returns from within NS_DURINGs with calls to
          NS_VALUERETURN because the doc says, "You cannot use goto or
          return to exit an exception handling domain -- errors will result."
  
          I replaced hard-coded analyses of -[NSMethodSignature
          methodReturnType] with more abstracted alternatives, since
          the documentation says "This encoding is implementation-specific,
          so applications should use it with caution," and then emits an
          evil cackle.
  
          I removed the early return in the case where a JavaScript caller
          supplies an insufficient number of arguments, because the right
          thing to do in such a case is to use JavaScript's defined behavior
          of supplying "undefined" for any missing arguments.
  
          I also changed ObjcInstance::invokeMethod so that it no longer
          deletes the method passed to it. It doesn't create the method,
          so it shouldn't delete it. A friend of mine named
          KERNEL_PROTECTION_FAILURE agrees with me on this point.
  
          Finally, I changed an assert(true) to assert(false) because
          all the other asserts were making fun of it.
  
          * bindings/objc/objc_instance.mm:
          (ObjcInstance::invokeMethod):
          (ObjcInstance::invokeDefaultMethod):
  
  Revision  Changes    Path
  1.880     +37 -0     JavaScriptCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
  retrieving revision 1.879
  retrieving revision 1.880
  diff -u -r1.879 -r1.880
  --- ChangeLog	7 Nov 2005 03:07:14 -0000	1.879
  +++ ChangeLog	9 Nov 2005 06:34:52 -0000	1.880
  @@ -1,3 +1,40 @@
  +2005-11-08  Geoffrey Garen  <ggaren at apple.com>
  +
  +        Reviewed by Darin.
  +
  +        This patch fixes some naughty naughty code -- 5 crashes and 2 
  +        may-go-haywire-in-the-futures.
  +        
  +        One such crash is <rdar://problem/4247330> 8C46 Crash with with 
  +        incomplete parameter list to webScript object function.
  +        
  +        I replaced early returns from within NS_DURINGs with calls to
  +        NS_VALUERETURN because the doc says, "You cannot use goto or 
  +        return to exit an exception handling domain -- errors will result."
  +        
  +        I replaced hard-coded analyses of -[NSMethodSignature 
  +        methodReturnType] with more abstracted alternatives, since
  +        the documentation says "This encoding is implementation-specific, 
  +        so applications should use it with caution," and then emits an
  +        evil cackle.
  +        
  +        I removed the early return in the case where a JavaScript caller
  +        supplies an insufficient number of arguments, because the right
  +        thing to do in such a case is to use JavaScript's defined behavior
  +        of supplying "undefined" for any missing arguments.
  +        
  +        I also changed ObjcInstance::invokeMethod so that it no longer
  +        deletes the method passed to it. It doesn't create the method,
  +        so it shouldn't delete it. A friend of mine named
  +        KERNEL_PROTECTION_FAILURE agrees with me on this point.
  +        
  +        Finally, I changed an assert(true) to assert(false) because
  +        all the other asserts were making fun of it.
  +
  +        * bindings/objc/objc_instance.mm:
  +        (ObjcInstance::invokeMethod):
  +        (ObjcInstance::invokeDefaultMethod):
  +
   2005-11-06  Geoffrey Garen  <ggaren at apple.com>
   
           Reviewed by Darin.
  
  
  
  1.15      +15 -23    JavaScriptCore/bindings/objc/objc_instance.mm
  
  Index: objc_instance.mm
  ===================================================================
  RCS file: /cvs/root/JavaScriptCore/bindings/objc/objc_instance.mm,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- objc_instance.mm	3 Oct 2005 21:11:47 -0000	1.14
  +++ objc_instance.mm	9 Nov 2005 06:34:56 -0000	1.15
  @@ -139,15 +139,11 @@
       NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
       [invocation setSelector:(SEL)method->name()];
       [invocation setTarget:_instance];
  -    unsigned i, count = args.size();
       
       if (method->isFallbackMethod()) {
  -        // invokeUndefinedMethodFromWebScript:withArguments: implementation must return an
  -        // object.
  -        if (strcmp ([signature methodReturnType], "@") != 0) {
  -            OBJC_LOG ("incorrect signature for invokeUndefinedMethodFromWebScript:withArguments:, expected object return type");
  -            delete method;
  -            return Undefined();
  +        if (objcValueTypeForType([signature methodReturnType]) != ObjcObjectType) {
  +            NSLog(@"Incorrect signature for invokeUndefinedMethodFromWebScript:withArguments: -- return type must be object.");
  +            NS_VALUERETURN(Undefined(), ValueImp *);
           }
           
           // Invoke invokeUndefinedMethodFromWebScript:withArguments:, pass JavaScript function
  @@ -156,18 +152,16 @@
           [invocation setArgument:&jsName atIndex:2];
           
           NSMutableArray *objcArgs = [NSMutableArray array];
  -        for (i = 0; i < count; i++) {
  +        int count = args.size();
  +        for (int i = 0; i < count; i++) {
               ObjcValue value = convertValueToObjcValue (exec, args.at(i), ObjcObjectType);
               [objcArgs addObject:value.objectValue];
           }
           [invocation setArgument:&objcArgs atIndex:3];
       }
       else {
  -        if (count != [signature numberOfArguments] - 2){
  -            return Undefined();
  -        }
  -        
  -        for (i = 2; i < count+2; i++) {
  +        unsigned count = [signature numberOfArguments];
  +        for (unsigned i = 2; i < count ; i++) {
               const char *type = [signature getArgumentTypeAtIndex:i];
               ObjcValueType objcValueType = objcValueTypeForType (type);
   
  @@ -205,7 +199,7 @@
                       // the assert above should have fired in the impossible case
                       // of an invalid type anyway).
                       fprintf (stderr, "%s:  invalid type (%d)\n", __PRETTY_FUNCTION__, (int)objcValueType);
  -                    assert (true);
  +                    assert(false);
               }
           }
       }
  @@ -239,7 +233,7 @@
   NS_HANDLER
       
       resultValue = Undefined();
  -    
  +
   NS_ENDHANDLER
   
       return resultValue;
  @@ -252,7 +246,7 @@
   NS_DURING
   
       if (![_instance respondsToSelector:@selector(invokeDefaultMethodWithArguments:)])
  -        return Undefined();
  +        NS_VALUERETURN(Undefined(), ValueImp *);
       
       NSMethodSignature *signature = [_instance methodSignatureForSelector:@selector(invokeDefaultMethodWithArguments:)];
       NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
  @@ -260,11 +254,9 @@
       [invocation setTarget:_instance];
       unsigned i, count = args.size();
       
  -    // invokeDefaultMethodWithArguments: implementation must return an
  -    // object.
  -    if (strcmp ([signature methodReturnType], "@") != 0) {
  -        OBJC_LOG ("incorrect signature for invokeDefaultMethodWithArguments:, expected object return type");
  -        return Undefined();
  +    if (objcValueTypeForType([signature methodReturnType]) != ObjcObjectType) {
  +        NSLog(@"Incorrect signature for invokeDefaultMethodWithArguments: -- return type must be object.");
  +        NS_VALUERETURN(Undefined(), ValueImp *);
       }
       
       NSMutableArray *objcArgs = [NSMutableArray array];
  @@ -290,9 +282,9 @@
       resultValue = convertObjcValueToValue (exec, buffer, objcValueType);
   
   NS_HANDLER
  -    
  +
       resultValue = Undefined();
  -    
  +
   NS_ENDHANDLER
   
       return resultValue;
  
  
  



More information about the webkit-changes mailing list