LibJS: Don't create StringOrSymbol(String) if from_value() fails

If value.to_string() throws an exception and returns a null string we
must create an invalid StringOrSymbol, not one from the null string
(which ASSERT()s).
This commit is contained in:
Linus Groh 2020-11-06 18:54:45 +00:00 committed by Andreas Kling
commit 965050796f
Notes: sideshowbarker 2024-07-19 01:32:20 +09:00

View file

@ -37,11 +37,14 @@ class StringOrSymbol {
public:
static StringOrSymbol from_value(GlobalObject& global_object, Value value)
{
if (value.is_empty())
return {};
if (value.is_symbol())
return &value.as_symbol();
if (!value.is_empty())
return value.to_string(global_object);
return {};
auto string = value.to_string(global_object);
if (string.is_null())
return {};
return string;
}
StringOrSymbol() = default;