硫磺:用 Rust 编写的 ES2025 JavaScript 引擎
Brimstone: ES2025 JavaScript engine written in Rust

原始链接: https://github.com/Hans-Halverson/brimstone

硫磺是一个用 Rust 构建的新型 JavaScript 引擎,致力于完全符合 ECMAScript 标准。目前仍在开发中,它通过了 test262 套件中超过 97% 的测试,并支持高达 ES2024 的特性,包括最近的 TC39 提案(不包括 SharedArrayBuffer Atomics)。 硫磺的设计灵感来自 V8 和 SerenityOS 的 LibJS,优先考虑从头开始的实现,并尽量减少依赖项——ICU4X 是一个关键例外。主要特性包括字节码虚拟机、压缩垃圾收集器、自定义 RegExp 引擎以及对内置对象和函数的完整实现。 硫磺使用标准的 `cargo` 命令构建和运行,并通过集成和单元测试(包括官方的 test262 套件)进行全面测试。虽然尚未达到生产就绪状态,但它展示了在 Rust 中创建强大且符合标准的 JavaScript 引擎方面取得了显著进展。

## 硫磺:一种用 Rust 编写的新型 JavaScript 引擎 Hans Halverson 创建了 **Brimstone**,一种用 Rust 编写的 JavaScript 引擎,旨在实现完整性和高性能。它在 Hacker News 上因其作为个人项目的出色进展而备受关注。 Brimstone 目前通过了 97% 的 JavaScript 规范,并且编译后的尺寸(6.3MB)明显小于另一个基于 Rust 的引擎 Boa(23MB)。这种尺寸差异主要归因于对 Unicode 支持的不同方法——Brimstone 使用比 Boa 包含的完整 ECMA-402 国际化 API 更小的 Unicode 表集。 虽然实现高规范符合性和小占用空间值得注意,但该项目在其垃圾收集器实现中使用了“unsafe” Rust。尽管如此,开发者强调将 `unsafe` 代码限制在易于验证的部分。Brimstone 现在已在 MIT 许可下发布。基准测试表明,它通常比 Boa 更快,使其成为 JavaScript 引擎领域的一个有希望的补充,尤其是在嵌入到 Rust 应用程序中时。
相关文章

原文

Brimstone is a JavaScript engine written from scratch in Rust, aiming to have full support for the JavaScript language.

Brimstone is a work in progress but already supports almost all of the JavaScript language (>97% of the ECMAScript language in test262). Not ready for use in production.

Implements the ECMAScript specification. Heavy inspiration is taken from the design of V8 and SerenityOS's LibJS. Brimstone chooses to implement almost all components of the engine from scratch with minimal dependencies, with the notable exception of ICU4X.

Brimstone features:

  • Bytecode VM, heavily inspired by the design of V8's Ignition
  • Compacting garbage collector, written in very unsafe Rust
  • Custom RegExp engine
  • Custom parser
  • Almost all builtin objects and functions implemented to spec

Standard cargo commands to build and run.

  • cargo build to build the bs executable
  • cargo run to run from source

JavaScript files can be executed with bs:

# Build brimstone
cargo build

# Execute a JavaScript file
./target/debug/bs ./hello.js
Hello world!

Brimstone relies heavily on a set of first and third party integration test suites, most notably the official test262 test suite. A custom integration test runner is included. This can be run with:

Unit and snapshot tests can be run with cargo test.

For more information on testing see the testing README.

All features up to ES2024 have been implemented, as well as all stage 4 proposals as of the Feb. 2025 TC39 meeting, except for the following features:

  • SharedArrayBuffer
  • Atomics
联系我们 contact @ memedata.com