Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/y21/dash
Experimental JavaScript implementation in Rust
https://github.com/y21/dash
compiler ecma262 es6 interpreter javascript parser rust wasm
Last synced: 2 months ago
JSON representation
Experimental JavaScript implementation in Rust
- Host: GitHub
- URL: https://github.com/y21/dash
- Owner: y21
- License: mit
- Created: 2021-04-20T21:29:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-09-12T15:35:42.000Z (4 months ago)
- Last Synced: 2024-09-13T04:10:32.231Z (4 months ago)
- Topics: compiler, ecma262, es6, interpreter, javascript, parser, rust, wasm
- Language: Rust
- Homepage:
- Size: 2.92 MB
- Stars: 40
- Watchers: 3
- Forks: 3
- Open Issues: 9
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# dash
![Tests](https://github.com/y21/dash/actions/workflows/test.yml/badge.svg)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/y21/dash)ECMA-262 implementation in pure Rust.
## ⚠️ WIP
This is a *WIP* and **not** yet production ready. It is actively being worked on and the API is constantly changing.Current status: Not recommended for use in real projects. Feel free to experiment. The majority of language constructs are implemented and "work fine". It currently passes around 21% of test262.
## Usage
### Using the CLI
```js
import * as http from '@std/http';// We already implement Optional Typing, so you can directly annotate parameters and variables with types
// without having to use a third tool such as tsc
function* counter(start: number) {
let num = start;
while (true) yield num++;
}const numbers = counter(0);
const port = 3030;http.listen(port, (ctx) => {
const next = numbers.next();
ctx.respond('Request count: ' + next.value);
});console.log('Listening on port: ' + port);
```
```sh
# Install Rust
$ curl -sSf https://sh.rustup.rs | sh
# Clone repo
$ git clone https://github.com/y21/dash
# Build cli
$ cargo install --path dash/cli
# Optional: rename binary to `dashjs`
$ mv ~/.cargo/bin/dash-cli ~/.cargo/bin/dashjs
# Run the program (run with --help for help)
$ dashjs run example.js
```
Now open up your browser, navigate to http://localhost:3030, refresh a bunch of times and see the numbers go up.### Embedding into a Rust application
Note that the API is not stable. Things are constantly changing, so your code may break at any time when bumping the version, which is why it is highly recommended to lock in to a specific revision for now.- Cargo.toml
```toml
[dependencies]
dash_vm = { git = "https://github.com/y21/dash", features = ["eval"] }
```
> The `eval` feature exposes a convenience `eval()` method on the `Vm` struct
> that lets you specify a JavaScript source string directly.- main.rs
```rs
use dash_vm::Vm;fn main() {
let source = "const x = 42; x * x";let mut vm = Vm::new(Default::default());
let result = vm.eval(source, Default::default()).expect("JS Exception");println!("Result: {}", match result {
Value::Number(n) => n,
_ => unreachable!()
});
}
```
See `dash-cli/` for a more detailed example### Node compatibility
There's experimental support for node compatibility. If you want to try it out, pass `--features nodejs` to the cargo install/build command.
When running dash, you can then pass `--node` and various node-specific things will be available to the JS environment, such as the `require` function.