LibJS: Add PropertyLookupPhase enum to distinguish Object [[Get]] calls

We can now tell the difference between an own property access and a
subsequent (automatic) prototype chain access.

This will be used to implement caching of prototype chain accesses.
This commit is contained in:
Andreas Kling 2024-05-02 11:13:08 +02:00
commit 493a04d5fe
Notes: sideshowbarker 2024-07-17 23:07:41 +09:00
17 changed files with 34 additions and 28 deletions

View file

@ -409,15 +409,15 @@ JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_has_property(JS::Prope
return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid;
}
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclaration::internal_get(JS::PropertyKey const& name, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata) const
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclaration::internal_get(JS::PropertyKey const& name, JS::Value receiver, JS::CacheablePropertyMetadata* cacheable_metadata, PropertyLookupPhase phase) const
{
if (name.is_number())
return { JS::PrimitiveString::create(vm(), item(name.as_number())) };
if (!name.is_string())
return Base::internal_get(name, receiver, cacheable_metadata);
return Base::internal_get(name, receiver, cacheable_metadata, phase);
auto property_id = property_id_from_name(name.to_string());
if (property_id == CSS::PropertyID::Invalid)
return Base::internal_get(name, receiver, cacheable_metadata);
return Base::internal_get(name, receiver, cacheable_metadata, phase);
if (auto maybe_property = property(property_id); maybe_property.has_value())
return { JS::PrimitiveString::create(vm(), maybe_property->value->to_string()) };
return { JS::PrimitiveString::create(vm(), String {}) };