Bug 184799 - Make WAKScrollView delegate a weak property
Summary: Make WAKScrollView delegate a weak property
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on: 184789
Blocks:
  Show dependency treegraph
 
Reported: 2018-04-19 15:58 PDT by David Kilzer (:ddkilzer)
Modified: 2018-04-26 11:22 PDT (History)
6 users (show)

See Also:


Attachments
Patch v1 (3.05 KB, patch)
2018-04-19 16:07 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Patch v2 (3.35 KB, patch)
2018-04-19 16:29 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff
Source for testing objc-arc and objc-weak (622 bytes, text/x-csrc)
2018-04-26 10:19 PDT, David Kilzer (:ddkilzer)
no flags Details
Patch v3 (fixed ChangeLog typo from v2) (3.35 KB, patch)
2018-04-26 10:34 PDT, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2018-04-19 15:58:50 PDT
Make WAKScrollView delegate a weak property to prevent crashes where the delegate has been released.

<rdar://problem/39469669>
Comment 1 David Kilzer (:ddkilzer) 2018-04-19 16:07:36 PDT
Created attachment 338374 [details]
Patch v1
Comment 2 David Kilzer (:ddkilzer) 2018-04-19 16:09:52 PDT
ERROR: Source/WebCore/platform/ios/wak/WAKScrollView.mm:65:  Should not have spaces around = in property synthesis.  [whitespace/property] [4]

Should I just delete the _delegate instance variable?
Comment 3 EWS Watchlist 2018-04-19 16:10:13 PDT
Attachment 338374 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/ios/wak/WAKScrollView.mm:65:  Should not have spaces around = in property synthesis.  [whitespace/property] [4]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 David Kilzer (:ddkilzer) 2018-04-19 16:20:16 PDT
(In reply to Build Bot from comment #3)
> Attachment 338374 [details] did not pass style-queue:
> 
> 
> ERROR: Source/WebCore/platform/ios/wak/WAKScrollView.mm:65:  Should not have
> spaces around = in property synthesis.  [whitespace/property] [4]
> Total errors found: 1 in 3 files
> 
> 
> If any of these errors are false positives, please file a bug against
> check-webkit-style.

Ha!  Even better reason to remove it (build failure on iOS Simulator):

In file included from ./platform/ios/wak/WAKScrollView.mm:27:
./platform/ios/wak/WAKScrollView.h:41:8: error: existing instance variable '_delegate' for __weak property 'delegate' must be __weak
    id _delegate;
       ^
./platform/ios/wak/WAKScrollView.h:60:32: note: property declared here
@property (nonatomic, weak) id delegate;
                               ^
In file included from /Volumes/Data/EWS/WebKit/WebKitBuild/Release-iphonesimulator/DerivedSources/WebCore/unified-sources/UnifiedSource45-mm.mm:1:
./platform/ios/wak/WAKScrollView.mm:65:13: note: property synthesized here
@synthesize delegate = _delegate;
            ^
1 error generated.
Comment 5 David Kilzer (:ddkilzer) 2018-04-19 16:29:07 PDT
Created attachment 338378 [details]
Patch v2
Comment 6 Simon Fraser (smfr) 2018-04-19 16:31:39 PDT
Comment on attachment 338378 [details]
Patch v2

This patch is effectively a no-op. 'weak' just means non-retained, which is what the old code was doing.
Comment 7 Simon Fraser (smfr) 2018-04-19 16:34:24 PDT
Maybe you're right:
https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
"A weak reference does not extend the lifetime of the object it points to, and automatically becomes nil when there are no strong references to the object."

Have you tested this?
Comment 8 David Kilzer (:ddkilzer) 2018-04-26 10:19:11 PDT
Created attachment 338887 [details]
Source for testing objc-arc and objc-weak
Comment 9 David Kilzer (:ddkilzer) 2018-04-26 10:23:40 PDT
(In reply to Simon Fraser (smfr) from comment #7)
> Maybe you're right:
> https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-
> TransitioningToARC/Introduction/Introduction.html
> "A weak reference does not extend the lifetime of the object it points to,
> and automatically becomes nil when there are no strong references to the
> object."
> 
> Have you tested this?

Using Attachment #338887 [details]:

With ARC:

$ clang -fobjc-arc -x objective-c -o weak-smfr-arc -framework Foundation weak-smfr.m 
$ ./weak-smfr-arc 
2018-04-26 10:17:42.295 weak-smfr-arc[97821:14281815] Before release: 0x7f916d40cb20
2018-04-26 10:17:42.295 weak-smfr-arc[97821:14281815] After release: 0x0

With MRR:

$ clang -x objective-c -o weak-smfr-mrr -framework Foundation weak-smfr.m 
$ ./weak-smfr-mrr 
2018-04-26 10:20:25.478 weak-smfr-mrr[97834:14292493] Before release: 0x7f88f2e06b00
2018-04-26 10:20:25.479 weak-smfr-mrr[97834:14292493] After release: 0x7f88f2e06b00

With MRR + WEAK:

$ clang -fobjc-weak -x objective-c -o weak-smfr-weak -framework Foundation weak-smfr.m 
$ ./weak-smfr-weak 
2018-04-26 10:20:38.310 weak-smfr-weak[97838:14293436] Before release: 0x7ff2eef04bd0
2018-04-26 10:20:38.310 weak-smfr-weak[97838:14293436] After release: 0x0

So, yes, this feature works as it was designed.  :)
Comment 10 David Kilzer (:ddkilzer) 2018-04-26 10:34:00 PDT
Created attachment 338889 [details]
Patch v3 (fixed ChangeLog typo from v2)
Comment 11 WebKit Commit Bot 2018-04-26 11:22:08 PDT
Comment on attachment 338889 [details]
Patch v3 (fixed ChangeLog typo from v2)

Clearing flags on attachment: 338889

Committed r231058: <https://trac.webkit.org/changeset/231058>
Comment 12 WebKit Commit Bot 2018-04-26 11:22:09 PDT
All reviewed patches have been landed.  Closing bug.