Bug 140203 - WKWebView crashes on deallocation
Summary: WKWebView crashes on deallocation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: iPhone / iPad All
: P2 Major
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
: 140915 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-01-07 14:00 PST by Eugene But
Modified: 2016-12-29 20:53 PST (History)
6 users (show)

See Also:


Attachments
Test App (18.97 KB, application/zip)
2015-01-07 14:00 PST, Eugene But
no flags Details
Crash Log (29.03 KB, text/plain)
2015-01-07 14:01 PST, Eugene But
no flags Details
Patch (10.81 KB, patch)
2015-01-26 18:38 PST, Simon Fraser (smfr)
simon.fraser: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene But 2015-01-07 14:00:48 PST
Created attachment 244195 [details]
Test App

Summary:
[Chrome] WKWebView crashes on deallocation if it has pending JavaScript evaluation.

Steps to Reproduce:
1. Unarchive WKWebView.zip
2. Build and run test project on device or simulator


Expected Results:
"No error" should appear in console

Actual Results:
App crashes
Comment 1 Eugene But 2015-01-07 14:01:29 PST
Created attachment 244196 [details]
Crash Log
Comment 2 Eugene But 2015-01-07 16:06:02 PST
Radar ID: 19036018
Comment 3 Simon Fraser (smfr) 2015-01-26 18:36:34 PST
*** Bug 140915 has been marked as a duplicate of this bug. ***
Comment 4 Simon Fraser (smfr) 2015-01-26 18:38:31 PST
Created attachment 245398 [details]
Patch
Comment 5 Simon Fraser (smfr) 2015-01-26 18:39:12 PST
Comment on attachment 245398 [details]
Patch

Sam said Yeah.
Comment 6 WebKit Commit Bot 2015-01-26 18:40:00 PST
Attachment 245398 [details] did not pass style-queue:


ERROR: Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm:45:  Place brace on its own line for function definitions.  [whitespace/braces] [4]
Total errors found: 1 in 5 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 7 Simon Fraser (smfr) 2015-01-26 18:41:55 PST
https://trac.webkit.org/r179161 and https://trac.webkit.org/r179160 (OOPS!)
Comment 8 Stuart Morgan 2015-01-27 06:50:40 PST
Thanks! Is there any reasonable way for us to work around this in versions of the OS that don't have the fix?
Comment 9 Simon Fraser (smfr) 2015-01-27 07:37:35 PST
Try calling -copy on the completion block that you send into -[WKWebView evaluateJavaScript:completionHandler:], and manage the lifetime of the resulting block yourself.
Comment 10 chenwenhong 2015-07-14 06:48:21 PDT
Hi,I fixed the WebKit's bug. The code below:

- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
{
    id strongSelf = self;
    
    [super evaluateJavaScript:javaScriptString completionHandler:^(id r, NSError *e) {
        [strongSelf title];
        
        if (completionHandler) {
            completionHandler(r, e);
        }
    }];
}