1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

LibJS: Stop using Optional<Value> in favor of Value's empty state

JS::Value already has the empty state ({} or Value() gives you one.)
Use this instead of wrapping Value in Optional in some places.
I've also added Value::value_or(Value) so you can easily provide a
fallback value when one is not present.
This commit is contained in:
Andreas Kling 2020-04-25 18:43:34 +02:00
parent 5adf4901df
commit 35aea2e454
14 changed files with 60 additions and 48 deletions

View file

@ -387,7 +387,7 @@ Value in(Interpreter& interpreter, Value lhs, Value rhs)
if (!rhs.is_object())
return interpreter.throw_exception<TypeError>("'in' operator must be used on object");
return Value(rhs.as_object().get(lhs.to_string()).has_value());
return Value(!rhs.as_object().get(lhs.to_string()).is_empty());
}
Value instance_of(Interpreter&, Value lhs, Value rhs)
@ -396,10 +396,10 @@ Value instance_of(Interpreter&, Value lhs, Value rhs)
return Value(false);
auto constructor_prototype_property = rhs.as_object().get("prototype");
if (!constructor_prototype_property.has_value() || !constructor_prototype_property.value().is_object())
if (!constructor_prototype_property.is_object())
return Value(false);
return Value(lhs.as_object().has_prototype(&constructor_prototype_property.value().as_object()));
return Value(lhs.as_object().has_prototype(&constructor_prototype_property.as_object()));
}
const LogStream& operator<<(const LogStream& stream, const Value& value)