Title: [253282] trunk/Tools
Revision
253282
Author
timothy_hor...@apple.com
Date
2019-12-08 23:25:00 -0800 (Sun, 08 Dec 2019)

Log Message

REGRESSION: Crash under UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification
https://bugs.webkit.org/show_bug.cgi?id=205002

Reviewed by Wenson Hsieh.

Keep a strong reference to the UIScriptController while running async tasks.
UIScriptContext will be nulled out if the view was torn down, but this way
we keep the UIScriptController itself and can find the null UIScriptContext
reliably.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::doAsyncTask):
(WTR::UIScriptControllerIOS::zoomToScale):
* DumpRenderTree/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::doAsyncTask):
(WTR::UIScriptControllerMac::activateDataListSuggestion):
(WTR::UIScriptControllerMac::removeViewFromWindow):
(WTR::UIScriptControllerMac::addViewToWindow):
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptControllerIOS::doAfterPresentationUpdate):
(WTR::UIScriptControllerIOS::doAfterNextStablePresentationUpdate):
(WTR::UIScriptControllerIOS::ensurePositionInformationIsUpToDateAt):
(WTR::UIScriptControllerIOS::doAfterVisibleContentRectUpdate):
(WTR::UIScriptControllerIOS::zoomToScale):
(WTR::UIScriptControllerIOS::retrieveSpeakSelectionContent):
(WTR::UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification):
(WTR::UIScriptControllerIOS::touchDownAtPoint):
(WTR::UIScriptControllerIOS::liftUpAtPoint):
(WTR::UIScriptControllerIOS::twoFingerSingleTapAtPoint):
(WTR::UIScriptControllerIOS::doubleTapAtPoint):
(WTR::UIScriptControllerIOS::stylusDownAtPoint):
(WTR::UIScriptControllerIOS::stylusMoveToPoint):
(WTR::UIScriptControllerIOS::stylusUpAtPoint):
(WTR::UIScriptControllerIOS::stylusTapAtPointWithModifiers):
(WTR::UIScriptControllerIOS::dragFromPointToPoint):
(WTR::UIScriptControllerIOS::longPressAtPoint):
(WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard):
(WTR::UIScriptControllerIOS::dismissFilePicker):
(WTR::UIScriptControllerIOS::applyAutocorrection):
(WTR::UIScriptControllerIOS::simulateRotation):
(WTR::UIScriptControllerIOS::simulateRotationLikeSafari):
(WTR::UIScriptControllerIOS::setDidStartFormControlInteractionCallback):
(WTR::UIScriptControllerIOS::setDidEndFormControlInteractionCallback):
(WTR::UIScriptControllerIOS::setDidShowContextMenuCallback):
(WTR::UIScriptControllerIOS::setDidDismissContextMenuCallback):
(WTR::UIScriptControllerIOS::setWillBeginZoomingCallback):
(WTR::UIScriptControllerIOS::setDidEndZoomingCallback):
(WTR::UIScriptControllerIOS::setDidShowKeyboardCallback):
(WTR::UIScriptControllerIOS::setDidHideKeyboardCallback):
(WTR::UIScriptControllerIOS::setWillPresentPopoverCallback):
(WTR::UIScriptControllerIOS::setDidDismissPopoverCallback):
(WTR::UIScriptControllerIOS::setDidEndScrollingCallback):
(WTR::UIScriptControllerIOS::activateDataListSuggestion):
(WTR::UIScriptControllerIOS::doAfterDoubleTapDelay):
* WebKitTestRunner/mac/UIScriptControllerMac.mm:
(WTR::UIScriptControllerMac::zoomToScale):
(WTR::UIScriptControllerMac::simulateAccessibilitySettingsChangeNotification):
(WTR::UIScriptControllerMac::chooseMenuAction):
(WTR::UIScriptControllerMac::activateAtPoint):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (253281 => 253282)


