mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
LibJS: Throw error in Object::to_string() if string conversion fails
This commit is contained in:
parent
95abcc3722
commit
2c6e7dbd07
2 changed files with 14 additions and 3 deletions
|
@ -69,8 +69,13 @@ String Value::to_string() const
|
|||
return String::format("%.4f", as_double());
|
||||
}
|
||||
|
||||
if (is_object())
|
||||
return as_object().to_primitive(Object::PreferredType::String).to_string();
|
||||
if (is_object()) {
|
||||
auto primitive_value = as_object().to_primitive(Object::PreferredType::String);
|
||||
// FIXME: Maybe we should pass in the Interpreter& and call interpreter.exception() instead?
|
||||
if (primitive_value.is_empty())
|
||||
return {};
|
||||
return primitive_value.to_string();
|
||||
}
|
||||
|
||||
if (is_string())
|
||||
return m_value.as_string->string();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue