mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
LibJS: Return false for NaN numbers in Value::to_boolean()
This commit is contained in:
parent
4a9485f830
commit
57bd194e5a
Notes:
sideshowbarker
2024-07-19 07:50:33 +09:00
Author: https://github.com/jack-karamanian Commit: https://github.com/SerenityOS/serenity/commit/57bd194e5a1 Pull-request: https://github.com/SerenityOS/serenity/pull/1682 Reviewed-by: https://github.com/bgianfo
2 changed files with 6 additions and 0 deletions
|
@ -83,6 +83,9 @@ bool Value::to_boolean() const
|
|||
case Type::Boolean:
|
||||
return m_value.as_bool;
|
||||
case Type::Number:
|
||||
if (is_nan()) {
|
||||
return false;
|
||||
}
|
||||
return !(m_value.as_double == 0 || m_value.as_double == -0);
|
||||
case Type::Null:
|
||||
case Type::Undefined:
|
||||
|
|
|
@ -10,6 +10,9 @@ try {
|
|||
assert(isNaN(undefined) === true);
|
||||
assert(isNaN(null) === false);
|
||||
assert(isNaN(Infinity) === false);
|
||||
assert(!!NaN === false);
|
||||
assert(!!nan === false);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
|
|
Loading…
Add table
Reference in a new issue