惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
A
About on SuperTechFans
量子位
Engineering at Meta
Engineering at Meta
B
Blog
The Cloudflare Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
J
Java Code Geeks
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno
Announcing Stable V8 Bindings for Rust | Deno
Ryan Dahl · 2024-09-24 · via Deno

Deno is a modern, zero-config JavaScript runtime written in Rust. At its core is Rusty V8, a library that provides high-quality, zero-overhead Rust bindings to V8’s C++ API. Over the past five years, Rusty V8 has undergone nearly 150 releases, racking up more than 3.1 million downloads on crates.io. Today, we’re excited to announce a major milestone: Rusty V8 is now stable and production-ready.

While we’d love to mark this moment with a “1.0” release, Rusty V8 is skipping version 1.0 entirely. Instead, we’re aligning with Chrome’s versioning scheme to stay in sync with V8. The first stable release of Rusty V8 will be version 129.0.0, in line with Chrome 129. This version guarantees API stability, moving us beyond years of 0.x releases, and solidifies Rusty V8 as a dependable tool for developers building on top of V8.

What Makes Rusty V8 Special?

Rusty V8 gives Rust developers direct, zero-overhead access to V8’s C++ API. It stands out for its completeness and seamless integration with high-performance environments. A key feature is Rusty V8’s automatic integration of V8’s complex build system into Cargo, allowing developers to easily embed V8 in Rust projects without manual setup. With Rusty V8, you can:

  • Build custom JavaScript runtimes: Rusty V8 is ideal for crafting your own JavaScript runtime, whether for embedded devices, serverless environments, or plugin systems.
  • Run WebAssembly modules: Rusty V8 seamlessly executes WebAssembly (Wasm) modules, allowing you to run high-performance code alongside JavaScript.
  • Leverage the V8 Inspector: Add debugging capabilities like breakpoints and profiling to your JavaScript runtime with the V8 Inspector.
  • Use the V8 Fast API: Rusty V8 allows you to call Rust functions from JavaScript with minimal overhead, perfect for high-performance applications.
  • Automatic memory management: V8’s cppgc garbage collector helps manage memory efficiently, reducing the need for manual memory handling in complex applications.

Origin Story

The journey to Rusty V8 started in 2015, when I was experimenting with building a JavaScript runtime in Go using a library called v8worker. Eventually, v8worker was used in the first Deno demo. However, as Deno evolved, it became clear that Go wasn’t the right fit for the project because of worries that Go’s own GC would conflict poorly with V8’s.

In late 2019, Deno co-founder Bert Belder led the effort to create a direct Rust binding to V8. The challenge was to bind V8’s complex C++ API to Rust without compromising on performance or safety. After much effort, Rusty V8 was born—a zero-overhead Rust binding to V8 that provides full control over V8, while ensuring memory safety through Rust’s ownership model.

Using Rusty V8

Here’s a simple example of how you can embed JavaScript in a Rust program using Rusty V8:

fn main() {
  
  let platform = v8::new_default_platform(0, false).make_shared();
  v8::V8::initialize_platform(platform);
  v8::V8::initialize();

  
  let isolate = &mut v8::Isolate::new(v8::CreateParams::default());

  
  let handle_scope = &mut v8::HandleScope::new(isolate);

  
  let context = v8::Context::new(handle_scope, Default::default());

  
  let scope = &mut v8::ContextScope::new(handle_scope, context);

  
  let code = v8::String::new(scope, "'Hello' + ' World!'").unwrap();

  
  let script = v8::Script::compile(scope, code, None).unwrap();

  
  let result = script.run(scope).unwrap();

  
  let result = result.to_string(scope).unwrap();
  println!("{}", result.to_rust_string_lossy(scope));
}

Rusty V8’s memory safety features are a core advantage over the C++ API. For example, in Rust, handles like Local<T> are tied to specific scopes and enforced at compile time. This prevents bugs caused by using or returning invalid handles—something that C++ developers must manage manually. In Rust, if you attempt to use a Local<T> outside its scope, the compiler will catch the mistake.

Here’s a quick example of Rust preventing invalid handle usage:

let isolate = &mut v8::Isolate::new(Default::default());
{
  let scope1 = &mut v8::HandleScope::new(isolate);
  let local = v8::Integer::new(scope1, 123);

  
  let invalid_local = {
    let scope2 = &mut v8::HandleScope::new(scope1);
    v8::Integer::new(scope2, 456) 
  };

  
}

Versioning

To keep in sync with V8, Rusty V8 will follow Chrome’s versioning scheme. The first stable release is version 129.0.0, corresponding to Chrome 129. While V8 does not follow semantic versioning (semver) and can introduce breaking changes even in minor versions, Rusty V8 will follow semver to ensure compatibility and stability for Rust developers.

Every 4 weeks, Rusty V8 will upgrade its V8 dependency and bump its major version. This means breaking changes to the Rusty V8 API will only happen when V8 upgrades, and the version will always reflect the underlying V8 version.

Ready for Production

Rusty V8 is now a stable, production-ready library for building high-performance JavaScript and WebAssembly runtimes in Rust. Whether you’re creating custom JavaScript runtimes, embedding JS in Rust-backed apps, or exploring server-side JavaScript applications, Rusty V8 provides the flexibility of V8 with the safety and performance guarantees of Rust.

Dive deeper by exploring the full documentation at docs.rs/v8.