mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Add spec comments to Value::typeof()
This commit is contained in:
parent
1fe7984160
commit
9a961af0b0
Notes:
sideshowbarker
2024-07-17 12:02:22 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/9a961af0b0 Pull-request: https://github.com/SerenityOS/serenity/pull/16405 Reviewed-by: https://github.com/davidot ✅
1 changed files with 20 additions and 9 deletions
|
@ -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
|
||||
DeprecatedString Value::typeof() const
|
||||
{
|
||||
// 9. If val is a Number, return "number".
|
||||
if (is_number())
|
||||
return "number";
|
||||
|
||||
switch (m_value.tag) {
|
||||
// 4. If val is undefined, return "undefined".
|
||||
case UNDEFINED_TAG:
|
||||
return "undefined";
|
||||
// 5. If val is null, return "object".
|
||||
case NULL_TAG:
|
||||
return "object";
|
||||
// 6. If val is a String, return "string".
|
||||
case STRING_TAG:
|
||||
return "string";
|
||||
case OBJECT_TAG:
|
||||
// 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";
|
||||
// 7. If val is a Symbol, return "symbol".
|
||||
case SYMBOL_TAG:
|
||||
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:
|
||||
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:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue