function boo() { throw new Error(); }
let foo = await boo();
I expect it will throw as if there was not the await expression. (Note, boo is not an async function.) However, I fail to find description of this code behavior in the ECMAScript spec.
Here is how await expression should be executed:
AwaitExpression : await UnaryExpression
1. Let exprRef be the result of evaluating UnaryExpression.
2. Let value be ? GetValue(exprRef).
3. Return ? Await(value).
GetValue results with an abrupt completion, so Await routine gets it as an argument.
It is the place where things become unclear to me. The Await wraps value in a promise. It is achieved with an aid of PromiseResolve procedure, which resolves the promise with value.
So should foo be set to an instance of Error thrown from boo? It is of course nonsense. But I am tied in knots and can't find another way in the spec.
GetValueresults with an abrupt completion, soAwaitroutine gets it as an argument.
No, the Await abstract operation is never executed. You're missing the (subtle) ? sign in front of ?GetValue(exprRef), which is a shorthand for ReturnIfAbrupt:
2. Let value be ReturnIfAbrupt(GetValue(exprRef))
so if there's an abrupt completion, it will just terminate the evaluation of the await and return the abrupt completion to the evaluation of the assignment expression.