{
njs_int_t ret;
njs_value_t **cur_local, **cur_closures, **cur_temp, *value;
- njs_frame_t *frame;
+ njs_frame_t *frame, *async_frame;
njs_function_t *function;
njs_async_ctx_t *ctx;
njs_native_frame_t *top, *async;
goto failed;
}
- async = ctx->await;
+ async_frame = ctx->await;
+ async = &async_frame->native;
async->previous = vm->top_frame;
function = async->function;
vm->levels[NJS_LEVEL_TEMP] = async->temp;
vm->top_frame = async;
- vm->active_frame = (njs_frame_t *) async;
+ vm->active_frame = async_frame;
*njs_scope_value(vm, ctx->index) = *value;
vm->retval = *value;
value = njs_arg(args, nargs, 1);
- if (ctx->await->pc == ctx->pc) {
+ if (ctx->await->native.pc == ctx->pc) {
(void) njs_function_call(vm, njs_function(&ctx->capability->reject),
&njs_value_undefined, value, 1, &vm->retval);
return NJS_ERROR;
}
- ctx->pc = ctx->await->pc;
+ ctx->pc = ctx->await->native.pc;
return njs_await_fulfilled(vm, args, nargs, unused);
}
typedef struct {
njs_promise_capability_t *capability;
- njs_native_frame_t *await;
+ njs_frame_t *await;
uintptr_t index;
u_char *pc;
} njs_async_ctx_t;
njs_int_t
-njs_function_frame_save(njs_vm_t *vm, njs_native_frame_t *native, u_char *pc)
+njs_function_frame_save(njs_vm_t *vm, njs_frame_t *frame, u_char *pc)
{
size_t value_count, n;
njs_value_t *start, *end, *p, **new, *value, **local;
njs_function_t *function;
- njs_native_frame_t *active;
+ njs_native_frame_t *active, *native;
+
+ *frame = *vm->active_frame;
+ frame->previous_active_frame = NULL;
+
+ native = &frame->native;
active = &vm->active_frame->native;
value_count = njs_function_frame_value_count(active);
value = (njs_value_t *) (new + value_count
+ function->u.lambda->temp);
- *native = *active;
native->arguments = value;
native->arguments_offset = value + (function->args_offset - 1);
njs_int_t njs_function_native_call(njs_vm_t *vm);
njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
-njs_int_t njs_function_frame_save(njs_vm_t *vm, njs_native_frame_t *native,
+njs_int_t njs_function_frame_save(njs_vm_t *vm, njs_frame_t *native,
u_char *pc);
njs_object_type_t njs_function_object_type(njs_vm_t *vm,
njs_function_t *function);
frame = (njs_frame_t *) active;
if (frame->exception.catch != NULL) {
- ctx->await->pc = frame->exception.catch;
+ ctx->await->native.pc = frame->exception.catch;
} else {
- ctx->await->pc = ctx->pc;
+ ctx->await->native.pc = ctx->pc;
}
fulfilled->context = ctx;
--- /dev/null
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)});
+}
+
+async function add(x) {
+ try {
+ const a = await pr(x);
+ throw 'Oops';
+ return a + b;
+
+ } catch (e) {
+ return `catch: ${e.toString()}`;
+ }
+}
+
+add(50)
+.then(
+ v => assert.sameValue(v, 'catch: Oops'),
+ v => $DONOTEVALUATE(),
+).then($DONE, $DONE);