1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:47:36 +00:00

LibJS: Convert PropertyKey::from_value() to ThrowCompletionOr

Lots of MUST() - perhaps we'll eventually come up with a better API for
the common case where it can't fail.
This commit is contained in:
Linus Groh 2022-01-04 22:33:30 +01:00
parent 62356cff40
commit 29e96eceeb
7 changed files with 23 additions and 25 deletions

View file

@ -26,15 +26,15 @@ public:
No,
};
static PropertyKey from_value(GlobalObject& global_object, Value value)
static ThrowCompletionOr<PropertyKey> from_value(GlobalObject& global_object, Value value)
{
if (value.is_empty())
return {};
return PropertyKey {};
if (value.is_symbol())
return value.as_symbol();
return PropertyKey { value.as_symbol() };
if (value.is_integral_number() && value.as_double() >= 0 && value.as_double() < NumericLimits<u32>::max())
return value.as_u32();
return TRY_OR_DISCARD(value.to_string(global_object));
return TRY(value.to_string(global_object));
}
PropertyKey() { }