#scripting #v8 #javascript

scriptit

scriptit is a simple way to run JavaScript code in Rust (native+wasm)

4 releases (breaking)

0.4.0 Oct 21, 2020
0.3.0 Oct 3, 2020
0.2.0 Sep 13, 2020
0.1.0 Aug 31, 2020

#998 in WebAssembly

MIT license

25KB
495 lines

scriptit

cargo build & test wasm-pack build & test

scriptit is a simple way to run JavaScript code in Rust

scriptit will run your JS differently depending on your platform:

  • Run in a V8 interpreter for "native" targets
  • Run in the WASM host interpreter for "wasm32" targets

You can call rust functions from JS.

Why?

I wanted to be able to do scripting in my rust applications, I do not need a fully-fledged embedding of v8 like node or deno and the only use here is as a library, so you get to choose what to inject.

Additionally I want to write most of my rust apps with a possible wasm target: as we likely have a js engine when running rust code on wasm targets, I thought about using the js interpreter on the host. This makes scriptit an extremely lightweight way to run scripts in wasm as we use host capabilities to do so!

Limitations

Due to those goals, scriptit will not give you the same amount of control that you would have embedding v8 yourself and will give you worst ergonomics than just using wasm_bindgen. It is unfortunately ruled by the lowest common denominators on both apis (v8 & wasm_bindgen).

Example

See the documentation for an example.

Roadmap

scriptit is extremely experimental, I wouldn't use it for anything now, at least not before the following is done:

  • ES Modules support
  • Event-loop support
  • Promises/Futures support
  • Events from rust support
  • Passing to functions by reference instead of a serialized JSON copy

See the issues for more details.

Dependencies

~0.7–14MB
~288K SLoC