Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
If not async function is awaited and throws, should caller code throw too?
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

GetValue results with an abrupt completion, so Await routine 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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!