Title: [262849] trunk/Source/WebKit
Revision
262849
Author
[email protected]
Date
2020-06-10 12:26:14 -0700 (Wed, 10 Jun 2020)

Log Message

Swift Overlay API refinements
https://bugs.webkit.org/show_bug.cgi?id=212939
<rdar://problem/64140013>

Reviewed by Darin Adler.

This patch cleans up some inconsistencies in the various Swift projections,
and modifies _javascript_ evaluation callbacks to be optional to account for
scripts which may not evaluate to a useful result (such as ones that simply
modify the DOM without reporting a status). It also standardizes on using
completionHandler as an argument label to match the rest of WebKit API, and
the majority of the Swift API refinements.

It also fixes a module issue where the WebKit.h umbrella was missing an
import of WKScriptReplyWithMessageHandler.h, making the type unusable from
Swift source files/

* Shared/API/Cocoa/WebKit.h: Add missing header.
* UIProcess/API/Cocoa/WebKitSwiftOverlay.swift:
(callAsyncJavaScript(_:arguments:in:completionHandler:)): Rename completion
    argument, and make optional. Note: Optional closures are implicitly
    @escaping, making the annotation redundant and incompatible, so it must
    be removed. In Swift, Optional.map()'s closure is invoked iff the Optional
    contains some value, and the result of that transform is returned, else
    nil is propagated. This allows us to apply the closure transform if the
    client value is non-nil, without using intermediary variables or if/let.
(evaluateJavaScript(_:in:completionHandler:)): Ditto.
* SwiftOverlay/Tests/WebKitTests.swift:
(WebKitTests.testAPI): Update names to reflect changes.
* SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything (Catalyst).xcscheme:
    Ensure that the unit test files get built as part of Build & Run, so that
    any changes to names get flagged without even running the tests.
* SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything.xcscheme:
    Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (262848 => 262849)


--- trunk/Source/WebKit/ChangeLog	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/ChangeLog	2020-06-10 19:26:14 UTC (rev 262849)
@@ -1,3 +1,40 @@
+2020-06-10  James Savage  <[email protected]>
+
+        Swift Overlay API refinements
+        https://bugs.webkit.org/show_bug.cgi?id=212939
+        <rdar://problem/64140013>
+
+        Reviewed by Darin Adler.
+
+        This patch cleans up some inconsistencies in the various Swift projections,
+        and modifies _javascript_ evaluation callbacks to be optional to account for
+        scripts which may not evaluate to a useful result (such as ones that simply
+        modify the DOM without reporting a status). It also standardizes on using
+        completionHandler as an argument label to match the rest of WebKit API, and
+        the majority of the Swift API refinements.
+        
+        It also fixes a module issue where the WebKit.h umbrella was missing an
+        import of WKScriptReplyWithMessageHandler.h, making the type unusable from
+        Swift source files/
+
+        * Shared/API/Cocoa/WebKit.h: Add missing header.
+        * UIProcess/API/Cocoa/WebKitSwiftOverlay.swift:
+        (callAsyncJavaScript(_:arguments:in:completionHandler:)): Rename completion
+            argument, and make optional. Note: Optional closures are implicitly
+            @escaping, making the annotation redundant and incompatible, so it must
+            be removed. In Swift, Optional.map()'s closure is invoked iff the Optional
+            contains some value, and the result of that transform is returned, else
+            nil is propagated. This allows us to apply the closure transform if the
+            client value is non-nil, without using intermediary variables or if/let.
+        (evaluateJavaScript(_:in:completionHandler:)): Ditto.
+        * SwiftOverlay/Tests/WebKitTests.swift:
+        (WebKitTests.testAPI): Update names to reflect changes.
+        * SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything (Catalyst).xcscheme:
+            Ensure that the unit test files get built as part of Build & Run, so that
+            any changes to names get flagged without even running the tests.
+        * SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything.xcscheme:
+            Ditto.
+
 2020-06-10  Kate Cheney  <[email protected]>
 
         ASSERTION FAILED: suspendedState == State::Running in WebKit::WebResourceLoadStatisticsStore::suspend

Modified: trunk/Source/WebKit/Shared/API/Cocoa/WebKit.h (262848 => 262849)


--- trunk/Source/WebKit/Shared/API/Cocoa/WebKit.h	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/Shared/API/Cocoa/WebKit.h	2020-06-10 19:26:14 UTC (rev 262849)
@@ -49,6 +49,7 @@
 #import <WebKit/WKProcessPool.h>
 #import <WebKit/WKScriptMessage.h>
 #import <WebKit/WKScriptMessageHandler.h>
+#import <WebKit/WKScriptMessageHandlerWithReply.h>
 #import <WebKit/WKSecurityOrigin.h>
 #import <WebKit/WKSnapshotConfiguration.h>
 #import <WebKit/WKUIDelegate.h>

