Node architecture: Is libuv's event loop exposed to V8?

474 views
Skip to first unread message

Felix Kiechle

unread,
Apr 8, 2016, 10:50:53 PM4/8/16
to libuv

http://stackoverflow.com/questions/36490779/node-architecture-is-libuvs-event-loop-exposed-to-v8

At the end of this article (section EventLoop) it says that libuv's event loop is passed to V8. On the first reading that seemed to make sence: In the browser V8 has it's own event loop, in Node it gets that of libuv. But then I started digging into the code and couldn't find a proof where the loop is passed to V8.


StartNodeInstance leads after some steps to the creation of a new Environment instance. The constructor is passed a newly created V8 Context, which is created from a V8 isolate, as well as a pointer to the libuv default loop.

Then the loop is passed to the creation of a IsolateData instance. I couldn't find a hint that the loop is actually passed or registered to V8. Nor that the Environment::New belongs to the V8 namespace, as said at the end of the article.


An isolate is a V8 VM instance with its own heap. A context is an execution environment that allows separate, unrelated, JavaScript code to run in a single instance of V8. You must explicitly specify the context in which you want any JavaScript code to be run.


Ben Noordhuis

unread,
Apr 9, 2016, 3:52:00 AM4/9/16
to li...@googlegroups.com
Newer versions of V8 have a concept of an event loop
(`v8::platform::PumpMessageLoop()`) that's used to drive the
micro-task queue for promise and observer events.

However, it's incorrect to say that node.js passes the libuv event
loop handle to V8. V8 is unaware of the existence of libuv, it merely
gets called by the embedder from time to time.
Message has been deleted

Felix Kiechle

unread,
May 8, 2016, 6:57:45 PM5/8/16
to libuv

Happy for comments on this article on JavaScript and the Node.Js architecture.
Reply all
Reply to author
Forward
0 new messages