Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda