mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibJS: Handle non-string primitive values in Object::to_string()
This commit is contained in:
parent
2c6e7dbd07
commit
4bdb6daac5
Notes:
sideshowbarker
2024-07-19 07:11:02 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/4bdb6daac58 Pull-request: https://github.com/SerenityOS/serenity/pull/2020
1 changed files with 3 additions and 3 deletions
|
@ -361,12 +361,12 @@ Value Object::to_string() const
|
|||
&& to_string_property.as_object().is_function()) {
|
||||
auto& to_string_function = static_cast<Function&>(to_string_property.as_object());
|
||||
auto& interpreter = const_cast<Object*>(this)->interpreter();
|
||||
auto string_value = interpreter.call(to_string_function, const_cast<Object*>(this));
|
||||
if (!string_value.is_string())
|
||||
auto to_string_result = interpreter.call(to_string_function, const_cast<Object*>(this));
|
||||
if (to_string_result.is_object())
|
||||
interpreter.throw_exception<TypeError>("Cannot convert object to string");
|
||||
if (interpreter.exception())
|
||||
return {};
|
||||
return string_value;
|
||||
return js_string(heap(), to_string_result.to_string());
|
||||
}
|
||||
return js_string(heap(), String::format("[object %s]", class_name()));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue