diff options
author | Jack Karamanian <karamanian.jack@gmail.com> | 2020-04-06 22:48:47 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-07 08:41:25 +0200 |
commit | 57bd194e5a11ae6bc8477eb976fb7d2c1e10ac35 (patch) | |
tree | c441aaa117f620dfeb9da7529497702341e91aef /Libraries | |
parent | 4a9485f830c1134177cbd066fdeb24458d1ec4d0 (diff) | |
download | serenity-57bd194e5a11ae6bc8477eb976fb7d2c1e10ac35.zip |
LibJS: Return false for NaN numbers in Value::to_boolean()
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Runtime/Value.cpp | 3 | ||||
-rw-r--r-- | Libraries/LibJS/Tests/NaN-basic.js | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 77d2fcc4f9..6e5d11c3ba 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -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: diff --git a/Libraries/LibJS/Tests/NaN-basic.js b/Libraries/LibJS/Tests/NaN-basic.js index b9a02bc425..17b51711d6 100644 --- a/Libraries/LibJS/Tests/NaN-basic.js +++ b/Libraries/LibJS/Tests/NaN-basic.js @@ -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); |