Skip to main content

Scope

Struct Scope 

Source
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

Source

pub fn new_global() -> Self

Creates a new global scope.

Source

pub fn new(parent: Self, function: bool) -> Self

Creates a new scope.

Source

pub fn all_bindings_local(&self) -> bool

Checks if the scope has only local bindings.

Source

pub fn escape_all_bindings(&self)

Marks all bindings in this scope as escaping.

Source

pub fn escaped_this(&self) -> bool

Has this binding escaped.

Source

pub fn has_lex_binding(&self, name: &JsString) -> bool

Check if the scope has a lexical binding with the given name.

Source

pub fn has_binding(&self, name: &JsString) -> bool

Check if the scope has a binding with the given name.

Source

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.

Source

pub fn num_bindings(&self) -> u32

Returns the number of bindings in this scope.

Source

pub fn num_bindings_non_local(&self) -> u32

Returns the number of bindings in this scope that are not local.

Source

pub fn scope_index(&self) -> u32

Returns the index of this scope.

Source

pub fn is_function(&self) -> bool

Check if the scope is a function scope.

Source

pub fn is_global(&self) -> bool

Check if the scope is a global scope.

Source

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.

Source

pub fn get_binding(&self, name: &JsString) -> Option<BindingLocator>

Get the locator for a binding name.

Source

pub fn get_binding_reference( &self, name: &JsString, ) -> Option<IdentifierReference>

Get the locator for a binding name.

Source

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.
Source

pub fn escape_this_in_enclosing_function_scope(&self)

Escape enclosing function environment’s this.

Source

pub fn create_mutable_binding( &self, name: JsString, function_scope: bool, ) -> BindingLocator

Creates a mutable binding.

Source

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.

Source

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.

Source

pub fn outer(&self) -> Option<&Self>

Gets the outer scope of this scope.

Source

pub fn unique_id(&self) -> u32

Returns the unique ID of this scope.

Trait Implementations§

Source§

impl<'a> Arbitrary<'a> for Scope

Available on crate feature arbitrary only.
Source§

fn arbitrary(_u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

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 Scope

Source§

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

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

impl Default for Scope

Source§

fn default() -> Self

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

impl PartialEq for Scope

Source§

fn eq(&self, other: &Scope) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Scope

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl !UnwindSafe for Scope

§

impl Freeze for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.