Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda