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);