javascript-globals 2.0.0

Global identifiers from different JavaScript environments
Documentation
// This file is generated by `xtask`.
//
// `data.bin` contains, in order:
// 1. shared ptrhash pilots and remap tables;
// 2. all UTF-8 names concatenated in PHF slot/ID order;
// 3. one u16 offset per name plus a final sentinel;
// 4. a membership bitset and sorted writable-ID list for each unique environment.
//
// The helpers below materialize typed arrays from those byte ranges during const evaluation.
// There is no runtime parsing or allocation.

use super::{GlobalNames, GlobalSet, Globals};

const DATA: &[u8; 33711] = include_bytes!("data.bin");

const fn bytes<const START: usize, const LEN: usize>() -> [u8; LEN] {
    let mut values = [0; LEN];
    let mut index = 0;
    while index < LEN {
        values[index] = DATA[START + index];
        index += 1;
    }
    values
}

const fn u16s<const START: usize, const LEN: usize>() -> [u16; LEN] {
    let mut values = [0; LEN];
    let mut index = 0;
    while index < LEN {
        let offset = START + index * 2;
        values[index] = u16::from_le_bytes([DATA[offset], DATA[offset + 1]]);
        index += 1;
    }
    values
}

const fn u32s<const START: usize, const LEN: usize>() -> [u32; LEN] {
    let mut values = [0; LEN];
    let mut index = 0;
    while index < LEN {
        let offset = START + index * 4;
        values[index] = u32::from_le_bytes([
            DATA[offset],
            DATA[offset + 1],
            DATA[offset + 2],
            DATA[offset + 3],
        ]);
        index += 1;
    }
    values
}

// Preserve the map-compatible iterator item type without emitting one Rust string literal per
// name. Every reference points into the single name blob owned by `GLOBAL_NAMES`.
const fn global_name_refs(names: &'static [u8], offsets: &'static [u16]) -> [&'static str; 1638] {
    let mut refs = [""; 1638];
    let mut index = 0;
    while index < refs.len() {
        let start = offsets[index] as usize;
        let end = offsets[index + 1] as usize;
        // SAFETY: The generator concatenates valid UTF-8 strings and records their boundaries.
        refs[index] = unsafe {
            let bytes = core::slice::from_raw_parts(names.as_ptr().add(start), end - start);
            core::str::from_utf8_unchecked(bytes)
        };
        index += 1;
    }
    refs
}

pub(super) const GLOBAL_NAME_COUNT: usize = 1638;
pub(super) const GLOBAL_NAME_BYTES: usize = 205;

// A ptrhash output slot is the global's shared numeric ID. `GlobalNames::get` verifies the string
// at the candidate slot because a perfect hash only distinguishes keys from its generated set.
pub(super) static GLOBAL_NAMES: GlobalNames = GlobalNames {
    seed: 16287231350648472473,
    pilots: &bytes::<0x0000, 549>(),
    remap: &u32s::<0x0225, 17>(),
    names: &bytes::<0x0269, 22100>(),
    offsets: &u16s::<0x58bd, 1639>(),
};

pub(super) static GLOBAL_NAME_REFS: [&str; 1638] =
    global_name_refs(GLOBAL_NAMES.names, GLOBAL_NAMES.offsets);

// Each set references its member bitset and sorted writable-ID slice inside `data.bin`. Equal sets
// are emitted as aliases by the generator.
#[rustfmt::skip]
pub static GLOBALS_BUILTIN: GlobalSet = GlobalSet { members: &bytes::<0x658b, 205>(), writable: &u16s::<0x6658, 0>() };

#[rustfmt::skip]
pub static GLOBALS_ES6: GlobalSet = GlobalSet { members: &bytes::<0x6658, 205>(), writable: &u16s::<0x6725, 0>() };

pub use GLOBALS_ES6 as GLOBALS_ES2015;

pub use GLOBALS_ES6 as GLOBALS_ES2016;

#[rustfmt::skip]
pub static GLOBALS_ES2017: GlobalSet = GlobalSet { members: &bytes::<0x6725, 205>(), writable: &u16s::<0x67f2, 0>() };

pub use GLOBALS_ES2017 as GLOBALS_ES2018;

pub use GLOBALS_ES2017 as GLOBALS_ES2019;

#[rustfmt::skip]
pub static GLOBALS_ES2020: GlobalSet = GlobalSet { members: &bytes::<0x67f2, 205>(), writable: &u16s::<0x68bf, 0>() };

#[rustfmt::skip]
pub static GLOBALS_ES2021: GlobalSet = GlobalSet { members: &bytes::<0x68bf, 205>(), writable: &u16s::<0x698c, 0>() };

pub use GLOBALS_ES2021 as GLOBALS_ES2022;

pub use GLOBALS_ES2021 as GLOBALS_ES2023;

pub use GLOBALS_ES2021 as GLOBALS_ES2024;

#[rustfmt::skip]
pub static GLOBALS_ES2025: GlobalSet = GlobalSet { members: &bytes::<0x698c, 205>(), writable: &u16s::<0x6a59, 0>() };

pub use GLOBALS_ES2025 as GLOBALS_ES2026;

#[rustfmt::skip]
pub static GLOBALS_AUDIOWORKLET: GlobalSet = GlobalSet { members: &bytes::<0x6a59, 205>(), writable: &u16s::<0x6b26, 0>() };

#[rustfmt::skip]
pub static GLOBALS_BROWSER: GlobalSet = GlobalSet { members: &bytes::<0x6b26, 205>(), writable: &u16s::<0x6bf3, 125>() };

#[rustfmt::skip]
pub static GLOBALS_BUN: GlobalSet = GlobalSet { members: &bytes::<0x6ced, 205>(), writable: &u16s::<0x6dba, 2>() };

#[rustfmt::skip]
pub static GLOBALS_NODE: GlobalSet = GlobalSet { members: &bytes::<0x6dbe, 205>(), writable: &u16s::<0x6e8b, 1>() };

#[rustfmt::skip]
pub static GLOBALS_SHARED_NODE_BROWSER: GlobalSet = GlobalSet { members: &bytes::<0x6e8d, 205>(), writable: &u16s::<0x6f5a, 0>() };

#[rustfmt::skip]
pub static GLOBALS_WORKER: GlobalSet = GlobalSet { members: &bytes::<0x6f5a, 205>(), writable: &u16s::<0x7027, 9>() };

#[rustfmt::skip]
pub static GLOBALS_SERVICEWORKER: GlobalSet = GlobalSet { members: &bytes::<0x7039, 205>(), writable: &u16s::<0x7106, 25>() };

#[rustfmt::skip]
pub static GLOBALS_AMD: GlobalSet = GlobalSet { members: &bytes::<0x7138, 205>(), writable: &u16s::<0x7205, 0>() };

#[rustfmt::skip]
pub static GLOBALS_APPLESCRIPT: GlobalSet = GlobalSet { members: &bytes::<0x7205, 205>(), writable: &u16s::<0x72d2, 0>() };

#[rustfmt::skip]
pub static GLOBALS_ASTRO: GlobalSet = GlobalSet { members: &bytes::<0x72d2, 205>(), writable: &u16s::<0x739f, 0>() };

#[rustfmt::skip]
pub static GLOBALS_ATOMTEST: GlobalSet = GlobalSet { members: &bytes::<0x739f, 205>(), writable: &u16s::<0x746c, 0>() };

#[rustfmt::skip]
pub static GLOBALS_COMMONJS: GlobalSet = GlobalSet { members: &bytes::<0x746c, 205>(), writable: &u16s::<0x7539, 1>() };

#[rustfmt::skip]
pub static GLOBALS_EMBERTEST: GlobalSet = GlobalSet { members: &bytes::<0x753b, 205>(), writable: &u16s::<0x7608, 0>() };

#[rustfmt::skip]
pub static GLOBALS_GREASEMONKEY: GlobalSet = GlobalSet { members: &bytes::<0x7608, 205>(), writable: &u16s::<0x76d5, 0>() };

#[rustfmt::skip]
pub static GLOBALS_JASMINE: GlobalSet = GlobalSet { members: &bytes::<0x76d5, 205>(), writable: &u16s::<0x77a2, 0>() };

#[rustfmt::skip]
pub static GLOBALS_JEST: GlobalSet = GlobalSet { members: &bytes::<0x77a2, 205>(), writable: &u16s::<0x786f, 0>() };

#[rustfmt::skip]
pub static GLOBALS_JQUERY: GlobalSet = GlobalSet { members: &bytes::<0x786f, 205>(), writable: &u16s::<0x793c, 0>() };

#[rustfmt::skip]
pub static GLOBALS_METEOR: GlobalSet = GlobalSet { members: &bytes::<0x793c, 205>(), writable: &u16s::<0x7a09, 0>() };

#[rustfmt::skip]
pub static GLOBALS_MOCHA: GlobalSet = GlobalSet { members: &bytes::<0x7a09, 205>(), writable: &u16s::<0x7ad6, 0>() };

#[rustfmt::skip]
pub static GLOBALS_MONGO: GlobalSet = GlobalSet { members: &bytes::<0x7ad6, 205>(), writable: &u16s::<0x7ba3, 0>() };

#[rustfmt::skip]
pub static GLOBALS_NASHORN: GlobalSet = GlobalSet { members: &bytes::<0x7ba3, 205>(), writable: &u16s::<0x7c70, 0>() };

#[rustfmt::skip]
pub static GLOBALS_PROTRACTOR: GlobalSet = GlobalSet { members: &bytes::<0x7c70, 205>(), writable: &u16s::<0x7d3d, 0>() };

#[rustfmt::skip]
pub static GLOBALS_PROTOTYPEJS: GlobalSet = GlobalSet { members: &bytes::<0x7d3d, 205>(), writable: &u16s::<0x7e0a, 0>() };

#[rustfmt::skip]
pub static GLOBALS_PHANTOMJS: GlobalSet = GlobalSet { members: &bytes::<0x7e0a, 205>(), writable: &u16s::<0x7ed7, 5>() };

#[rustfmt::skip]
pub static GLOBALS_SHELLJS: GlobalSet = GlobalSet { members: &bytes::<0x7ee1, 205>(), writable: &u16s::<0x7fae, 0>() };

#[rustfmt::skip]
pub static GLOBALS_SVELTE: GlobalSet = GlobalSet { members: &bytes::<0x7fae, 205>(), writable: &u16s::<0x807b, 0>() };

#[rustfmt::skip]
pub static GLOBALS_WEBEXTENSIONS: GlobalSet = GlobalSet { members: &bytes::<0x807b, 205>(), writable: &u16s::<0x8148, 0>() };

#[rustfmt::skip]
pub static GLOBALS_QUNIT: GlobalSet = GlobalSet { members: &bytes::<0x8148, 205>(), writable: &u16s::<0x8215, 0>() };

#[rustfmt::skip]
pub static GLOBALS_VITEST: GlobalSet = GlobalSet { members: &bytes::<0x8215, 205>(), writable: &u16s::<0x82e2, 0>() };

#[rustfmt::skip]
pub static GLOBALS_VUE: GlobalSet = GlobalSet { members: &bytes::<0x82e2, 205>(), writable: &u16s::<0x83af, 0>() };

pub(super) static ENVIRONMENTS: [(&str, &GlobalSet); 44] = [
    ("builtin", &GLOBALS_BUILTIN),
    ("es6", &GLOBALS_ES6),
    ("es2015", &GLOBALS_ES2015),
    ("es2016", &GLOBALS_ES2016),
    ("es2017", &GLOBALS_ES2017),
    ("es2018", &GLOBALS_ES2018),
    ("es2019", &GLOBALS_ES2019),
    ("es2020", &GLOBALS_ES2020),
    ("es2021", &GLOBALS_ES2021),
    ("es2022", &GLOBALS_ES2022),
    ("es2023", &GLOBALS_ES2023),
    ("es2024", &GLOBALS_ES2024),
    ("es2025", &GLOBALS_ES2025),
    ("es2026", &GLOBALS_ES2026),
    ("audioworklet", &GLOBALS_AUDIOWORKLET),
    ("browser", &GLOBALS_BROWSER),
    ("bun", &GLOBALS_BUN),
    ("node", &GLOBALS_NODE),
    ("shared-node-browser", &GLOBALS_SHARED_NODE_BROWSER),
    ("worker", &GLOBALS_WORKER),
    ("serviceworker", &GLOBALS_SERVICEWORKER),
    ("amd", &GLOBALS_AMD),
    ("applescript", &GLOBALS_APPLESCRIPT),
    ("astro", &GLOBALS_ASTRO),
    ("atomtest", &GLOBALS_ATOMTEST),
    ("commonjs", &GLOBALS_COMMONJS),
    ("embertest", &GLOBALS_EMBERTEST),
    ("greasemonkey", &GLOBALS_GREASEMONKEY),
    ("jasmine", &GLOBALS_JASMINE),
    ("jest", &GLOBALS_JEST),
    ("jquery", &GLOBALS_JQUERY),
    ("meteor", &GLOBALS_METEOR),
    ("mocha", &GLOBALS_MOCHA),
    ("mongo", &GLOBALS_MONGO),
    ("nashorn", &GLOBALS_NASHORN),
    ("protractor", &GLOBALS_PROTRACTOR),
    ("prototypejs", &GLOBALS_PROTOTYPEJS),
    ("phantomjs", &GLOBALS_PHANTOMJS),
    ("shelljs", &GLOBALS_SHELLJS),
    ("svelte", &GLOBALS_SVELTE),
    ("webextensions", &GLOBALS_WEBEXTENSIONS),
    ("qunit", &GLOBALS_QUNIT),
    ("vitest", &GLOBALS_VITEST),
    ("vue", &GLOBALS_VUE),
];

