From: Alexander Borisov Date: Tue, 3 Nov 2020 17:14:33 +0000 (+0300) Subject: Promise: fixed the catch handler for Promise.prototype.finally(). X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=ef696d43f036f6722838f7929007b494dd215a40;p=njs.git Promise: fixed the catch handler for Promise.prototype.finally(). By spec, the catch handler for the .finally() should always return an exception. The issue was introduced in 61bf7a31e685. --- diff --git a/src/njs_promise.c b/src/njs_promise.c index 41704c07..ee04f93a 100644 --- a/src/njs_promise.c +++ b/src/njs_promise.c @@ -1023,7 +1023,11 @@ static njs_int_t njs_promise_catch_finally_function(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_index_t unused) { - return njs_promise_then_finally_function(vm, args, nargs, unused); + (void) njs_promise_then_finally_function(vm, args, nargs, unused); + + njs_vm_retval_set(vm, njs_arg(args, nargs, 1)); + + return NJS_ERROR; } diff --git a/test/js/promise_then_throw_finally_catch.js b/test/js/promise_then_throw_finally_catch.js new file mode 100644 index 00000000..534154c2 --- /dev/null +++ b/test/js/promise_then_throw_finally_catch.js @@ -0,0 +1,4 @@ +Promise.resolve() +.then(() => {nonExsisting()}) +.finally(() => {}) +.catch(() => {console.log("Done")}); \ No newline at end of file diff --git a/test/njs_expect_test.exp b/test/njs_expect_test.exp index 3d51ace5..22e0c4dd 100644 --- a/test/njs_expect_test.exp +++ b/test/njs_expect_test.exp @@ -1044,3 +1044,6 @@ njs_run {"./test/js/fs_promises_008.js"} \ njs_run {"./test/js/fs_promises_009.js"} \ "test recursive fs.rmdirSync" + +njs_run {"./test/js/promise_then_throw_finally_catch.js"} \ +"Done"