From 688ca7b196d2567f46125e54fa8463327cc798d4 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 29 May 2020 12:20:14 +0100 Subject: [PATCH] LibJS: Make Object::invoke() non-const As suggested in #2431's code review. --- Libraries/LibJS/Runtime/Object.cpp | 6 +++--- Libraries/LibJS/Runtime/Object.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/LibJS/Runtime/Object.cpp b/Libraries/LibJS/Runtime/Object.cpp index eff0d31e12..915ce3b251 100644 --- a/Libraries/LibJS/Runtime/Object.cpp +++ b/Libraries/LibJS/Runtime/Object.cpp @@ -662,9 +662,9 @@ Value Object::to_string() const return js_string(heap(), String::format("[object %s]", class_name())); } -Value Object::invoke(const FlyString& property_name, Optional arguments) const +Value Object::invoke(const FlyString& property_name, Optional arguments) { - auto& interpreter = const_cast(this)->interpreter(); + auto& interpreter = this->interpreter(); auto property = get(property_name).value_or(js_undefined()); if (interpreter.exception()) return {}; @@ -672,7 +672,7 @@ Value Object::invoke(const FlyString& property_name, Optional a interpreter.throw_exception(String::format("%s is not a function", property.to_string_without_side_effects().characters())); return {}; } - return interpreter.call(property.as_function(), const_cast(this), move(arguments)); + return interpreter.call(property.as_function(), this, move(arguments)); } } diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 503ba55857..5abc982154 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -108,7 +108,7 @@ public: IndexedProperties& indexed_properties() { return m_indexed_properties; } void set_indexed_property_elements(Vector&& values) { m_indexed_properties = IndexedProperties(move(values)); } - Value invoke(const FlyString& property_name, Optional arguments = {}) const; + Value invoke(const FlyString& property_name, Optional arguments = {}); private: virtual Value get_by_index(u32 property_index) const;