diff options
author | Linus Groh <mail@linusgroh.de> | 2020-11-06 18:54:45 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-07 10:08:05 +0100 |
commit | 965050796f901fb28696e83574568db20e3b7b2b (patch) | |
tree | d16364affd1b636cdd9d247f29575e52cf77cf06 | |
parent | a0130b55d44fe7e681a7a452e0beb464167af292 (diff) | |
download | serenity-965050796f901fb28696e83574568db20e3b7b2b.zip |
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).
-rw-r--r-- | Libraries/LibJS/Runtime/StringOrSymbol.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Libraries/LibJS/Runtime/StringOrSymbol.h b/Libraries/LibJS/Runtime/StringOrSymbol.h index 3273e7f640..b21c1785c6 100644 --- a/Libraries/LibJS/Runtime/StringOrSymbol.h +++ b/Libraries/LibJS/Runtime/StringOrSymbol.h @@ -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; |