diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-13 00:04:52 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-13 09:36:20 +0200 |
commit | 0c14ee035cec4f5c151cda5d0342f81d50b6e400 (patch) | |
tree | 00bce479b3f82d1a67c2f50ba22c20b990b8c48a /Libraries/LibJS/Runtime/Value.cpp | |
parent | 7b8765c311ab4a2f42c923e009216478c6c3e2d1 (diff) | |
download | serenity-0c14ee035cec4f5c151cda5d0342f81d50b6e400.zip |
LibJS: Make string to number coercion work for doubles
Diffstat (limited to 'Libraries/LibJS/Runtime/Value.cpp')
-rw-r--r-- | Libraries/LibJS/Runtime/Value.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 2c94a253dd..78c42dee5d 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -173,13 +173,11 @@ Value Value::to_number() const return js_infinity(); if (string == "-Infinity") return js_negative_infinity(); - bool ok; - //FIXME: Parse in a better way - auto parsed_int = string.to_int(ok); - if (ok) - return Value(parsed_int); - - return js_nan(); + char* endptr; + auto parsed_double = strtod(string.characters(), &endptr); + if (*endptr) + return js_nan(); + return Value(parsed_double); } case Type::Object: return m_value.as_object->to_primitive(Object::PreferredType::Number).to_number(); |