mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 03:09:08 +00:00
LibJS: Throw error in Object::to_string() if string conversion fails
This commit is contained in:
committed by
Andreas Kling
parent
95abcc3722
commit
2c6e7dbd07
@@ -360,7 +360,13 @@ Value Object::to_string() const
|
||||
&& to_string_property.is_object()
|
||||
&& to_string_property.as_object().is_function()) {
|
||||
auto& to_string_function = static_cast<Function&>(to_string_property.as_object());
|
||||
return const_cast<Object*>(this)->interpreter().call(to_string_function, const_cast<Object*>(this));
|
||||
auto& interpreter = const_cast<Object*>(this)->interpreter();
|
||||
auto string_value = interpreter.call(to_string_function, const_cast<Object*>(this));
|
||||
if (!string_value.is_string())
|
||||
interpreter.throw_exception<TypeError>("Cannot convert object to string");
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
return string_value;
|
||||
}
|
||||
return js_string(heap(), String::format("[object %s]", class_name()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user