LibJS: Add Object::may_interfere_with_indexed_property_access() virtual

This function must return true if the object may intercept and customize
access to indexed properties (properties where the property name is a
non-negative integer.)

This will be used to implement fast path optimizations for array-like
accesses in subsequent commits.
This commit is contained in:
Andreas Kling 2023-10-05 08:58:30 +02:00
parent 900334a4aa
commit 7df1692580
12 changed files with 28 additions and 0 deletions

View file

@ -2573,6 +2573,8 @@ private:
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override;
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
JS::Realm& m_realm; // [[Realm]]
};
)~~~");

View file

@ -27,6 +27,8 @@ public:
virtual ThrowCompletionOr<bool> internal_set(PropertyKey const&, Value value, Value receiver) override;
virtual ThrowCompletionOr<bool> internal_delete(PropertyKey const&) override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
// [[ParameterMap]]
Object& parameter_map() { return *m_parameter_map; }

View file

@ -31,6 +31,8 @@ public:
virtual ThrowCompletionOr<MarkedVector<Value>> internal_own_property_keys() const override;
virtual void initialize(Realm&) override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
private:
ModuleNamespaceObject(Realm&, Module* module, Vector<DeprecatedFlyString> exports);

View file

@ -135,6 +135,12 @@ public:
virtual ThrowCompletionOr<bool> internal_delete(PropertyKey const&);
virtual ThrowCompletionOr<MarkedVector<Value>> internal_own_property_keys() const;
// NOTE: Any subclass of Object that overrides property access slots ([[Get]], [[Set]] etc)
// to customize access to indexed properties (properties where the name is a positive integer)
// must return true for this, to opt out of optimizations that rely on assumptions that
// might not hold when property access behaves differently.
virtual bool may_interfere_with_indexed_property_access() const { return false; }
ThrowCompletionOr<bool> ordinary_set_with_own_descriptor(PropertyKey const&, Value, Value, Optional<PropertyDescriptor>);
// 10.4.7 Immutable Prototype Exotic Objects, https://tc39.es/ecma262/#sec-immutable-prototype-exotic-objects

View file

@ -45,6 +45,8 @@ public:
virtual ThrowCompletionOr<Value> internal_call(Value this_argument, MarkedVector<Value> arguments_list) override;
virtual ThrowCompletionOr<NonnullGCPtr<Object>> internal_construct(MarkedVector<Value> arguments_list, FunctionObject& new_target) override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
private:
ProxyObject(Object& target, Object& handler, Object& prototype);

View file

@ -30,6 +30,8 @@ private:
virtual ThrowCompletionOr<bool> internal_define_own_property(PropertyKey const&, PropertyDescriptor const&) override;
virtual ThrowCompletionOr<MarkedVector<Value>> internal_own_property_keys() const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
virtual bool is_string_object() const final { return true; }
virtual void visit_edges(Visitor&) override;

View file

@ -414,6 +414,8 @@ public:
return { move(keys) };
}
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
ReadonlySpan<UnderlyingBufferDataType> data() const
{
return { reinterpret_cast<UnderlyingBufferDataType const*>(m_viewed_array_buffer->buffer().data() + m_byte_offset), m_array_length };

View file

@ -29,6 +29,8 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_prevent_extensions() override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
enum class IgnoreNamedProps {
No,
Yes,

View file

@ -51,6 +51,8 @@ private:
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const& property_name) const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
JS::MarkedVector<JS::NonnullGCPtr<AudioTrack>> m_audio_tracks;
};

View file

@ -64,6 +64,8 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
HTML::CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; }
HTML::CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; }

View file

@ -44,6 +44,8 @@ private:
virtual void initialize(JS::Realm&) override;
virtual JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> internal_get_own_property(JS::PropertyKey const& property_name) const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
JS::MarkedVector<JS::NonnullGCPtr<VideoTrack>> m_video_tracks;
};

View file

@ -31,6 +31,8 @@ public:
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
virtual bool may_interfere_with_indexed_property_access() const final { return true; }
JS::GCPtr<Window> window() const { return m_window; }
void set_window(JS::NonnullGCPtr<Window>);