Top Related Projects
The official GitHub mirror of the Chromium source
Read-only Git mirror of the Mercurial gecko repositories at https://hg.mozilla.org. How to contribute: https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
Home of the WebKit project, the browser engine used by Safari, Mail, App Store and many other applications on macOS, iOS and Linux.
Node.js JavaScript runtime ✨🐢🚀✨
A modern runtime for JavaScript and TypeScript.
A JavaScript engine optimized for running React Native.
Quick Overview
V8 is Google's open-source high-performance JavaScript and WebAssembly engine. It is written in C++ and is used in Google Chrome and Node.js. V8 implements ECMAScript and WebAssembly, and runs on Windows, macOS, and Linux systems.
Pros
- High performance: V8 uses advanced optimization techniques to execute JavaScript quickly
- Continuous updates: Regularly updated to support the latest ECMAScript features
- Cross-platform: Runs on multiple operating systems and architectures
- Extensive documentation: Well-documented codebase and APIs for developers
Cons
- Complexity: The codebase is large and complex, making it challenging for new contributors
- Resource intensive: Can be memory-hungry, especially for large applications
- Limited standalone use: Primarily designed for integration into larger projects
- Learning curve: Requires significant C++ knowledge to work on the engine itself
Code Examples
V8 is not a code library in the traditional sense, but rather an engine that executes JavaScript. However, here are some examples of how to use V8's C++ API to embed it in a C++ application:
- Initializing V8:
#include <v8.h>
int main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
// Use V8 here
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
return 0;
}
- Executing a simple JavaScript script:
v8::Isolate* isolate = v8::Isolate::New(create_params);
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, "'Hello' + ', World!'").ToLocalChecked();
v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked();
v8::Local<v8::Value> result = script->Run(context).ToLocalChecked();
v8::String::Utf8Value utf8(isolate, result);
printf("%s\n", *utf8);
- Exposing a C++ function to JavaScript:
void PrintCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
v8::String::Utf8Value str(isolate, args[0]);
printf("%s\n", *str);
}
// In your setup code:
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::Local<v8::FunctionTemplate> print_tmpl = v8::FunctionTemplate::New(isolate, PrintCallback);
context->Global()->Set(context, v8::String::NewFromUtf8(isolate, "print").ToLocalChecked(),
print_tmpl->GetFunction(context).ToLocalChecked()).Check();
// Now you can use the 'print' function in JavaScript
v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, "print('Hello from JS!');").ToLocalChecked();
v8::Local<v8::Script> script = v8::Script::Compile(context, source).ToLocalChecked();
script->Run(context).ToLocalChecked();
Getting Started
To get started with V8:
- Clone the repository: `git clone https://
Competitor Comparisons
The official GitHub mirror of the Chromium source
Pros of Chromium
- Broader scope: Full web browser project with extensive features and capabilities
- Larger community: More contributors and wider adoption in various applications
- Cross-platform support: Available on multiple operating systems and devices
Cons of Chromium
- Higher complexity: Larger codebase and more dependencies to manage
- Steeper learning curve: Requires understanding of multiple components and systems
- Heavier resource usage: Consumes more memory and processing power
Code Comparison
V8:
bool Isolate::InitWithoutSnapshot() {
IsolateAllocationMode mode = IsolateAllocationMode::kInV8Heap;
return InitWithoutSnapshot(mode);
}
Chromium:
bool ContentBrowserClient::AllowServiceWorker(
const GURL& scope,
const GURL& first_party_url,
content::BrowserContext* context) {
return true;
}
The V8 code snippet shows a method for initializing an Isolate without a snapshot, while the Chromium code demonstrates a method for allowing service workers in the browser. This highlights the difference in focus between the two projects, with V8 dealing with JavaScript engine internals and Chromium handling broader browser functionality.
Read-only Git mirror of the Mercurial gecko repositories at https://hg.mozilla.org. How to contribute: https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
Pros of gecko-dev
- Broader scope: Full browser engine implementation, including rendering and networking
- More comprehensive web standards support
- Larger community and contributor base
Cons of gecko-dev
- More complex codebase due to its broader scope
- Potentially slower development cycle for specific features
- Higher resource requirements for building and testing
Code Comparison
V8 (JavaScript engine focus):
bool Compiler::Analyze(ParseInfo* parse_info) {
DCHECK_NOT_NULL(parse_info->literal());
RuntimeCallTimerScope runtimeTimer(
runtime_call_stats_, RuntimeCallCounterId::kCompileAnalyse);
Handle<SharedFunctionInfo> shared = parse_info->shared_info();
return AnalyzeImpl(parse_info, shared, local_zone());
}
gecko-dev (Broader browser engine implementation):
nsresult
nsDocShell::CreateAboutBlankContentViewer() {
// Protect against re-entrancy.
if (mCreatingInitialContentViewer) {
return NS_OK;
}
// If we already have a content viewer, then we're done.
if (mContentViewer) {
return NS_OK;
}
This comparison highlights the different focus areas of the two projects. V8 concentrates on JavaScript engine optimization, while gecko-dev encompasses a wider range of browser functionalities, including content handling and rendering.
Home of the WebKit project, the browser engine used by Safari, Mail, App Store and many other applications on macOS, iOS and Linux.
Pros of WebKit
- Broader platform support, including macOS, iOS, and various Unix-based systems
- More comprehensive web standards implementation, particularly for CSS and HTML features
- Stronger focus on privacy and security features
Cons of WebKit
- Generally slower JavaScript performance compared to V8
- Less frequent updates and slower adoption of new ECMAScript features
- More complex codebase due to supporting multiple rendering engines (WebCore and JavaScriptCore)
Code Comparison
WebKit (JavaScript parsing):
JSTokenLocation startLocation = tokenLocation();
JSTextPosition startPosition = tokenPosition();
TreeStatement result = parseStatement(context);
V8 (JavaScript parsing):
bool ok = true;
Statement* result = ParseStatement(&ok);
if (!ok) return nullptr;
Both repositories use C++ for their core implementations, but V8 tends to have a more streamlined approach to parsing and execution, which contributes to its performance advantages. WebKit's code often includes more checks and abstractions to support its broader feature set and platform compatibility.
Node.js JavaScript runtime ✨🐢🚀✨
Pros of Node.js
- Broader ecosystem and application focus
- Built-in package manager (npm) for easy dependency management
- Extensive standard library for various tasks (e.g., file system, networking)
Cons of Node.js
- Larger codebase and potentially slower development cycle
- More complex architecture due to additional layers on top of V8
- May have slightly higher memory footprint for simple applications
Code Comparison
V8:
v8::Isolate* isolate = v8::Isolate::New();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
Node.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, World!');
});
server.listen(3000);
The V8 example shows low-level JavaScript engine initialization, while the Node.js example demonstrates a simple HTTP server setup, highlighting the higher-level abstractions provided by Node.js.
A modern runtime for JavaScript and TypeScript.
Pros of Deno
- Built-in TypeScript support without additional configuration
- Secure by default, with explicit permissions for file, network, and environment access
- Includes a standard library and built-in tooling (formatter, linter, etc.)
Cons of Deno
- Smaller ecosystem compared to Node.js, which V8 powers
- Not fully compatible with existing Node.js modules and packages
- Learning curve for developers familiar with Node.js
Code Comparison
V8 (JavaScript engine):
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
Local<Script> script = Script::Compile(context, source).ToLocalChecked();
Local<Value> result = script->Run(context).ToLocalChecked();
Deno (Runtime):
const text = "Hello, World!";
console.log(text);
await Deno.writeTextFile("hello.txt", text);
const content = await Deno.readTextFile("hello.txt");
console.log(content);
Note: The code snippets demonstrate different levels of abstraction. V8 is a low-level JavaScript engine, while Deno is a high-level runtime built on top of V8.
A JavaScript engine optimized for running React Native.
Pros of Hermes
- Optimized for React Native, providing better performance on mobile devices
- Smaller binary size, reducing app download and installation times
- Faster startup time due to bytecode precompilation
Cons of Hermes
- Limited support for full ECMAScript features compared to V8
- Narrower ecosystem and community support
- Less suitable for server-side JavaScript environments
Code Comparison
V8:
Local<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Local<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'");
Local<Script> script = Script::Compile(context, source).ToLocalChecked();
Local<Value> result = script->Run(context).ToLocalChecked();
Hermes:
jsi::Runtime& runtime = hermes::makeHermesRuntime();
jsi::Value result = runtime.evaluateJavaScript(
std::make_shared<jsi::StringBuffer>("'Hello' + ', World!'"),
"inline");
Summary
Hermes is tailored for mobile environments, particularly React Native, offering smaller size and faster startup. V8 provides broader JavaScript support and is more versatile across different environments. The code comparison shows V8's C++ API is more verbose, while Hermes offers a simpler interface for basic JavaScript evaluation.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
V8 JavaScript Engine
V8 is Google's open source JavaScript engine.
V8 implements ECMAScript as specified in ECMA-262.
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 can run standalone, or can be embedded into any C++ application.
V8 Project page: https://v8.dev/docs
Getting the Code
Checkout depot tools, and run
fetch v8
This will checkout V8 into the directory v8
and fetch all of its dependencies.
To stay up to date, run
git pull origin
gclient sync
For fetching all branches, add the following into your remote
configuration in .git/config
:
fetch = +refs/branch-heads/*:refs/remotes/branch-heads/*
fetch = +refs/tags/*:refs/tags/*
Contributing
Please follow the instructions mentioned at v8.dev/docs/contribute.
Top Related Projects
The official GitHub mirror of the Chromium source
Read-only Git mirror of the Mercurial gecko repositories at https://hg.mozilla.org. How to contribute: https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
Home of the WebKit project, the browser engine used by Safari, Mail, App Store and many other applications on macOS, iOS and Linux.
Node.js JavaScript runtime ✨🐢🚀✨
A modern runtime for JavaScript and TypeScript.
A JavaScript engine optimized for running React Native.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot