mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibJS: Cache access to bindings in the global environment
This patch adds a special EnvironmentCoordinate::global_marker value that signifies that a binding lookup ended up searching the global environment. It doesn't matter if we find it there or not, the global marker is always returned. This allows us to bypass other environments on subsequent access, going directly to the global environment.
This commit is contained in:
parent
7b30df0840
commit
d7e5a2058d
Notes:
sideshowbarker
2024-07-17 05:19:06 +09:00
Author: https://github.com/awesomekling
Commit: d7e5a2058d
Pull-request: https://github.com/SerenityOS/serenity/pull/16017
Reviewed-by: https://github.com/IdanHo
Reviewed-by: https://github.com/linusg ✅
4 changed files with 18 additions and 8 deletions
|
@ -68,7 +68,7 @@ ThrowCompletionOr<void> Reference::put_value(VM& vm, Value value)
|
|||
VERIFY(m_base_environment);
|
||||
|
||||
// c. Return ? base.SetMutableBinding(V.[[ReferencedName]], W, V.[[Strict]]) (see 9.1).
|
||||
if (m_environment_coordinate.has_value())
|
||||
if (m_environment_coordinate.has_value() && m_environment_coordinate->index != EnvironmentCoordinate::global_marker)
|
||||
return static_cast<DeclarativeEnvironment*>(m_base_environment)->set_mutable_binding_direct(vm, m_environment_coordinate->index, value, m_strict);
|
||||
else
|
||||
return m_base_environment->set_mutable_binding(vm, m_name.as_string(), value, m_strict);
|
||||
|
@ -138,7 +138,7 @@ ThrowCompletionOr<Value> Reference::get_value(VM& vm) const
|
|||
VERIFY(m_base_environment);
|
||||
|
||||
// c. Return ? base.GetBindingValue(V.[[ReferencedName]], V.[[Strict]]) (see 9.1).
|
||||
if (m_environment_coordinate.has_value())
|
||||
if (m_environment_coordinate.has_value() && m_environment_coordinate->index != EnvironmentCoordinate::global_marker)
|
||||
return static_cast<DeclarativeEnvironment*>(m_base_environment)->get_binding_value_direct(vm, m_environment_coordinate->index, m_strict);
|
||||
return m_base_environment->get_binding_value(vm, m_name.as_string(), m_strict);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue