summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-12-09 23:57:06 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-10 11:23:23 +0000
commite3c8e1362ffbee1afad29fa39133bcfc13f8d337 (patch)
treeb90e2c6d9d1b5bddcc6ff181f405970e72c0c716 /Userland/Libraries/LibJS/Runtime
parent596b30df5f3b73e22f08854804103e24cdd17a92 (diff)
downloadserenity-e3c8e1362ffbee1afad29fa39133bcfc13f8d337.zip
LibJS: Add spec comments to Value::to_boolean()
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Value.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp
index e7aaf70bf5..1ba8e52750 100644
--- a/Userland/Libraries/LibJS/Runtime/Value.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Value.cpp
@@ -436,23 +436,27 @@ bool Value::to_boolean() const
}
switch (m_value.tag) {
+ // 1. If argument is a Boolean, return argument.
+ case BOOLEAN_TAG:
+ return as_bool();
+ // 2. If argument is any of undefined, null, +0𝔽, -0𝔽, NaN, 0ℤ, or the empty String, return false.
case UNDEFINED_TAG:
case NULL_TAG:
return false;
- case BOOLEAN_TAG:
- return as_bool();
case INT32_TAG:
return as_i32() != 0;
case STRING_TAG:
return !as_string().is_empty();
- case SYMBOL_TAG:
- return true;
case BIGINT_TAG:
return as_bigint().big_integer() != BIGINT_ZERO;
case OBJECT_TAG:
- // B.3.7.1 Changes to ToBoolean, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-to-boolean
+ // B.3.6.1 Changes to ToBoolean, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-to-boolean
+ // 3. If argument is an Object and argument has an [[IsHTMLDDA]] internal slot, return false.
if (as_object().is_htmldda())
return false;
+ // 4. Return true.
+ return true;
+ case SYMBOL_TAG:
return true;
default:
VERIFY_NOT_REACHED();