Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
MiniV8
MiniV8 is a minimal embedded V8 JavaScript engine wrapper for Rust.
Quick tour
extern crate mini_v8;
use ;
Other features
- Custom user data can be bound to a
MiniV8
(seeMiniV8::set_user_data
). This is useful for storing state between embedded Rust function calls. - All kinds of standard Rust types can be passed in and out of the JavaScript environment (the number types,
String
,Vec
,BTreeMap
,HashSet
, etc.). You can define a conversion interface for your own types, too. SeeToValue
/FromValue
andsrc/conversion.rs
for more information. - Execution timeout support.
Building
Building V8 is notoriously complicated. Currently, MiniV8 requires that consumers manually specify a path to a pre-built V8 using the V8_PATH
environment variable. Follow the official build guide to get up and running. V8 8.6.57 is the currently required version. Other major versions likely have compatibility issues.
Prior art
MiniV8 is inspired by the MiniRacer Ruby gem, which implements a minimal bridge with V8. From its README: "This [minimal design] reduces the surface area making upgrading [V8] much simpler and exhaustive testing simpler." Contrast this with the ambitious v8-rs crate, which remains unmaintained because "the maintenance burden is too high." The rusty_v8
crate (itself part of the larger Deno project) provides inspiration for how the V8 build process should be integrated. In the future, I would like this crate to build off of rusty_v8
. Unfortunately, at the time of writing, rusty_v8
is too unstable to use as a dependency (track issue #3).
This work is a companion to my own ducc crate, which provides a minimal wrapper around the Duktape JavaScript engine.
Purpose
When utilizing any FFI, it's significantly easier to select a subset of the entire source library than to attempt to map one-to-one all of its constructs. This of course means sacrificing features and perhaps performance, but allows for flexibility during API design leading to more idiomatic code in the target language.
It's clear that I chose the "minimal bridge" model for MiniV8. If you're looking to take advantage of all of V8's many internal constructs then MiniV8 is not for you. If you're looking to ergonomically execute scripts with one of the fastest JavaScript engines there is from within Rust then MiniV8 might be for you.
Shortcomings
- MiniV8 only implements a minimal bridge for the full set of types that modern ECMAScript offers. Perhaps the current
Value
bridge should be expanded to support a few more special object types (Uint8Array
seems useful). - The
Error
type is very limited.- There's no way to pass a script or function name into JavaScript for error reporting. This can be easily improved by modifying
MiniV8::eval
. - Once an
Error
is converted into aValue
to be thrown as an exception in JavaScript land, there's no going back. It would be nice to be able to maintain the sourceError
across the Rust-JavaScript boundary. This should be implemented by adding a hidden property to the exception value that points back to theError
(we already do this sort of trick to bind Rust closures to V8 functions).
- There's no way to pass a script or function name into JavaScript for error reporting. This can be easily improved by modifying
- No support for limiting memory usage.