--- trunk/Tools/ChangeLog	2019-12-09 01:52:19 UTC (rev 253281)
+++ trunk/Tools/ChangeLog	2019-12-09 07:25:00 UTC (rev 253282)
@@ -1,3 +1,65 @@
+2019-12-08  Tim Horton  <timothy_hor...@apple.com>
+
+        REGRESSION: Crash under UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification
+        https://bugs.webkit.org/show_bug.cgi?id=205002
+
+        Reviewed by Wenson Hsieh.
+
+        Keep a strong reference to the UIScriptController while running async tasks.
+        UIScriptContext will be nulled out if the view was torn down, but this way
+        we keep the UIScriptController itself and can find the null UIScriptContext
+        reliably.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptControllerIOS::doAsyncTask):
+        (WTR::UIScriptControllerIOS::zoomToScale):
+        * DumpRenderTree/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptControllerMac::doAsyncTask):
+        (WTR::UIScriptControllerMac::activateDataListSuggestion):
+        (WTR::UIScriptControllerMac::removeViewFromWindow):
+        (WTR::UIScriptControllerMac::addViewToWindow):
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptControllerIOS::doAfterPresentationUpdate):
+        (WTR::UIScriptControllerIOS::doAfterNextStablePresentationUpdate):
+        (WTR::UIScriptControllerIOS::ensurePositionInformationIsUpToDateAt):
+        (WTR::UIScriptControllerIOS::doAfterVisibleContentRectUpdate):
+        (WTR::UIScriptControllerIOS::zoomToScale):
+        (WTR::UIScriptControllerIOS::retrieveSpeakSelectionContent):
+        (WTR::UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification):
+        (WTR::UIScriptControllerIOS::touchDownAtPoint):
+        (WTR::UIScriptControllerIOS::liftUpAtPoint):
+        (WTR::UIScriptControllerIOS::twoFingerSingleTapAtPoint):
+        (WTR::UIScriptControllerIOS::doubleTapAtPoint):
+        (WTR::UIScriptControllerIOS::stylusDownAtPoint):
+        (WTR::UIScriptControllerIOS::stylusMoveToPoint):
+        (WTR::UIScriptControllerIOS::stylusUpAtPoint):
+        (WTR::UIScriptControllerIOS::stylusTapAtPointWithModifiers):
+        (WTR::UIScriptControllerIOS::dragFromPointToPoint):
+        (WTR::UIScriptControllerIOS::longPressAtPoint):
+        (WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard):
+        (WTR::UIScriptControllerIOS::dismissFilePicker):
+        (WTR::UIScriptControllerIOS::applyAutocorrection):
+        (WTR::UIScriptControllerIOS::simulateRotation):
+        (WTR::UIScriptControllerIOS::simulateRotationLikeSafari):
+        (WTR::UIScriptControllerIOS::setDidStartFormControlInteractionCallback):
+        (WTR::UIScriptControllerIOS::setDidEndFormControlInteractionCallback):
+        (WTR::UIScriptControllerIOS::setDidShowContextMenuCallback):
+        (WTR::UIScriptControllerIOS::setDidDismissContextMenuCallback):
+        (WTR::UIScriptControllerIOS::setWillBeginZoomingCallback):
+        (WTR::UIScriptControllerIOS::setDidEndZoomingCallback):
+        (WTR::UIScriptControllerIOS::setDidShowKeyboardCallback):
+        (WTR::UIScriptControllerIOS::setDidHideKeyboardCallback):
+        (WTR::UIScriptControllerIOS::setWillPresentPopoverCallback):
+        (WTR::UIScriptControllerIOS::setDidDismissPopoverCallback):
+        (WTR::UIScriptControllerIOS::setDidEndScrollingCallback):
+        (WTR::UIScriptControllerIOS::activateDataListSuggestion):
+        (WTR::UIScriptControllerIOS::doAfterDoubleTapDelay):
+        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
+        (WTR::UIScriptControllerMac::zoomToScale):
+        (WTR::UIScriptControllerMac::simulateAccessibilitySettingsChangeNotification):
+        (WTR::UIScriptControllerMac::chooseMenuAction):
+        (WTR::UIScriptControllerMac::activateAtPoint):
+
 2019-12-07  Said Abou-Hallawa  <sabouhall...@apple.com>
 
         Make ColorSpace an enum class

