web-api-cat 0.5.0

Bindings between boa-cat (JS engine) and the DOM (html-cat tree) plus fetch (net-cat). v0.5.0 bumps to boa-cat 0.6 + ecma-parse-cat 0.2 to track the async stack across the workspace: existing match arms gain `Value::Promise(_) => None` so DOM extraction skips engine-allocated promises, and the v0.4 `document.cookie` accessor pair continues to work unchanged on top of the new engine surface. Seventh sub-crate of a Servo-replacement webview runtime targeting Tauri.
//! Install the web APIs (`document`, `fetch`, `window`) into a boa-cat
//! environment and heap.

use boa_cat::Value;
use boa_cat::env::Env;
use boa_cat::heap::Heap;
use boa_cat::value::Cell;
use html_cat::Document as HtmlDoc;

use crate::document::build as build_document;
use crate::fetch::fetch_impl;

/// Fold the web APIs and the parsed document into `env` and `heap`,
/// returning the extended pair.  Each binding (document, fetch,
/// window) lands as a const cell so scripts can't rebind it.
#[must_use]
pub fn install(env: Env, heap: Heap, html_doc: &HtmlDoc) -> (Env, Heap) {
    let (document_value, _root_value, heap) = build_document(html_doc, heap);
    let bindings: Vec<(&str, Value)> = vec![
        ("document", document_value.clone()),
        ("fetch", Value::Native(fetch_impl)),
        ("window", document_value),
    ];
    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)
        })
}