Welcome! Log In Create A New Profile

Advanced

[njs] Fixed order of code execution after await in try block.

Alexander Borisov
September 01, 2021 02:28PM
details: https://hg.nginx.org/njs/rev/4b018107386d
branches:
changeset: 1699:4b018107386d
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Wed Sep 01 21:25:10 2021 +0300
description:
Fixed order of code execution after await in try block.

The bug was introduced in 92d10cd761e2.

diffstat:

src/njs_async.c | 4 +++-
test/js/async_await_try_resolve.js | 15 +++++++++++++++
test/njs_expect_test.exp | 2 ++
3 files changed, 20 insertions(+), 1 deletions(-)

diffs (49 lines):

diff -r 92d10cd761e2 -r 4b018107386d src/njs_async.c
--- a/src/njs_async.c Wed Sep 01 16:31:08 2021 +0300
+++ b/src/njs_async.c Wed Sep 01 21:25:10 2021 +0300
@@ -90,7 +90,7 @@ njs_await_fulfilled(njs_vm_t *vm, njs_va

vm->top_frame->retval = &vm->retval;

- ret = njs_vmcode_interpreter(vm, async->pc);
+ ret = njs_vmcode_interpreter(vm, ctx->pc);

vm->levels[NJS_LEVEL_LOCAL] = cur_local;
vm->levels[NJS_LEVEL_CLOSURE] = cur_closures;
@@ -148,6 +148,8 @@ njs_await_rejected(njs_vm_t *vm, njs_val
return NJS_ERROR;
}

+ ctx->pc = ctx->await->pc;
+
return njs_await_fulfilled(vm, args, nargs, unused);
}

diff -r 92d10cd761e2 -r 4b018107386d test/js/async_await_try_resolve.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_await_try_resolve.js Wed Sep 01 21:25:10 2021 +0300
@@ -0,0 +1,15 @@
+async function af() {
+ let key;
+
+ try {
+ key = await Promise.resolve("key");
+ key += ": resolve";
+
+ } catch (e) {
+ key += ": exception";
+ }
+
+ return key;
+};
+
+af().then(v => console.log(v));
diff -r 92d10cd761e2 -r 4b018107386d test/njs_expect_test.exp
--- a/test/njs_expect_test.exp Wed Sep 01 16:31:08 2021 +0300
+++ b/test/njs_expect_test.exp Wed Sep 01 21:25:10 2021 +0300
@@ -1171,3 +1171,5 @@ njs_run {"./test/js/async_await_try_thro
finally
end"

+njs_run {"./test/js/async_await_try_resolve.js"} \
+"key: resolve"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed order of code execution after await in try block.

Alexander Borisov 78 September 01, 2021 02:28PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready