4 releases

0.18.0 Mar 7, 2024
0.17.3 Sep 26, 2023
0.17.1 Sep 26, 2023
0.17.0 Jul 8, 2023

#243 in WebAssembly

Download history 1113/week @ 2024-01-28 651/week @ 2024-02-04 461/week @ 2024-02-11 1051/week @ 2024-02-18 1326/week @ 2024-02-25 1400/week @ 2024-03-03 925/week @ 2024-03-10 1378/week @ 2024-03-17 841/week @ 2024-03-24 830/week @ 2024-03-31 1627/week @ 2024-04-07 2395/week @ 2024-04-14 822/week @ 2024-04-21 628/week @ 2024-04-28 994/week @ 2024-05-05 908/week @ 2024-05-12

3,454 downloads per month
Used in 5 crates

Unlicense OR MIT

4.5MB
82K 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, js_string };
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–19MB
~266K SLoC