Welcome! Log In Create A New Profile

Advanced

[njs] Shell: fixed unhandled rejected promises handling.

Dmitry Volyntsev
January 23, 2024 07:42PM
details: https://hg.nginx.org/njs/rev/6485ad23565e
branches:
changeset: 2270:6485ad23565e
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Jan 23 16:33:29 2024 -0800
description:
Shell: fixed unhandled rejected promises handling.

The issue was introduced in dffdf7c50dfc (not released yet).

diffstat:

external/njs_shell.c | 10 +++++-----
test/js/promise_reject_post_catch.t.js | 9 ---------
test/shell_test.exp | 9 +++++++++
3 files changed, 14 insertions(+), 14 deletions(-)

diffs (59 lines):

diff -r 8aad26845b18 -r 6485ad23565e external/njs_shell.c
--- a/external/njs_shell.c Thu Jan 18 18:03:35 2024 -0800
+++ b/external/njs_shell.c Tue Jan 23 16:33:29 2024 -0800
@@ -1207,6 +1207,11 @@ njs_process_script(njs_vm_t *vm, void *r
}
}

+ ret = njs_process_events(runtime);
+ if (njs_slow_path(ret == NJS_ERROR)) {
+ break;
+ }
+
if (njs_unhandled_rejection(runtime)) {
njs_process_output(vm, NULL, NJS_ERROR);

@@ -1215,11 +1220,6 @@ njs_process_script(njs_vm_t *vm, void *r
}
}

- ret = njs_process_events(runtime);
- if (njs_slow_path(ret == NJS_ERROR)) {
- break;
- }
-
if (ret == NJS_OK) {
break;
}
diff -r 8aad26845b18 -r 6485ad23565e test/js/promise_reject_post_catch.t.js
--- a/test/js/promise_reject_post_catch.t.js Thu Jan 18 18:03:35 2024 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-/*---
-includes: []
-flags: []
-negative:
- phase: runtime
----*/
-
-var p = Promise.reject();
-setImmediate(() => {p.catch(() => {})});
diff -r 8aad26845b18 -r 6485ad23565e test/shell_test.exp
--- a/test/shell_test.exp Thu Jan 18 18:03:35 2024 -0800
+++ b/test/shell_test.exp Tue Jan 23 16:33:29 2024 -0800
@@ -476,6 +476,15 @@ ReferenceError: \"ref\" is not defined
at anonymous \\\(string:1\\\)
at main \\\(string:1\\\)\n$"

+njs_test {
+ {"setImmediate(() => { console.log('x'); return Promise.reject('xx'); })\r\n"
+ "0\r\nx\r\nThrown:\r\nError: unhandled promise rejection: xx\r\n"}
+ {"setImmediate(() => { console.log('x'); return Promise.reject('xx'); })\r\n"
+ "1\r\nx\r\nThrown:\r\nError: unhandled promise rejection: xx\r\n"}
+ {"42\r\n"
+ "42\r\n"}
+}
+
# CLI OPTIONS

# help
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Shell: fixed unhandled rejected promises handling.

Dmitry Volyntsev 173 January 23, 2024 07:42PM



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

Online Users

Guests: 216
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready