boa_engine/environments/mod.rs
1//! Boa's implementation of ECMAScript's `Environment Records`.
2//!
3//! Environments contain the bindings of identifiers to their values.
4//! The implementation differs from the methods defined by the specification,
5//! but the resulting behavior should be the same.
6//!
7//! To make the runtime more performant, environment specific behavior is split
8//! between bytecode compilation and the runtime.
9//! While the association of identifiers to values seems like a natural fit for a hashmap,
10//! lookups of the values at runtime are very expensive.
11//! Environments can also have outer environments.
12//! In the worst case, there are as many hashmap lookups, as there are environments.
13//!
14//! To avoid these costs, hashmaps are not used at runtime.
15//! At runtime, environments are represented as fixed size lists of binding values.
16//! The positions of the bindings in these lists is determined at bytecode compile time.
17//!
18//! A binding is uniquely identified by two indices:
19//! - An environment index, that identifies the environment in which the binding exists
20//! - A binding index, that identifies the binding in the environment
21//!
22//! More information:
23//! - [ECMAScript reference][spec]
24//!
25//! [spec]: https://tc39.es/ecma262/#sec-environment-records
26
27mod runtime;
28
29pub(crate) use runtime::{
30 DeclarativeEnvironment, Environment, EnvironmentStack, FunctionSlots, PrivateEnvironment,
31 SavedEnvironments, ThisBindingStatus,
32};
33
34#[cfg(test)]
35mod tests;