pub struct LocalVars { /* private fields */ }Expand description
Variables a direct eval declared in one function call.
A sloppy eval declares its vars in the caller’s variable environment, not on the
global object: function f() { eval("var x = 1") } f(); x is a ReferenceError, and
two calls to f get two xs. Each entry therefore records the phase it was declared
in, so a lookup from the parameter list cannot see a body declaration.
Implementations§
Source§impl LocalVars
impl LocalVars
Sourcepub fn get(&self, name: &str, phase: u8) -> Option<Gc<Cell>>
pub fn get(&self, name: &str, phase: u8) -> Option<Gc<Cell>>
The cell name resolves to, when it was declared in phase or earlier.
Sourcepub fn declare(&self, name: &str, phase: u8, cell: Gc<Cell>) -> Gc<Cell>
pub fn declare(&self, name: &str, phase: u8, cell: Gc<Cell>) -> Gc<Cell>
The cell for name, declaring it if this is the first time.
Sourcepub fn declare_deletable(
&self,
name: &str,
phase: u8,
cell: Gc<Cell>,
) -> Gc<Cell>
pub fn declare_deletable( &self, name: &str, phase: u8, cell: Gc<Cell>, ) -> Gc<Cell>
The same, for a binding delete may remove — what an eval creates.
Sourcepub fn delete(&self, name: &str) -> Option<bool>
pub fn delete(&self, name: &str) -> Option<bool>
delete name: None when this set does not bind the name at all.
Some(true) removes the entry, so a later read falls through to the global object
and, finding nothing there, is a ReferenceError — which is exactly what
eval("var x; delete x; x") has to be.