by Mayank Tripathi
Before diving deep into the core of Chrome’s V8, first, let’s get our fundamentals down. All of our systems consist of microprocessors, the thing that is sitting inside your computer right now and allowing you to read this.
Microprocessors are tiny machines that work with electrical signals and ultimately do the job. We give microprocessors the instructions. The instructions are in the language that microprocessors can interpret. Different microprocessors speak different languages. Some of the most common are IA-32, x86–64, MIPS, and ARM. These languages directly interact with the hardware so the code written in them is called machine code. Code that we write on our computers is converted or compiled into machine code.
That’s what machine code looks like:
It consists of instructions that are performed at a particular piece of memory in your system at a low level. You must feel lucky for not having to write all this to run your program!
The Chrome V8 engine :
- The V8 engine is written in C++ and used in Chrome and Nodejs.
- It implements ECMAScript as specified in ECMA-262.
- The V8 engine can run standalone we can embed it with our own C++ program.
So for example:
Node.js in itself is a C++ implementation of a V8 engine allowing server-side programming and networking applications.
Let’s now look at some of the open source code inside the engine. To do this, you need to go to the v8/samples/shell.cc folder.
Here you can see the implementation of different functions such as
Read, which are natively not available in Node.js.
Below, you can see the implementation of the
print() function is invoked in Node.js, it will create a callback and the function will be executed.
Similarly, we can add our own implementation of different new functions in C++ inside V8 allowing it to be understood by Node.js.
That is certainly too much to grab for a simple statement and that’s the amount of work V8 engine does under the hood.
Now you must have a clear understanding of how Node.js works and what actually is the Chrome V8 engine.
Thanks for reading this article. Let’s follow up on Twitter, Linkedin, Github, and Facebook.