Changeset 259005 in webkit
- Timestamp:
- Mar 25, 2020 1:02:59 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r258995 r259005 1 2020-03-25 Brady Eidson <beidson@apple.com> 2 3 Some WKWebView.h header doc cleanup. 4 https://bugs.webkit.org/show_bug.cgi?id=209549 5 6 Reviewed by Simon Fraser. 7 8 * UIProcess/API/Cocoa/WKWebView.h: 9 1 10 2020-03-25 Daniel Bates <dabates@apple.com> 2 11 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.h
r257819 r259005 234 234 Those changes will only be visibile to scripts executed in the same WKContentWorld. 235 235 evaluateJavaScript: is a great way to set up global state for future JavaScript execution in a given world. (e.g. Importing libraries/utilities that future JavaScript execution will rely on) 236 Once your global state is set up, consider using callAsyncJavaScript Function: for more flexible interaction with the JavaScript programming model.236 Once your global state is set up, consider using callAsyncJavaScript: for more flexible interaction with the JavaScript programming model. 237 237 */ 238 238 - (void)evaluateJavaScript:(NSString *)javaScriptString inContentWorld:(WKContentWorld *)contentWorld completionHandler:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler NS_REFINED_FOR_SWIFT WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); … … 244 244 @param completionHandler A block to invoke with the return value of the function call, or with the asynchronous resolution of the function's return value. 245 245 @discussion The functionBody string is treated as an anonymous JavaScript function body that can be called with named arguments. 246 Do not format your string as one of the variants of function call available in JavaScript. 247 Instead pass in a JavaScript string representing the function body, formatted for evaluation. 246 Do not format your functionBody string as a function-like callable object as you would in pure JavaScript. 247 Your functionBody string should contain only the function body you want executed. 248 248 249 For example do not pass in the string: 249 function(x, y, z) { return x ? y : z; } 250 @textblock 251 function(x, y, z) 252 { 253 return x ? y : z; 254 } 255 @/textblock 256 250 257 Instead pass in the string: 258 @textblock 251 259 return x ? y : z; 260 @/textblock 252 261 253 262 The arguments dictionary supplies the values for those arguments which are serialized into JavaScript equivalents. 254 263 For example: 264 @textblock 255 265 @{ @"x" : @YES, @"y" : @1, @"z" : @"hello world" }; 256 257 Combining the above arguments dictionary with the above functionBody string, a function with the arguments named "x", "y", and "z" is called with values YES, 1, and "hello world" respectively. 266 @/textblock 267 268 Combining the above arguments dictionary with the above functionBody string, a function with the arguments named "x", "y", and "z" is called with values true, 1, and "hello world" respectively. 258 269 259 270 Allowed argument types are: … … 280 291 Since the function is a JavaScript "async" function you can use JavaScript "await" on thenable objects inside your function body. 281 292 For example: 293 @textblock 282 294 var p = new Promise(function (f) { 283 295 window.setTimeout("f(42)", 1000); … … 285 297 await p; 286 298 return p; 299 @/textblock 287 300 288 301 The above function text will create a promise that will fulfull with the value 42 after a one second delay, wait for it to resolve, then return the fulfillment value of 42.
Note: See TracChangeset
for help on using the changeset viewer.