1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 19:27:45 +00:00

LibJS: Add spec comments to Value::typeof()

This commit is contained in:
Linus Groh 2022-12-09 23:55:47 +00:00
parent 1fe7984160
commit 9a961af0b0

View file

@ -296,29 +296,40 @@ ThrowCompletionOr<bool> Value::is_regexp(VM& vm) const
// 13.5.3 The typeof Operator, https://tc39.es/ecma262/#sec-typeof-operator // 13.5.3 The typeof Operator, https://tc39.es/ecma262/#sec-typeof-operator
DeprecatedString Value::typeof() const DeprecatedString Value::typeof() const
{ {
// 9. If val is a Number, return "number".
if (is_number()) if (is_number())
return "number"; return "number";
switch (m_value.tag) { switch (m_value.tag) {
// 4. If val is undefined, return "undefined".
case UNDEFINED_TAG: case UNDEFINED_TAG:
return "undefined"; return "undefined";
// 5. If val is null, return "object".
case NULL_TAG: case NULL_TAG:
return "object"; return "object";
// 6. If val is a String, return "string".
case STRING_TAG: case STRING_TAG:
return "string"; return "string";
case OBJECT_TAG: // 7. If val is a Symbol, return "symbol".
// B.3.7.3 Changes to the typeof Operator, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-typeof
if (as_object().is_htmldda())
return "undefined";
if (is_function())
return "function";
return "object";
case BOOLEAN_TAG:
return "boolean";
case SYMBOL_TAG: case SYMBOL_TAG:
return "symbol"; return "symbol";
// 8. If val is a Boolean, return "boolean".
case BOOLEAN_TAG:
return "boolean";
// 10. If val is a BigInt, return "bigint".
case BIGINT_TAG: case BIGINT_TAG:
return "bigint"; return "bigint";
// 11. Assert: val is an Object.
case OBJECT_TAG:
// B.3.6.3 Changes to the typeof Operator, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-typeof
// 12. If val has an [[IsHTMLDDA]] internal slot, return "undefined".
if (as_object().is_htmldda())
return "undefined";
// 13. If val has a [[Call]] internal slot, return "function".
if (is_function())
return "function";
// 14. Return "object".
return "object";
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }