The Internals of Deno
  • The Internals of Deno
  • Audience
  • Reviews
  • Translations
  • Formats
  • Contents
  • Chapter 1 - INTRODUCTION
    • 1.0 Cover page
    • 1.1 Introduction
    • 1.2 History of Deno
    • 1.3 About Deno
    • 1.4 Releases
    • 1.5 The Deno Company
    • 1.6 Deno's source
    • 1.7 What's next
  • Chapter 2 - ARCHITECTURE
    • 2.0 Cover page
    • 2.1 Architecture
    • 2.2 Overall architecture
    • 2.3 Programming Languages
    • 2.4 Deno components
    • 2.5 OPs
    • 2.6 TSC/SWC
    • 2.7 Rusty_v8
    • 2.8 Tokio
    • 2.9 V8
    • 2.10 What's next
  • CHAPTER 3 - THREADING MODEL
    • 3.0 Cover page
    • 3.1 Threading model
    • 3.2 Default threading model
    • 3.3 Asynchronous green threads
    • 3.4 What's next
  • CHAPTER 4 - BRIDGE
    • 4.0 Cover page
    • 4.1 The bridge
    • 4.2 Print
    • 4.3 Encode and decode
    • 4.4 What's next
  • CHAPTER 5 - FOUNDATIONS
    • 5.0 Cover page
    • 5.1 Hello world program
    • 5.2 Basic hello world
    • 5.3 Main program of Deno
    • 5.4 Module Specifier
    • 5.5 CLI Factory
    • 5.6 Permissions
    • 5.7 Main Worker
    • 5.8 JS Runtime
    • 5.9 Run main module
    • 5.10 Load module
    • 5.11 Recursive module loading
    • 5.12 Module graphs
    • 5.13 File fetching
    • 5.14 Transpile
    • 5.15 Register / compile module
    • 5.16 Instantiate module
    • 5.17 Evaluate module
    • 5.18 What's next
  • CHAPTER 6 - IMPORTS AND OPS
    • 6.0 Cover page
    • 6.1 Imports and ops
    • 6.2 Hello world program v2
    • 6.3 Module graph with imports
    • 6.4 Transpile
    • 6.5 Registration and instantiation
    • 6.6 Registration of ops
    • 6.7 Evaluate module
    • 6.8 Sync OPs
    • 6.9 Debug logs
    • 6.10 What's next
  • CHAPTER 7 - LOCAL AND SESSION STORAGE
    • 7.0 Cover page
    • 7.1 Introduction
    • 7.2 Local storage
    • 7.3 Session storage
    • 7.4 What's next
  • AFTERWORD
    • Afterword
Powered by GitBook
On this page
  • Overview
  • Example
  1. Chapter 2 - ARCHITECTURE

2.7 Rusty_v8

Overview

V8 and Deno have different core programming languages: V8 uses C++, while Deno uses Rust. To bridge this gap, the innovative "rusty_v8" library was developed. This library creates efficient Rust bindings to V8's complex C++ APIs, achieving seamless integration without additional call overhead. By doing so, rusty_v8 enables the harmonious interaction between V8's C++ foundation and Deno's Rust infrastructure.

When working with APIs, rusty_v8 harmonizes with V8's APIs through a straightforward translation of functionalities, maintaining efficiency without extra burdens. This synchronization is a testament to the library's ability to foster compatibility and efficiency. The creation of rusty_v8 demonstrates the successful integration of languages and technologies, showcasing the potential for dynamic interaction between different programming languages. This connection highlights the compatibility of C++ and Rust, emphasizing the commitment to efficiency and seamless integration within the Deno ecosystem.

Example

Let's examine a few code examples to better understand how rusty_v8 works. Analyzing its practical uses will help us comprehend rusty_v8 more effectively. A specific aspect to investigate is the way rusty_v8 implements Strings.

pub fn length(&self) -> usize {
    unsafe { v8__String__Length(self) as usize }
}

The String class in Rust includes a function that calculates the length of a string. When this "length" function is called, it activates the "v8__String__Length" code, which is written in C++. This code determines the length of the v8 string data type. There is a direct and simple relationship between the function and the code, with a one-to-one correspondence. This means that the function and code are closely linked, providing a clear connection between the Rust String class and v8's string data type.

int v8__String__Length(const v8::String& self) { 
    return self.Length(); } 
}

Let's explore another example within the rusty_v8 module, specifically the 'parse' function:

pub fn parse<'s>(
  scope: &mut HandleScope<'s>,
  json_string: Local<'_, String>,
) -> Option<Local<'s, Value>> {
  unsafe {
    scope
      .cast_local(|sd| v8__JSON__Parse(sd.get_current_context(), &*json_string))
  }
}

Rusty_v8 has a parse function that matches the v8__JSON__Parse function. The parse function, written in C++, acts as a connector to access the corresponding function in the v8 library. This connection enables Rusty_v8 to utilize v8's capabilities for parsing JSON data.

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)));
}
Previous2.6 TSC/SWCNext2.8 Tokio

Last updated 10 months ago

Rusty_v8 generally matches the v8 API in most cases. For more information on rusty_v8, visit their GitHub page at . Now, let's discuss Tokio, a tool that enables Deno to perform tasks asynchronously. This means Deno can handle tasks efficiently without getting stuck on one task, improving its overall performance and responsiveness.

https://github.com/denoland/rusty_v8