Modified: trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm (253281 => 253282)


--- trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2019-12-09 01:52:19 UTC (rev 253281)
+++ trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm	2019-12-09 07:25:00 UTC (rev 253282)
@@ -32,6 +32,7 @@
 #import "UIScriptContext.h"
 #import <_javascript_Core/OpaqueJSString.h>
 #import <WebCore/FloatRect.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/MainThread.h>
 
 extern DumpRenderTreeBrowserView *gWebBrowserView;
@@ -48,11 +49,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 void UIScriptControllerIOS::zoomToScale(double scale, JSValueRef callback)
@@ -61,11 +62,11 @@
 
     RefPtr<UIScriptController> protectedThis(this);
     dispatch_async(dispatch_get_main_queue(), ^{
-        [gWebScrollView zoomToScale:scale animated:YES completionHandler:^{
+        [gWebScrollView zoomToScale:scale animated:YES completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
             if (!m_context)
                 return;
             m_context->asyncTaskComplete(callbackID);
-        }];
+        }).get()];
     });
 }
 

Modified: trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm (253281 => 253282)


--- trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2019-12-09 01:52:19 UTC (rev 253281)
+++ trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm	2019-12-09 07:25:00 UTC (rev 253282)
@@ -34,6 +34,7 @@
 #import <_javascript_Core/OpaqueJSString.h>
 #import <WebKit/WebKit.h>
 #import <WebKit/WebViewPrivate.h>
+#import <wtf/BlockPtr.h>
 
 #if PLATFORM(MAC)
 
@@ -50,11 +51,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 void UIScriptControllerMac::replaceTextAtRange(JSStringRef text, int location, int length)
@@ -106,11 +107,11 @@
     UNUSED_PARAM(index);
 
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 void UIScriptControllerMac::overridePreference(JSStringRef preferenceRef, JSStringRef valueRef)
@@ -129,11 +130,11 @@
     WebView *webView = [mainFrame webView];
     [webView removeFromSuperview];
 
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 void UIScriptControllerMac::addViewToWindow(JSValueRef callback)
@@ -143,11 +144,11 @@
     WebView *webView = [mainFrame webView];
     [[mainWindow contentView] addSubview:webView];
 
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 void UIScriptControllerMac::toggleCapsLock(JSValueRef callback)

Modified: trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm (253281 => 253282)


--- trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2019-12-09 01:52:19 UTC (rev 253281)
+++ trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm	2019-12-09 07:25:00 UTC (rev 253282)
@@ -120,40 +120,41 @@
 void UIScriptControllerIOS::doAfterPresentationUpdate(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    [webView() _doAfterNextPresentationUpdate:^{
+    [webView() _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::doAfterNextStablePresentationUpdate(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    [webView() _doAfterNextStablePresentationUpdate:^() {
-        if (m_context)
-            m_context->asyncTaskComplete(callbackID);
-    }];
+    [webView() _doAfterNextStablePresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get()];
 }
 
 void UIScriptControllerIOS::ensurePositionInformationIsUpToDateAt(long x, long y, JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    [webView() _requestActivatedElementAtPosition:CGPointMake(x, y) completionBlock:^(_WKActivatedElementInfo *) {
+    [webView() _requestActivatedElementAtPosition:CGPointMake(x, y) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] (_WKActivatedElementInfo *) {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::doAfterVisibleContentRectUpdate(JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    [webView() _doAfterNextVisibleContentRectUpdate:^ {
+    [webView() _doAfterNextVisibleContentRectUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::zoomToScale(double scale, JSValueRef callback)
@@ -160,11 +161,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    [webView() zoomToScale:scale animated:YES completionHandler:^{
+    [webView() zoomToScale:scale animated:YES completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::retrieveSpeakSelectionContent(JSValueRef callback)
@@ -171,11 +172,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     
-    [webView() accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:^() {
+    [webView() accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 JSRetainPtr<JSStringRef> UIScriptControllerIOS::accessibilitySpeakSelectionContent() const
@@ -191,11 +192,11 @@
     NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
     [center postNotificationName:UIAccessibilityInvertColorsStatusDidChangeNotification object:webView];
 
-    [webView _doAfterNextPresentationUpdate: ^{
+    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 double UIScriptControllerIOS::zoomScale() const
@@ -217,11 +218,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] touchDown:location touchCount:touchCount completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] touchDown:location touchCount:touchCount completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::liftUpAtPoint(long x, long y, long touchCount, JSValueRef callback)
@@ -229,11 +230,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] liftUp:location touchCount:touchCount completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] liftUp:location touchCount:touchCount completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::singleTapAtPoint(long x, long y, JSValueRef callback)
@@ -260,11 +261,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] twoFingerTap:location completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] twoFingerTap:location completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::singleTapAtPointWithModifiers(long x, long y, JSValueRef modifierArray, JSValueRef callback)
@@ -299,11 +300,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
-    [[HIDEventGenerator sharedHIDEventGenerator] doubleTap:globalToContentCoordinates(webView(), x, y) delay:delay completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] doubleTap:globalToContentCoordinates(webView(), x, y) delay:delay completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::stylusDownAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
@@ -311,11 +312,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] stylusDownAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] stylusDownAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::stylusMoveToPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
@@ -323,11 +324,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] stylusMoveToPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] stylusMoveToPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::stylusUpAtPoint(long x, long y, JSValueRef callback)
@@ -335,11 +336,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] stylusUpAtPoint:location completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] stylusUpAtPoint:location completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, JSValueRef callback)
@@ -358,7 +359,7 @@
         [[HIDEventGenerator sharedHIDEventGenerator] keyDown:modifierFlag];
 
     auto location = globalToContentCoordinates(webView(), x, y);
-    [[HIDEventGenerator sharedHIDEventGenerator] stylusTapAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] stylusTapAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID, modifierFlags = WTFMove(modifierFlags)] {
         if (!m_context)
             return;
         for (size_t i = modifierFlags.size(); i; ) {
@@ -365,12 +366,12 @@
             --i;
             [[HIDEventGenerator sharedHIDEventGenerator] keyUp:modifierFlags[i]];
         }
-        [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{
+        [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
             if (!m_context)
                 return;
             m_context->asyncTaskComplete(callbackID);
-        }];
-    }];
+        }).get()];
+    }).get()];
 }
 
 void convertCoordinates(TestRunnerWKWebView *webView, NSMutableDictionary *event)
@@ -428,11 +429,11 @@
     CGPoint startPoint = globalToContentCoordinates(webView(), startX, startY);
     CGPoint endPoint = globalToContentCoordinates(webView(), endX, endY);
     
-    [[HIDEventGenerator sharedHIDEventGenerator] dragWithStartPoint:startPoint endPoint:endPoint duration:durationSeconds completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] dragWithStartPoint:startPoint endPoint:endPoint duration:durationSeconds completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
     
 void UIScriptControllerIOS::longPressAtPoint(long x, long y, JSValueRef callback)
