summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-01-17 09:39:01 -0500
committerAnatoli Papirovski <apapirovski@mac.com>2018-01-21 12:37:43 -0500
commitd62566e1b1bb4734635d51d53c16f6efa3a7f5b5 (patch)
tree9856b59d53f036aa7047b79660e86252a7b6a88e /test
parent9545c48a5e90d53923feb485e2c02cd03126f8f2 (diff)
downloadandroid-node-v8-d62566e1b1bb4734635d51d53c16f6efa3a7f5b5.tar.gz
android-node-v8-d62566e1b1bb4734635d51d53c16f6efa3a7f5b5.tar.bz2
android-node-v8-d62566e1b1bb4734635d51d53c16f6efa3a7f5b5.zip
promises: refactor rejection handling
Remove the unnecessary microTasksTickObject for scheduling microtasks and instead use TickInfo to keep track of whether promise rejections exist that need to be emitted. Consequently allow the microtasks to execute on average fewer times, in more predictable manner than previously. Simplify unhandled & handled rejection tracking to do more in C++ to avoid needing to expose additional info in JS. When new unhandledRejections are emitted within an unhandledRejection handler, allow the event loop to proceed first instead. This means that if the end-user code handles all promise rejections on nextTick, rejections within unhandledRejection now won't spiral into an infinite loop. PR-URL: https://github.com/nodejs/node/pull/18207 Fixes: https://github.com/nodejs/node/issues/17913 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/message/unhandled_promise_trace_warnings.out5
-rw-r--r--test/parallel/test-promises-unhandled-rejections.js13
2 files changed, 14 insertions, 4 deletions
diff --git a/test/message/unhandled_promise_trace_warnings.out b/test/message/unhandled_promise_trace_warnings.out
index c9c7a5c870..069e6cc678 100644
--- a/test/message/unhandled_promise_trace_warnings.out
+++ b/test/message/unhandled_promise_trace_warnings.out
@@ -14,7 +14,6 @@
at *
at *
at *
- at *
(node:*) Error: This was rejected
at * (*test*message*unhandled_promise_trace_warnings.js:*)
at *
@@ -34,9 +33,7 @@
at *
at *
(node:*) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
- at getAsynchronousRejectionWarningObject (internal/process/promises.js:*)
- at rejectionHandled (internal/process/promises.js:*)
- at *
+ at handledRejection (internal/process/promises.js:*)
at Promise.catch *
at Immediate.setImmediate (*test*message*unhandled_promise_trace_warnings.js:*)
at *
diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js
index ed5d485ac7..1ade061994 100644
--- a/test/parallel/test-promises-unhandled-rejections.js
+++ b/test/parallel/test-promises-unhandled-rejections.js
@@ -684,3 +684,16 @@ asyncTest('Throwing an error inside a rejectionHandled handler goes to' +
}
}, 1);
});
+
+asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +
+ ' to proceed first', function(done) {
+ clean();
+ Promise.reject(0);
+ let didCall = false;
+ process.on('unhandledRejection', () => {
+ assert(!didCall);
+ didCall = true;
+ const promise = Promise.reject(0);
+ process.nextTick(() => promise.catch(() => done()));
+ });
+});