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: boolThe 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: boolThe 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: boolWhether 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: boolWhether 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.