]> git.kaiwu.me - njs.git/commitdiff
Promise: fixed the catch handler for Promise.prototype.finally().
authorAlexander Borisov <alexander.borisov@nginx.com>
Tue, 3 Nov 2020 17:14:33 +0000 (20:14 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Tue, 3 Nov 2020 17:14:33 +0000 (20:14 +0300)
By spec, the catch handler for the .finally() should always return an
exception.

The issue was introduced in 61bf7a31e685.

src/njs_promise.c
test/js/promise_then_throw_finally_catch.js [new file with mode: 0644]
test/njs_expect_test.exp

index 41704c079d0146d13a9ceb851941c2a9a8eae24f..ee04f93a6696b07f8dbf4b1d290797fd0c793807 100644 (file)
@@ -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 (file)
index 0000000..534154c
--- /dev/null
@@ -0,0 +1,4 @@
+Promise.resolve()
+.then(() => {nonExsisting()})
+.finally(() => {})
+.catch(() => {console.log("Done")});
\ No newline at end of file
index 3d51ace5fec4605fc9d11c3aab634d5dc4f9d75a..22e0c4ddfe197bd600da4869319c23b5f0a00967 100644 (file)
@@ -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"