diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-16 20:39:39 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-16 22:54:48 +0100 |
commit | 6352a33ed2adc3d8f3e862ae956aa98f6cacadb7 (patch) | |
tree | ea6673466f9c1e6da1c28989ddf9b8fd624398bd | |
parent | 317b88a8c395bf34b0290eaddeefb6afe4b584ed (diff) | |
download | serenity-6352a33ed2adc3d8f3e862ae956aa98f6cacadb7.zip |
LibJS: Respect Object::get's without_side_effects parameter for numbers
5 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index fee600bcba..e2795a3d9f 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -812,7 +812,7 @@ void Object::ensure_shape_is_unique() 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; while (object) { @@ -821,7 +821,7 @@ Value Object::get_by_index(u32 property_index) const if (property_index < string.length()) return js_string(heap(), string.substring(property_index, 1)); } 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()) return {}; 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()); 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()) { auto& property_string = property_name.as_string(); i32 property_index = property_string.to_int().value_or(-1); if (property_index >= 0) - return get_by_index(property_index); + return get_by_index(property_index, without_side_effects); } if (receiver.is_empty()) diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 64df83284d..2628f3096c 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -163,7 +163,7 @@ protected: explicit Object(GlobalObjectTag); 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); private: diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index 49a9f2ce10..0ef0e600b6 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -77,10 +77,10 @@ public: 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) - return Base::get_by_index(property_index); + return Base::get_by_index(property_index, without_side_effects); if constexpr (sizeof(UnderlyingBufferDataType) < 4) { return Value((i32)data()[property_index]); diff --git a/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp index 1bec8b5fce..2a2b5493c8 100644 --- a/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp +++ b/Userland/Libraries/LibWeb/Bindings/HTMLCollectionWrapperCustom.cpp @@ -22,11 +22,11 @@ JS::Value HTMLCollectionWrapper::get(JS::PropertyName const& name, JS::Value rec 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); if (!item) - return Base::get_by_index(property_index); + return Base::get_by_index(property_index, without_side_effects); return wrap(global_object(), *item); } diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index 0ce81ccb99..c6f7895367 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -791,7 +791,7 @@ public: } if (interface.extended_attributes.contains("CustomGetByIndex")) { 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")) { |