Bug 1338870 - Don't call [super respondsToSelector:] because it doesn't do what you might think. r?spohl draft
authorMarkus Stange <mstange@themasta.com>
Fri, 17 Feb 2017 13:21:21 -0500
changeset 486259 750ea2177b8faf72de35b1150a860b843b990398
parent 486258 34c617baca1d1cebecc1bcf554337ed330fa8b94
child 546200 66b84e15e00a793f5cf9ead2bb44a4db14193096
push id45932
push userbmo:mstange@themasta.com
push dateFri, 17 Feb 2017 18:24:00 +0000
reviewersspohl
bugs1338870, 1418956, 1418583
milestone54.0a1
Bug 1338870 - Don't call [super respondsToSelector:] because it doesn't do what you might think. r?spohl From https://developer.apple.com/reference/objectivec/1418956-nsobject/1418583-respondstoselector : > You cannot test whether an object inherits a method from its superclass by > sending respondsToSelector: to the object using the super keyword. This method > will still be testing the object as a whole, not just the superclass’s > implementation. Therefore, sending respondsToSelector: to super is equivalent > to sending it to self. Instead, you must invoke the NSObject class method > instancesRespondToSelector: directly on the object’s superclass. MozReview-Commit-ID: 8wTexCQWUPw
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -3183,17 +3183,19 @@ static const NSString* kStateCollectionB
   return [super contentRectForFrameRect:aRect];
 }
 
 - (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(NSUInteger)aMask
 {
   if ([self drawsContentsIntoWindowFrame]) {
     return aRect;
   }
-  if ([super respondsToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
+  // Call the instance method on super, if it exists (it's undocumented so we
+  // shouldn't rely on it), or fall back to the (documented) class method.
+  if ([NSWindow instancesRespondToSelector:@selector(contentRectForFrameRect:styleMask:)]) {
     return [super contentRectForFrameRect:aRect styleMask:aMask];
   } else {
     return [NSWindow contentRectForFrameRect:aRect styleMask:aMask];
   }
 }
 
 - (NSRect)frameRectForContentRect:(NSRect)aRect
 {
@@ -3203,17 +3205,19 @@ static const NSString* kStateCollectionB
   return [super frameRectForContentRect:aRect];
 }
 
 - (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(NSUInteger)aMask
 {
   if ([self drawsContentsIntoWindowFrame]) {
     return aRect;
   }
-  if ([super respondsToSelector:@selector(frameRectForContentRect:styleMask:)]) {
+  // Call the instance method on super, if it exists (it's undocumented so we
+  // shouldn't rely on it), or fall back to the (documented) class method.
+  if ([NSWindow instancesRespondToSelector:@selector(frameRectForContentRect:styleMask:)]) {
     return [super frameRectForContentRect:aRect styleMask:aMask];
   } else {
     return [NSWindow frameRectForContentRect:aRect styleMask:aMask];
   }
 }
 
 - (void)setContentView:(NSView*)aView
 {