[Webkit-unassigned] [Bug 165681] Web Inspector: Console could be made useful for very simple await expressions

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Dec 9 14:45:54 PST 2016


https://bugs.webkit.org/show_bug.cgi?id=165681

--- Comment #1 from Brian Burg <bburg at apple.com> ---
(In reply to comment #0)
> Summary:
> Console could be made useful for very simple await expressions
> 
> In the console it would be really useful to just type:
> 
>     json = await fetch("data.json")
> 
> However `await` won't work unless it is inside of an async function. So to
> do something like this you would need to end up with something like:
> 
>     var json; (async function() { json = await fetch("data.json") })();
> 
> Or, if await was unavailable, then users would have to:
> 
>     var json; fetch("data.json").then((x) => { json = x });
> 
> I could see a useful convenience for the Inspector Console to allow you to
> run await expressions to populate a variable. Typing `x = await
> fetch("foo.json")` will eventually populate `x`. In practice the populate is
> almost immediate (JavaScript executes very quickly, and a human types
> relatively slowly). But it can be a long running operation in which case we
> could inform the user the value has populated.
> 
>     Example input:
> 
>         (a) await 10
>         (b) json = await fetch("data.json")
> 
>     Sample Detection:
> 
>         1. Input fail to parse normally.
>         2. Input succeed parsing if wrapped in "(async function() {" + input
> + "})"

Are there conflicts? Could other syntax errors aside from `await` be made whole? If so we might need to sniff for the actual `await` keyword.

>         3. If there are multiple `await` expressions, bail.
>            - Convenience is meant for something very simple, if you are
> doing complex code just write the full syntax.
>         4. If there was an assignment use the variable name, otherwise use
> $result.
>            - We could even make $result a Console ONLY value like
> $exception, $0, $1..$99 etc
> 
>     Transformation for (a) and (b):
> 
>         var $result;
>         (async function() {
>           $result = await 10;
>           console.info("`$result` populated");
>         })();
> 
>         var json;
>         (async function() {
>              let start = Date.now();
>              json = await fetch("data.json");
>              let end = Date.now();
>              // If this took more than one second to populate, tell the user
> it populated.
>              if ((end - start) > 1000)
>                  console.info("`json` populated");
>          })();
> 
> What do people think?
> 
> Advantages: Let users make use of await expressions in the console to
> simplify poking around in the console
> Disadvantages: Obfuscates the fact that await can only be used in async
> functions. Can be misleading.
> Precedent: We already do a convenience conversion for: `{a:1,b:2}` to
> `({a:1,b:2})` to produce objects instead of producing a Syntax Error for
> labelled statements

Let's do it!

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20161209/5c48fce1/attachment.html>


More information about the webkit-unassigned mailing list