boa_engine/environments/runtime/declarative/
lexical.rs

1use boa_gc::{Finalize, Trace};
2
3use crate::JsValue;
4
5use super::PoisonableEnvironment;
6
7#[derive(Debug, Trace, Finalize)]
8pub(crate) struct LexicalEnvironment {
9    inner: PoisonableEnvironment,
10}
11
12impl LexicalEnvironment {
13    /// Creates a new `LexicalEnvironment`.
14    pub(crate) fn new(bindings: u32, poisoned: bool, with: bool) -> Self {
15        Self {
16            inner: PoisonableEnvironment::new(bindings, poisoned, with),
17        }
18    }
19
20    /// Gets the `poisonable_environment` of this lexical environment.
21    pub(crate) const fn poisonable_environment(&self) -> &PoisonableEnvironment {
22        &self.inner
23    }
24
25    /// Gets the binding value from the environment by it's index.
26    ///
27    /// # Panics
28    ///
29    /// Panics if the binding value is out of range or not initialized.
30    #[track_caller]
31    pub(crate) fn get(&self, index: u32) -> Option<JsValue> {
32        self.inner.get(index)
33    }
34
35    /// Sets the binding value from the environment by index.
36    ///
37    /// # Panics
38    ///
39    /// Panics if the binding value is out of range.
40    #[track_caller]
41    pub(crate) fn set(&self, index: u32, value: JsValue) {
42        self.inner.set(index, value);
43    }
44}