6 releases

0.19.1 Sep 12, 2024
0.19.0 Jul 11, 2024
0.18.0 Mar 7, 2024
0.17.3 Sep 26, 2023
0.17.0 Jul 8, 2023

#217 in WebAssembly

Download history 301/week @ 2024-07-22 177/week @ 2024-07-29 281/week @ 2024-08-05 442/week @ 2024-08-12 308/week @ 2024-08-19 409/week @ 2024-08-26 353/week @ 2024-09-02 633/week @ 2024-09-09 313/week @ 2024-09-16 231/week @ 2024-09-23 357/week @ 2024-09-30 112/week @ 2024-10-07 242/week @ 2024-10-14 169/week @ 2024-10-21 181/week @ 2024-10-28 89/week @ 2024-11-04

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

Unlicense OR MIT

4.5MB
81K 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

~12–18MB
~264K SLoC