Modified: trunk/Source/WebKit/SwiftOverlay/Tests/WebKitTests.swift (262848 => 262849)


--- trunk/Source/WebKit/SwiftOverlay/Tests/WebKitTests.swift	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/SwiftOverlay/Tests/WebKitTests.swift	2020-06-10 19:26:14 UTC (rev 262849)
@@ -30,10 +30,10 @@
     /// This is a compile-time test that ensures the function names are what we expect.
     func testAPI() {
         _ = WKContentWorld.world(name:)
-        _ = WKWebView.callAsyncJavaScript(_:arguments:in:completion:)
+        _ = WKWebView.callAsyncJavaScript(_:arguments:in:completionHandler:)
         _ = WKWebView.createPDF(configuration:completionHandler:)
         _ = WKWebView.createWebArchiveData(completionHandler:)
-        _ = WKWebView.evaluateJavaScript(_:in:completion:)
+        _ = WKWebView.evaluateJavaScript(_:in:completionHandler:)
         _ = WKWebView.find(_:configuration:completionHandler:)
     }
 

Modified: trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything (Catalyst).xcscheme (262848 => 262849)


--- trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything (Catalyst).xcscheme	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything (Catalyst).xcscheme	2020-06-10 19:26:14 UTC (rev 262849)
@@ -20,6 +20,20 @@
                ReferencedContainer = "container:WebKitSwiftOverlay.xcodeproj">
             </BuildableReference>
          </BuildActionEntry>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "NO"
+            buildForArchiving = "NO"
+            buildForAnalyzing = "NO">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "7D20071522F4ECCA008DF640"
+               BuildableName = "WebKitSwiftOverlayTests-maccatalyst.xctest"
+               BlueprintName = "WebKitSwiftOverlayTests-maccatalyst"
+               ReferencedContainer = "container:WebKitSwiftOverlay.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
       </BuildActionEntries>
    </BuildAction>
    <TestAction

Modified: trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything.xcscheme (262848 => 262849)


--- trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything.xcscheme	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/SwiftOverlay/WebKitSwiftOverlay.xcodeproj/xcshareddata/xcschemes/Everything.xcscheme	2020-06-10 19:26:14 UTC (rev 262849)
@@ -22,7 +22,7 @@
          </BuildActionEntry>
          <BuildActionEntry
             buildForTesting = "YES"
-            buildForRunning = "NO"
+            buildForRunning = "YES"
             buildForProfiling = "NO"
             buildForArchiving = "NO"
             buildForAnalyzing = "NO">

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WebKitSwiftOverlay.swift (262848 => 262849)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WebKitSwiftOverlay.swift	2020-06-10 19:20:39 UTC (rev 262848)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WebKitSwiftOverlay.swift	2020-06-10 19:26:14 UTC (rev 262849)
@@ -35,8 +35,8 @@
 
 @available(iOS 14.0, macOS 10.16, *)
 extension WKWebView {
-    public func callAsyncJavaScript(_ functionBody: String, arguments: [String:Any] = [:], in contentWorld: WKContentWorld, completion: @escaping(Result<Any, Error>) -> Void) {
-        __callAsyncJavaScript(functionBody, arguments: arguments, in: contentWorld, completionHandler: makeResultHandler(completion))
+    public func callAsyncJavaScript(_ functionBody: String, arguments: [String:Any] = [:], in contentWorld: WKContentWorld, completionHandler: ((Result<Any, Error>) -> Void)? = nil) {
+        __callAsyncJavaScript(functionBody, arguments: arguments, in: contentWorld, completionHandler: completionHandler.map(makeResultHandler))
     }
 
     public func createPDF(configuration: WKPDFConfiguration = .init(), completionHandler: @escaping (Result<Data, Error>) -> Void) {
@@ -47,8 +47,8 @@
         __createWebArchiveData(completionHandler: makeResultHandler(completionHandler))
     }
 
-    public func evaluateJavaScript(_ _javascript_: String, in contentWorld: WKContentWorld, completion: @escaping (Result<Any, Error>) -> Void) {
-        __evaluateJavaScript(_javascript_, in: contentWorld, completionHandler: makeResultHandler(completion))
+    public func evaluateJavaScript(_ _javascript_: String, in contentWorld: WKContentWorld, completionHandler: ((Result<Any, Error>) -> Void)? = nil) {
+        __evaluateJavaScript(_javascript_, in: contentWorld, completionHandler: completionHandler.map(makeResultHandler))
     }
 
     public func find(_ string: String, configuration: WKFindConfiguration = .init(), completionHandler: @escaping (WKFindResult) -> Void) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to