2.4 Rusty_v8


Rusty_v8 is a part of the Deno project but it's not located inside the main Deno repository. Therefore we treat it as a third-party component.
V8 is written in C++, while Deno is written in Rust. To have them interwork, rusty_v8 was conceived. The purpose of rusty_v8 library is to provide high-quality rust bindings to v8's C++ APIs. Rusty_v8 is very efficient. There is no additional call overhead.
In terms of the API, Rusty_v8 tries it's best to match the V8 APIs as much as possible. In most cases, it'd be a simple mapping.
Rusty_v8 is efficient and doesn't introduce additional call overhead.


Some code examples will help to understand rusty_v8 better.
Consider one of the functions in rusty_v8's String implementation:
pub fn length(&self) -> usize {
unsafe { v8__String__Length(self) as usize }
This function is part of the implementation of the String class in rust. When the length is called, it'll call v8__String__Length which is a C++ code that returns the length of v8's string data type. Very simple 1:1 mapping.
int v8__String__Length(const v8::String& self) {
return self.Length();
Consider one more example in rusty_v8, parse:
pub fn parse<'s>(
scope: &mut HandleScope<'s>,
json_string: Local<'_, String>,
) -> Option<Local<'s, Value>> {
unsafe {
.cast_local(|sd| v8__JSON__Parse(sd.get_current_context(), &*json_string))
Rusty_v8 provides a parse function that maps to v8__JSON__Parse which is a C++ function that calls the corresponding function of v8:
const v8::Value* v8__JSON__Parse(const v8::Context& context,
const v8::String& json_string) {
return maybe_local_to_ptr(
v8::JSON::Parse(ptr_to_local(&context), ptr_to_local(&json_string)));
In most of the cases, rusty_v8 simply matches the v8 API.
For more information on rusty_v8 visit https://github.com/denoland/rusty_v8.
Let's move on to tokio, which makes Deno fully async.