#run-time #js #javascript #wasm-engine

boa_runtime

Example runtime for the Boa JavaScript engine

7 unstable releases (3 breaking)

0.20.0 Dec 5, 2024
0.19.1 Sep 12, 2024
0.19.0 Jul 11, 2024
0.18.0 Mar 7, 2024
0.17.0 Jul 8, 2023

#368 in WebAssembly

Download history 65/week @ 2024-11-18 98/week @ 2024-11-25 229/week @ 2024-12-02 157/week @ 2024-12-09 79/week @ 2024-12-16 71/week @ 2024-12-23 151/week @ 2024-12-30 84/week @ 2025-01-06 36/week @ 2025-01-13 34/week @ 2025-01-20 22/week @ 2025-01-27 120/week @ 2025-02-03 36/week @ 2025-02-10 166/week @ 2025-02-17 178/week @ 2025-02-24 152/week @ 2025-03-03

536 downloads per month
Used in 6 crates (4 directly)

Unlicense OR MIT

4.5MB
85K SLoC

Boa's boa_runtime crate contains an example runtime and basic runtime features and functionality for the boa_engine crate for runtime implementors.

Example: Adding Web API's Console Object

  1. Add boa_runtime as a dependency to your project along with boa_engine.
use boa_engine::{js_string, property::Attribute, Context, Source};
use boa_runtime::Console;

// Create the context.
let mut context = Context::default();

// Initialize the Console object.
let console = Console::init(&mut context);

// Register the console as a global property to the context.
context
    .register_global_property(js_string!(Console::NAME), console, Attribute::all())
    .expect("the console object shouldn't exist yet");

// JavaScript source for parsing.
let js_code = "console.log('Hello World from a JS code string!')";

// Parse the source code
match context.eval(Source::from_bytes(js_code)) {
    Ok(res) => {
        println!(
            "{}",
            res.to_string(&mut context).unwrap().to_std_string_escaped()
        );
    }
    Err(e) => {
        // Pretty print the error
        eprintln!("Uncaught {e}");
        # panic!("An error occured in boa_runtime's js_code");
    }
};

Dependencies

~11–18MB
~260K SLoC