pub struct Scope { /* private fields */ }Expand description
A scope maps bound identifiers to their binding positions.
It can be either a global scope or a function scope or a declarative scope.
Implementations§
Source§impl Scope
impl Scope
Sourcepub fn new_global() -> Self
pub fn new_global() -> Self
Creates a new global scope.
Sourcepub fn all_bindings_local(&self) -> bool
pub fn all_bindings_local(&self) -> bool
Checks if the scope has only local bindings.
Sourcepub fn escape_all_bindings(&self)
pub fn escape_all_bindings(&self)
Marks all bindings in this scope as escaping.
Sourcepub fn escaped_this(&self) -> bool
pub fn escaped_this(&self) -> bool
Has this binding escaped.
Sourcepub fn has_lex_binding(&self, name: &JsString) -> bool
pub fn has_lex_binding(&self, name: &JsString) -> bool
Check if the scope has a lexical binding with the given name.
Sourcepub fn has_binding(&self, name: &JsString) -> bool
pub fn has_binding(&self, name: &JsString) -> bool
Check if the scope has a binding with the given name.
Sourcepub fn get_identifier_reference(&self, name: JsString) -> IdentifierReference
pub fn get_identifier_reference(&self, name: JsString) -> IdentifierReference
Get the binding locator for a binding with the given name. Fall back to the global scope if the binding is not found.
Sourcepub fn num_bindings(&self) -> u32
pub fn num_bindings(&self) -> u32
Returns the number of bindings in this scope.
Sourcepub fn num_bindings_non_local(&self) -> u32
pub fn num_bindings_non_local(&self) -> u32
Returns the number of bindings in this scope that are not local.
Sourcepub fn scope_index(&self) -> u32
pub fn scope_index(&self) -> u32
Returns the index of this scope.
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if the scope is a function scope.
Sourcepub fn is_binding_mutable(&self, name: &JsString) -> Option<bool>
pub fn is_binding_mutable(&self, name: &JsString) -> Option<bool>
Check if a binding with the given name is mutable.
Returns Some(true) for mutable bindings (let, var),
Some(false) for immutable bindings (const),
or None if the binding is not found in this or any outer scope.
Sourcepub fn get_binding(&self, name: &JsString) -> Option<BindingLocator>
pub fn get_binding(&self, name: &JsString) -> Option<BindingLocator>
Get the locator for a binding name.
Sourcepub fn get_binding_reference(
&self,
name: &JsString,
) -> Option<IdentifierReference>
pub fn get_binding_reference( &self, name: &JsString, ) -> Option<IdentifierReference>
Get the locator for a binding name.
Sourcepub fn access_binding(&self, name: &JsString, eval_or_with: bool)
pub fn access_binding(&self, name: &JsString, eval_or_with: bool)
Simulate a binding access.
- If the binding access crosses a function border, the binding is marked as escaping.
- If the binding access is in an eval or with scope, the binding is marked as escaping.
Sourcepub fn escape_this_in_enclosing_function_scope(&self)
pub fn escape_this_in_enclosing_function_scope(&self)
Escape enclosing function environment’s this.
Sourcepub fn create_mutable_binding(
&self,
name: JsString,
function_scope: bool,
) -> BindingLocator
pub fn create_mutable_binding( &self, name: JsString, function_scope: bool, ) -> BindingLocator
Creates a mutable binding.
Sourcepub fn set_mutable_binding(
&self,
name: JsString,
) -> Result<IdentifierReference, BindingLocatorError>
pub fn set_mutable_binding( &self, name: JsString, ) -> Result<IdentifierReference, BindingLocatorError>
Return the binding locator for a mutable binding.
§Errors
Returns an error if the binding is not mutable or does not exist.
Sourcepub fn set_mutable_binding_var(
&self,
name: JsString,
) -> Result<IdentifierReference, BindingLocatorError>
pub fn set_mutable_binding_var( &self, name: JsString, ) -> Result<IdentifierReference, BindingLocatorError>
Return the binding locator for a set operation on an existing var binding.
§Errors
Returns an error if the binding is not mutable or does not exist.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for Scope
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for Scope
arbitrary only.Source§fn arbitrary(_u: &mut Unstructured<'a>) -> Result<Self>
fn arbitrary(_u: &mut Unstructured<'a>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read more