It's not a problem or bug. I just view code in node.cc, and could not find where to invoke the node::MakeCallback function which actually execute callbacks bound with process.nextTick.
It looks like those code make sense:
if (!env->KickNextTick(&callback_scope)) {
return Undefined(env->isolate());
}
I think what you are looking for is https://github.com/nodejs/node/blob/32f6098eefc7404ef74ca59dfdfceebb009f6f53/src/node.js#L430 (& friends) within startup.processNextTick() in src/node.js.
@Fishrock123 I've found that, I also found that in module.js, Module.runMain would execute the first tick in main loop from js code, but I want to know when the main loop execute the callback exactly in every event loop iteration. In other words, when c++ code running uv_run, where to deal with functions bound with process.nextTick(callback).
process._setupNextTick(_tickCallback, etc) is set here and is a call to c++ which sets env->tick_callback_function. This gets called from Environment::KickNextTick which in turn gets called from within Local<Value> MakeCallback. ... I'm not exactly sure where that gets called though. Does that help? I can try digging further.
@Fishrock123 I've found that as I described in first comment, as you can see I鈥榤 still doubt about when MakeCallback to get called in each event loop iteration, I haven't debug into the recompiled code yet. I want to know "the truth". :-]
Ping @trevnorris who probably knows XD
@AceMood I'm slightly confused by the question. node::MakeCallback is only called by the setImmediate() API internally. Everything else uses AsyncWrap::MakeCallback.
The Environment::KickNextTick call is defined in src/env.cc. This makes the call to tick_callback_function, which is a Persistent<Function> stored on Environment. That function is stored when process.setupNextTick() is called, calling node::SetupNextTick, which is the _tickCallback() function in src/node.js. Unless you then require('domain') at which time the function is overridden in the node::SetupDomainUse, replacing it with _tickDomainCallback also located in src/node.js.
Am I missing anything?
@trevnorris Maybe a little confusing, let me make it clear :)
In every event loop iteration, call uv_run would find proper callbacks to execute, I can find when c++ execute timeout callbacks and setImmediate callbacks in node.cc and other source code, but I couldn't find where to call the callbacks bound with process.nextTick, how node schedule it.

Here's an article I wrote about how the event loop works: https://nodesource.com/blog/understanding-the-nodejs-event-loop/
This is what you're looking for:
All callbacks scheduled via process.nextTick() are run at the end of a phase of the event loop (e.g. timers) before transitioning to the next phase. This creates the potential to unintentionally starve the event loop with recursive calls to process.nextTick().
Processing nextTick callbacks is done by node. Not scheduled in libuv. They're called just before the JS stack is about to exit, and before the event loop continues.
@trevnorris Yes, what you said is the key point. I want to know what the time exactly execute the callbacks (bound use process.nextTick in javascript code). As you mentioned above, it would be the end of each event loop iteration. I have dived into the source code node.cc, and found that in the node::StartNodeInstance method, node setup the event loop work, but I didn't find where to do the nextTick job. It's indeed not a part of work of libuv, but I want to know how node do this work. I have found the code in MakeCallback (node.cc)
if (!env->KickNextTick(&callback_scope)) {
return Undefined(env->isolate());
}
so I asked the question about the entry point of this call, want to get more information. But as you described above, it use AsyncWrap::MakeCallback to schedule the tick_callback_function, so I think maybe somewhere call the AsyncWrap::MakeCallback, could you please show me the entry point of that?
node::AsyncWrap::MakeCallback() is used in all classes that inherit from AsyncWrap. node::MakeCallback() is used in node::EnableDebug(), node::EmitBeforeExit(), node::EmitExit() and node::CheckImmediate(). All of which are located in src/node.cc.
If you want to know, when is the _first_ time it's run, that varies based on what's being run. Say we run:
> node -e 'process.nextTick(() => console.log("hi"))'
The nextTick will be executed from node::EmitBeforeExit. In fact anything you pass in using -p or -e will trigger the same. Because of implementation details.
If you run the following script:
process.nextTick(() => console.log('hi'));
MakeCallback() is never run, but 'hi' is still printed. This is because in lib/module.js there's the following:
// bootstrap main module.
Module.runMain = function() {
// Load the main module--the command line argument.
Module._load(process.argv[1], null, true);
// Handle any nextTicks added in the first tick of the program
process._tickCallback();
};
This manually processes the nextTickQueue after the main script has run. So MakeCallback() is never executed in this case before the process exits. Now take the following:
require('net').createServer((c) => {
process.nextTick(() => console.log('hi');
}).listen(8080);
and the nextTickQueue will be processed by a call to node::AsyncWrap::MakeCallback() via node::TCPWrap::OnConnection(). So in these cases it simply depends on what AsyncWrap child class triggers the call first.
That explain what you're after?
@trevnorris @Fishrock123 Thank you very much, several days ago I added some stacktrace code and logs to make it clear. The last comment you wrote, I will add it to my post later. Again thanks for your response.
http://acemood.github.io/2016/02/01/event-loop-in-javascript/
Most helpful comment
Here's an article I wrote about how the event loop works: https://nodesource.com/blog/understanding-the-nodejs-event-loop/
This is what you're looking for:
Processing nextTick callbacks is done by node. Not scheduled in libuv. They're called just before the JS stack is about to exit, and before the event loop continues.