1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 11:47:39 +00:00

LibJS: Respect Object::get's without_side_effects parameter for numbers

This commit is contained in:
Idan Horowitz 2021-06-16 20:39:39 +03:00 committed by Linus Groh
parent 317b88a8c3
commit 6352a33ed2
5 changed files with 10 additions and 10 deletions

View file

@ -812,7 +812,7 @@ void Object::ensure_shape_is_unique()
m_shape = m_shape->create_unique_clone(); m_shape = m_shape->create_unique_clone();
} }
Value Object::get_by_index(u32 property_index) const Value Object::get_by_index(u32 property_index, bool without_side_effects) const
{ {
const Object* object = this; const Object* object = this;
while (object) { while (object) {
@ -821,7 +821,7 @@ Value Object::get_by_index(u32 property_index) const
if (property_index < string.length()) if (property_index < string.length())
return js_string(heap(), string.substring(property_index, 1)); return js_string(heap(), string.substring(property_index, 1));
} else if (static_cast<size_t>(property_index) < object->m_indexed_properties.array_like_size()) { } else if (static_cast<size_t>(property_index) < object->m_indexed_properties.array_like_size()) {
auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index); auto result = object->m_indexed_properties.get(const_cast<Object*>(this), property_index, !without_side_effects);
if (vm().exception()) if (vm().exception())
return {}; return {};
if (result.has_value() && !result.value().value.is_empty()) if (result.has_value() && !result.value().value.is_empty())
@ -839,13 +839,13 @@ Value Object::get(const PropertyName& property_name, Value receiver, bool withou
VERIFY(property_name.is_valid()); VERIFY(property_name.is_valid());
if (property_name.is_number()) if (property_name.is_number())
return get_by_index(property_name.as_number()); return get_by_index(property_name.as_number(), without_side_effects);
if (property_name.is_string() && property_name.string_may_be_number()) { if (property_name.is_string() && property_name.string_may_be_number()) {
auto& property_string = property_name.as_string(); auto& property_string = property_name.as_string();
i32 property_index = property_string.to_int().value_or(-1); i32 property_index = property_string.to_int().value_or(-1);
if (property_index >= 0) if (property_index >= 0)
return get_by_index(property_index); return get_by_index(property_index, without_side_effects);
} }
if (receiver.is_empty()) if (receiver.is_empty())

View file

@ -163,7 +163,7 @@ protected:
explicit Object(GlobalObjectTag); explicit Object(GlobalObjectTag);
Object(ConstructWithoutPrototypeTag, GlobalObject&); Object(ConstructWithoutPrototypeTag, GlobalObject&);
virtual Value get_by_index(u32 property_index) const; virtual Value get_by_index(u32 property_index, bool without_side_effects = false) const;
virtual bool put_by_index(u32 property_index, Value); virtual bool put_by_index(u32 property_index, Value);
private: private:

View file

@ -77,10 +77,10 @@ public:
return true; return true;
} }
virtual Value get_by_index(u32 property_index) const override virtual Value get_by_index(u32 property_index, bool without_side_effects = false) const override
{ {
if (property_index >= m_array_length) if (property_index >= m_array_length)
return Base::get_by_index(property_index); return Base::get_by_index(property_index, without_side_effects);
if constexpr (sizeof(UnderlyingBufferDataType) < 4) { if constexpr (sizeof(UnderlyingBufferDataType) < 4) {
return Value((i32)data()[property_index]); return Value((i32)data()[property_index]);

View file

@ -22,11 +22,11 @@ JS::Value HTMLCollectionWrapper::get(JS::PropertyName const& name, JS::Value rec
return JS::Value { wrap(global_object(), *item) }; return JS::Value { wrap(global_object(), *item) };
} }
JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index) const JS::Value HTMLCollectionWrapper::get_by_index(u32 property_index, bool without_side_effects) const
{ {
auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index); auto* item = const_cast<DOM::HTMLCollection&>(impl()).item(property_index);
if (!item) if (!item)
return Base::get_by_index(property_index); return Base::get_by_index(property_index, without_side_effects);
return wrap(global_object(), *item); return wrap(global_object(), *item);
} }

View file

@ -791,7 +791,7 @@ public:
} }
if (interface.extended_attributes.contains("CustomGetByIndex")) { if (interface.extended_attributes.contains("CustomGetByIndex")) {
generator.append(R"~~~( generator.append(R"~~~(
virtual JS::Value get_by_index(u32 property_index) const override; virtual JS::Value get_by_index(u32 property_index, bool without_side_effects = false) const override;
)~~~"); )~~~");
} }
if (interface.extended_attributes.contains("CustomPut")) { if (interface.extended_attributes.contains("CustomPut")) {