3 releases

0.17.3 Sep 26, 2023
0.17.1 Sep 26, 2023
0.17.0 Jul 8, 2023

#396 in WebAssembly

Download history 909/week @ 2023-08-15 817/week @ 2023-08-22 1320/week @ 2023-08-29 829/week @ 2023-09-05 722/week @ 2023-09-12 866/week @ 2023-09-19 783/week @ 2023-09-26 881/week @ 2023-10-03 1135/week @ 2023-10-10 1176/week @ 2023-10-17 1093/week @ 2023-10-24 996/week @ 2023-10-31 1053/week @ 2023-11-07 527/week @ 2023-11-14 1319/week @ 2023-11-21 846/week @ 2023-11-28

4,082 downloads per month
Used in 2 crates

Unlicense/MIT

3.5MB
69K 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::{ Context, Source, property::Attribute };
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(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

~15–21MB
~228K SLoC