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

LibJS: Handle Infinity in Value::to_number()

This commit is contained in:
Linus Groh 2020-04-12 13:06:34 +01:00 committed by Andreas Kling
parent 477bacddad
commit f226746394
3 changed files with 17 additions and 0 deletions

View file

@ -136,9 +136,14 @@ Value Value::to_number() const
case Type::Null:
return Value(0);
case Type::String: {
// FIXME: Trim whitespace beforehand
auto& string = as_string()->string();
if (string.is_empty())
return Value(0);
if (string == "Infinity" || string == "+Infinity")
return js_infinity();
if (string == "-Infinity")
return Value(-js_infinity().as_double());
bool ok;
//FIXME: Parse in a better way
auto parsed_int = string.to_int(ok);