@@ -439,11 +440,11 @@
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     
-    [[HIDEventGenerator sharedHIDEventGenerator] longPress:globalToContentCoordinates(webView(), x, y) completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] longPress:globalToContentCoordinates(webView(), x, y) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 void UIScriptControllerIOS::enterText(JSStringRef text)
@@ -457,11 +458,11 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     // Assumes that the keyboard is already shown.
-    [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:^{
+    [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 static UIPhysicalKeyboardEvent *createUIPhysicalKeyboardEvent(NSString *hidInputString, NSString *uiEventInputString, UIKeyModifierFlags modifierFlags, UIKeyboardInputFlags inputFlags, bool isKeyDown)
@@ -522,10 +523,11 @@
 
     // Round-trip with the WebProcess to make sure it has been notified of the dismissal.
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    [webView evaluateJavaScript:@"" completionHandler:^(id result, NSError *error) {
-        if (m_context)
-            m_context->asyncTaskComplete(callbackID);
-    }];
+    [webView evaluateJavaScript:@"" completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] (id result, NSError *error) {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get()];
 }
 
 JSRetainPtr<JSStringRef> UIScriptControllerIOS::selectFormPopoverTitle() const
@@ -654,15 +656,18 @@
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
 
     TestRunnerWKWebView *webView = this->webView();
-    [webView applyAutocorrection:toWTFString(toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:^ {
-        // applyAutocorrection can call its completion handler synchronously,
-        // which makes UIScriptController unhappy (see bug 172884).
-        dispatch_async(dispatch_get_main_queue(), ^ {
+    [webView applyAutocorrection:toWTFString(toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+        dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+            // applyAutocorrection can call its completion handler synchronously,
+            // which makes UIScriptController unhappy (see bug 172884).
             if (!m_context)
                 return;
             m_context->asyncTaskComplete(callbackID);
-        });
-    }];
+        }).get());
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get()];
 }
 
 double UIScriptControllerIOS::minimumZoomScale() const
@@ -804,11 +809,11 @@
     
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     
-    webView.rotationDidEndCallback = ^{
+    webView.rotationDidEndCallback = makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    };
+    }).get();
     
     [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
 }
@@ -820,11 +825,11 @@
     
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
     
-    webView.rotationDidEndCallback = ^{
+    webView.rotationDidEndCallback = makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    };
+    }).get();
     
     [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
 }
@@ -832,81 +837,81 @@
 void UIScriptControllerIOS::setDidStartFormControlInteractionCallback(JSValueRef callback)
 {
     UIScriptController::setDidStartFormControlInteractionCallback(callback);
-    webView().didStartFormControlInteractionCallback = ^{
+    webView().didStartFormControlInteractionCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidStartFormControlInteraction);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidEndFormControlInteractionCallback(JSValueRef callback)
 {
     UIScriptController::setDidEndFormControlInteractionCallback(callback);
-    webView().didEndFormControlInteractionCallback = ^{
+    webView().didEndFormControlInteractionCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
-    };
+    }).get();
 }
     
 void UIScriptControllerIOS::setDidShowContextMenuCallback(JSValueRef callback)
 {
     UIScriptController::setDidShowContextMenuCallback(callback);
-    webView().didShowContextMenuCallback = ^{
+    webView().didShowContextMenuCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidShowContextMenu);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidDismissContextMenuCallback(JSValueRef callback)
 {
     UIScriptController::setDidDismissContextMenuCallback(callback);
-    webView().didDismissContextMenuCallback = ^{
+    webView().didDismissContextMenuCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setWillBeginZoomingCallback(JSValueRef callback)
 {
     UIScriptController::setWillBeginZoomingCallback(callback);
-    webView().willBeginZoomingCallback = ^{
+    webView().willBeginZoomingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeWillBeginZooming);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidEndZoomingCallback(JSValueRef callback)
 {
     UIScriptController::setDidEndZoomingCallback(callback);
-    webView().didEndZoomingCallback = ^{
+    webView().didEndZoomingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidEndZooming);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidShowKeyboardCallback(JSValueRef callback)
 {
     UIScriptController::setDidShowKeyboardCallback(callback);
-    webView().didShowKeyboardCallback = ^{
+    webView().didShowKeyboardCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidShowKeyboard);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidHideKeyboardCallback(JSValueRef callback)
 {
     UIScriptController::setDidHideKeyboardCallback(callback);
-    webView().didHideKeyboardCallback = ^{
+    webView().didHideKeyboardCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidHideKeyboard);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::chooseMenuAction(JSStringRef jsAction, JSValueRef callback)
@@ -931,21 +936,21 @@
 void UIScriptControllerIOS::setWillPresentPopoverCallback(JSValueRef callback)
 {
     UIScriptController::setWillPresentPopoverCallback(callback);
-    webView().willPresentPopoverCallback = ^{
+    webView().willPresentPopoverCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeWillPresentPopover);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::setDidDismissPopoverCallback(JSValueRef callback)
 {
     UIScriptController::setDidDismissPopoverCallback(callback);
-    webView().didDismissPopoverCallback = ^{
+    webView().didDismissPopoverCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidDismissPopover);
-    };
+    }).get();
 }
 
 JSObjectRef UIScriptControllerIOS::rectForMenuAction(JSStringRef jsAction) const
@@ -1004,11 +1009,11 @@
 void UIScriptControllerIOS::setDidEndScrollingCallback(JSValueRef callback)
 {
     UIScriptController::setDidEndScrollingCallback(callback);
-    webView().didEndScrollingCallback = ^{
+    webView().didEndScrollingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
         if (!m_context)
             return;
         m_context->fireCallback(CallbackTypeDidEndScrolling);
-    };
+    }).get();
 }
 
 void UIScriptControllerIOS::clearAllCallbacks()
@@ -1038,11 +1043,11 @@
     UNUSED_PARAM(index);
 
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
-    dispatch_async(dispatch_get_main_queue(), ^{
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    });
+    }).get());
 }
 
 bool UIScriptControllerIOS::isShowingDataListSuggestions() const
