obeli_sk_boa_wintertc/lib.rs
1//! Boa's **`boa_wintertc`** crate implements the [WinterTC (TC55) Minimum Common Web API](https://min-common-api.proposal.wintertc.org/)
2//! for the `boa_engine` crate.
3//!
4//! `WinterTC` (TC55) is an Ecma International Technical Committee working towards a baseline set
5//! of Web Platform APIs that all server-side JavaScript runtimes (Deno, Bun, Cloudflare Workers,
6//! Node.js, etc.) agree to implement, enabling portable server-side JavaScript.
7//!
8//! # Relationship to `boa_runtime`
9//!
10//! `boa_wintertc` is a standalone crate that depends only on `boa_engine`.
11//! `boa_runtime` depends on `boa_wintertc` and re-exports its APIs, so users of `boa_runtime`
12//! automatically get TC55 compliance without any extra setup.
13//!
14//! If you only want the TC55-mandated APIs and nothing else, depend on `boa_wintertc` directly.
15//!
16//! # Example: Registering all TC55 APIs
17//!
18//! ```no_run
19//! use boa_engine::Context;
20//!
21//! let mut context = Context::default();
22//!
23//! boa_wintertc::register(None, &mut context)
24//! .expect("failed to register TC55 APIs");
25//! ```
26#![doc = include_str!("../ABOUT.md")]
27#![doc(
28 html_logo_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo_black.svg",
29 html_favicon_url = "https://raw.githubusercontent.com/boa-dev/boa/main/assets/logo_black.svg"
30)]
31#![cfg_attr(not(test), forbid(clippy::unwrap_used))]
32#![allow(
33 clippy::module_name_repetitions,
34 clippy::redundant_pub_crate,
35 clippy::let_unit_value
36)]
37
38pub mod abort;
39pub mod base64;
40pub mod clone;
41pub mod console;
42pub mod encoding;
43pub mod events;
44#[cfg(feature = "fetch")]
45pub mod fetch;
46pub mod microtask;
47pub mod timers;
48#[cfg(feature = "url")]
49pub mod url;
50
51/// Register all TC55-mandated Web APIs into the given [`boa_engine::Context`].
52///
53/// This registers the Minimum Common Web API as specified by `WinterTC` (TC55):
54/// <https://min-common-api.proposal.wintertc.org/>
55///
56/// # Errors
57///
58/// Returns a [`boa_engine::JsError`] if any API fails to register (e.g. a global
59/// object already exists with a conflicting name).
60#[allow(clippy::needless_pass_by_value)]
61pub fn register(
62 realm: Option<boa_engine::realm::Realm>,
63 ctx: &mut boa_engine::Context,
64) -> boa_engine::JsResult<()> {
65 console::register(realm.clone(), ctx)?;
66 timers::register(realm.clone(), ctx)?;
67 encoding::register(realm.clone(), ctx)?;
68 microtask::register(realm.clone(), ctx)?;
69 clone::register(realm.clone(), ctx)?;
70 base64::register(realm.clone(), ctx)?;
71 abort::register(realm.clone(), ctx)?;
72 #[cfg(feature = "url")]
73 url::register(realm.clone(), ctx)?;
74 #[cfg(feature = "fetch")]
75 fetch::register(realm, ctx)?;
76
77 Ok(())
78}