[Webkit-unassigned] [Bug 165681] New: 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 13:43:34 PST 2016
https://bugs.webkit.org/show_bug.cgi?id=165681
Bug ID: 165681
Summary: Web Inspector: Console could be made useful for very
simple await expressions
Classification: Unclassified
Product: WebKit
Version: WebKit Nightly Build
Hardware: All
OS: All
Status: NEW
Severity: Normal
Priority: P2
Component: Web Inspector
Assignee: webkit-unassigned at lists.webkit.org
Reporter: joepeck at webkit.org
CC: bburg at apple.com, caitp at igalia.com, joepeck at webkit.org,
mattbaker at apple.com, nvasilyev at apple.com,
sbarati at apple.com, timothy at apple.com,
utatane.tea at gmail.com,
webkit-bug-importer at group.apple.com
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 + "})"
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
--
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/329c4938/attachment-0001.html>
More information about the webkit-unassigned
mailing list