Skip to main content

EvalContext

Struct EvalContext 

Source
pub struct EvalContext {
    pub in_method: bool,
    pub in_derived_constructor: bool,
    pub private_names: Vec<String>,
    pub arguments_allowed: bool,
    pub new_target_allowed: bool,
}
Expand description

What the code that called a direct eval allows its body to use.

Fields§

§in_method: bool

The caller is a method (or a nested arrow in one), so super.x is legal — the eval’d code runs with the caller’s [[HomeObject]].

§in_derived_constructor: bool

The caller is a derived class constructor, so super() is legal too.

§private_names: Vec<String>

The private names the calling code can see.

Private names are lexically scoped (§15.10.2 AllPrivateIdentifiersValid), and a direct eval runs inside the scope of its caller, so class C { #m = 44; f() { return eval("this.#m") } } is legal and answers 44. The source text alone cannot know that — the names come from the class surrounding the call site, a different compilation unit — so the caller says which ones are live. An indirect eval sees none of them, which is why this belongs to the direct-only context rather than to the parser.

§arguments_allowed: bool

Whether arguments is a binding at the call site.

A class field initializer and a static block have none (§15.7 puts them outside any function’s arguments), so eval('arguments') there is a SyntaxError rather than the caller’s arguments object.

§new_target_allowed: bool

Whether new.target is reachable from the call site.

Legal in a direct eval inside any function (§15.8.1 makes it a syntactic form whose target is the enclosing function’s), and a SyntaxError in an indirect one: there is no enclosing function to ask.

Trait Implementations§

Source§

impl Clone for EvalContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EvalContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EvalContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for EvalContext

§

impl Freeze for EvalContext

§

impl Move for EvalContext

§

impl RefUnwindSafe for EvalContext

§

impl Send for EvalContext
where RawVecInner: Send,

§

impl Sync for EvalContext
where RawVecInner: Sync,

§

impl Unpin for EvalContext
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for EvalContext

§

impl UnwindSafe for EvalContext
where RawVecInner: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.