Bug 206364 - Make the callAsyncJavaScriptFunction function actually be async (so await works)
Summary: Make the callAsyncJavaScriptFunction function actually be async (so await works)
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Website (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-16 11:22 PST by Brady Eidson
Modified: 2020-01-17 10:47 PST (History)
6 users (show)

See Also:


Attachments
Patch (7.49 KB, patch)
2020-01-16 11:39 PST, Brady Eidson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brady Eidson 2020-01-16 11:22:16 PST
Make the callAsyncJavaScriptFunction function actually be async (so await works)

<rdar://problem/58571682>
Comment 1 Brady Eidson 2020-01-16 11:39:11 PST
Created attachment 387938 [details]
Patch
Comment 2 Geoffrey Garen 2020-01-16 11:41:31 PST
Comment on attachment 387938 [details]
Patch

r=me
Comment 3 Devin Rousso 2020-01-16 11:47:02 PST
Comment on attachment 387938 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=387938&action=review

> Source/WebCore/bindings/js/ScriptController.cpp:607
> +    functionStringBuilder.append("(async function(");

One issue with making a function `async` is that they _always_ return a `Promise`.  I think it would be better to have `ScriptController:callInWorld` take an `enum class IsAsync { Yes, No };` so that callers can decide whether or not they want this.
Comment 4 Brady Eidson 2020-01-16 11:57:38 PST
(In reply to Devin Rousso from comment #3)
> Comment on attachment 387938 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=387938&action=review
> 
> > Source/WebCore/bindings/js/ScriptController.cpp:607
> > +    functionStringBuilder.append("(async function(");
> 
> One issue with making a function `async` is that they _always_ return a
> `Promise`.  

Which is fine, because literally the only client of this is "callAsyncJavaScriptFunction" which expects promise results.

> I think it would be better to have
> `ScriptController:callInWorld` take an `enum class IsAsync { Yes, No };` so
> that callers can decide whether or not they want this.

There's no reason to do now that because there would be no client of "No"
Comment 5 WebKit Commit Bot 2020-01-16 13:30:43 PST
Comment on attachment 387938 [details]
Patch

Clearing flags on attachment: 387938

Committed r254704: <https://trac.webkit.org/changeset/254704>
Comment 6 WebKit Commit Bot 2020-01-16 13:30:45 PST
All reviewed patches have been landed.  Closing bug.
Comment 7 Saam Barati 2020-01-16 23:45:11 PST
(In reply to Devin Rousso from comment #3)
> Comment on attachment 387938 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=387938&action=review
> 
> > Source/WebCore/bindings/js/ScriptController.cpp:607
> > +    functionStringBuilder.append("(async function(");
> 
> One issue with making a function `async` is that they _always_ return a
> `Promise`.  I think it would be better to have
> `ScriptController:callInWorld` take an `enum class IsAsync { Yes, No };` so
> that callers can decide whether or not they want this.

Why would the API change here? When the Promise that’s returned is resolved, we IPC the result back to the UI process, so I think it should not be (very) observable to users. (Like if you treat it like a non async function, and do something like “return 42;”, everything Just Works and the UI process is called back with “42”.)

I think the only concern here is that async functions have slightly different semantics than non async functions. I think(?) things like reserved identifiers and such. But I think that’s ok here, especially because this will be documented.
Comment 8 Devin Rousso 2020-01-17 10:47:05 PST
Comment on attachment 387938 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=387938&action=review

>>>> Source/WebCore/bindings/js/ScriptController.cpp:607
>>>> +    functionStringBuilder.append("(async function(");
>>> 
>>> One issue with making a function `async` is that they _always_ return a `Promise`.  I think it would be better to have `ScriptController:callInWorld` take an `enum class IsAsync { Yes, No };` so that callers can decide whether or not they want this.
>> 
>> Which is fine, because literally the only client of this is "callAsyncJavaScriptFunction" which expects promise results.
> 
> Why would the API change here? When the Promise that’s returned is resolved, we IPC the result back to the UI process, so I think it should not be (very) observable to users. (Like if you treat it like a non async function, and do something like “return 42;”, everything Just Works and the UI process is called back with “42”.)
> 
> I think the only concern here is that async functions have slightly different semantics than non async functions. I think(?) things like reserved identifiers and such. But I think that’s ok here, especially because this will be documented.

I misread how `ScriptController::callInWorld` was being used.  My apologies for the confusion.