Bindings: Avoid second property index lookup for platform objects

While conceptually is_supported_property_index is a cheap index lookup,
it is not currently cheap for an container such as HTMLAllCollection
that is operating on an uncached collection. Instead - just do the
lookup once. It also happens to look a little nicer to not blindly
dereference an optional.
This commit is contained in:
Shannon Booth 2024-07-25 19:16:40 +12:00 committed by Andreas Kling
parent 8a5985b87f
commit 22969a8e92
Notes: github-actions[bot] 2024-07-26 12:27:06 +00:00

View file

@ -91,12 +91,12 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> PlatformObject::legacy_p
u32 index = property_name.as_number();
// 2. If index is a supported property index, then:
if (is_supported_property_index(index)) {
if (auto maybe_value = item_value(index); maybe_value.has_value()) {
// 1. Let operation be the operation used to declare the indexed property getter.
// 2. Let value be an uninitialized variable.
// 3. If operation was defined without an identifier, then set value to the result of performing the steps listed in the interface description to determine the value of an indexed property with index as the index.
// 4. Otherwise, operation was defined with an identifier. Set value to the result of performing the method steps of operation with O as this and « index » as the argument values.
auto value = *item_value(index);
auto value = maybe_value.release_value();
// 5. Let desc be a newly created Property Descriptor with no fields.
JS::PropertyDescriptor descriptor;