Skip to main content

javascript_globals/generated/
mod.rs

1// This file is generated by `xtask`.
2//
3// `data.bin` contains, in order:
4// 1. shared ptrhash pilots and remap tables;
5// 2. all UTF-8 names concatenated in PHF slot/ID order;
6// 3. one u16 offset per name plus a final sentinel;
7// 4. a membership bitset and sorted writable-ID list for each unique environment.
8//
9// The helpers below materialize typed arrays from those byte ranges during const evaluation.
10// There is no runtime parsing or allocation.
11
12use super::{GlobalNames, GlobalSet, Globals};
13
14const DATA: &[u8; 33711] = include_bytes!("data.bin");
15
16const fn bytes<const START: usize, const LEN: usize>() -> [u8; LEN] {
17    let mut values = [0; LEN];
18    let mut index = 0;
19    while index < LEN {
20        values[index] = DATA[START + index];
21        index += 1;
22    }
23    values
24}
25
26const fn u16s<const START: usize, const LEN: usize>() -> [u16; LEN] {
27    let mut values = [0; LEN];
28    let mut index = 0;
29    while index < LEN {
30        let offset = START + index * 2;
31        values[index] = u16::from_le_bytes([DATA[offset], DATA[offset + 1]]);
32        index += 1;
33    }
34    values
35}
36
37const fn u32s<const START: usize, const LEN: usize>() -> [u32; LEN] {
38    let mut values = [0; LEN];
39    let mut index = 0;
40    while index < LEN {
41        let offset = START + index * 4;
42        values[index] = u32::from_le_bytes([
43            DATA[offset],
44            DATA[offset + 1],
45            DATA[offset + 2],
46            DATA[offset + 3],
47        ]);
48        index += 1;
49    }
50    values
51}
52
53// Preserve the map-compatible iterator item type without emitting one Rust string literal per
54// name. Every reference points into the single name blob owned by `GLOBAL_NAMES`.
55const fn global_name_refs(names: &'static [u8], offsets: &'static [u16]) -> [&'static str; 1638] {
56    let mut refs = [""; 1638];
57    let mut index = 0;
58    while index < refs.len() {
59        let start = offsets[index] as usize;
60        let end = offsets[index + 1] as usize;
61        // SAFETY: The generator concatenates valid UTF-8 strings and records their boundaries.
62        refs[index] = unsafe {
63            let bytes = core::slice::from_raw_parts(names.as_ptr().add(start), end - start);
64            core::str::from_utf8_unchecked(bytes)
65        };
66        index += 1;
67    }
68    refs
69}
70
71pub(super) const GLOBAL_NAME_COUNT: usize = 1638;
72pub(super) const GLOBAL_NAME_BYTES: usize = 205;
73
74// A ptrhash output slot is the global's shared numeric ID. `GlobalNames::get` verifies the string
75// at the candidate slot because a perfect hash only distinguishes keys from its generated set.
76pub(super) static GLOBAL_NAMES: GlobalNames = GlobalNames {
77    seed: 16287231350648472473,
78    pilots: &bytes::<0x0000, 549>(),
79    remap: &u32s::<0x0225, 17>(),
80    names: &bytes::<0x0269, 22100>(),
81    offsets: &u16s::<0x58bd, 1639>(),
82};
83
84pub(super) static GLOBAL_NAME_REFS: [&str; 1638] =
85    global_name_refs(GLOBAL_NAMES.names, GLOBAL_NAMES.offsets);
86
87// Each set references its member bitset and sorted writable-ID slice inside `data.bin`. Equal sets
88// are emitted as aliases by the generator.
89#[rustfmt::skip]
90pub static GLOBALS_BUILTIN: GlobalSet = GlobalSet { members: &bytes::<0x658b, 205>(), writable: &u16s::<0x6658, 0>() };
91
92#[rustfmt::skip]
93pub static GLOBALS_ES6: GlobalSet = GlobalSet { members: &bytes::<0x6658, 205>(), writable: &u16s::<0x6725, 0>() };
94
95pub use GLOBALS_ES6 as GLOBALS_ES2015;
96
97pub use GLOBALS_ES6 as GLOBALS_ES2016;
98
99#[rustfmt::skip]
100pub static GLOBALS_ES2017: GlobalSet = GlobalSet { members: &bytes::<0x6725, 205>(), writable: &u16s::<0x67f2, 0>() };
101
102pub use GLOBALS_ES2017 as GLOBALS_ES2018;
103
104pub use GLOBALS_ES2017 as GLOBALS_ES2019;
105
106#[rustfmt::skip]
107pub static GLOBALS_ES2020: GlobalSet = GlobalSet { members: &bytes::<0x67f2, 205>(), writable: &u16s::<0x68bf, 0>() };
108
109#[rustfmt::skip]
110pub static GLOBALS_ES2021: GlobalSet = GlobalSet { members: &bytes::<0x68bf, 205>(), writable: &u16s::<0x698c, 0>() };
111
112pub use GLOBALS_ES2021 as GLOBALS_ES2022;
113
114pub use GLOBALS_ES2021 as GLOBALS_ES2023;
115
116pub use GLOBALS_ES2021 as GLOBALS_ES2024;
117
118#[rustfmt::skip]
119pub static GLOBALS_ES2025: GlobalSet = GlobalSet { members: &bytes::<0x698c, 205>(), writable: &u16s::<0x6a59, 0>() };
120
121pub use GLOBALS_ES2025 as GLOBALS_ES2026;
122
123#[rustfmt::skip]
124pub static GLOBALS_AUDIOWORKLET: GlobalSet = GlobalSet { members: &bytes::<0x6a59, 205>(), writable: &u16s::<0x6b26, 0>() };
125
126#[rustfmt::skip]
127pub static GLOBALS_BROWSER: GlobalSet = GlobalSet { members: &bytes::<0x6b26, 205>(), writable: &u16s::<0x6bf3, 125>() };
128
129#[rustfmt::skip]
130pub static GLOBALS_BUN: GlobalSet = GlobalSet { members: &bytes::<0x6ced, 205>(), writable: &u16s::<0x6dba, 2>() };
131
132#[rustfmt::skip]
133pub static GLOBALS_NODE: GlobalSet = GlobalSet { members: &bytes::<0x6dbe, 205>(), writable: &u16s::<0x6e8b, 1>() };
134
135#[rustfmt::skip]
136pub static GLOBALS_SHARED_NODE_BROWSER: GlobalSet = GlobalSet { members: &bytes::<0x6e8d, 205>(), writable: &u16s::<0x6f5a, 0>() };
137
138#[rustfmt::skip]
139pub static GLOBALS_WORKER: GlobalSet = GlobalSet { members: &bytes::<0x6f5a, 205>(), writable: &u16s::<0x7027, 9>() };
140
141#[rustfmt::skip]
142pub static GLOBALS_SERVICEWORKER: GlobalSet = GlobalSet { members: &bytes::<0x7039, 205>(), writable: &u16s::<0x7106, 25>() };
143
144#[rustfmt::skip]
145pub static GLOBALS_AMD: GlobalSet = GlobalSet { members: &bytes::<0x7138, 205>(), writable: &u16s::<0x7205, 0>() };
146
147#[rustfmt::skip]
148pub static GLOBALS_APPLESCRIPT: GlobalSet = GlobalSet { members: &bytes::<0x7205, 205>(), writable: &u16s::<0x72d2, 0>() };
149
150#[rustfmt::skip]
151pub static GLOBALS_ASTRO: GlobalSet = GlobalSet { members: &bytes::<0x72d2, 205>(), writable: &u16s::<0x739f, 0>() };
152
153#[rustfmt::skip]
154pub static GLOBALS_ATOMTEST: GlobalSet = GlobalSet { members: &bytes::<0x739f, 205>(), writable: &u16s::<0x746c, 0>() };
155
156#[rustfmt::skip]
157pub static GLOBALS_COMMONJS: GlobalSet = GlobalSet { members: &bytes::<0x746c, 205>(), writable: &u16s::<0x7539, 1>() };
158
159#[rustfmt::skip]
160pub static GLOBALS_EMBERTEST: GlobalSet = GlobalSet { members: &bytes::<0x753b, 205>(), writable: &u16s::<0x7608, 0>() };
161
162#[rustfmt::skip]
163pub static GLOBALS_GREASEMONKEY: GlobalSet = GlobalSet { members: &bytes::<0x7608, 205>(), writable: &u16s::<0x76d5, 0>() };
164
165#[rustfmt::skip]
166pub static GLOBALS_JASMINE: GlobalSet = GlobalSet { members: &bytes::<0x76d5, 205>(), writable: &u16s::<0x77a2, 0>() };
167
168#[rustfmt::skip]
169pub static GLOBALS_JEST: GlobalSet = GlobalSet { members: &bytes::<0x77a2, 205>(), writable: &u16s::<0x786f, 0>() };
170
171#[rustfmt::skip]
172pub static GLOBALS_JQUERY: GlobalSet = GlobalSet { members: &bytes::<0x786f, 205>(), writable: &u16s::<0x793c, 0>() };
173
174#[rustfmt::skip]
175pub static GLOBALS_METEOR: GlobalSet = GlobalSet { members: &bytes::<0x793c, 205>(), writable: &u16s::<0x7a09, 0>() };
176
177#[rustfmt::skip]
178pub static GLOBALS_MOCHA: GlobalSet = GlobalSet { members: &bytes::<0x7a09, 205>(), writable: &u16s::<0x7ad6, 0>() };
179
180#[rustfmt::skip]
181pub static GLOBALS_MONGO: GlobalSet = GlobalSet { members: &bytes::<0x7ad6, 205>(), writable: &u16s::<0x7ba3, 0>() };
182
183#[rustfmt::skip]
184pub static GLOBALS_NASHORN: GlobalSet = GlobalSet { members: &bytes::<0x7ba3, 205>(), writable: &u16s::<0x7c70, 0>() };
185
186#[rustfmt::skip]
187pub static GLOBALS_PROTRACTOR: GlobalSet = GlobalSet { members: &bytes::<0x7c70, 205>(), writable: &u16s::<0x7d3d, 0>() };
188
189#[rustfmt::skip]
190pub static GLOBALS_PROTOTYPEJS: GlobalSet = GlobalSet { members: &bytes::<0x7d3d, 205>(), writable: &u16s::<0x7e0a, 0>() };
191
192#[rustfmt::skip]
193pub static GLOBALS_PHANTOMJS: GlobalSet = GlobalSet { members: &bytes::<0x7e0a, 205>(), writable: &u16s::<0x7ed7, 5>() };
194
195#[rustfmt::skip]
196pub static GLOBALS_SHELLJS: GlobalSet = GlobalSet { members: &bytes::<0x7ee1, 205>(), writable: &u16s::<0x7fae, 0>() };
197
198#[rustfmt::skip]
199pub static GLOBALS_SVELTE: GlobalSet = GlobalSet { members: &bytes::<0x7fae, 205>(), writable: &u16s::<0x807b, 0>() };
200
201#[rustfmt::skip]
202pub static GLOBALS_WEBEXTENSIONS: GlobalSet = GlobalSet { members: &bytes::<0x807b, 205>(), writable: &u16s::<0x8148, 0>() };
203
204#[rustfmt::skip]
205pub static GLOBALS_QUNIT: GlobalSet = GlobalSet { members: &bytes::<0x8148, 205>(), writable: &u16s::<0x8215, 0>() };
206
207#[rustfmt::skip]
208pub static GLOBALS_VITEST: GlobalSet = GlobalSet { members: &bytes::<0x8215, 205>(), writable: &u16s::<0x82e2, 0>() };
209
210#[rustfmt::skip]
211pub static GLOBALS_VUE: GlobalSet = GlobalSet { members: &bytes::<0x82e2, 205>(), writable: &u16s::<0x83af, 0>() };
212
213pub(super) static ENVIRONMENTS: [(&str, &GlobalSet); 44] = [
214    ("builtin", &GLOBALS_BUILTIN),
215    ("es6", &GLOBALS_ES6),
216    ("es2015", &GLOBALS_ES2015),
217    ("es2016", &GLOBALS_ES2016),
218    ("es2017", &GLOBALS_ES2017),
219    ("es2018", &GLOBALS_ES2018),
220    ("es2019", &GLOBALS_ES2019),
221    ("es2020", &GLOBALS_ES2020),
222    ("es2021", &GLOBALS_ES2021),
223    ("es2022", &GLOBALS_ES2022),
224    ("es2023", &GLOBALS_ES2023),
225    ("es2024", &GLOBALS_ES2024),
226    ("es2025", &GLOBALS_ES2025),
227    ("es2026", &GLOBALS_ES2026),
228    ("audioworklet", &GLOBALS_AUDIOWORKLET),
229    ("browser", &GLOBALS_BROWSER),
230    ("bun", &GLOBALS_BUN),
231    ("node", &GLOBALS_NODE),
232    ("shared-node-browser", &GLOBALS_SHARED_NODE_BROWSER),
233    ("worker", &GLOBALS_WORKER),
234    ("serviceworker", &GLOBALS_SERVICEWORKER),
235    ("amd", &GLOBALS_AMD),
236    ("applescript", &GLOBALS_APPLESCRIPT),
237    ("astro", &GLOBALS_ASTRO),
238    ("atomtest", &GLOBALS_ATOMTEST),
239    ("commonjs", &GLOBALS_COMMONJS),
240    ("embertest", &GLOBALS_EMBERTEST),
241    ("greasemonkey", &GLOBALS_GREASEMONKEY),
242    ("jasmine", &GLOBALS_JASMINE),
243    ("jest", &GLOBALS_JEST),
244    ("jquery", &GLOBALS_JQUERY),
245    ("meteor", &GLOBALS_METEOR),
246    ("mocha", &GLOBALS_MOCHA),
247    ("mongo", &GLOBALS_MONGO),
248    ("nashorn", &GLOBALS_NASHORN),
249    ("protractor", &GLOBALS_PROTRACTOR),
250    ("prototypejs", &GLOBALS_PROTOTYPEJS),
251    ("phantomjs", &GLOBALS_PHANTOMJS),
252    ("shelljs", &GLOBALS_SHELLJS),
253    ("svelte", &GLOBALS_SVELTE),
254    ("webextensions", &GLOBALS_WEBEXTENSIONS),
255    ("qunit", &GLOBALS_QUNIT),
256    ("vitest", &GLOBALS_VITEST),
257    ("vue", &GLOBALS_VUE),
258];
259
260// Keep iteration data separate from lookup code: users of `GLOBALS.get` get a direct match, and
261// linkers can discard `ENVIRONMENTS` when `GLOBALS.entries` is unused.
262pub(super) fn get_environment(key: &str) -> Option<&'static GlobalSet> {
263    match key {
264        "builtin" => Some(&GLOBALS_BUILTIN),
265        "es6" => Some(&GLOBALS_ES6),
266        "es2015" => Some(&GLOBALS_ES2015),
267        "es2016" => Some(&GLOBALS_ES2016),
268        "es2017" => Some(&GLOBALS_ES2017),
269        "es2018" => Some(&GLOBALS_ES2018),
270        "es2019" => Some(&GLOBALS_ES2019),
271        "es2020" => Some(&GLOBALS_ES2020),
272        "es2021" => Some(&GLOBALS_ES2021),
273        "es2022" => Some(&GLOBALS_ES2022),
274        "es2023" => Some(&GLOBALS_ES2023),
275        "es2024" => Some(&GLOBALS_ES2024),
276        "es2025" => Some(&GLOBALS_ES2025),
277        "es2026" => Some(&GLOBALS_ES2026),
278        "audioworklet" => Some(&GLOBALS_AUDIOWORKLET),
279        "browser" => Some(&GLOBALS_BROWSER),
280        "bun" => Some(&GLOBALS_BUN),
281        "node" => Some(&GLOBALS_NODE),
282        "shared-node-browser" => Some(&GLOBALS_SHARED_NODE_BROWSER),
283        "worker" => Some(&GLOBALS_WORKER),
284        "serviceworker" => Some(&GLOBALS_SERVICEWORKER),
285        "amd" => Some(&GLOBALS_AMD),
286        "applescript" => Some(&GLOBALS_APPLESCRIPT),
287        "astro" => Some(&GLOBALS_ASTRO),
288        "atomtest" => Some(&GLOBALS_ATOMTEST),
289        "commonjs" => Some(&GLOBALS_COMMONJS),
290        "embertest" => Some(&GLOBALS_EMBERTEST),
291        "greasemonkey" => Some(&GLOBALS_GREASEMONKEY),
292        "jasmine" => Some(&GLOBALS_JASMINE),
293        "jest" => Some(&GLOBALS_JEST),
294        "jquery" => Some(&GLOBALS_JQUERY),
295        "meteor" => Some(&GLOBALS_METEOR),
296        "mocha" => Some(&GLOBALS_MOCHA),
297        "mongo" => Some(&GLOBALS_MONGO),
298        "nashorn" => Some(&GLOBALS_NASHORN),
299        "protractor" => Some(&GLOBALS_PROTRACTOR),
300        "prototypejs" => Some(&GLOBALS_PROTOTYPEJS),
301        "phantomjs" => Some(&GLOBALS_PHANTOMJS),
302        "shelljs" => Some(&GLOBALS_SHELLJS),
303        "svelte" => Some(&GLOBALS_SVELTE),
304        "webextensions" => Some(&GLOBALS_WEBEXTENSIONS),
305        "qunit" => Some(&GLOBALS_QUNIT),
306        "vitest" => Some(&GLOBALS_VITEST),
307        "vue" => Some(&GLOBALS_VUE),
308        _ => None,
309    }
310}
311
312/// All available environments.
313pub static GLOBALS: Globals = Globals;