<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&#64;apple.com" title="Brian Burg &lt;bburg&#64;apple.com&gt;"> <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">&gt; Summary:
&gt; Console could be made useful for very simple await expressions
&gt; 
&gt; In the console it would be really useful to just type:
&gt; 
&gt;     json = await fetch(&quot;data.json&quot;)
&gt; 
&gt; However `await` won't work unless it is inside of an async function. So to
&gt; do something like this you would need to end up with something like:
&gt; 
&gt;     var json; (async function() { json = await fetch(&quot;data.json&quot;) })();
&gt; 
&gt; Or, if await was unavailable, then users would have to:
&gt; 
&gt;     var json; fetch(&quot;data.json&quot;).then((x) =&gt; { json = x });
&gt; 
&gt; I could see a useful convenience for the Inspector Console to allow you to
&gt; run await expressions to populate a variable. Typing `x = await
&gt; fetch(&quot;foo.json&quot;)` will eventually populate `x`. In practice the populate is
&gt; almost immediate (JavaScript executes very quickly, and a human types
&gt; relatively slowly). But it can be a long running operation in which case we
&gt; could inform the user the value has populated.
&gt; 
&gt;     Example input:
&gt; 
&gt;         (a) await 10
&gt;         (b) json = await fetch(&quot;data.json&quot;)
&gt; 
&gt;     Sample Detection:
&gt; 
&gt;         1. Input fail to parse normally.
&gt;         2. Input succeed parsing if wrapped in &quot;(async function() {&quot; + input
&gt; + &quot;})&quot;</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">&gt;         3. If there are multiple `await` expressions, bail.
&gt;            - Convenience is meant for something very simple, if you are
&gt; doing complex code just write the full syntax.
&gt;         4. If there was an assignment use the variable name, otherwise use
&gt; $result.
&gt;            - We could even make $result a Console ONLY value like
&gt; $exception, $0, $1..$99 etc
&gt; 
&gt;     Transformation for (a) and (b):
&gt; 
&gt;         var $result;
&gt;         (async function() {
&gt;           $result = await 10;
&gt;           console.info(&quot;`$result` populated&quot;);
&gt;         })();
&gt; 
&gt;         var json;
&gt;         (async function() {
&gt;              let start = Date.now();
&gt;              json = await fetch(&quot;data.json&quot;);
&gt;              let end = Date.now();
&gt;              // If this took more than one second to populate, tell the user
&gt; it populated.
&gt;              if ((end - start) &gt; 1000)
&gt;                  console.info(&quot;`json` populated&quot;);
&gt;          })();
&gt; 
&gt; What do people think?
&gt; 
&gt; Advantages: Let users make use of await expressions in the console to
&gt; simplify poking around in the console
&gt; Disadvantages: Obfuscates the fact that await can only be used in async
&gt; functions. Can be misleading.
&gt; Precedent: We already do a convenience conversion for: `{a:1,b:2}` to
&gt; `({a:1,b:2})` to produce objects instead of producing a Syntax Error for
&gt; 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>