mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Make string to number coercion work for doubles
This commit is contained in:
parent
7b8765c311
commit
0c14ee035c
Notes:
sideshowbarker
2024-07-19 06:41:14 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/0c14ee035ce Pull-request: https://github.com/SerenityOS/serenity/pull/2208
2 changed files with 7 additions and 10 deletions
|
@ -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();
|
||||
|
|
|
@ -27,9 +27,8 @@ try {
|
|||
assert(-42 === -42);
|
||||
assert(+1.23 === 1.23);
|
||||
assert(-1.23 === -1.23);
|
||||
// FIXME: returns NaN
|
||||
// assert(+"1.23" === 1.23)
|
||||
// assert(-"1.23" === -1.23)
|
||||
assert(+"1.23" === 1.23)
|
||||
assert(-"1.23" === -1.23)
|
||||
assert(+"Infinity" === Infinity);
|
||||
assert(+"+Infinity" === Infinity);
|
||||
assert(+"-Infinity" === -Infinity);
|
||||
|
|
Loading…
Reference in a new issue