mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibJS: Add spec comments to Value::to_boolean()
This commit is contained in:
parent
596b30df5f
commit
e3c8e1362f
1 changed files with 9 additions and 5 deletions
|
@ -436,23 +436,27 @@ bool Value::to_boolean() const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_value.tag) {
|
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 UNDEFINED_TAG:
|
||||||
case NULL_TAG:
|
case NULL_TAG:
|
||||||
return false;
|
return false;
|
||||||
case BOOLEAN_TAG:
|
|
||||||
return as_bool();
|
|
||||||
case INT32_TAG:
|
case INT32_TAG:
|
||||||
return as_i32() != 0;
|
return as_i32() != 0;
|
||||||
case STRING_TAG:
|
case STRING_TAG:
|
||||||
return !as_string().is_empty();
|
return !as_string().is_empty();
|
||||||
case SYMBOL_TAG:
|
|
||||||
return true;
|
|
||||||
case BIGINT_TAG:
|
case BIGINT_TAG:
|
||||||
return as_bigint().big_integer() != BIGINT_ZERO;
|
return as_bigint().big_integer() != BIGINT_ZERO;
|
||||||
case OBJECT_TAG:
|
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())
|
if (as_object().is_htmldda())
|
||||||
return false;
|
return false;
|
||||||
|
// 4. Return true.
|
||||||
|
return true;
|
||||||
|
case SYMBOL_TAG:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue