#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![allow(clippy::similar_names)]
#![allow(clippy::float_cmp)]
#![allow(clippy::cast_precision_loss)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::cast_possible_wrap)]
pub mod coercion;
pub mod console;
pub mod error;
pub mod globals;
pub mod json;
pub mod math;
use boa_cat::Value;
use boa_cat::env::Env;
use boa_cat::heap::Heap;
use boa_cat::value::Cell;
pub use error::Error;
#[must_use]
pub fn build_initial() -> (Env, Heap) {
install(Env::empty(), Heap::new())
}
#[must_use]
pub fn install(env: Env, heap: Heap) -> (Env, Heap) {
let (console_value, heap) = console::build(heap);
let (math_value, heap) = math::build(heap);
let (json_value, heap) = json::build(heap);
let bindings: Vec<(&str, Value)> = vec![
("undefined", Value::Undefined),
("NaN", Value::Number(f64::NAN)),
("Infinity", Value::Number(f64::INFINITY)),
("console", console_value),
("Math", math_value),
("JSON", json_value),
("parseInt", Value::Native(globals::parse_int_impl)),
("parseFloat", Value::Native(globals::parse_float_impl)),
("isNaN", Value::Native(globals::is_nan_impl)),
("isFinite", Value::Native(globals::is_finite_impl)),
("Number", Value::Native(globals::number_impl)),
("String", Value::Native(globals::string_impl)),
("Boolean", Value::Native(globals::boolean_impl)),
];
bindings
.into_iter()
.fold((env, heap), |(env, heap), (name, value)| {
let (cell_id, heap) = heap.alloc_cell(Cell::new(value, false));
(env.extend_cell(name, cell_id), heap)
})
}