From 63f6099cc38a5b95e60d4eb1d36366602ec99dbb Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 9 Dec 2022 23:58:26 +0000 Subject: [PATCH] LibJS: Add spec comments to Value::to_object() --- Userland/Libraries/LibJS/Runtime/Value.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index ceaa9a0f4f..93bf2f7e4d 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -519,22 +519,39 @@ ThrowCompletionOr Value::to_object(VM& vm) const { auto& realm = *vm.current_realm(); VERIFY(!is_empty()); - if (is_number()) + + // Number + if (is_number()) { + // Return a new Number object whose [[NumberData]] internal slot is set to argument. See 21.1 for a description of Number objects. return NumberObject::create(realm, as_double()); + } switch (m_value.tag) { + // Undefined + // Null case UNDEFINED_TAG: case NULL_TAG: + // Throw a TypeError exception. return vm.throw_completion(ErrorType::ToObjectNullOrUndefined); + // Boolean case BOOLEAN_TAG: + // Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 20.3 for a description of Boolean objects. return BooleanObject::create(realm, as_bool()); + // String case STRING_TAG: + // Return a new String object whose [[StringData]] internal slot is set to argument. See 22.1 for a description of String objects. return StringObject::create(realm, const_cast(as_string()), *realm.intrinsics().string_prototype()); + // Symbol case SYMBOL_TAG: + // Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 20.4 for a description of Symbol objects. return SymbolObject::create(realm, const_cast(as_symbol())); + // BigInt case BIGINT_TAG: + // Return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See 21.2 for a description of BigInt objects. return BigIntObject::create(realm, const_cast(as_bigint())); + // Object case OBJECT_TAG: + // Return argument. return &const_cast(as_object()); default: VERIFY_NOT_REACHED();