-
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathlexical.rs
More file actions
44 lines (38 loc) · 1.23 KB
/
lexical.rs
File metadata and controls
44 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use boa_gc::{Finalize, GcRefCell, Trace};
use crate::{JsResult, JsValue};
#[derive(Debug, Trace, Finalize)]
pub(crate) struct LexicalEnvironment {
bindings: GcRefCell<Vec<Option<JsValue>>>,
}
impl LexicalEnvironment {
/// Creates a new `LexicalEnvironment`.
pub(crate) fn new(bindings: u32) -> Self {
Self {
bindings: GcRefCell::new(vec![None; bindings as usize]),
}
}
/// Gets the binding value from the environment by it's index.
///
/// # Panics
///
/// Panics if the binding value is out of range or not initialized.
#[track_caller]
pub(crate) fn get(&self, index: u32) -> Option<JsValue> {
self.bindings.borrow()[index as usize].clone()
}
/// Sets the binding value from the environment by index.
///
/// # Panics
///
/// Panics if the binding value is out of range.
#[track_caller]
pub(crate) fn set(&self, index: u32, value: JsValue) -> JsResult<()> {
self.bindings.borrow_mut()[index as usize] = Some(value);
Ok(())
}
/// Gets the bindings of this poisonable environment.
#[expect(dead_code)]
pub(crate) const fn bindings(&self) -> &GcRefCell<Vec<Option<JsValue>>> {
&self.bindings
}
}