LibJS: Allow direct index-based initialization of a declarative binding
Similar to the direct getter and setter in DeclarativeEnvironment, there are cases where we already know the index of a binding and can avoid a O(n) lookup to re-find that index.
This commit is contained in:
parent
533170fbfa
commit
435f49d98e
Notes:
sideshowbarker
2024-07-17 17:43:21 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/435f49d98e Pull-request: https://github.com/SerenityOS/serenity/pull/12951 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/linusg ✅
2 changed files with 9 additions and 2 deletions
|
@ -86,11 +86,17 @@ ThrowCompletionOr<void> DeclarativeEnvironment::create_immutable_binding(GlobalO
|
|||
}
|
||||
|
||||
// 9.1.1.1.4 InitializeBinding ( N, V ), https://tc39.es/ecma262/#sec-declarative-environment-records-initializebinding-n-v
|
||||
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(GlobalObject&, FlyString const& name, Value value)
|
||||
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding(GlobalObject& global_object, FlyString const& name, Value value)
|
||||
{
|
||||
auto index = find_binding_index(name);
|
||||
VERIFY(index.has_value());
|
||||
auto& binding = m_bindings[*index];
|
||||
|
||||
return initialize_binding_direct(global_object, *index, value);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> DeclarativeEnvironment::initialize_binding_direct(GlobalObject&, size_t index, Value value)
|
||||
{
|
||||
auto& binding = m_bindings[index];
|
||||
|
||||
// 1. Assert: envRec must have an uninitialized binding for N.
|
||||
VERIFY(binding.initialized == false);
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
return names;
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> initialize_binding_direct(GlobalObject&, size_t index, Value);
|
||||
ThrowCompletionOr<Value> get_binding_value_direct(GlobalObject&, size_t index, bool strict);
|
||||
ThrowCompletionOr<void> set_mutable_binding_direct(GlobalObject&, size_t index, Value, bool strict);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue