|
|
@ -77,11 +77,11 @@ impl EnvironmentStack { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Gets the current global environment.
|
|
|
|
/// Gets the current global environment.
|
|
|
|
pub(crate) fn global(&self) -> Gc<DeclarativeEnvironment> { |
|
|
|
pub(crate) fn global(&self) -> &Gc<DeclarativeEnvironment> { |
|
|
|
let env = self.stack[0].clone(); |
|
|
|
let env = &self.stack[0]; |
|
|
|
|
|
|
|
|
|
|
|
match env { |
|
|
|
match env { |
|
|
|
Environment::Declarative(ref env) => env.clone(), |
|
|
|
Environment::Declarative(ref env) => env, |
|
|
|
Environment::Object(_) => { |
|
|
|
Environment::Object(_) => { |
|
|
|
unreachable!("first environment should be the global environment") |
|
|
|
unreachable!("first environment should be the global environment") |
|
|
|
} |
|
|
|
} |
|
|
@ -89,7 +89,7 @@ impl EnvironmentStack { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Gets the next outer function environment.
|
|
|
|
/// Gets the next outer function environment.
|
|
|
|
pub(crate) fn outer_function_environment(&self) -> Gc<DeclarativeEnvironment> { |
|
|
|
pub(crate) fn outer_function_environment(&self) -> &Gc<DeclarativeEnvironment> { |
|
|
|
for env in self |
|
|
|
for env in self |
|
|
|
.stack |
|
|
|
.stack |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
@ -97,7 +97,7 @@ impl EnvironmentStack { |
|
|
|
.rev() |
|
|
|
.rev() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if let DeclarativeEnvironmentKind::Function(_) = &env.kind() { |
|
|
|
if let DeclarativeEnvironmentKind::Function(_) = &env.kind() { |
|
|
|
return env.clone(); |
|
|
|
return env; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
self.global() |
|
|
|
self.global() |
|
|
@ -288,11 +288,10 @@ impl EnvironmentStack { |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// Panics if no environment exists on the stack.
|
|
|
|
/// Panics if no environment exists on the stack.
|
|
|
|
#[track_caller] |
|
|
|
#[track_caller] |
|
|
|
pub(crate) fn current(&self) -> Environment { |
|
|
|
pub(crate) fn current_ref(&self) -> &Environment { |
|
|
|
self.stack |
|
|
|
self.stack |
|
|
|
.last() |
|
|
|
.last() |
|
|
|
.expect("global environment must always exist") |
|
|
|
.expect("global environment must always exist") |
|
|
|
.clone() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Get the compile environment for the current runtime environment.
|
|
|
|
/// Get the compile environment for the current runtime environment.
|
|
|
@ -502,7 +501,7 @@ impl Context { |
|
|
|
/// are completely removed of runtime checks because the specification guarantees that runtime
|
|
|
|
/// are completely removed of runtime checks because the specification guarantees that runtime
|
|
|
|
/// semantics cannot add or remove lexical bindings.
|
|
|
|
/// semantics cannot add or remove lexical bindings.
|
|
|
|
pub(crate) fn find_runtime_binding(&mut self, locator: &mut BindingLocator) -> JsResult<()> { |
|
|
|
pub(crate) fn find_runtime_binding(&mut self, locator: &mut BindingLocator) -> JsResult<()> { |
|
|
|
let current = self.vm.environments.current(); |
|
|
|
let current = self.vm.environments.current_ref(); |
|
|
|
if let Some(env) = current.as_declarative() { |
|
|
|
if let Some(env) = current.as_declarative() { |
|
|
|
if !env.with() && !env.poisoned() { |
|
|
|
if !env.with() && !env.poisoned() { |
|
|
|
return Ok(()); |
|
|
|
return Ok(()); |
|
|
@ -553,7 +552,7 @@ impl Context { |
|
|
|
&mut self, |
|
|
|
&mut self, |
|
|
|
locator: &BindingLocator, |
|
|
|
locator: &BindingLocator, |
|
|
|
) -> JsResult<Option<JsObject>> { |
|
|
|
) -> JsResult<Option<JsObject>> { |
|
|
|
let current = self.vm.environments.current(); |
|
|
|
let current = self.vm.environments.current_ref(); |
|
|
|
if let Some(env) = current.as_declarative() { |
|
|
|
if let Some(env) = current.as_declarative() { |
|
|
|
if !env.with() { |
|
|
|
if !env.with() { |
|
|
|
return Ok(None); |
|
|
|
return Ok(None); |
|
|
|