Skip to main content

ClosureEnv

Struct ClosureEnv 

Source
pub struct ClosureEnv {
    pub cells: Vec<Gc<Cell>>,
    pub eval_scope: Option<Gc<EvalScope>>,
    pub local_vars: Option<Gc<LocalVars>>,
    pub local_phase: u8,
}
Expand description

The reference cells a closure captured from enclosing scopes.

Fields§

§cells: Vec<Gc<Cell>>

Indexed the way the bytecode’s closure-variable table indexes them.

§eval_scope: Option<Gc<EvalScope>>

The eval scope this closure was created in, if any.

A function built by eval has to keep seeing the caller’s bindings after the eval has returned — for (let i …) eval("push(() => i)") collects closures that read i later. Those bindings live in the caller’s frame, which is long gone by then, so the environment carries them by name instead. Ordinary closures leave this None and resolve globals exactly as before.

§local_vars: Option<Gc<LocalVars>>

Variables a direct eval declared in the frame this closure was created in, and how much of that frame it may see.

A closure is created at a place in a function, and a direct eval can add variables after that point. Those variables belong to the variable environment that was current at the closure’s creation — the parameter list or the body — which is what local_phase records.

§local_phase: u8

0 for a closure created in a parameter list, 1 for one in a body. A parameter list’s closure must not see variables a later eval in the body declared: function f(a, p = () => c) { eval("var c = 1") } has p() resolve c outside the function entirely.

Trait Implementations§

Source§

impl Trace for ClosureEnv

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

Auto Trait Implementations§

§

impl !RefUnwindSafe for ClosureEnv

§

impl !Send for ClosureEnv

§

impl !Sync for ClosureEnv

§

impl !UnwindSafe for ClosureEnv

§

impl Forget for ClosureEnv

§

impl Freeze for ClosureEnv
where *const u8 is !null: Freeze, PhantomData<Gc<Cell>>: Freeze, *const GcBox<EvalScope> is !null: Freeze, *const GcBox<LocalVars> is !null: Freeze,

§

impl Move for ClosureEnv

§

impl Unpin for ClosureEnv
where *const u8 is !null: Unpin, *const GcBox<Cell> is !null: Unpin, *const GcBox<EvalScope> is !null: Unpin, *const GcBox<LocalVars> is !null: Unpin,

§

impl UnsafeUnpin for ClosureEnv

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.