Skip to content

Commit 5e5b1f8

Browse files
trevnorrisevanlucas
authored andcommitted
src: return early if nextTickQueue is empty
This brings the node::MakeCallback and node::AsyncWrap::MakeCallback implementations into alignment in that they return early if the nextTickQueue is empty after processing the MicrotaskQueue. Include test to make sure early return happens. Test has text explaining the conditions for the test to pass, since it relies on internal mechanisms that aren't guaranteed in the future. PR-URL: #10274 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 586967a commit 5e5b1f8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/node.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ Local<Value> MakeCallback(Environment* env,
12741274

12751275
if (tick_info->length() == 0) {
12761276
tick_info->set_index(0);
1277+
return ret;
12771278
}
12781279

12791280
if (env->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
var allsGood = false;
6+
var cntr = 0;
7+
8+
process.on('exit', () => {
9+
assert.ok(cntr > 0, '_tickDomainCallback was never called');
10+
});
11+
12+
/**
13+
* This test relies upon the following internals to work as specified:
14+
* - require('domain') causes node::Environment::set_tick_callback_function()
15+
* to use process._tickDomainCallback() to process the nextTickQueue;
16+
* replacing process._tickCallback().
17+
* - setImmediate() uses node::MakeCallback() instead of
18+
* node::AsyncWrap::MakeCallback(). Otherwise the test will always pass.
19+
* Have not found a way to verify that node::MakeCallback() is used.
20+
*/
21+
process._tickDomainCallback = function _tickDomainCallback() {
22+
assert.ok(allsGood, '_tickDomainCallback should not have been called');
23+
cntr++;
24+
};
25+
26+
setImmediate(common.mustCall(() => {
27+
require('domain');
28+
setImmediate(common.mustCall(() => setImmediate(common.mustCall(() => {
29+
allsGood = true;
30+
process.nextTick(() => {});
31+
}))));
32+
}));

0 commit comments

Comments
 (0)