owned this note
owned this note
Published
Linked with GitHub
AN ARTICLE ON JAVASCRIPT ENGINE OF MAJOR BROWSERS.
INTRODUCTION
What is JavaScript Engine?
The JavaScript Engine is an open-source computer program whose responsibility is to execute/run JavaScript.
There are a lot of steps involved in executing the JavaScript Engine, but essentially executing JavaScript code is what an engine does. All modern browsers have their own version of the JavaScript Engine. But Google's V8 Engine is the most popular JavaScript Engine.
An elementary JavaScript engine includes a baseline compiler whose job is to compile JavaScript source code into an intermediate representation (IR) called the bytecode and feeds this bytecode to the interpreter. The interpreter takes this bytecode and converts it to the machine code, which is ultimately run on the machine’s hardware (CPU).
ECMAScript Standards are being followed by the JavaScript engines to execute the code on the browser. The role of these standards is to give a definition and specification to JavaScript engines on how they should work and what features they should have.
Here is a list of JavaScript Engines for major Internet browsers:
1. V8 – JavaScript Engine developed by Google for Chrome
2. SpiderMonkey – The JavaScript Engine used by Mozilla Firefox
3. JavaScriptCore – Developed by Apple for Safari
4. Rhino – Managed by Mozilla Foundation for Firefox
5. Chakra – A JavaScript Engine for Microsoft Edge
6. JerryScript – A JavaScript Engine employed for the Internet of Things.
How JavaScript engine works?
The JavaScript engine works on the JavaScript source code and puts it and then executes the compilation to binary instructions (machine code) that are easily understandable by the CPU. A JavaScript engine generally consists of a baseline compiler that works on the compilation of the code in the form of intermediate representation (IR) /byte code and then passes the byte code to the interpreter.
Later, the interpreter takes this byte code and makes the conversion into machine code, which will further run this code on the hardware of the machine to generate the results and that's how JavaScript engine works. The assignment of a baseline compiler is to perform the compilation of the code as fast as possible and to generate less-optimized byte codes.
A JavaScript engine can make an intuition about the data types of the variables and perform the generation of much better code that increases the effectiveness of the system and user experience at large.
The JavaScript engine can also work on gathering, and profiling data on the execution of the code and analyzing the speed of the code. Codes that run slow or take time to process are commonly known as "Hot" codes as they get burned in the CPU. System designers have the option to further optimize and replace machine code that has already been optimized to avoid burns.
Types of JavaScript engines?
Now that you have a better understanding of how javascript engine works, let look at the different types of major javascript engines we have.
1. V8
It is a JavaScript engine developed by the Chromium Project for Google Chrome and Chromium web browsers which can run standalone or be embedded into any C++ application. V8 uses its own parser and generates an abstract syntax tree, used for generating bytecode by Ignition using the internal V8 bytecode format. V8 provides an edge as it allows JavaScript to run much faster, which improves users' experience of the web and the overall functionality of the system.
2. CHAKRA
Chakra is a JavaScript engine developed by Microsoft used for Microsoft Internet Explorer. It is proprietary software with distinctive features. Chakra can JIT compile scripts on a separate CPU core parallel to the web browser. Firstly, Chakra Core reads through the Javascript code syntax and parses it to generate its AST. After the AST is generated, the code is passed to the byte code generator to profile the byte codes. Chakra works a bit differently from V8, as V8 has a decision process that decides whether a piece of code should be profiled and optimized or should be turned into byte code.
3. SPIDER MONKEY
SpiderMonkey is the first JavaScript engine, written by Brendan Eich at Netscape Communications, released as open-source, and is currently maintained and used by the Mozilla Foundation. It contains a JavaScript compiler and interpreter along with several service programs. It is written in C++, Rust and JavaScript can be embedded into C++ and Rust projects and run as a stand-alone shell.
4. JAVASCRIPTCORE
JavaScriptCore (JSC) is the JavaScript engine used by Apple's WebKit browser engine. It powers Safari and other applications on Apple's platforms. Here are some key aspects of JSC:
Key Features
i. Lightweight and Fast: Designed for performance, with Just-In-Time (JIT) compilation.
ii. C API: Allows embedding JavaScript into C and C++ applications.
iii. Garbage Collection: Uses a garbage collector to manage memory automatically.
iv. Supports ES6+: Implements modern JavaScript features.
5. RHINO
6.
Rhino is an open-source JavaScript engine written in Java, developed by Mozilla. It allows Java applications to execute JavaScript code.
Key Features
i. 100% Java Implementation: Unlike V8 or JavaScriptCore, Rhino is written entirely in Java.
ii. Java Integration: Can call Java methods from JavaScript and vice versa.
iii. Interpreted and Compiled Modes: Supports both interpretation and Just-In-Time (JIT) compilation to bytecode.
iv. ECMAScript Support: Implements ECMAScript (ES5, with partial ES6 support).
6. JERRYSCRIPT
JerryScript is a lightweight JavaScript engine designed for embedded systems with constrained resources. It is optimized for low memory usage and can run on microcontrollers with as little as 64 KB of RAM and 200 KB of flash memory.
Key Features of
JerryScript:
i. Small Footprint: Designed to work in constrained environments, it minimizes RAM and flash usage.
ii. ECMAScript Support: Implements a subset of ECMAScript 5.1 with some ES6+ features.
iii. Portable & Cross-Platform: Can run on various platforms, including ARM Cortex-M, Linux, and even in browsers.
iv. Interoperability: Offers API bindings to interact with C code, making it useful for IoT and embedded applications.
v. Garbage Collection: Includes an efficient garbage collector to manage memory usage dynamically.