// Keep iteration data separate from lookup code: users of `GLOBALS.get` get a direct match, and
// linkers can discard `ENVIRONMENTS` when `GLOBALS.entries` is unused.
pub(super) fn get_environment(key: &str) -> Option<&'static GlobalSet> {
    match key {
        "builtin" => Some(&GLOBALS_BUILTIN),
        "es6" => Some(&GLOBALS_ES6),
        "es2015" => Some(&GLOBALS_ES2015),
        "es2016" => Some(&GLOBALS_ES2016),
        "es2017" => Some(&GLOBALS_ES2017),
        "es2018" => Some(&GLOBALS_ES2018),
        "es2019" => Some(&GLOBALS_ES2019),
        "es2020" => Some(&GLOBALS_ES2020),
        "es2021" => Some(&GLOBALS_ES2021),
        "es2022" => Some(&GLOBALS_ES2022),
        "es2023" => Some(&GLOBALS_ES2023),
        "es2024" => Some(&GLOBALS_ES2024),
        "es2025" => Some(&GLOBALS_ES2025),
        "es2026" => Some(&GLOBALS_ES2026),
        "audioworklet" => Some(&GLOBALS_AUDIOWORKLET),
        "browser" => Some(&GLOBALS_BROWSER),
        "bun" => Some(&GLOBALS_BUN),
        "node" => Some(&GLOBALS_NODE),
        "shared-node-browser" => Some(&GLOBALS_SHARED_NODE_BROWSER),
        "worker" => Some(&GLOBALS_WORKER),
        "serviceworker" => Some(&GLOBALS_SERVICEWORKER),
        "amd" => Some(&GLOBALS_AMD),
        "applescript" => Some(&GLOBALS_APPLESCRIPT),
        "astro" => Some(&GLOBALS_ASTRO),
        "atomtest" => Some(&GLOBALS_ATOMTEST),
        "commonjs" => Some(&GLOBALS_COMMONJS),
        "embertest" => Some(&GLOBALS_EMBERTEST),
        "greasemonkey" => Some(&GLOBALS_GREASEMONKEY),
        "jasmine" => Some(&GLOBALS_JASMINE),
        "jest" => Some(&GLOBALS_JEST),
        "jquery" => Some(&GLOBALS_JQUERY),
        "meteor" => Some(&GLOBALS_METEOR),
        "mocha" => Some(&GLOBALS_MOCHA),
        "mongo" => Some(&GLOBALS_MONGO),
        "nashorn" => Some(&GLOBALS_NASHORN),
        "protractor" => Some(&GLOBALS_PROTRACTOR),
        "prototypejs" => Some(&GLOBALS_PROTOTYPEJS),
        "phantomjs" => Some(&GLOBALS_PHANTOMJS),
        "shelljs" => Some(&GLOBALS_SHELLJS),
        "svelte" => Some(&GLOBALS_SVELTE),
        "webextensions" => Some(&GLOBALS_WEBEXTENSIONS),
        "qunit" => Some(&GLOBALS_QUNIT),
        "vitest" => Some(&GLOBALS_VITEST),
        "vue" => Some(&GLOBALS_VUE),
        _ => None,
    }
}

/// All available environments.
pub static GLOBALS: Globals = Globals;