1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

LibJS: Make Object::invoke() non-const

As suggested in #2431's code review.
This commit is contained in:
Linus Groh 2020-05-29 12:20:14 +01:00 committed by Andreas Kling
parent 1dd44210b7
commit 688ca7b196
2 changed files with 4 additions and 4 deletions

View file

@ -662,9 +662,9 @@ Value Object::to_string() const
return js_string(heap(), String::format("[object %s]", class_name())); return js_string(heap(), String::format("[object %s]", class_name()));
} }
Value Object::invoke(const FlyString& property_name, Optional<MarkedValueList> arguments) const Value Object::invoke(const FlyString& property_name, Optional<MarkedValueList> arguments)
{ {
auto& interpreter = const_cast<Object*>(this)->interpreter(); auto& interpreter = this->interpreter();
auto property = get(property_name).value_or(js_undefined()); auto property = get(property_name).value_or(js_undefined());
if (interpreter.exception()) if (interpreter.exception())
return {}; return {};
@ -672,7 +672,7 @@ Value Object::invoke(const FlyString& property_name, Optional<MarkedValueList> a
interpreter.throw_exception<TypeError>(String::format("%s is not a function", property.to_string_without_side_effects().characters())); interpreter.throw_exception<TypeError>(String::format("%s is not a function", property.to_string_without_side_effects().characters()));
return {}; return {};
} }
return interpreter.call(property.as_function(), const_cast<Object*>(this), move(arguments)); return interpreter.call(property.as_function(), this, move(arguments));
} }
} }

View file

@ -108,7 +108,7 @@ public:
IndexedProperties& indexed_properties() { return m_indexed_properties; } IndexedProperties& indexed_properties() { return m_indexed_properties; }
void set_indexed_property_elements(Vector<Value>&& values) { m_indexed_properties = IndexedProperties(move(values)); } void set_indexed_property_elements(Vector<Value>&& values) { m_indexed_properties = IndexedProperties(move(values)); }
Value invoke(const FlyString& property_name, Optional<MarkedValueList> arguments = {}) const; Value invoke(const FlyString& property_name, Optional<MarkedValueList> arguments = {});
private: private:
virtual Value get_by_index(u32 property_index) const; virtual Value get_by_index(u32 property_index) const;