1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:47:35 +00:00

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
parent a0130b55d4
commit 965050796f

View file

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