<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - Web Inspector: Console could be made useful for very simple await expressions"
href="https://bugs.webkit.org/show_bug.cgi?id=165681#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - Web Inspector: Console could be made useful for very simple await expressions"
href="https://bugs.webkit.org/show_bug.cgi?id=165681">bug 165681</a>
from <span class="vcard"><a class="email" href="mailto:bburg@apple.com" title="Brian Burg <bburg@apple.com>"> <span class="fn">Brian Burg</span></a>
</span></b>
<pre>(In reply to <a href="show_bug.cgi?id=165681#c0">comment #0</a>)
<span class="quote">> 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
> + "})"</span >
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.
<span class="quote">> 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</span >
Let's do it!</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>