[njs] Tests: making async/await test filenames shorter.
Dmitry Volyntsev
xeioex at nginx.com
Tue Nov 30 16:36:12 UTC 2021
details: https://hg.nginx.org/njs/rev/6aaf1c14c1e7
branches:
changeset: 1754:6aaf1c14c1e7
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Mon Nov 29 18:14:25 2021 +0000
description:
Tests: making async/await test filenames shorter.
diffstat:
test/js/async_add.t.js | 15 ++++++++++++
test/js/async_await_add.t.js | 15 ------------
test/js/async_await_blank.t.js | 13 ----------
test/js/async_await_catch.t.js | 13 ----------
test/js/async_await_finally.t.js | 15 ------------
test/js/async_await_for.t.js | 31 -------------------------
test/js/async_await_inline.t.js | 18 ---------------
test/js/async_await_many_call.t.js | 35 -----------------------------
test/js/async_await_reject.t.js | 15 ------------
test/js/async_await_stages.t.js | 36 ------------------------------
test/js/async_await_throw.t.js | 22 ------------------
test/js/async_await_throw_async.t.js | 25 --------------------
test/js/async_await_throw_catch.t.js | 20 ----------------
test/js/async_await_throw_catch_async.t.js | 25 --------------------
test/js/async_await_try_catch.t.js | 30 -------------------------
test/js/async_await_try_finally.t.js | 32 --------------------------
test/js/async_await_try_resolve.t.js | 23 -------------------
test/js/async_await_try_throw.t.js | 27 ----------------------
test/js/async_await_try_throw_catch.t.js | 27 ----------------------
test/js/async_blank.t.js | 13 ++++++++++
test/js/async_catch.t.js | 13 ++++++++++
test/js/async_finally.t.js | 15 ++++++++++++
test/js/async_for.t.js | 31 +++++++++++++++++++++++++
test/js/async_inline.t.js | 18 +++++++++++++++
test/js/async_many_call.t.js | 35 +++++++++++++++++++++++++++++
test/js/async_reject.t.js | 15 ++++++++++++
test/js/async_stages.t.js | 36 ++++++++++++++++++++++++++++++
test/js/async_throw.t.js | 22 ++++++++++++++++++
test/js/async_throw_async.t.js | 25 ++++++++++++++++++++
test/js/async_throw_catch.t.js | 20 ++++++++++++++++
test/js/async_throw_catch_async.t.js | 25 ++++++++++++++++++++
test/js/async_try_catch.t.js | 30 +++++++++++++++++++++++++
test/js/async_try_finally.t.js | 32 ++++++++++++++++++++++++++
test/js/async_try_resolve.t.js | 23 +++++++++++++++++++
test/js/async_try_throw.t.js | 27 ++++++++++++++++++++++
test/js/async_try_throw_catch.t.js | 27 ++++++++++++++++++++++
36 files changed, 422 insertions(+), 422 deletions(-)
diffs (988 lines):
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_add.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_add.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,15 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+async function af(x) {
+ const y = await new Promise(resolve => {resolve(x + 10)});
+
+ return x + y;
+}
+
+af(50).then(v => {
+ assert.sameValue(v, 110);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_add.t.js
--- a/test/js/async_await_add.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-async function af(x) {
- const y = await new Promise(resolve => {resolve(x + 10)});
-
- return x + y;
-}
-
-af(50).then(v => {
- assert.sameValue(v, 110);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_blank.t.js
--- a/test/js/async_await_blank.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-async function af(x) {
- return x;
-}
-
-af(12345).then(v => {
- assert.sameValue(v, 12345)
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_catch.t.js
--- a/test/js/async_await_catch.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-async function add(x) {
- return await new Promise((resolve, reject) => {reject(x)}).catch(v => v + 1);
-}
-
-add(50).then(v => {
- assert.sameValue(v, 51);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_finally.t.js
--- a/test/js/async_await_finally.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-let called = false;
-async function add(x) {
- return await new Promise((resolve, reject) => {reject(x + 1)})
- .finally(() => {called = true});
-}
-
-add(50).catch(e => {
- assert.sameValue(e, 51);
- assert.sameValue(called, true, "finally was not invoked");
-}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_for.t.js
--- a/test/js/async_await_for.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-let stage = [];
-
-async function f() {
- let sum = 0;
-
- stage.push(2);
-
- for (let x = 4; x < 14; x++) {
- sum += await new Promise((resolve, reject) => {resolve(x)});
-
- stage.push(x);
- }
-
- stage.push("end");
-
- return sum;
-}
-
-stage.push(1);
-
-f().then(v => {
- assert.sameValue(v, 85);
- assert.compareArray(stage, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "end"]);
-}).then($DONE, $DONE);
-
-stage.push(3);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_inline.t.js
--- a/test/js/async_await_inline.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)});
-}
-
-async function add() {
- const a = pr(20);
- const b = pr(50);
- return await a + await b;
-}
-
-add().then(v => {
- assert.sameValue(v, 70);
-}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_many_call.t.js
--- a/test/js/async_await_many_call.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-async function test(name) {
- let k1, k2;
-
- switch (name) {
- case "First":
- k1 = await Promise.resolve("SUN");
- k2 = await Promise.resolve("MOON");
- break;
-
- case "Second":
- k1 = await Promise.resolve("CAT");
- k2 = await Promise.resolve("MOUSE");
- break;
-
- case "Third":
- k1 = await Promise.resolve("MAN");
- k2 = await Promise.resolve("WOMAN");
- break;
-
- default:
- break;
- }
-
- return `${name}: ${k1} ${k2}`;
-};
-
-Promise.all(['First', 'Second', 'Third'].map(v => test(v)))
-.then(results => {
- assert.compareArray(results, ['First: SUN MOON','Second: CAT MOUSE','Third: MAN WOMAN']);
-}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_reject.t.js
--- a/test/js/async_await_reject.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-async function add(x) {
- return await new Promise((resolve, reject) => {reject(x)});
-}
-
-add(50)
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- assert.sameValue(v, 50);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_stages.t.js
--- a/test/js/async_await_stages.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)})
- .then(v => v).then(v => v);
-}
-
-let stage = [];
-
-async function f() {
- let sum = 0;
-
- stage.push(2);
-
- const a1 = await pr(10);
-
- stage.push(4);
-
- const a2 = await pr(20);
-
- stage.push(5);
-
- return a1 + a2;
-}
-
-stage.push(1);
-
-f().then(v => {
- stage.push(v);
- assert.compareArray(stage, [1, 2, 3, 4, 5, 30]);
-}).then($DONE, $DONE);
-
-stage.push(3);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_throw.t.js
--- a/test/js/async_await_throw.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)}).then(v => {throw v});
-}
-
-async function add(x) {
- const a = await pr(x);
- const b = await pr(x);
-
- return a + b;
-}
-
-add(50)
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- assert.sameValue(v, 50);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_throw_async.t.js
--- a/test/js/async_await_throw_async.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)});
-}
-
-async function add(x) {
- const a = await pr(x);
-
- throw a + 1;
-
- const b = await pr(x + 10);
-
- return a + b;
-}
-
-add(50)
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- assert.sameValue(v, 51);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_throw_catch.t.js
--- a/test/js/async_await_throw_catch.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)}).then(v => {throw v}).catch(v => v);
-}
-
-async function add(x) {
- const a = await pr(x);
- const b = await pr(x + 10);
-
- return a + b;
-}
-
-add(50).then(v => {
- assert.sameValue(v, 110);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_throw_catch_async.t.js
--- a/test/js/async_await_throw_catch_async.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-function pr(x) {
- return new Promise(resolve => {resolve(x)});
-}
-
-async function add(x) {
- const a = await pr(x);
-
- throw a + 1;
-
- const b = await pr(x + 10);
-
- return a + b;
-}
-
-add(50)
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- assert.sameValue(v, 51);
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_try_catch.t.js
--- a/test/js/async_await_try_catch.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-let stages = [];
-
-async function af() {
- try {
- await new Promise(function(resolve, reject) {
- reject("reject");
- });
-
- $DONOTEVALUATE();
- }
- catch (v) {
- stages.push(v);
- }
- finally {
- stages.push('finally');
- }
-
- return "end";
-};
-
-af().then(v => {
- stages.push(v);
- assert.compareArray(stages, ['reject', 'finally', 'end']);
-})
-.then($DONE, $DONE)
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_try_finally.t.js
--- a/test/js/async_await_try_finally.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-let stages = [];
-
-async function af() {
- try {
- await new Promise(function(resolve, reject) {
- reject("reject");
- });
-
- $DONOTEVALUATE();
- }
- finally {
- await new Promise(function(resolve, reject) {
- reject("finally reject");
- });
-
- $DONOTEVALUATE();
- }
-
- return "shouldn't happen: end";
-};
-
-af()
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- assert.sameValue(v, "finally reject");
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_try_resolve.t.js
--- a/test/js/async_await_try_resolve.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-/*---
-includes: []
-flags: [async]
----*/
-
-async function af() {
- let key;
-
- try {
- key = await Promise.resolve("key");
- key += ": resolve";
-
- } catch (e) {
- key += ": exception";
- }
-
- return key;
-};
-
-af().then(v => {
- assert.sameValue(v, "key: resolve");
-})
-.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_try_throw.t.js
--- a/test/js/async_await_try_throw.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-let stages = [];
-
-async function af() {
- try {
- throw "try";
-
- $DONOTEVALUATE();
- }
- finally {
- stages.push("finally");
- }
-
- return "shouldn't happen: end";
-};
-
-af()
-.then(v => $DONOTEVALUATE())
-.catch(v => {
- stages.push(v);
- assert.compareArray(stages, ['finally', 'try']);
-})
-.then($DONE, $DONE)
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_await_try_throw_catch.t.js
--- a/test/js/async_await_try_throw_catch.t.js Mon Nov 29 16:50:41 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*---
-includes: [compareArray.js]
-flags: [async]
----*/
-
-let stage = [];
-
-async function af() {
- try {
- throw "try";
-
- $DONOTEVALUATE();
- }
- catch (v) {
- stage.push(v);
- }
- finally {
- stage.push("finally");
- }
-
- return "end";
-};
-
-af().then(v => {
- stage.push(v);
- assert.compareArray(stage, ['try', 'finally', 'end'])
-}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_blank.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_blank.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,13 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+async function af(x) {
+ return x;
+}
+
+af(12345).then(v => {
+ assert.sameValue(v, 12345)
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_catch.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_catch.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,13 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+async function add(x) {
+ return await new Promise((resolve, reject) => {reject(x)}).catch(v => v + 1);
+}
+
+add(50).then(v => {
+ assert.sameValue(v, 51);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_finally.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_finally.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,15 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+let called = false;
+async function add(x) {
+ return await new Promise((resolve, reject) => {reject(x + 1)})
+ .finally(() => {called = true});
+}
+
+add(50).catch(e => {
+ assert.sameValue(e, 51);
+ assert.sameValue(called, true, "finally was not invoked");
+}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_for.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_for.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,31 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stage = [];
+
+async function f() {
+ let sum = 0;
+
+ stage.push(2);
+
+ for (let x = 4; x < 14; x++) {
+ sum += await new Promise((resolve, reject) => {resolve(x)});
+
+ stage.push(x);
+ }
+
+ stage.push("end");
+
+ return sum;
+}
+
+stage.push(1);
+
+f().then(v => {
+ assert.sameValue(v, 85);
+ assert.compareArray(stage, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, "end"]);
+}).then($DONE, $DONE);
+
+stage.push(3);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_inline.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_inline.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,18 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)});
+}
+
+async function add() {
+ const a = pr(20);
+ const b = pr(50);
+ return await a + await b;
+}
+
+add().then(v => {
+ assert.sameValue(v, 70);
+}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_many_call.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_many_call.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,35 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+async function test(name) {
+ let k1, k2;
+
+ switch (name) {
+ case "First":
+ k1 = await Promise.resolve("SUN");
+ k2 = await Promise.resolve("MOON");
+ break;
+
+ case "Second":
+ k1 = await Promise.resolve("CAT");
+ k2 = await Promise.resolve("MOUSE");
+ break;
+
+ case "Third":
+ k1 = await Promise.resolve("MAN");
+ k2 = await Promise.resolve("WOMAN");
+ break;
+
+ default:
+ break;
+ }
+
+ return `${name}: ${k1} ${k2}`;
+};
+
+Promise.all(['First', 'Second', 'Third'].map(v => test(v)))
+.then(results => {
+ assert.compareArray(results, ['First: SUN MOON','Second: CAT MOUSE','Third: MAN WOMAN']);
+}).then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_reject.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_reject.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,15 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+async function add(x) {
+ return await new Promise((resolve, reject) => {reject(x)});
+}
+
+add(50)
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ assert.sameValue(v, 50);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_stages.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_stages.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,36 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)})
+ .then(v => v).then(v => v);
+}
+
+let stage = [];
+
+async function f() {
+ let sum = 0;
+
+ stage.push(2);
+
+ const a1 = await pr(10);
+
+ stage.push(4);
+
+ const a2 = await pr(20);
+
+ stage.push(5);
+
+ return a1 + a2;
+}
+
+stage.push(1);
+
+f().then(v => {
+ stage.push(v);
+ assert.compareArray(stage, [1, 2, 3, 4, 5, 30]);
+}).then($DONE, $DONE);
+
+stage.push(3);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_throw.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_throw.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,22 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)}).then(v => {throw v});
+}
+
+async function add(x) {
+ const a = await pr(x);
+ const b = await pr(x);
+
+ return a + b;
+}
+
+add(50)
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ assert.sameValue(v, 50);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_throw_async.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_throw_async.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,25 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)});
+}
+
+async function add(x) {
+ const a = await pr(x);
+
+ throw a + 1;
+
+ const b = await pr(x + 10);
+
+ return a + b;
+}
+
+add(50)
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ assert.sameValue(v, 51);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_throw_catch.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_throw_catch.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,20 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)}).then(v => {throw v}).catch(v => v);
+}
+
+async function add(x) {
+ const a = await pr(x);
+ const b = await pr(x + 10);
+
+ return a + b;
+}
+
+add(50).then(v => {
+ assert.sameValue(v, 110);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_throw_catch_async.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_throw_catch_async.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,25 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+function pr(x) {
+ return new Promise(resolve => {resolve(x)});
+}
+
+async function add(x) {
+ const a = await pr(x);
+
+ throw a + 1;
+
+ const b = await pr(x + 10);
+
+ return a + b;
+}
+
+add(50)
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ assert.sameValue(v, 51);
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_try_catch.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_try_catch.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,30 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stages = [];
+
+async function af() {
+ try {
+ await new Promise(function(resolve, reject) {
+ reject("reject");
+ });
+
+ $DONOTEVALUATE();
+ }
+ catch (v) {
+ stages.push(v);
+ }
+ finally {
+ stages.push('finally');
+ }
+
+ return "end";
+};
+
+af().then(v => {
+ stages.push(v);
+ assert.compareArray(stages, ['reject', 'finally', 'end']);
+})
+.then($DONE, $DONE)
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_try_finally.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_try_finally.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,32 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+let stages = [];
+
+async function af() {
+ try {
+ await new Promise(function(resolve, reject) {
+ reject("reject");
+ });
+
+ $DONOTEVALUATE();
+ }
+ finally {
+ await new Promise(function(resolve, reject) {
+ reject("finally reject");
+ });
+
+ $DONOTEVALUATE();
+ }
+
+ return "shouldn't happen: end";
+};
+
+af()
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ assert.sameValue(v, "finally reject");
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_try_resolve.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_try_resolve.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,23 @@
+/*---
+includes: []
+flags: [async]
+---*/
+
+async function af() {
+ let key;
+
+ try {
+ key = await Promise.resolve("key");
+ key += ": resolve";
+
+ } catch (e) {
+ key += ": exception";
+ }
+
+ return key;
+};
+
+af().then(v => {
+ assert.sameValue(v, "key: resolve");
+})
+.then($DONE, $DONE);
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_try_throw.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_try_throw.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,27 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stages = [];
+
+async function af() {
+ try {
+ throw "try";
+
+ $DONOTEVALUATE();
+ }
+ finally {
+ stages.push("finally");
+ }
+
+ return "shouldn't happen: end";
+};
+
+af()
+.then(v => $DONOTEVALUATE())
+.catch(v => {
+ stages.push(v);
+ assert.compareArray(stages, ['finally', 'try']);
+})
+.then($DONE, $DONE)
diff -r 3b035831f64a -r 6aaf1c14c1e7 test/js/async_try_throw_catch.t.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/js/async_try_throw_catch.t.js Mon Nov 29 18:14:25 2021 +0000
@@ -0,0 +1,27 @@
+/*---
+includes: [compareArray.js]
+flags: [async]
+---*/
+
+let stage = [];
+
+async function af() {
+ try {
+ throw "try";
+
+ $DONOTEVALUATE();
+ }
+ catch (v) {
+ stage.push(v);
+ }
+ finally {
+ stage.push("finally");
+ }
+
+ return "end";
+};
+
+af().then(v => {
+ stage.push(v);
+ assert.compareArray(stage, ['try', 'finally', 'end'])
+}).then($DONE, $DONE);
More information about the nginx-devel
mailing list