ctx = vm->top_frame->function->context;
value = njs_arg(args, nargs, 1);
- if (njs_is_error(value)) {
- goto failed;
- }
async_frame = ctx->await;
async = &async_frame->native;
value = njs_arg(args, nargs, 1);
if (ctx->await->native.pc == ctx->pc) {
+ /* No catch block was set before await. */
(void) njs_function_call(vm, njs_function(&ctx->capability->reject),
&njs_value_undefined, value, 1, &vm->retval);
return NJS_ERROR;
}
+ /* ctx->await->native.pc points to a catch block here. */
+
ctx->pc = ctx->await->native.pc;
return njs_await_fulfilled(vm, args, nargs, unused);
--- /dev/null
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stages = [];
+const fn = async () => { throw new Error('Oops') };
+
+async function af() {
+ try {
+ await fn();
+
+ $DONOTEVALUATE();
+ }
+ catch (v) {
+ stages.push(`catch:${v}`);
+ }
+ finally {
+ stages.push('finally');
+ }
+
+ return "end";
+};
+
+af().then(v => {
+ stages.push(v);
+ assert.compareArray(stages, ['catch:Error: Oops', 'finally', 'end']);
+})
+.then($DONE, $DONE)
--- /dev/null
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stages = [];
+
+async function af() {
+ try {
+ await ({}).a.a();
+
+ $DONOTEVALUATE();
+ }
+ catch (v) {
+ stages.push('catch');
+ }
+ finally {
+ stages.push('finally');
+ }
+
+ return "end";
+};
+
+af().then(v => {
+ stages.push(v);
+ assert.compareArray(stages, ['catch', 'finally', 'end']);
+})
+.then($DONE, $DONE)