Previously, the result of module evaluation was awaited, but the
outcome was not checked:
- a rejected top-level await was silently ignored;
- a top-level await on a promise settled only by a timer or another
asynchronous event remained pending.
In both cases the module was considered loaded without its exports
and each request failed later with a misleading "js function not
found" error.
Now, both cases fail the context creation with an explicit error.
The issue was introduced in
9a5430e6 (0.9.5).
}
rc = ngx_qjs_await(cx, ctx->log, &rv);
- JS_FreeValue(cx, rv);
- if (rc == NGX_ERROR) {
+ if (rc == NGX_ERROR || JS_IsException(rv)) {
+ JS_FreeValue(cx, rv);
ngx_qjs_log_exception(engine, ctx->log, "await exception");
goto failed;
}
+ if (JS_PromiseState(cx, rv) == JS_PROMISE_PENDING) {
+ JS_FreeValue(cx, rv);
+ ngx_log_error(NGX_LOG_ERR, ctx->log, 0,
+ "js top-level await is not settled");
+ goto failed;
+ }
+
+ JS_FreeValue(cx, rv);
+
return engine;
failed: