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() -> Scope
pub fn new_global() -> Scope
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 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§
impl StructuralPartialEq for Scope
Auto Trait Implementations§
impl Freeze for Scope
impl !RefUnwindSafe for Scope
impl !Send for Scope
impl !Sync for Scope
impl Unpin for Scope
impl !UnwindSafe for Scope
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.