@@ -1193,10 +1198,11 @@
         maximumIntervalBetweenSuccessiveTaps += additionalDelayBetweenSuccessiveTaps;
     }
 
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(maximumIntervalBetweenSuccessiveTaps * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        if (m_context)
-            m_context->asyncTaskComplete(callbackID);
-    });
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(maximumIntervalBetweenSuccessiveTaps * NSEC_PER_SEC)), dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get());
 }
 
 void UIScriptControllerIOS::copyText(JSStringRef text)

Modified: trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm (253281 => 253282)


--- trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2019-12-09 01:52:19 UTC (rev 253281)
+++ trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm	2019-12-09 07:25:00 UTC (rev 253282)
@@ -43,6 +43,7 @@
 #import <_javascript_Core/_javascript_Core.h>
 #import <_javascript_Core/OpaqueJSString.h>
 #import <WebKit/WKWebViewPrivate.h>
+#import <wtf/BlockPtr.h>
 
 namespace WTR {
 
@@ -68,11 +69,11 @@
     auto* webView = this->webView();
     [webView _setPageScale:scale withOrigin:CGPointZero];
 
-    [webView _doAfterNextPresentationUpdate:^{
+    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 double UIScriptControllerMac::zoomScale() const
@@ -88,11 +89,11 @@
     NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
     [center postNotificationName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:webView];
 
-    [webView _doAfterNextPresentationUpdate:^{
+    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
         if (!m_context)
             return;
         m_context->asyncTaskComplete(callbackID);
-    }];
+    }).get()];
 }
 
 bool UIScriptControllerMac::isShowingDataListSuggestions() const
@@ -171,10 +172,11 @@
         [activeMenu cancelTracking];
     }
 
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (m_context)
-            m_context->asyncTaskComplete(callbackID);
-    });
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get());
 }
 
 void UIScriptControllerMac::beginBackSwipe(JSValueRef callback)
@@ -247,10 +249,11 @@
     eventSender->mouseDown(0, 0);
     eventSender->mouseUp(0, 0);
 
-    dispatch_async(dispatch_get_main_queue(), ^{
-        if (m_context)
-            m_context->asyncTaskComplete(callbackID);
-    });
+    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
+        if (!m_context)
+            return;
+        m_context->asyncTaskComplete(callbackID);
+    }).get());
 }
 
 void UIScriptControllerMac::copyText(JSStringRef text)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to