From dacb64b847f477c42e5e3bbaec93e4fec09ec65a Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Fri, 17 Feb 2017 13:21:21 -0500 Subject: [PATCH] Bug 1338870 - Don't call [super respondsToSelector:] because it doesn't do what you might think. r=spohl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --HG-- extra : rebase_source : f392bfe75c0a5c270b12b0f4ea2abdc6f737d5c2 --- widget/cocoa/nsCocoaWindow.mm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 95fc6ead4c57..dae21241956c 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -3188,7 +3188,9 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior"; 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]; @@ -3208,7 +3210,9 @@ static const NSString* kStateCollectionBehavior = @"collectionBehavior"; 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];