mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 09:58:14 +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
4 changed files with 18 additions and 8 deletions
|
@ -39,8 +39,11 @@ ThrowCompletionOr<Value> GlobalEnvironment::get_this_binding(VM&) const
|
|||
}
|
||||
|
||||
// 9.1.1.4.1 HasBinding ( N ), https://tc39.es/ecma262/#sec-global-environment-records-hasbinding-n
|
||||
ThrowCompletionOr<bool> GlobalEnvironment::has_binding(FlyString const& name, Optional<size_t>*) const
|
||||
ThrowCompletionOr<bool> GlobalEnvironment::has_binding(FlyString const& name, Optional<size_t>* out_index) const
|
||||
{
|
||||
if (out_index)
|
||||
*out_index = EnvironmentCoordinate::global_marker;
|
||||
|
||||
// 1. Let DclRec be envRec.[[DeclarativeRecord]].
|
||||
// 2. If ! DclRec.HasBinding(N) is true, return true.
|
||||
if (MUST(m_declarative_record->has_binding(name)))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue